OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPaint.h" | 8 #include "SkPaint.h" |
9 #include "SkPoint.h" | 9 #include "SkPoint.h" |
10 #include "SkTextBlob.h" | 10 #include "SkTextBlob.h" |
11 | 11 |
12 #include "Test.h" | 12 #include "Test.h" |
13 | 13 |
14 | |
15 class TextBlobTester { | 14 class TextBlobTester { |
16 public: | 15 public: |
17 // This unit test feeds an SkTextBlobBuilder various runs then checks to see
if | 16 // This unit test feeds an SkTextBlobBuilder various runs then checks to see
if |
18 // the result contains the provided data and merges runs when appropriate. | 17 // the result contains the provided data and merges runs when appropriate. |
19 static void TestBuilder(skiatest::Reporter* reporter) { | 18 static void TestBuilder(skiatest::Reporter* reporter) { |
20 SkTextBlobBuilder builder; | 19 SkTextBlobBuilder builder; |
21 | 20 |
22 // empty run set | 21 // empty run set |
23 RunBuilderTest(reporter, builder, nullptr, 0, nullptr, 0); | 22 RunBuilderTest(reporter, builder, nullptr, 0, nullptr, 0); |
24 | 23 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); | 147 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); |
149 } | 148 } |
150 | 149 |
151 // Implicit bounds | 150 // Implicit bounds |
152 | 151 |
153 { | 152 { |
154 // Exercise the empty bounds path, and ensure that RunRecord-aligned
pos buffers | 153 // Exercise the empty bounds path, and ensure that RunRecord-aligned
pos buffers |
155 // don't trigger asserts (http://crbug.com/542643). | 154 // don't trigger asserts (http://crbug.com/542643). |
156 SkPaint p; | 155 SkPaint p; |
157 p.setTextSize(0); | 156 p.setTextSize(0); |
158 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 157 p.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
159 | 158 |
160 const char* txt = "BOOO"; | 159 const char* txt = "BOOO"; |
161 const size_t len = strlen(txt); | 160 const size_t txtLen = strlen(txt); |
162 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(p,
(int)len); | 161 const int glyphCount = p.textToGlyphs(txt, txtLen, nullptr); |
163 p.textToGlyphs(txt, len, buffer.glyphs); | 162 |
164 memset(buffer.pos, 0, sizeof(SkScalar) * len * 2); | 163 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 164 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(p,
glyphCount); |
| 165 |
| 166 p.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
| 167 p.textToGlyphs(txt, txtLen, buffer.glyphs); |
| 168 |
| 169 memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2); |
165 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | 170 SkAutoTUnref<const SkTextBlob> blob(builder.build()); |
166 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); | 171 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); |
167 } | 172 } |
168 } | 173 } |
169 | 174 |
170 private: | 175 private: |
171 struct RunDef { | 176 struct RunDef { |
172 unsigned count; | 177 unsigned count; |
173 SkTextBlob::GlyphPositioning pos; | 178 SkTextBlob::GlyphPositioning pos; |
174 SkScalar x, y; | 179 SkScalar x, y; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 default: | 254 default: |
250 SkFAIL("unhandled positioning value"); | 255 SkFAIL("unhandled positioning value"); |
251 } | 256 } |
252 } | 257 } |
253 }; | 258 }; |
254 | 259 |
255 DEF_TEST(TextBlob_builder, reporter) { | 260 DEF_TEST(TextBlob_builder, reporter) { |
256 TextBlobTester::TestBuilder(reporter); | 261 TextBlobTester::TestBuilder(reporter); |
257 TextBlobTester::TestBounds(reporter); | 262 TextBlobTester::TestBounds(reporter); |
258 } | 263 } |
OLD | NEW |