1c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita/*
2c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita * Copyright 2014 Google Inc.
3c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita *
4c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita * Use of this source code is governed by a BSD-style license that can be
5c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita * found in the LICENSE file.
6c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita */
7c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
8c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita#include "SkPaint.h"
9c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita#include "SkPoint.h"
10c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita#include "SkTextBlob.h"
11c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
12c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita#include "Test.h"
13c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
14c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
15c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalitaclass TextBlobTester {
16c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalitapublic:
1751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita    // This unit test feeds an SkTextBlobBuilder various runs then checks to see if
1851bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita    // the result contains the provided data and merges runs when appropriate.
1951bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita    static void TestBuilder(skiatest::Reporter* reporter) {
20c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        SkTextBlobBuilder builder;
21c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
22c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        // empty run set
2351bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunBuilderTest(reporter, builder, NULL, 0, NULL, 0);
24c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
2551bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunDef set1[] = {
26c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 100 },
27c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        };
2851bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunBuilderTest(reporter, builder, set1, SK_ARRAY_COUNT(set1), set1, SK_ARRAY_COUNT(set1));
29c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
3051bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunDef set2[] = {
31c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 100, 100 },
32c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        };
3351bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunBuilderTest(reporter, builder, set2, SK_ARRAY_COUNT(set2), set2, SK_ARRAY_COUNT(set2));
34c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
3551bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunDef set3[] = {
36c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kFull_Positioning, 100, 100 },
37c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        };
3851bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunBuilderTest(reporter, builder, set3, SK_ARRAY_COUNT(set3), set3, SK_ARRAY_COUNT(set3));
39c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
4051bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunDef set4[] = {
41c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
42c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
43c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
44c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        };
4551bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunBuilderTest(reporter, builder, set4, SK_ARRAY_COUNT(set4), set4, SK_ARRAY_COUNT(set4));
46c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
4751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunDef set5[] = {
48c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 100, 150 },
49c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 200, 150 },
50c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 300, 250 },
51c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        };
5251bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunDef mergedSet5[] = {
53c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 256, SkTextBlob::kHorizontal_Positioning, 0, 150 },
54c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 0, 250 },
55c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        };
5651bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunBuilderTest(reporter, builder, set5, SK_ARRAY_COUNT(set5), mergedSet5,
5751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita                       SK_ARRAY_COUNT(mergedSet5));
58c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
5951bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunDef set6[] = {
60c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kFull_Positioning, 100, 100 },
61c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kFull_Positioning, 200, 200 },
62c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kFull_Positioning, 300, 300 },
63c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        };
6451bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunDef mergedSet6[] = {
65c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 384, SkTextBlob::kFull_Positioning, 0, 0 },
66c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        };
6751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunBuilderTest(reporter, builder, set6, SK_ARRAY_COUNT(set6), mergedSet6,
6851bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita                       SK_ARRAY_COUNT(mergedSet6));
69c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
7051bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunDef set7[] = {
71c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
72c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
73c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 100, 150 },
74c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 200, 150 },
75c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kFull_Positioning, 400, 350 },
76c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kFull_Positioning, 400, 350 },
77c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
78c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
79c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 100, 550 },
80c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 200, 650 },
81c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kFull_Positioning, 400, 750 },
82c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kFull_Positioning, 400, 850 },
83c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        };
8451bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunDef mergedSet7[] = {
85c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
86c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
87c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 256, SkTextBlob::kHorizontal_Positioning, 0, 150 },
88c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 256, SkTextBlob::kFull_Positioning, 0, 0 },
89c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
90c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
91c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 0, 550 },
92c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 128, SkTextBlob::kHorizontal_Positioning, 0, 650 },
93c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            { 256, SkTextBlob::kFull_Positioning, 0, 0 },
94c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        };
9551bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        RunBuilderTest(reporter, builder, set7, SK_ARRAY_COUNT(set7), mergedSet7,
9651bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita                       SK_ARRAY_COUNT(mergedSet7));
9751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita    }
9851bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
9951bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita    // This unit test verifies blob bounds computation.
10051bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita    static void TestBounds(skiatest::Reporter* reporter) {
10151bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        SkTextBlobBuilder builder;
10251bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        SkPaint font;
10351bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
10451bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
10551bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        // Explicit bounds.
10651bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        {
10751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkAutoTUnref<const SkTextBlob> blob(builder.build());
10851bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
10951bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        }
11051bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
11151bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        {
11251bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
11351bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            builder.allocRun(font, 16, 0, 0, &r1);
11451bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkAutoTUnref<const SkTextBlob> blob(builder.build());
11551bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            REPORTER_ASSERT(reporter, blob->bounds() == r1);
11651bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        }
11751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
11851bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        {
11951bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
12051bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            builder.allocRunPosH(font, 16, 0, &r1);
12151bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkAutoTUnref<const SkTextBlob> blob(builder.build());
12251bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            REPORTER_ASSERT(reporter, blob->bounds() == r1);
12351bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        }
12451bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
12551bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        {
12651bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
12751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            builder.allocRunPos(font, 16, &r1);
12851bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkAutoTUnref<const SkTextBlob> blob(builder.build());
12951bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            REPORTER_ASSERT(reporter, blob->bounds() == r1);
13051bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        }
13151bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
13251bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        {
13351bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
13451bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkRect r2 = SkRect::MakeXYWH(15, 20, 50, 50);
13551bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkRect r3 = SkRect::MakeXYWH(0, 5, 10, 5);
13651bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
13751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            builder.allocRun(font, 16, 0, 0, &r1);
13851bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            builder.allocRunPosH(font, 16, 0, &r2);
13951bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            builder.allocRunPos(font, 16, &r3);
14051bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
14151bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkAutoTUnref<const SkTextBlob> blob(builder.build());
14251bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            REPORTER_ASSERT(reporter, blob->bounds() == SkRect::MakeXYWH(0, 5, 65, 65));
14351bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        }
14451bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
14551bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        {
14651bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            // Verify empty blob bounds after building some non-empty blobs.
14751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            SkAutoTUnref<const SkTextBlob> blob(builder.build());
14851bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
14951bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        }
15051bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
15151bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        // Implicit bounds
15251bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        // FIXME: not supported yet.
153c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita    }
154c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
155c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalitaprivate:
156c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita    struct RunDef {
157c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        unsigned                     count;
158c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        SkTextBlob::GlyphPositioning pos;
159c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        SkScalar                     x, y;
160c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita    };
161c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
16251bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita    static void RunBuilderTest(skiatest::Reporter* reporter, SkTextBlobBuilder& builder,
163c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                               const RunDef in[], unsigned inCount,
164c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                               const RunDef out[], unsigned outCount) {
16551bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        SkPaint font;
16651bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita        font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
16751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita
168c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        unsigned glyphCount = 0;
169c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        unsigned posCount = 0;
170c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
171c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        for (unsigned i = 0; i < inCount; ++i) {
17251bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita            AddRun(font, in[i].count, in[i].pos, SkPoint::Make(in[i].x, in[i].y), builder);
173c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            glyphCount += in[i].count;
174c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            posCount += in[i].count * in[i].pos;
175c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        }
176c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
177c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        SkAutoTUnref<const SkTextBlob> blob(builder.build());
178c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
179c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        SkTextBlob::RunIterator it(blob);
180c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        for (unsigned i = 0; i < outCount; ++i) {
181c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            REPORTER_ASSERT(reporter, !it.done());
182c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            REPORTER_ASSERT(reporter, out[i].pos == it.positioning());
183c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            REPORTER_ASSERT(reporter, out[i].count == it.glyphCount());
184c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            if (SkTextBlob::kDefault_Positioning == out[i].pos) {
185c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                REPORTER_ASSERT(reporter, out[i].x == it.offset().x());
186c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                REPORTER_ASSERT(reporter, out[i].y == it.offset().y());
187c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            } else if (SkTextBlob::kHorizontal_Positioning == out[i].pos) {
188c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                REPORTER_ASSERT(reporter, out[i].y == it.offset().y());
189c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            }
190c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
191c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            for (unsigned k = 0; k < it.glyphCount(); ++k) {
192c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                REPORTER_ASSERT(reporter, k % 128 == it.glyphs()[k]);
193c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                if (SkTextBlob::kHorizontal_Positioning == it.positioning()) {
194c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                    REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k]);
195c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                } else if (SkTextBlob::kFull_Positioning == it.positioning()) {
196c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                    REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k * 2]);
197c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                    REPORTER_ASSERT(reporter, -SkIntToScalar(k % 128) == it.pos()[k * 2 + 1]);
198c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                }
199c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            }
200c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
201c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            it.next();
202c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        }
203c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
204c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        REPORTER_ASSERT(reporter, it.done());
205c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita    }
206c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
20751bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita    static void AddRun(const SkPaint& font, int count, SkTextBlob::GlyphPositioning pos,
208c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                       const SkPoint& offset, SkTextBlobBuilder& builder,
209c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                       const SkRect* bounds = NULL) {
210c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        switch (pos) {
211c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        case SkTextBlob::kDefault_Positioning: {
212c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            const SkTextBlobBuilder::RunBuffer& rb = builder.allocRun(font, count, offset.x(),
213c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                                                                      offset.y(), bounds);
214c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            for (int i = 0; i < count; ++i) {
215c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                rb.glyphs[i] = i;
216c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            }
217c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        } break;
218c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        case SkTextBlob::kHorizontal_Positioning: {
219c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPosH(font, count, offset.y(),
220c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                                                                          bounds);
221c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            for (int i = 0; i < count; ++i) {
222c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                rb.glyphs[i] = i;
223c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                rb.pos[i] = SkIntToScalar(i);
224c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            }
225c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        } break;
226c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        case SkTextBlob::kFull_Positioning: {
227c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPos(font, count, bounds);
228c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            for (int i = 0; i < count; ++i) {
229c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                rb.glyphs[i] = i;
230c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                rb.pos[i * 2] = SkIntToScalar(i);
231c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita                rb.pos[i * 2 + 1] = -SkIntToScalar(i);
232c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            }
233c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        } break;
234c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        default:
235c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita            SkFAIL("unhandled positioning value");
236c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita        }
237c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita    }
238c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita};
239c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita
240c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalitaDEF_TEST(TextBlob_builder, reporter) {
24151bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita    TextBlobTester::TestBuilder(reporter);
24251bf9573b8b875aec47cbeb9f4649f58bcbf56b7fmalita    TextBlobTester::TestBounds(reporter);
243c6765d69e3aceaa316fe2d2ef00a7f0d138def2ffmalita}
244