• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             font.setSize(0);
158 
159             const char* txt = "BOOO";
160             const size_t txtLen = strlen(txt);
161             const int glyphCount = font.countText(txt, txtLen, SkTextEncoding::kUTF8);
162             const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(font, glyphCount);
163 
164             font.textToGlyphs(txt, txtLen, SkTextEncoding::kUTF8, buffer.glyphs, glyphCount);
165 
166             memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2);
167             sk_sp<SkTextBlob> blob(builder.make());
168             REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
169         }
170     }
171 
172     // Verify that text-related properties are captured in run paints.
TestPaintProps(skiatest::Reporter * reporter)173     static void TestPaintProps(skiatest::Reporter* reporter) {
174         SkFont font;
175         // Kitchen sink font.
176         font.setSize(42);
177         font.setScaleX(4.2f);
178         font.setTypeface(ToolUtils::create_portable_typeface());
179         font.setSkewX(0.42f);
180         font.setHinting(SkFontHinting::kFull);
181         font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
182         font.setEmbolden(true);
183         font.setLinearMetrics(true);
184         font.setSubpixel(true);
185         font.setEmbeddedBitmaps(true);
186         font.setForceAutoHinting(true);
187 
188         // Ensure we didn't pick default values by mistake.
189         SkFont defaultFont;
190         REPORTER_ASSERT(reporter, defaultFont.getSize() != font.getSize());
191         REPORTER_ASSERT(reporter, defaultFont.getScaleX() != font.getScaleX());
192         REPORTER_ASSERT(reporter, defaultFont.getTypefaceOrDefault() != font.getTypefaceOrDefault());
193         REPORTER_ASSERT(reporter, defaultFont.getSkewX() != font.getSkewX());
194         REPORTER_ASSERT(reporter, defaultFont.getHinting() != font.getHinting());
195         REPORTER_ASSERT(reporter, defaultFont.getEdging() != font.getEdging());
196         REPORTER_ASSERT(reporter, defaultFont.isEmbolden() != font.isEmbolden());
197         REPORTER_ASSERT(reporter, defaultFont.isLinearMetrics() != font.isLinearMetrics());
198         REPORTER_ASSERT(reporter, defaultFont.isSubpixel() != font.isSubpixel());
199         REPORTER_ASSERT(reporter,
200                         defaultFont.isEmbeddedBitmaps() != font.isEmbeddedBitmaps());
201         REPORTER_ASSERT(reporter, defaultFont.isForceAutoHinting() != font.isForceAutoHinting());
202 
203         SkTextBlobBuilder builder;
204         AddRun(font, 1, SkTextBlobRunIterator::kDefault_Positioning, SkPoint::Make(0, 0), builder);
205         AddRun(font, 1, SkTextBlobRunIterator::kHorizontal_Positioning, SkPoint::Make(0, 0),
206                builder);
207         AddRun(font, 1, SkTextBlobRunIterator::kFull_Positioning, SkPoint::Make(0, 0), builder);
208         sk_sp<SkTextBlob> blob(builder.make());
209 
210         SkTextBlobRunIterator it(blob.get());
211         while (!it.done()) {
212             REPORTER_ASSERT(reporter, it.font() == font);
213             it.next();
214         }
215 
216     }
217 
218 private:
219     struct RunDef {
220         unsigned                                count;
221         SkTextBlobRunIterator::GlyphPositioning pos;
222         SkScalar                                x, y;
223     };
224 
RunBuilderTest(skiatest::Reporter * reporter,SkTextBlobBuilder & builder,const RunDef in[],unsigned inCount,const RunDef out[],unsigned outCount)225     static void RunBuilderTest(skiatest::Reporter* reporter, SkTextBlobBuilder& builder,
226                                const RunDef in[], unsigned inCount,
227                                const RunDef out[], unsigned outCount) {
228         SkFont font;
229 
230         for (unsigned i = 0; i < inCount; ++i) {
231             AddRun(font, in[i].count, in[i].pos, SkPoint::Make(in[i].x, in[i].y), builder);
232         }
233 
234         sk_sp<SkTextBlob> blob(builder.make());
235         REPORTER_ASSERT(reporter, (inCount > 0) == SkToBool(blob));
236         if (!blob) {
237             return;
238         }
239 
240         SkTextBlobRunIterator it(blob.get());
241         for (unsigned i = 0; i < outCount; ++i) {
242             REPORTER_ASSERT(reporter, !it.done());
243             REPORTER_ASSERT(reporter, out[i].pos == it.positioning());
244             REPORTER_ASSERT(reporter, out[i].count == it.glyphCount());
245             if (SkTextBlobRunIterator::kDefault_Positioning == out[i].pos) {
246                 REPORTER_ASSERT(reporter, out[i].x == it.offset().x());
247                 REPORTER_ASSERT(reporter, out[i].y == it.offset().y());
248             } else if (SkTextBlobRunIterator::kHorizontal_Positioning == out[i].pos) {
249                 REPORTER_ASSERT(reporter, out[i].y == it.offset().y());
250             }
251 
252             for (unsigned k = 0; k < it.glyphCount(); ++k) {
253                 REPORTER_ASSERT(reporter, k % 128 == it.glyphs()[k]);
254                 if (SkTextBlobRunIterator::kHorizontal_Positioning == it.positioning()) {
255                     REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k]);
256                 } else if (SkTextBlobRunIterator::kFull_Positioning == it.positioning()) {
257                     REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k * 2]);
258                     REPORTER_ASSERT(reporter, -SkIntToScalar(k % 128) == it.pos()[k * 2 + 1]);
259                 }
260             }
261 
262             it.next();
263         }
264 
265         REPORTER_ASSERT(reporter, it.done());
266     }
267 
AddRun(const SkFont & font,int count,SkTextBlobRunIterator::GlyphPositioning pos,const SkPoint & offset,SkTextBlobBuilder & builder,const SkRect * bounds=nullptr)268     static void AddRun(const SkFont& font, int count, SkTextBlobRunIterator::GlyphPositioning pos,
269                        const SkPoint& offset, SkTextBlobBuilder& builder,
270                        const SkRect* bounds = nullptr) {
271         switch (pos) {
272         case SkTextBlobRunIterator::kDefault_Positioning: {
273             const SkTextBlobBuilder::RunBuffer& rb = builder.allocRun(font, count, offset.x(),
274                                                                       offset.y(), bounds);
275             for (int i = 0; i < count; ++i) {
276                 rb.glyphs[i] = i;
277             }
278         } break;
279         case SkTextBlobRunIterator::kHorizontal_Positioning: {
280             const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPosH(font, count, offset.y(),
281                                                                           bounds);
282             for (int i = 0; i < count; ++i) {
283                 rb.glyphs[i] = i;
284                 rb.pos[i] = SkIntToScalar(i);
285             }
286         } break;
287         case SkTextBlobRunIterator::kFull_Positioning: {
288             const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPos(font, count, bounds);
289             for (int i = 0; i < count; ++i) {
290                 rb.glyphs[i] = i;
291                 rb.pos[i * 2] = SkIntToScalar(i);
292                 rb.pos[i * 2 + 1] = -SkIntToScalar(i);
293             }
294         } break;
295         default:
296             SK_ABORT("unhandled positioning value");
297         }
298     }
299 };
300 
DEF_TEST(TextBlob_builder,reporter)301 DEF_TEST(TextBlob_builder, reporter) {
302     TextBlobTester::TestBuilder(reporter);
303     TextBlobTester::TestBounds(reporter);
304 }
305 
DEF_TEST(TextBlob_paint,reporter)306 DEF_TEST(TextBlob_paint, reporter) {
307     TextBlobTester::TestPaintProps(reporter);
308 }
309 
DEF_TEST(TextBlob_extended,reporter)310 DEF_TEST(TextBlob_extended, reporter) {
311     SkTextBlobBuilder textBlobBuilder;
312     SkFont font;
313     const char text1[] = "Foo";
314     const char text2[] = "Bar";
315 
316     int glyphCount = font.countText(text1, strlen(text1), SkTextEncoding::kUTF8);
317     SkAutoTMalloc<uint16_t> glyphs(glyphCount);
318     (void)font.textToGlyphs(text1, strlen(text1), SkTextEncoding::kUTF8, glyphs.get(), glyphCount);
319 
320     auto run = textBlobBuilder.allocRunText(font, glyphCount, 0, 0, SkToInt(strlen(text2)));
321     memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount);
322     memcpy(run.utf8text, text2, strlen(text2));
323     for (int i = 0; i < glyphCount; ++i) {
324         run.clusters[i] = std::min(SkToU32(i), SkToU32(strlen(text2)));
325     }
326     sk_sp<SkTextBlob> blob(textBlobBuilder.make());
327     REPORTER_ASSERT(reporter, blob);
328 
329     for (SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) {
330         REPORTER_ASSERT(reporter, it.glyphCount() == (uint32_t)glyphCount);
331         for (uint32_t i = 0; i < it.glyphCount(); ++i) {
332             REPORTER_ASSERT(reporter, it.glyphs()[i] == glyphs[i]);
333         }
334         REPORTER_ASSERT(reporter, SkTextBlobRunIterator::kDefault_Positioning == it.positioning());
335         REPORTER_ASSERT(reporter, (SkPoint{0.0f, 0.0f}) == it.offset());
336         REPORTER_ASSERT(reporter, it.textSize() > 0);
337         REPORTER_ASSERT(reporter, it.clusters());
338         for (uint32_t i = 0; i < it.glyphCount(); ++i) {
339             REPORTER_ASSERT(reporter, i == it.clusters()[i]);
340         }
341         REPORTER_ASSERT(reporter, 0 == strncmp(text2, it.text(), it.textSize()));
342     }
343 }
344 
345 ///////////////////////////////////////////////////////////////////////////////////////////////////
346 #include "include/core/SkCanvas.h"
347 #include "include/core/SkSurface.h"
348 #include "include/private/SkTArray.h"
349 
add_run(SkTextBlobBuilder * builder,const char text[],SkScalar x,SkScalar y,sk_sp<SkTypeface> tf)350 static void add_run(SkTextBlobBuilder* builder, const char text[], SkScalar x, SkScalar y,
351                     sk_sp<SkTypeface> tf) {
352     SkFont font;
353     font.setEdging(SkFont::Edging::kAntiAlias);
354     font.setSubpixel(true);
355     font.setSize(16);
356     font.setTypeface(tf);
357 
358     int glyphCount = font.countText(text, strlen(text), SkTextEncoding::kUTF8);
359 
360     SkTextBlobBuilder::RunBuffer buffer = builder->allocRun(font, glyphCount, x, y);
361 
362     (void)font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, buffer.glyphs, glyphCount);
363 }
364 
render(const SkTextBlob * blob)365 static sk_sp<SkImage> render(const SkTextBlob* blob) {
366     auto surf = SkSurface::MakeRasterN32Premul(SkScalarRoundToInt(blob->bounds().width()),
367                                                SkScalarRoundToInt(blob->bounds().height()));
368     if (!surf) {
369         return nullptr; // bounds are empty?
370     }
371     surf->getCanvas()->clear(SK_ColorWHITE);
372     surf->getCanvas()->drawTextBlob(blob, -blob->bounds().left(), -blob->bounds().top(), SkPaint());
373     return surf->makeImageSnapshot();
374 }
375 
SerializeTypeface(SkTypeface * tf,void * ctx)376 static sk_sp<SkData> SerializeTypeface(SkTypeface* tf, void* ctx) {
377     auto array = (SkTArray<sk_sp<SkTypeface>>*)ctx;
378     const size_t idx = array->size();
379     array->emplace_back(sk_ref_sp(tf));
380     // In this test, we are deserializing on the same machine, so we don't worry about endianness.
381     return SkData::MakeWithCopy(&idx, sizeof(idx));
382 }
383 
DeserializeTypeface(const void * data,size_t length,void * ctx)384 static sk_sp<SkTypeface> DeserializeTypeface(const void* data, size_t length, void* ctx) {
385     auto array = (SkTArray<sk_sp<SkTypeface>>*)ctx;
386     if (length != sizeof(size_t)) {
387         SkASSERT(false);
388         return nullptr;
389     }
390     size_t idx = *reinterpret_cast<const size_t*>(data);
391     if (idx >= array->size()) {
392         SkASSERT(false);
393         return nullptr;
394     }
395     return (*array)[idx];
396 }
397 
398 /*
399  *  Build a blob with more than one typeface.
400  *  Draw it into an offscreen,
401  *  then serialize and deserialize,
402  *  Then draw the new instance and assert it draws the same as the original.
403  */
DEF_TEST(TextBlob_serialize,reporter)404 DEF_TEST(TextBlob_serialize, reporter) {
405     sk_sp<SkTextBlob> blob0 = []() {
406         sk_sp<SkTypeface> tf = SkTypeface::MakeFromName(nullptr, SkFontStyle::BoldItalic());
407 
408         SkTextBlobBuilder builder;
409         add_run(&builder, "Hello", 10, 20, nullptr);    // don't flatten a typeface
410         add_run(&builder, "World", 10, 40, tf);         // do flatten this typeface
411         return builder.make();
412     }();
413 
414     SkTArray<sk_sp<SkTypeface>> array;
415     SkSerialProcs serializeProcs;
416     serializeProcs.fTypefaceProc = &SerializeTypeface;
417     serializeProcs.fTypefaceCtx = (void*) &array;
418     sk_sp<SkData> data = blob0->serialize(serializeProcs);
419     REPORTER_ASSERT(reporter, array.count() == 1);
420     SkDeserialProcs deserializeProcs;
421     deserializeProcs.fTypefaceProc = &DeserializeTypeface;
422     deserializeProcs.fTypefaceCtx = (void*) &array;
423     sk_sp<SkTextBlob> blob1 = SkTextBlob::Deserialize(data->data(), data->size(), deserializeProcs);
424 
425     sk_sp<SkImage> img0 = render(blob0.get());
426     sk_sp<SkImage> img1 = render(blob1.get());
427     if (img0 && img1) {
428         REPORTER_ASSERT(reporter, ToolUtils::equal_pixels(img0.get(), img1.get()));
429     }
430 }
431 
DEF_TEST(TextBlob_MakeAsDrawText,reporter)432 DEF_TEST(TextBlob_MakeAsDrawText, reporter) {
433     const char text[] = "Hello";
434     auto blob = SkTextBlob::MakeFromString(text, SkFont(), SkTextEncoding::kUTF8);
435 
436     int runs = 0;
437     for(SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) {
438         REPORTER_ASSERT(reporter, it.glyphCount() == strlen(text));
439         REPORTER_ASSERT(reporter, it.positioning() == SkTextBlobRunIterator::kFull_Positioning);
440         runs += 1;
441     }
442     REPORTER_ASSERT(reporter, runs == 1);
443 
444 }
445 
DEF_TEST(TextBlob_iter,reporter)446 DEF_TEST(TextBlob_iter, reporter) {
447     sk_sp<SkTypeface> tf = SkTypeface::MakeFromName(nullptr, SkFontStyle::BoldItalic());
448 
449     SkTextBlobBuilder builder;
450     add_run(&builder, "Hello", 10, 20, nullptr);
451     add_run(&builder, "World", 10, 40, tf);
452     auto blob = builder.make();
453 
454     SkTextBlob::Iter::Run expected[] = {
455         { nullptr, 5, nullptr },
456         { tf.get(), 5, nullptr },
457     };
458 
459     SkTextBlob::Iter iter(*blob);
460     SkTextBlob::Iter::Run run;
461     for (auto exp : expected) {
462         REPORTER_ASSERT(reporter, iter.next(&run));
463         REPORTER_ASSERT(reporter, run.fTypeface == exp.fTypeface);
464         REPORTER_ASSERT(reporter, run.fGlyphCount == exp.fGlyphCount);
465         for (int i = 0; i < run.fGlyphCount; ++i) {
466             REPORTER_ASSERT(reporter, run.fGlyphIndices[i] != 0);
467         }
468     }
469     REPORTER_ASSERT(reporter, !iter.next(&run));    // we're done
470 
471     SkTextBlob::Iter iter2(*blob);
472     REPORTER_ASSERT(reporter, iter2.next(&run));
473     // Hello should have the same glyph repeated for the 'l'
474     REPORTER_ASSERT(reporter, run.fGlyphIndices[2] == run.fGlyphIndices[3]);
475 }
476 
DEF_TEST(TextBlob_getIntercepts,reporter)477 DEF_TEST(TextBlob_getIntercepts, reporter) {
478     SkFont font;
479     font.setSize(16);
480 
481     SkPoint lowPos[1] = { SkPoint::Make(0, 5) };
482     SkPoint highPos[1] = { SkPoint::Make(0, -8) };
483     SkPoint zeroPos[1] = { SkPoint::Make(0, 0) };
484 
485     // 'x' sitting on baseline
486     auto blobZeroX = SkTextBlob::MakeFromPosText("x", 1, zeroPos, font);
487     // 'x' lowered to intersect baseline
488     auto blobLowX = SkTextBlob::MakeFromPosText("x", 1, lowPos, font);
489     // 'y' sitting on baseline
490     auto blobZeroY = SkTextBlob::MakeFromPosText("y", 1, zeroPos, font);
491     // 'y' raised to not intersect baseline
492     auto blobHighY = SkTextBlob::MakeFromPosText("y", 1, highPos, font);
493 
494     // bounds right below baseline
495     SkScalar bounds[2] = { 1, 2 };
496 
497     // 'x' on baseline should not intersect
498     REPORTER_ASSERT(reporter, blobZeroX->getIntercepts(bounds, nullptr) == 0);
499     // lowered 'x' should intersect
500     REPORTER_ASSERT(reporter, blobLowX->getIntercepts(bounds, nullptr) == 2);
501     // 'y' on baseline should intersect
502     REPORTER_ASSERT(reporter, blobZeroY->getIntercepts(bounds, nullptr) == 2);
503     // raised 'y' should not intersect
504     REPORTER_ASSERT(reporter, blobHighY->getIntercepts(bounds, nullptr) == 0);
505 }
506