From 38fbc56351ecceb851f26f73602344c2d71c6121 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 25 Mar 2021 15:15:58 -0700 Subject: Use separate XML for update config in system This CL is a refactoring to address following things: - Separate XML definition of fonts.xml and update. Since there are lots of concept mismatches between system font config and update config, e.g. file paths, family variants, etc. It is good to manage separtely. - Stop keeping udpated config in memory in FontManagerService. As a side effect of above change, FontManagerService no longer keeps FontConfig.FontFamily mappings. This will be created from XML file when necessary. This is better in FontManagerService since this map is only necessary the boot time. After the system is booted, this map is only necessary when the update request is called from client which happens quite rare. Bug: 183752879 Test: atest UpdatableFontDirTest Test: atest FontManagerTest Test: atest UpdatableSystemFontTest Test: atest FontFamilyUpdateRequestTest Test: atest PersistentSystemFontConfigTest Change-Id: If2c12a8029f859efc52721b07cfeab04be2deb78 --- graphics/java/android/graphics/FontListParser.java | 62 ---------------------- 1 file changed, 62 deletions(-) (limited to 'graphics/java/android') diff --git a/graphics/java/android/graphics/FontListParser.java b/graphics/java/android/graphics/FontListParser.java index 95c7715a1688..6fdf5526edf5 100644 --- a/graphics/java/android/graphics/FontListParser.java +++ b/graphics/java/android/graphics/FontListParser.java @@ -25,8 +25,6 @@ import android.graphics.fonts.FontVariationAxis; import android.os.Build; import android.os.LocaleList; import android.text.FontConfig; -import android.text.TextUtils; -import android.util.TypedXmlSerializer; import android.util.Xml; import org.xmlpull.v1.XmlPullParser; @@ -194,32 +192,6 @@ public class FontListParser { return new FontConfig.FontFamily(fonts, name, LocaleList.forLanguageTags(lang), intVariant); } - /** - * Write a family tag representing {@code fontFamily}. The tag should be started by the caller. - */ - public static void writeFamily(TypedXmlSerializer out, FontConfig.FontFamily fontFamily) - throws IOException { - if (!TextUtils.isEmpty(fontFamily.getName())) { - out.attribute(null, ATTR_NAME, fontFamily.getName()); - } - if (!fontFamily.getLocaleList().isEmpty()) { - out.attribute(null, ATTR_LANG, fontFamily.getLocaleList().toLanguageTags()); - } - switch (fontFamily.getVariant()) { - case FontConfig.FontFamily.VARIANT_COMPACT: - out.attribute(null, ATTR_VARIANT, VARIANT_COMPACT); - break; - case FontConfig.FontFamily.VARIANT_ELEGANT: - out.attribute(null, ATTR_VARIANT, VARIANT_ELEGANT); - break; - } - for (FontConfig.Font font : fontFamily.getFontList()) { - out.startTag(null, TAG_FONT); - writeFont(out, font); - out.endTag(null, TAG_FONT); - } - } - /** Matches leading and trailing XML whitespace. */ private static final Pattern FILENAME_WHITESPACE_PATTERN = Pattern.compile("^[ \\n\\r\\t]+|[ \\n\\r\\t]+$"); @@ -292,34 +264,6 @@ public class FontListParser { return null; } - private static void writeFont(TypedXmlSerializer out, FontConfig.Font font) - throws IOException { - if (font.getTtcIndex() != 0) { - out.attributeInt(null, ATTR_INDEX, font.getTtcIndex()); - } - if (font.getStyle().getWeight() != FontStyle.FONT_WEIGHT_NORMAL) { - out.attributeInt(null, ATTR_WEIGHT, font.getStyle().getWeight()); - } - if (font.getStyle().getSlant() == FontStyle.FONT_SLANT_ITALIC) { - out.attribute(null, ATTR_STYLE, STYLE_ITALIC); - } else { - out.attribute(null, ATTR_STYLE, STYLE_NORMAL); - } - if (!TextUtils.isEmpty(font.getFontFamilyName())) { - out.attribute(null, ATTR_FALLBACK_FOR, font.getFontFamilyName()); - } - out.text(font.getFile().getName()); - FontVariationAxis[] axes = - FontVariationAxis.fromFontVariationSettings(font.getFontVariationSettings()); - if (axes != null) { - for (FontVariationAxis axis : axes) { - out.startTag(null, TAG_AXIS); - writeAxis(out, axis); - out.endTag(null, TAG_AXIS); - } - } - } - private static FontVariationAxis readAxis(XmlPullParser parser) throws XmlPullParserException, IOException { String tagStr = parser.getAttributeValue(null, ATTR_TAG); @@ -328,12 +272,6 @@ public class FontListParser { return new FontVariationAxis(tagStr, Float.parseFloat(styleValueStr)); } - private static void writeAxis(TypedXmlSerializer out, FontVariationAxis axis) - throws IOException { - out.attribute(null, ATTR_TAG, axis.getTag()); - out.attributeFloat(null, ATTR_STYLEVALUE, axis.getStyleValue()); - } - /** * Reads alias elements */ -- cgit v1.2.3-59-g8ed1b