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
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user