Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: gm/dftext.cpp

Issue 1248703004: make color emoji gm portable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more 565 color fixes Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/coloremoji.cpp ('k') | gm/mixedtextblobs.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkSurface.h" 11 #include "SkSurface.h"
12 #include "SkTypeface.h" 12 #include "SkTypeface.h"
13 13
14 class DFTextGM : public skiagm::GM { 14 class DFTextGM : public skiagm::GM {
15 public: 15 public:
16 DFTextGM() { 16 DFTextGM() {
17 this->setBGColor(0xFFFFFFFF); 17 this->setBGColor(0xFFFFFFFF);
18 fTypeface = NULL;
19 }
20
21 virtual ~DFTextGM() {
22 SkSafeUnref(fTypeface);
23 } 18 }
24 19
25 protected: 20 protected:
26 void onOnceBeforeDraw() override { 21 void onOnceBeforeDraw() override {
27 fTypeface = GetResourceAsTypeface("/fonts/Funkster.ttf"); 22 fEmojiTypeface.reset(sk_tool_utils::emoji_typeface());
23 fEmojiText = sk_tool_utils::emoji_sample_text();
28 } 24 }
29 25
30 SkString onShortName() override { 26 SkString onShortName() override {
31 return SkString("dftext"); 27 SkString name("dftext");
28 name.append(sk_tool_utils::platform_os_emoji());
29 return name;
32 } 30 }
33 31
34 SkISize onISize() override { 32 SkISize onISize() override {
35 return SkISize::Make(1024, 768); 33 return SkISize::Make(1024, 768);
36 } 34 }
37 35
38 static void rotate_about(SkCanvas* canvas, 36 static void rotate_about(SkCanvas* canvas,
39 SkScalar degrees, 37 SkScalar degrees,
40 SkScalar px, SkScalar py) { 38 SkScalar px, SkScalar py) {
41 canvas->translate(px, py); 39 canvas->translate(px, py);
(...skipping 24 matching lines...) Expand all
66 SkCanvas* canvas = inputCanvas; 64 SkCanvas* canvas = inputCanvas;
67 #endif 65 #endif
68 // apply global scale to test glyph positioning 66 // apply global scale to test glyph positioning
69 canvas->scale(1.05f, 1.05f); 67 canvas->scale(1.05f, 1.05f);
70 canvas->clear(0xffffffff); 68 canvas->clear(0xffffffff);
71 69
72 SkPaint paint; 70 SkPaint paint;
73 paint.setAntiAlias(true); 71 paint.setAntiAlias(true);
74 paint.setSubpixelText(true); 72 paint.setSubpixelText(true);
75 73
76 sk_tool_utils::set_portable_typeface(&paint, "Times New Roman", SkTypefa ce::kNormal); 74 sk_tool_utils::set_portable_typeface_always(&paint, "serif", SkTypeface: :kNormal);
77 75
78 const char* text = "Hamburgefons"; 76 const char* text = "Hamburgefons";
79 const size_t textLen = strlen(text); 77 const size_t textLen = strlen(text);
80 78
81 // check scaling up 79 // check scaling up
82 SkScalar x = SkIntToScalar(0); 80 SkScalar x = SkIntToScalar(0);
83 SkScalar y = SkIntToScalar(78); 81 SkScalar y = SkIntToScalar(78);
84 for (size_t i = 0; i < SK_ARRAY_COUNT(textSizes); ++i) { 82 for (size_t i = 0; i < SK_ARRAY_COUNT(textSizes); ++i) {
85 SkAutoCanvasRestore acr(canvas, true); 83 SkAutoCanvasRestore acr(canvas, true);
86 canvas->translate(x, y); 84 canvas->translate(x, y);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 142
145 143
146 // check gamma-corrected blending 144 // check gamma-corrected blending
147 const SkColor fg[] = { 145 const SkColor fg[] = {
148 0xFFFFFFFF, 146 0xFFFFFFFF,
149 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF, 147 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF,
150 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 148 0xFFFF0000, 0xFF00FF00, 0xFF0000FF,
151 0xFF000000, 149 0xFF000000,
152 }; 150 };
153 151
154 paint.setColor(0xFFF1F1F1); 152 paint.setColor(0xFFF7F3F7);
155 SkRect r = SkRect::MakeLTRB(670, 250, 820, 460); 153 SkRect r = SkRect::MakeLTRB(670, 250, 820, 460);
156 canvas->drawRect(r, paint); 154 canvas->drawRect(r, paint);
157 155
158 x = SkIntToScalar(680); 156 x = SkIntToScalar(680);
159 y = SkIntToScalar(270); 157 y = SkIntToScalar(270);
160 #ifdef SK_BUILD_FOR_ANDROID 158 #ifdef SK_BUILD_FOR_ANDROID
161 paint.setTextSize(SkIntToScalar(19)); 159 paint.setTextSize(SkIntToScalar(19));
162 #else 160 #else
163 paint.setTextSize(SkIntToScalar(22)); 161 paint.setTextSize(SkIntToScalar(22));
164 #endif 162 #endif
165 for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) { 163 for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
166 paint.setColor(fg[i]); 164 paint.setColor(fg[i]);
167 165
168 canvas->drawText(text, textLen, x, y, paint); 166 canvas->drawText(text, textLen, x, y, paint);
169 y += paint.getFontMetrics(NULL); 167 y += paint.getFontMetrics(NULL);
170 } 168 }
171 169
172 paint.setColor(0xFF1F1F1F); 170 paint.setColor(0xFF181C18);
173 r = SkRect::MakeLTRB(820, 250, 970, 460); 171 r = SkRect::MakeLTRB(820, 250, 970, 460);
174 canvas->drawRect(r, paint); 172 canvas->drawRect(r, paint);
175 173
176 x = SkIntToScalar(830); 174 x = SkIntToScalar(830);
177 y = SkIntToScalar(270); 175 y = SkIntToScalar(270);
178 #ifdef SK_BUILD_FOR_ANDROID 176 #ifdef SK_BUILD_FOR_ANDROID
179 paint.setTextSize(SkIntToScalar(19)); 177 paint.setTextSize(SkIntToScalar(19));
180 #else 178 #else
181 paint.setTextSize(SkIntToScalar(22)); 179 paint.setTextSize(SkIntToScalar(22));
182 #endif 180 #endif
(...skipping 14 matching lines...) Expand all
197 } 195 }
198 { 196 {
199 paint.setLCDRenderText(true); 197 paint.setLCDRenderText(true);
200 SkAutoCanvasRestore acr(canvas, true); 198 SkAutoCanvasRestore acr(canvas, true);
201 canvas->skew(0.5f, 0.0f); 199 canvas->skew(0.5f, 0.0f);
202 paint.setTextSize(SkIntToScalar(32)); 200 paint.setTextSize(SkIntToScalar(32));
203 canvas->drawText(text, textLen, 580, 230, paint); 201 canvas->drawText(text, textLen, 580, 230, paint);
204 } 202 }
205 203
206 // check color emoji 204 // check color emoji
207 paint.setTypeface(fTypeface); 205 if (fEmojiTypeface) {
208 #ifdef SK_BUILD_FOR_ANDROID 206 paint.setTypeface(fEmojiTypeface);
209 paint.setTextSize(SkIntToScalar(19)); 207 paint.setTextSize(SkIntToScalar(19));
210 #else 208 canvas->drawText(fEmojiText, strlen(fEmojiText), 670, 100, paint);
211 paint.setTextSize(SkIntToScalar(22)); 209 }
212 #endif
213 canvas->drawText(text, textLen, 670, 100, paint);
214
215 #if SK_SUPPORT_GPU 210 #if SK_SUPPORT_GPU
216 // render offscreen buffer 211 // render offscreen buffer
217 if (surface) { 212 if (surface) {
218 SkAutoCanvasRestore acr(inputCanvas, true); 213 SkAutoCanvasRestore acr(inputCanvas, true);
219 // since we prepended this matrix already, we blit using identity 214 // since we prepended this matrix already, we blit using identity
220 inputCanvas->resetMatrix(); 215 inputCanvas->resetMatrix();
221 SkImage* image = surface->newImageSnapshot(); 216 SkImage* image = surface->newImageSnapshot();
222 inputCanvas->drawImage(image, 0, 0, NULL); 217 inputCanvas->drawImage(image, 0, 0, NULL);
223 image->unref(); 218 image->unref();
224 } 219 }
225 #endif 220 #endif
226 } 221 }
227 222
228 private: 223 private:
229 SkTypeface* fTypeface; 224 SkAutoTUnref<SkTypeface> fEmojiTypeface;
225 const char* fEmojiText;
230 226
231 typedef skiagm::GM INHERITED; 227 typedef skiagm::GM INHERITED;
232 }; 228 };
233 229
234 DEF_GM( return SkNEW(DFTextGM); ) 230 DEF_GM( return SkNEW(DFTextGM); )
OLDNEW
« no previous file with comments | « gm/coloremoji.cpp ('k') | gm/mixedtextblobs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698