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

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: Line lengths. Created 5 years, 10 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 = "πŸ’°πŸ‘πŸŽ…πŸͺπŸ•πŸš€πŸš»πŸ’©πŸ“·πŸ“¦πŸ‡ΊπŸ‡ΈπŸ‡¦";
reed1 2015/01/26 21:04:40 can we use an escaped version?
bungeman-skia 2015/01/26 22:01:12 Done.
66 } 71 }
67 72
68 SkString onShortName() SK_OVERRIDE { 73 SkString onShortName() SK_OVERRIDE {
69 return SkString("coloremoji"); 74 return SkString("coloremoji");
70 } 75 }
71 76
72 SkISize onISize() SK_OVERRIDE { 77 SkISize onISize() SK_OVERRIDE {
73 return SkISize::Make(650, 480); 78 return SkISize::Make(650, 900);
74 } 79 }
75 80
76 void onDraw(SkCanvas* canvas) SK_OVERRIDE { 81 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
77 82
78 canvas->drawColor(SK_ColorGRAY); 83 canvas->drawColor(SK_ColorGRAY);
79 84
80 SkPaint paint; 85 for (size_t i = 0; i < SK_ARRAY_COUNT(emojiFonts); ++i) {
81 paint.setTypeface(fTypeface); 86 SkPaint paint;
87 paint.setTypeface(emojiFonts[i].typeface);
88 const char* text = emojiFonts[i].text;
82 89
83 const char* text = "hamburgerfons"; 90 // draw text at different point sizes
91 const int textSize[] = { 10, 30, 50, };
92 const int textYOffset[] = { 10, 40, 100, };
93 SkASSERT(sizeof(textSize) == sizeof(textYOffset));
94 size_t y_offset = 0;
95 for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y++) {
96 paint.setTextSize(SkIntToScalar(textSize[y]));
97 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffs et[y]), paint);
98 y_offset += textYOffset[y];
99 }
84 100
85 // draw text at different point sizes 101 // draw with shaders and image filters
86 const int textSize[] = { 10, 30, 50, }; 102 for (int makeLinear = 0; makeLinear < 2; makeLinear++) {
87 const int textYOffset[] = { 10, 40, 100, }; 103 for (int makeBlur = 0; makeBlur < 2; makeBlur++) {
88 SkASSERT(sizeof(textSize) == sizeof(textYOffset)); 104 for (int makeGray = 0; makeGray < 2; makeGray++) {
89 size_t y_offset = 0; 105 SkPaint shaderPaint;
90 for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y++) { 106 shaderPaint.setTypeface(paint.getTypeface());
91 paint.setTextSize(SkIntToScalar(textSize[y])); 107 if (SkToBool(makeLinear)) {
92 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y ]), paint); 108 shaderPaint.setShader(MakeLinear())->unref();
93 y_offset += textYOffset[y]; 109 }
94 }
95 110
96 // draw with shaders and image filters 111 if (SkToBool(makeBlur) && SkToBool(makeGray)) {
97 for (int i = 0; i < 2; i++) { 112 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale (NULL));
98 for (int j = 0; j < 2; j++) { 113 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, gra yScale));
99 for (int k = 0; k < 2; k++) { 114 shaderPaint.setImageFilter(blur);
100 SkPaint shaderPaint; 115 } else if (SkToBool(makeBlur)) {
101 shaderPaint.setTypeface(fTypeface); 116 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, NUL L));
102 if (SkToBool(i)) { 117 shaderPaint.setImageFilter(blur);
103 shaderPaint.setShader(MakeLinear())->unref(); 118 } else if (SkToBool(makeGray)) {
119 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale (NULL));
120 shaderPaint.setImageFilter(grayScale);
121 }
122 shaderPaint.setTextSize(30);
123 canvas->drawText(text, strlen(text), 380, SkIntToScalar( y_offset),
124 shaderPaint);
125 y_offset += 32;
104 } 126 }
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 } 127 }
121 } 128 }
122 }
123 129
124 // setup work needed to draw text with different clips 130 // setup work needed to draw text with different clips
125 canvas->translate(10, 160); 131 canvas->translate(10, 160);
126 paint.setTextSize(40); 132 paint.setTextSize(40);
127 133
128 // compute the bounds of the text 134 // compute the bounds of the text
129 SkRect bounds; 135 SkRect bounds;
130 paint.measureText(text, strlen(text), &bounds); 136 paint.measureText(text, strlen(text), &bounds);
131 137
132 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf; 138 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
133 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf; 139 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
134 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf; 140 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf;
135 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf; 141 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHal f;
136 142
137 SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(), 143 SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(),
138 boundsHalfWidth, boundsHalfHeigh t); 144 boundsHalfWidth, boundsHalfH eight);
139 SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.center Y(), 145 SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.ce nterY(),
140 boundsHalfWidth, boundsHalfHeig ht); 146 boundsHalfWidth, boundsHalf Height);
141 SkRect interiorClip = bounds; 147 SkRect interiorClip = bounds;
142 interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight); 148 interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight);
143 149
144 const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, inte riorClip }; 150 const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, interiorClip };
145 151
146 SkPaint clipHairline; 152 SkPaint clipHairline;
147 clipHairline.setColor(SK_ColorWHITE); 153 clipHairline.setColor(SK_ColorWHITE);
148 clipHairline.setStyle(SkPaint::kStroke_Style); 154 clipHairline.setStyle(SkPaint::kStroke_Style);
149 155
150 for (size_t x = 0; x < sizeof(clipRects) / sizeof(SkRect); ++x) { 156 for (size_t x = 0; x < sizeof(clipRects) / sizeof(SkRect); ++x) {
151 canvas->save(); 157 canvas->save();
152 canvas->drawRect(clipRects[x], clipHairline); 158 canvas->drawRect(clipRects[x], clipHairline);
153 paint.setAlpha(0x20); 159 paint.setAlpha(0x20);
154 canvas->drawText(text, strlen(text), 0, 0, paint); 160 canvas->drawText(text, strlen(text), 0, 0, paint);
155 canvas->clipRect(clipRects[x]); 161 canvas->clipRect(clipRects[x]);
156 paint.setAlpha(0xFF); 162 paint.setAlpha(0xFF);
157 canvas->drawText(text, strlen(text), 0, 0, paint); 163 canvas->drawText(text, strlen(text), 0, 0, paint);
158 canvas->restore(); 164 canvas->restore();
159 canvas->translate(0, bounds.height() + SkIntToScalar(25)); 165 canvas->translate(0, bounds.height() + SkIntToScalar(25));
166 }
160 } 167 }
161 } 168 }
162 169
163 private: 170 private:
164 SkTypeface* fTypeface; 171 SkAutoTUnref<SkTypeface> fCBDT_CBLC_Typeface;
172 SkAutoTUnref<SkTypeface> fSBIX_Typeface;
165 173
166 typedef GM INHERITED; 174 typedef GM INHERITED;
167 }; 175 };
168 176
169 ////////////////////////////////////////////////////////////////////////////// 177 //////////////////////////////////////////////////////////////////////////////
170 178
171 static GM* MyFactory(void*) { return new ColorEmojiGM; } 179 static GM* MyFactory(void*) { return new ColorEmojiGM; }
172 static GMRegistry reg(MyFactory); 180 static GMRegistry reg(MyFactory);
173 181
174 } 182 }
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