Fix TextBlobTest valgrind error
authorfmalita <fmalita@chromium.org>
Wed, 14 Oct 2015 15:11:40 +0000 (08:11 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 14 Oct 2015 15:11:40 +0000 (08:11 -0700)
When converting text to glyph IDs, the paint needs to reflect the actual
text encoding.

R=bungeman@google.com,herb@google.com

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

tests/TextBlobTest.cpp

index 2a74e5a..027fd2a 100644 (file)
@@ -11,7 +11,6 @@
 
 #include "Test.h"
 
-
 class TextBlobTester {
 public:
     // This unit test feeds an SkTextBlobBuilder various runs then checks to see if
@@ -155,13 +154,19 @@ public:
             // don't trigger asserts (http://crbug.com/542643).
             SkPaint p;
             p.setTextSize(0);
-            p.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+            p.setTextEncoding(SkPaint::kUTF8_TextEncoding);
 
             const char* txt = "BOOO";
-            const size_t len = strlen(txt);
-            const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(p, (int)len);
-            p.textToGlyphs(txt, len, buffer.glyphs);
-            memset(buffer.pos, 0, sizeof(SkScalar) * len * 2);
+            const size_t txtLen = strlen(txt);
+            const int glyphCount = p.textToGlyphs(txt, txtLen, nullptr);
+
+            p.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+            const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(p, glyphCount);
+
+            p.setTextEncoding(SkPaint::kUTF8_TextEncoding);
+            p.textToGlyphs(txt, txtLen, buffer.glyphs);
+
+            memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2);
             SkAutoTUnref<const SkTextBlob> blob(builder.build());
             REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
         }