Introduce ttcIndex attribute into system font configuration.
ttcIndex is used for specifying index of the TrueType Collection.
No user visible change is expected with this CL.
BUG: 10861108
Change-Id: I76a1c890164bb55a7ece7b9c7db2ce2bac3f8b89
diff --git a/core/jni/android/graphics/FontFamily.cpp b/core/jni/android/graphics/FontFamily.cpp
index dac6d96..ab0df55 100644
--- a/core/jni/android/graphics/FontFamily.cpp
+++ b/core/jni/android/graphics/FontFamily.cpp
@@ -56,10 +56,11 @@
return result;
}
-static jboolean FontFamily_addFont(JNIEnv* env, jobject clazz, jlong familyPtr, jstring path) {
+static jboolean FontFamily_addFont(JNIEnv* env, jobject clazz, jlong familyPtr, jstring path,
+ jint ttcIndex) {
NPE_CHECK_RETURN_ZERO(env, path);
ScopedUtfChars str(env, path);
- SkTypeface* face = SkTypeface::CreateFromFile(str.c_str());
+ SkTypeface* face = SkTypeface::CreateFromFile(str.c_str(), ttcIndex);
if (face == NULL) {
ALOGE("addFont failed to create font %s", str.c_str());
return false;
@@ -69,10 +70,10 @@
}
static jboolean FontFamily_addFontWeightStyle(JNIEnv* env, jobject clazz, jlong familyPtr,
- jstring path, jint weight, jboolean isItalic) {
+ jstring path, jint ttcIndex, jint weight, jboolean isItalic) {
NPE_CHECK_RETURN_ZERO(env, path);
ScopedUtfChars str(env, path);
- SkTypeface* face = SkTypeface::CreateFromFile(str.c_str());
+ SkTypeface* face = SkTypeface::CreateFromFile(str.c_str(), ttcIndex);
if (face == NULL) {
ALOGE("addFont failed to create font %s", str.c_str());
return false;
@@ -127,8 +128,8 @@
static const JNINativeMethod gFontFamilyMethods[] = {
{ "nCreateFamily", "(Ljava/lang/String;I)J", (void*)FontFamily_create },
{ "nUnrefFamily", "(J)V", (void*)FontFamily_unref },
- { "nAddFont", "(JLjava/lang/String;)Z", (void*)FontFamily_addFont },
- { "nAddFontWeightStyle", "(JLjava/lang/String;IZ)Z", (void*)FontFamily_addFontWeightStyle },
+ { "nAddFont", "(JLjava/lang/String;I)Z", (void*)FontFamily_addFont },
+ { "nAddFontWeightStyle", "(JLjava/lang/String;IIZ)Z", (void*)FontFamily_addFontWeightStyle },
{ "nAddFontFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)Z",
(void*)FontFamily_addFontFromAsset },
};
diff --git a/graphics/java/android/graphics/FontFamily.java b/graphics/java/android/graphics/FontFamily.java
index b8b7e76..6309ed3 100644
--- a/graphics/java/android/graphics/FontFamily.java
+++ b/graphics/java/android/graphics/FontFamily.java
@@ -58,12 +58,12 @@
}
}
- public boolean addFont(String path) {
- return nAddFont(mNativePtr, path);
+ public boolean addFont(String path, int ttcIndex) {
+ return nAddFont(mNativePtr, path, ttcIndex);
}
- public boolean addFontWeightStyle(String path, int weight, boolean style) {
- return nAddFontWeightStyle(mNativePtr, path, weight, style);
+ public boolean addFontWeightStyle(String path, int ttcIndex, int weight, boolean style) {
+ return nAddFontWeightStyle(mNativePtr, path, ttcIndex, weight, style);
}
public boolean addFontFromAsset(AssetManager mgr, String path) {
@@ -72,9 +72,9 @@
private static native long nCreateFamily(String lang, int variant);
private static native void nUnrefFamily(long nativePtr);
- private static native boolean nAddFont(long nativeFamily, String path);
+ private static native boolean nAddFont(long nativeFamily, String path, int ttcIndex);
private static native boolean nAddFontWeightStyle(long nativeFamily, String path,
- int weight, boolean isItalic);
+ int ttcIndex, int weight, boolean isItalic);
private static native boolean nAddFontFromAsset(long nativeFamily, AssetManager mgr,
String path);
}
diff --git a/graphics/java/android/graphics/FontListParser.java b/graphics/java/android/graphics/FontListParser.java
index 97081f9..e4494ca 100644
--- a/graphics/java/android/graphics/FontListParser.java
+++ b/graphics/java/android/graphics/FontListParser.java
@@ -43,12 +43,14 @@
}
public static class Font {
- Font(String fontName, int weight, boolean isItalic) {
+ Font(String fontName, int ttcIndex, int weight, boolean isItalic) {
this.fontName = fontName;
+ this.ttcIndex = ttcIndex;
this.weight = weight;
this.isItalic = isItalic;
}
public String fontName;
+ public int ttcIndex;
public int weight;
public boolean isItalic;
}
@@ -112,12 +114,13 @@
if (parser.getEventType() != XmlPullParser.START_TAG) continue;
String tag = parser.getName();
if (tag.equals("font")) {
+ int ttcIndex = Integer.parseInt(parser.getAttributeValue("0", "ttcIndex"));
String weightStr = parser.getAttributeValue(null, "weight");
int weight = weightStr == null ? 400 : Integer.parseInt(weightStr);
boolean isItalic = "italic".equals(parser.getAttributeValue(null, "style"));
String filename = parser.nextText();
String fullFilename = "/system/fonts/" + filename;
- fonts.add(new Font(fullFilename, weight, isItalic));
+ fonts.add(new Font(fullFilename, ttcIndex, weight, isItalic));
} else {
skip(parser);
}
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index 7eb5584..1294323 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -209,7 +209,7 @@
public static Typeface createFromFile(String path) {
if (sFallbackFonts != null) {
FontFamily fontFamily = new FontFamily();
- if (fontFamily.addFont(path)) {
+ if (fontFamily.addFont(path, 0 /* ttcIndex */)) {
FontFamily[] families = { fontFamily };
return createFromFamiliesWithDefault(families);
}
@@ -262,7 +262,7 @@
private static FontFamily makeFamilyFromParsed(FontListParser.Family family) {
FontFamily fontFamily = new FontFamily(family.lang, family.variant);
for (FontListParser.Font font : family.fonts) {
- fontFamily.addFontWeightStyle(font.fontName, font.weight, font.isItalic);
+ fontFamily.addFontWeightStyle(font.fontName, font.ttcIndex, font.weight, font.isItalic);
}
return fontFamily;
}