1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

pass to java font families list index instead of list

This commit is contained in:
Nikolay Pultsin 2014-03-30 20:39:23 +03:00
parent 37a421359a
commit 43bfe572f7
10 changed files with 44 additions and 41 deletions

View file

@ -33,7 +33,7 @@ BookModel::BookModel(const shared_ptr<Book> book, jobject javaModel) : myBook(bo
myJavaModel = AndroidUtil::getEnv()->NewGlobalRef(javaModel); myJavaModel = AndroidUtil::getEnv()->NewGlobalRef(javaModel);
const std::string cacheDirectory = Library::Instance().cacheDirectory(); const std::string cacheDirectory = Library::Instance().cacheDirectory();
myBookTextModel = new ZLTextPlainModel(std::string(), book->language(), 131072, cacheDirectory, "ncache"); myBookTextModel = new ZLTextPlainModel(std::string(), book->language(), 131072, cacheDirectory, "ncache", myFontManager);
myContentsTree = new ContentsTree(); myContentsTree = new ContentsTree();
/*shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().plugin(book->file(), false); /*shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().plugin(book->file(), false);
if (!plugin.isNull()) { if (!plugin.isNull()) {

View file

@ -55,7 +55,7 @@ void BookReader::setFootnoteTextModel(const std::string &id) {
if (myFootnotesAllocator.isNull()) { if (myFootnotesAllocator.isNull()) {
myFootnotesAllocator = new ZLCachedMemoryAllocator(8192, Library::Instance().cacheDirectory(), "footnotes"); myFootnotesAllocator = new ZLCachedMemoryAllocator(8192, Library::Instance().cacheDirectory(), "footnotes");
} }
myCurrentTextModel = new ZLTextPlainModel(id, myModel.myBookTextModel->language(), myFootnotesAllocator); myCurrentTextModel = new ZLTextPlainModel(id, myModel.myBookTextModel->language(), myFootnotesAllocator, myModel.myFontManager);
myModel.myFootnotes.insert(std::make_pair(id, myCurrentTextModel)); myModel.myFootnotes.insert(std::make_pair(id, myCurrentTextModel));
} }
} }

View file

@ -45,3 +45,14 @@ std::string FontManager::put(const std::string &family, shared_ptr<FontEntry> en
return std::string(); return std::string();
} }
int FontManager::familyListIndex(const std::vector<std::string> &familyList) {
std::vector<std::vector<std::string> >::const_iterator it =
std::find(myFamilyLists.begin(), myFamilyLists.end(), familyList);
if (it == myFamilyLists.end()) {
myFamilyLists.push_back(familyList);
return myFamilyLists.size() - 1;
} else {
return it - myFamilyLists.begin();
}
}

View file

@ -22,6 +22,7 @@
#include <string> #include <string>
#include <map> #include <map>
#include <vector>
#include <shared_ptr.h> #include <shared_ptr.h>
@ -31,9 +32,11 @@ class FontManager {
public: public:
std::string put(const std::string &family, shared_ptr<FontEntry> entry); std::string put(const std::string &family, shared_ptr<FontEntry> entry);
int familyListIndex(const std::vector<std::string> &familyList);
private: private:
std::map<std::string,shared_ptr<FontEntry> > myMap; std::map<std::string,shared_ptr<FontEntry> > myMap;
std::vector<std::vector<std::string> > myFamilyLists;
}; };
#endif /* __FONTMANAGER_H__ */ #endif /* __FONTMANAGER_H__ */

View file

@ -27,6 +27,7 @@
#include <ZLUnicodeUtil.h> #include <ZLUnicodeUtil.h>
//#include <ZLStringUtil.h> //#include <ZLStringUtil.h>
#include <ZLLogger.h> #include <ZLLogger.h>
#include <FontManager.h>
#include "ZLTextModel.h" #include "ZLTextModel.h"
#include "ZLTextParagraph.h" #include "ZLTextParagraph.h"
@ -34,18 +35,20 @@
#include "ZLVideoEntry.h" #include "ZLVideoEntry.h"
ZLTextModel::ZLTextModel(const std::string &id, const std::string &language, const std::size_t rowSize, ZLTextModel::ZLTextModel(const std::string &id, const std::string &language, const std::size_t rowSize,
const std::string &directoryName, const std::string &fileExtension) : const std::string &directoryName, const std::string &fileExtension, FontManager &fManager) :
myId(id), myId(id),
myLanguage(language.empty() ? ZLibrary::Language() : language), myLanguage(language.empty() ? ZLibrary::Language() : language),
myAllocator(new ZLCachedMemoryAllocator(rowSize, directoryName, fileExtension)), myAllocator(new ZLCachedMemoryAllocator(rowSize, directoryName, fileExtension)),
myLastEntryStart(0) { myLastEntryStart(0),
myFontManager(fManager) {
} }
ZLTextModel::ZLTextModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator) : ZLTextModel::ZLTextModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager) :
myId(id), myId(id),
myLanguage(language.empty() ? ZLibrary::Language() : language), myLanguage(language.empty() ? ZLibrary::Language() : language),
myAllocator(allocator), myAllocator(allocator),
myLastEntryStart(0) { myLastEntryStart(0),
myFontManager(fManager) {
} }
ZLTextModel::~ZLTextModel() { ZLTextModel::~ZLTextModel() {
@ -135,12 +138,12 @@ void ZLTextModel::addParagraphInternal(ZLTextParagraph *paragraph) {
} }
ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, const std::size_t rowSize, ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, const std::size_t rowSize,
const std::string &directoryName, const std::string &fileExtension) : const std::string &directoryName, const std::string &fileExtension, FontManager &fManager) :
ZLTextModel(id, language, rowSize, directoryName, fileExtension) { ZLTextModel(id, language, rowSize, directoryName, fileExtension, fManager) {
} }
ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator) : ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager) :
ZLTextModel(id, language, allocator) { ZLTextModel(id, language, allocator, fManager) {
} }
void ZLTextPlainModel::createParagraph(ZLTextParagraph::Kind kind) { void ZLTextPlainModel::createParagraph(ZLTextParagraph::Kind kind) {
@ -251,15 +254,8 @@ void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry, const std::vector
if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE)) { if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE)) {
len += 2; len += 2;
} }
std::vector<ZLUnicodeUtil::Ucs2String> fontFamiliesUcs2;
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) { if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
len += 2; len += 2;
for (std::vector<std::string>::const_iterator it = fontFamilies.begin(); it != fontFamilies.end(); ++it) {
ZLUnicodeUtil::Ucs2String ucs2;
ZLUnicodeUtil::utf8ToUcs2(ucs2, *it);
len += 2 + ucs2.size() * 2;
fontFamiliesUcs2.push_back(ucs2);
}
} }
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) { if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) {
len += 2; len += 2;
@ -297,10 +293,7 @@ void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry, const std::vector
*address++ = 0; *address++ = 0;
} }
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) { if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
address = ZLCachedMemoryAllocator::writeUInt16(address, fontFamiliesUcs2.size()); address = ZLCachedMemoryAllocator::writeUInt16(address, myFontManager.familyListIndex(fontFamilies));
for (std::vector<ZLUnicodeUtil::Ucs2String>::const_iterator it = fontFamiliesUcs2.begin(); it != fontFamiliesUcs2.end(); ++it) {
address = ZLCachedMemoryAllocator::writeString(address, *it);
}
} }
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) { if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) {
*address++ = entry.mySupportedFontModifier; *address++ = entry.mySupportedFontModifier;

View file

@ -34,14 +34,15 @@
class ZLTextStyleEntry; class ZLTextStyleEntry;
class ZLVideoEntry; class ZLVideoEntry;
class FontManager;
class ZLTextModel { class ZLTextModel {
protected: protected:
ZLTextModel(const std::string &id, const std::string &language, const std::size_t rowSize, ZLTextModel(const std::string &id, const std::string &language, const std::size_t rowSize,
const std::string &directoryName, const std::string &fileExtension); const std::string &directoryName, const std::string &fileExtension, FontManager &fManager);
ZLTextModel(const std::string &id, const std::string &language, ZLTextModel(const std::string &id, const std::string &language,
shared_ptr<ZLCachedMemoryAllocator> allocator); shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager);
public: public:
virtual ~ZLTextModel(); virtual ~ZLTextModel();
@ -105,6 +106,8 @@ private:
std::vector<jint> myTextSizes; std::vector<jint> myTextSizes;
std::vector<jbyte> myParagraphKinds; std::vector<jbyte> myParagraphKinds;
FontManager &myFontManager;
private: private:
ZLTextModel(const ZLTextModel&); ZLTextModel(const ZLTextModel&);
const ZLTextModel &operator = (const ZLTextModel&); const ZLTextModel &operator = (const ZLTextModel&);
@ -114,9 +117,9 @@ class ZLTextPlainModel : public ZLTextModel {
public: public:
ZLTextPlainModel(const std::string &id, const std::string &language, const std::size_t rowSize, ZLTextPlainModel(const std::string &id, const std::string &language, const std::size_t rowSize,
const std::string &directoryName, const std::string &fileExtension); const std::string &directoryName, const std::string &fileExtension, FontManager &fManager);
ZLTextPlainModel(const std::string &id, const std::string &language, ZLTextPlainModel(const std::string &id, const std::string &language,
shared_ptr<ZLCachedMemoryAllocator> allocator); shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager);
void createParagraph(ZLTextParagraph::Kind kind); void createParagraph(ZLTextParagraph::Kind kind);
}; };

View file

@ -183,11 +183,11 @@ void JavaInputStream::seek(int offset, bool absoluteOffset) {
return; return;
} }
JNIEnv *env = AndroidUtil::getEnv(); JNIEnv *env = AndroidUtil::getEnv();
if (myNeedRepositionToStart || offset < myOffset) { if (myNeedRepositionToStart || offset < (int)myOffset) {
rewind(env); rewind(env);
myNeedRepositionToStart = false; myNeedRepositionToStart = false;
} }
if (offset > myOffset) { if (offset > (int)myOffset) {
skip(env, offset - myOffset); skip(env, offset - myOffset);
} }
} }

