Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0fc0c83 authored by Seigo Nonaka's avatar Seigo Nonaka Committed by Android (Google) Code Review
Browse files

Merge "Introduce ttcIndex attribute into system font configuration."

parents d340926c 3fa667e2
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -56,10 +56,11 @@ static jboolean addSkTypeface(FontFamily* family, SkTypeface* face) {
    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_addFont(JNIEnv* env, jobject clazz, jlong familyPtr,
}

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 jboolean FontFamily_addFontFromAsset(JNIEnv* env, jobject, jlong familyPt
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 },
};
+6 −6
Original line number Diff line number Diff line
@@ -58,12 +58,12 @@ public class FontFamily {
        }
    }

    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 @@ public class FontFamily {

    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);
}
+5 −2
Original line number Diff line number Diff line
@@ -43,12 +43,14 @@ public class FontListParser {
    }

    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 @@ public class FontListParser {
            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);
            }
+2 −2
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ public class Typeface {
    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 @@ public class Typeface {
    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;
    }