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

Side by Side Diff: gm/dftext.cpp

Issue 670533002: Add color emoji fallback for distance field text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update comment Created 6 years, 2 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
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"
9 #include "SkCanvas.h"
10 #include "SkStream.h"
8 #include "SkSurface.h" 11 #include "SkSurface.h"
9 #include "SkTypeface.h" 12 #include "SkTypeface.h"
10 13
11 namespace skiagm { 14 namespace skiagm {
12 15
13 class DFTextGM : public GM { 16 class DFTextGM : public GM {
14 public: 17 public:
15 DFTextGM() { 18 DFTextGM() {
16 this->setBGColor(0xFFFFFFFF); 19 this->setBGColor(0xFFFFFFFF);
20 fTypeface = NULL;
17 } 21 }
18 22
19 virtual ~DFTextGM() { 23 virtual ~DFTextGM() {
24 SkSafeUnref(fTypeface);
20 } 25 }
21 26
22 protected: 27 protected:
28 virtual void onOnceBeforeDraw() SK_OVERRIDE {
29 SkString filename = GetResourcePath("/Funkster.ttf");
30 SkAutoTUnref<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
31 if (!stream->isValid()) {
32 SkDebugf("Could not find Funkster.ttf, please set --resourcePath cor rectly.\n");
33 return;
34 }
35
36 fTypeface = SkTypeface::CreateFromStream(stream);
37 }
38
23 virtual uint32_t onGetFlags() const SK_OVERRIDE { 39 virtual uint32_t onGetFlags() const SK_OVERRIDE {
24 return kGPUOnly_Flag; 40 return kGPUOnly_Flag;
25 } 41 }
26 42
robertphillips 2014/10/20 18:52:11 SK_OVERRIDE ?
jvanverth1 2014/10/20 20:04:40 Done.
27 virtual SkString onShortName() { 43 virtual SkString onShortName() {
28 return SkString("dftext"); 44 return SkString("dftext");
29 } 45 }
30 46
robertphillips 2014/10/20 18:52:11 SK_OVERRIDE ?
jvanverth1 2014/10/20 20:04:40 Done.
31 virtual SkISize onISize() { 47 virtual SkISize onISize() {
32 return SkISize::Make(1024, 768); 48 return SkISize::Make(1024, 768);
33 } 49 }
34 50
35 static void rotate_about(SkCanvas* canvas, 51 static void rotate_about(SkCanvas* canvas,
36 SkScalar degrees, 52 SkScalar degrees,
37 SkScalar px, SkScalar py) { 53 SkScalar px, SkScalar py) {
38 canvas->translate(px, py); 54 canvas->translate(px, py);
39 canvas->rotate(degrees); 55 canvas->rotate(degrees);
40 canvas->translate(-px, -py); 56 canvas->translate(-px, -py);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 #else 194 #else
179 paint.setTextSize(SkIntToScalar(22)); 195 paint.setTextSize(SkIntToScalar(22));
180 #endif 196 #endif
181 for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) { 197 for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
182 paint.setColor(fg[i]); 198 paint.setColor(fg[i]);
183 199
184 canvas->drawText(text, textLen, x, y, paint); 200 canvas->drawText(text, textLen, x, y, paint);
185 y += paint.getFontMetrics(NULL); 201 y += paint.getFontMetrics(NULL);
186 } 202 }
187 203
204 // check color emoji
205 paint.setTypeface(fTypeface);
206 canvas->drawText(text, textLen, 670, 100, paint);
207
188 #if SK_SUPPORT_GPU 208 #if SK_SUPPORT_GPU
189 // render offscreen buffer 209 // render offscreen buffer
190 if (surface) { 210 if (surface) {
191 SkAutoCanvasRestore acr(inputCanvas, true); 211 SkAutoCanvasRestore acr(inputCanvas, true);
192 // since we prepended this matrix already, we blit using identity 212 // since we prepended this matrix already, we blit using identity
193 inputCanvas->resetMatrix(); 213 inputCanvas->resetMatrix();
194 SkImage* image = surface->newImageSnapshot(); 214 SkImage* image = surface->newImageSnapshot();
195 inputCanvas->drawImage(image, 0, 0, NULL); 215 inputCanvas->drawImage(image, 0, 0, NULL);
196 image->unref(); 216 image->unref();
197 } 217 }
198 #endif 218 #endif
199 } 219 }
200 220
201 private: 221 private:
222 SkTypeface* fTypeface;
223
202 typedef GM INHERITED; 224 typedef GM INHERITED;
203 }; 225 };
204 226
205 ////////////////////////////////////////////////////////////////////////////// 227 //////////////////////////////////////////////////////////////////////////////
206 228
robertphillips 2014/10/20 18:52:11 DEF_GM ?
jvanverth1 2014/10/20 20:04:40 Done.
207 static GM* MyFactory(void*) { return new DFTextGM; } 229 static GM* MyFactory(void*) { return new DFTextGM; }
208 static GMRegistry reg(MyFactory); 230 static GMRegistry reg(MyFactory);
209 231
210 } 232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698