OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "Resources.h" | 8 #include "Resources.h" |
9 #include "SkFixed.h" | 9 #include "SkFixed.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
11 #include "SkFontMgr.h" | 11 #include "SkFontMgr.h" |
12 #include "SkTypeface.h" | 12 #include "SkTypeface.h" |
13 | 13 |
14 namespace skiagm { | 14 namespace skiagm { |
15 | 15 |
16 class FontScalerDistortableGM : public GM { | 16 class FontScalerDistortableGM : public GM { |
17 public: | 17 public: |
18 FontScalerDistortableGM() { | 18 FontScalerDistortableGM() { |
19 this->setBGColor(0xFFFFFFFF); | 19 this->setBGColor(0xFFFFFFFF); |
20 } | 20 } |
21 | 21 |
22 virtual ~FontScalerDistortableGM() { } | |
23 | |
24 protected: | 22 protected: |
25 | 23 |
26 SkString onShortName() override { | 24 SkString onShortName() override { |
27 return SkString("fontscalerdistortable"); | 25 return SkString("fontscalerdistortable"); |
28 } | 26 } |
29 | 27 |
30 SkISize onISize() override { | 28 SkISize onISize() override { |
31 return SkISize::Make(550, 700); | 29 return SkISize::Make(550, 700); |
32 } | 30 } |
33 | 31 |
34 static void rotate_about(SkCanvas* canvas, SkScalar degrees, SkScalar px, Sk
Scalar py) { | |
35 canvas->translate(px, py); | |
36 canvas->rotate(degrees); | |
37 canvas->translate(-px, -py); | |
38 } | |
39 | |
40 void onDraw(SkCanvas* canvas) override { | 32 void onDraw(SkCanvas* canvas) override { |
41 SkPaint paint; | 33 SkPaint paint; |
42 paint.setAntiAlias(true); | 34 paint.setAntiAlias(true); |
43 paint.setLCDRenderText(true); | 35 paint.setLCDRenderText(true); |
44 SkAutoTUnref<SkFontMgr> fontMgr(SkFontMgr::RefDefault()); | 36 SkAutoTUnref<SkFontMgr> fontMgr(SkFontMgr::RefDefault()); |
45 | 37 |
46 SkAutoTDelete<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Dis
tortable.ttf")); | 38 SkAutoTDelete<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Dis
tortable.ttf")); |
47 if (!distortable) { | 39 if (!distortable) { |
48 return; | 40 return; |
49 } | 41 } |
50 const char* text = "abc"; | 42 const char* text = "abc"; |
51 const size_t textLen = strlen(text); | 43 const size_t textLen = strlen(text); |
52 | 44 |
53 for (int j = 0; j < 2; ++j) { | 45 for (int j = 0; j < 2; ++j) { |
54 for (int i = 0; i < 5; ++i) { | 46 for (int i = 0; i < 5; ++i) { |
55 SkScalar x = SkIntToScalar(10); | 47 SkScalar x = SkIntToScalar(10); |
56 SkScalar y = SkIntToScalar(20); | 48 SkScalar y = SkIntToScalar(20); |
57 | 49 |
58 SkFourByteTag tag = SkSetFourByteTag('w','g','h','t'); | 50 SkFourByteTag tag = SkSetFourByteTag('w','g','h','t'); |
59 SkScalar styleValue = SkDoubleToScalar(0.5 + (5*j + i) * ((2.0 -
0.5) / (2 * 5))); | 51 SkScalar styleValue = SkDoubleToScalar(0.5 + (5*j + i) * ((2.0 -
0.5) / (2 * 5))); |
60 SkFontMgr::FontParameters::Axis axes[] = { { tag, styleValue } }
; | 52 SkFontMgr::FontParameters::Axis axes[] = { { tag, styleValue } }
; |
61 paint.setTypeface(sk_sp<SkTypeface>(fontMgr->createFromStream( | 53 paint.setTypeface(sk_sp<SkTypeface>(fontMgr->createFromStream( |
62 distortable->duplicate(), SkFontMgr::FontParameters().se
tAxes(axes, 1)))); | 54 distortable->duplicate(), SkFontMgr::FontParameters().se
tAxes(axes, 1)))); |
63 | 55 |
64 SkAutoCanvasRestore acr(canvas, true); | 56 SkAutoCanvasRestore acr(canvas, true); |
65 canvas->translate(SkIntToScalar(30 + i * 100), SkIntToScalar(20)
); | 57 canvas->translate(SkIntToScalar(30 + i * 100), SkIntToScalar(20)
); |
66 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); | 58 canvas->rotate(SkIntToScalar(i * 5), x, y * 10); |
67 | 59 |
68 { | 60 { |
69 SkPaint p; | 61 SkPaint p; |
70 p.setAntiAlias(true); | 62 p.setAntiAlias(true); |
71 SkRect r; | 63 SkRect r; |
72 r.set(x - SkIntToScalar(3), SkIntToScalar(15), | 64 r.set(x - SkIntToScalar(3), SkIntToScalar(15), |
73 x - SkIntToScalar(1), SkIntToScalar(280)); | 65 x - SkIntToScalar(1), SkIntToScalar(280)); |
74 canvas->drawRect(r, p); | 66 canvas->drawRect(r, p); |
75 } | 67 } |
76 | 68 |
(...skipping 11 matching lines...) Expand all Loading... |
88 private: | 80 private: |
89 typedef GM INHERITED; | 81 typedef GM INHERITED; |
90 }; | 82 }; |
91 | 83 |
92 ////////////////////////////////////////////////////////////////////////////// | 84 ////////////////////////////////////////////////////////////////////////////// |
93 | 85 |
94 static GM* MyFactory(void*) { return new FontScalerDistortableGM; } | 86 static GM* MyFactory(void*) { return new FontScalerDistortableGM; } |
95 static GMRegistry reg(MyFactory); | 87 static GMRegistry reg(MyFactory); |
96 | 88 |
97 } | 89 } |
OLD | NEW |