[TextBlob] Fall back to TightRunBounds when the font bounds are empty
authorfmalita <fmalita@chromium.org>
Mon, 10 Aug 2015 16:24:31 +0000 (09:24 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 10 Aug 2015 16:24:31 +0000 (09:24 -0700)
Empty font bounds are likely an indication of a font bug.  As a best
effort, we can use TightRunBounds in this easily detectable case.

BUG=507022
R=reed@google.com,bungeman@google.com

Review URL: https://codereview.chromium.org/1284693002

src/core/SkTextBlob.cpp

index d1a77e7..4ba7df8 100644 (file)
@@ -382,7 +382,16 @@ SkRect SkTextBlobBuilder::ConservativeRunBounds(const SkTextBlob::RunRecord& run
     SkASSERT(SkTextBlob::kFull_Positioning == run.positioning() ||
              SkTextBlob::kHorizontal_Positioning == run.positioning());
 
-    // First, compute the glyph position bbox.
+    SkPaint paint;
+    run.font().applyToPaint(&paint);
+    const SkRect fontBounds = paint.getFontBounds();
+    if (fontBounds.isEmpty()) {
+        // Empty font bounds are likely a font bug.  TightBounds has a better chance of
+        // producing useful results in this case.
+        return TightRunBounds(run);
+    }
+
+    // Compute the glyph position bbox.
     SkRect bounds;
     switch (run.positioning()) {
     case SkTextBlob::kHorizontal_Positioning: {
@@ -410,9 +419,6 @@ SkRect SkTextBlobBuilder::ConservativeRunBounds(const SkTextBlob::RunRecord& run
     }
 
     // Expand by typeface glyph bounds.
-    SkPaint paint;
-    run.font().applyToPaint(&paint);
-    const SkRect fontBounds = paint.getFontBounds();
     bounds.fLeft   += fontBounds.left();
     bounds.fTop    += fontBounds.top();
     bounds.fRight  += fontBounds.right();