diff options
author | halcanary <halcanary@google.com> | 2016-08-30 11:58:33 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-30 11:58:33 -0700 |
commit | 4f0a23a8d54f5eb0fdacfff7c109b9045b548978 (patch) | |
tree | 18a57576bf48037cbf2f4485b0f2c635de4fc567 /tests | |
parent | fd7f867a0577a241ddbcb06eaa6aa104b78ff695 (diff) |
SkTextBlob: Begin implementing Extended TextBlob API
BUG=skia:5434
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2084533004
Review-Url: https://codereview.chromium.org/2084533004
Diffstat (limited to 'tests')
-rw-r--r-- | tests/TextBlobTest.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp index 61070247b4..82bbb21a11 100644 --- a/tests/TextBlobTest.cpp +++ b/tests/TextBlobTest.cpp @@ -349,3 +349,40 @@ DEF_TEST(TextBlob_builder, reporter) { DEF_TEST(TextBlob_paint, reporter) { TextBlobTester::TestPaintProps(reporter); } + +DEF_TEST(TextBlob_extended, reporter) { + SkTextBlobBuilder textBlobBuilder; + SkPaint paint; + const char text1[] = "Foo"; + const char text2[] = "Bar"; + + int glyphCount = paint.textToGlyphs(text1, strlen(text1), nullptr); + SkAutoTMalloc<uint16_t> glyphs(glyphCount); + (void)paint.textToGlyphs(text1, strlen(text1), glyphs.get()); + paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); + + auto run = textBlobBuilder.allocRunText( + paint, glyphCount, 0, 0, SkToInt(strlen(text2)), SkString(), nullptr); + memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount); + memcpy(run.utf8text, text2, strlen(text2)); + for (int i = 0; i < glyphCount; ++i) { + run.clusters[i] = SkTMin(SkToU32(i), SkToU32(strlen(text2))); + } + sk_sp<const SkTextBlob> blob(textBlobBuilder.build()); + REPORTER_ASSERT(reporter, blob); + + for (SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) { + REPORTER_ASSERT(reporter, it.glyphCount() == (uint32_t)glyphCount); + for (uint32_t i = 0; i < it.glyphCount(); ++i) { + REPORTER_ASSERT(reporter, it.glyphs()[i] == glyphs[i]); + } + REPORTER_ASSERT(reporter, SkTextBlob::kDefault_Positioning == it.positioning()); + REPORTER_ASSERT(reporter, (SkPoint{0.0f, 0.0f}) == it.offset()); + REPORTER_ASSERT(reporter, it.textSize() > 0); + REPORTER_ASSERT(reporter, it.clusters()); + for (uint32_t i = 0; i < it.glyphCount(); ++i) { + REPORTER_ASSERT(reporter, i == it.clusters()[i]); + } + REPORTER_ASSERT(reporter, 0 == strncmp(text2, it.text(), it.textSize())); + } +} |