From ded5ed963c3939a2668ce1152ab60efb7bbbb2bd Mon Sep 17 00:00:00 2001 From: Victoria Lease Date: Tue, 12 Feb 2013 13:36:22 -0800 Subject: [PATCH] Count baseGlyphCount once for scripts without typefaces Characters from complex scripts without dedicated typefaces were getting baseGlyphCount counted twice: once in shapeFontRun() and then a second time during SkScalerContext::getNextContext() chaining. This was a problem for text runs beginning with full-width Latn characters - shapeFontRun() would get the base glyph count for the typeface containing those characters, then realise it had no typeface specified for the Latn script, resetting the typeface to default without resetting the base glyph count along with it. Mojibake full-width Latn characters, ho! The same issue also affected Cherokee text, which this fix also addresses. Bug: 8127795 Bug: 8034351 Change-Id: I058d81cffbbf86426cc3c5aafcc91a76f4fe6b62 --- core/jni/android/graphics/TextLayoutCache.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp index 75446459665e1..1ace23e22e417 100644 --- a/core/jni/android/graphics/TextLayoutCache.cpp +++ b/core/jni/android/graphics/TextLayoutCache.cpp @@ -785,10 +785,6 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* conte /** * Return the first typeface in the logical change, starting with this typeface, * that contains the specified unichar, or NULL if none is found. - * - * Note that this function does _not_ increment the reference count on the typeface, as the - * assumption is that its lifetime is managed elsewhere - in particular, the fallback typefaces - * for the default font live in a global cache. */ SkTypeface* TextLayoutShaper::typefaceForScript(const SkPaint* paint, SkTypeface* typeface, hb_script_t script) { @@ -798,7 +794,7 @@ SkTypeface* TextLayoutShaper::typefaceForScript(const SkPaint* paint, SkTypeface } typeface = SkCreateTypefaceForScriptNG(script, currentStyle); #if DEBUG_GLYPHS - ALOGD("Using Harfbuzz Script %d, Style %d", script, currentStyle); + ALOGD("Using Harfbuzz Script %c%c%c%c, Style %d", HB_UNTAG(script), currentStyle); #endif return typeface; } @@ -845,6 +841,7 @@ size_t TextLayoutShaper::shapeFontRun(const SkPaint* paint) { if (baseGlyphCount != 0) { typeface = typefaceForScript(paint, typeface, hb_buffer_get_script(mBuffer)); if (!typeface) { + baseGlyphCount = 0; typeface = mDefaultTypeface; SkSafeRef(typeface); #if DEBUG_GLYPHS