blob: dd645bd38b06b4cb03744409066d9fe1161bcdcf [file] [log] [blame]
Bruce Wang77bf48a2018-07-18 15:32:08 -04001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "tools/ToolUtils.h"
Bruce Wang77bf48a2018-07-18 15:32:08 -040023
Ben Wagner7fde8e12019-05-01 17:28:53 -040024#include <string.h>
25#include <initializer_list>
Bruce Wang77bf48a2018-07-18 15:32:08 -040026
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");
Mike Kleinea3f0142019-03-20 11:12:10 -050039 typefaces[3] = ToolUtils::create_portable_typeface("Emoji", SkFontStyle());
Bruce Wang77bf48a2018-07-18 15:32:08 -040040 }
41
42 SkString onShortName() override {
Mike Kleinbea1f942019-03-08 11:11:55 -060043 return SkString("scaledemoji_rendering");
Bruce Wang77bf48a2018-07-18 15:32:08 -040044 }
45
46 SkISize onISize() override { return SkISize::Make(1200, 1200); }
47
48 void onDraw(SkCanvas* canvas) override {
49
Mike Kleind46dce32018-08-16 10:17:03 -040050 canvas->drawColor(SK_ColorGRAY);
Bruce Wang77bf48a2018-07-18 15:32:08 -040051 SkScalar y = 0;
52
53 for (const auto& typeface: typefaces) {
Mike Reed088b74e2018-12-24 14:52:46 -050054 SkFont font(typeface);
55 font.setEdging(SkFont::Edging::kAlias);
56
Bruce Wang77bf48a2018-07-18 15:32:08 -040057 SkPaint paint;
Mike Kleinea3f0142019-03-20 11:12:10 -050058 const char* text = ToolUtils::emoji_sample_text();
Mike Reedb5784ac2018-11-12 09:35:15 -050059 SkFontMetrics metrics;
Bruce Wang77bf48a2018-07-18 15:32:08 -040060
61 for (SkScalar textSize : { 70, 150 }) {
Mike Reed088b74e2018-12-24 14:52:46 -050062 font.setSize(textSize);
63 font.getMetrics(&metrics);
Bruce Wang77bf48a2018-07-18 15:32:08 -040064 // All typefaces should support subpixel mode
Mike Reed088b74e2018-12-24 14:52:46 -050065 font.setSubpixel(true);
Bruce Wang77bf48a2018-07-18 15:32:08 -040066 y += -metrics.fAscent;
67
Ben Wagner51e15a62019-05-07 15:38:46 -040068 canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8,
Mike Reed088b74e2018-12-24 14:52:46 -050069 10, y, font, paint);
Bruce Wang77bf48a2018-07-18 15:32:08 -040070 y += metrics.fDescent + metrics.fLeading;
71 }
72 }
73 }
74
75private:
76 typedef GM INHERITED;
77};
78
79//////////////////////////////////////////////////////////////////////////////
80
81DEF_GM(return new ScaledEmojiRenderingGM;)
Mike Kleind46dce32018-08-16 10:17:03 -040082}