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:
Victoria Lease
2012-06-08 10:25:19 -07:00
parent f27f2f8f71
commit b26fa0ce68
5 changed files with 9 additions and 2 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
}