1 /* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "gm.h" 9 #include "sk_tool_utils.h" 10 11 #include "Resources.h" 12 #include "SkCanvas.h" 13 #include "SkFontMetrics.h" 14 #include "SkStream.h" 15 #include "SkTo.h" 16 #include "SkTypeface.h" 17 18 namespace skiagm { 19 class ScaledEmojiRenderingGM : public GM { 20 public: ScaledEmojiRenderingGM()21 ScaledEmojiRenderingGM() {} 22 23 protected: 24 sk_sp<SkTypeface> typefaces[4]; 25 onOnceBeforeDraw()26 void onOnceBeforeDraw() override { 27 typefaces[0] = MakeResourceAsTypeface("fonts/colr.ttf"); 28 typefaces[1] = MakeResourceAsTypeface("fonts/sbix.ttf"); 29 typefaces[2] = MakeResourceAsTypeface("fonts/cbdt.ttf"); 30 typefaces[3] = sk_tool_utils::create_portable_typeface("Emoji", SkFontStyle()); 31 } 32 onShortName()33 SkString onShortName() override { 34 SkString name("scaledemoji_rendering"); 35 name.append(sk_tool_utils::platform_font_manager()); 36 return name; 37 } 38 onISize()39 SkISize onISize() override { return SkISize::Make(1200, 1200); } 40 onDraw(SkCanvas * canvas)41 void onDraw(SkCanvas* canvas) override { 42 43 canvas->drawColor(SK_ColorGRAY); 44 SkScalar y = 0; 45 46 for (const auto& typeface: typefaces) { 47 SkFont font(typeface); 48 font.setEdging(SkFont::Edging::kAlias); 49 50 SkPaint paint; 51 const char* text = sk_tool_utils::emoji_sample_text(); 52 SkFontMetrics metrics; 53 54 for (SkScalar textSize : { 70, 150 }) { 55 font.setSize(textSize); 56 font.getMetrics(&metrics); 57 // All typefaces should support subpixel mode 58 font.setSubpixel(true); 59 y += -metrics.fAscent; 60 61 canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 62 10, y, font, paint); 63 y += metrics.fDescent + metrics.fLeading; 64 } 65 } 66 } 67 68 private: 69 typedef GM INHERITED; 70 }; 71 72 ////////////////////////////////////////////////////////////////////////////// 73 74 DEF_GM(return new ScaledEmojiRenderingGM;) 75 } 76