From 1aa57ec5c581ddaec5f677c332af54dc80bb9223 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 3 Dec 2020 20:02:16 -0800 Subject: [PATCH] Parse fonts.xml when SystemFonts#getAvailableFonts is called The fonts.xml is no longer parsed once we move to new model. Thus, need to parse fonts.xml when SystemFonts#getAvailableFonts is called. Bug: 173752727 Test: atest NativeSystemFontTest Change-Id: I628a2586f8450b942caf34ede5dc827e31fff0ef --- .../android/graphics/fonts/SystemFonts.java | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/graphics/java/android/graphics/fonts/SystemFonts.java b/graphics/java/android/graphics/fonts/SystemFonts.java index 28943baf95035..fb6ea99be7ab6 100644 --- a/graphics/java/android/graphics/fonts/SystemFonts.java +++ b/graphics/java/android/graphics/fonts/SystemFonts.java @@ -88,31 +88,19 @@ public final class SystemFonts { } private static @NonNull Set collectAllFonts() { - Map map = Typeface.getSystemFontMap(); - HashSet seenFonts = new HashSet<>(); - HashSet result = new HashSet<>(); - for (Typeface typeface : map.values()) { - List families = NativeFont.readTypeface(typeface); - for (NativeFont.Family family : families) { - for (NativeFont.Font font : family.getFonts()) { - if (seenFonts.contains(font)) { - continue; - } - seenFonts.add(font); - try { - result.add(new Font.Builder(font.getFile(), family.getLocale()) - .setFontVariationSettings(font.getAxes()) - .setTtcIndex(font.getIndex()) - .setWeight(font.getStyle().getWeight()) - .setSlant(font.getStyle().getSlant()) - .build()); - } catch (IOException e) { - Log.w(TAG, "Failed to load " + font.getFile(), e); - } + final FontCustomizationParser.Result oemCustomization = + readFontCustomization("/product/etc/fonts_customization.xml", "/product/fonts/"); + Map map = new ArrayMap<>(); + buildSystemFallback("/system/etc/fonts.xml", "/system/fonts/", oemCustomization, map); + Set res = new HashSet<>(); + for (FontFamily[] families : map.values()) { + for (FontFamily family : families) { + for (int i = 0; i < family.getSize(); ++i) { + res.add(family.getFont(i)); } } } - return result; + return res; } private static @Nullable ByteBuffer mmap(@NonNull String fullPath) {