Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: tests/TextBlobTest.cpp

Issue 1447403003: SkTextBlob should store per-run text alignment (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkTextBlob.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkTextBlobRunIterator.h" 10 #include "SkTextBlobRunIterator.h"
11 #include "SkTypeface.h"
11 12
12 #include "Test.h" 13 #include "Test.h"
13 14
14 class TextBlobTester { 15 class TextBlobTester {
15 public: 16 public:
16 // This unit test feeds an SkTextBlobBuilder various runs then checks to see if 17 // This unit test feeds an SkTextBlobBuilder various runs then checks to see if
17 // the result contains the provided data and merges runs when appropriate. 18 // the result contains the provided data and merges runs when appropriate.
18 static void TestBuilder(skiatest::Reporter* reporter) { 19 static void TestBuilder(skiatest::Reporter* reporter) {
19 SkTextBlobBuilder builder; 20 SkTextBlobBuilder builder;
20 21
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 166
166 p.setTextEncoding(SkPaint::kUTF8_TextEncoding); 167 p.setTextEncoding(SkPaint::kUTF8_TextEncoding);
167 p.textToGlyphs(txt, txtLen, buffer.glyphs); 168 p.textToGlyphs(txt, txtLen, buffer.glyphs);
168 169
169 memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2); 170 memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2);
170 SkAutoTUnref<const SkTextBlob> blob(builder.build()); 171 SkAutoTUnref<const SkTextBlob> blob(builder.build());
171 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); 172 REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
172 } 173 }
173 } 174 }
174 175
176 // Verify that text-related properties are captured in run paints.
177 static void TestPaintProps(skiatest::Reporter* reporter) {
178 SkPaint font;
179 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
180
181 SkAutoTUnref<SkTypeface> typeface(SkTypeface::RefDefault());
182
183 // Kitchen sink font.
184 font.setTextSize(42);
185 font.setTextScaleX(4.2f);
186 font.setTypeface(typeface);
187 font.setTextSkewX(0.42f);
188 font.setTextAlign(SkPaint::kCenter_Align);
189 font.setHinting(SkPaint::kFull_Hinting);
190 font.setAntiAlias(true);
191 font.setUnderlineText(true);
192 font.setStrikeThruText(true);
193 font.setFakeBoldText(true);
194 font.setLinearText(true);
195 font.setSubpixelText(true);
196 font.setDevKernText(true);
197 font.setLCDRenderText(true);
198 font.setEmbeddedBitmapText(true);
199 font.setAutohinted(true);
200 font.setVerticalText(true);
201 font.setFlags(font.getFlags() | SkPaint::kGenA8FromLCD_Flag);
202
203 // Ensure we didn't pick default values by mistake.
204 SkPaint defaultPaint;
205 REPORTER_ASSERT(reporter, defaultPaint.getTextSize() != font.getTextSize ());
206 REPORTER_ASSERT(reporter, defaultPaint.getTextScaleX() != font.getTextSc aleX());
207 REPORTER_ASSERT(reporter, defaultPaint.getTypeface() != font.getTypeface ());
208 REPORTER_ASSERT(reporter, defaultPaint.getTextSkewX() != font.getTextSke wX());
209 REPORTER_ASSERT(reporter, defaultPaint.getTextAlign() != font.getTextAli gn());
210 REPORTER_ASSERT(reporter, defaultPaint.getHinting() != font.getHinting() );
211 REPORTER_ASSERT(reporter, defaultPaint.isAntiAlias() != font.isAntiAlias ());
212 REPORTER_ASSERT(reporter, defaultPaint.isUnderlineText() != font.isUnder lineText());
213 REPORTER_ASSERT(reporter, defaultPaint.isStrikeThruText() != font.isStri keThruText());
214 REPORTER_ASSERT(reporter, defaultPaint.isFakeBoldText() != font.isFakeBo ldText());
215 REPORTER_ASSERT(reporter, defaultPaint.isLinearText() != font.isLinearTe xt());
216 REPORTER_ASSERT(reporter, defaultPaint.isSubpixelText() != font.isSubpix elText());
217 REPORTER_ASSERT(reporter, defaultPaint.isDevKernText() != font.isDevKern Text());
218 REPORTER_ASSERT(reporter, defaultPaint.isLCDRenderText() != font.isLCDRe nderText());
219 REPORTER_ASSERT(reporter, defaultPaint.isEmbeddedBitmapText() != font.is EmbeddedBitmapText());
220 REPORTER_ASSERT(reporter, defaultPaint.isAutohinted() != font.isAutohint ed());
221 REPORTER_ASSERT(reporter, defaultPaint.isVerticalText() != font.isVertic alText());
222 REPORTER_ASSERT(reporter, (defaultPaint.getFlags() & SkPaint::kGenA8From LCD_Flag) !=
223 (font.getFlags() & SkPaint::kGenA8FromLCD_Flag ));
224
225 SkTextBlobBuilder builder;
226 AddRun(font, 1, SkTextBlob::kDefault_Positioning, SkPoint::Make(0, 0), b uilder);
227 AddRun(font, 1, SkTextBlob::kHorizontal_Positioning, SkPoint::Make(0, 0) , builder);
228 AddRun(font, 1, SkTextBlob::kFull_Positioning, SkPoint::Make(0, 0), buil der);
229 SkAutoTUnref<const SkTextBlob> blob(builder.build());
230
231 SkTextBlobRunIterator it(blob);
232 while (!it.done()) {
233 SkPaint paint;
234 it.applyFontToPaint(&paint);
235
236 REPORTER_ASSERT(reporter, paint.getTextSize() == font.getTextSize()) ;
237 REPORTER_ASSERT(reporter, paint.getTextScaleX() == font.getTextScale X());
238 REPORTER_ASSERT(reporter, paint.getTypeface() == font.getTypeface()) ;
239 REPORTER_ASSERT(reporter, paint.getTextSkewX() == font.getTextSkewX( ));
240 REPORTER_ASSERT(reporter, paint.getTextAlign() == font.getTextAlign( ));
241 REPORTER_ASSERT(reporter, paint.getHinting() == font.getHinting());
242 REPORTER_ASSERT(reporter, paint.isAntiAlias() == font.isAntiAlias()) ;
243 REPORTER_ASSERT(reporter, paint.isUnderlineText() == font.isUnderlin eText());
244 REPORTER_ASSERT(reporter, paint.isStrikeThruText() == font.isStrikeT hruText());
245 REPORTER_ASSERT(reporter, paint.isFakeBoldText() == font.isFakeBoldT ext());
246 REPORTER_ASSERT(reporter, paint.isLinearText() == font.isLinearText( ));
247 REPORTER_ASSERT(reporter, paint.isSubpixelText() == font.isSubpixelT ext());
248 REPORTER_ASSERT(reporter, paint.isDevKernText() == font.isDevKernTex t());
249 REPORTER_ASSERT(reporter, paint.isLCDRenderText() == font.isLCDRende rText());
250 REPORTER_ASSERT(reporter, paint.isEmbeddedBitmapText() == font.isEmb eddedBitmapText());
251 REPORTER_ASSERT(reporter, paint.isAutohinted() == font.isAutohinted( ));
252 REPORTER_ASSERT(reporter, paint.isVerticalText() == font.isVerticalT ext());
253 REPORTER_ASSERT(reporter, (paint.getFlags() & SkPaint::kGenA8FromLCD _Flag) ==
254 (font.getFlags() & SkPaint::kGenA8FromLCD_ Flag));
255
256 it.next();
257 }
258
259 }
260
175 private: 261 private:
176 struct RunDef { 262 struct RunDef {
177 unsigned count; 263 unsigned count;
178 SkTextBlob::GlyphPositioning pos; 264 SkTextBlob::GlyphPositioning pos;
179 SkScalar x, y; 265 SkScalar x, y;
180 }; 266 };
181 267
182 static void RunBuilderTest(skiatest::Reporter* reporter, SkTextBlobBuilder& builder, 268 static void RunBuilderTest(skiatest::Reporter* reporter, SkTextBlobBuilder& builder,
183 const RunDef in[], unsigned inCount, 269 const RunDef in[], unsigned inCount,
184 const RunDef out[], unsigned outCount) { 270 const RunDef out[], unsigned outCount) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 default: 340 default:
255 SkFAIL("unhandled positioning value"); 341 SkFAIL("unhandled positioning value");
256 } 342 }
257 } 343 }
258 }; 344 };
259 345
260 DEF_TEST(TextBlob_builder, reporter) { 346 DEF_TEST(TextBlob_builder, reporter) {
261 TextBlobTester::TestBuilder(reporter); 347 TextBlobTester::TestBuilder(reporter);
262 TextBlobTester::TestBounds(reporter); 348 TextBlobTester::TestBounds(reporter);
263 } 349 }
350
351 DEF_TEST(TextBlob_paint, reporter) {
352 TextBlobTester::TestPaintProps(reporter);
353 }
OLDNEW
« no previous file with comments | « src/core/SkTextBlob.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698