blob: cb35367f44ea998a8485e3ea9f9df1bd5950d147 [file] [log] [blame]
Herb Derby41f4f312018-06-06 17:45:53 +00001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/core/SkGlyphRun.h"
Herb Derby41f4f312018-06-06 17:45:53 +00009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkTextBlob.h"
11#include "tests/Test.h"
Hal Canary8a001442018-09-19 11:31:27 -040012
Herb Derby8378dfb2018-08-30 14:50:04 -040013#include <algorithm>
14#include <memory>
15
Herb Derbyb9177cf2018-06-18 19:13:37 -040016
Mike Reed30cf62b2018-12-20 11:18:24 -050017#if 0 // should we revitalize this by consing up a device for drawTextBlob() ?
Herb Derby8a6348e2018-07-12 15:30:35 -040018DEF_TEST(GlyphRunBlob, reporter) {
19 constexpr uint16_t count = 5;
20 constexpr int runCount = 2;
21
22 auto tf = SkTypeface::MakeFromName("monospace", SkFontStyle());
23
Mike Reed2ed78202018-11-21 15:10:08 -050024 SkFont font;
Herb Derby8a6348e2018-07-12 15:30:35 -040025 font.setTypeface(tf);
Ben Wagner5785e4a2019-05-07 16:50:29 -040026 font.setHinting(SkFontHinting::kNormal);
Mike Reed2ed78202018-11-21 15:10:08 -050027 font.setSize(1u);
Herb Derby8a6348e2018-07-12 15:30:35 -040028
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
Herb Derby8a6348e2018-07-12 15:30:35 -040043 SkGlyphRunBuilder runBuilder;
Mike Reed2ed78202018-11-21 15:10:08 -050044 SkPaint legacy_paint;
45 font.LEGACY_applyToPaint(&legacy_paint);
46 runBuilder.drawTextBlob(legacy_paint, *blob, SkPoint::Make(0, 0));
Herb Derby8a6348e2018-07-12 15:30:35 -040047
48 auto runList = runBuilder.useGlyphRunList();
49
Herb Derbyb935cf82018-07-26 16:54:18 -040050 REPORTER_ASSERT(reporter, runList.size() == runCount);
Herb Derby8a6348e2018-07-12 15:30:35 -040051 int runIndex = 0;
Herb Derbyb935cf82018-07-26 16:54:18 -040052 for (auto& run : runList) {
Herb Derby8a6348e2018-07-12 15:30:35 -040053 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}
Mike Reed30cf62b2018-12-20 11:18:24 -050067#endif