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/gm.h" 9#include "include/core/SkCanvas.h" 10#include "include/core/SkColor.h" 11#include "include/core/SkFont.h" 12#include "include/core/SkFontMetrics.h" 13#include "include/core/SkFontStyle.h" 14#include "include/core/SkFontTypes.h" 15#include "include/core/SkPaint.h" 16#include "include/core/SkRefCnt.h" 17#include "include/core/SkScalar.h" 18#include "include/core/SkSize.h" 19#include "include/core/SkString.h" 20#include "include/core/SkTypeface.h" 21#include "tools/Resources.h" 22#include "tools/ToolUtils.h" 23 24#include <string.h> 25#include <initializer_list> 26 27namespace skiagm { 28class ScaledEmojiRenderingGM : public GM { 29public: 30 ScaledEmojiRenderingGM() {} 31 32protected: 33 sk_sp<SkTypeface> typefaces[4]; 34 35 void onOnceBeforeDraw() override { 36 typefaces[0] = MakeResourceAsTypeface("fonts/colr.ttf"); 37 typefaces[1] = MakeResourceAsTypeface("fonts/sbix.ttf"); 38 typefaces[2] = MakeResourceAsTypeface("fonts/cbdt.ttf"); 39 typefaces[3] = ToolUtils::create_portable_typeface("Emoji", SkFontStyle()); 40 } 41 42 SkString onShortName() override { 43 return SkString("scaledemoji_rendering"); 44 } 45 46 SkISize onISize() override { return SkISize::Make(1200, 1200); } 47 48 void onDraw(SkCanvas* canvas) override { 49 50 canvas->drawColor(SK_ColorGRAY); 51 SkScalar y = 0; 52 53 for (const auto& typeface: typefaces) { 54 SkFont font(typeface); 55 font.setEdging(SkFont::Edging::kAlias); 56 57 SkPaint paint; 58 const char* text = ToolUtils::emoji_sample_text(); 59 SkFontMetrics metrics; 60 61 for (SkScalar textSize : { 70, 150 }) { 62 font.setSize(textSize); 63 font.getMetrics(&metrics); 64 // All typefaces should support subpixel mode 65 font.setSubpixel(true); 66 y += -metrics.fAscent; 67 68 canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 69 10, y, font, paint); 70 y += metrics.fDescent + metrics.fLeading; 71 } 72 } 73 } 74 75private: 76 using INHERITED = GM; 77}; 78 79////////////////////////////////////////////////////////////////////////////// 80 81DEF_GM(return new ScaledEmojiRenderingGM;) 82} // namespace skiagm 83