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