1 /*
2 * Copyright 2014 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 "include/core/SkPaint.h"
9 #include "include/core/SkPoint.h"
10 #include "include/core/SkSerialProcs.h"
11 #include "include/core/SkTypeface.h"
12 #include "include/private/SkTo.h"
13 #include "src/core/SkTextBlobPriv.h"
14
15 #include "tests/Test.h"
16 #include "tools/ToolUtils.h"
17
18 class TextBlobTester {
19 public:
20 // This unit test feeds an SkTextBlobBuilder various runs then checks to see if
21 // the result contains the provided data and merges runs when appropriate.
TestBuilder(skiatest::Reporter * reporter)22 static void TestBuilder(skiatest::Reporter* reporter) {
23 SkTextBlobBuilder builder;
24
25 // empty run set
26 RunBuilderTest(reporter, builder, nullptr, 0, nullptr, 0);
27
28 RunDef set1[] = {
29 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 100 },
30 };
31 RunBuilderTest(reporter, builder, set1, SK_ARRAY_COUNT(set1), set1, SK_ARRAY_COUNT(set1));
32
33 RunDef set2[] = {
34 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 100, 100 },
35 };
36 RunBuilderTest(reporter, builder, set2, SK_ARRAY_COUNT(set2), set2, SK_ARRAY_COUNT(set2));
37
38 RunDef set3[] = {
39 { 128, SkTextBlobRunIterator::kFull_Positioning, 100, 100 },
40 };
41 RunBuilderTest(reporter, builder, set3, SK_ARRAY_COUNT(set3), set3, SK_ARRAY_COUNT(set3));
42
43 RunDef set4[] = {
44 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 },
45 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 },
46 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 },
47 };
48 RunBuilderTest(reporter, builder, set4, SK_ARRAY_COUNT(set4), set4, SK_ARRAY_COUNT(set4));
49
50 RunDef set5[] = {
51 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 100, 150 },
52 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 200, 150 },
53 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 300, 250 },
54 };
55 RunDef mergedSet5[] = {
56 { 256, SkTextBlobRunIterator::kHorizontal_Positioning, 0, 150 },
57 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 0, 250 },
58 };
59 RunBuilderTest(reporter, builder, set5, SK_ARRAY_COUNT(set5), mergedSet5,
60 SK_ARRAY_COUNT(mergedSet5));
61
62 RunDef set6[] = {
63 { 128, SkTextBlobRunIterator::kFull_Positioning, 100, 100 },
64 { 128, SkTextBlobRunIterator::kFull_Positioning, 200, 200 },
65 { 128, SkTextBlobRunIterator::kFull_Positioning, 300, 300 },
66 };
67 RunDef mergedSet6[] = {
68 { 384, SkTextBlobRunIterator::kFull_Positioning, 0, 0 },
69 };
70 RunBuilderTest(reporter, builder, set6, SK_ARRAY_COUNT(set6), mergedSet6,
71 SK_ARRAY_COUNT(mergedSet6));
72
73 RunDef set7[] = {
74 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 },
75 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 },
76 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 100, 150 },
77 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 200, 150 },
78 { 128, SkTextBlobRunIterator::kFull_Positioning, 400, 350 },
79 { 128, SkTextBlobRunIterator::kFull_Positioning, 400, 350 },
80 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 450 },
81 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 450 },
82 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 100, 550 },
83 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 200, 650 },
84 { 128, SkTextBlobRunIterator::kFull_Positioning, 400, 750 },
85 { 128, SkTextBlobRunIterator::kFull_Positioning, 400, 850 },
86 };
87 RunDef mergedSet7[] = {
88 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 },
89 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 },
90 { 256, SkTextBlobRunIterator::kHorizontal_Positioning, 0, 150 },
91 { 256, SkTextBlobRunIterator::kFull_Positioning, 0, 0 },
92 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 450 },
93 { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 450 },
94 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 0, 550 },
95 { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 0, 650 },
96 { 256, SkTextBlobRunIterator::kFull_Positioning, 0, 0 },
97 };
98 RunBuilderTest(reporter, builder, set7, SK_ARRAY_COUNT(set7), mergedSet7,
99 SK_ARRAY_COUNT(mergedSet7));
100 }
101
102 // This unit test verifies blob bounds computation.
TestBounds(skiatest::Reporter * reporter)103 static void TestBounds(skiatest::Reporter* reporter) {
104 SkTextBlobBuilder builder;
105 SkFont font;
106
107 // Explicit bounds.
108 {
109 sk_sp<SkTextBlob> blob(builder.make());
110 REPORTER_ASSERT(reporter, !blob);
111 }
112
113 {
114 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
115 builder.allocRun(font, 16, 0, 0, &r1);
116 sk_sp<SkTextBlob> blob(builder.make());
117 REPORTER_ASSERT(reporter, blob->bounds() == r1);
118 }
119
120 {
121 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
122 builder.allocRunPosH(font, 16, 0, &r1);
123 sk_sp<SkTextBlob> blob(builder.make());
124 REPORTER_ASSERT(reporter, blob->bounds() == r1);
125 }
126
127 {
128 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
129 builder.allocRunPos(font, 16, &r1);
130 sk_sp<SkTextBlob> blob(builder.make());
131 REPORTER_ASSERT(reporter, blob->bounds() == r1);
132 }
133
134 {
135 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
136 SkRect r2 = SkRect::MakeXYWH(15, 20, 50, 50);
137 SkRect r3 = SkRect::MakeXYWH(0, 5, 10, 5);
138
139 builder.allocRun(font, 16, 0, 0, &r1);
140 builder.allocRunPosH(font, 16, 0, &r2);
141 builder.allocRunPos(font, 16, &r3);
142
143 sk_sp<SkTextBlob> blob(builder.make());
144 REPORTER_ASSERT(reporter, blob->bounds() == SkRect::MakeXYWH(0, 5, 65, 65));
145 }
146
147 {
148 sk_sp<SkTextBlob> blob(builder.make());
149 REPORTER_ASSERT(reporter, !blob);
150 }
151
152 // Implicit bounds
153
154 {
155 // Exercise the empty bounds path, and ensure that RunRecord-aligned pos buffers
156 // don't trigger asserts (http://crbug.com/542643).
157 SkFont font;
158 font.setSize(0);
159
160 const char* txt = "BOOO";
161 const size_t txtLen = strlen(txt);
162 const int glyphCount = font.countText(txt, txtLen, SkTextEncoding::kUTF8);
163 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(font, glyphCount);
164
165 font.textToGlyphs(txt, txtLen, SkTextEncoding::kUTF8, buffer.glyphs, glyphCount);
166
167 memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2);
168 sk_sp<SkTextBlob> blob(builder.make());
169 REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
170 }
171 }
172
173 // Verify that text-related properties are captured in run paints.
TestPaintProps(skiatest::Reporter * reporter)174 static void TestPaintProps(skiatest::Reporter* reporter) {
175 SkFont font;
176 // Kitchen sink font.
177 font.setSize(42);
178 font.setScaleX(4.2f);
179 font.setTypeface(ToolUtils::create_portable_typeface());
180 font.setSkewX(0.42f);
181 font.setHinting(SkFontHinting::kFull);
182 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
183 font.setEmbolden(true);
184 font.setLinearMetrics(true);
185 font.setSubpixel(true);
186 font.setEmbeddedBitmaps(true);
187 font.setForceAutoHinting(true);
188
189 // Ensure we didn't pick default values by mistake.
190 SkFont defaultFont;
191 REPORTER_ASSERT(reporter, defaultFont.getSize() != font.getSize());
192 REPORTER_ASSERT(reporter, defaultFont.getScaleX() != font.getScaleX());
193 REPORTER_ASSERT(reporter, defaultFont.getTypefaceOrDefault() != font.getTypefaceOrDefault());
194 REPORTER_ASSERT(reporter, defaultFont.getSkewX() != font.getSkewX());
195 REPORTER_ASSERT(reporter, defaultFont.getHinting() != font.getHinting());
196 REPORTER_ASSERT(reporter, defaultFont.getEdging() != font.getEdging());
197 REPORTER_ASSERT(reporter, defaultFont.isEmbolden() != font.isEmbolden());
198 REPORTER_ASSERT(reporter, defaultFont.isLinearMetrics() != font.isLinearMetrics());
199 REPORTER_ASSERT(reporter, defaultFont.isSubpixel() != font.isSubpixel());
200 REPORTER_ASSERT(reporter,
201 defaultFont.isEmbeddedBitmaps() != font.isEmbeddedBitmaps());
202 REPORTER_ASSERT(reporter, defaultFont.isForceAutoHinting() != font.isForceAutoHinting());
203
204 SkTextBlobBuilder builder;
205 AddRun(font, 1, SkTextBlobRunIterator::kDefault_Positioning, SkPoint::Make(0, 0), builder);
206 AddRun(font, 1, SkTextBlobRunIterator::kHorizontal_Positioning, SkPoint::Make(0, 0),
207 builder);
208 AddRun(font, 1, SkTextBlobRunIterator::kFull_Positioning, SkPoint::Make(0, 0), builder);
209 sk_sp<SkTextBlob> blob(builder.make());
210
211 SkTextBlobRunIterator it(blob.get());
212 while (!it.done()) {
213 REPORTER_ASSERT(reporter, it.font() == font);
214 it.next();
215 }
216
217 }
218
219 private:
220 struct RunDef {
221 unsigned count;
222 SkTextBlobRunIterator::GlyphPositioning pos;
223 SkScalar x, y;
224 };
225
RunBuilderTest(skiatest::Reporter * reporter,SkTextBlobBuilder & builder,const RunDef in[],unsigned inCount,const RunDef out[],unsigned outCount)226 static void RunBuilderTest(skiatest::Reporter* reporter, SkTextBlobBuilder& builder,
227 const RunDef in[], unsigned inCount,
228 const RunDef out[], unsigned outCount) {
229 SkFont font;
230
231 unsigned glyphCount = 0;
232 unsigned posCount = 0;
233
234 for (unsigned i = 0; i < inCount; ++i) {
235 AddRun(font, in[i].count, in[i].pos, SkPoint::Make(in[i].x, in[i].y), builder);
236 glyphCount += in[i].count;
237 posCount += in[i].count * in[i].pos;
238 }
239
240 sk_sp<SkTextBlob> blob(builder.make());
241 REPORTER_ASSERT(reporter, (inCount > 0) == SkToBool(blob));
242 if (!blob) {
243 return;
244 }
245
246 SkTextBlobRunIterator it(blob.get());
247 for (unsigned i = 0; i < outCount; ++i) {
248 REPORTER_ASSERT(reporter, !it.done());
249 REPORTER_ASSERT(reporter, out[i].pos == it.positioning());
250 REPORTER_ASSERT(reporter, out[i].count == it.glyphCount());
251 if (SkTextBlobRunIterator::kDefault_Positioning == out[i].pos) {
252 REPORTER_ASSERT(reporter, out[i].x == it.offset().x());
253 REPORTER_ASSERT(reporter, out[i].y == it.offset().y());
254 } else if (SkTextBlobRunIterator::kHorizontal_Positioning == out[i].pos) {
255 REPORTER_ASSERT(reporter, out[i].y == it.offset().y());
256 }
257
258 for (unsigned k = 0; k < it.glyphCount(); ++k) {
259 REPORTER_ASSERT(reporter, k % 128 == it.glyphs()[k]);
260 if (SkTextBlobRunIterator::kHorizontal_Positioning == it.positioning()) {
261 REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k]);
262 } else if (SkTextBlobRunIterator::kFull_Positioning == it.positioning()) {
263 REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k * 2]);
264 REPORTER_ASSERT(reporter, -SkIntToScalar(k % 128) == it.pos()[k * 2 + 1]);
265 }
266 }
267
268 it.next();
269 }
270
271 REPORTER_ASSERT(reporter, it.done());
272 }
273
AddRun(const SkFont & font,int count,SkTextBlobRunIterator::GlyphPositioning pos,const SkPoint & offset,SkTextBlobBuilder & builder,const SkRect * bounds=nullptr)274 static void AddRun(const SkFont& font, int count, SkTextBlobRunIterator::GlyphPositioning pos,
275 const SkPoint& offset, SkTextBlobBuilder& builder,
276 const SkRect* bounds = nullptr) {
277 switch (pos) {
278 case SkTextBlobRunIterator::kDefault_Positioning: {
279 const SkTextBlobBuilder::RunBuffer& rb = builder.allocRun(font, count, offset.x(),
280 offset.y(), bounds);
281 for (int i = 0; i < count; ++i) {
282 rb.glyphs[i] = i;
283 }
284 } break;
285 case SkTextBlobRunIterator::kHorizontal_Positioning: {
286 const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPosH(font, count, offset.y(),
287 bounds);
288 for (int i = 0; i < count; ++i) {
289 rb.glyphs[i] = i;
290 rb.pos[i] = SkIntToScalar(i);
291 }
292 } break;
293 case SkTextBlobRunIterator::kFull_Positioning: {
294 const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPos(font, count, bounds);
295 for (int i = 0; i < count; ++i) {
296 rb.glyphs[i] = i;
297 rb.pos[i * 2] = SkIntToScalar(i);
298 rb.pos[i * 2 + 1] = -SkIntToScalar(i);
299 }
300 } break;
301 default:
302 SK_ABORT("unhandled positioning value");
303 }
304 }
305 };
306
DEF_TEST(TextBlob_builder,reporter)307 DEF_TEST(TextBlob_builder, reporter) {
308 TextBlobTester::TestBuilder(reporter);
309 TextBlobTester::TestBounds(reporter);
310 }
311
DEF_TEST(TextBlob_paint,reporter)312 DEF_TEST(TextBlob_paint, reporter) {
313 TextBlobTester::TestPaintProps(reporter);
314 }
315
DEF_TEST(TextBlob_extended,reporter)316 DEF_TEST(TextBlob_extended, reporter) {
317 SkTextBlobBuilder textBlobBuilder;
318 SkFont font;
319 const char text1[] = "Foo";
320 const char text2[] = "Bar";
321
322 int glyphCount = font.countText(text1, strlen(text1), SkTextEncoding::kUTF8);
323 SkAutoTMalloc<uint16_t> glyphs(glyphCount);
324 (void)font.textToGlyphs(text1, strlen(text1), SkTextEncoding::kUTF8, glyphs.get(), glyphCount);
325
326 auto run = textBlobBuilder.allocRunText(font, glyphCount, 0, 0, SkToInt(strlen(text2)));
327 memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount);
328 memcpy(run.utf8text, text2, strlen(text2));
329 for (int i = 0; i < glyphCount; ++i) {
330 run.clusters[i] = std::min(SkToU32(i), SkToU32(strlen(text2)));
331 }
332 sk_sp<SkTextBlob> blob(textBlobBuilder.make());
333 REPORTER_ASSERT(reporter, blob);
334
335 for (SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) {
336 REPORTER_ASSERT(reporter, it.glyphCount() == (uint32_t)glyphCount);
337 for (uint32_t i = 0; i < it.glyphCount(); ++i) {
338 REPORTER_ASSERT(reporter, it.glyphs()[i] == glyphs[i]);
339 }
340 REPORTER_ASSERT(reporter, SkTextBlobRunIterator::kDefault_Positioning == it.positioning());
341 REPORTER_ASSERT(reporter, (SkPoint{0.0f, 0.0f}) == it.offset());
342 REPORTER_ASSERT(reporter, it.textSize() > 0);
343 REPORTER_ASSERT(reporter, it.clusters());
344 for (uint32_t i = 0; i < it.glyphCount(); ++i) {
345 REPORTER_ASSERT(reporter, i == it.clusters()[i]);
346 }
347 REPORTER_ASSERT(reporter, 0 == strncmp(text2, it.text(), it.textSize()));
348 }
349 }
350
351 ///////////////////////////////////////////////////////////////////////////////////////////////////
352 #include "include/core/SkCanvas.h"
353 #include "include/core/SkSurface.h"
354 #include "include/private/SkTArray.h"
355
add_run(SkTextBlobBuilder * builder,const char text[],SkScalar x,SkScalar y,sk_sp<SkTypeface> tf)356 static void add_run(SkTextBlobBuilder* builder, const char text[], SkScalar x, SkScalar y,
357 sk_sp<SkTypeface> tf) {
358 SkFont font;
359 font.setEdging(SkFont::Edging::kAntiAlias);
360 font.setSubpixel(true);
361 font.setSize(16);
362 font.setTypeface(tf);
363
364 int glyphCount = font.countText(text, strlen(text), SkTextEncoding::kUTF8);
365
366 SkTextBlobBuilder::RunBuffer buffer = builder->allocRun(font, glyphCount, x, y);
367
368 (void)font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, buffer.glyphs, glyphCount);
369 }
370
render(const SkTextBlob * blob)371 static sk_sp<SkImage> render(const SkTextBlob* blob) {
372 auto surf = SkSurface::MakeRasterN32Premul(SkScalarRoundToInt(blob->bounds().width()),
373 SkScalarRoundToInt(blob->bounds().height()));
374 if (!surf) {
375 return nullptr; // bounds are empty?
376 }
377 surf->getCanvas()->clear(SK_ColorWHITE);
378 surf->getCanvas()->drawTextBlob(blob, -blob->bounds().left(), -blob->bounds().top(), SkPaint());
379 return surf->makeImageSnapshot();
380 }
381
SerializeTypeface(SkTypeface * tf,void * ctx)382 static sk_sp<SkData> SerializeTypeface(SkTypeface* tf, void* ctx) {
383 auto array = (SkTArray<sk_sp<SkTypeface>>*)ctx;
384 const size_t idx = array->size();
385 array->emplace_back(sk_ref_sp(tf));
386 // In this test, we are deserializing on the same machine, so we don't worry about endianness.
387 return SkData::MakeWithCopy(&idx, sizeof(idx));
388 }
389
DeserializeTypeface(const void * data,size_t length,void * ctx)390 static sk_sp<SkTypeface> DeserializeTypeface(const void* data, size_t length, void* ctx) {
391 auto array = (SkTArray<sk_sp<SkTypeface>>*)ctx;
392 if (length != sizeof(size_t)) {
393 SkASSERT(false);
394 return nullptr;
395 }
396 size_t idx = *reinterpret_cast<const size_t*>(data);
397 if (idx >= array->size()) {
398 SkASSERT(false);
399 return nullptr;
400 }
401 return (*array)[idx];
402 }
403
404 /*
405 * Build a blob with more than one typeface.
406 * Draw it into an offscreen,
407 * then serialize and deserialize,
408 * Then draw the new instance and assert it draws the same as the original.
409 */
DEF_TEST(TextBlob_serialize,reporter)410 DEF_TEST(TextBlob_serialize, reporter) {
411 sk_sp<SkTextBlob> blob0 = []() {
412 sk_sp<SkTypeface> tf = SkTypeface::MakeFromName(nullptr, SkFontStyle::BoldItalic());
413
414 SkTextBlobBuilder builder;
415 add_run(&builder, "Hello", 10, 20, nullptr); // don't flatten a typeface
416 add_run(&builder, "World", 10, 40, tf); // do flatten this typeface
417 return builder.make();
418 }();
419
420 SkTArray<sk_sp<SkTypeface>> array;
421 SkSerialProcs serializeProcs;
422 serializeProcs.fTypefaceProc = &SerializeTypeface;
423 serializeProcs.fTypefaceCtx = (void*) &array;
424 sk_sp<SkData> data = blob0->serialize(serializeProcs);
425 REPORTER_ASSERT(reporter, array.count() == 1);
426 SkDeserialProcs deserializeProcs;
427 deserializeProcs.fTypefaceProc = &DeserializeTypeface;
428 deserializeProcs.fTypefaceCtx = (void*) &array;
429 sk_sp<SkTextBlob> blob1 = SkTextBlob::Deserialize(data->data(), data->size(), deserializeProcs);
430
431 sk_sp<SkImage> img0 = render(blob0.get());
432 sk_sp<SkImage> img1 = render(blob1.get());
433 if (img0 && img1) {
434 REPORTER_ASSERT(reporter, ToolUtils::equal_pixels(img0.get(), img1.get()));
435 }
436 }
437
DEF_TEST(TextBlob_MakeAsDrawText,reporter)438 DEF_TEST(TextBlob_MakeAsDrawText, reporter) {
439 const char text[] = "Hello";
440 auto blob = SkTextBlob::MakeFromString(text, SkFont(), SkTextEncoding::kUTF8);
441
442 int runs = 0;
443 for(SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) {
444 REPORTER_ASSERT(reporter, it.glyphCount() == strlen(text));
445 REPORTER_ASSERT(reporter, it.positioning() == SkTextBlobRunIterator::kFull_Positioning);
446 runs += 1;
447 }
448 REPORTER_ASSERT(reporter, runs == 1);
449
450 }
451
DEF_TEST(TextBlob_iter,reporter)452 DEF_TEST(TextBlob_iter, reporter) {
453 sk_sp<SkTypeface> tf = SkTypeface::MakeFromName(nullptr, SkFontStyle::BoldItalic());
454
455 SkTextBlobBuilder builder;
456 add_run(&builder, "Hello", 10, 20, nullptr);
457 add_run(&builder, "World", 10, 40, tf);
458 auto blob = builder.make();
459
460 SkTextBlob::Iter::Run expected[] = {
461 { nullptr, 5, nullptr },
462 { tf.get(), 5, nullptr },
463 };
464
465 SkTextBlob::Iter iter(*blob);
466 SkTextBlob::Iter::Run run;
467 for (auto exp : expected) {
468 REPORTER_ASSERT(reporter, iter.next(&run));
469 REPORTER_ASSERT(reporter, run.fTypeface == exp.fTypeface);
470 REPORTER_ASSERT(reporter, run.fGlyphCount == exp.fGlyphCount);
471 for (int i = 0; i < run.fGlyphCount; ++i) {
472 REPORTER_ASSERT(reporter, run.fGlyphIndices[i] != 0);
473 }
474 }
475 REPORTER_ASSERT(reporter, !iter.next(&run)); // we're done
476
477 SkTextBlob::Iter iter2(*blob);
478 REPORTER_ASSERT(reporter, iter2.next(&run));
479 // Hello should have the same glyph repeated for the 'l'
480 REPORTER_ASSERT(reporter, run.fGlyphIndices[2] == run.fGlyphIndices[3]);
481 }
482
DEF_TEST(TextBlob_getIntercepts,reporter)483 DEF_TEST(TextBlob_getIntercepts, reporter) {
484 SkFont font;
485 font.setSize(16);
486
487 SkPoint lowPos[1] = { SkPoint::Make(0, 5) };
488 SkPoint highPos[1] = { SkPoint::Make(0, -8) };
489 SkPoint zeroPos[1] = { SkPoint::Make(0, 0) };
490
491 // 'x' sitting on baseline
492 auto blobZeroX = SkTextBlob::MakeFromPosText("x", 1, zeroPos, font);
493 // 'x' lowered to intersect baseline
494 auto blobLowX = SkTextBlob::MakeFromPosText("x", 1, lowPos, font);
495 // 'y' sitting on baseline
496 auto blobZeroY = SkTextBlob::MakeFromPosText("y", 1, zeroPos, font);
497 // 'y' raised to not intersect baseline
498 auto blobHighY = SkTextBlob::MakeFromPosText("y", 1, highPos, font);
499
500 // bounds right below baseline
501 SkScalar bounds[2] = { 1, 2 };
502
503 // 'x' on baseline should not intersect
504 REPORTER_ASSERT(reporter, blobZeroX->getIntercepts(bounds, nullptr) == 0);
505 // lowered 'x' should intersect
506 REPORTER_ASSERT(reporter, blobLowX->getIntercepts(bounds, nullptr) == 2);
507 // 'y' on baseline should intersect
508 REPORTER_ASSERT(reporter, blobZeroY->getIntercepts(bounds, nullptr) == 2);
509 // raised 'y' should not intersect
510 REPORTER_ASSERT(reporter, blobHighY->getIntercepts(bounds, nullptr) == 0);
511 }
512