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 class TypefaceRenderingGM : public skiagm::GM { | 157 DEF_GM( return new TypefaceStylesGM(false); ) |
158 sk_sp<SkTypeface> fFace; | 158 DEF_GM( return new TypefaceStylesGM(true); ) |
159 | 159 |
160 protected: | 160 //////////////////////////////////////////////////////////////////////////////// |
161 void onOnceBeforeDraw() override { | |
162 fFace = MakeResourceAsTypeface("/fonts/hintgasp.ttf"); | |
163 } | |
164 | 161 |
165 SkString onShortName() override { | 162 static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp<SkTypeface> face, |
166 SkString name("typefacerendering"); | 163 char character = 'A') { |
167 name.append(sk_tool_utils::major_platform_os_name()); | |
168 return name; | |
169 } | |
170 | |
171 SkISize onISize() override { | |
172 return SkISize::Make(640, 680); | |
173 } | |
174 | |
175 void onDraw(SkCanvas* canvas) override { | |
176 struct AliasType { | 164 struct AliasType { |
177 bool antiAlias; | 165 bool antiAlias; |
178 bool subpixelAntitalias; | 166 bool subpixelAntitalias; |
179 bool inLayer; | 167 bool inLayer; |
180 } constexpr aliasTypes[] { | 168 } constexpr aliasTypes[] { |
181 #ifndef SK_BUILD_FOR_IOS | 169 #ifndef SK_BUILD_FOR_IOS |
182 // This gm crashes on iOS when drawing an embedded bitmap when reque
sting aliased rendering. | 170 // This gm crashes on iOS when drawing an embedded bitmap when reque
sting aliased rendering. |
183 // The crash looks like | 171 // The crash looks like |
184 // libTrueTypeScaler.dylib`<redacted> + 80 | 172 // libTrueTypeScaler.dylib`<redacted> + 80 |
185 // stop reason = EXC_BAD_ACCESS (code=EXC_ARM_DA_ALIGN, address=..
.) | 173 // stop reason = EXC_BAD_ACCESS (code=EXC_ARM_DA_ALIGN, address=..
.) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } constexpr subpixelTypes[] = { | 207 } constexpr subpixelTypes[] = { |
220 { false, { 0.00, 0.00 } }, | 208 { false, { 0.00, 0.00 } }, |
221 { true , { 0.00, 0.00 } }, | 209 { true , { 0.00, 0.00 } }, |
222 { true , { 0.25, 0.00 } }, | 210 { true , { 0.25, 0.00 } }, |
223 { true , { 0.25, 0.25 } }, | 211 { true , { 0.25, 0.25 } }, |
224 }; | 212 }; |
225 | 213 |
226 constexpr bool rotateABitTypes[] = { false, true }; | 214 constexpr bool rotateABitTypes[] = { false, true }; |
227 | 215 |
228 SkPaint paint; | 216 SkPaint paint; |
229 paint.setTypeface(fFace); | 217 paint.setTypeface(face); |
230 paint.setEmbeddedBitmapText(true); | 218 paint.setEmbeddedBitmapText(true); |
231 | 219 |
232 SkScalar x = 0; | 220 SkScalar x = 0; |
233 SkScalar xMax = x; | 221 SkScalar xMax = x; |
234 SkScalar xBase = 0; | 222 SkScalar xBase = 0; |
235 SkScalar y = 0; // The baseline of the previous output | 223 SkScalar y = 0; // The baseline of the previous output |
236 for (const SubpixelType subpixel : subpixelTypes) { | 224 for (const SubpixelType subpixel : subpixelTypes) { |
237 y = 0; | 225 y = 0; |
238 paint.setSubpixelText(subpixel.requested); | 226 paint.setSubpixelText(subpixel.requested); |
239 | 227 |
(...skipping 13 matching lines...) Expand all Loading... |
253 y += dy; | 241 y += dy; |
254 for (const SkPaint::Hinting& hinting : hintingTypes) { | 242 for (const SkPaint::Hinting& hinting : hintingTypes) { |
255 paint.setHinting(hinting); | 243 paint.setHinting(hinting); |
256 | 244 |
257 for (const bool& rotateABit : rotateABitTypes) { | 245 for (const bool& rotateABit : rotateABitTypes) { |
258 SkAutoCanvasRestore acr(canvas, true); | 246 SkAutoCanvasRestore acr(canvas, true); |
259 if (rotateABit) { | 247 if (rotateABit) { |
260 canvas->rotate(2, x + subpixel.offset.x(), | 248 canvas->rotate(2, x + subpixel.offset.x(), |
261 y + subpixel.offset.y()); | 249 y + subpixel.offset.y()); |
262 } | 250 } |
263 canvas->drawText("A", 1, x + subpixel.offset.x(), | 251 canvas->drawText(&character, 1, |
264 y + subpixel.offset.y(), pa
int); | 252 x + subpixel.offset.x(), |
| 253 y + subpixel.offset.y(), paint); |
265 | 254 |
266 SkScalar dx = SkScalarCeilToScalar(paint.measureText
("A", 1)) + 5; | 255 SkScalar dx = SkScalarCeilToScalar( |
| 256 paint.measureText(&character, 1)) + 5; |
267 x += dx; | 257 x += dx; |
268 xMax = SkTMax(x, xMax); | 258 xMax = SkTMax(x, xMax); |
269 } | 259 } |
270 } | 260 } |
271 } | 261 } |
272 y += 10; | 262 y += 10; |
273 } | 263 } |
274 xBase = xMax; | 264 xBase = xMax; |
275 } | 265 } |
| 266 } |
| 267 |
| 268 DEF_SIMPLE_GM_BG_NAME(typefacerendering, canvas, 640, 680, SK_ColorWHITE, |
| 269 SkStringPrintf("typefacerendering%s", |
| 270 sk_tool_utils::major_platform_os_name().c_s
tr())) { |
| 271 if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("/fonts/hintgasp.ttf"))
{ |
| 272 draw_typeface_rendering_gm(canvas, std::move(face)); |
276 } | 273 } |
| 274 } |
277 | 275 |
278 private: | 276 // Type1 fonts don't currently work in Skia on Windows. |
279 typedef skiagm::GM INHERITED; | 277 #ifndef SK_BUILD_FOR_WIN |
280 }; | |
281 | 278 |
282 /////////////////////////////////////////////////////////////////////////////// | 279 DEF_SIMPLE_GM_BG_NAME(typefacerendering_pfa, canvas, 640, 680, SK_ColorWHITE, |
| 280 SkStringPrintf("typefacerendering_pfa%s", |
| 281 sk_tool_utils::major_platform_os_name().c_s
tr())) { |
| 282 if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto2-Regular.p
fa")) { |
| 283 // This subsetted typeface doesn't have the character 'A'. |
| 284 draw_typeface_rendering_gm(canvas, std::move(face), 'O'); |
| 285 } |
| 286 } |
283 | 287 |
284 DEF_GM( return new TypefaceStylesGM(false); ) | 288 DEF_SIMPLE_GM_BG_NAME(typefacerendering_pfb, canvas, 640, 680, SK_ColorWHITE, |
285 DEF_GM( return new TypefaceStylesGM(true); ) | 289 SkStringPrintf("typefacerendering_pfb%s", |
286 DEF_GM( return new TypefaceRenderingGM(); ) | 290 sk_tool_utils::major_platform_os_name().c_s
tr())) { |
| 291 if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto2-Regular.p
fb")) { |
| 292 draw_typeface_rendering_gm(canvas, std::move(face), 'O'); |
| 293 } |
| 294 } |
| 295 |
| 296 #endif |
OLD | NEW |