diff options
author | Raph Levien <raph@google.com> | 2013-11-06 11:12:11 -0800 |
---|---|---|
committer | Raph Levien <raph@google.com> | 2013-11-06 11:16:01 -0800 |
commit | 4f0064fa3448c95e116a8d5646547a7a0fa8a432 (patch) | |
tree | c801159ccd2545cd3d4b403a4fa4191c21361483 | |
parent | a80d6424987602cc3141d4cb4cdee21a54747691 (diff) | |
download | frameworks_base-4f0064fa3448c95e116a8d5646547a7a0fa8a432.zip frameworks_base-4f0064fa3448c95e116a8d5646547a7a0fa8a432.tar.gz frameworks_base-4f0064fa3448c95e116a8d5646547a7a0fa8a432.tar.bz2 |
Fix for Typeface.create(Typeface, style) semantics changed in KK
This is a fix for bug 11553661. The "closest match" heuristic for
resolving a typeface when an exact match was not found changed between
JB MR2 and KK, resulting in loss of custom typeface when StyleSpan was
applied. This patch reinstates the logic that had been present. Also
reported externally as:
https://code.google.com/p/android/issues/detail?id=61771
Change-Id: Ia432fca07c4bf3b830ee2487cd8f5267a9cfb7ff
-rw-r--r-- | core/jni/android/graphics/Typeface.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/core/jni/android/graphics/Typeface.cpp b/core/jni/android/graphics/Typeface.cpp index a7a0bb2..ccd75d5 100644 --- a/core/jni/android/graphics/Typeface.cpp +++ b/core/jni/android/graphics/Typeface.cpp @@ -34,6 +34,13 @@ static SkTypeface* Typeface_create(JNIEnv* env, jobject, jstring name, if (NULL != name) { AutoJavaStringToUTF8 str(env, name); face = SkTypeface::CreateFromName(str.c_str(), style); + // Try to find the closest matching font, using the standard heuristic + if (NULL == face) { + face = SkTypeface::CreateFromName(str.c_str(), (SkTypeface::Style)(style ^ SkTypeface::kItalic)); + } + for (int i = 0; NULL == face && i < 4; i++) { + face = SkTypeface::CreateFromName(str.c_str(), (SkTypeface::Style)i); + } } // return the default font at the best style if no exact match exists @@ -45,8 +52,13 @@ static SkTypeface* Typeface_create(JNIEnv* env, jobject, jstring name, static SkTypeface* Typeface_createFromTypeface(JNIEnv* env, jobject, SkTypeface* family, int style) { SkTypeface* face = SkTypeface::CreateFromTypeface(family, (SkTypeface::Style)style); - // return the default font at the best style if the requested style does not - // exist in the provided family + // Try to find the closest matching font, using the standard heuristic + if (NULL == face) { + face = SkTypeface::CreateFromTypeface(family, (SkTypeface::Style)(style ^ SkTypeface::kItalic)); + } + for (int i = 0; NULL == face && i < 4; i++) { + face = SkTypeface::CreateFromTypeface(family, (SkTypeface::Style)i); + } if (NULL == face) { face = SkTypeface::CreateFromName(NULL, (SkTypeface::Style)style); } |