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

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: 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; 18 fTypeface = NULL;
19 } 19 }
20 20
21 virtual ~DFTextGM() { 21 virtual ~DFTextGM() {
22 SkSafeUnref(fTypeface); 22 SkSafeUnref(fTypeface);
23 } 23 }
24 24
25 protected: 25 protected:
26 void onOnceBeforeDraw() override { 26 void onOnceBeforeDraw() override {
27 fTypeface = GetResourceAsTypeface("/fonts/Funkster.ttf"); 27 if (!strcmp(sk_tool_utils::platform_os_emoji(), "CBDT")) {
28 fTypeface = GetResourceAsTypeface("/fonts/Funkster.ttf");
29 } else if (!strcmp(sk_tool_utils::platform_os_emoji(), "SBIX")) {
30 fTypeface = SkTypeface::CreateFromName("Apple Color Emoji", SkTypefa ce::kNormal);
31 } else {
32 fTypeface = NULL;
33 }
28 } 34 }
29 35
30 SkString onShortName() override { 36 SkString onShortName() override {
31 return SkString("dftext"); 37 SkString name("dftext");
38 name.append(sk_tool_utils::platform_os_emoji());
39 return name;
32 } 40 }
33 41
34 SkISize onISize() override { 42 SkISize onISize() override {
35 return SkISize::Make(1024, 768); 43 return SkISize::Make(1024, 768);
36 } 44 }
37 45
38 static void rotate_about(SkCanvas* canvas, 46 static void rotate_about(SkCanvas* canvas,
39 SkScalar degrees, 47 SkScalar degrees,
40 SkScalar px, SkScalar py) { 48 SkScalar px, SkScalar py) {
41 canvas->translate(px, py); 49 canvas->translate(px, py);
(...skipping 24 matching lines...) Expand all
66 SkCanvas* canvas = inputCanvas; 74 SkCanvas* canvas = inputCanvas;
67 #endif 75 #endif
68 // apply global scale to test glyph positioning 76 // apply global scale to test glyph positioning
69 canvas->scale(1.05f, 1.05f); 77 canvas->scale(1.05f, 1.05f);
70 canvas->clear(0xffffffff); 78 canvas->clear(0xffffffff);
71 79
72 SkPaint paint; 80 SkPaint paint;
73 paint.setAntiAlias(true); 81 paint.setAntiAlias(true);
74 paint.setSubpixelText(true); 82 paint.setSubpixelText(true);
75 83
76 sk_tool_utils::set_portable_typeface(&paint, "Times New Roman", SkTypefa ce::kNormal); 84 sk_tool_utils::set_portable_typeface_always(&paint, "serif", SkTypeface: :kNormal);
77 85
78 const char* text = "Hamburgefons"; 86 const char* text = "Hamburgefons";
bungeman-skia 2015/07/21 18:17:16 Apple Color Emoji should use different chars here
79 const size_t textLen = strlen(text); 87 const size_t textLen = strlen(text);
80 88
81 // check scaling up 89 // check scaling up
82 SkScalar x = SkIntToScalar(0); 90 SkScalar x = SkIntToScalar(0);
83 SkScalar y = SkIntToScalar(78); 91 SkScalar y = SkIntToScalar(78);
84 for (size_t i = 0; i < SK_ARRAY_COUNT(textSizes); ++i) { 92 for (size_t i = 0; i < SK_ARRAY_COUNT(textSizes); ++i) {
85 SkAutoCanvasRestore acr(canvas, true); 93 SkAutoCanvasRestore acr(canvas, true);
86 canvas->translate(x, y); 94 canvas->translate(x, y);
87 canvas->scale(scales[i], scales[i]); 95 canvas->scale(scales[i], scales[i]);
88 paint.setTextSize(textSizes[i]); 96 paint.setTextSize(textSizes[i]);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 #else 170 #else
163 paint.setTextSize(SkIntToScalar(22)); 171 paint.setTextSize(SkIntToScalar(22));
164 #endif 172 #endif
165 for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) { 173 for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
166 paint.setColor(fg[i]); 174 paint.setColor(fg[i]);
167 175
168 canvas->drawText(text, textLen, x, y, paint); 176 canvas->drawText(text, textLen, x, y, paint);
169 y += paint.getFontMetrics(NULL); 177 y += paint.getFontMetrics(NULL);
170 } 178 }
171 179
172 paint.setColor(0xFF1F1F1F); 180 paint.setColor(sk_tool_utils::color_to_565(0xFF1F1F1F));
173 r = SkRect::MakeLTRB(820, 250, 970, 460); 181 r = SkRect::MakeLTRB(820, 250, 970, 460);
174 canvas->drawRect(r, paint); 182 canvas->drawRect(r, paint);
175 183
176 x = SkIntToScalar(830); 184 x = SkIntToScalar(830);
177 y = SkIntToScalar(270); 185 y = SkIntToScalar(270);
178 #ifdef SK_BUILD_FOR_ANDROID 186 #ifdef SK_BUILD_FOR_ANDROID
179 paint.setTextSize(SkIntToScalar(19)); 187 paint.setTextSize(SkIntToScalar(19));
180 #else 188 #else
181 paint.setTextSize(SkIntToScalar(22)); 189 paint.setTextSize(SkIntToScalar(22));
182 #endif 190 #endif
(...skipping 14 matching lines...) Expand all
197 } 205 }
198 { 206 {
199 paint.setLCDRenderText(true); 207 paint.setLCDRenderText(true);
200 SkAutoCanvasRestore acr(canvas, true); 208 SkAutoCanvasRestore acr(canvas, true);
201 canvas->skew(0.5f, 0.0f); 209 canvas->skew(0.5f, 0.0f);
202 paint.setTextSize(SkIntToScalar(32)); 210 paint.setTextSize(SkIntToScalar(32));
203 canvas->drawText(text, textLen, 580, 230, paint); 211 canvas->drawText(text, textLen, 580, 230, paint);
204 } 212 }
205 213
206 // check color emoji 214 // check color emoji
207 paint.setTypeface(fTypeface); 215 if (fTypeface) {
208 #ifdef SK_BUILD_FOR_ANDROID 216 paint.setTypeface(fTypeface);
209 paint.setTextSize(SkIntToScalar(19)); 217 paint.setTextSize(SkIntToScalar(19));
210 #else 218 canvas->drawText(text, textLen, 670, 100, paint);
211 paint.setTextSize(SkIntToScalar(22)); 219 }
212 #endif
213 canvas->drawText(text, textLen, 670, 100, paint);
214
215 #if SK_SUPPORT_GPU 220 #if SK_SUPPORT_GPU
216 // render offscreen buffer 221 // render offscreen buffer
217 if (surface) { 222 if (surface) {
218 SkAutoCanvasRestore acr(inputCanvas, true); 223 SkAutoCanvasRestore acr(inputCanvas, true);
219 // since we prepended this matrix already, we blit using identity 224 // since we prepended this matrix already, we blit using identity
220 inputCanvas->resetMatrix(); 225 inputCanvas->resetMatrix();
221 SkImage* image = surface->newImageSnapshot(); 226 SkImage* image = surface->newImageSnapshot();
222 inputCanvas->drawImage(image, 0, 0, NULL); 227 inputCanvas->drawImage(image, 0, 0, NULL);
223 image->unref(); 228 image->unref();
224 } 229 }
225 #endif 230 #endif
226 } 231 }
227 232
228 private: 233 private:
229 SkTypeface* fTypeface; 234 SkTypeface* fTypeface;
230 235
231 typedef skiagm::GM INHERITED; 236 typedef skiagm::GM INHERITED;
232 }; 237 };
233 238
234 DEF_GM( return SkNEW(DFTextGM); ) 239 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