diff options
| author | 2013-11-06 19:30:22 +0000 | |
|---|---|---|
| committer | 2013-11-06 19:30:23 +0000 | |
| commit | c89eaf916ad7e88565d2a15991432b22cd9099ff (patch) | |
| tree | 39ba60a6f514b7d05edd2c7e675f082ef731eaf9 | |
| parent | 04cead14b627947df7f1b713c35a3e03bef94286 (diff) | |
| parent | 4f0064fa3448c95e116a8d5646547a7a0fa8a432 (diff) | |
Merge "Fix for Typeface.create(Typeface, style) semantics changed in KK" into klp-dev
| -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 a7a0bb222cdf..ccd75d565ae5 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); } |