fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 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 "include/core/SkPaint.h" |
| 9 | #include "include/core/SkPoint.h" |
| 10 | #include "include/core/SkSerialProcs.h" |
| 11 | #include "include/core/SkTypeface.h" |
| 12 | #include "include/private/SkTo.h" |
| 13 | #include "src/core/SkTextBlobPriv.h" |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 14 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "tests/Test.h" |
| 16 | #include "tools/ToolUtils.h" |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 17 | |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 18 | class TextBlobTester { |
| 19 | public: |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 20 | // This unit test feeds an SkTextBlobBuilder various runs then checks to see if |
| 21 | // the result contains the provided data and merges runs when appropriate. |
| 22 | static void TestBuilder(skiatest::Reporter* reporter) { |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 23 | SkTextBlobBuilder builder; |
| 24 | |
| 25 | // empty run set |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 26 | RunBuilderTest(reporter, builder, nullptr, 0, nullptr, 0); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 27 | |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 28 | RunDef set1[] = { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 29 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 100 }, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 30 | }; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 31 | RunBuilderTest(reporter, builder, set1, SK_ARRAY_COUNT(set1), set1, SK_ARRAY_COUNT(set1)); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 32 | |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 33 | RunDef set2[] = { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 34 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 100, 100 }, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 35 | }; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 36 | RunBuilderTest(reporter, builder, set2, SK_ARRAY_COUNT(set2), set2, SK_ARRAY_COUNT(set2)); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 37 | |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 38 | RunDef set3[] = { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 39 | { 128, SkTextBlobRunIterator::kFull_Positioning, 100, 100 }, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 40 | }; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 41 | RunBuilderTest(reporter, builder, set3, SK_ARRAY_COUNT(set3), set3, SK_ARRAY_COUNT(set3)); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 42 | |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 43 | RunDef set4[] = { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 44 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 }, |
| 45 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 }, |
| 46 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 }, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 47 | }; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 48 | RunBuilderTest(reporter, builder, set4, SK_ARRAY_COUNT(set4), set4, SK_ARRAY_COUNT(set4)); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 49 | |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 50 | RunDef set5[] = { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 51 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 100, 150 }, |
| 52 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 200, 150 }, |
| 53 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 300, 250 }, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 54 | }; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 55 | RunDef mergedSet5[] = { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 56 | { 256, SkTextBlobRunIterator::kHorizontal_Positioning, 0, 150 }, |
| 57 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 0, 250 }, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 58 | }; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 59 | RunBuilderTest(reporter, builder, set5, SK_ARRAY_COUNT(set5), mergedSet5, |
| 60 | SK_ARRAY_COUNT(mergedSet5)); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 61 | |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 62 | RunDef set6[] = { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 63 | { 128, SkTextBlobRunIterator::kFull_Positioning, 100, 100 }, |
| 64 | { 128, SkTextBlobRunIterator::kFull_Positioning, 200, 200 }, |
| 65 | { 128, SkTextBlobRunIterator::kFull_Positioning, 300, 300 }, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 66 | }; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 67 | RunDef mergedSet6[] = { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 68 | { 384, SkTextBlobRunIterator::kFull_Positioning, 0, 0 }, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 69 | }; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 70 | RunBuilderTest(reporter, builder, set6, SK_ARRAY_COUNT(set6), mergedSet6, |
| 71 | SK_ARRAY_COUNT(mergedSet6)); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 72 | |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 73 | RunDef set7[] = { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 74 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 }, |
| 75 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 }, |
| 76 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 100, 150 }, |
| 77 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 200, 150 }, |
| 78 | { 128, SkTextBlobRunIterator::kFull_Positioning, 400, 350 }, |
| 79 | { 128, SkTextBlobRunIterator::kFull_Positioning, 400, 350 }, |
| 80 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 450 }, |
| 81 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 450 }, |
| 82 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 100, 550 }, |
| 83 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 200, 650 }, |
| 84 | { 128, SkTextBlobRunIterator::kFull_Positioning, 400, 750 }, |
| 85 | { 128, SkTextBlobRunIterator::kFull_Positioning, 400, 850 }, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 86 | }; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 87 | RunDef mergedSet7[] = { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 88 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 }, |
| 89 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 150 }, |
| 90 | { 256, SkTextBlobRunIterator::kHorizontal_Positioning, 0, 150 }, |
| 91 | { 256, SkTextBlobRunIterator::kFull_Positioning, 0, 0 }, |
| 92 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 450 }, |
| 93 | { 128, SkTextBlobRunIterator::kDefault_Positioning, 100, 450 }, |
| 94 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 0, 550 }, |
| 95 | { 128, SkTextBlobRunIterator::kHorizontal_Positioning, 0, 650 }, |
| 96 | { 256, SkTextBlobRunIterator::kFull_Positioning, 0, 0 }, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 97 | }; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 98 | RunBuilderTest(reporter, builder, set7, SK_ARRAY_COUNT(set7), mergedSet7, |
| 99 | SK_ARRAY_COUNT(mergedSet7)); |
| 100 | } |
| 101 | |
| 102 | // This unit test verifies blob bounds computation. |
| 103 | static void TestBounds(skiatest::Reporter* reporter) { |
| 104 | SkTextBlobBuilder builder; |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 105 | SkFont font; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 106 | |
| 107 | // Explicit bounds. |
| 108 | { |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 109 | sk_sp<SkTextBlob> blob(builder.make()); |
Florin Malita | 3a9a7a3 | 2017-03-13 09:03:24 -0400 | [diff] [blame] | 110 | REPORTER_ASSERT(reporter, !blob); |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | { |
| 114 | SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); |
| 115 | builder.allocRun(font, 16, 0, 0, &r1); |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 116 | sk_sp<SkTextBlob> blob(builder.make()); |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 117 | REPORTER_ASSERT(reporter, blob->bounds() == r1); |
| 118 | } |
| 119 | |
| 120 | { |
| 121 | SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); |
| 122 | builder.allocRunPosH(font, 16, 0, &r1); |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 123 | sk_sp<SkTextBlob> blob(builder.make()); |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 124 | REPORTER_ASSERT(reporter, blob->bounds() == r1); |
| 125 | } |
| 126 | |
| 127 | { |
| 128 | SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); |
| 129 | builder.allocRunPos(font, 16, &r1); |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 130 | sk_sp<SkTextBlob> blob(builder.make()); |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 131 | REPORTER_ASSERT(reporter, blob->bounds() == r1); |
| 132 | } |
| 133 | |
| 134 | { |
| 135 | SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); |
| 136 | SkRect r2 = SkRect::MakeXYWH(15, 20, 50, 50); |
| 137 | SkRect r3 = SkRect::MakeXYWH(0, 5, 10, 5); |
| 138 | |
| 139 | builder.allocRun(font, 16, 0, 0, &r1); |
| 140 | builder.allocRunPosH(font, 16, 0, &r2); |
| 141 | builder.allocRunPos(font, 16, &r3); |
| 142 | |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 143 | sk_sp<SkTextBlob> blob(builder.make()); |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 144 | REPORTER_ASSERT(reporter, blob->bounds() == SkRect::MakeXYWH(0, 5, 65, 65)); |
| 145 | } |
| 146 | |
| 147 | { |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 148 | sk_sp<SkTextBlob> blob(builder.make()); |
Florin Malita | 3a9a7a3 | 2017-03-13 09:03:24 -0400 | [diff] [blame] | 149 | REPORTER_ASSERT(reporter, !blob); |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | // Implicit bounds |
fmalita | 9ae8fe1 | 2015-10-13 08:59:23 -0700 | [diff] [blame] | 153 | |
| 154 | { |
| 155 | // Exercise the empty bounds path, and ensure that RunRecord-aligned pos buffers |
| 156 | // don't trigger asserts (http://crbug.com/542643). |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 157 | font.setSize(0); |
fmalita | 9ae8fe1 | 2015-10-13 08:59:23 -0700 | [diff] [blame] | 158 | |
| 159 | const char* txt = "BOOO"; |
fmalita | 0b01da7 | 2015-10-14 08:11:40 -0700 | [diff] [blame] | 160 | const size_t txtLen = strlen(txt); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 161 | const int glyphCount = font.countText(txt, txtLen, SkTextEncoding::kUTF8); |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 162 | const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(font, glyphCount); |
fmalita | 0b01da7 | 2015-10-14 08:11:40 -0700 | [diff] [blame] | 163 | |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 164 | font.textToGlyphs(txt, txtLen, SkTextEncoding::kUTF8, buffer.glyphs, glyphCount); |
fmalita | 0b01da7 | 2015-10-14 08:11:40 -0700 | [diff] [blame] | 165 | |
| 166 | memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2); |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 167 | sk_sp<SkTextBlob> blob(builder.make()); |
fmalita | 9ae8fe1 | 2015-10-13 08:59:23 -0700 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); |
| 169 | } |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 170 | } |
| 171 | |
fmalita | 32d6b87 | 2015-11-17 11:39:32 -0800 | [diff] [blame] | 172 | // Verify that text-related properties are captured in run paints. |
| 173 | static void TestPaintProps(skiatest::Reporter* reporter) { |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 174 | SkFont font; |
fmalita | 32d6b87 | 2015-11-17 11:39:32 -0800 | [diff] [blame] | 175 | // Kitchen sink font. |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 176 | font.setSize(42); |
| 177 | font.setScaleX(4.2f); |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 178 | font.setTypeface(ToolUtils::create_portable_typeface()); |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 179 | font.setSkewX(0.42f); |
Ben Wagner | 5785e4a | 2019-05-07 16:50:29 -0400 | [diff] [blame] | 180 | font.setHinting(SkFontHinting::kFull); |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 181 | font.setEdging(SkFont::Edging::kSubpixelAntiAlias); |
| 182 | font.setEmbolden(true); |
| 183 | font.setLinearMetrics(true); |
| 184 | font.setSubpixel(true); |
| 185 | font.setEmbeddedBitmaps(true); |
| 186 | font.setForceAutoHinting(true); |
fmalita | 32d6b87 | 2015-11-17 11:39:32 -0800 | [diff] [blame] | 187 | |
| 188 | // Ensure we didn't pick default values by mistake. |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 189 | SkFont defaultFont; |
| 190 | REPORTER_ASSERT(reporter, defaultFont.getSize() != font.getSize()); |
| 191 | REPORTER_ASSERT(reporter, defaultFont.getScaleX() != font.getScaleX()); |
Herb Derby | 087fad7 | 2019-01-22 14:45:16 -0500 | [diff] [blame] | 192 | REPORTER_ASSERT(reporter, defaultFont.getTypefaceOrDefault() != font.getTypefaceOrDefault()); |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 193 | REPORTER_ASSERT(reporter, defaultFont.getSkewX() != font.getSkewX()); |
| 194 | REPORTER_ASSERT(reporter, defaultFont.getHinting() != font.getHinting()); |
| 195 | REPORTER_ASSERT(reporter, defaultFont.getEdging() != font.getEdging()); |
| 196 | REPORTER_ASSERT(reporter, defaultFont.isEmbolden() != font.isEmbolden()); |
| 197 | REPORTER_ASSERT(reporter, defaultFont.isLinearMetrics() != font.isLinearMetrics()); |
| 198 | REPORTER_ASSERT(reporter, defaultFont.isSubpixel() != font.isSubpixel()); |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 199 | REPORTER_ASSERT(reporter, |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 200 | defaultFont.isEmbeddedBitmaps() != font.isEmbeddedBitmaps()); |
| 201 | REPORTER_ASSERT(reporter, defaultFont.isForceAutoHinting() != font.isForceAutoHinting()); |
fmalita | 32d6b87 | 2015-11-17 11:39:32 -0800 | [diff] [blame] | 202 | |
| 203 | SkTextBlobBuilder builder; |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 204 | AddRun(font, 1, SkTextBlobRunIterator::kDefault_Positioning, SkPoint::Make(0, 0), builder); |
| 205 | AddRun(font, 1, SkTextBlobRunIterator::kHorizontal_Positioning, SkPoint::Make(0, 0), |
| 206 | builder); |
| 207 | AddRun(font, 1, SkTextBlobRunIterator::kFull_Positioning, SkPoint::Make(0, 0), builder); |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 208 | sk_sp<SkTextBlob> blob(builder.make()); |
fmalita | 32d6b87 | 2015-11-17 11:39:32 -0800 | [diff] [blame] | 209 | |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 210 | SkTextBlobRunIterator it(blob.get()); |
fmalita | 32d6b87 | 2015-11-17 11:39:32 -0800 | [diff] [blame] | 211 | while (!it.done()) { |
Mike Reed | 60a0e87 | 2019-01-04 09:41:49 -0500 | [diff] [blame] | 212 | REPORTER_ASSERT(reporter, it.font() == font); |
fmalita | 32d6b87 | 2015-11-17 11:39:32 -0800 | [diff] [blame] | 213 | it.next(); |
| 214 | } |
| 215 | |
| 216 | } |
| 217 | |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 218 | private: |
| 219 | struct RunDef { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 220 | unsigned count; |
| 221 | SkTextBlobRunIterator::GlyphPositioning pos; |
| 222 | SkScalar x, y; |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 223 | }; |
| 224 | |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 225 | static void RunBuilderTest(skiatest::Reporter* reporter, SkTextBlobBuilder& builder, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 226 | const RunDef in[], unsigned inCount, |
| 227 | const RunDef out[], unsigned outCount) { |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 228 | SkFont font; |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 229 | |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 230 | for (unsigned i = 0; i < inCount; ++i) { |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 231 | AddRun(font, in[i].count, in[i].pos, SkPoint::Make(in[i].x, in[i].y), builder); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 232 | } |
| 233 | |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 234 | sk_sp<SkTextBlob> blob(builder.make()); |
Florin Malita | 3a9a7a3 | 2017-03-13 09:03:24 -0400 | [diff] [blame] | 235 | REPORTER_ASSERT(reporter, (inCount > 0) == SkToBool(blob)); |
| 236 | if (!blob) { |
| 237 | return; |
| 238 | } |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 239 | |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 240 | SkTextBlobRunIterator it(blob.get()); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 241 | for (unsigned i = 0; i < outCount; ++i) { |
| 242 | REPORTER_ASSERT(reporter, !it.done()); |
| 243 | REPORTER_ASSERT(reporter, out[i].pos == it.positioning()); |
| 244 | REPORTER_ASSERT(reporter, out[i].count == it.glyphCount()); |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 245 | if (SkTextBlobRunIterator::kDefault_Positioning == out[i].pos) { |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 246 | REPORTER_ASSERT(reporter, out[i].x == it.offset().x()); |
| 247 | REPORTER_ASSERT(reporter, out[i].y == it.offset().y()); |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 248 | } else if (SkTextBlobRunIterator::kHorizontal_Positioning == out[i].pos) { |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 249 | REPORTER_ASSERT(reporter, out[i].y == it.offset().y()); |
| 250 | } |
| 251 | |
| 252 | for (unsigned k = 0; k < it.glyphCount(); ++k) { |
| 253 | REPORTER_ASSERT(reporter, k % 128 == it.glyphs()[k]); |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 254 | if (SkTextBlobRunIterator::kHorizontal_Positioning == it.positioning()) { |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 255 | REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k]); |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 256 | } else if (SkTextBlobRunIterator::kFull_Positioning == it.positioning()) { |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 257 | REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k * 2]); |
| 258 | REPORTER_ASSERT(reporter, -SkIntToScalar(k % 128) == it.pos()[k * 2 + 1]); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | it.next(); |
| 263 | } |
| 264 | |
| 265 | REPORTER_ASSERT(reporter, it.done()); |
| 266 | } |
| 267 | |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 268 | static void AddRun(const SkFont& font, int count, SkTextBlobRunIterator::GlyphPositioning pos, |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 269 | const SkPoint& offset, SkTextBlobBuilder& builder, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 270 | const SkRect* bounds = nullptr) { |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 271 | switch (pos) { |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 272 | case SkTextBlobRunIterator::kDefault_Positioning: { |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 273 | const SkTextBlobBuilder::RunBuffer& rb = builder.allocRun(font, count, offset.x(), |
| 274 | offset.y(), bounds); |
| 275 | for (int i = 0; i < count; ++i) { |
| 276 | rb.glyphs[i] = i; |
| 277 | } |
| 278 | } break; |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 279 | case SkTextBlobRunIterator::kHorizontal_Positioning: { |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 280 | const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPosH(font, count, offset.y(), |
| 281 | bounds); |
| 282 | for (int i = 0; i < count; ++i) { |
| 283 | rb.glyphs[i] = i; |
| 284 | rb.pos[i] = SkIntToScalar(i); |
| 285 | } |
| 286 | } break; |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 287 | case SkTextBlobRunIterator::kFull_Positioning: { |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 288 | const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPos(font, count, bounds); |
| 289 | for (int i = 0; i < count; ++i) { |
| 290 | rb.glyphs[i] = i; |
| 291 | rb.pos[i * 2] = SkIntToScalar(i); |
| 292 | rb.pos[i * 2 + 1] = -SkIntToScalar(i); |
| 293 | } |
| 294 | } break; |
| 295 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 296 | SK_ABORT("unhandled positioning value"); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | }; |
| 300 | |
| 301 | DEF_TEST(TextBlob_builder, reporter) { |
fmalita | 51bf957 | 2014-08-22 07:50:45 -0700 | [diff] [blame] | 302 | TextBlobTester::TestBuilder(reporter); |
| 303 | TextBlobTester::TestBounds(reporter); |
fmalita | c6765d6 | 2014-08-21 15:03:04 -0700 | [diff] [blame] | 304 | } |
fmalita | 32d6b87 | 2015-11-17 11:39:32 -0800 | [diff] [blame] | 305 | |
| 306 | DEF_TEST(TextBlob_paint, reporter) { |
| 307 | TextBlobTester::TestPaintProps(reporter); |
| 308 | } |
halcanary | 4f0a23a | 2016-08-30 11:58:33 -0700 | [diff] [blame] | 309 | |
| 310 | DEF_TEST(TextBlob_extended, reporter) { |
| 311 | SkTextBlobBuilder textBlobBuilder; |
Mike Reed | 6d59568 | 2018-12-05 17:28:14 -0500 | [diff] [blame] | 312 | SkFont font; |
halcanary | 4f0a23a | 2016-08-30 11:58:33 -0700 | [diff] [blame] | 313 | const char text1[] = "Foo"; |
| 314 | const char text2[] = "Bar"; |
| 315 | |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 316 | int glyphCount = font.countText(text1, strlen(text1), SkTextEncoding::kUTF8); |
halcanary | 4f0a23a | 2016-08-30 11:58:33 -0700 | [diff] [blame] | 317 | SkAutoTMalloc<uint16_t> glyphs(glyphCount); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 318 | (void)font.textToGlyphs(text1, strlen(text1), SkTextEncoding::kUTF8, glyphs.get(), glyphCount); |
halcanary | 4f0a23a | 2016-08-30 11:58:33 -0700 | [diff] [blame] | 319 | |
Ben Wagner | 5d9c20e | 2021-02-24 11:43:07 -0500 | [diff] [blame] | 320 | auto run = textBlobBuilder.allocRunText(font, glyphCount, 0, 0, SkToInt(strlen(text2))); |
halcanary | 4f0a23a | 2016-08-30 11:58:33 -0700 | [diff] [blame] | 321 | memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount); |
| 322 | memcpy(run.utf8text, text2, strlen(text2)); |
| 323 | for (int i = 0; i < glyphCount; ++i) { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 324 | run.clusters[i] = std::min(SkToU32(i), SkToU32(strlen(text2))); |
halcanary | 4f0a23a | 2016-08-30 11:58:33 -0700 | [diff] [blame] | 325 | } |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 326 | sk_sp<SkTextBlob> blob(textBlobBuilder.make()); |
halcanary | 4f0a23a | 2016-08-30 11:58:33 -0700 | [diff] [blame] | 327 | REPORTER_ASSERT(reporter, blob); |
| 328 | |
| 329 | for (SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) { |
| 330 | REPORTER_ASSERT(reporter, it.glyphCount() == (uint32_t)glyphCount); |
| 331 | for (uint32_t i = 0; i < it.glyphCount(); ++i) { |
| 332 | REPORTER_ASSERT(reporter, it.glyphs()[i] == glyphs[i]); |
| 333 | } |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 334 | REPORTER_ASSERT(reporter, SkTextBlobRunIterator::kDefault_Positioning == it.positioning()); |
halcanary | 4f0a23a | 2016-08-30 11:58:33 -0700 | [diff] [blame] | 335 | REPORTER_ASSERT(reporter, (SkPoint{0.0f, 0.0f}) == it.offset()); |
| 336 | REPORTER_ASSERT(reporter, it.textSize() > 0); |
| 337 | REPORTER_ASSERT(reporter, it.clusters()); |
| 338 | for (uint32_t i = 0; i < it.glyphCount(); ++i) { |
| 339 | REPORTER_ASSERT(reporter, i == it.clusters()[i]); |
| 340 | } |
| 341 | REPORTER_ASSERT(reporter, 0 == strncmp(text2, it.text(), it.textSize())); |
| 342 | } |
| 343 | } |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 344 | |
| 345 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 346 | #include "include/core/SkCanvas.h" |
| 347 | #include "include/core/SkSurface.h" |
Ben Wagner | 96fdfe0 | 2019-07-09 16:39:29 -0400 | [diff] [blame] | 348 | #include "include/private/SkTArray.h" |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 349 | |
| 350 | static void add_run(SkTextBlobBuilder* builder, const char text[], SkScalar x, SkScalar y, |
| 351 | sk_sp<SkTypeface> tf) { |
Mike Reed | 70914f5 | 2018-11-23 13:08:33 -0500 | [diff] [blame] | 352 | SkFont font; |
| 353 | font.setEdging(SkFont::Edging::kAntiAlias); |
| 354 | font.setSubpixel(true); |
| 355 | font.setSize(16); |
| 356 | font.setTypeface(tf); |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 357 | |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 358 | int glyphCount = font.countText(text, strlen(text), SkTextEncoding::kUTF8); |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 359 | |
Mike Reed | 70914f5 | 2018-11-23 13:08:33 -0500 | [diff] [blame] | 360 | SkTextBlobBuilder::RunBuffer buffer = builder->allocRun(font, glyphCount, x, y); |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 361 | |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 362 | (void)font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, buffer.glyphs, glyphCount); |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static sk_sp<SkImage> render(const SkTextBlob* blob) { |
| 366 | auto surf = SkSurface::MakeRasterN32Premul(SkScalarRoundToInt(blob->bounds().width()), |
| 367 | SkScalarRoundToInt(blob->bounds().height())); |
Mike Reed | 7e49d53 | 2017-07-11 15:07:08 -0400 | [diff] [blame] | 368 | if (!surf) { |
| 369 | return nullptr; // bounds are empty? |
| 370 | } |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 371 | surf->getCanvas()->clear(SK_ColorWHITE); |
| 372 | surf->getCanvas()->drawTextBlob(blob, -blob->bounds().left(), -blob->bounds().top(), SkPaint()); |
| 373 | return surf->makeImageSnapshot(); |
| 374 | } |
| 375 | |
Cary Clark | 785586a | 2018-07-19 10:07:01 -0400 | [diff] [blame] | 376 | static sk_sp<SkData> SerializeTypeface(SkTypeface* tf, void* ctx) { |
Ben Wagner | 96fdfe0 | 2019-07-09 16:39:29 -0400 | [diff] [blame] | 377 | auto array = (SkTArray<sk_sp<SkTypeface>>*)ctx; |
| 378 | const size_t idx = array->size(); |
| 379 | array->emplace_back(sk_ref_sp(tf)); |
| 380 | // In this test, we are deserializing on the same machine, so we don't worry about endianness. |
| 381 | return SkData::MakeWithCopy(&idx, sizeof(idx)); |
Cary Clark | 785586a | 2018-07-19 10:07:01 -0400 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | static sk_sp<SkTypeface> DeserializeTypeface(const void* data, size_t length, void* ctx) { |
Ben Wagner | 96fdfe0 | 2019-07-09 16:39:29 -0400 | [diff] [blame] | 385 | auto array = (SkTArray<sk_sp<SkTypeface>>*)ctx; |
| 386 | if (length != sizeof(size_t)) { |
| 387 | SkASSERT(false); |
| 388 | return nullptr; |
Cary Clark | 785586a | 2018-07-19 10:07:01 -0400 | [diff] [blame] | 389 | } |
Ben Wagner | 96fdfe0 | 2019-07-09 16:39:29 -0400 | [diff] [blame] | 390 | size_t idx = *reinterpret_cast<const size_t*>(data); |
| 391 | if (idx >= array->size()) { |
| 392 | SkASSERT(false); |
| 393 | return nullptr; |
| 394 | } |
| 395 | return (*array)[idx]; |
Cary Clark | 785586a | 2018-07-19 10:07:01 -0400 | [diff] [blame] | 396 | } |
| 397 | |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 398 | /* |
| 399 | * Build a blob with more than one typeface. |
| 400 | * Draw it into an offscreen, |
| 401 | * then serialize and deserialize, |
| 402 | * Then draw the new instance and assert it draws the same as the original. |
| 403 | */ |
| 404 | DEF_TEST(TextBlob_serialize, reporter) { |
Mike Reed | 4bcef3c | 2017-12-08 11:46:09 -0500 | [diff] [blame] | 405 | sk_sp<SkTextBlob> blob0 = []() { |
Ben Wagner | 96fdfe0 | 2019-07-09 16:39:29 -0400 | [diff] [blame] | 406 | sk_sp<SkTypeface> tf = SkTypeface::MakeFromName(nullptr, SkFontStyle::BoldItalic()); |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 407 | |
Mike Reed | 4bcef3c | 2017-12-08 11:46:09 -0500 | [diff] [blame] | 408 | SkTextBlobBuilder builder; |
Mike Reed | 0951cc2 | 2018-12-21 16:19:24 -0500 | [diff] [blame] | 409 | add_run(&builder, "Hello", 10, 20, nullptr); // don't flatten a typeface |
| 410 | add_run(&builder, "World", 10, 40, tf); // do flatten this typeface |
Mike Reed | 4bcef3c | 2017-12-08 11:46:09 -0500 | [diff] [blame] | 411 | return builder.make(); |
| 412 | }(); |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 413 | |
Ben Wagner | 96fdfe0 | 2019-07-09 16:39:29 -0400 | [diff] [blame] | 414 | SkTArray<sk_sp<SkTypeface>> array; |
Cary Clark | 785586a | 2018-07-19 10:07:01 -0400 | [diff] [blame] | 415 | SkSerialProcs serializeProcs; |
| 416 | serializeProcs.fTypefaceProc = &SerializeTypeface; |
| 417 | serializeProcs.fTypefaceCtx = (void*) &array; |
| 418 | sk_sp<SkData> data = blob0->serialize(serializeProcs); |
Mike Reed | 0951cc2 | 2018-12-21 16:19:24 -0500 | [diff] [blame] | 419 | REPORTER_ASSERT(reporter, array.count() == 1); |
Cary Clark | 785586a | 2018-07-19 10:07:01 -0400 | [diff] [blame] | 420 | SkDeserialProcs deserializeProcs; |
| 421 | deserializeProcs.fTypefaceProc = &DeserializeTypeface; |
| 422 | deserializeProcs.fTypefaceCtx = (void*) &array; |
| 423 | sk_sp<SkTextBlob> blob1 = SkTextBlob::Deserialize(data->data(), data->size(), deserializeProcs); |
Mike Reed | 7e49d53 | 2017-07-11 15:07:08 -0400 | [diff] [blame] | 424 | |
| 425 | sk_sp<SkImage> img0 = render(blob0.get()); |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 426 | sk_sp<SkImage> img1 = render(blob1.get()); |
Mike Reed | 7e49d53 | 2017-07-11 15:07:08 -0400 | [diff] [blame] | 427 | if (img0 && img1) { |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 428 | REPORTER_ASSERT(reporter, ToolUtils::equal_pixels(img0.get(), img1.get())); |
Mike Reed | b99bedd | 2017-07-11 10:27:40 -0400 | [diff] [blame] | 429 | } |
| 430 | } |
Herb Derby | 4b3a515 | 2018-07-17 16:10:30 -0400 | [diff] [blame] | 431 | |
| 432 | DEF_TEST(TextBlob_MakeAsDrawText, reporter) { |
Herb Derby | 4b3a515 | 2018-07-17 16:10:30 -0400 | [diff] [blame] | 433 | const char text[] = "Hello"; |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 434 | auto blob = SkTextBlob::MakeFromString(text, SkFont(), SkTextEncoding::kUTF8); |
Herb Derby | 4b3a515 | 2018-07-17 16:10:30 -0400 | [diff] [blame] | 435 | |
| 436 | int runs = 0; |
| 437 | for(SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) { |
| 438 | REPORTER_ASSERT(reporter, it.glyphCount() == strlen(text)); |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 439 | REPORTER_ASSERT(reporter, it.positioning() == SkTextBlobRunIterator::kFull_Positioning); |
Herb Derby | 4b3a515 | 2018-07-17 16:10:30 -0400 | [diff] [blame] | 440 | runs += 1; |
| 441 | } |
| 442 | REPORTER_ASSERT(reporter, runs == 1); |
| 443 | |
| 444 | } |
Mike Reed | a32654c | 2019-10-04 10:18:34 -0400 | [diff] [blame] | 445 | |
| 446 | DEF_TEST(TextBlob_iter, reporter) { |
| 447 | sk_sp<SkTypeface> tf = SkTypeface::MakeFromName(nullptr, SkFontStyle::BoldItalic()); |
| 448 | |
| 449 | SkTextBlobBuilder builder; |
| 450 | add_run(&builder, "Hello", 10, 20, nullptr); |
| 451 | add_run(&builder, "World", 10, 40, tf); |
| 452 | auto blob = builder.make(); |
| 453 | |
| 454 | SkTextBlob::Iter::Run expected[] = { |
| 455 | { nullptr, 5, nullptr }, |
| 456 | { tf.get(), 5, nullptr }, |
| 457 | }; |
| 458 | |
| 459 | SkTextBlob::Iter iter(*blob); |
| 460 | SkTextBlob::Iter::Run run; |
| 461 | for (auto exp : expected) { |
| 462 | REPORTER_ASSERT(reporter, iter.next(&run)); |
| 463 | REPORTER_ASSERT(reporter, run.fTypeface == exp.fTypeface); |
| 464 | REPORTER_ASSERT(reporter, run.fGlyphCount == exp.fGlyphCount); |
| 465 | for (int i = 0; i < run.fGlyphCount; ++i) { |
| 466 | REPORTER_ASSERT(reporter, run.fGlyphIndices[i] != 0); |
| 467 | } |
| 468 | } |
| 469 | REPORTER_ASSERT(reporter, !iter.next(&run)); // we're done |
| 470 | |
| 471 | SkTextBlob::Iter iter2(*blob); |
| 472 | REPORTER_ASSERT(reporter, iter2.next(&run)); |
| 473 | // Hello should have the same glyph repeated for the 'l' |
| 474 | REPORTER_ASSERT(reporter, run.fGlyphIndices[2] == run.fGlyphIndices[3]); |
| 475 | } |
Lee Salzman | 634d150 | 2019-10-15 13:53:09 -0400 | [diff] [blame] | 476 | |
| 477 | DEF_TEST(TextBlob_getIntercepts, reporter) { |
| 478 | SkFont font; |
| 479 | font.setSize(16); |
| 480 | |
| 481 | SkPoint lowPos[1] = { SkPoint::Make(0, 5) }; |
| 482 | SkPoint highPos[1] = { SkPoint::Make(0, -8) }; |
| 483 | SkPoint zeroPos[1] = { SkPoint::Make(0, 0) }; |
| 484 | |
| 485 | // 'x' sitting on baseline |
| 486 | auto blobZeroX = SkTextBlob::MakeFromPosText("x", 1, zeroPos, font); |
| 487 | // 'x' lowered to intersect baseline |
| 488 | auto blobLowX = SkTextBlob::MakeFromPosText("x", 1, lowPos, font); |
| 489 | // 'y' sitting on baseline |
| 490 | auto blobZeroY = SkTextBlob::MakeFromPosText("y", 1, zeroPos, font); |
| 491 | // 'y' raised to not intersect baseline |
| 492 | auto blobHighY = SkTextBlob::MakeFromPosText("y", 1, highPos, font); |
| 493 | |
| 494 | // bounds right below baseline |
| 495 | SkScalar bounds[2] = { 1, 2 }; |
| 496 | |
| 497 | // 'x' on baseline should not intersect |
| 498 | REPORTER_ASSERT(reporter, blobZeroX->getIntercepts(bounds, nullptr) == 0); |
| 499 | // lowered 'x' should intersect |
| 500 | REPORTER_ASSERT(reporter, blobLowX->getIntercepts(bounds, nullptr) == 2); |
| 501 | // 'y' on baseline should intersect |
| 502 | REPORTER_ASSERT(reporter, blobZeroY->getIntercepts(bounds, nullptr) == 2); |
| 503 | // raised 'y' should not intersect |
| 504 | REPORTER_ASSERT(reporter, blobHighY->getIntercepts(bounds, nullptr) == 0); |
| 505 | } |