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 | |
| 8 | #include "SkGlyphRun.h" |
| 9 | |
Herb Derby | b9177cf | 2018-06-18 19:13:37 -0400 | [diff] [blame^] | 10 | #include "SkTextBlob.h" |
| 11 | |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 12 | #include "Test.h" |
| 13 | |
Herb Derby | b9177cf | 2018-06-18 19:13:37 -0400 | [diff] [blame^] | 14 | DEF_TEST(GlyphSetBasic, reporter) { |
| 15 | SkGlyphSet set; |
| 16 | |
| 17 | std::vector<SkGlyphID> unique; |
| 18 | |
| 19 | set.reuse(10, &unique); |
| 20 | REPORTER_ASSERT(reporter, set.add(7) == 0); |
| 21 | REPORTER_ASSERT(reporter, set.add(3) == 1); |
| 22 | set.reuse(10, &unique); |
| 23 | REPORTER_ASSERT(reporter, set.add(5) == 0); |
| 24 | REPORTER_ASSERT(reporter, set.add(8) == 1); |
| 25 | REPORTER_ASSERT(reporter, set.add(3) == 2); |
| 26 | |
| 27 | REPORTER_ASSERT(reporter, unique.size() == 5); |
| 28 | REPORTER_ASSERT(reporter, unique[0] == 7); |
| 29 | REPORTER_ASSERT(reporter, unique[1] == 3); |
| 30 | REPORTER_ASSERT(reporter, unique[2] == 5); |
| 31 | REPORTER_ASSERT(reporter, unique[3] == 8); |
| 32 | REPORTER_ASSERT(reporter, unique[4] == 3); |
| 33 | } |
| 34 | |
| 35 | DEF_TEST(GlyphRunBasic, reporter) { |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 36 | SkGlyphID glyphs[] = {100, 3, 240, 3, 234, 111, 3, 4, 10, 11}; |
| 37 | uint16_t count = SK_ARRAY_COUNT(glyphs); |
| 38 | |
| 39 | SkPaint paint; |
| 40 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 41 | |
Herb Derby | 59d997a | 2018-06-07 12:44:09 -0400 | [diff] [blame] | 42 | SkGlyphRunBuilder builder; |
| 43 | builder.prepareDrawText(paint, glyphs, count, SkPoint::Make(0, 0)); |
Herb Derby | b9177cf | 2018-06-18 19:13:37 -0400 | [diff] [blame^] | 44 | } |
Herb Derby | 4ffa027 | 2018-06-04 15:49:15 -0400 | [diff] [blame] | 45 | |
Herb Derby | b9177cf | 2018-06-18 19:13:37 -0400 | [diff] [blame^] | 46 | DEF_TEST(GlyphRunBlob, reporter) { |
| 47 | constexpr uint16_t count = 10; |
| 48 | |
| 49 | auto tf = SkTypeface::MakeFromName("monospace", SkFontStyle()); |
| 50 | |
| 51 | SkPaint font; |
| 52 | font.setTypeface(tf); |
| 53 | font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 54 | font.setTextAlign(SkPaint::kLeft_Align); |
| 55 | font.setStyle(SkPaint::kFill_Style); |
| 56 | font.setHinting(SkPaint::kNormal_Hinting); |
| 57 | font.setTextSize(1u); |
| 58 | |
| 59 | SkTextBlobBuilder blobBuilder; |
| 60 | for (int runNum = 0; runNum < 2; runNum++) { |
| 61 | const auto& runBuffer = blobBuilder.allocRunPosH(font, count, runNum); |
| 62 | SkASSERT(runBuffer.utf8text == nullptr); |
| 63 | SkASSERT(runBuffer.clusters == nullptr); |
| 64 | |
| 65 | for (int i = 0; i < count; i++) { |
| 66 | runBuffer.glyphs[i] = static_cast<SkGlyphID>(i + runNum * 10); |
| 67 | runBuffer.pos[i] = SkIntToScalar(i + runNum * 10); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | auto blob = blobBuilder.make(); |
| 72 | |
| 73 | SkPaint paint; |
| 74 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 75 | |
| 76 | SkGlyphRunBuilder runBuilder; |
| 77 | runBuilder.prepareTextBlob(font, *blob, SkPoint::Make(0, 0)); |
| 78 | |
| 79 | auto runList = runBuilder.useGlyphRunList(); |
| 80 | |
| 81 | REPORTER_ASSERT(reporter, runList->size() == 2); |
| 82 | for (auto& run : *runList) { |
| 83 | REPORTER_ASSERT(reporter, run.runSize() == 10); |
| 84 | REPORTER_ASSERT(reporter, run.uniqueSize() == 10); |
| 85 | } |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 86 | } |