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;
}
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;
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 },
};
}
}
- 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) {
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);
}
}
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;
}
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);
}
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);
}
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;
}