Merge "Update SystemFonts.getAvailableFonts returns updated font files" into sc-dev
This commit is contained in:
@@ -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);
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,29 +355,41 @@ 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)));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const JNINativeMethod gTypefaceMethods[] = {
|
||||
{ "nativeCreateFromTypeface", "(JI)J", (void*)Typeface_createFromTypeface },
|
||||
{ "nativeCreateFromTypefaceWithExactStyle", "(JIZ)J",
|
||||
(void*)Typeface_createFromTypefaceWithExactStyle },
|
||||
{ "nativeCreateFromTypefaceWithVariation", "(JLjava/util/List;)J",
|
||||
(void*)Typeface_createFromTypefaceWithVariation },
|
||||
{ "nativeCreateWeightAlias", "(JI)J", (void*)Typeface_createWeightAlias },
|
||||
{ "nativeGetReleaseFunc", "()J", (void*)Typeface_getReleaseFunc },
|
||||
{ "nativeGetStyle", "(J)I", (void*)Typeface_getStyle },
|
||||
{ "nativeGetWeight", "(J)I", (void*)Typeface_getWeight },
|
||||
{ "nativeCreateFromArray", "([JJII)J",
|
||||
(void*)Typeface_createFromArray },
|
||||
{ "nativeSetDefault", "(J)V", (void*)Typeface_setDefault },
|
||||
{ "nativeGetSupportedAxes", "(J)[I", (void*)Typeface_getSupportedAxes },
|
||||
{ "nativeRegisterGenericFamily", "(Ljava/lang/String;J)V",
|
||||
(void*)Typeface_registerGenericFamily },
|
||||
{ "nativeWriteTypefaces", "(Ljava/nio/ByteBuffer;[J)I", (void*)Typeface_writeTypefaces},
|
||||
{ "nativeReadTypefaces", "(Ljava/nio/ByteBuffer;)[J", (void*)Typeface_readTypefaces},
|
||||
{ "nativeForceSetStaticFinalField", "(Ljava/lang/String;Landroid/graphics/Typeface;)V",
|
||||
(void*)Typeface_forceSetStaticFinalField },
|
||||
{"nativeCreateFromTypeface", "(JI)J", (void*)Typeface_createFromTypeface},
|
||||
{"nativeCreateFromTypefaceWithExactStyle", "(JIZ)J",
|
||||
(void*)Typeface_createFromTypefaceWithExactStyle},
|
||||
{"nativeCreateFromTypefaceWithVariation", "(JLjava/util/List;)J",
|
||||
(void*)Typeface_createFromTypefaceWithVariation},
|
||||
{"nativeCreateWeightAlias", "(JI)J", (void*)Typeface_createWeightAlias},
|
||||
{"nativeGetReleaseFunc", "()J", (void*)Typeface_getReleaseFunc},
|
||||
{"nativeGetStyle", "(J)I", (void*)Typeface_getStyle},
|
||||
{"nativeGetWeight", "(J)I", (void*)Typeface_getWeight},
|
||||
{"nativeCreateFromArray", "([JJII)J", (void*)Typeface_createFromArray},
|
||||
{"nativeSetDefault", "(J)V", (void*)Typeface_setDefault},
|
||||
{"nativeGetSupportedAxes", "(J)[I", (void*)Typeface_getSupportedAxes},
|
||||
{"nativeRegisterGenericFamily", "(Ljava/lang/String;J)V",
|
||||
(void*)Typeface_registerGenericFamily},
|
||||
{"nativeWriteTypefaces", "(Ljava/nio/ByteBuffer;[J)I", (void*)Typeface_writeTypefaces},
|
||||
{"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)
|
||||
|
||||
Reference in New Issue
Block a user