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

Side by Side Diff: gm/coloremoji.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 | « no previous file | gm/dftext.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 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() : fCBDT_CBLC_Typeface(NULL), fSBIX_Typeface(NULL) { } 49 ColorEmojiGM() { }
50 50
51 protected: 51 protected:
52 struct EmojiFont { 52 struct EmojiFont {
53 SkTypeface* typeface; 53 SkTypeface* typeface;
54 const char* text; 54 const char* text;
55 } emojiFonts[2]; 55 } emojiFont;
56 virtual void onOnceBeforeDraw() override { 56 virtual void onOnceBeforeDraw() override {
57 fCBDT_CBLC_Typeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf")); 57 emojiFont.typeface = sk_tool_utils::emoji_typeface();
58 emojiFonts[0].typeface = fCBDT_CBLC_Typeface; 58 emojiFont.text = sk_tool_utils::emoji_sample_text();
59 emojiFonts[0].text = "hamburgerfons";
60
61 fSBIX_Typeface.reset(SkTypeface::CreateFromName("Apple Color Emoji", SkT ypeface::kNormal));
62 emojiFonts[1].typeface = fSBIX_Typeface;
63 emojiFonts[1].text = "\xF0\x9F\x92\xB0" "\xF0\x9F\x8F\xA1" "\xF0\x9F\x8E \x85" // πŸ’°πŸ‘πŸŽ…
64 "\xF0\x9F\x8D\xAA" "\xF0\x9F\x8D\x95" "\xF0\x9F\x9A \x80" // πŸͺπŸ•πŸš€
65 "\xF0\x9F\x9A\xBB" "\xF0\x9F\x92\xA9" "\xF0\x9F\x93 \xB7" // πŸš»πŸ’©πŸ“·
66 "\xF0\x9F\x93\xA6" // πŸ“¦
67 "\xF0\x9F\x87\xBA" "\xF0\x9F\x87\xB8" "\xF0\x9F\x87 \xA6"; // πŸ‡ΊπŸ‡ΈπŸ‡¦
68 } 59 }
69 60
70 SkString onShortName() override { 61 SkString onShortName() override {
71 return SkString("coloremoji"); 62 SkString name("coloremoji");
63 name.append(sk_tool_utils::platform_os_emoji());
64 return name;
72 } 65 }
73 66
74 SkISize onISize() override { 67 SkISize onISize() override {
75 return SkISize::Make(650, 900); 68 return SkISize::Make(650, 900);
76 } 69 }
77 70
78 void onDraw(SkCanvas* canvas) override { 71 void onDraw(SkCanvas* canvas) override {
79 72
80 canvas->drawColor(SK_ColorGRAY); 73 canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorGRAY));
81 74
82 for (size_t i = 0; i < SK_ARRAY_COUNT(emojiFonts); ++i) { 75 SkPaint paint;
83 SkPaint paint; 76 paint.setTypeface(emojiFont.typeface);
84 paint.setTypeface(emojiFonts[i].typeface); 77 const char* text = emojiFont.text;
85 const char* text = emojiFonts[i].text;
86 78
87 // draw text at different point sizes 79 // draw text at different point sizes
88 const int textSize[] = { 10, 30, 50, }; 80 const int textSize[] = { 10, 30, 50, };
89 const int textYOffset[] = { 10, 40, 100, }; 81 const int textYOffset[] = { 10, 40, 100, };
90 SkASSERT(sizeof(textSize) == sizeof(textYOffset)); 82 SkASSERT(sizeof(textSize) == sizeof(textYOffset));
91 size_t y_offset = 0; 83 size_t y_offset = 0;
92 for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y++) { 84 for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y++) {
93 paint.setTextSize(SkIntToScalar(textSize[y])); 85 paint.setTextSize(SkIntToScalar(textSize[y]));
94 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffs et[y]), paint); 86 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y ]), paint);
95 y_offset += textYOffset[y]; 87 y_offset += textYOffset[y];
96 } 88 }
97 89
98 // draw with shaders and image filters 90 // draw with shaders and image filters
99 for (int makeLinear = 0; makeLinear < 2; makeLinear++) { 91 for (int makeLinear = 0; makeLinear < 2; makeLinear++) {
100 for (int makeBlur = 0; makeBlur < 2; makeBlur++) { 92 for (int makeBlur = 0; makeBlur < 2; makeBlur++) {
101 for (int makeGray = 0; makeGray < 2; makeGray++) { 93 for (int makeGray = 0; makeGray < 2; makeGray++) {
102 SkPaint shaderPaint; 94 SkPaint shaderPaint;
103 shaderPaint.setTypeface(paint.getTypeface()); 95 shaderPaint.setTypeface(paint.getTypeface());
104 if (SkToBool(makeLinear)) { 96 if (SkToBool(makeLinear)) {
105 shaderPaint.setShader(MakeLinear())->unref(); 97 shaderPaint.setShader(MakeLinear())->unref();
106 } 98 }
107 99
108 if (SkToBool(makeBlur) && SkToBool(makeGray)) { 100 if (SkToBool(makeBlur) && SkToBool(makeGray)) {
109 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale (NULL)); 101 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NUL L));
110 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, gra yScale)); 102 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, graySca le));
111 shaderPaint.setImageFilter(blur); 103 shaderPaint.setImageFilter(blur);
112 } else if (SkToBool(makeBlur)) { 104 } else if (SkToBool(makeBlur)) {
113 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, NUL L)); 105 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, NULL));
114 shaderPaint.setImageFilter(blur); 106 shaderPaint.setImageFilter(blur);
115 } else if (SkToBool(makeGray)) { 107 } else if (SkToBool(makeGray)) {
116 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale (NULL)); 108 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NUL L));
117 shaderPaint.setImageFilter(grayScale); 109 shaderPaint.setImageFilter(grayScale);
118 }
119 shaderPaint.setTextSize(30);
120 canvas->drawText(text, strlen(text), 380, SkIntToScalar( y_offset),
121 shaderPaint);
122 y_offset += 32;
123 } 110 }
111 shaderPaint.setTextSize(30);
112 canvas->drawText(text, strlen(text), 380, SkIntToScalar(y_of fset),
113 shaderPaint);
114 y_offset += 32;
124 } 115 }
125 } 116 }
117 }
126 118
127 // setup work needed to draw text with different clips 119 // setup work needed to draw text with different clips
128 canvas->translate(10, 160); 120 canvas->translate(10, 160);
129 paint.setTextSize(40); 121 paint.setTextSize(40);
130 122
131 // compute the bounds of the text 123 // compute the bounds of the text
132 SkRect bounds; 124 SkRect bounds;
133 paint.measureText(text, strlen(text), &bounds); 125 paint.measureText(text, strlen(text), &bounds);
134 126
135 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf; 127 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
136 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf; 128 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
137 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf; 129 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf;
138 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHal f; 130 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf;
139 131
140 SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(), 132 SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(),
141 boundsHalfWidth, boundsHalfH eight); 133 boundsHalfWidth, boundsHalfHeigh t);
142 SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.ce nterY(), 134 SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.center Y(),
143 boundsHalfWidth, boundsHalf Height); 135 boundsHalfWidth, boundsHalfHeig ht);
144 SkRect interiorClip = bounds; 136 SkRect interiorClip = bounds;
145 interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight); 137 interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight);
146 138
147 const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, interiorClip }; 139 const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, inte riorClip };
148 140
149 SkPaint clipHairline; 141 SkPaint clipHairline;
150 clipHairline.setColor(SK_ColorWHITE); 142 clipHairline.setColor(SK_ColorWHITE);
151 clipHairline.setStyle(SkPaint::kStroke_Style); 143 clipHairline.setStyle(SkPaint::kStroke_Style);
152 144
153 for (size_t x = 0; x < sizeof(clipRects) / sizeof(SkRect); ++x) { 145 for (size_t x = 0; x < sizeof(clipRects) / sizeof(SkRect); ++x) {
154 canvas->save(); 146 canvas->save();
155 canvas->drawRect(clipRects[x], clipHairline); 147 canvas->drawRect(clipRects[x], clipHairline);
156 paint.setAlpha(0x20); 148 paint.setAlpha(0x20);
157 canvas->drawText(text, strlen(text), 0, 0, paint); 149 canvas->drawText(text, strlen(text), 0, 0, paint);
158 canvas->clipRect(clipRects[x]); 150 canvas->clipRect(clipRects[x]);
159 paint.setAlpha(0xFF); 151 paint.setAlpha(0xFF);
160 canvas->drawText(text, strlen(text), 0, 0, paint); 152 canvas->drawText(text, strlen(text), 0, 0, paint);
161 canvas->restore(); 153 canvas->restore();
162 canvas->translate(0, bounds.height() + SkIntToScalar(25)); 154 canvas->translate(0, bounds.height() + SkIntToScalar(25));
163 }
164 } 155 }
165 } 156 }
166 157
167 private: 158 private:
168 SkAutoTUnref<SkTypeface> fCBDT_CBLC_Typeface; 159 SkAutoTUnref<SkTypeface> fCBDT_CBLC_Typeface;
169 SkAutoTUnref<SkTypeface> fSBIX_Typeface; 160 SkAutoTUnref<SkTypeface> fSBIX_Typeface;
170 161
171 typedef GM INHERITED; 162 typedef GM INHERITED;
172 }; 163 };
173 164
174 ////////////////////////////////////////////////////////////////////////////// 165 //////////////////////////////////////////////////////////////////////////////
175 166
176 static GM* MyFactory(void*) { return new ColorEmojiGM; } 167 static GM* MyFactory(void*) { return new ColorEmojiGM; }
177 static GMRegistry reg(MyFactory); 168 static GMRegistry reg(MyFactory);
178 169
179 } 170 }
OLDNEW
« no previous file with comments | « no previous file | gm/dftext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698