Increment text pointer when the width is zero in the subpixel with center and right...
authorherb <herb@google.com>
Thu, 12 Nov 2015 16:53:42 +0000 (08:53 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 12 Nov 2015 16:53:42 +0000 (08:53 -0800)
BUG=skia:

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

src/core/SkFindAndPlaceGlyph.h
tests/DrawTextTest.cpp

index 0280e90..3de4c61 100644 (file)
@@ -293,6 +293,8 @@ private:
                 const SkGlyph &metricGlyph = fGlyphCacheProc(fCache, &tempText, 0, 0);
 
                 if (metricGlyph.fWidth <= 0) {
+                    // Exiting early, be sure to update text pointer.
+                    *text = tempText;
                     return;
                 }
 
index 3a96c4f..f2da450 100644 (file)
@@ -74,33 +74,38 @@ DEF_TEST(DrawText, reporter) {
     create(&drawPosTextBitmap, drawPosTextRect);
     SkCanvas drawPosTextCanvas(drawPosTextBitmap);
 
-    for (float offsetY = 0.0f; offsetY < 1.0f; offsetY += (1.0f / 16.0f)) {
-        for (float offsetX = 0.0f; offsetX < 1.0f; offsetX += (1.0f / 16.0f)) {
-            SkPoint point = SkPoint::Make(25.0f + offsetX,
-                                          25.0f + offsetY);
-
-            for (int align = 0; align < SkPaint::kAlignCount; ++align) {
-                paint.setTextAlign(static_cast<SkPaint::Align>(align));
-
-                for (unsigned int flags = 0; flags < (1 << 3); ++flags) {
-                    static const unsigned int antiAliasFlag = 1;
-                    static const unsigned int subpixelFlag = 1 << 1;
-                    static const unsigned int lcdFlag = 1 << 2;
-
-                    paint.setAntiAlias(SkToBool(flags & antiAliasFlag));
-                    paint.setSubpixelText(SkToBool(flags & subpixelFlag));
-                    paint.setLCDRenderText(SkToBool(flags & lcdFlag));
-
-                    // Test: drawText and drawPosText draw the same.
-                    drawBG(&drawTextCanvas);
-                    drawTextCanvas.drawText("A", 1, point.fX, point.fY, paint);
-
-                    drawBG(&drawPosTextCanvas);
-                    drawPosTextCanvas.drawPosText("A", 1, &point, paint);
-
-                    REPORTER_ASSERT(reporter,
-                        compare(drawTextBitmap, drawTextRect,
-                                drawPosTextBitmap, drawPosTextRect));
+    // Two test cases "A" for the normal path through the code, and " " to check the
+    // early return path.
+    const char* cases[] = {"A", " "};
+    for (auto c : cases) {
+        for (float offsetY = 0.0f; offsetY < 1.0f; offsetY += (1.0f / 16.0f)) {
+            for (float offsetX = 0.0f; offsetX < 1.0f; offsetX += (1.0f / 16.0f)) {
+                SkPoint point = SkPoint::Make(25.0f + offsetX,
+                                              25.0f + offsetY);
+
+                for (int align = 0; align < SkPaint::kAlignCount; ++align) {
+                    paint.setTextAlign(static_cast<SkPaint::Align>(align));
+
+                    for (unsigned int flags = 0; flags < (1 << 3); ++flags) {
+                        static const unsigned int antiAliasFlag = 1;
+                        static const unsigned int subpixelFlag = 1 << 1;
+                        static const unsigned int lcdFlag = 1 << 2;
+
+                        paint.setAntiAlias(SkToBool(flags & antiAliasFlag));
+                        paint.setSubpixelText(SkToBool(flags & subpixelFlag));
+                        paint.setLCDRenderText(SkToBool(flags & lcdFlag));
+
+                        // Test: drawText and drawPosText draw the same.
+                        drawBG(&drawTextCanvas);
+                        drawTextCanvas.drawText(c, 1, point.fX, point.fY, paint);
+
+                        drawBG(&drawPosTextCanvas);
+                        drawPosTextCanvas.drawPosText(c, 1, &point, paint);
+
+                        REPORTER_ASSERT(reporter,
+                                        compare(drawTextBitmap, drawTextRect,
+                                                drawPosTextBitmap, drawPosTextRect));
+                    }
                 }
             }
         }