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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user