1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 02:09:35 +02:00

store encryption info in FontEntry as well as file path

This commit is contained in:
Nikolay Pultsin 2014-04-07 20:18:43 +01:00
parent d7af2c58d5
commit 48cdfee8a2
7 changed files with 59 additions and 33 deletions

View file

@ -276,6 +276,10 @@ static void initTOC(JNIEnv *env, jobject javaModel, const ContentsTree &tree) {
} }
} }
static jstring createJavaString(JNIEnv *env, shared_ptr<FileInfo> info) {
return info.isNull() ? 0 : AndroidUtil::createJavaString(env, info->Path);
}
extern "C" extern "C"
JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readModelNative(JNIEnv* env, jobject thiz, jobject javaModel) { JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readModelNative(JNIEnv* env, jobject thiz, jobject javaModel) {
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz); shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
@ -345,10 +349,10 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
continue; continue;
} }
jstring family = AndroidUtil::createJavaString(env, it->first); jstring family = AndroidUtil::createJavaString(env, it->first);
jstring normal = AndroidUtil::createJavaString(env, it->second->Normal); jstring normal = createJavaString(env, it->second->Normal);
jstring bold = AndroidUtil::createJavaString(env, it->second->Bold); jstring bold = createJavaString(env, it->second->Bold);
jstring italic = AndroidUtil::createJavaString(env, it->second->Italic); jstring italic = createJavaString(env, it->second->Italic);
jstring boldItalic = AndroidUtil::createJavaString(env, it->second->BoldItalic); jstring boldItalic = createJavaString(env, it->second->BoldItalic);
AndroidUtil::Method_NativeBookModel_registerFontEntry->call( AndroidUtil::Method_NativeBookModel_registerFontEntry->call(
javaModel, family, normal, bold, italic, boldItalic javaModel, family, normal, bold, italic, boldItalic

View file

@ -240,7 +240,7 @@ shared_ptr<ZLTextStyleEntry> StyleSheetSingleStyleParser::parseSingleEntry(const
return control; return control;
} }
StyleSheetMultiStyleParser::StyleSheetMultiStyleParser(const std::string &pathPrefix, shared_ptr<FontMap> fontMap) : StyleSheetParser(pathPrefix), myFontMap(fontMap.isNull() ? new FontMap() : fontMap) { StyleSheetMultiStyleParser::StyleSheetMultiStyleParser(const std::string &pathPrefix, shared_ptr<FontMap> fontMap, shared_ptr<EncryptionMap> encryptionMap) : StyleSheetParser(pathPrefix), myFontMap(fontMap.isNull() ? new FontMap() : fontMap), myEncryptionMap(encryptionMap) {
} }
void StyleSheetMultiStyleParser::storeData(const std::string &selector, const StyleSheetTable::AttributeMap &map) { 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<std::string>::const_iterator jt = ids.begin(); jt != ids.end(); ++jt) { for (std::vector<std::string>::const_iterator jt = ids.begin(); jt != ids.end(); ++jt) {
if (ZLStringUtil::stringStartsWith(*jt, "url(") && if (ZLStringUtil::stringStartsWith(*jt, "url(") &&
ZLStringUtil::stringEndsWith(*jt, ")")) { ZLStringUtil::stringEndsWith(*jt, ")")) {
path = url2FullPath(*jt); path = ZLFile(url2FullPath(*jt)).path();
break; 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 weight = value(attributes, "font-weight");
const std::string style = value(attributes, "font-style"); 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> fontMap) : StyleSheetMultiStyleParser(pathPrefix, fontMap), myStyleTable(styleTable) { StyleSheetTableParser::StyleSheetTableParser(const std::string &pathPrefix, StyleSheetTable &styleTable, shared_ptr<FontMap> fontMap, shared_ptr<EncryptionMap> encryptionMap) : StyleSheetMultiStyleParser(pathPrefix, fontMap, encryptionMap), myStyleTable(styleTable) {
} }
void StyleSheetTableParser::store(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map) { void StyleSheetTableParser::store(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map) {
myStyleTable.addMap(tag, aClass, map); myStyleTable.addMap(tag, aClass, map);
} }
StyleSheetParserWithCache::StyleSheetParserWithCache(const ZLFile &file, const std::string &pathPrefix, shared_ptr<FontMap> fontMap, shared_ptr<EncryptionMap> encryptionMap) : StyleSheetMultiStyleParser(pathPrefix, fontMap), myEncryptionMap(encryptionMap) { StyleSheetParserWithCache::StyleSheetParserWithCache(const ZLFile &file, const std::string &pathPrefix, shared_ptr<FontMap> fontMap, shared_ptr<EncryptionMap> encryptionMap) : StyleSheetMultiStyleParser(pathPrefix, fontMap, encryptionMap) {
myProcessedFiles.insert(file.path()); myProcessedFiles.insert(file.path());
} }

View file

@ -86,7 +86,7 @@ public:
class StyleSheetMultiStyleParser : public StyleSheetParser { class StyleSheetMultiStyleParser : public StyleSheetParser {
protected: protected:
StyleSheetMultiStyleParser(const std::string &pathPrefix, shared_ptr<FontMap> myFontMap); StyleSheetMultiStyleParser(const std::string &pathPrefix, shared_ptr<FontMap> fontMap, shared_ptr<EncryptionMap> encryptionMap);
protected: protected:
virtual void store(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map) = 0; virtual void store(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map) = 0;
@ -97,12 +97,13 @@ private:
protected: protected:
shared_ptr<FontMap> myFontMap; shared_ptr<FontMap> myFontMap;
shared_ptr<EncryptionMap> myEncryptionMap;
}; };
class StyleSheetTableParser : public StyleSheetMultiStyleParser { class StyleSheetTableParser : public StyleSheetMultiStyleParser {
public: public:
StyleSheetTableParser(const std::string &pathPrexix, StyleSheetTable &styleTable, shared_ptr<FontMap> fontMap); StyleSheetTableParser(const std::string &pathPrexix, StyleSheetTable &styleTable, shared_ptr<FontMap> fontMap, shared_ptr<EncryptionMap> encryptionMap);
private: private:
void store(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map); void store(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map);
@ -133,7 +134,6 @@ private:
private: private:
std::list<shared_ptr<Entry> > myEntries; std::list<shared_ptr<Entry> > myEntries;
std::set<std::string> myProcessedFiles; std::set<std::string> myProcessedFiles;
shared_ptr<EncryptionMap> myEncryptionMap;
}; };
inline StyleSheetParserWithCache::Entry::Entry(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map) : Tag(tag), Class(aClass), Map(map) { inline StyleSheetParserWithCache::Entry::Entry(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map) : Tag(tag), Class(aClass), Map(map) {

View file

@ -274,7 +274,7 @@ HtmlStyleTagAction::HtmlStyleTagAction(HtmlBookReader &reader) : HtmlTagAction(r
} }
void HtmlStyleTagAction::run(const HtmlReader::HtmlTag &tag) { 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) { if (!tag.Start) {
myReader.myStyleSheetTable.dump(); myReader.myStyleSheetTable.dump();

View file

@ -229,7 +229,7 @@ void XHTMLTagStyleAction::doAtStart(XHTMLReader &reader, const char **xmlattribu
if (reader.myReadState == XHTML_READ_NOTHING) { if (reader.myReadState == XHTML_READ_NOTHING) {
reader.myReadState = XHTML_READ_STYLE; 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"); ZLLogger::Instance().println("CSS", "parsing style tag content");
} }
} }

View file

@ -21,18 +21,22 @@
#include "FontMap.h" #include "FontMap.h"
void FontEntry::addFile(bool bold, bool italic, const std::string &filePath) { FileInfo::FileInfo(const std::string &path, shared_ptr<FileEncryptionInfo> info) : Path(path), EncryptionInfo(info) {
}
void FontEntry::addFile(bool bold, bool italic, const std::string &filePath, shared_ptr<FileEncryptionInfo> encryptionInfo) {
shared_ptr<FileInfo> fileInfo = new FileInfo(filePath, encryptionInfo);
if (bold) { if (bold) {
if (italic) { if (italic) {
BoldItalic = new std::string(filePath); BoldItalic = fileInfo;
} else { } else {
Bold = new std::string(filePath); Bold = fileInfo;
} }
} else { } else {
if (italic) { if (italic) {
Italic = new std::string(filePath); Italic = fileInfo;
} else { } else {
Normal = new std::string(filePath); Normal = fileInfo;
} }
} }
} }
@ -52,30 +56,30 @@ void FontEntry::merge(const FontEntry &fontEntry) {
} }
} }
static bool compareStringPtrs(shared_ptr<std::string> str0, shared_ptr<std::string> str1) { static bool compareFileInfos(shared_ptr<FileInfo> info0, shared_ptr<FileInfo> info1) {
return str0.isNull() ? str1.isNull() : (!str1.isNull() && *str0 == *str1); return info0.isNull() ? info1.isNull() : (!info1.isNull() && info0->Path == info1->Path);
} }
bool FontEntry::operator == (const FontEntry &other) const { bool FontEntry::operator == (const FontEntry &other) const {
return return
compareStringPtrs(Normal, other.Normal) && compareFileInfos(Normal, other.Normal) &&
compareStringPtrs(Bold, other.Bold) && compareFileInfos(Bold, other.Bold) &&
compareStringPtrs(Italic, other.Italic) && compareFileInfos(Italic, other.Italic) &&
compareStringPtrs(BoldItalic, other.BoldItalic); compareFileInfos(BoldItalic, other.BoldItalic);
} }
bool FontEntry::operator != (const FontEntry &other) const { bool FontEntry::operator != (const FontEntry &other) const {
return !operator ==(other); 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<FileEncryptionInfo> encryptionInfo) {
const ZLFile fontFile(path); const ZLFile fontFile(path);
shared_ptr<FontEntry> entry = myMap[family]; shared_ptr<FontEntry> entry = myMap[family];
if (entry.isNull()) { if (entry.isNull()) {
entry = new FontEntry(); entry = new FontEntry();
myMap[family] = entry; myMap[family] = entry;
} }
entry->addFile(bold, italic, fontFile.path()); entry->addFile(bold, italic, fontFile.path(), encryptionInfo);
} }
void FontMap::merge(const FontMap &fontMap) { void FontMap::merge(const FontMap &fontMap) {

View file

@ -25,26 +25,38 @@
#include <shared_ptr.h> #include <shared_ptr.h>
#include <FileEncryptionInfo.h>
class FileInfo {
public:
FileInfo(const std::string &path, shared_ptr<FileEncryptionInfo> info);
public:
const std::string Path;
shared_ptr<FileEncryptionInfo> EncryptionInfo;
};
class FontEntry { class FontEntry {
public: public:
void addFile(bool bold, bool italic, const std::string &filePath); void addFile(bool bold, bool italic, const std::string &filePath, shared_ptr<FileEncryptionInfo> encryptionInfo);
void merge(const FontEntry &fontEntry); void merge(const FontEntry &fontEntry);
bool operator == (const FontEntry &other) const; bool operator == (const FontEntry &other) const;
bool operator != (const FontEntry &other) const; bool operator != (const FontEntry &other) const;
public: public:
shared_ptr<std::string> Normal; shared_ptr<FileInfo> Normal;
shared_ptr<std::string> Bold; shared_ptr<FileInfo> Bold;
shared_ptr<std::string> Italic; shared_ptr<FileInfo> Italic;
shared_ptr<std::string> BoldItalic; shared_ptr<FileInfo> BoldItalic;
}; };
class FontMap { class FontMap {
public: 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<FileEncryptionInfo> encryptionInfo);
void merge(const FontMap &fontMap); void merge(const FontMap &fontMap);
shared_ptr<FontEntry> get(const std::string &family); shared_ptr<FontEntry> get(const std::string &family);