1 /*
2  * Copyright 2018 The Android Open Source Project
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 "src/core/SkGlyphRun.h"
9 
10 #include "include/core/SkTextBlob.h"
11 #include "tests/Test.h"
12 
13 #include <algorithm>
14 #include <memory>
15 
16 
17 #if 0   // should we revitalize this by consing up a device for drawTextBlob() ?
18 DEF_TEST(GlyphRunBlob, reporter) {
19     constexpr uint16_t count = 5;
20     constexpr int runCount = 2;
21 
22     auto tf = SkTypeface::MakeFromName("monospace", SkFontStyle());
23 
24     SkFont font;
25     font.setTypeface(tf);
26     font.setHinting(SkFontHinting::kNormal);
27     font.setSize(1u);
28 
29     SkTextBlobBuilder blobBuilder;
30     for (int runNum = 0; runNum < runCount; runNum++) {
31         const auto& runBuffer = blobBuilder.allocRunPosH(font, count, runNum);
32         SkASSERT(runBuffer.utf8text == nullptr);
33         SkASSERT(runBuffer.clusters == nullptr);
34 
35         for (int i = 0; i < count; i++) {
36             runBuffer.glyphs[i] = static_cast<SkGlyphID>(i + runNum * count);
37             runBuffer.pos[i] = SkIntToScalar(i + runNum * count);
38         }
39     }
40 
41     auto blob = blobBuilder.make();
42 
43     SkGlyphRunBuilder runBuilder;
44     SkPaint legacy_paint;
45     font.LEGACY_applyToPaint(&legacy_paint);
46     runBuilder.drawTextBlob(legacy_paint, *blob, SkPoint::Make(0, 0));
47 
48     auto runList = runBuilder.useGlyphRunList();
49 
50     REPORTER_ASSERT(reporter, runList.size() == runCount);
51     int runIndex = 0;
52     for (auto& run : runList) {
53         REPORTER_ASSERT(reporter, run.runSize() == count);
54 
55         int index = 0;
56         for (auto p : run.positions()) {
57             if (p.x() != runIndex * count + index) {
58                 ERRORF(reporter, "x: %g != k: %d", p.x(), runIndex * count + index);
59                 break;
60             }
61             index += 1;
62         }
63 
64         runIndex += 1;
65     }
66 }
67 #endif
68