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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "sk_tool_utils.h"
|
|
|
|
|
|
|
|
#include "Resources.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTo.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
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");
|
|
|
|
typefaces[3] = sk_tool_utils::create_portable_typeface("Emoji", SkFontStyle());
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
SkString name("scaledemoji_rendering");
|
|
|
|
name.append(sk_tool_utils::platform_font_manager());
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
const char* text = sk_tool_utils::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;
|
|
|
|
|
2018-12-24 19:52:46 +00:00
|
|
|
canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding,
|
|
|
|
10, y, font, paint);
|
2018-07-18 19:32:08 +00:00
|
|
|
y += metrics.fDescent + metrics.fLeading;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new ScaledEmojiRenderingGM;)
|
2018-08-16 14:17:03 +00:00
|
|
|
}
|