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

Commit b26fa0ce authored by Victoria Lease's avatar Victoria Lease
Browse files

Fix fake bold for fallback fonts in frameworks.

This change is analogous to Ic0e9f1bbd8cae9fdd3a6d1d015bb9224c8be545c
in WebView, and depends upon the same Skia change that that CL makes
use of.

This flips the "fake bold" flag on for bold fonts in
TextView.setTypeface(), with the expectation that Skia will ignore
the flag if the final typeface used to render the glyphs is already
bold. It also does the same for StyleSpans, TextAppearanceSpans,
TypefaceSpans, and the Switch widget.

With this, fake bold should work uniformly across all scripts - if
fake bold works for a primary typeface, it should also work for all
fallback typefaces.

Bug: 6629786
Change-Id: Id3b8639ab0df83052ffd82809cb12adaacc1d46b
parent f27f2f8f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ public class StyleSpan extends MetricAffectingSpan implements ParcelableSpan {
        }

        int fake = want & ~tf.getStyle();
        fake |= tf.getStyle() & Typeface.BOLD;

        if ((fake & Typeface.BOLD) != 0) {
            paint.setFakeBoldText(true);
+1 −0
Original line number Diff line number Diff line
@@ -235,6 +235,7 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
            }

            int fake = style & ~tf.getStyle();
            fake |= tf.getStyle() & Typeface.BOLD;

            if ((fake & Typeface.BOLD) != 0) {
                ds.setFakeBoldText(true);
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ public class TypefaceSpan extends MetricAffectingSpan implements ParcelableSpan

        Typeface tf = Typeface.create(family, oldStyle);
        int fake = oldStyle & ~tf.getStyle();
        fake |= tf.getStyle() & Typeface.BOLD;

        if ((fake & Typeface.BOLD) != 0) {
            paint.setFakeBoldText(true);
+3 −1
Original line number Diff line number Diff line
@@ -259,10 +259,12 @@ public class Switch extends CompoundButton {
            // now compute what (if any) algorithmic styling is needed
            int typefaceStyle = tf != null ? tf.getStyle() : 0;
            int need = style & ~typefaceStyle;
            need |= typefaceStyle & Typeface.BOLD;
            mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
            mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
        } else {
            mTextPaint.setFakeBoldText(false);
            int typefaceStyle = tf != null ? tf.getStyle() : 0;
            mTextPaint.setFakeBoldText((typefaceStyle & Typeface.BOLD) != 0);
            mTextPaint.setTextSkewX(0);
            setSwitchTypeface(tf);
        }
+3 −1
Original line number Diff line number Diff line
@@ -1237,10 +1237,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            // now compute what (if any) algorithmic styling is needed
            int typefaceStyle = tf != null ? tf.getStyle() : 0;
            int need = style & ~typefaceStyle;
            need |= typefaceStyle & Typeface.BOLD; // keep bold in
            mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
            mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
        } else {
            mTextPaint.setFakeBoldText(false);
            int typefaceStyle = tf != null ? tf.getStyle() : 0;
            mTextPaint.setFakeBoldText((typefaceStyle & Typeface.BOLD) != 0);
            mTextPaint.setTextSkewX(0);
            setTypeface(tf);
        }