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

Commit 690e62bb authored by Mihai Popa's avatar Mihai Popa
Browse files

Enable variation settings for fonts in XMLs

Bug: 37853920
Test: bit FrameworksCoreTests:android.content.res.FontResourcesParserTest

Change-Id: I1acf9767fb1cecc5f4982b79405f92280b31bfa7
parent 58488631
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -612,6 +612,7 @@ package android {
    field public static final int fontProviderPackage = 16844119; // 0x1010557
    field public static final int fontProviderQuery = 16844113; // 0x1010551
    field public static final int fontStyle = 16844095; // 0x101053f
    field public static final int fontVariationSettings = 16844144; // 0x1010570
    field public static final int fontWeight = 16844083; // 0x1010533
    field public static final int footerDividersEnabled = 16843311; // 0x101022f
    field public static final int forceHasOverlappingRendering = 16844065; // 0x1010521
+1 −0
Original line number Diff line number Diff line
@@ -744,6 +744,7 @@ package android {
    field public static final int fontProviderPackage = 16844119; // 0x1010557
    field public static final int fontProviderQuery = 16844113; // 0x1010551
    field public static final int fontStyle = 16844095; // 0x101053f
    field public static final int fontVariationSettings = 16844144; // 0x1010570
    field public static final int fontWeight = 16844083; // 0x1010533
    field public static final int footerDividersEnabled = 16843311; // 0x101022f
    field public static final int forceHasOverlappingRendering = 16844065; // 0x1010521
+1 −0
Original line number Diff line number Diff line
@@ -612,6 +612,7 @@ package android {
    field public static final int fontProviderPackage = 16844119; // 0x1010557
    field public static final int fontProviderQuery = 16844113; // 0x1010551
    field public static final int fontStyle = 16844095; // 0x101053f
    field public static final int fontVariationSettings = 16844144; // 0x1010570
    field public static final int fontWeight = 16844083; // 0x1010533
    field public static final int footerDividersEnabled = 16843311; // 0x101022f
    field public static final int forceHasOverlappingRendering = 16844065; // 0x1010521
+10 −2
Original line number Diff line number Diff line
@@ -80,13 +80,15 @@ public class FontResourcesParser {
        private int mWeight;
        private int mItalic;
        private int mTtcIndex;
        private String mVariationSettings;
        private int mResourceId;

        public FontFileResourceEntry(@NonNull String fileName, int weight, int italic,
                int ttcIndex) {
                @Nullable String variationSettings, int ttcIndex) {
            mFileName = fileName;
            mWeight = weight;
            mItalic = italic;
            mVariationSettings = variationSettings;
            mTtcIndex = ttcIndex;
        }

@@ -102,6 +104,10 @@ public class FontResourcesParser {
            return mItalic;
        }

        public @Nullable String getVariationSettings() {
            return mVariationSettings;
        }

        public int getTtcIndex() {
            return mTtcIndex;
        }
@@ -211,6 +217,8 @@ public class FontResourcesParser {
                Typeface.RESOLVE_BY_FONT_TABLE);
        int italic = array.getInt(R.styleable.FontFamilyFont_fontStyle,
                Typeface.RESOLVE_BY_FONT_TABLE);
        String variationSettings = array.getString(
                R.styleable.FontFamilyFont_fontVariationSettings);
        int ttcIndex = array.getInt(R.styleable.FontFamilyFont_ttcIndex, 0);
        String filename = array.getString(R.styleable.FontFamilyFont_font);
        array.recycle();
@@ -220,7 +228,7 @@ public class FontResourcesParser {
        if (filename == null) {
            return null;
        }
        return new FontFileResourceEntry(filename, weight, italic, ttcIndex);
        return new FontFileResourceEntry(filename, weight, italic, variationSettings, ttcIndex);
    }

    private static void skip(XmlPullParser parser) throws XmlPullParserException, IOException {
+5 −0
Original line number Diff line number Diff line
@@ -8673,6 +8673,11 @@
        <!-- The index of the font in the tcc font file. If the font file referenced is not in the
         tcc format, this attribute needs not be specified. -->
        <attr name="ttcIndex" format="integer" />
        <!-- The variation settings to be applied to the font. The string should be in the following
         format: "'tag1' value1, 'tag2' value2, ...". If the default variation settings should be
         used, or the font used does not support variation settings, this attribute needs not be
         specified. -->
        <attr name="fontVariationSettings" format="string" />
    </declare-styleable>

    <!-- Attributes that are read when parsing a <fontfamily> tag. -->
Loading