diff --git a/jni/NativeFormats/JavaNativeFormatPlugin.cpp b/jni/NativeFormats/JavaNativeFormatPlugin.cpp index e44ebe80c..2f7f06621 100644 --- a/jni/NativeFormats/JavaNativeFormatPlugin.cpp +++ b/jni/NativeFormats/JavaNativeFormatPlugin.cpp @@ -276,6 +276,10 @@ static void initTOC(JNIEnv *env, jobject javaModel, const ContentsTree &tree) { } } +static jstring createJavaString(JNIEnv *env, shared_ptr info) { + return info.isNull() ? 0 : AndroidUtil::createJavaString(env, info->Path); +} + extern "C" JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readModelNative(JNIEnv* env, jobject thiz, jobject javaModel) { shared_ptr plugin = findCppPlugin(thiz); @@ -345,10 +349,10 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin continue; } jstring family = AndroidUtil::createJavaString(env, it->first); - jstring normal = AndroidUtil::createJavaString(env, it->second->Normal); - jstring bold = AndroidUtil::createJavaString(env, it->second->Bold); - jstring italic = AndroidUtil::createJavaString(env, it->second->Italic); - jstring boldItalic = AndroidUtil::createJavaString(env, it->second->BoldItalic); + jstring normal = createJavaString(env, it->second->Normal); + jstring bold = createJavaString(env, it->second->Bold); + jstring italic = createJavaString(env, it->second->Italic); + jstring boldItalic = createJavaString(env, it->second->BoldItalic); AndroidUtil::Method_NativeBookModel_registerFontEntry->call( javaModel, family, normal, bold, italic, boldItalic diff --git a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.cpp b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.cpp index 74df25d95..244004ae0 100644 --- a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.cpp +++ b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.cpp @@ -240,7 +240,7 @@ shared_ptr StyleSheetSingleStyleParser::parseSingleEntry(const return control; } -StyleSheetMultiStyleParser::StyleSheetMultiStyleParser(const std::string &pathPrefix, shared_ptr fontMap) : StyleSheetParser(pathPrefix), myFontMap(fontMap.isNull() ? new FontMap() : fontMap) { +StyleSheetMultiStyleParser::StyleSheetMultiStyleParser(const std::string &pathPrefix, shared_ptr fontMap, shared_ptr encryptionMap) : StyleSheetParser(pathPrefix), myFontMap(fontMap.isNull() ? new FontMap() : fontMap), myEncryptionMap(encryptionMap) { } void StyleSheetMultiStyleParser::storeData(const std::string &selector, const StyleSheetTable::AttributeMap &map) { @@ -297,7 +297,7 @@ void StyleSheetMultiStyleParser::processAtRule(const std::string &name, const St for (std::vector::const_iterator jt = ids.begin(); jt != ids.end(); ++jt) { if (ZLStringUtil::stringStartsWith(*jt, "url(") && ZLStringUtil::stringEndsWith(*jt, ")")) { - path = url2FullPath(*jt); + path = ZLFile(url2FullPath(*jt)).path(); break; } } @@ -310,18 +310,24 @@ void StyleSheetMultiStyleParser::processAtRule(const std::string &name, const St const std::string weight = value(attributes, "font-weight"); const std::string style = value(attributes, "font-style"); - myFontMap->append(family, weight == "bold", style == "italic" || style == "oblique", path); + myFontMap->append( + family, + weight == "bold", + style == "italic" || style == "oblique", + path, + myEncryptionMap.isNull() ? 0 : myEncryptionMap->info(path) + ); } } -StyleSheetTableParser::StyleSheetTableParser(const std::string &pathPrefix, StyleSheetTable &styleTable, shared_ptr fontMap) : StyleSheetMultiStyleParser(pathPrefix, fontMap), myStyleTable(styleTable) { +StyleSheetTableParser::StyleSheetTableParser(const std::string &pathPrefix, StyleSheetTable &styleTable, shared_ptr fontMap, shared_ptr encryptionMap) : StyleSheetMultiStyleParser(pathPrefix, fontMap, encryptionMap), myStyleTable(styleTable) { } void StyleSheetTableParser::store(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map) { myStyleTable.addMap(tag, aClass, map); } -StyleSheetParserWithCache::StyleSheetParserWithCache(const ZLFile &file, const std::string &pathPrefix, shared_ptr fontMap, shared_ptr encryptionMap) : StyleSheetMultiStyleParser(pathPrefix, fontMap), myEncryptionMap(encryptionMap) { +StyleSheetParserWithCache::StyleSheetParserWithCache(const ZLFile &file, const std::string &pathPrefix, shared_ptr fontMap, shared_ptr encryptionMap) : StyleSheetMultiStyleParser(pathPrefix, fontMap, encryptionMap) { myProcessedFiles.insert(file.path()); } diff --git a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.h b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.h index dbc151309..30406a1dc 100644 --- a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.h +++ b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.h @@ -86,7 +86,7 @@ public: class StyleSheetMultiStyleParser : public StyleSheetParser { protected: - StyleSheetMultiStyleParser(const std::string &pathPrefix, shared_ptr myFontMap); + StyleSheetMultiStyleParser(const std::string &pathPrefix, shared_ptr fontMap, shared_ptr encryptionMap); protected: virtual void store(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map) = 0; @@ -97,12 +97,13 @@ private: protected: shared_ptr myFontMap; + shared_ptr myEncryptionMap; }; class StyleSheetTableParser : public StyleSheetMultiStyleParser { public: - StyleSheetTableParser(const std::string &pathPrexix, StyleSheetTable &styleTable, shared_ptr fontMap); + StyleSheetTableParser(const std::string &pathPrexix, StyleSheetTable &styleTable, shared_ptr fontMap, shared_ptr encryptionMap); private: void store(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map); @@ -133,7 +134,6 @@ private: private: std::list > myEntries; std::set myProcessedFiles; - shared_ptr myEncryptionMap; }; inline StyleSheetParserWithCache::Entry::Entry(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map) : Tag(tag), Class(aClass), Map(map) { diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.cpp b/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.cpp index 9cde4e5ec..9ee9c2048 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.cpp @@ -274,7 +274,7 @@ HtmlStyleTagAction::HtmlStyleTagAction(HtmlBookReader &reader) : HtmlTagAction(r } void HtmlStyleTagAction::run(const HtmlReader::HtmlTag &tag) { - myReader.myStyleSheetParser = tag.Start ? new StyleSheetTableParser(myReader.myBaseDirPath, myReader.myStyleSheetTable, myReader.myFontMap) : 0; + myReader.myStyleSheetParser = tag.Start ? new StyleSheetTableParser(myReader.myBaseDirPath, myReader.myStyleSheetTable, myReader.myFontMap, 0) : 0; /* if (!tag.Start) { myReader.myStyleSheetTable.dump(); diff --git a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp index 3e3e31b71..0deede194 100644 --- a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp @@ -229,7 +229,7 @@ void XHTMLTagStyleAction::doAtStart(XHTMLReader &reader, const char **xmlattribu if (reader.myReadState == XHTML_READ_NOTHING) { reader.myReadState = XHTML_READ_STYLE; - reader.myTableParser = new StyleSheetTableParser(reader.myPathPrefix, reader.myStyleSheetTable, reader.myFontMap); + reader.myTableParser = new StyleSheetTableParser(reader.myPathPrefix, reader.myStyleSheetTable, reader.myFontMap, reader.myEncryptionMap); ZLLogger::Instance().println("CSS", "parsing style tag content"); } } diff --git a/jni/NativeFormats/zlibrary/text/src/fonts/FontMap.cpp b/jni/NativeFormats/zlibrary/text/src/fonts/FontMap.cpp index 4d1e0cbe9..25adfb1e9 100644 --- a/jni/NativeFormats/zlibrary/text/src/fonts/FontMap.cpp +++ b/jni/NativeFormats/zlibrary/text/src/fonts/FontMap.cpp @@ -21,18 +21,22 @@ #include "FontMap.h" -void FontEntry::addFile(bool bold, bool italic, const std::string &filePath) { +FileInfo::FileInfo(const std::string &path, shared_ptr info) : Path(path), EncryptionInfo(info) { +} + +void FontEntry::addFile(bool bold, bool italic, const std::string &filePath, shared_ptr encryptionInfo) { + shared_ptr fileInfo = new FileInfo(filePath, encryptionInfo); if (bold) { if (italic) { - BoldItalic = new std::string(filePath); + BoldItalic = fileInfo; } else { - Bold = new std::string(filePath); + Bold = fileInfo; } } else { if (italic) { - Italic = new std::string(filePath); + Italic = fileInfo; } else { - Normal = new std::string(filePath); + Normal = fileInfo; } } } @@ -52,30 +56,30 @@ void FontEntry::merge(const FontEntry &fontEntry) { } } -static bool compareStringPtrs(shared_ptr str0, shared_ptr str1) { - return str0.isNull() ? str1.isNull() : (!str1.isNull() && *str0 == *str1); +static bool compareFileInfos(shared_ptr info0, shared_ptr info1) { + return info0.isNull() ? info1.isNull() : (!info1.isNull() && info0->Path == info1->Path); } bool FontEntry::operator == (const FontEntry &other) const { return - compareStringPtrs(Normal, other.Normal) && - compareStringPtrs(Bold, other.Bold) && - compareStringPtrs(Italic, other.Italic) && - compareStringPtrs(BoldItalic, other.BoldItalic); + compareFileInfos(Normal, other.Normal) && + compareFileInfos(Bold, other.Bold) && + compareFileInfos(Italic, other.Italic) && + compareFileInfos(BoldItalic, other.BoldItalic); } bool FontEntry::operator != (const FontEntry &other) const { return !operator ==(other); } -void FontMap::append(const std::string &family, bool bold, bool italic, const std::string &path) { +void FontMap::append(const std::string &family, bool bold, bool italic, const std::string &path, shared_ptr encryptionInfo) { const ZLFile fontFile(path); shared_ptr entry = myMap[family]; if (entry.isNull()) { entry = new FontEntry(); myMap[family] = entry; } - entry->addFile(bold, italic, fontFile.path()); + entry->addFile(bold, italic, fontFile.path(), encryptionInfo); } void FontMap::merge(const FontMap &fontMap) { diff --git a/jni/NativeFormats/zlibrary/text/src/fonts/FontMap.h b/jni/NativeFormats/zlibrary/text/src/fonts/FontMap.h index 570b6a545..3720e608d 100644 --- a/jni/NativeFormats/zlibrary/text/src/fonts/FontMap.h +++ b/jni/NativeFormats/zlibrary/text/src/fonts/FontMap.h @@ -25,26 +25,38 @@ #include +#include + +class FileInfo { + +public: + FileInfo(const std::string &path, shared_ptr info); + +public: + const std::string Path; + shared_ptr EncryptionInfo; +}; + class FontEntry { public: - void addFile(bool bold, bool italic, const std::string &filePath); + void addFile(bool bold, bool italic, const std::string &filePath, shared_ptr encryptionInfo); void merge(const FontEntry &fontEntry); bool operator == (const FontEntry &other) const; bool operator != (const FontEntry &other) const; public: - shared_ptr Normal; - shared_ptr Bold; - shared_ptr Italic; - shared_ptr BoldItalic; + shared_ptr Normal; + shared_ptr Bold; + shared_ptr Italic; + shared_ptr BoldItalic; }; class FontMap { public: - void append(const std::string &family, bool bold, bool italic, const std::string &path); + void append(const std::string &family, bool bold, bool italic, const std::string &path, shared_ptr encryptionInfo); void merge(const FontMap &fontMap); shared_ptr get(const std::string &family);