2018-07-18 19:32:08 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkFontMetrics.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkFontStyle.h"
|
|
|
|
#include "include/core/SkFontTypes.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "tools/Resources.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <initializer_list>
|
2018-07-18 19:32:08 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
class ScaledEmojiRenderingGM : public GM {
|
|
|
|
public:
|
|
|
|
ScaledEmojiRenderingGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
sk_sp<SkTypeface> typefaces[4];
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
typefaces[0] = MakeResourceAsTypeface("fonts/colr.ttf");
|
|
|
|
typefaces[1] = MakeResourceAsTypeface("fonts/sbix.ttf");
|
|
|
|
typefaces[2] = MakeResourceAsTypeface("fonts/cbdt.ttf");
|
2019-03-20 16:12:10 +00:00
|
|
|
typefaces[3] = ToolUtils::create_portable_typeface("Emoji", SkFontStyle());
|
2018-07-18 19:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
2019-03-08 17:11:55 +00:00
|
|
|
return SkString("scaledemoji_rendering");
|
2018-07-18 19:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override { return SkISize::Make(1200, 1200); }
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
|
2018-08-16 14:17:03 +00:00
|
|
|
canvas->drawColor(SK_ColorGRAY);
|
2018-07-18 19:32:08 +00:00
|
|
|
SkScalar y = 0;
|
|
|
|
|
|
|
|
for (const auto& typeface: typefaces) {
|
2018-12-24 19:52:46 +00:00
|
|
|
SkFont font(typeface);
|
|
|
|
font.setEdging(SkFont::Edging::kAlias);
|
|
|
|
|
2018-07-18 19:32:08 +00:00
|
|
|
SkPaint paint;
|
2019-03-20 16:12:10 +00:00
|
|
|
const char* text = ToolUtils::emoji_sample_text();
|
2018-11-12 14:35:15 +00:00
|
|
|
SkFontMetrics metrics;
|
2018-07-18 19:32:08 +00:00
|
|
|
|
|
|
|
for (SkScalar textSize : { 70, 150 }) {
|
2018-12-24 19:52:46 +00:00
|
|
|
font.setSize(textSize);
|
|
|
|
font.getMetrics(&metrics);
|
2018-07-18 19:32:08 +00:00
|
|
|
// All typefaces should support subpixel mode
|
2018-12-24 19:52:46 +00:00
|
|
|
font.setSubpixel(true);
|
2018-07-18 19:32:08 +00:00
|
|
|
y += -metrics.fAscent;
|
|
|
|
|
2019-05-07 19:38:46 +00:00
|
|
|
canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8,
|
2018-12-24 19:52:46 +00:00
|
|
|
10, y, font, paint);
|
2018-07-18 19:32:08 +00:00
|
|
|
y += metrics.fDescent + metrics.fLeading;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2018-07-18 19:32:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new ScaledEmojiRenderingGM;)
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|