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