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 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 TextBlobTransforms() {} | 21 TextBlobTransforms() {} |
22 | 22 |
23 protected: | 23 protected: |
24 void onOnceBeforeDraw() override { | 24 void onOnceBeforeDraw() override { |
25 SkTextBlobBuilder builder; | 25 SkTextBlobBuilder builder; |
26 | 26 |
27 // make textblob. To stress distance fields, we choose sizes appropriat
ely | 27 // make textblob. To stress distance fields, we choose sizes appropriat
ely |
28 SkPaint paint; | 28 SkPaint paint; |
29 paint.setTextSize(162); | 29 paint.setTextSize(162); |
30 const char* text = "A"; | 30 const char* text = "A"; |
31 sk_tool_utils::set_portable_typeface(&paint); | 31 sk_tool_utils::set_portable_typeface_always(&paint); |
32 | 32 |
33 SkRect bounds; | 33 SkRect bounds; |
34 paint.measureText(text, strlen(text), &bounds); | 34 paint.measureText(text, strlen(text), &bounds); |
35 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0); | 35 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0); |
36 | 36 |
37 // Medium | 37 // Medium |
38 SkScalar xOffset = bounds.width() + 5; | 38 SkScalar xOffset = bounds.width() + 5; |
39 paint.setTextSize(72); | 39 paint.setTextSize(72); |
40 text = "B"; | 40 text = "B"; |
41 sk_tool_utils::add_to_text_blob(&builder, text, paint, xOffset, 0); | 41 sk_tool_utils::add_to_text_blob(&builder, text, paint, xOffset, 0); |
(...skipping 13 matching lines...) Expand all Loading... |
55 SkString onShortName() override { | 55 SkString onShortName() override { |
56 return SkString("textblobtransforms"); | 56 return SkString("textblobtransforms"); |
57 } | 57 } |
58 | 58 |
59 SkISize onISize() override { | 59 SkISize onISize() override { |
60 return SkISize::Make(kWidth, kHeight); | 60 return SkISize::Make(kWidth, kHeight); |
61 } | 61 } |
62 | 62 |
63 void onDraw(SkCanvas* canvas) override { | 63 void onDraw(SkCanvas* canvas) override { |
64 | 64 |
65 canvas->drawColor(SK_ColorGRAY); | 65 canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorGRAY)); |
66 | 66 |
67 SkPaint paint; | 67 SkPaint paint; |
68 | 68 |
69 SkRect bounds = fBlob->bounds(); | 69 SkRect bounds = fBlob->bounds(); |
70 canvas->translate(20, 20); | 70 canvas->translate(20, 20); |
71 | 71 |
72 // Colors were chosen to map to pairs of canonical colors. The GPU Back
end will cache A8 | 72 // Colors were chosen to map to pairs of canonical colors. The GPU Back
end will cache A8 |
73 // Texture Blobs based on the canonical color they map to. Canonical co
lors are used to | 73 // Texture Blobs based on the canonical color they map to. Canonical co
lors are used to |
74 // create masks. For A8 there are 8 of them. | 74 // create masks. For A8 there are 8 of them. |
75 //SkColor colors[] = {SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorYELLOW, SK_C
olorWHITE}; | 75 //SkColor colors[] = {SK_ColorCYAN, sk_tool_utils::color_to_565(SK_Color
LTGRAY), SK_ColorYELLOW, SK_ColorWHITE}; |
76 | 76 |
77 SkScalar xOffset = SkScalarCeilToScalar(bounds.width()); | 77 SkScalar xOffset = SkScalarCeilToScalar(bounds.width()); |
78 SkScalar yOffset = SkScalarCeilToScalar(bounds.height()); | 78 SkScalar yOffset = SkScalarCeilToScalar(bounds.height()); |
79 // first translate | 79 // first translate |
80 canvas->translate(xOffset, 2 * yOffset); | 80 canvas->translate(xOffset, 2 * yOffset); |
81 canvas->drawTextBlob(fBlob, 0, 0, paint); | 81 canvas->drawTextBlob(fBlob, 0, 0, paint); |
82 canvas->translate(-xOffset, 0); | 82 canvas->translate(-xOffset, 0); |
83 canvas->drawTextBlob(fBlob, 0, 0, paint); | 83 canvas->drawTextBlob(fBlob, 0, 0, paint); |
84 canvas->translate(2 * xOffset, 0); | 84 canvas->translate(2 * xOffset, 0); |
85 canvas->drawTextBlob(fBlob, 0, 0, paint); | 85 canvas->drawTextBlob(fBlob, 0, 0, paint); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 static const int kWidth = 1000; | 163 static const int kWidth = 1000; |
164 static const int kHeight = 1200; | 164 static const int kHeight = 1200; |
165 | 165 |
166 typedef GM INHERITED; | 166 typedef GM INHERITED; |
167 }; | 167 }; |
168 | 168 |
169 ////////////////////////////////////////////////////////////////////////////// | 169 ////////////////////////////////////////////////////////////////////////////// |
170 | 170 |
171 DEF_GM( return SkNEW(TextBlobTransforms); ) | 171 DEF_GM( return SkNEW(TextBlobTransforms); ) |
172 } | 172 } |
OLD | NEW |