Loading core/jni/android/graphics/FontFamily.cpp +16 −12 Original line number Diff line number Diff line Loading @@ -81,18 +81,21 @@ static void FontFamily_unref(jlong familyPtr) { } static void addSkTypeface(jlong builderPtr, sk_sp<SkTypeface> face, const void* fontData, size_t fontSize, int ttcIndex) { size_t fontSize, int ttcIndex, jint givenWeight, jboolean givenItalic) { minikin::MinikinFont* minikinFont = new MinikinFontSkia(std::move(face), fontData, fontSize, ttcIndex); NativeFamilyBuilder* builder = reinterpret_cast<NativeFamilyBuilder*>(builderPtr); int weight; bool italic; int weight = givenWeight / 100; bool italic = givenItalic; if (weight == 0) { if (!minikin::FontFamily::analyzeStyle(minikinFont, &weight, &italic)) { ALOGE("analyzeStyle failed. Using default style"); weight = 400; weight = 4; italic = false; } builder->fonts.push_back(minikin::Font(minikinFont, minikin::FontStyle(weight / 100, italic))); } builder->fonts.push_back(minikin::Font(minikinFont, minikin::FontStyle(weight, italic))); minikinFont->Unref(); } Loading Loading @@ -146,7 +149,7 @@ static jboolean FontFamily_addFont(JNIEnv* env, jobject clazz, jlong builderPtr, ALOGE("addFont failed to create font"); return false; } addSkTypeface(builderPtr, std::move(face), fontPtr, (size_t)fontSize, ttcIndex); addSkTypeface(builderPtr, std::move(face), fontPtr, (size_t)fontSize, ttcIndex, 0, false); return true; } Loading Loading @@ -218,7 +221,8 @@ static void releaseAsset(const void* ptr, void* context) { } static jboolean FontFamily_addFontFromAssetManager(JNIEnv* env, jobject, jlong builderPtr, jobject jassetMgr, jstring jpath, jint cookie, jboolean isAsset) { jobject jassetMgr, jstring jpath, jint cookie, jboolean isAsset, jint weight, jboolean isItalic) { NPE_CHECK_RETURN_ZERO(env, jassetMgr); NPE_CHECK_RETURN_ZERO(env, jpath); Loading Loading @@ -261,7 +265,7 @@ static jboolean FontFamily_addFontFromAssetManager(JNIEnv* env, jobject, jlong b return false; } addSkTypeface(builderPtr, std::move(face), buf, bufSize, 0 /* ttc index */); addSkTypeface(builderPtr, std::move(face), buf, bufSize, 0 /* ttc index */, weight, isItalic); return true; } Loading @@ -275,7 +279,7 @@ static const JNINativeMethod gFontFamilyMethods[] = { { "nAddFont", "(JLjava/nio/ByteBuffer;I)Z", (void*)FontFamily_addFont }, { "nAddFontWeightStyle", "(JLjava/nio/ByteBuffer;ILjava/util/List;IZ)Z", (void*)FontFamily_addFontWeightStyle }, { "nAddFontFromAssetManager", "(JLandroid/content/res/AssetManager;Ljava/lang/String;IZ)Z", { "nAddFontFromAssetManager", "(JLandroid/content/res/AssetManager;Ljava/lang/String;IZIZ)Z", (void*)FontFamily_addFontFromAssetManager }, }; Loading graphics/java/android/graphics/FontFamily.java +15 −3 Original line number Diff line number Diff line Loading @@ -111,12 +111,24 @@ public class FontFamily { return nAddFontWeightStyle(mBuilderPtr, font, ttcIndex, axes, weight, style); } /** * @param mgr The AssetManager to use for this context. * @param path The path to the font file to load. * @param cookie If available, the resource cookie given by Resources. * @param isAsset {@code true} if this is from the assets/ folder, {@code false} if from * resources * @param weight The weight of the font. If 0 is given, the weight and italic will be resolved * using the OS/2 table in the font. * @param isItalic Whether this font is italic. If the weight is set to 0, this will be resolved * using the OS/2 table in the font. * @return */ public boolean addFontFromAssetManager(AssetManager mgr, String path, int cookie, boolean isAsset) { boolean isAsset, int weight, boolean isItalic) { if (mBuilderPtr == 0) { throw new IllegalStateException("Unable to call addFontFromAsset after freezing."); } return nAddFontFromAssetManager(mBuilderPtr, mgr, path, cookie, isAsset); return nAddFontFromAssetManager(mBuilderPtr, mgr, path, cookie, isAsset, weight, isItalic); } private static native long nInitBuilder(String lang, int variant); Loading @@ -134,5 +146,5 @@ public class FontFamily { int ttcIndex, List<FontConfig.Axis> listOfAxis, int weight, boolean isItalic); private static native boolean nAddFontFromAssetManager(long builderPtr, AssetManager mgr, String path, int cookie, boolean isAsset); String path, int cookie, boolean isAsset, int weight, boolean isItalic); } graphics/java/android/graphics/Typeface.java +6 −3 Original line number Diff line number Diff line Loading @@ -144,7 +144,8 @@ public class Typeface { if (typeface != null) return typeface; FontFamily fontFamily = new FontFamily(); if (fontFamily.addFontFromAssetManager(mgr, path, cookie, false /* isAsset */)) { if (fontFamily.addFontFromAssetManager(mgr, path, cookie, false /* isAsset */, 0 /* use OS/2 table to determine weight and italic */, false)) { fontFamily.freeze(); FontFamily[] families = {fontFamily}; typeface = createFromFamiliesWithDefault(families); Loading Loading @@ -199,7 +200,8 @@ public class Typeface { FontConfig.Font font = fonts.get(i); // TODO: Use style and weight info if (!fontFamily.addFontFromAssetManager(mgr, font.getFontName(), 0 /* resourceCookie */, false /* isAsset */)) { 0 /* resourceCookie */, false /* isAsset */, font.getWeight(), font.isItalic())) { return null; } } Loading Loading @@ -498,7 +500,8 @@ public class Typeface { if (typeface != null) return typeface; FontFamily fontFamily = new FontFamily(); if (fontFamily.addFontFromAssetManager(mgr, path, 0, true /* isAsset */)) { if (fontFamily.addFontFromAssetManager(mgr, path, 0, true /* isAsset */, 0 /* use OS/2 table to determine weight and italic */, false)) { fontFamily.freeze(); FontFamily[] families = { fontFamily }; typeface = createFromFamiliesWithDefault(families); Loading Loading
core/jni/android/graphics/FontFamily.cpp +16 −12 Original line number Diff line number Diff line Loading @@ -81,18 +81,21 @@ static void FontFamily_unref(jlong familyPtr) { } static void addSkTypeface(jlong builderPtr, sk_sp<SkTypeface> face, const void* fontData, size_t fontSize, int ttcIndex) { size_t fontSize, int ttcIndex, jint givenWeight, jboolean givenItalic) { minikin::MinikinFont* minikinFont = new MinikinFontSkia(std::move(face), fontData, fontSize, ttcIndex); NativeFamilyBuilder* builder = reinterpret_cast<NativeFamilyBuilder*>(builderPtr); int weight; bool italic; int weight = givenWeight / 100; bool italic = givenItalic; if (weight == 0) { if (!minikin::FontFamily::analyzeStyle(minikinFont, &weight, &italic)) { ALOGE("analyzeStyle failed. Using default style"); weight = 400; weight = 4; italic = false; } builder->fonts.push_back(minikin::Font(minikinFont, minikin::FontStyle(weight / 100, italic))); } builder->fonts.push_back(minikin::Font(minikinFont, minikin::FontStyle(weight, italic))); minikinFont->Unref(); } Loading Loading @@ -146,7 +149,7 @@ static jboolean FontFamily_addFont(JNIEnv* env, jobject clazz, jlong builderPtr, ALOGE("addFont failed to create font"); return false; } addSkTypeface(builderPtr, std::move(face), fontPtr, (size_t)fontSize, ttcIndex); addSkTypeface(builderPtr, std::move(face), fontPtr, (size_t)fontSize, ttcIndex, 0, false); return true; } Loading Loading @@ -218,7 +221,8 @@ static void releaseAsset(const void* ptr, void* context) { } static jboolean FontFamily_addFontFromAssetManager(JNIEnv* env, jobject, jlong builderPtr, jobject jassetMgr, jstring jpath, jint cookie, jboolean isAsset) { jobject jassetMgr, jstring jpath, jint cookie, jboolean isAsset, jint weight, jboolean isItalic) { NPE_CHECK_RETURN_ZERO(env, jassetMgr); NPE_CHECK_RETURN_ZERO(env, jpath); Loading Loading @@ -261,7 +265,7 @@ static jboolean FontFamily_addFontFromAssetManager(JNIEnv* env, jobject, jlong b return false; } addSkTypeface(builderPtr, std::move(face), buf, bufSize, 0 /* ttc index */); addSkTypeface(builderPtr, std::move(face), buf, bufSize, 0 /* ttc index */, weight, isItalic); return true; } Loading @@ -275,7 +279,7 @@ static const JNINativeMethod gFontFamilyMethods[] = { { "nAddFont", "(JLjava/nio/ByteBuffer;I)Z", (void*)FontFamily_addFont }, { "nAddFontWeightStyle", "(JLjava/nio/ByteBuffer;ILjava/util/List;IZ)Z", (void*)FontFamily_addFontWeightStyle }, { "nAddFontFromAssetManager", "(JLandroid/content/res/AssetManager;Ljava/lang/String;IZ)Z", { "nAddFontFromAssetManager", "(JLandroid/content/res/AssetManager;Ljava/lang/String;IZIZ)Z", (void*)FontFamily_addFontFromAssetManager }, }; Loading
graphics/java/android/graphics/FontFamily.java +15 −3 Original line number Diff line number Diff line Loading @@ -111,12 +111,24 @@ public class FontFamily { return nAddFontWeightStyle(mBuilderPtr, font, ttcIndex, axes, weight, style); } /** * @param mgr The AssetManager to use for this context. * @param path The path to the font file to load. * @param cookie If available, the resource cookie given by Resources. * @param isAsset {@code true} if this is from the assets/ folder, {@code false} if from * resources * @param weight The weight of the font. If 0 is given, the weight and italic will be resolved * using the OS/2 table in the font. * @param isItalic Whether this font is italic. If the weight is set to 0, this will be resolved * using the OS/2 table in the font. * @return */ public boolean addFontFromAssetManager(AssetManager mgr, String path, int cookie, boolean isAsset) { boolean isAsset, int weight, boolean isItalic) { if (mBuilderPtr == 0) { throw new IllegalStateException("Unable to call addFontFromAsset after freezing."); } return nAddFontFromAssetManager(mBuilderPtr, mgr, path, cookie, isAsset); return nAddFontFromAssetManager(mBuilderPtr, mgr, path, cookie, isAsset, weight, isItalic); } private static native long nInitBuilder(String lang, int variant); Loading @@ -134,5 +146,5 @@ public class FontFamily { int ttcIndex, List<FontConfig.Axis> listOfAxis, int weight, boolean isItalic); private static native boolean nAddFontFromAssetManager(long builderPtr, AssetManager mgr, String path, int cookie, boolean isAsset); String path, int cookie, boolean isAsset, int weight, boolean isItalic); }
graphics/java/android/graphics/Typeface.java +6 −3 Original line number Diff line number Diff line Loading @@ -144,7 +144,8 @@ public class Typeface { if (typeface != null) return typeface; FontFamily fontFamily = new FontFamily(); if (fontFamily.addFontFromAssetManager(mgr, path, cookie, false /* isAsset */)) { if (fontFamily.addFontFromAssetManager(mgr, path, cookie, false /* isAsset */, 0 /* use OS/2 table to determine weight and italic */, false)) { fontFamily.freeze(); FontFamily[] families = {fontFamily}; typeface = createFromFamiliesWithDefault(families); Loading Loading @@ -199,7 +200,8 @@ public class Typeface { FontConfig.Font font = fonts.get(i); // TODO: Use style and weight info if (!fontFamily.addFontFromAssetManager(mgr, font.getFontName(), 0 /* resourceCookie */, false /* isAsset */)) { 0 /* resourceCookie */, false /* isAsset */, font.getWeight(), font.isItalic())) { return null; } } Loading Loading @@ -498,7 +500,8 @@ public class Typeface { if (typeface != null) return typeface; FontFamily fontFamily = new FontFamily(); if (fontFamily.addFontFromAssetManager(mgr, path, 0, true /* isAsset */)) { if (fontFamily.addFontFromAssetManager(mgr, path, 0, true /* isAsset */, 0 /* use OS/2 table to determine weight and italic */, false)) { fontFamily.freeze(); FontFamily[] families = { fontFamily }; typeface = createFromFamiliesWithDefault(families); Loading