OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "gm.h" | 7 #include "gm.h" |
8 #include "SkTypeface.h" | 8 #include "SkTypeface.h" |
9 | 9 |
10 namespace skiagm { | 10 namespace skiagm { |
11 | 11 |
12 class FontScalerGM : public GM { | 12 class FontScalerGM : public GM { |
13 public: | 13 public: |
14 FontScalerGM() { | 14 FontScalerGM() { |
15 this->setBGColor(0xFFFFFFFF); | 15 this->setBGColor(0xFFFFFFFF); |
16 } | 16 } |
17 | 17 |
18 virtual ~FontScalerGM() { | |
19 } | |
20 | |
21 protected: | 18 protected: |
22 | 19 |
23 SkString onShortName() override { | 20 SkString onShortName() override { |
24 SkString name("fontscaler"); | 21 SkString name("fontscaler"); |
25 name.append(sk_tool_utils::major_platform_os_name()); | 22 name.append(sk_tool_utils::major_platform_os_name()); |
26 return name; | 23 return name; |
27 } | 24 } |
28 | 25 |
29 SkISize onISize() override { | 26 SkISize onISize() override { |
30 return SkISize::Make(1450, 750); | 27 return SkISize::Make(1450, 750); |
31 } | 28 } |
32 | 29 |
33 static void rotate_about(SkCanvas* canvas, | |
34 SkScalar degrees, | |
35 SkScalar px, SkScalar py) { | |
36 canvas->translate(px, py); | |
37 canvas->rotate(degrees); | |
38 canvas->translate(-px, -py); | |
39 } | |
40 | |
41 void onDraw(SkCanvas* canvas) override { | 30 void onDraw(SkCanvas* canvas) override { |
42 SkPaint paint; | 31 SkPaint paint; |
43 | 32 |
44 paint.setAntiAlias(true); | 33 paint.setAntiAlias(true); |
45 paint.setLCDRenderText(true); | 34 paint.setLCDRenderText(true); |
46 //With freetype the default (normal hinting) can be really ugly. | 35 //With freetype the default (normal hinting) can be really ugly. |
47 //Most distros now set slight (vertical hinting only) in any event. | 36 //Most distros now set slight (vertical hinting only) in any event. |
48 paint.setHinting(SkPaint::kSlight_Hinting); | 37 paint.setHinting(SkPaint::kSlight_Hinting); |
49 | 38 |
50 const char* text = "Hamburgefons ooo mmm"; | 39 const char* text = "Hamburgefons ooo mmm"; |
51 const size_t textLen = strlen(text); | 40 const size_t textLen = strlen(text); |
52 | 41 |
53 for (int j = 0; j < 2; ++j) { | 42 for (int j = 0; j < 2; ++j) { |
54 // This used to do 6 iterations but it causes the N4 to crash in the
MSAA4 config. | 43 // This used to do 6 iterations but it causes the N4 to crash in the
MSAA4 config. |
55 for (int i = 0; i < 5; ++i) { | 44 for (int i = 0; i < 5; ++i) { |
56 SkScalar x = SkIntToScalar(10); | 45 SkScalar x = SkIntToScalar(10); |
57 SkScalar y = SkIntToScalar(20); | 46 SkScalar y = SkIntToScalar(20); |
58 | 47 |
59 SkAutoCanvasRestore acr(canvas, true); | 48 SkAutoCanvasRestore acr(canvas, true); |
60 canvas->translate(SkIntToScalar(50 + i * 230), | 49 canvas->translate(SkIntToScalar(50 + i * 230), |
61 SkIntToScalar(20)); | 50 SkIntToScalar(20)); |
62 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); | 51 canvas->rotate(SkIntToScalar(i * 5), x, y * 10); |
63 | 52 |
64 { | 53 { |
65 SkPaint p; | 54 SkPaint p; |
66 p.setAntiAlias(true); | 55 p.setAntiAlias(true); |
67 SkRect r; | 56 SkRect r; |
68 r.set(x - SkIntToScalar(3), SkIntToScalar(15), | 57 r.set(x - SkIntToScalar(3), SkIntToScalar(15), |
69 x - SkIntToScalar(1), SkIntToScalar(280)); | 58 x - SkIntToScalar(1), SkIntToScalar(280)); |
70 canvas->drawRect(r, p); | 59 canvas->drawRect(r, p); |
71 } | 60 } |
72 | 61 |
(...skipping 11 matching lines...) Expand all Loading... |
84 private: | 73 private: |
85 typedef GM INHERITED; | 74 typedef GM INHERITED; |
86 }; | 75 }; |
87 | 76 |
88 ////////////////////////////////////////////////////////////////////////////// | 77 ////////////////////////////////////////////////////////////////////////////// |
89 | 78 |
90 static GM* MyFactory(void*) { return new FontScalerGM; } | 79 static GM* MyFactory(void*) { return new FontScalerGM; } |
91 static GMRegistry reg(MyFactory); | 80 static GMRegistry reg(MyFactory); |
92 | 81 |
93 } | 82 } |
OLD | NEW |