From fe8e21fd80f0594f2be341643ef52d2095eda3b6 Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Mon, 23 Sep 2013 08:32:16 -0400 Subject: [PATCH] Fix Java API error where requesting another style for a provided family fails Internally the API uses the same code path as SkTypeface::CreateFromName which returns NULL if the requested style is not supported by the existing family. However, the existing Java API expects that we return the default font in the requested style so this CL ensures that we do. bug: 10860066 Change-Id: Ide3a0cc24015e97fa35aef283b42e7d7d11edd9c --- core/jni/android/graphics/Typeface.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/jni/android/graphics/Typeface.cpp b/core/jni/android/graphics/Typeface.cpp index ff62fffc1029b..a7a0bb222cdf8 100644 --- a/core/jni/android/graphics/Typeface.cpp +++ b/core/jni/android/graphics/Typeface.cpp @@ -44,7 +44,13 @@ static SkTypeface* Typeface_create(JNIEnv* env, jobject, jstring name, } static SkTypeface* Typeface_createFromTypeface(JNIEnv* env, jobject, SkTypeface* family, int style) { - return SkTypeface::CreateFromTypeface(family, (SkTypeface::Style)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 + if (NULL == face) { + face = SkTypeface::CreateFromName(NULL, (SkTypeface::Style)style); + } + return face; } static void Typeface_unref(JNIEnv* env, jobject obj, SkTypeface* face) {