1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 17:59:33 +02:00

pass font file names to java style

This commit is contained in:
Nikolay Pultsin 2014-03-31 16:04:42 +01:00
parent fcd2640be7
commit ccd1c34858
11 changed files with 102 additions and 11 deletions

View file

@ -313,7 +313,6 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
env->DeleteLocalRef(javaFootnoteModel); env->DeleteLocalRef(javaFootnoteModel);
} }
// TODO: synchronize FontManager
const std::vector<std::vector<std::string> > familyLists = model->fontManager().familyLists(); 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) { for (std::vector<std::vector<std::string> >::const_iterator it = familyLists.begin(); it != familyLists.end(); ++it) {
const std::vector<std::string> &lst = *it; const std::vector<std::string> &lst = *it;
@ -327,6 +326,28 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
env->DeleteLocalRef(jList); env->DeleteLocalRef(jList);
} }
const std::map<std::string,shared_ptr<FontEntry> > entries = model->fontManager().entries();
for (std::map<std::string,shared_ptr<FontEntry> >::const_iterator it = entries.begin(); it != entries.end(); ++it) {
if (it->second.isNull()) {
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);
AndroidUtil::Method_NativeBookModel_registerFontEntry->call(
javaModel, family, normal, bold, italic, boldItalic
);
if (boldItalic != 0) env->DeleteLocalRef(boldItalic);
if (italic != 0) env->DeleteLocalRef(italic);
if (bold != 0) env->DeleteLocalRef(bold);
if (normal != 0) env->DeleteLocalRef(normal);
env->DeleteLocalRef(family);
}
return 0; return 0;
} }

View file

@ -280,7 +280,7 @@ static std::string value(const StyleSheetTable::AttributeMap &map, const std::st
} }
void StyleSheetMultiStyleParser::processAtRule(const std::string &name, const StyleSheetTable::AttributeMap &attributes) { void StyleSheetMultiStyleParser::processAtRule(const std::string &name, const StyleSheetTable::AttributeMap &attributes) {
ZLLogger::Instance().registerClass("FONT"); //ZLLogger::Instance().registerClass("FONT");
if (name == "@font-face") { if (name == "@font-face") {
std::string family = value(attributes, "font-family"); std::string family = value(attributes, "font-family");
if (family.empty()) { if (family.empty()) {

View file

@ -124,6 +124,7 @@ 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<VoidMethod> AndroidUtil::Method_NativeBookModel_registerFontFamilyList;
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_registerFontEntry;
//shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_BookReadingException_throwForFile; //shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_BookReadingException_throwForFile;
@ -206,6 +207,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
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;)"); Method_NativeBookModel_registerFontFamilyList = new VoidMethod(Class_NativeBookModel, "registerFontFamilyList", "([Ljava/lang/String;)");
Method_NativeBookModel_registerFontEntry = new VoidMethod(Class_NativeBookModel, "registerFontEntry", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)");
/* /*
Class_BookReadingException = new JavaClass(env, "org/geometerplus/fbreader/bookmodel/BookReadingException"); Class_BookReadingException = new JavaClass(env, "org/geometerplus/fbreader/bookmodel/BookReadingException");
@ -286,6 +288,10 @@ std::string AndroidUtil::fromJavaString(JNIEnv *env, jstring from) {
return result; return result;
} }
jstring AndroidUtil::createJavaString(JNIEnv* env, shared_ptr<std::string> str) {
return str.isNull() ? 0 : createJavaString(env, *str);
}
jstring AndroidUtil::createJavaString(JNIEnv* env, const std::string &str) { jstring AndroidUtil::createJavaString(JNIEnv* env, const std::string &str) {
if (str.empty()) { if (str.empty()) {
return 0; return 0;

View file

@ -146,6 +146,7 @@ public:
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<VoidMethod> Method_NativeBookModel_registerFontFamilyList;
static shared_ptr<VoidMethod> Method_NativeBookModel_registerFontEntry;
//static shared_ptr<StaticObjectMethod> StaticMethod_BookReadingException_throwForFile; //static shared_ptr<StaticObjectMethod> StaticMethod_BookReadingException_throwForFile;
@ -154,6 +155,7 @@ public:
static JNIEnv *getEnv(); static JNIEnv *getEnv();
static std::string fromJavaString(JNIEnv *env, jstring from); static std::string fromJavaString(JNIEnv *env, jstring from);
static jstring createJavaString(JNIEnv* env, shared_ptr<std::string>);
static jstring createJavaString(JNIEnv* env, const std::string &str); static jstring createJavaString(JNIEnv* env, const std::string &str);
static std::string convertNonUtfString(const std::string &str); static std::string convertNonUtfString(const std::string &str);

View file

@ -22,13 +22,13 @@
#include "FontManager.h" #include "FontManager.h"
std::string FontManager::put(const std::string &family, shared_ptr<FontEntry> entry) { std::string FontManager::put(const std::string &family, shared_ptr<FontEntry> entry) {
shared_ptr<FontEntry> existing = myMap[family]; shared_ptr<FontEntry> existing = myEntries[family];
if (existing.isNull() || *existing == *entry) { if (existing.isNull() || *existing == *entry) {
myMap[family] = entry; myEntries[family] = entry;
return family; return family;
} }
for (std::map<std::string,shared_ptr<FontEntry> >::const_iterator it = myMap.begin(); it != myMap.end(); ++it) { for (std::map<std::string,shared_ptr<FontEntry> >::const_iterator it = myEntries.begin(); it != myEntries.end(); ++it) {
if (*it->second == *entry) { if (*it->second == *entry) {
return it->first; return it->first;
} }
@ -37,8 +37,8 @@ std::string FontManager::put(const std::string &family, shared_ptr<FontEntry> en
for (int i = 1; i < 1000; ++i) { for (int i = 1; i < 1000; ++i) {
std::string indexed = family + "#"; std::string indexed = family + "#";
ZLStringUtil::appendNumber(indexed, i); ZLStringUtil::appendNumber(indexed, i);
if (myMap[indexed].isNull()) { if (myEntries[indexed].isNull()) {
myMap[indexed] = entry; myEntries[indexed] = entry;
return indexed; return indexed;
} }
} }
@ -57,6 +57,10 @@ int FontManager::familyListIndex(const std::vector<std::string> &familyList) {
} }
} }
const std::map<std::string,shared_ptr<FontEntry> > &FontManager::entries() const {
return myEntries;
}
const std::vector<std::vector<std::string> > &FontManager::familyLists() const { const std::vector<std::vector<std::string> > &FontManager::familyLists() const {
return myFamilyLists; return myFamilyLists;
} }

View file

@ -33,10 +33,12 @@ 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::map<std::string,shared_ptr<FontEntry> > &entries() const;
const std::vector<std::vector<std::string> > &familyLists() const; 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> > myEntries;
std::vector<std::vector<std::string> > myFamilyLists; std::vector<std::vector<std::string> > myFamilyLists;
}; };

View file

@ -23,6 +23,7 @@ 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.FontEntry;
import org.geometerplus.zlibrary.text.fonts.FontManager; import org.geometerplus.zlibrary.text.fonts.FontManager;
import org.geometerplus.fbreader.book.Book; import org.geometerplus.fbreader.book.Book;
@ -100,4 +101,12 @@ public abstract class BookModel {
public void registerFontFamilyList(String[] families) { public void registerFontFamilyList(String[] families) {
FontManager.index(Arrays.asList(families)); FontManager.index(Arrays.asList(families));
} }
public void registerFontEntry(String family, FontEntry entry) {
FontManager.Entries.put(family, entry);
}
public void registerFontEntry(String family, String normal, String bold, String italic, String boldItalic) {
registerFontEntry(family, new FontEntry(normal, bold, italic, boldItalic));
}
} }

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2007-2014 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.zlibrary.text.fonts;
public class FontEntry {
public final String Normal;
public final String Bold;
public final String Italic;
public final String BoldItalic;
public FontEntry(String normal, String bold, String italic, String boldItalic) {
Normal = normal;
Bold = bold;
Italic = italic;
BoldItalic = boldItalic;
}
@Override
public String toString() {
return "FontEntry[" + Normal + ";" + Bold + ";" + Italic + ";" + BoldItalic + "]";
}
}

View file

@ -23,6 +23,8 @@ import java.util.*;
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>>();
public final Map<String,FontEntry> Entries =
Collections.synchronizedMap(new HashMap<String,FontEntry>());
public synchronized int index(List<String> families) { public synchronized int index(List<String> families) {
for (int i = 0; i < myFamilyLists.size(); ++i) { for (int i = 0; i < myFamilyLists.size(); ++i) {
@ -35,6 +37,7 @@ public class FontManager {
} }
public synchronized List<String> getFamilyList(int index) { public synchronized List<String> getFamilyList(int index) {
return index < myFamilyLists.size() ? myFamilyLists.get(index) : Collections.<String>emptyList(); return index < myFamilyLists.size()
? myFamilyLists.get(index) : Collections.<String>emptyList();
} }
} }

View file

@ -147,6 +147,10 @@ public abstract class ZLTextStyleEntry {
return myFontFamilies; return myFontFamilies;
} }
public final FontManager getFontManager() {
return myFontManager;
}
final void setFontModifiers(byte supported, byte values) { final void setFontModifiers(byte supported, byte values) {
myFeatureMask |= 1 << Feature.FONT_STYLE_MODIFIER; myFeatureMask |= 1 << Feature.FONT_STYLE_MODIFIER;
mySupportedFontModifiers = supported; mySupportedFontModifiers = supported;

View file

@ -35,8 +35,9 @@ 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 LIST = " + myEntry.getFontFamilies()); for (String family : myEntry.getFontFamilies()) {
// TODO: implement System.err.println("FAMILY = " + family + " => " + myEntry.getFontManager().Entries.get(family));
}
} }
return Parent.getFontFamily(); return Parent.getFontFamily();
} }