View file

@ -213,14 +213,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
entry.setAlignmentType((byte)(value & 0xFF)); entry.setAlignmentType((byte)(value & 0xFF));
} }
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_FAMILY)) { if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_FAMILY)) {
final short listLength = (short)data[dataOffset++]; entry.setFontFamiliesIndex((short)data[dataOffset++]);
final ArrayList<String> families = new ArrayList<String>(listLength);
for (short i = 0; i < listLength; ++i) {
final short familyLength = (short)data[dataOffset++];
families.add(new String(data, dataOffset, familyLength));
dataOffset += familyLength;
}
entry.setFontFamilies(families);
} }
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_STYLE_MODIFIER)) { if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_STYLE_MODIFIER)) {
final short value = (short)data[dataOffset++]; final short value = (short)data[dataOffset++];

View file

@ -71,7 +71,7 @@ public abstract class ZLTextStyleEntry {
private Length[] myLengths = new Length[Feature.NUMBER_OF_LENGTHS]; private Length[] myLengths = new Length[Feature.NUMBER_OF_LENGTHS];
private byte myAlignmentType; private byte myAlignmentType;
private List<String> myFontFamilies; private int myFontFamiliesIndex;
private byte mySupportedFontModifiers; private byte mySupportedFontModifiers;
private byte myFontModifiers; private byte myFontModifiers;
@ -134,13 +134,13 @@ public abstract class ZLTextStyleEntry {
return myAlignmentType; return myAlignmentType;
} }
final void setFontFamilies(List<String> fontFamilies) { final void setFontFamiliesIndex(int fontFamiliesIndex) {
myFeatureMask |= 1 << Feature.FONT_FAMILY; myFeatureMask |= 1 << Feature.FONT_FAMILY;
myFontFamilies = new ArrayList<String>(fontFamilies); myFontFamiliesIndex = fontFamiliesIndex;
} }
public final List<String> getFontFamilies() { public final int getFontFamiliesIndex() {
return myFontFamilies; return myFontFamiliesIndex;
} }
final void setFontModifiers(byte supported, byte values) { final void setFontModifiers(byte supported, byte values) {

View file

@ -35,7 +35,7 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
@Override @Override
protected String getFontFamilyInternal() { protected String getFontFamilyInternal() {
if (myEntry.isFeatureSupported(FONT_FAMILY)) { if (myEntry.isFeatureSupported(FONT_FAMILY)) {
System.err.println(myEntry.getFontFamilies()); System.err.println("FONT FAMILIES INDEX = " + myEntry.getFontFamiliesIndex());
// TODO: implement // TODO: implement
} }
return Parent.getFontFamily(); return Parent.getFontFamily();