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 "Resources.h" | 8 #include "Resources.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkStream.h" | 10 #include "SkStream.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 SkString onShortName() override { | 26 SkString onShortName() override { |
27 SkString name("dftext"); | 27 SkString name("dftext"); |
28 name.append(sk_tool_utils::platform_os_emoji()); | 28 name.append(sk_tool_utils::platform_os_emoji()); |
29 return name; | 29 return name; |
30 } | 30 } |
31 | 31 |
32 SkISize onISize() override { | 32 SkISize onISize() override { |
33 return SkISize::Make(1024, 768); | 33 return SkISize::Make(1024, 768); |
34 } | 34 } |
35 | 35 |
36 static void rotate_about(SkCanvas* canvas, | |
37 SkScalar degrees, | |
38 SkScalar px, SkScalar py) { | |
39 canvas->translate(px, py); | |
40 canvas->rotate(degrees); | |
41 canvas->translate(-px, -py); | |
42 } | |
43 | |
44 virtual void onDraw(SkCanvas* inputCanvas) override { | 36 virtual void onDraw(SkCanvas* inputCanvas) override { |
45 SkScalar textSizes[] = { 9.0f, 9.0f*2.0f, 9.0f*5.0f, 9.0f*2.0f*5.0f }; | 37 SkScalar textSizes[] = { 9.0f, 9.0f*2.0f, 9.0f*5.0f, 9.0f*2.0f*5.0f }; |
46 SkScalar scales[] = { 2.0f*5.0f, 5.0f, 2.0f, 1.0f }; | 38 SkScalar scales[] = { 2.0f*5.0f, 5.0f, 2.0f, 1.0f }; |
47 | 39 |
48 // set up offscreen rendering with distance field text | 40 // set up offscreen rendering with distance field text |
49 #if SK_SUPPORT_GPU | 41 #if SK_SUPPORT_GPU |
50 GrContext* ctx = inputCanvas->getGrContext(); | 42 GrContext* ctx = inputCanvas->getGrContext(); |
51 SkISize size = onISize(); | 43 SkISize size = onISize(); |
52 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), kPr
emul_SkAlphaType, | 44 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), kPr
emul_SkAlphaType, |
53 sk_ref_sp(inputCanvas->imageInfo
().colorSpace())); | 45 sk_ref_sp(inputCanvas->imageInfo
().colorSpace())); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 y += paint.getFontMetrics(nullptr)*scales[i]; | 80 y += paint.getFontMetrics(nullptr)*scales[i]; |
89 } | 81 } |
90 | 82 |
91 // check rotation | 83 // check rotation |
92 for (size_t i = 0; i < 5; ++i) { | 84 for (size_t i = 0; i < 5; ++i) { |
93 SkScalar rotX = SkIntToScalar(10); | 85 SkScalar rotX = SkIntToScalar(10); |
94 SkScalar rotY = y; | 86 SkScalar rotY = y; |
95 | 87 |
96 SkAutoCanvasRestore acr(canvas, true); | 88 SkAutoCanvasRestore acr(canvas, true); |
97 canvas->translate(SkIntToScalar(10 + i * 200), -80); | 89 canvas->translate(SkIntToScalar(10 + i * 200), -80); |
98 rotate_about(canvas, SkIntToScalar(i * 5), rotX, rotY); | 90 canvas->rotate(SkIntToScalar(i * 5), rotX, rotY); |
99 for (int ps = 6; ps <= 32; ps += 3) { | 91 for (int ps = 6; ps <= 32; ps += 3) { |
100 paint.setTextSize(SkIntToScalar(ps)); | 92 paint.setTextSize(SkIntToScalar(ps)); |
101 canvas->drawText(text, textLen, rotX, rotY, paint); | 93 canvas->drawText(text, textLen, rotX, rotY, paint); |
102 rotY += paint.getFontMetrics(nullptr); | 94 rotY += paint.getFontMetrics(nullptr); |
103 } | 95 } |
104 } | 96 } |
105 | 97 |
106 // check scaling down | 98 // check scaling down |
107 paint.setLCDRenderText(true); | 99 paint.setLCDRenderText(true); |
108 x = SkIntToScalar(680); | 100 x = SkIntToScalar(680); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 203 } |
212 | 204 |
213 private: | 205 private: |
214 sk_sp<SkTypeface> fEmojiTypeface; | 206 sk_sp<SkTypeface> fEmojiTypeface; |
215 const char* fEmojiText; | 207 const char* fEmojiText; |
216 | 208 |
217 typedef skiagm::GM INHERITED; | 209 typedef skiagm::GM INHERITED; |
218 }; | 210 }; |
219 | 211 |
220 DEF_GM(return new DFTextGM;) | 212 DEF_GM(return new DFTextGM;) |
OLD | NEW |