mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
font families list passed to java style
This commit is contained in:
parent
7ca30d0c9e
commit
fcd2640be7
17 changed files with 78 additions and 29 deletions
|
@ -314,6 +314,18 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
|
|||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -82,6 +82,8 @@ public:
|
|||
|
||||
const shared_ptr<Book> book() const;
|
||||
|
||||
const FontManager &fontManager() const;
|
||||
|
||||
bool flush();
|
||||
|
||||
private:
|
||||
|
@ -101,6 +103,7 @@ inline shared_ptr<ZLTextModel> BookModel::bookTextModel() const { return myBookT
|
|||
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,BookModel::Label> &BookModel::internalHyperlinks() const { return myInternalHyperlinks; }
|
||||
inline const FontManager &BookModel::fontManager() const { return myFontManager; }
|
||||
|
||||
inline ContentsTree::ContentsTree() : myReference(-1) {}
|
||||
inline ContentsTree::ContentsTree(ContentsTree &parent, int reference) : myReference(reference) {
|
||||
|
|
|
@ -123,6 +123,7 @@ shared_ptr<ObjectMethod> AndroidUtil::Method_NativeBookModel_createTextModel;
|
|||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_setBookTextModel;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_setFootnoteModel;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_addImage;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_registerFontFamilyList;
|
||||
|
||||
//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_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_registerFontFamilyList = new VoidMethod(Class_NativeBookModel, "registerFontFamilyList", "([Ljava/lang/String;)");
|
||||
|
||||
/*
|
||||
Class_BookReadingException = new JavaClass(env, "org/geometerplus/fbreader/bookmodel/BookReadingException");
|
||||
|
|
|
@ -145,6 +145,7 @@ public:
|
|||
static shared_ptr<VoidMethod> Method_NativeBookModel_setBookTextModel;
|
||||
static shared_ptr<VoidMethod> Method_NativeBookModel_setFootnoteModel;
|
||||
static shared_ptr<VoidMethod> Method_NativeBookModel_addImage;
|
||||
static shared_ptr<VoidMethod> Method_NativeBookModel_registerFontFamilyList;
|
||||
|
||||
//static shared_ptr<StaticObjectMethod> StaticMethod_BookReadingException_throwForFile;
|
||||
|
||||
|
|
|
@ -56,3 +56,7 @@ int FontManager::familyListIndex(const std::vector<std::string> &familyList) {
|
|||
return it - myFamilyLists.begin();
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::vector<std::string> > &FontManager::familyLists() const {
|
||||
return myFamilyLists;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ class FontManager {
|
|||
public:
|
||||
std::string put(const std::string &family, shared_ptr<FontEntry> entry);
|
||||
int familyListIndex(const std::vector<std::string> &familyList);
|
||||
const std::vector<std::vector<std::string> > &familyLists() const;
|
||||
|
||||
private:
|
||||
std::map<std::string,shared_ptr<FontEntry> > myMap;
|
||||
|
|
|
@ -35,20 +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, FontManager &fManager) :
|
||||
const std::string &directoryName, const std::string &fileExtension, FontManager &fontManager) :
|
||||
myId(id),
|
||||
myLanguage(language.empty() ? ZLibrary::Language() : language),
|
||||
myAllocator(new ZLCachedMemoryAllocator(rowSize, directoryName, fileExtension)),
|
||||
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),
|
||||
myLanguage(language.empty() ? ZLibrary::Language() : language),
|
||||
myAllocator(allocator),
|
||||
myLastEntryStart(0),
|
||||
myFontManager(fManager) {
|
||||
myFontManager(fontManager) {
|
||||
}
|
||||
|
||||
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,
|
||||
const std::string &directoryName, const std::string &fileExtension, FontManager &fManager) :
|
||||
ZLTextModel(id, language, rowSize, directoryName, fileExtension, fManager) {
|
||||
const std::string &directoryName, const std::string &fileExtension, FontManager &fontManager) :
|
||||
ZLTextModel(id, language, rowSize, directoryName, fileExtension, fontManager) {
|
||||
}
|
||||
|
||||
ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager) :
|
||||
ZLTextModel(id, language, allocator, fManager) {
|
||||
ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fontManager) :
|
||||
ZLTextModel(id, language, allocator, fontManager) {
|
||||
}
|
||||
|
||||
void ZLTextPlainModel::createParagraph(ZLTextParagraph::Kind kind) {
|
||||
|
|
|
@ -40,9 +40,9 @@ 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, FontManager &fManager);
|
||||
const std::string &directoryName, const std::string &fileExtension, FontManager &fontManager);
|
||||
ZLTextModel(const std::string &id, const std::string &language,
|
||||
shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fManager);
|
||||
shared_ptr<ZLCachedMemoryAllocator> allocator, FontManager &fontManager);
|
||||
|
||||
public:
|
||||
virtual ~ZLTextModel();
|
||||
|
@ -117,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, FontManager &fManager);
|
||||
const std::string &directoryName, const std::string &fileExtension, FontManager &fontManager);
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -19,9 +19,11 @@
|
|||
|
||||
package org.geometerplus.fbreader.bookmodel;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.geometerplus.zlibrary.text.model.*;
|
||||
import org.geometerplus.zlibrary.text.fonts.FontManager;
|
||||
|
||||
import org.geometerplus.fbreader.book.Book;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
|
@ -52,6 +54,7 @@ public abstract class BookModel {
|
|||
|
||||
public final Book Book;
|
||||
public final TOCTree TOCTree = new TOCTree();
|
||||
public final FontManager FontManager = new FontManager();
|
||||
|
||||
public static final class Label {
|
||||
public final String ModelId;
|
||||
|
@ -93,4 +96,8 @@ public abstract class BookModel {
|
|||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
public void registerFontFamilyList(String[] families) {
|
||||
FontManager.index(Arrays.asList(families));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class JavaBookModel extends BookModelImpl {
|
|||
JavaBookModel(Book book) {
|
||||
super(book);
|
||||
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
|
||||
|
@ -42,7 +42,7 @@ public class JavaBookModel extends BookModelImpl {
|
|||
public ZLTextModel getFootnoteModel(String id) {
|
||||
ZLTextModel model = myFootnotes.get(id);
|
||||
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);
|
||||
}
|
||||
return model;
|
||||
|
|
|
@ -59,7 +59,7 @@ public class NativeBookModel extends BookModelImpl {
|
|||
id, language, paragraphsNumber,
|
||||
entryIndices, entryOffsets,
|
||||
paragraphLenghts, textSizes, paragraphKinds,
|
||||
directoryName, fileExtension, blocksNumber, myImageMap
|
||||
directoryName, fileExtension, blocksNumber, myImageMap, FontManager
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
package org.geometerplus.zlibrary.text.fonts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class FontManager {
|
||||
private final ArrayList<List<String>> myFamilyLists = new ArrayList<List<String>>();
|
||||
|
@ -34,4 +33,8 @@ public class FontManager {
|
|||
myFamilyLists.add(new ArrayList<String>(families));
|
||||
return myFamilyLists.size() - 1;
|
||||
}
|
||||
|
||||
public synchronized List<String> getFamilyList(int index) {
|
||||
return index < myFamilyLists.size() ? myFamilyLists.get(index) : Collections.<String>emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import java.util.Map;
|
|||
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
|
||||
import org.geometerplus.zlibrary.text.fonts.FontManager;
|
||||
|
||||
public class ZLTextNativeModel extends ZLTextPlainModel {
|
||||
public ZLTextNativeModel(
|
||||
String id, String language, int paragraphsNumber,
|
||||
|
@ -30,13 +32,15 @@ public class ZLTextNativeModel extends ZLTextPlainModel {
|
|||
int[] paragraphLengths, int[] textSizes,
|
||||
byte[] paragraphKinds,
|
||||
String directoryName, String fileExtension, int blocksNumber,
|
||||
Map<String,ZLImage> imageMap
|
||||
Map<String,ZLImage> imageMap,
|
||||
FontManager fontManager
|
||||
) {
|
||||
super(
|
||||
id, language,
|
||||
entryIndices, entryOffsets, paragraphLengths, textSizes, paragraphKinds,
|
||||
new CachedCharStorageRO(directoryName, fileExtension, blocksNumber),
|
||||
imageMap
|
||||
imageMap,
|
||||
fontManager
|
||||
);
|
||||
myParagraphsNumber = paragraphsNumber;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.*;
|
|||
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.util.*;
|
||||
import org.geometerplus.zlibrary.text.fonts.FontManager;
|
||||
|
||||
public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
||||
private final String myId;
|
||||
|
@ -41,6 +42,8 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
|
||||
private ArrayList<ZLTextMark> myMarks;
|
||||
|
||||
private final FontManager myFontManager;
|
||||
|
||||
final class EntryIteratorImpl implements ZLTextParagraph.EntryIterator {
|
||||
private int myCounter;
|
||||
private int myLength;
|
||||
|
@ -213,7 +216,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
entry.setAlignmentType((byte)(value & 0xFF));
|
||||
}
|
||||
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_FAMILY)) {
|
||||
entry.setFontFamiliesIndex((short)data[dataOffset++]);
|
||||
entry.setFontFamilies(myFontManager, (short)data[dataOffset++]);
|
||||
}
|
||||
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_STYLE_MODIFIER)) {
|
||||
final short value = (short)data[dataOffset++];
|
||||
|
@ -261,7 +264,8 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
int[] textSizes,
|
||||
byte[] paragraphKinds,
|
||||
CharStorage storage,
|
||||
Map<String,ZLImage> imageMap
|
||||
Map<String,ZLImage> imageMap,
|
||||
FontManager fontManager
|
||||
) {
|
||||
myId = id;
|
||||
myLanguage = language;
|
||||
|
@ -272,6 +276,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
myParagraphKinds = paragraphKinds;
|
||||
myStorage = storage;
|
||||
myImageMap = imageMap;
|
||||
myFontManager = fontManager;
|
||||
}
|
||||
|
||||
public final String getId() {
|
||||
|
|
|
@ -24,6 +24,8 @@ import java.util.List;
|
|||
|
||||
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
|
||||
|
||||
import org.geometerplus.zlibrary.text.fonts.FontManager;
|
||||
|
||||
public abstract class ZLTextStyleEntry {
|
||||
public interface Feature {
|
||||
int LENGTH_LEFT_INDENT = 0;
|
||||
|
@ -71,7 +73,8 @@ public abstract class ZLTextStyleEntry {
|
|||
|
||||
private Length[] myLengths = new Length[Feature.NUMBER_OF_LENGTHS];
|
||||
private byte myAlignmentType;
|
||||
private int myFontFamiliesIndex;
|
||||
private FontManager myFontManager;
|
||||
private List<String> myFontFamilies;
|
||||
private byte mySupportedFontModifiers;
|
||||
private byte myFontModifiers;
|
||||
|
||||
|
@ -134,13 +137,14 @@ public abstract class ZLTextStyleEntry {
|
|||
return myAlignmentType;
|
||||
}
|
||||
|
||||
final void setFontFamiliesIndex(int fontFamiliesIndex) {
|
||||
final void setFontFamilies(FontManager fontManager, int fontFamiliesIndex) {
|
||||
myFeatureMask |= 1 << Feature.FONT_FAMILY;
|
||||
myFontFamiliesIndex = fontFamiliesIndex;
|
||||
myFontManager = fontManager;
|
||||
myFontFamilies = fontManager.getFamilyList(fontFamiliesIndex);
|
||||
}
|
||||
|
||||
public final int getFontFamiliesIndex() {
|
||||
return myFontFamiliesIndex;
|
||||
public final List<String> getFontFamilies() {
|
||||
return myFontFamilies;
|
||||
}
|
||||
|
||||
final void setFontModifiers(byte supported, byte values) {
|
||||
|
|
|
@ -24,18 +24,21 @@ import java.util.Map;
|
|||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.util.*;
|
||||
|
||||
import org.geometerplus.zlibrary.text.fonts.FontManager;
|
||||
|
||||
public final class ZLTextWritablePlainModel extends ZLTextPlainModel implements ZLTextWritableModel {
|
||||
private char[] myCurrentDataBlock;
|
||||
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(
|
||||
id, language,
|
||||
new int[arraySize], new int[arraySize],
|
||||
new int[arraySize], new int[arraySize],
|
||||
new byte[arraySize],
|
||||
new CachedCharStorage(dataBlockSize, directoryName, extension),
|
||||
imageMap
|
||||
imageMap,
|
||||
fontManager
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
|
|||
@Override
|
||||
protected String getFontFamilyInternal() {
|
||||
if (myEntry.isFeatureSupported(FONT_FAMILY)) {
|
||||
System.err.println("FONT FAMILIES INDEX = " + myEntry.getFontFamiliesIndex());
|
||||
System.err.println("FONT FAMILIES LIST = " + myEntry.getFontFamilies());
|
||||
// TODO: implement
|
||||
}
|
||||
return Parent.getFontFamily();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue