Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf3c622e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use fonts_fallback XML only when flag is ON." into main

parents ccd8b9ec 5da9ab7a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
package: "com.android.text.flags"

flag {
  name: "deprecate_fonts_xml"
  namespace: "text"
  description: "Feature flag for deprecating fonts.xml. By setting true for this feature flag, the new font configuration XML, /system/etc/font_fallback.xml is used. The new XML has a new syntax and flexibility of variable font declarations, but it is not compatible with the apps that reads fonts.xml. So, fonts.xml is maintained as a subset of the font_fallback.xml"
  bug: "281769620"
}
+4 −1
Original line number Diff line number Diff line
@@ -1475,7 +1475,10 @@ public class Typeface {
        String locale = SystemProperties.get("persist.sys.locale", "en-US");
        String script = ULocale.addLikelySubtags(ULocale.forLanguageTag(locale)).getScript();

        FontConfig config = SystemFonts.getSystemPreinstalledFontConfig();
        // The feature flag cannot be referred from Zygote. Use legacy fonts.xml for preloading font
        // files.
        // TODO(nona): Use new XML file once the feature is fully launched.
        FontConfig config = SystemFonts.getSystemPreinstalledFontConfigFromLegacyXml();
        for (int i = 0; i < config.getFontFamilies().size(); ++i) {
            FontConfig.FontFamily family = config.getFontFamilies().get(i);
            if (!family.getLocaleList().isEmpty()) {
+24 −2
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ public final class SystemFonts {
    private static final String TAG = "SystemFonts";

    private static final String FONTS_XML = "/system/etc/font_fallback.xml";
    private static final String LEGACY_FONTS_XML = "/system/etc/fonts.xml";

    /** @hide */
    public static final String SYSTEM_FONT_DIR = "/system/fonts/";
    private static final String OEM_XML = "/product/etc/fonts_customization.xml";
@@ -230,7 +232,13 @@ public final class SystemFonts {
            long lastModifiedDate,
            int configVersion
    ) {
        return getSystemFontConfigInternal(FONTS_XML, SYSTEM_FONT_DIR, OEM_XML, OEM_FONT_DIR,
        final String fontsXml;
        if (com.android.text.flags.Flags.deprecateFontsXml()) {
            fontsXml = FONTS_XML;
        } else {
            fontsXml = LEGACY_FONTS_XML;
        }
        return getSystemFontConfigInternal(fontsXml, SYSTEM_FONT_DIR, OEM_XML, OEM_FONT_DIR,
                updatableFontMap, lastModifiedDate, configVersion);
    }

@@ -255,10 +263,24 @@ public final class SystemFonts {
     * @hide
     */
    public static @NonNull FontConfig getSystemPreinstalledFontConfig() {
        return getSystemFontConfigInternal(FONTS_XML, SYSTEM_FONT_DIR, OEM_XML, OEM_FONT_DIR, null,
        final String fontsXml;
        if (com.android.text.flags.Flags.deprecateFontsXml()) {
            fontsXml = FONTS_XML;
        } else {
            fontsXml = LEGACY_FONTS_XML;
        }
        return getSystemFontConfigInternal(fontsXml, SYSTEM_FONT_DIR, OEM_XML, OEM_FONT_DIR, null,
                0, 0);
    }

    /**
     * @hide
     */
    public static @NonNull FontConfig getSystemPreinstalledFontConfigFromLegacyXml() {
        return getSystemFontConfigInternal(LEGACY_FONTS_XML, SYSTEM_FONT_DIR, OEM_XML, OEM_FONT_DIR,
                null, 0, 0);
    }

    /* package */ static @NonNull FontConfig getSystemFontConfigInternal(
            @NonNull String fontsXml,
            @NonNull String systemFontDir,