OSDN Git Service

use appropriate fallback chain for style
authorVictoria Lease <violets@google.com>
Mon, 15 Apr 2013 22:29:36 +0000 (15:29 -0700)
committerVictoria Lease <violets@google.com>
Tue, 16 Apr 2013 16:51:45 +0000 (09:51 -0700)
TextLayoutShaper was defaulting to the Regular-style fallback chain
for all unknown scripts. This became problematic in that the
codepoint->glyphID enumeration stage of shaping was always using the
Regular-style fallback chain for unknown scripts, and there's no
guarantee that glyph indices are compatible between fallback chains.

Defaulting to a style-appropriate fallback chain addresses this
issue, and probably unreported but related issues, as well.

Bug: 8189208
Change-Id: I6ecf531c74d71a8e4a5359d23439ccc950b0cf80

core/jni/android/graphics/TextLayoutCache.cpp
core/jni/android/graphics/TextLayoutCache.h

index 1ace23e..17f205d 100644 (file)
@@ -339,23 +339,11 @@ uint32_t TextLayoutValue::getElapsedTime() {
 }
 
 TextLayoutShaper::TextLayoutShaper() {
-    init();
-
     mBuffer = hb_buffer_create();
 }
 
-void TextLayoutShaper::init() {
-    mDefaultTypeface = SkFontHost::CreateTypeface(NULL, NULL, SkTypeface::kNormal);
-}
-
-void TextLayoutShaper::unrefTypefaces() {
-    SkSafeUnref(mDefaultTypeface);
-}
-
 TextLayoutShaper::~TextLayoutShaper() {
     hb_buffer_destroy(mBuffer);
-
-    unrefTypefaces();
 }
 
 void TextLayoutShaper::computeValues(TextLayoutValue* value, const SkPaint* paint, const UChar* chars,
@@ -839,23 +827,27 @@ size_t TextLayoutShaper::shapeFontRun(const SkPaint* paint) {
     }
 
     if (baseGlyphCount != 0) {
+        SkTypeface::Style style = SkTypeface::kNormal;
+        if (typeface != NULL) {
+            style = typeface->style();
+        }
         typeface = typefaceForScript(paint, typeface, hb_buffer_get_script(mBuffer));
         if (!typeface) {
             baseGlyphCount = 0;
-            typeface = mDefaultTypeface;
-            SkSafeRef(typeface);
+            typeface = SkFontHost::CreateTypeface(NULL, NULL, style);
 #if DEBUG_GLYPHS
             ALOGD("Using Default Typeface");
 #endif
         }
     } else {
         if (!typeface) {
-            typeface = mDefaultTypeface;
+            typeface = SkFontHost::CreateTypeface(NULL, NULL, SkTypeface::kNormal);
 #if DEBUG_GLYPHS
-            ALOGD("Using Default Typeface");
+            ALOGD("Using Default Typeface (normal style)");
 #endif
+        } else {
+            SkSafeRef(typeface);
         }
-        SkSafeRef(typeface);
     }
 
     mShapingPaint.setTypeface(typeface);
@@ -899,8 +891,6 @@ void TextLayoutShaper::purgeCaches() {
         hb_face_destroy(mCachedHBFaces.valueAt(i));
     }
     mCachedHBFaces.clear();
-    unrefTypefaces();
-    init();
 }
 
 TextLayoutEngine::TextLayoutEngine() {
index f9b9900..5414a11 100644 (file)
@@ -197,18 +197,10 @@ private:
     SkPaint mShapingPaint;
 
     /**
-     * Skia default typeface to be returned if we cannot resolve script
-     */
-    SkTypeface* mDefaultTypeface;
-
-    /**
      * Cache of Harfbuzz faces
      */
     KeyedVector<SkFontID, hb_face_t*> mCachedHBFaces;
 
-    void init();
-    void unrefTypefaces();
-
     SkTypeface* typefaceForScript(const SkPaint* paint, SkTypeface* typeface,
         hb_script_t script);
 
@@ -228,7 +220,6 @@ private:
     hb_face_t* referenceCachedHBFace(SkTypeface* typeface);
 
     bool isComplexScript(hb_script_t script);
-
 }; // TextLayoutShaper
 
 /**