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

Side by Side Diff: gm/coloremoji.cpp

Issue 797043002: Add sbix font to coloremoji gm. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Create string from explicit utf-8. Created 5 years, 11 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 | « no previous file | no next file » | 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 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"
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 static SkImageFilter* make_blur(float amount, SkImageFilter* input = NULL) { 41 static SkImageFilter* make_blur(float amount, SkImageFilter* input = NULL) {
42 return SkBlurImageFilter::Create(amount, amount, input); 42 return SkBlurImageFilter::Create(amount, amount, input);
43 } 43 }
44 44
45 namespace skiagm { 45 namespace skiagm {
46 46
47 class ColorEmojiGM : public GM { 47 class ColorEmojiGM : public GM {
48 public: 48 public:
49 ColorEmojiGM() { 49 ColorEmojiGM() : fCBDT_CBLC_Typeface(NULL), fSBIX_Typeface(NULL) { }
50 fTypeface = NULL;
51 }
52 50
53 ~ColorEmojiGM() {
54 SkSafeUnref(fTypeface);
55 }
56 protected: 51 protected:
57 void onOnceBeforeDraw() SK_OVERRIDE { 52 struct EmojiFont {
53 SkTypeface* typeface;
54 const char* text;
55 } emojiFonts[2];
56 virtual void onOnceBeforeDraw() SK_OVERRIDE {
58 SkString filename = GetResourcePath("/Funkster.ttf"); 57 SkString filename = GetResourcePath("/Funkster.ttf");
59 SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str())); 58 SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
60 if (!stream->isValid()) { 59 if (stream->isValid()) {
60 fCBDT_CBLC_Typeface.reset(SkTypeface::CreateFromStream(stream.detach ()));
61 emojiFonts[0].typeface = fCBDT_CBLC_Typeface;
62 } else {
61 SkDebugf("Could not find Funkster.ttf, please set --resourcePath cor rectly.\n"); 63 SkDebugf("Could not find Funkster.ttf, please set --resourcePath cor rectly.\n");
62 return; 64 emojiFonts[0].typeface = NULL;
63 } 65 }
66 emojiFonts[0].text = "hamburgerfons";
64 67
65 fTypeface = SkTypeface::CreateFromStream(stream.detach()); 68 fSBIX_Typeface.reset(SkTypeface::CreateFromName("Apple Color Emoji", SkT ypeface::kNormal));
69 emojiFonts[1].typeface = fSBIX_Typeface;
70 emojiFonts[1].text = "\xF0\x9F\x92\xB0" "\xF0\x9F\x8F\xA1" "\xF0\x9F\x8E \x85" // πŸ’°πŸ‘πŸŽ…
71 "\xF0\x9F\x8D\xAA" "\xF0\x9F\x8D\x95" "\xF0\x9F\x9A \x80" // πŸͺπŸ•πŸš€
72 "\xF0\x9F\x9A\xBB" "\xF0\x9F\x92\xA9" "\xF0\x9F\x93 \xB7" // πŸš»πŸ’©πŸ“·
73 "\xF0\x9F\x93\xA6" // πŸ“¦
74 "\xF0\x9F\x87\xBA" "\xF0\x9F\x87\xB8" "\xF0\x9F\x87 \xA6"; // πŸ‡ΊπŸ‡ΈπŸ‡¦
66 } 75 }
67 76
68 SkString onShortName() SK_OVERRIDE { 77 SkString onShortName() SK_OVERRIDE {
69 return SkString("coloremoji"); 78 return SkString("coloremoji");
70 } 79 }
71 80
72 SkISize onISize() SK_OVERRIDE { 81 SkISize onISize() SK_OVERRIDE {
73 return SkISize::Make(650, 480); 82 return SkISize::Make(650, 900);
74 } 83 }
75 84
76 void onDraw(SkCanvas* canvas) SK_OVERRIDE { 85 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
77 86
78 canvas->drawColor(SK_ColorGRAY); 87 canvas->drawColor(SK_ColorGRAY);
79 88
80 SkPaint paint; 89 for (size_t i = 0; i < SK_ARRAY_COUNT(emojiFonts); ++i) {
81 paint.setTypeface(fTypeface); 90 SkPaint paint;
91 paint.setTypeface(emojiFonts[i].typeface);
92 const char* text = emojiFonts[i].text;
82 93
83 const char* text = "hamburgerfons"; 94 // draw text at different point sizes
95 const int textSize[] = { 10, 30, 50, };
96 const int textYOffset[] = { 10, 40, 100, };
97 SkASSERT(sizeof(textSize) == sizeof(textYOffset));
98 size_t y_offset = 0;
99 for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y++) {
100 paint.setTextSize(SkIntToScalar(textSize[y]));
101 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffs et[y]), paint);
102 y_offset += textYOffset[y];
103 }
84 104
85 // draw text at different point sizes 105 // draw with shaders and image filters
86 const int textSize[] = { 10, 30, 50, }; 106 for (int makeLinear = 0; makeLinear < 2; makeLinear++) {
87 const int textYOffset[] = { 10, 40, 100, }; 107 for (int makeBlur = 0; makeBlur < 2; makeBlur++) {
88 SkASSERT(sizeof(textSize) == sizeof(textYOffset)); 108 for (int makeGray = 0; makeGray < 2; makeGray++) {
89 size_t y_offset = 0; 109 SkPaint shaderPaint;
90 for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y++) { 110 shaderPaint.setTypeface(paint.getTypeface());
91 paint.setTextSize(SkIntToScalar(textSize[y])); 111 if (SkToBool(makeLinear)) {
92 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y ]), paint); 112 shaderPaint.setShader(MakeLinear())->unref();
93 y_offset += textYOffset[y]; 113 }
94 }
95 114
96 // draw with shaders and image filters 115 if (SkToBool(makeBlur) && SkToBool(makeGray)) {
97 for (int i = 0; i < 2; i++) { 116 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale (NULL));
98 for (int j = 0; j < 2; j++) { 117 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, gra yScale));
99 for (int k = 0; k < 2; k++) { 118 shaderPaint.setImageFilter(blur);
100 SkPaint shaderPaint; 119 } else if (SkToBool(makeBlur)) {
101 shaderPaint.setTypeface(fTypeface); 120 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, NUL L));
102 if (SkToBool(i)) { 121 shaderPaint.setImageFilter(blur);
103 shaderPaint.setShader(MakeLinear())->unref(); 122 } else if (SkToBool(makeGray)) {
123 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale (NULL));
124 shaderPaint.setImageFilter(grayScale);
125 }
126 shaderPaint.setTextSize(30);
127 canvas->drawText(text, strlen(text), 380, SkIntToScalar( y_offset),
128 shaderPaint);
129 y_offset += 32;
104 } 130 }
105
106 if (SkToBool(j) && SkToBool(k)) {
107 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NUL L));
108 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, graySca le));
109 shaderPaint.setImageFilter(blur);
110 } else if (SkToBool(j)) {
111 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, NULL));
112 shaderPaint.setImageFilter(blur);
113 } else if (SkToBool(k)) {
114 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NUL L));
115 shaderPaint.setImageFilter(grayScale);
116 }
117 shaderPaint.setTextSize(30);
118 canvas->drawText(text, strlen(text), 380, SkIntToScalar(y_of fset), shaderPaint);
119 y_offset += 32;
120 } 131 }
121 } 132 }
122 }
123 133
124 // setup work needed to draw text with different clips 134 // setup work needed to draw text with different clips
125 canvas->translate(10, 160); 135 canvas->translate(10, 160);
126 paint.setTextSize(40); 136 paint.setTextSize(40);
127 137
128 // compute the bounds of the text 138 // compute the bounds of the text
129 SkRect bounds; 139 SkRect bounds;
130 paint.measureText(text, strlen(text), &bounds); 140 paint.measureText(text, strlen(text), &bounds);
131 141
132 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf; 142 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
133 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf; 143 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
134 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf; 144 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf;
135 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf; 145 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHal f;
136 146
137 SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(), 147 SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(),
138 boundsHalfWidth, boundsHalfHeigh t); 148 boundsHalfWidth, boundsHalfH eight);
139 SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.center Y(), 149 SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.ce nterY(),
140 boundsHalfWidth, boundsHalfHeig ht); 150 boundsHalfWidth, boundsHalf Height);
141 SkRect interiorClip = bounds; 151 SkRect interiorClip = bounds;
142 interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight); 152 interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight);
143 153
144 const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, inte riorClip }; 154 const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, interiorClip };
145 155
146 SkPaint clipHairline; 156 SkPaint clipHairline;
147 clipHairline.setColor(SK_ColorWHITE); 157 clipHairline.setColor(SK_ColorWHITE);
148 clipHairline.setStyle(SkPaint::kStroke_Style); 158 clipHairline.setStyle(SkPaint::kStroke_Style);
149 159
150 for (size_t x = 0; x < sizeof(clipRects) / sizeof(SkRect); ++x) { 160 for (size_t x = 0; x < sizeof(clipRects) / sizeof(SkRect); ++x) {
151 canvas->save(); 161 canvas->save();
152 canvas->drawRect(clipRects[x], clipHairline); 162 canvas->drawRect(clipRects[x], clipHairline);
153 paint.setAlpha(0x20); 163 paint.setAlpha(0x20);
154 canvas->drawText(text, strlen(text), 0, 0, paint); 164 canvas->drawText(text, strlen(text), 0, 0, paint);
155 canvas->clipRect(clipRects[x]); 165 canvas->clipRect(clipRects[x]);
156 paint.setAlpha(0xFF); 166 paint.setAlpha(0xFF);
157 canvas->drawText(text, strlen(text), 0, 0, paint); 167 canvas->drawText(text, strlen(text), 0, 0, paint);
158 canvas->restore(); 168 canvas->restore();
159 canvas->translate(0, bounds.height() + SkIntToScalar(25)); 169 canvas->translate(0, bounds.height() + SkIntToScalar(25));
170 }
160 } 171 }
161 } 172 }
162 173
163 private: 174 private:
164 SkTypeface* fTypeface; 175 SkAutoTUnref<SkTypeface> fCBDT_CBLC_Typeface;
176 SkAutoTUnref<SkTypeface> fSBIX_Typeface;
165 177
166 typedef GM INHERITED; 178 typedef GM INHERITED;
167 }; 179 };
168 180
169 ////////////////////////////////////////////////////////////////////////////// 181 //////////////////////////////////////////////////////////////////////////////
170 182
171 static GM* MyFactory(void*) { return new ColorEmojiGM; } 183 static GM* MyFactory(void*) { return new ColorEmojiGM; }
172 static GMRegistry reg(MyFactory); 184 static GMRegistry reg(MyFactory);
173 185
174 } 186 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698