blob: 0e0c441b7502e2af8675c945841d8124d12ac4d0 [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
8#include "SkGlyphRun.h"
9
Herb Derbyb9177cf2018-06-18 19:13:37 -040010#include "SkTextBlob.h"
11
Herb Derby41f4f312018-06-06 17:45:53 +000012#include "Test.h"
13
Herb Derbyfd77fe52018-07-09 17:06:09 -040014DEF_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 Derbyb9177cf2018-06-18 19:13:37 -040020
Herb Derbyfd77fe52018-07-09 17:06:09 -040021 SkGlyphIDSet gs;
22 auto uniqueGlyphIDs = gs.uniquifyGlyphIDs(universeSize, glyphIDs, uniqueGlyphs, denseIndices);
Herb Derbyb9177cf2018-06-18 19:13:37 -040023
Herb Derbyfd77fe52018-07-09 17:06:09 -040024 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 Derbyb9177cf2018-06-18 19:13:37 -040034
Herb Derbyfd77fe52018-07-09 17:06:09 -040035 {
36 SkGlyphID answer[] = {100, 3, 240, 234};
37 REPORTER_ASSERT(reporter,
38 std::equal(answer, std::end(answer), uniqueGlyphs));
39 }
Herb Derbyb9177cf2018-06-18 19:13:37 -040040}
41
42DEF_TEST(GlyphRunBasic, reporter) {
Herb Derby41f4f312018-06-06 17:45:53 +000043 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 Derby59d997a2018-06-07 12:44:09 -040049 SkGlyphRunBuilder builder;
50 builder.prepareDrawText(paint, glyphs, count, SkPoint::Make(0, 0));
Herb Derbyb9177cf2018-06-18 19:13:37 -040051}