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

Side by Side Diff: gm/typeface.cpp

Issue 2080453002: Add gm for various font rendering combinations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More combinations in a better grid. Created 4 years, 5 months 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 | « no previous file | resources/fonts/hintgasp.ttf » ('j') | 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 2012 Google Inc. 2 * Copyright 2012 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 "gm.h" 8 #include "gm.h"
9 #include "Resources.h"
9 #include "SkCanvas.h" 10 #include "SkCanvas.h"
10 #include "SkString.h" 11 #include "SkString.h"
12 #include "SkSurfaceProps.h"
11 #include "SkTypeface.h" 13 #include "SkTypeface.h"
12 #include "SkTypes.h" 14 #include "SkTypes.h"
13 15
14 static void getGlyphPositions(const SkPaint& paint, const uint16_t glyphs[], 16 static void getGlyphPositions(const SkPaint& paint, const uint16_t glyphs[],
15 int count, SkScalar x, SkScalar y, SkPoint pos[]) { 17 int count, SkScalar x, SkScalar y, SkPoint pos[]) {
16 SkASSERT(SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()); 18 SkASSERT(SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding());
17 19
18 SkAutoSTMalloc<128, SkScalar> widthStorage(count); 20 SkAutoSTMalloc<128, SkScalar> widthStorage(count);
19 SkScalar* widths = widthStorage.get(); 21 SkScalar* widths = widthStorage.get();
20 paint.getTextWidths(glyphs, count * sizeof(uint16_t), widths); 22 paint.getTextWidths(glyphs, count * sizeof(uint16_t), widths);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 drawKernText(canvas, text, textLen, x + 240, y, paint); 147 drawKernText(canvas, text, textLen, x + 240, y, paint);
146 } 148 }
147 y += dy; 149 y += dy;
148 } 150 }
149 } 151 }
150 152
151 private: 153 private:
152 typedef skiagm::GM INHERITED; 154 typedef skiagm::GM INHERITED;
153 }; 155 };
154 156
157 static void rotate_about(SkCanvas* canvas,
158 SkScalar degrees,
159 SkScalar px, SkScalar py) {
160 canvas->translate(px, py);
161 canvas->rotate(degrees);
162 canvas->translate(-px, -py);
163 }
164
165 class TypefaceRenderingGM : public skiagm::GM {
166 sk_sp<SkTypeface> fFace;
167
168 public:
169 TypefaceRenderingGM() { }
170
171 protected:
172 void onOnceBeforeDraw() override {
173 fFace = MakeResourceAsTypeface("/fonts/hintgasp.ttf");
174 }
175
176 SkString onShortName() override {
177 SkString name("typefacerendering");
178 name.append(sk_tool_utils::major_platform_os_name());
179 return name;
180 }
181
182 SkISize onISize() override {
183 return SkISize::Make(640, 480);
184 }
185
186 void onDraw(SkCanvas* canvas) override {
187 struct AliasType {
188 bool antiAlias;
189 bool subpixelAntitalias;
190 bool inLayer;
191 } constexpr aliasTypes[] {
192 { false, false, false }, // aliased
193 { true, false, false }, // anti-aliased
194 { true, true , false }, // subpixel anti-aliased
195 { true, false, true }, // anti-aliased in layer (flat pixel geome try)
196 { true, true , true }, // subpixel anti-aliased in layer (flat pi xel geometry)
197 };
198
199 // The hintgasp.ttf is designed for the following sizes to be different.
200 // GASP_DOGRAY 0x0002 0<=ppem<=10
201 // GASP_SYMMETRIC_SMOOTHING 0x0008 0<=ppem<=10
202 // GASP_GRIDFIT 0x0001 11<=ppem<=12
203 // GASP_SYMMETRIC_GRIDFIT 0x0004 11<=ppem<=12
204 // GASP_DOGRAY|GASP_GRIDFIT 0x0003 13<=ppem<=14
205 // GASP_SYMMETRIC_SMOOTHING|GASP_SYMMETRIC_GRIDFIT 0x000C 13<=ppem<=14
206 // (neither) 0x0000 15<=ppem
207 constexpr SkScalar textSizes[] = { 10, 12, 14, 16 };
208
209 constexpr SkPaint::Hinting hintingTypes[] = { SkPaint::kNo_Hinting,
210 SkPaint::kSlight_Hinting,
211 SkPaint::kNormal_Hinting,
212 SkPaint::kFull_Hinting };
213
214 struct SubpixelType {
215 bool requested;
216 SkVector offset;
217 } constexpr subpixelTypes[] = {
218 { false, { 0.00, 0.00 } },
219 { true , { 0.00, 0.00 } },
220 { true , { 0.25, 0.00 } },
221 { true , { 0.25, 0.25 } },
222 };
223
224 constexpr bool rotateABitTypes[] = { false, true };
225
226 SkPaint paint;
227 SkScalar x = 0;
228 SkScalar xMax = x;
229 SkScalar xBase = 0;
230 SkScalar y = 0; // The baseline of the previous output
231 for (const SubpixelType subpixel : subpixelTypes) {
232 y = 0;
233 paint.setSubpixelText(subpixel.requested);
234
235 for (const AliasType& alias : aliasTypes) {
236 paint.setAntiAlias(alias.antiAlias);
237 paint.setLCDRenderText(alias.subpixelAntitalias);
238 SkAutoCanvasRestore acr(canvas, false);
239 if (alias.inLayer) {
240 canvas->saveLayer(nullptr, &paint);
241 }
242
243 for (const SkScalar& textSize : textSizes) {
244 x = xBase + 5;
245 paint.setTextSize(textSize);
246
247 SkScalar dy = SkScalarCeilToScalar(paint.getFontMetrics(null ptr));
248 y += dy;
249 for (const SkPaint::Hinting& hinting : hintingTypes) {
250 paint.setHinting(hinting);
251
252 for (const bool& rotateABit : rotateABitTypes) {
253 SkAutoCanvasRestore acr(canvas, true);
254 if (rotateABit) {
255 rotate_about(canvas, 2, x + subpixel.offset.x(),
256 y + subpixel.offset.y()) ;
257 }
258 canvas->drawText("A", 1, x + subpixel.offset.x(),
259 y + subpixel.offset.y(), pa int);
260
261 SkScalar dx = SkScalarCeilToScalar(paint.measureText ("A", 1)) + 5;
262 x += dx;
263 xMax = SkTMax(x, xMax);
264 }
265 }
266 }
267 y += 10;
268 }
269 xBase = xMax;
270 }
271 }
272
273 private:
274 typedef skiagm::GM INHERITED;
275 };
276
155 /////////////////////////////////////////////////////////////////////////////// 277 ///////////////////////////////////////////////////////////////////////////////
156 278
157 DEF_GM( return new TypefaceStylesGM(false); ) 279 DEF_GM( return new TypefaceStylesGM(false); )
158 DEF_GM( return new TypefaceStylesGM(true); ) 280 DEF_GM( return new TypefaceStylesGM(true); )
281 DEF_GM( return new TypefaceRenderingGM(); )
OLDNEW
« no previous file with comments | « no previous file | resources/fonts/hintgasp.ttf » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698