OLD | NEW |
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 "Resources.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 drawKernText(canvas, text, textLen, x + 240, y, paint); | 147 drawKernText(canvas, text, textLen, x + 240, y, paint); |
148 } | 148 } |
149 y += dy; | 149 y += dy; |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 private: | 153 private: |
154 typedef skiagm::GM INHERITED; | 154 typedef skiagm::GM INHERITED; |
155 }; | 155 }; |
156 | 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 { | 157 class TypefaceRenderingGM : public skiagm::GM { |
166 sk_sp<SkTypeface> fFace; | 158 sk_sp<SkTypeface> fFace; |
167 | 159 |
168 public: | |
169 TypefaceRenderingGM() { } | |
170 | |
171 protected: | 160 protected: |
172 void onOnceBeforeDraw() override { | 161 void onOnceBeforeDraw() override { |
173 fFace = MakeResourceAsTypeface("/fonts/hintgasp.ttf"); | 162 fFace = MakeResourceAsTypeface("/fonts/hintgasp.ttf"); |
174 } | 163 } |
175 | 164 |
176 SkString onShortName() override { | 165 SkString onShortName() override { |
177 SkString name("typefacerendering"); | 166 SkString name("typefacerendering"); |
178 name.append(sk_tool_utils::major_platform_os_name()); | 167 name.append(sk_tool_utils::major_platform_os_name()); |
179 return name; | 168 return name; |
180 } | 169 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 paint.setTextSize(textSize); | 238 paint.setTextSize(textSize); |
250 | 239 |
251 SkScalar dy = SkScalarCeilToScalar(paint.getFontMetrics(null
ptr)); | 240 SkScalar dy = SkScalarCeilToScalar(paint.getFontMetrics(null
ptr)); |
252 y += dy; | 241 y += dy; |
253 for (const SkPaint::Hinting& hinting : hintingTypes) { | 242 for (const SkPaint::Hinting& hinting : hintingTypes) { |
254 paint.setHinting(hinting); | 243 paint.setHinting(hinting); |
255 | 244 |
256 for (const bool& rotateABit : rotateABitTypes) { | 245 for (const bool& rotateABit : rotateABitTypes) { |
257 SkAutoCanvasRestore acr(canvas, true); | 246 SkAutoCanvasRestore acr(canvas, true); |
258 if (rotateABit) { | 247 if (rotateABit) { |
259 rotate_about(canvas, 2, x + subpixel.offset.x(), | 248 canvas->rotate(2, x + subpixel.offset.x(), |
260 y + subpixel.offset.y())
; | 249 y + subpixel.offset.y()); |
261 } | 250 } |
262 canvas->drawText("A", 1, x + subpixel.offset.x(), | 251 canvas->drawText("A", 1, x + subpixel.offset.x(), |
263 y + subpixel.offset.y(), pa
int); | 252 y + subpixel.offset.y(), pa
int); |
264 | 253 |
265 SkScalar dx = SkScalarCeilToScalar(paint.measureText
("A", 1)) + 5; | 254 SkScalar dx = SkScalarCeilToScalar(paint.measureText
("A", 1)) + 5; |
266 x += dx; | 255 x += dx; |
267 xMax = SkTMax(x, xMax); | 256 xMax = SkTMax(x, xMax); |
268 } | 257 } |
269 } | 258 } |
270 } | 259 } |
271 y += 10; | 260 y += 10; |
272 } | 261 } |
273 xBase = xMax; | 262 xBase = xMax; |
274 } | 263 } |
275 } | 264 } |
276 | 265 |
277 private: | 266 private: |
278 typedef skiagm::GM INHERITED; | 267 typedef skiagm::GM INHERITED; |
279 }; | 268 }; |
280 | 269 |
281 /////////////////////////////////////////////////////////////////////////////// | 270 /////////////////////////////////////////////////////////////////////////////// |
282 | 271 |
283 DEF_GM( return new TypefaceStylesGM(false); ) | 272 DEF_GM( return new TypefaceStylesGM(false); ) |
284 DEF_GM( return new TypefaceStylesGM(true); ) | 273 DEF_GM( return new TypefaceStylesGM(true); ) |
285 DEF_GM( return new TypefaceRenderingGM(); ) | 274 DEF_GM( return new TypefaceRenderingGM(); ) |
OLD | NEW |