1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +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);
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();
/*shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().plugin(book->file(), false);
if (!plugin.isNull()) {

View file

@ -55,7 +55,7 @@ void BookReader::setFootnoteTextModel(const std::string &id) {
if (myFootnotesAllocator.isNull()) {
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));
}
}

View file

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

View file

@ -27,6 +27,7 @@
#include <ZLUnicodeUtil.h>
//#include <ZLStringUtil.h>
#include <ZLLogger.h>
#include <FontManager.h>
#include "ZLTextModel.h"
#include "ZLTextParagraph.h"
@ -34,18 +35,20 @@
#include "ZLVideoEntry.h"
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),
myLanguage(language.empty() ? ZLibrary::Language() : language),
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),
myLanguage(language.empty() ? ZLibrary::Language() : language),
myAllocator(allocator),
myLastEntryStart(0) {
myLastEntryStart(0),
myFontManager(fManager) {
}
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,
const std::string &directoryName, const std::string &fileExtension) :
ZLTextModel(id, language, rowSize, directoryName, fileExtension) {
const std::string &directoryName, const std::string &fileExtension, FontManager &fManager) :
ZLTextModel(id, language, rowSize, directoryName, fileExtension, fManager) {
}
ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator) :
ZLTextModel(id, language, allocator) {
ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager) :
ZLTextModel(id, language, allocator, fManager) {
}
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)) {
len += 2;
}
std::vector<ZLUnicodeUtil::Ucs2String> fontFamiliesUcs2;
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
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)) {
len += 2;
@ -297,10 +293,7 @@ void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry, const std::vector
*address++ = 0;
}
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
address = ZLCachedMemoryAllocator::writeUInt16(address, fontFamiliesUcs2.size());
for (std::vector<ZLUnicodeUtil::Ucs2String>::const_iterator it = fontFamiliesUcs2.begin(); it != fontFamiliesUcs2.end(); ++it) {
address = ZLCachedMemoryAllocator::writeString(address, *it);
}
address = ZLCachedMemoryAllocator::writeUInt16(address, myFontManager.familyListIndex(fontFamilies));
}
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) {
*address++ = entry.mySupportedFontModifier;

View file

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

View file

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

View file

@ -213,14 +213,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
entry.setAlignmentType((byte)(value & 0xFF));
}
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_FAMILY)) {
final short listLength = (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);
entry.setFontFamiliesIndex((short)data[dataOffset++]);
}
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_STYLE_MODIFIER)) {
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 byte myAlignmentType;
private List<String> myFontFamilies;
private int myFontFamiliesIndex;
private byte mySupportedFontModifiers;
private byte myFontModifiers;
@ -134,13 +134,13 @@ public abstract class ZLTextStyleEntry {
return myAlignmentType;
}
final void setFontFamilies(List<String> fontFamilies) {
final void setFontFamiliesIndex(int fontFamiliesIndex) {
myFeatureMask |= 1 << Feature.FONT_FAMILY;
myFontFamilies = new ArrayList<String>(fontFamilies);
myFontFamiliesIndex = fontFamiliesIndex;
}
public final List<String> getFontFamilies() {
return myFontFamilies;
public final int getFontFamiliesIndex() {
return myFontFamiliesIndex;
}
final void setFontModifiers(byte supported, byte values) {

View file

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