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

Commit b3372956 authored by Deepanshu Gupta's avatar Deepanshu Gupta Committed by Android (Google) Code Review
Browse files

Merge "LayoutLib: Better support for compact/elegant fonts." into lmp-preview-dev

parents 0a1335d7 86837dc2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -81,8 +81,8 @@ public class Paint_Delegate {
    private float mTextScaleX;
    private float mTextSkewX;
    private int mHintingMode = Paint.HINTING_ON;
    // Variant of the font.
    private FontVariant mFontVariant = FontVariant.NONE;
    // Variant of the font. A paint's variant can only be compact or elegant.
    private FontVariant mFontVariant = FontVariant.COMPACT;

    private Xfermode_Delegate mXfermode;
    private ColorFilter_Delegate mColorFilter;
+29 −11
Original line number Diff line number Diff line
@@ -70,29 +70,47 @@ public final class Typeface_Delegate {
        return sManager.getDelegate(nativeTypeface);
    }

    /**
     * Return a list of fonts that match the style and variant. The list is ordered according to
     * preference of fonts.
     *
     * @param variant The variant preferred. Can only be {@link FontVariant#COMPACT} or
     *                {@link FontVariant#ELEGANT}
     */
    public List<Font> getFonts(FontVariant variant) {
        assert variant != FontVariant.NONE;
        List<Font> fonts = new ArrayList<Font>(mFontFamilies.length);
        // If we are unable to find fonts matching the variant, we return the fonts from the
        // other variant since we always want to draw something, rather than nothing.
        // TODO: check this behaviour with platform.
        List<Font> otherVariantFonts = new ArrayList<Font>();
        for (FontFamily_Delegate ffd : mFontFamilies) {
        for (int i = 0; i < mFontFamilies.length; i++) {
            FontFamily_Delegate ffd = mFontFamilies[i];
            if (ffd != null) {
                Font font = ffd.getFont(mStyle);
                if (font != null) {
                    if (ffd.getVariant() == variant || ffd.getVariant() == FontVariant.NONE) {
                    FontVariant ffdVariant = ffd.getVariant();
                    if (ffdVariant == FontVariant.NONE) {
                        fonts.add(font);
                        continue;
                    }
                    // We cannot open each font and get locales supported, etc to match the fonts.
                    // As a workaround, we hardcode certain assumptions like Elegant and Compact
                    // always appear in pairs.
                    assert i < mFontFamilies.length - 1;
                    FontFamily_Delegate ffd2 = mFontFamilies[++i];
                    assert ffd2 != null;
                    FontVariant ffd2Variant = ffd2.getVariant();
                    Font font2 = ffd2.getFont(mStyle);
                    assert ffd2Variant != FontVariant.NONE && ffd2Variant != ffdVariant
                            && font2 != null;
                    // Add the font with the matching variant to the list.
                    if (variant == ffd.getVariant()) {
                        fonts.add(font);
                    } else {
                        otherVariantFonts.add(font);
                        fonts.add(font2);
                    }
                }
            }
        }
        if (fonts.size() > 0) {
        return fonts;
    }
        return otherVariantFonts;
    }

    // ---- native methods ----