Loading core/jni/android/graphics/Typeface.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -20,11 +20,13 @@ #include "FontUtils.h" #include "GraphicsJNI.h" #include <nativehelper/ScopedPrimitiveArray.h> #include <nativehelper/ScopedUtfChars.h> #include "SkTypeface.h" #include <android_runtime/android_util_AssetManager.h> #include <androidfw/AssetManager.h> #include <hwui/Typeface.h> #include <minikin/FontFamily.h> #include <minikin/SystemFonts.h> using namespace android; Loading Loading @@ -108,6 +110,7 @@ static jlong Typeface_createFromArray(JNIEnv *env, jobject, jlongArray familyArr // CriticalNative static void Typeface_setDefault(jlong faceHandle) { Typeface::setDefault(toTypeface(faceHandle)); minikin::SystemFonts::registerDefault(toTypeface(faceHandle)->fFontCollection); } static jobject Typeface_getSupportedAxes(JNIEnv *env, jobject, jlong faceHandle) { Loading @@ -128,6 +131,12 @@ static jobject Typeface_getSupportedAxes(JNIEnv *env, jobject, jlong faceHandle) return result; } static void Typeface_registerGenericFamily(JNIEnv *env, jobject, jstring familyName, jlong ptr) { ScopedUtfChars familyNameChars(env, familyName); minikin::SystemFonts::registerFallback(familyNameChars.c_str(), toTypeface(ptr)->fFontCollection); } /////////////////////////////////////////////////////////////////////////////// static const JNINativeMethod gTypefaceMethods[] = { Loading @@ -144,6 +153,8 @@ static const JNINativeMethod gTypefaceMethods[] = { (void*)Typeface_createFromArray }, { "nativeSetDefault", "(J)V", (void*)Typeface_setDefault }, { "nativeGetSupportedAxes", "(J)[I", (void*)Typeface_getSupportedAxes }, { "nativeRegisterGenericFamily", "(Ljava/lang/String;J)V", (void*)Typeface_registerGenericFamily }, }; int register_android_graphics_Typeface(JNIEnv* env) Loading graphics/java/android/graphics/Typeface.java +18 −0 Original line number Diff line number Diff line Loading @@ -1115,6 +1115,13 @@ public class Typeface { } } private static void registerGenericFamilyNative(@NonNull String familyName, @Nullable Typeface typeface) { if (typeface != null) { nativeRegisterGenericFamily(familyName, typeface.native_instance); } } static { final HashMap<String, Typeface> systemFontMap = new HashMap<>(); initSystemDefaultTypefaces(systemFontMap, SystemFonts.getRawSystemFallbackMap(), Loading @@ -1140,6 +1147,15 @@ public class Typeface { create((String) null, Typeface.BOLD_ITALIC), }; // A list of generic families to be registered in native. // https://www.w3.org/TR/css-fonts-4/#generic-font-families String[] genericFamilies = { "serif", "sans-serif", "cursive", "fantasy", "monospace", "system-ui" }; for (String genericFamily : genericFamilies) { registerGenericFamilyNative(genericFamily, systemFontMap.get(genericFamily)); } } @Override Loading Loading @@ -1202,4 +1218,6 @@ public class Typeface { @CriticalNative private static native long nativeGetReleaseFunc(); private static native void nativeRegisterGenericFamily(String str, long nativePtr); } Loading
core/jni/android/graphics/Typeface.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -20,11 +20,13 @@ #include "FontUtils.h" #include "GraphicsJNI.h" #include <nativehelper/ScopedPrimitiveArray.h> #include <nativehelper/ScopedUtfChars.h> #include "SkTypeface.h" #include <android_runtime/android_util_AssetManager.h> #include <androidfw/AssetManager.h> #include <hwui/Typeface.h> #include <minikin/FontFamily.h> #include <minikin/SystemFonts.h> using namespace android; Loading Loading @@ -108,6 +110,7 @@ static jlong Typeface_createFromArray(JNIEnv *env, jobject, jlongArray familyArr // CriticalNative static void Typeface_setDefault(jlong faceHandle) { Typeface::setDefault(toTypeface(faceHandle)); minikin::SystemFonts::registerDefault(toTypeface(faceHandle)->fFontCollection); } static jobject Typeface_getSupportedAxes(JNIEnv *env, jobject, jlong faceHandle) { Loading @@ -128,6 +131,12 @@ static jobject Typeface_getSupportedAxes(JNIEnv *env, jobject, jlong faceHandle) return result; } static void Typeface_registerGenericFamily(JNIEnv *env, jobject, jstring familyName, jlong ptr) { ScopedUtfChars familyNameChars(env, familyName); minikin::SystemFonts::registerFallback(familyNameChars.c_str(), toTypeface(ptr)->fFontCollection); } /////////////////////////////////////////////////////////////////////////////// static const JNINativeMethod gTypefaceMethods[] = { Loading @@ -144,6 +153,8 @@ static const JNINativeMethod gTypefaceMethods[] = { (void*)Typeface_createFromArray }, { "nativeSetDefault", "(J)V", (void*)Typeface_setDefault }, { "nativeGetSupportedAxes", "(J)[I", (void*)Typeface_getSupportedAxes }, { "nativeRegisterGenericFamily", "(Ljava/lang/String;J)V", (void*)Typeface_registerGenericFamily }, }; int register_android_graphics_Typeface(JNIEnv* env) Loading
graphics/java/android/graphics/Typeface.java +18 −0 Original line number Diff line number Diff line Loading @@ -1115,6 +1115,13 @@ public class Typeface { } } private static void registerGenericFamilyNative(@NonNull String familyName, @Nullable Typeface typeface) { if (typeface != null) { nativeRegisterGenericFamily(familyName, typeface.native_instance); } } static { final HashMap<String, Typeface> systemFontMap = new HashMap<>(); initSystemDefaultTypefaces(systemFontMap, SystemFonts.getRawSystemFallbackMap(), Loading @@ -1140,6 +1147,15 @@ public class Typeface { create((String) null, Typeface.BOLD_ITALIC), }; // A list of generic families to be registered in native. // https://www.w3.org/TR/css-fonts-4/#generic-font-families String[] genericFamilies = { "serif", "sans-serif", "cursive", "fantasy", "monospace", "system-ui" }; for (String genericFamily : genericFamilies) { registerGenericFamilyNative(genericFamily, systemFontMap.get(genericFamily)); } } @Override Loading Loading @@ -1202,4 +1218,6 @@ public class Typeface { @CriticalNative private static native long nativeGetReleaseFunc(); private static native void nativeRegisterGenericFamily(String str, long nativePtr); }