Flutter Engine
The Flutter Engine
scaledemoji_rendering.cpp
Go to the documentation of this file.
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"
11#include "include/core/SkFont.h"
18#include "include/core/SkSize.h"
22#include "tools/Resources.h"
23#include "tools/ToolUtils.h"
25
26#include <string.h>
27#include <initializer_list>
28
29namespace skiagm {
30class ScaledEmojiRenderingGM : public GM {
31public:
33
34protected:
41 };
43 void onOnceBeforeDraw() override {
44 for (auto&& [i, format] : SkMakeEnumerate(formatsToTest)) {
46 if (!fontSamples[i].typeface) {
48 }
49 }
50 }
51
52 SkString getName() const override { return SkString("scaledemoji_rendering"); }
53
54 SkISize getISize() override { return SkISize::Make(1200, 1200); }
55
56 void onDraw(SkCanvas* canvas) override {
57
58 canvas->drawColor(SK_ColorGRAY);
59 SkPaint textPaint;
60 textPaint.setColor(SK_ColorCYAN);
61
62 SkPaint boundsPaint;
63 boundsPaint.setStrokeWidth(2);
65 boundsPaint.setColor(SK_ColorGREEN);
66
67 SkPaint advancePaint;
68 advancePaint.setColor(SK_ColorRED);
69
70 SkScalar y = 0;
71 for (auto& sample : fontSamples) {
72 SkFont font(sample.typeface);
74
75 const char* text = sample.sampleText;
76 SkFontMetrics metrics;
77
78 for (SkScalar textSize : { 70, 150 }) {
79 font.setSize(textSize);
80 font.getMetrics(&metrics);
81 // All typefaces should support subpixel mode
82 font.setSubpixel(true);
83
84 y += -metrics.fAscent;
85
86 SkScalar x = 0;
87 for (bool fakeBold : { false, true }) {
88 font.setEmbolden(fakeBold);
90 SkScalar advance = font.measureText(text, strlen(text), SkTextEncoding::kUTF8,
91 &bounds, &textPaint);
93 x, y, font, textPaint);
94 if ((false)) {
95 bounds.offset(x, y);
96 canvas->drawRect(bounds, boundsPaint);
97 SkRect advanceRect = SkRect::MakeLTRB(x, y + 2, x + advance, y + 4);
98 canvas->drawRect(advanceRect, advancePaint);
99 }
100 x += bounds.width() * 1.2;
101 }
102 y += metrics.fDescent + metrics.fLeading;
103 x = 0;
104 }
105 }
106 }
107
108private:
109 using INHERITED = GM;
110};
111
112//////////////////////////////////////////////////////////////////////////////
113
114DEF_GM(return new ScaledEmojiRenderingGM;)
115} // namespace skiagm
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkEnumerate< Iter > SkMakeEnumerate(C &c)
Definition: SkEnumerate.h:102
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void onDraw(SkCanvas *canvas) override
SkString getName() const override
ToolUtils::EmojiTestSample fontSamples[std::size(formatsToTest)]
static constexpr ToolUtils::EmojiFontFormat formatsToTest[]
float SkScalar
Definition: extension.cpp:12
uint32_t uint32_t * format
std::u16string text
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
EmojiTestSample EmojiSample()
sk_sp< SkTypeface > DefaultTypeface()
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
SkScalar fLeading
distance to add between lines, typically positive or zero
Definition: SkFontMetrics.h:57
SkScalar fAscent
distance to reserve above baseline, typically negative
Definition: SkFontMetrics.h:54
SkScalar fDescent
distance to reserve below baseline, typically positive
Definition: SkFontMetrics.h:55
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
sk_sp< SkTypeface > typeface
Definition: FontToolUtils.h:48