mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
store encryption info in FontEntry as well as file path
This commit is contained in:
parent
d7af2c58d5
commit
48cdfee8a2
7 changed files with 59 additions and 33 deletions
|
@ -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"
|
||||
JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readModelNative(JNIEnv* env, jobject thiz, jobject javaModel) {
|
||||
shared_ptr<FormatPlugin> 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
|
||||
|
|
|
@ -240,7 +240,7 @@ shared_ptr<ZLTextStyleEntry> StyleSheetSingleStyleParser::parseSingleEntry(const
|
|||
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) {
|
||||
|
@ -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) {
|
||||
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> 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) {
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ public:
|
|||
class StyleSheetMultiStyleParser : public StyleSheetParser {
|
||||
|
||||
protected:
|
||||
StyleSheetMultiStyleParser(const std::string &pathPrefix, shared_ptr<FontMap> myFontMap);
|
||||
StyleSheetMultiStyleParser(const std::string &pathPrefix, shared_ptr<FontMap> fontMap, shared_ptr<EncryptionMap> 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<FontMap> myFontMap;
|
||||
shared_ptr<EncryptionMap> myEncryptionMap;
|
||||
};
|
||||
|
||||
class StyleSheetTableParser : public StyleSheetMultiStyleParser {
|
||||
|
||||
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:
|
||||
void store(const std::string &tag, const std::string &aClass, const StyleSheetTable::AttributeMap &map);
|
||||
|
@ -133,7 +134,6 @@ private:
|
|||
private:
|
||||
std::list<shared_ptr<Entry> > myEntries;
|
||||
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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<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 (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<std::string> str0, shared_ptr<std::string> str1) {
|
||||
return str0.isNull() ? str1.isNull() : (!str1.isNull() && *str0 == *str1);
|
||||
static bool compareFileInfos(shared_ptr<FileInfo> info0, shared_ptr<FileInfo> 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<FileEncryptionInfo> encryptionInfo) {
|
||||
const ZLFile fontFile(path);
|
||||
shared_ptr<FontEntry> 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) {
|
||||
|
|
|
@ -25,26 +25,38 @@
|
|||
|
||||
#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 {
|
||||
|
||||
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);
|
||||
|
||||
bool operator == (const FontEntry &other) const;
|
||||
bool operator != (const FontEntry &other) const;
|
||||
|
||||
public:
|
||||
shared_ptr<std::string> Normal;
|
||||
shared_ptr<std::string> Bold;
|
||||
shared_ptr<std::string> Italic;
|
||||
shared_ptr<std::string> BoldItalic;
|
||||
shared_ptr<FileInfo> Normal;
|
||||
shared_ptr<FileInfo> Bold;
|
||||
shared_ptr<FileInfo> Italic;
|
||||
shared_ptr<FileInfo> 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<FileEncryptionInfo> encryptionInfo);
|
||||
void merge(const FontMap &fontMap);
|
||||
shared_ptr<FontEntry> get(const std::string &family);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue