diff options
-rw-r--r-- | core/jni/android/graphics/FontFamily.cpp | 11 | ||||
-rw-r--r-- | core/jni/android/graphics/MinikinUtils.cpp | 8 | ||||
-rw-r--r-- | graphics/java/android/graphics/FontFamily.java | 19 | ||||
-rw-r--r-- | graphics/java/android/graphics/FontListParser.java | 16 | ||||
-rw-r--r-- | graphics/java/android/graphics/Typeface.java | 2 |
5 files changed, 46 insertions, 10 deletions
diff --git a/core/jni/android/graphics/FontFamily.cpp b/core/jni/android/graphics/FontFamily.cpp index 041790f..3bab8a2 100644 --- a/core/jni/android/graphics/FontFamily.cpp +++ b/core/jni/android/graphics/FontFamily.cpp @@ -31,9 +31,14 @@ namespace android { -static jlong FontFamily_create(JNIEnv* env, jobject clazz) { +static jlong FontFamily_create(JNIEnv* env, jobject clazz, jstring lang, jint variant) { #ifdef USE_MINIKIN - return (jlong)new FontFamily(); + FontLanguage fontLanguage; + if (lang != NULL) { + ScopedUtfChars str(env, lang); + fontLanguage = FontLanguage(str.c_str(), str.size()); + } + return (jlong)new FontFamily(fontLanguage, variant); #else return 0; #endif @@ -67,7 +72,7 @@ static jboolean FontFamily_addFont(JNIEnv* env, jobject clazz, jlong familyPtr, /////////////////////////////////////////////////////////////////////////////// static JNINativeMethod gFontFamilyMethods[] = { - { "nCreateFamily", "()J", (void*)FontFamily_create }, + { "nCreateFamily", "(Ljava/lang/String;I)J", (void*)FontFamily_create }, { "nUnrefFamily", "(J)V", (void*)FontFamily_unref }, { "nAddFont", "(JLjava/lang/String;)Z", (void*)FontFamily_addFont }, }; diff --git a/core/jni/android/graphics/MinikinUtils.cpp b/core/jni/android/graphics/MinikinUtils.cpp index ee04d6f..79381ad 100644 --- a/core/jni/android/graphics/MinikinUtils.cpp +++ b/core/jni/android/graphics/MinikinUtils.cpp @@ -28,11 +28,17 @@ void MinikinUtils::SetLayoutProperties(Layout* layout, SkPaint* paint, int flags layout->setFontCollection(resolvedFace->fFontCollection); FontStyle style = resolvedFace->fStyle; char css[256]; - sprintf(css, "font-size: %d; font-weight: %d; font-style: %s; -minikin-bidi: %d", + int off = snprintf(css, sizeof(css), + "font-size: %d; font-weight: %d; font-style: %s; -minikin-bidi: %d;", (int)paint->getTextSize(), style.getWeight() * 100, style.getItalic() ? "italic" : "normal", flags); + SkString langString = paint->getPaintOptionsAndroid().getLanguage().getTag(); + off += snprintf(css + off, sizeof(css) - off, " lang: %s;", langString.c_str()); + SkPaintOptionsAndroid::FontVariant var = paint->getPaintOptionsAndroid().getFontVariant(); + const char* varstr = var == SkPaintOptionsAndroid::kElegant_Variant ? "elegant" : "compact"; + off += snprintf(css + off, sizeof(css) - off, " -minikin-variant: %s;", varstr); layout->setProperties(css); } diff --git a/graphics/java/android/graphics/FontFamily.java b/graphics/java/android/graphics/FontFamily.java index 210ea86b..6802b9a 100644 --- a/graphics/java/android/graphics/FontFamily.java +++ b/graphics/java/android/graphics/FontFamily.java @@ -30,9 +30,22 @@ public class FontFamily { public long mNativePtr; public FontFamily() { - mNativePtr = nCreateFamily(); + mNativePtr = nCreateFamily(null, 0); if (mNativePtr == 0) { - throw new RuntimeException(); + throw new IllegalStateException("error creating native FontFamily"); + } + } + + public FontFamily(String lang, String variant) { + int varEnum = 0; + if ("compact".equals(variant)) { + varEnum = 1; + } else if ("elegant".equals(variant)) { + varEnum = 2; + } + mNativePtr = nCreateFamily(lang, varEnum); + if (mNativePtr == 0) { + throw new IllegalStateException("error creating native FontFamily"); } } @@ -49,7 +62,7 @@ public class FontFamily { return nAddFont(mNativePtr, path.getAbsolutePath()); } - static native long nCreateFamily(); + static native long nCreateFamily(String lang, int variant); static native void nUnrefFamily(long nativePtr); static native boolean nAddFont(long nativeFamily, String path); } diff --git a/graphics/java/android/graphics/FontListParser.java b/graphics/java/android/graphics/FontListParser.java index f304f4e..a863a06 100644 --- a/graphics/java/android/graphics/FontListParser.java +++ b/graphics/java/android/graphics/FontListParser.java @@ -34,14 +34,18 @@ import java.util.List; public class FontListParser { public static class Family { - public Family(List<String> names, List<String> fontFiles) { + public Family(List<String> names, List<String> fontFiles, String lang, String variant) { this.names = names; this.fontFiles = fontFiles; + this.lang = lang; + this.variant = variant; } public List<String> names; // todo: need attributes for font files public List<String> fontFiles; + public String lang; + public String variant; } /* Parse fallback list (no names) */ @@ -75,6 +79,8 @@ public class FontListParser { throws XmlPullParserException, IOException { List<String> names = null; List<String> fontFiles = new ArrayList<String>(); + String lang = null; + String variant = null; while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) continue; String tag = parser.getName(); @@ -82,6 +88,12 @@ public class FontListParser { while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) continue; if (parser.getName().equals("file")) { + if (lang == null) { + lang = parser.getAttributeValue(null, "lang"); + } + if (variant == null) { + variant = parser.getAttributeValue(null, "variant"); + } String filename = parser.nextText(); String fullFilename = "/system/fonts/" + filename; fontFiles.add(fullFilename); @@ -98,7 +110,7 @@ public class FontListParser { } } } - return new Family(names, fontFiles); + return new Family(names, fontFiles, lang, variant); } private static void skip(XmlPullParser parser) throws XmlPullParserException, IOException { diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java index b7613fb..2b07c3f 100644 --- a/graphics/java/android/graphics/Typeface.java +++ b/graphics/java/android/graphics/Typeface.java @@ -245,7 +245,7 @@ public class Typeface { private static FontFamily makeFamilyFromParsed(FontListParser.Family family) { // TODO: expand to handle attributes like lang and variant - FontFamily fontFamily = new FontFamily(); + FontFamily fontFamily = new FontFamily(family.lang, family.variant); for (String fontFile : family.fontFiles) { fontFamily.addFont(new File(fontFile)); } |