| 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 21 matching lines...) Expand all Loading... |
| 32 canvas->drawTextBlob(blob, 0, 0, paint); | 32 canvas->drawTextBlob(blob, 0, 0, paint); |
| 33 canvas->restore(); | 33 canvas->restore(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 class MixedTextBlobsGM : public GM { | 36 class MixedTextBlobsGM : public GM { |
| 37 public: | 37 public: |
| 38 MixedTextBlobsGM() { } | 38 MixedTextBlobsGM() { } |
| 39 | 39 |
| 40 protected: | 40 protected: |
| 41 void onOnceBeforeDraw() override { | 41 void onOnceBeforeDraw() override { |
| 42 #ifndef SK_BUILD_FOR_MAC | 42 fEmojiTypeface.reset(sk_tool_utils::emoji_typeface()); |
| 43 fEmojiTypeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf")); | 43 fEmojiText = sk_tool_utils::emoji_sample_text(); |
| 44 fEmojiText = "Emoji!!!"; | |
| 45 #else | |
| 46 fEmojiTypeface.reset(SkTypeface::CreateFromName("Apple Color Emoji", SkT
ypeface::kNormal)); | |
| 47 fEmojiText = "\xF0\x9F\x92\xB0" "\xF0\x9F\x8F\xA1" "\xF0\x9F\x8E\x85" //
💰🏡🎅 | |
| 48 "\xF0\x9F\x8D\xAA" "\xF0\x9F\x8D\x95" "\xF0\x9F\x9A\x80"; /
/ 🍪🍕🚀 | |
| 49 #endif | |
| 50 fReallyBigATypeface.reset(GetResourceAsTypeface("/fonts/ReallyBigA.ttf")
); | 44 fReallyBigATypeface.reset(GetResourceAsTypeface("/fonts/ReallyBigA.ttf")
); |
| 51 | 45 |
| 52 SkTextBlobBuilder builder; | 46 SkTextBlobBuilder builder; |
| 53 | 47 |
| 54 // make textblob | 48 // make textblob |
| 55 // Text so large we draw as paths | 49 // Text so large we draw as paths |
| 56 SkPaint paint; | 50 SkPaint paint; |
| 57 paint.setTextSize(385); | 51 paint.setTextSize(385); |
| 58 const char* text = "O"; | 52 const char* text = "O"; |
| 59 sk_tool_utils::set_portable_typeface(&paint); | 53 sk_tool_utils::set_portable_typeface(&paint); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 76 paint.setTextSize(32); | 70 paint.setTextSize(32); |
| 77 text = "LCD!!!!!"; | 71 text = "LCD!!!!!"; |
| 78 paint.setSubpixelText(true); | 72 paint.setSubpixelText(true); |
| 79 paint.setLCDRenderText(true); | 73 paint.setLCDRenderText(true); |
| 80 paint.measureText(text, strlen(text), &bounds); | 74 paint.measureText(text, strlen(text), &bounds); |
| 81 sk_tool_utils::add_to_text_blob(&builder, text, paint, xOffset - bounds.
width() * 0.25f, | 75 sk_tool_utils::add_to_text_blob(&builder, text, paint, xOffset - bounds.
width() * 0.25f, |
| 82 yOffset - bounds.height() * 0.5f); | 76 yOffset - bounds.height() * 0.5f); |
| 83 yOffset += bounds.height(); | 77 yOffset += bounds.height(); |
| 84 | 78 |
| 85 // color emoji | 79 // color emoji |
| 86 paint.setSubpixelText(false); | 80 if (fEmojiTypeface) { |
| 87 paint.setLCDRenderText(false); | 81 paint.setSubpixelText(false); |
| 88 paint.setTypeface(fEmojiTypeface); | 82 paint.setLCDRenderText(false); |
| 89 text = fEmojiText; | 83 paint.setTypeface(fEmojiTypeface); |
| 90 paint.measureText(text, strlen(text), &bounds); | 84 text = fEmojiText; |
| 91 sk_tool_utils::add_to_text_blob(&builder, text, paint, xOffset - bounds.
width() * 0.3f, | 85 paint.measureText(text, strlen(text), &bounds); |
| 92 yOffset); | 86 sk_tool_utils::add_to_text_blob(&builder, text, paint, xOffset - bou
nds.width() * 0.3f, |
| 87 yOffset); |
| 88 } |
| 93 | 89 |
| 94 // Corrupted font | 90 // Corrupted font |
| 95 paint.setTextSize(12); | 91 paint.setTextSize(12); |
| 96 text = "aA"; | 92 text = "aA"; |
| 97 paint.setTypeface(fReallyBigATypeface); | 93 paint.setTypeface(fReallyBigATypeface); |
| 98 sk_tool_utils::add_to_text_blob(&builder, text, paint, corruptedAx, corr
uptedAy); | 94 sk_tool_utils::add_to_text_blob(&builder, text, paint, corruptedAx, corr
uptedAy); |
| 99 fBlob.reset(builder.build()); | 95 fBlob.reset(builder.build()); |
| 100 } | 96 } |
| 101 | 97 |
| 102 SkString onShortName() override { | 98 SkString onShortName() override { |
| 103 return SkString("mixedtextblobs"); | 99 SkString name("mixedtextblobs"); |
| 100 name.append(sk_tool_utils::platform_os_emoji()); |
| 101 return name; |
| 104 } | 102 } |
| 105 | 103 |
| 106 SkISize onISize() override { | 104 SkISize onISize() override { |
| 107 return SkISize::Make(kWidth, kHeight); | 105 return SkISize::Make(kWidth, kHeight); |
| 108 } | 106 } |
| 109 | 107 |
| 110 void onDraw(SkCanvas* canvas) override { | 108 void onDraw(SkCanvas* canvas) override { |
| 111 | 109 |
| 112 canvas->drawColor(SK_ColorGRAY); | 110 canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorGRAY)); |
| 113 | 111 |
| 114 SkPaint paint; | 112 SkPaint paint; |
| 115 | 113 |
| 116 // setup work needed to draw text with different clips | 114 // setup work needed to draw text with different clips |
| 117 paint.setColor(SK_ColorBLACK); | 115 paint.setColor(SK_ColorBLACK); |
| 118 canvas->translate(10, 40); | 116 canvas->translate(10, 40); |
| 119 | 117 |
| 120 paint.setTextSize(40); | 118 paint.setTextSize(40); |
| 121 | 119 |
| 122 // compute the bounds of the text and setup some clips | 120 // compute the bounds of the text and setup some clips |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 static const int kWidth = 1250; | 156 static const int kWidth = 1250; |
| 159 static const int kHeight = 700; | 157 static const int kHeight = 700; |
| 160 | 158 |
| 161 typedef GM INHERITED; | 159 typedef GM INHERITED; |
| 162 }; | 160 }; |
| 163 | 161 |
| 164 ////////////////////////////////////////////////////////////////////////////// | 162 ////////////////////////////////////////////////////////////////////////////// |
| 165 | 163 |
| 166 DEF_GM( return SkNEW(MixedTextBlobsGM); ) | 164 DEF_GM( return SkNEW(MixedTextBlobsGM); ) |
| 167 } | 165 } |
| OLD | NEW |