Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/core/SkGlyphRun.h" |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkTextBlob.h" |
| 11 | #include "tests/Test.h" |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 12 | |
Herb Derby | 8378dfb | 2018-08-30 14:50:04 -0400 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | #include <memory> |
| 15 | |
Herb Derby | b9177cf | 2018-06-18 19:13:37 -0400 | [diff] [blame] | 16 | |
Mike Reed | 30cf62b | 2018-12-20 11:18:24 -0500 | [diff] [blame] | 17 | #if 0 // should we revitalize this by consing up a device for drawTextBlob() ? |
Herb Derby | 8a6348e | 2018-07-12 15:30:35 -0400 | [diff] [blame] | 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 | |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 24 | SkFont font; |
Herb Derby | 8a6348e | 2018-07-12 15:30:35 -0400 | [diff] [blame] | 25 | font.setTypeface(tf); |
Ben Wagner | 5785e4a | 2019-05-07 16:50:29 -0400 | [diff] [blame] | 26 | font.setHinting(SkFontHinting::kNormal); |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 27 | font.setSize(1u); |
Herb Derby | 8a6348e | 2018-07-12 15:30:35 -0400 | [diff] [blame] | 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 | |
Herb Derby | 8a6348e | 2018-07-12 15:30:35 -0400 | [diff] [blame] | 43 | SkGlyphRunBuilder runBuilder; |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 44 | SkPaint legacy_paint; |
| 45 | font.LEGACY_applyToPaint(&legacy_paint); |
| 46 | runBuilder.drawTextBlob(legacy_paint, *blob, SkPoint::Make(0, 0)); |
Herb Derby | 8a6348e | 2018-07-12 15:30:35 -0400 | [diff] [blame] | 47 | |
| 48 | auto runList = runBuilder.useGlyphRunList(); |
| 49 | |
Herb Derby | b935cf8 | 2018-07-26 16:54:18 -0400 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, runList.size() == runCount); |
Herb Derby | 8a6348e | 2018-07-12 15:30:35 -0400 | [diff] [blame] | 51 | int runIndex = 0; |
Herb Derby | b935cf8 | 2018-07-26 16:54:18 -0400 | [diff] [blame] | 52 | for (auto& run : runList) { |
Herb Derby | 8a6348e | 2018-07-12 15:30:35 -0400 | [diff] [blame] | 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 | } |
Mike Reed | 30cf62b | 2018-12-20 11:18:24 -0500 | [diff] [blame] | 67 | #endif |