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 | fd77fe5 | 2018-07-09 17:06:09 -0400 | [diff] [blame^] | 14 | DEF_TEST(GlyphRunGlyphIDSetBasic, reporter) { |
| 15 | SkGlyphID glyphs[] = {100, 3, 240, 3, 234}; |
| 16 | auto glyphIDs = SkSpan<const SkGlyphID>(glyphs, SK_ARRAY_COUNT(glyphs)); |
| 17 | int universeSize = 1000; |
| 18 | SkGlyphID uniqueGlyphs[SK_ARRAY_COUNT(glyphs)]; |
| 19 | uint16_t denseIndices[SK_ARRAY_COUNT(glyphs)]; |
Herb Derby | b9177cf | 2018-06-18 19:13:37 -0400 | [diff] [blame] | 20 | |
Herb Derby | fd77fe5 | 2018-07-09 17:06:09 -0400 | [diff] [blame^] | 21 | SkGlyphIDSet gs; |
| 22 | auto uniqueGlyphIDs = gs.uniquifyGlyphIDs(universeSize, glyphIDs, uniqueGlyphs, denseIndices); |
Herb Derby | b9177cf | 2018-06-18 19:13:37 -0400 | [diff] [blame] | 23 | |
Herb Derby | fd77fe5 | 2018-07-09 17:06:09 -0400 | [diff] [blame^] | 24 | std::vector<SkGlyphID> test{uniqueGlyphIDs.begin(), uniqueGlyphIDs.end()}; |
| 25 | std::sort(test.begin(), test.end()); |
| 26 | auto newEnd = std::unique(test.begin(), test.end()); |
| 27 | REPORTER_ASSERT(reporter, uniqueGlyphIDs.size() == newEnd - test.begin()); |
| 28 | REPORTER_ASSERT(reporter, uniqueGlyphIDs.size() == 4); |
| 29 | { |
| 30 | uint16_t answer[] = {0, 1, 2, 1, 3}; |
| 31 | REPORTER_ASSERT(reporter, |
| 32 | std::equal(answer, std::end(answer), denseIndices)); |
| 33 | } |
Herb Derby | b9177cf | 2018-06-18 19:13:37 -0400 | [diff] [blame] | 34 | |
Herb Derby | fd77fe5 | 2018-07-09 17:06:09 -0400 | [diff] [blame^] | 35 | { |
| 36 | SkGlyphID answer[] = {100, 3, 240, 234}; |
| 37 | REPORTER_ASSERT(reporter, |
| 38 | std::equal(answer, std::end(answer), uniqueGlyphs)); |
| 39 | } |
Herb Derby | b9177cf | 2018-06-18 19:13:37 -0400 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | DEF_TEST(GlyphRunBasic, reporter) { |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 43 | SkGlyphID glyphs[] = {100, 3, 240, 3, 234, 111, 3, 4, 10, 11}; |
| 44 | uint16_t count = SK_ARRAY_COUNT(glyphs); |
| 45 | |
| 46 | SkPaint paint; |
| 47 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 48 | |
Herb Derby | 59d997a | 2018-06-07 12:44:09 -0400 | [diff] [blame] | 49 | SkGlyphRunBuilder builder; |
| 50 | builder.prepareDrawText(paint, glyphs, count, SkPoint::Make(0, 0)); |
Herb Derby | b9177cf | 2018-06-18 19:13:37 -0400 | [diff] [blame] | 51 | } |