OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkGradientShader.h" | 12 #include "SkGradientShader.h" |
13 #include "SkStream.h" | 13 #include "SkStream.h" |
14 #include "SkTextBlob.h" | 14 #include "SkTextBlob.h" |
15 #include "SkTypeface.h" | 15 #include "SkTypeface.h" |
16 | 16 |
17 namespace skiagm { | 17 namespace skiagm { |
18 | 18 |
19 static void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const
SkPaint& origPaint, | |
20 SkScalar x, SkScalar y) { | |
21 SkPaint paint(origPaint); | |
22 SkTDArray<uint16_t> glyphs; | |
23 | |
24 size_t len = strlen(text); | |
25 glyphs.append(paint.textToGlyphs(text, len, NULL)); | |
26 paint.textToGlyphs(text, len, glyphs.begin()); | |
27 | |
28 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
29 const SkTextBlobBuilder::RunBuffer& run = builder->allocRun(paint, glyphs.co
unt(), x, y, | |
30 NULL); | |
31 memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t)); | |
32 } | |
33 | |
34 static void draw_blob(SkCanvas* canvas, const SkTextBlob* blob, const SkPaint& s
kPaint, | 19 static void draw_blob(SkCanvas* canvas, const SkTextBlob* blob, const SkPaint& s
kPaint, |
35 const SkRect& clipRect) { | 20 const SkRect& clipRect) { |
36 SkPaint clipHairline; | 21 SkPaint clipHairline; |
37 clipHairline.setColor(SK_ColorWHITE); | 22 clipHairline.setColor(SK_ColorWHITE); |
38 clipHairline.setStyle(SkPaint::kStroke_Style); | 23 clipHairline.setStyle(SkPaint::kStroke_Style); |
39 | 24 |
40 SkPaint paint(skPaint); | 25 SkPaint paint(skPaint); |
41 canvas->save(); | 26 canvas->save(); |
42 canvas->drawRect(clipRect, clipHairline); | 27 canvas->drawRect(clipRect, clipHairline); |
43 paint.setAlpha(0x20); | 28 paint.setAlpha(0x20); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // Text so large we draw as paths | 69 // Text so large we draw as paths |
85 SkPaint paint; | 70 SkPaint paint; |
86 paint.setTextSize(384); | 71 paint.setTextSize(384); |
87 const char* text = "O"; | 72 const char* text = "O"; |
88 sk_tool_utils::set_portable_typeface(&paint); | 73 sk_tool_utils::set_portable_typeface(&paint); |
89 | 74 |
90 SkRect bounds; | 75 SkRect bounds; |
91 paint.measureText(text, strlen(text), &bounds); | 76 paint.measureText(text, strlen(text), &bounds); |
92 | 77 |
93 SkScalar yOffset = bounds.height(); | 78 SkScalar yOffset = bounds.height(); |
94 add_to_text_blob(&builder, text, paint, 10, yOffset); | 79 sk_tool_utils::add_to_text_blob(&builder, text, paint, 10, yOffset); |
95 SkScalar corruptedAx = bounds.width(); | 80 SkScalar corruptedAx = bounds.width(); |
96 SkScalar corruptedAy = yOffset; | 81 SkScalar corruptedAy = yOffset; |
97 | 82 |
98 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf; | 83 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf; |
99 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf; | 84 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf; |
100 | 85 |
101 SkScalar xOffset = boundsHalfWidth; | 86 SkScalar xOffset = boundsHalfWidth; |
102 yOffset = boundsHalfHeight; | 87 yOffset = boundsHalfHeight; |
103 | 88 |
104 // LCD | 89 // LCD |
105 paint.setTextSize(32); | 90 paint.setTextSize(32); |
106 text = "LCD!!!!!"; | 91 text = "LCD!!!!!"; |
107 paint.setSubpixelText(true); | 92 paint.setSubpixelText(true); |
108 paint.setLCDRenderText(true); | 93 paint.setLCDRenderText(true); |
109 paint.measureText(text, strlen(text), &bounds); | 94 paint.measureText(text, strlen(text), &bounds); |
110 add_to_text_blob(&builder, text, paint, xOffset - bounds.width() * 0.25f
, | 95 sk_tool_utils::add_to_text_blob(&builder, text, paint, xOffset - bounds.
width() * 0.25f, |
111 yOffset - bounds.height() * 0.5f
); | 96 yOffset - bounds.height() * 0.5f); |
112 yOffset += bounds.height(); | 97 yOffset += bounds.height(); |
113 | 98 |
114 // color emoji | 99 // color emoji |
115 paint.setSubpixelText(false); | 100 paint.setSubpixelText(false); |
116 paint.setLCDRenderText(false); | 101 paint.setLCDRenderText(false); |
117 paint.setTypeface(fEmojiTypeface); | 102 paint.setTypeface(fEmojiTypeface); |
118 text = fEmojiText; | 103 text = fEmojiText; |
119 paint.measureText(text, strlen(text), &bounds); | 104 paint.measureText(text, strlen(text), &bounds); |
120 add_to_text_blob(&builder, text, paint, xOffset - bounds.width() * 0.3f,
yOffset); | 105 sk_tool_utils::add_to_text_blob(&builder, text, paint, xOffset - bounds.
width() * 0.3f, |
| 106 yOffset); |
121 | 107 |
122 // Corrupted font | 108 // Corrupted font |
123 paint.setTextSize(12); | 109 paint.setTextSize(12); |
124 text = "aA"; | 110 text = "aA"; |
125 paint.setTypeface(fReallyBigATypeface); | 111 paint.setTypeface(fReallyBigATypeface); |
126 add_to_text_blob(&builder, text, paint, corruptedAx, corruptedAy); | 112 sk_tool_utils::add_to_text_blob(&builder, text, paint, corruptedAx, corr
uptedAy); |
127 fBlob.reset(builder.build()); | 113 fBlob.reset(builder.build()); |
128 } | 114 } |
129 | 115 |
130 SkString onShortName() override { | 116 SkString onShortName() override { |
131 return SkString("mixedtextblobs"); | 117 return SkString("mixedtextblobs"); |
132 } | 118 } |
133 | 119 |
134 SkISize onISize() override { | 120 SkISize onISize() override { |
135 return SkISize::Make(kWidth, kHeight); | 121 return SkISize::Make(kWidth, kHeight); |
136 } | 122 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 static const int kWidth = 1250; | 172 static const int kWidth = 1250; |
187 static const int kHeight = 700; | 173 static const int kHeight = 700; |
188 | 174 |
189 typedef GM INHERITED; | 175 typedef GM INHERITED; |
190 }; | 176 }; |
191 | 177 |
192 ////////////////////////////////////////////////////////////////////////////// | 178 ////////////////////////////////////////////////////////////////////////////// |
193 | 179 |
194 DEF_GM( return SkNEW(MixedTextBlobsGM); ) | 180 DEF_GM( return SkNEW(MixedTextBlobsGM); ) |
195 } | 181 } |
OLD | NEW |