Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "Test.h" | |
| 9 #include "SkTextBlob.h" | |
| 10 | |
| 11 #include "SkTextBlobRunIterator.h" | |
| 12 | |
| 13 DEF_TEST(ExtendedTextBlob, reporter) { | |
|
f(malita)
2016/06/27 20:21:56
This could be added to TextBlobTest.cpp instead of
hal.canary
2016/06/28 15:39:13
Done.
| |
| 14 SkTextBlobBuilder textBlobBuilder; | |
| 15 SkPaint paint; | |
| 16 const char text1[] = "Foo"; | |
| 17 const char text2[] = "Bar"; | |
| 18 | |
| 19 int glyphCount = paint.textToGlyphs(text1, strlen(text1), nullptr); | |
| 20 SkAutoTMalloc<uint16_t> glyphs(glyphCount); | |
| 21 (void)paint.textToGlyphs(text1, strlen(text1), glyphs.get()); | |
| 22 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
| 23 | |
| 24 auto run = textBlobBuilder.allocRunText( | |
| 25 paint, glyphCount, 0, 0, strlen(text2), SkString(), nullptr); | |
| 26 memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount); | |
| 27 memcpy(run.utf8text, text2, strlen(text2)); | |
| 28 for (int i = 0; i < glyphCount; ++i) { | |
| 29 run.clusters[i] = SkTMin<uint32_t>(i, strlen(text2)); | |
| 30 } | |
| 31 sk_sp<const SkTextBlob> blob(textBlobBuilder.build()); | |
| 32 REPORTER_ASSERT(reporter, blob); | |
| 33 | |
| 34 for (SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) { | |
| 35 REPORTER_ASSERT(reporter, it.glyphCount() == (uint32_t)glyphCount); | |
| 36 for (uint32_t i = 0; i < it.glyphCount(); ++i) { | |
| 37 REPORTER_ASSERT(reporter, it.glyphs()[i] == glyphs[i]); | |
| 38 } | |
| 39 REPORTER_ASSERT(reporter, SkTextBlob::kDefault_Positioning == it.positio ning()); | |
| 40 REPORTER_ASSERT(reporter, (SkPoint{0.0f, 0.0f}) == it.offset()); | |
| 41 REPORTER_ASSERT(reporter, it.isExtended()); | |
| 42 REPORTER_ASSERT(reporter, it.clusterBuffer()); | |
| 43 for (uint32_t i = 0; i < it.glyphCount(); ++i) { | |
| 44 REPORTER_ASSERT(reporter, i == it.clusterBuffer()[i]); | |
| 45 } | |
| 46 REPORTER_ASSERT(reporter, 0 == strncmp(text2, it.textBuffer(), it.textSi ze())); | |
| 47 } | |
| 48 } | |
| OLD | NEW |