Loading graphics/java/android/graphics/Typeface.java +17 −0 Original line number Diff line number Diff line Loading @@ -1414,6 +1414,16 @@ public class Typeface { return Arrays.binarySearch(mSupportedAxes, axis) >= 0; } /** @hide */ public List<FontFamily> getFallback() { ArrayList<FontFamily> families = new ArrayList<>(); int familySize = nativeGetFamilySize(native_instance); for (int i = 0; i < familySize; ++i) { families.add(new FontFamily(nativeGetFamily(native_instance, i))); } return families; } private static native long nativeCreateFromTypeface(long native_instance, int style); private static native long nativeCreateFromTypefaceWithExactStyle( long native_instance, int weight, boolean italic); Loading @@ -1439,6 +1449,13 @@ public class Typeface { @CriticalNative private static native long nativeGetReleaseFunc(); @CriticalNative private static native int nativeGetFamilySize(long naitvePtr); @CriticalNative private static native long nativeGetFamily(long nativePtr, int index); private static native void nativeRegisterGenericFamily(String str, long nativePtr); private static native int nativeWriteTypefaces( Loading graphics/java/android/graphics/fonts/FontFamily.java +3 −2 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ public final class FontFamily { nAddFont(builderPtr, mFonts.get(i).getNativePtr()); } final long ptr = nBuild(builderPtr, langTags, variant, isCustomFallback); final FontFamily family = new FontFamily(mFonts, ptr); final FontFamily family = new FontFamily(ptr); sFamilyRegistory.registerNativeAllocation(family, ptr); return family; } Loading @@ -146,7 +146,8 @@ public final class FontFamily { private final long mNativePtr; // Use Builder instead. private FontFamily(@NonNull ArrayList<Font> fonts, long ptr) { /** @hide */ public FontFamily(long ptr) { mNativePtr = ptr; } Loading graphics/java/android/graphics/fonts/SystemFonts.java +7 −37 Original line number Diff line number Diff line Loading @@ -68,44 +68,23 @@ public final class SystemFonts { */ public static @NonNull Set<Font> getAvailableFonts() { synchronized (LOCK) { if (sAvailableFonts != null) { return sAvailableFonts; } if (Typeface.ENABLE_LAZY_TYPEFACE_INITIALIZATION) { sAvailableFonts = collectAllFonts(); } else { if (sAvailableFonts == null) { Set<Font> set = new ArraySet<>(); for (FontFamily[] items : sFamilyMap.values()) { for (FontFamily family : items) { for (int i = 0; i < family.getSize(); ++i) { set.add(family.getFont(i)); for (Typeface tf : Typeface.getSystemFontMap().values()) { List<FontFamily> families = tf.getFallback(); for (int i = 0; i < families.size(); ++i) { FontFamily family = families.get(i); for (int j = 0; j < family.getSize(); ++j) { set.add(family.getFont(j)); } } } sAvailableFonts = Collections.unmodifiableSet(set); } return sAvailableFonts; } } private static @NonNull Set<Font> collectAllFonts() { // TODO: use updated fonts FontConfig fontConfig = getSystemPreinstalledFontConfig(); Map<String, FontFamily[]> map = buildSystemFallback(fontConfig); Set<Font> res = new ArraySet<>(); for (FontFamily[] families : map.values()) { for (FontFamily family : families) { for (int i = 0; i < family.getSize(); ++i) { res.add(family.getFont(i)); } } } return res; } private static @Nullable ByteBuffer mmap(@NonNull String fullPath) { try (FileInputStream file = new FileInputStream(fullPath)) { final FileChannel fileChannel = file.getChannel(); Loading Loading @@ -329,13 +308,4 @@ public final class SystemFonts { Typeface.initSystemDefaultTypefaces(fallbackMap, fontConfig.getAliases(), result); return result; } /** * @hide */ public void resetFallbackMapping(Map<String, FontFamily[]> fallbackMap) { synchronized (LOCK) { sFamilyMap = fallbackMap; } } } libs/hwui/jni/Typeface.cpp +31 −19 Original line number Diff line number Diff line Loading @@ -355,6 +355,17 @@ static void Typeface_forceSetStaticFinalField(JNIEnv *env, jclass cls, jstring f env->SetStaticObjectField(cls, fid, typeface); } // Critical Native static jint Typeface_getFamilySize(CRITICAL_JNI_PARAMS_COMMA jlong faceHandle) { return toTypeface(faceHandle)->fFontCollection->getFamilies().size(); } // Critical Native static jlong Typeface_getFamily(CRITICAL_JNI_PARAMS_COMMA jlong faceHandle, jint index) { std::shared_ptr<minikin::FontFamily> family = toTypeface(faceHandle)->fFontCollection->getFamilies()[index]; return reinterpret_cast<jlong>(new FontFamilyWrapper(std::move(family))); } /////////////////////////////////////////////////////////////////////////////// Loading @@ -368,8 +379,7 @@ static const JNINativeMethod gTypefaceMethods[] = { {"nativeGetReleaseFunc", "()J", (void*)Typeface_getReleaseFunc}, {"nativeGetStyle", "(J)I", (void*)Typeface_getStyle}, {"nativeGetWeight", "(J)I", (void*)Typeface_getWeight}, { "nativeCreateFromArray", "([JJII)J", (void*)Typeface_createFromArray }, {"nativeCreateFromArray", "([JJII)J", (void*)Typeface_createFromArray}, {"nativeSetDefault", "(J)V", (void*)Typeface_setDefault}, {"nativeGetSupportedAxes", "(J)[I", (void*)Typeface_getSupportedAxes}, {"nativeRegisterGenericFamily", "(Ljava/lang/String;J)V", Loading @@ -378,6 +388,8 @@ static const JNINativeMethod gTypefaceMethods[] = { {"nativeReadTypefaces", "(Ljava/nio/ByteBuffer;)[J", (void*)Typeface_readTypefaces}, {"nativeForceSetStaticFinalField", "(Ljava/lang/String;Landroid/graphics/Typeface;)V", (void*)Typeface_forceSetStaticFinalField}, {"nativeGetFamilySize", "(J)I", (void*)Typeface_getFamilySize}, {"nativeGetFamily", "(JI)J", (void*)Typeface_getFamily}, }; int register_android_graphics_Typeface(JNIEnv* env) Loading Loading
graphics/java/android/graphics/Typeface.java +17 −0 Original line number Diff line number Diff line Loading @@ -1414,6 +1414,16 @@ public class Typeface { return Arrays.binarySearch(mSupportedAxes, axis) >= 0; } /** @hide */ public List<FontFamily> getFallback() { ArrayList<FontFamily> families = new ArrayList<>(); int familySize = nativeGetFamilySize(native_instance); for (int i = 0; i < familySize; ++i) { families.add(new FontFamily(nativeGetFamily(native_instance, i))); } return families; } private static native long nativeCreateFromTypeface(long native_instance, int style); private static native long nativeCreateFromTypefaceWithExactStyle( long native_instance, int weight, boolean italic); Loading @@ -1439,6 +1449,13 @@ public class Typeface { @CriticalNative private static native long nativeGetReleaseFunc(); @CriticalNative private static native int nativeGetFamilySize(long naitvePtr); @CriticalNative private static native long nativeGetFamily(long nativePtr, int index); private static native void nativeRegisterGenericFamily(String str, long nativePtr); private static native int nativeWriteTypefaces( Loading
graphics/java/android/graphics/fonts/FontFamily.java +3 −2 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ public final class FontFamily { nAddFont(builderPtr, mFonts.get(i).getNativePtr()); } final long ptr = nBuild(builderPtr, langTags, variant, isCustomFallback); final FontFamily family = new FontFamily(mFonts, ptr); final FontFamily family = new FontFamily(ptr); sFamilyRegistory.registerNativeAllocation(family, ptr); return family; } Loading @@ -146,7 +146,8 @@ public final class FontFamily { private final long mNativePtr; // Use Builder instead. private FontFamily(@NonNull ArrayList<Font> fonts, long ptr) { /** @hide */ public FontFamily(long ptr) { mNativePtr = ptr; } Loading
graphics/java/android/graphics/fonts/SystemFonts.java +7 −37 Original line number Diff line number Diff line Loading @@ -68,44 +68,23 @@ public final class SystemFonts { */ public static @NonNull Set<Font> getAvailableFonts() { synchronized (LOCK) { if (sAvailableFonts != null) { return sAvailableFonts; } if (Typeface.ENABLE_LAZY_TYPEFACE_INITIALIZATION) { sAvailableFonts = collectAllFonts(); } else { if (sAvailableFonts == null) { Set<Font> set = new ArraySet<>(); for (FontFamily[] items : sFamilyMap.values()) { for (FontFamily family : items) { for (int i = 0; i < family.getSize(); ++i) { set.add(family.getFont(i)); for (Typeface tf : Typeface.getSystemFontMap().values()) { List<FontFamily> families = tf.getFallback(); for (int i = 0; i < families.size(); ++i) { FontFamily family = families.get(i); for (int j = 0; j < family.getSize(); ++j) { set.add(family.getFont(j)); } } } sAvailableFonts = Collections.unmodifiableSet(set); } return sAvailableFonts; } } private static @NonNull Set<Font> collectAllFonts() { // TODO: use updated fonts FontConfig fontConfig = getSystemPreinstalledFontConfig(); Map<String, FontFamily[]> map = buildSystemFallback(fontConfig); Set<Font> res = new ArraySet<>(); for (FontFamily[] families : map.values()) { for (FontFamily family : families) { for (int i = 0; i < family.getSize(); ++i) { res.add(family.getFont(i)); } } } return res; } private static @Nullable ByteBuffer mmap(@NonNull String fullPath) { try (FileInputStream file = new FileInputStream(fullPath)) { final FileChannel fileChannel = file.getChannel(); Loading Loading @@ -329,13 +308,4 @@ public final class SystemFonts { Typeface.initSystemDefaultTypefaces(fallbackMap, fontConfig.getAliases(), result); return result; } /** * @hide */ public void resetFallbackMapping(Map<String, FontFamily[]> fallbackMap) { synchronized (LOCK) { sFamilyMap = fallbackMap; } } }
libs/hwui/jni/Typeface.cpp +31 −19 Original line number Diff line number Diff line Loading @@ -355,6 +355,17 @@ static void Typeface_forceSetStaticFinalField(JNIEnv *env, jclass cls, jstring f env->SetStaticObjectField(cls, fid, typeface); } // Critical Native static jint Typeface_getFamilySize(CRITICAL_JNI_PARAMS_COMMA jlong faceHandle) { return toTypeface(faceHandle)->fFontCollection->getFamilies().size(); } // Critical Native static jlong Typeface_getFamily(CRITICAL_JNI_PARAMS_COMMA jlong faceHandle, jint index) { std::shared_ptr<minikin::FontFamily> family = toTypeface(faceHandle)->fFontCollection->getFamilies()[index]; return reinterpret_cast<jlong>(new FontFamilyWrapper(std::move(family))); } /////////////////////////////////////////////////////////////////////////////// Loading @@ -368,8 +379,7 @@ static const JNINativeMethod gTypefaceMethods[] = { {"nativeGetReleaseFunc", "()J", (void*)Typeface_getReleaseFunc}, {"nativeGetStyle", "(J)I", (void*)Typeface_getStyle}, {"nativeGetWeight", "(J)I", (void*)Typeface_getWeight}, { "nativeCreateFromArray", "([JJII)J", (void*)Typeface_createFromArray }, {"nativeCreateFromArray", "([JJII)J", (void*)Typeface_createFromArray}, {"nativeSetDefault", "(J)V", (void*)Typeface_setDefault}, {"nativeGetSupportedAxes", "(J)[I", (void*)Typeface_getSupportedAxes}, {"nativeRegisterGenericFamily", "(Ljava/lang/String;J)V", Loading @@ -378,6 +388,8 @@ static const JNINativeMethod gTypefaceMethods[] = { {"nativeReadTypefaces", "(Ljava/nio/ByteBuffer;)[J", (void*)Typeface_readTypefaces}, {"nativeForceSetStaticFinalField", "(Ljava/lang/String;Landroid/graphics/Typeface;)V", (void*)Typeface_forceSetStaticFinalField}, {"nativeGetFamilySize", "(J)I", (void*)Typeface_getFamilySize}, {"nativeGetFamily", "(JI)J", (void*)Typeface_getFamily}, }; int register_android_graphics_Typeface(JNIEnv* env) Loading