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

font families list passed to java style

This commit is contained in:
Nikolay Pultsin 2014-03-31 15:19:40 +01:00
parent 7ca30d0c9e
commit fcd2640be7
17 changed files with 78 additions and 29 deletions

View file

@ -314,6 +314,18 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
} }
// TODO: synchronize FontManager // TODO: synchronize FontManager
const std::vector<std::vector<std::string> > familyLists = model->fontManager().familyLists();
for (std::vector<std::vector<std::string> >::const_iterator it = familyLists.begin(); it != familyLists.end(); ++it) {
const std::vector<std::string> &lst = *it;
jobjectArray jList = env->NewObjectArray(lst.size(), AndroidUtil::Class_java_lang_String.j(), 0);
for (std::size_t i = 0; i < lst.size(); ++i) {
jstring jString = AndroidUtil::createJavaString(env, lst[i]);
env->SetObjectArrayElement(jList, i, jString);
env->DeleteLocalRef(jString);
}
AndroidUtil::Method_NativeBookModel_registerFontFamilyList->call(javaModel, jList);
env->DeleteLocalRef(jList);
}
return 0; return 0;
} }

View file

@ -82,6 +82,8 @@ public:
const shared_ptr<Book> book() const; const shared_ptr<Book> book() const;
const FontManager &fontManager() const;
bool flush(); bool flush();
private: private:
@ -101,6 +103,7 @@ inline shared_ptr<ZLTextModel> BookModel::bookTextModel() const { return myBookT
inline shared_ptr<ContentsTree> BookModel::contentsTree() const { return myContentsTree; } inline shared_ptr<ContentsTree> BookModel::contentsTree() const { return myContentsTree; }
inline const std::map<std::string,shared_ptr<ZLTextModel> > &BookModel::footnotes() const { return myFootnotes; } inline const std::map<std::string,shared_ptr<ZLTextModel> > &BookModel::footnotes() const { return myFootnotes; }
inline const std::map<std::string,BookModel::Label> &BookModel::internalHyperlinks() const { return myInternalHyperlinks; } inline const std::map<std::string,BookModel::Label> &BookModel::internalHyperlinks() const { return myInternalHyperlinks; }
inline const FontManager &BookModel::fontManager() const { return myFontManager; }
inline ContentsTree::ContentsTree() : myReference(-1) {} inline ContentsTree::ContentsTree() : myReference(-1) {}
inline ContentsTree::ContentsTree(ContentsTree &parent, int reference) : myReference(reference) { inline ContentsTree::ContentsTree(ContentsTree &parent, int reference) : myReference(reference) {

View file

@ -123,6 +123,7 @@ shared_ptr<ObjectMethod> AndroidUtil::Method_NativeBookModel_createTextModel;
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_setBookTextModel; shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_setBookTextModel;
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_setFootnoteModel; shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_setFootnoteModel;
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_addImage; shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_addImage;
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_registerFontFamilyList;
//shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_BookReadingException_throwForFile; //shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_BookReadingException_throwForFile;
@ -204,6 +205,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
Method_NativeBookModel_setBookTextModel = new VoidMethod(Class_NativeBookModel, "setBookTextModel", "(Lorg/geometerplus/zlibrary/text/model/ZLTextModel;)"); Method_NativeBookModel_setBookTextModel = new VoidMethod(Class_NativeBookModel, "setBookTextModel", "(Lorg/geometerplus/zlibrary/text/model/ZLTextModel;)");
Method_NativeBookModel_setFootnoteModel = new VoidMethod(Class_NativeBookModel, "setFootnoteModel", "(Lorg/geometerplus/zlibrary/text/model/ZLTextModel;)"); Method_NativeBookModel_setFootnoteModel = new VoidMethod(Class_NativeBookModel, "setFootnoteModel", "(Lorg/geometerplus/zlibrary/text/model/ZLTextModel;)");
Method_NativeBookModel_addImage = new VoidMethod(Class_NativeBookModel, "addImage", "(Ljava/lang/String;Lorg/geometerplus/zlibrary/core/image/ZLImage;)"); Method_NativeBookModel_addImage = new VoidMethod(Class_NativeBookModel, "addImage", "(Ljava/lang/String;Lorg/geometerplus/zlibrary/core/image/ZLImage;)");
Method_NativeBookModel_registerFontFamilyList = new VoidMethod(Class_NativeBookModel, "registerFontFamilyList", "([Ljava/lang/String;)");
/* /*
Class_BookReadingException = new JavaClass(env, "org/geometerplus/fbreader/bookmodel/BookReadingException"); Class_BookReadingException = new JavaClass(env, "org/geometerplus/fbreader/bookmodel/BookReadingException");

View file

@ -145,6 +145,7 @@ public:
static shared_ptr<VoidMethod> Method_NativeBookModel_setBookTextModel; static shared_ptr<VoidMethod> Method_NativeBookModel_setBookTextModel;
static shared_ptr<VoidMethod> Method_NativeBookModel_setFootnoteModel; static shared_ptr<VoidMethod> Method_NativeBookModel_setFootnoteModel;
static shared_ptr<VoidMethod> Method_NativeBookModel_addImage; static shared_ptr<VoidMethod> Method_NativeBookModel_addImage;
static shared_ptr<VoidMethod> Method_NativeBookModel_registerFontFamilyList;
//static shared_ptr<StaticObjectMethod> StaticMethod_BookReadingException_throwForFile; //static shared_ptr<StaticObjectMethod> StaticMethod_BookReadingException_throwForFile;

View file

@ -56,3 +56,7 @@ int FontManager::familyListIndex(const std::vector<std::string> &familyList) {
return it - myFamilyLists.begin(); return it - myFamilyLists.begin();
} }
} }
const std::vector<std::vector<std::string> > &FontManager::familyLists() const {
return myFamilyLists;
}

View file

@ -33,6 +33,7 @@ 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); int familyListIndex(const std::vector<std::string> &familyList);
const std::vector<std::vector<std::string> > &familyLists() const;
private: private:
std::map<std::string,shared_ptr<FontEntry> > myMap; std::map<std::string,shared_ptr<FontEntry> > myMap;

View file

@ -35,20 +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, FontManager &fManager) : const std::string &directoryName, const std::string &fileExtension, FontManager &fontManager) :
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) { myFontManager(fontManager) {
} }
ZLTextModel::ZLTextModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager) : ZLTextModel::ZLTextModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fontManager) :
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) { myFontManager(fontManager) {
} }
ZLTextModel::~ZLTextModel() { ZLTextModel::~ZLTextModel() {
@ -138,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, FontManager &fManager) : const std::string &directoryName, const std::string &fileExtension, FontManager &fontManager) :
ZLTextModel(id, language, rowSize, directoryName, fileExtension, fManager) { ZLTextModel(id, language, rowSize, directoryName, fileExtension, fontManager) {
} }
ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager) : ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fontManager) :
ZLTextModel(id, language, allocator, fManager) { ZLTextModel(id, language, allocator, fontManager) {
} }
void ZLTextPlainModel::createParagraph(ZLTextParagraph::Kind kind) { void ZLTextPlainModel::createParagraph(ZLTextParagraph::Kind kind) {

View file

@ -40,9 +40,9 @@ 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, FontManager &fManager); const std::string &directoryName, const std::string &fileExtension, FontManager &fontManager);
ZLTextModel(const std::string &id, const std::string &language, ZLTextModel(const std::string &id, const std::string &language,
shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager); shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fontManager);
public: public:
virtual ~ZLTextModel(); virtual ~ZLTextModel();
@ -117,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, FontManager &fManager); const std::string &directoryName, const std::string &fileExtension, FontManager &fontManager);
ZLTextPlainModel(const std::string &id, const std::string &language, ZLTextPlainModel(const std::string &id, const std::string &language,
shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager); shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fontManager);
void createParagraph(ZLTextParagraph::Kind kind); void createParagraph(ZLTextParagraph::Kind kind);
}; };

View file

@ -19,9 +19,11 @@
package org.geometerplus.fbreader.bookmodel; package org.geometerplus.fbreader.bookmodel;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.geometerplus.zlibrary.text.model.*; import org.geometerplus.zlibrary.text.model.*;
import org.geometerplus.zlibrary.text.fonts.FontManager;
import org.geometerplus.fbreader.book.Book; import org.geometerplus.fbreader.book.Book;
import org.geometerplus.fbreader.formats.FormatPlugin; import org.geometerplus.fbreader.formats.FormatPlugin;
@ -52,6 +54,7 @@ public abstract class BookModel {
public final Book Book; public final Book Book;
public final TOCTree TOCTree = new TOCTree(); public final TOCTree TOCTree = new TOCTree();
public final FontManager FontManager = new FontManager();
public static final class Label { public static final class Label {
public final String ModelId; public final String ModelId;
@ -93,4 +96,8 @@ public abstract class BookModel {
} }
return label; return label;
} }
public void registerFontFamilyList(String[] families) {
FontManager.index(Arrays.asList(families));
}
} }

View file

@ -30,7 +30,7 @@ public class JavaBookModel extends BookModelImpl {
JavaBookModel(Book book) { JavaBookModel(Book book) {
super(book); super(book);
myInternalHyperlinks = new CachedCharStorage(32768, Paths.cacheDirectory(), "links"); myInternalHyperlinks = new CachedCharStorage(32768, Paths.cacheDirectory(), "links");
BookTextModel = new ZLTextWritablePlainModel(null, book.getLanguage(), 1024, 65536, Paths.cacheDirectory(), "cache", myImageMap); BookTextModel = new ZLTextWritablePlainModel(null, book.getLanguage(), 1024, 65536, Paths.cacheDirectory(), "cache", myImageMap, FontManager);
} }
@Override @Override
@ -42,7 +42,7 @@ public class JavaBookModel extends BookModelImpl {
public ZLTextModel getFootnoteModel(String id) { public ZLTextModel getFootnoteModel(String id) {
ZLTextModel model = myFootnotes.get(id); ZLTextModel model = myFootnotes.get(id);
if (model == null) { if (model == null) {
model = new ZLTextWritablePlainModel(id, Book.getLanguage(), 8, 512, Paths.cacheDirectory(), "cache" + myFootnotes.size(), myImageMap); model = new ZLTextWritablePlainModel(id, Book.getLanguage(), 8, 512, Paths.cacheDirectory(), "cache" + myFootnotes.size(), myImageMap, FontManager);
myFootnotes.put(id, model); myFootnotes.put(id, model);
} }
return model; return model;

View file

@ -59,7 +59,7 @@ public class NativeBookModel extends BookModelImpl {
id, language, paragraphsNumber, id, language, paragraphsNumber,
entryIndices, entryOffsets, entryIndices, entryOffsets,
paragraphLenghts, textSizes, paragraphKinds, paragraphLenghts, textSizes, paragraphKinds,
directoryName, fileExtension, blocksNumber, myImageMap directoryName, fileExtension, blocksNumber, myImageMap, FontManager
); );
} }

View file

@ -19,8 +19,7 @@
package org.geometerplus.zlibrary.text.fonts; package org.geometerplus.zlibrary.text.fonts;
import java.util.ArrayList; import java.util.*;
import java.util.List;
public class FontManager { public class FontManager {
private final ArrayList<List<String>> myFamilyLists = new ArrayList<List<String>>(); private final ArrayList<List<String>> myFamilyLists = new ArrayList<List<String>>();
@ -34,4 +33,8 @@ public class FontManager {
myFamilyLists.add(new ArrayList<String>(families)); myFamilyLists.add(new ArrayList<String>(families));
return myFamilyLists.size() - 1; return myFamilyLists.size() - 1;
} }
public synchronized List<String> getFamilyList(int index) {
return index < myFamilyLists.size() ? myFamilyLists.get(index) : Collections.<String>emptyList();
}
} }

View file

@ -23,6 +23,8 @@ import java.util.Map;
import org.geometerplus.zlibrary.core.image.ZLImage; import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.text.fonts.FontManager;
public class ZLTextNativeModel extends ZLTextPlainModel { public class ZLTextNativeModel extends ZLTextPlainModel {
public ZLTextNativeModel( public ZLTextNativeModel(
String id, String language, int paragraphsNumber, String id, String language, int paragraphsNumber,
@ -30,13 +32,15 @@ public class ZLTextNativeModel extends ZLTextPlainModel {
int[] paragraphLengths, int[] textSizes, int[] paragraphLengths, int[] textSizes,
byte[] paragraphKinds, byte[] paragraphKinds,
String directoryName, String fileExtension, int blocksNumber, String directoryName, String fileExtension, int blocksNumber,
Map<String,ZLImage> imageMap Map<String,ZLImage> imageMap,
FontManager fontManager
) { ) {
super( super(
id, language, id, language,
entryIndices, entryOffsets, paragraphLengths, textSizes, paragraphKinds, entryIndices, entryOffsets, paragraphLengths, textSizes, paragraphKinds,
new CachedCharStorageRO(directoryName, fileExtension, blocksNumber), new CachedCharStorageRO(directoryName, fileExtension, blocksNumber),
imageMap imageMap,
fontManager
); );
myParagraphsNumber = paragraphsNumber; myParagraphsNumber = paragraphsNumber;
} }

View file

@ -23,6 +23,7 @@ import java.util.*;
import org.geometerplus.zlibrary.core.image.ZLImage; import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.core.util.*; import org.geometerplus.zlibrary.core.util.*;
import org.geometerplus.zlibrary.text.fonts.FontManager;
public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature { public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
private final String myId; private final String myId;
@ -41,6 +42,8 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
private ArrayList<ZLTextMark> myMarks; private ArrayList<ZLTextMark> myMarks;
private final FontManager myFontManager;
final class EntryIteratorImpl implements ZLTextParagraph.EntryIterator { final class EntryIteratorImpl implements ZLTextParagraph.EntryIterator {
private int myCounter; private int myCounter;
private int myLength; private int myLength;
@ -213,7 +216,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)) {
entry.setFontFamiliesIndex((short)data[dataOffset++]); entry.setFontFamilies(myFontManager, (short)data[dataOffset++]);
} }
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++];
@ -261,7 +264,8 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
int[] textSizes, int[] textSizes,
byte[] paragraphKinds, byte[] paragraphKinds,
CharStorage storage, CharStorage storage,
Map<String,ZLImage> imageMap Map<String,ZLImage> imageMap,
FontManager fontManager
) { ) {
myId = id; myId = id;
myLanguage = language; myLanguage = language;
@ -272,6 +276,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
myParagraphKinds = paragraphKinds; myParagraphKinds = paragraphKinds;
myStorage = storage; myStorage = storage;
myImageMap = imageMap; myImageMap = imageMap;
myFontManager = fontManager;
} }
public final String getId() { public final String getId() {

View file

@ -24,6 +24,8 @@ import java.util.List;
import org.geometerplus.zlibrary.core.util.ZLBoolean3; import org.geometerplus.zlibrary.core.util.ZLBoolean3;
import org.geometerplus.zlibrary.text.fonts.FontManager;
public abstract class ZLTextStyleEntry { public abstract class ZLTextStyleEntry {
public interface Feature { public interface Feature {
int LENGTH_LEFT_INDENT = 0; int LENGTH_LEFT_INDENT = 0;
@ -71,7 +73,8 @@ 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 int myFontFamiliesIndex; private FontManager myFontManager;
private List<String> myFontFamilies;
private byte mySupportedFontModifiers; private byte mySupportedFontModifiers;
private byte myFontModifiers; private byte myFontModifiers;
@ -134,13 +137,14 @@ public abstract class ZLTextStyleEntry {
return myAlignmentType; return myAlignmentType;
} }
final void setFontFamiliesIndex(int fontFamiliesIndex) { final void setFontFamilies(FontManager fontManager, int fontFamiliesIndex) {
myFeatureMask |= 1 << Feature.FONT_FAMILY; myFeatureMask |= 1 << Feature.FONT_FAMILY;
myFontFamiliesIndex = fontFamiliesIndex; myFontManager = fontManager;
myFontFamilies = fontManager.getFamilyList(fontFamiliesIndex);
} }
public final int getFontFamiliesIndex() { public final List<String> getFontFamilies() {
return myFontFamiliesIndex; return myFontFamilies;
} }
final void setFontModifiers(byte supported, byte values) { final void setFontModifiers(byte supported, byte values) {

View file

@ -24,18 +24,21 @@ import java.util.Map;
import org.geometerplus.zlibrary.core.image.ZLImage; import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.core.util.*; import org.geometerplus.zlibrary.core.util.*;
import org.geometerplus.zlibrary.text.fonts.FontManager;
public final class ZLTextWritablePlainModel extends ZLTextPlainModel implements ZLTextWritableModel { public final class ZLTextWritablePlainModel extends ZLTextPlainModel implements ZLTextWritableModel {
private char[] myCurrentDataBlock; private char[] myCurrentDataBlock;
private int myBlockOffset; private int myBlockOffset;
public ZLTextWritablePlainModel(String id, String language, int arraySize, int dataBlockSize, String directoryName, String extension, Map<String,ZLImage> imageMap) { public ZLTextWritablePlainModel(String id, String language, int arraySize, int dataBlockSize, String directoryName, String extension, Map<String,ZLImage> imageMap, FontManager fontManager) {
super( super(
id, language, id, language,
new int[arraySize], new int[arraySize], new int[arraySize], new int[arraySize],
new int[arraySize], new int[arraySize], new int[arraySize], new int[arraySize],
new byte[arraySize], new byte[arraySize],
new CachedCharStorage(dataBlockSize, directoryName, extension), new CachedCharStorage(dataBlockSize, directoryName, extension),
imageMap imageMap,
fontManager
); );
} }

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("FONT FAMILIES INDEX = " + myEntry.getFontFamiliesIndex()); System.err.println("FONT FAMILIES LIST = " + myEntry.getFontFamilies());
// TODO: implement // TODO: implement
} }
return Parent.getFontFamily(); return Parent.getFontFamily();