Flutter Engine
The Flutter Engine
gradtext.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
14#include "include/core/SkRect.h"
18#include "include/core/SkSize.h"
24#include "tools/ToolUtils.h"
26
27namespace {
28
29// test shader w/ transparency
31 SkColor colors[] = { SK_ColorRED, 0x0000FF00, SK_ColorBLUE };
32 SkPoint pts[] = { { 0, 0 }, { width, 0 } };
35}
36
37// test opaque shader
38static sk_sp<SkShader> make_grad2(SkScalar width) {
40 SkPoint pts[] = { { 0, 0 }, { width, 0 } };
43}
44
45static sk_sp<SkShader> make_chrome_solid() {
47 SkPoint pts[] = { { 0, 0 }, { 1, 0 } };
49}
50
51// Replicate chrome layout test - clipped pathed gradient-shaded text
52class ChromeGradTextGM1 : public skiagm::GM {
53 SkString getName() const override { return SkString("chrome_gradtext1"); }
54
55 SkISize getISize() override { return {500, 480}; }
56
57 void onDraw(SkCanvas* canvas) override {
60
61 canvas->clipRect(r);
62
63 paint.setColor(SK_ColorRED);
64 canvas->drawRect(r, paint);
65
66 // Minimal repro doesn't require AA, LCD, or a nondefault typeface
67 paint.setShader(make_chrome_solid());
68
71
72 canvas->drawString("I", 0, 100, font, paint);
73 }
74};
75
76// Replicate chrome layout test - switching between solid & gradient text
77class ChromeGradTextGM2 : public skiagm::GM {
78 SkString getName() const override { return SkString("chrome_gradtext2"); }
79
80 SkISize getISize() override { return {500, 480}; }
81
82 void onDraw(SkCanvas* canvas) override {
86
88 canvas->drawString("Normal Fill Text", 0, 50, font, paint);
90 canvas->drawString("Normal Stroke Text", 0, 100, font, paint);
91
92 // Minimal repro doesn't require AA, LCD, or a nondefault typeface
93 paint.setShader(make_chrome_solid());
94
96 canvas->drawString("Gradient Fill Text", 0, 150, font, paint);
98 canvas->drawString("Gradient Stroke Text", 0, 200, font, paint);
99 }
100};
101} // namespace
102
103DEF_GM( return new ChromeGradTextGM1; )
104DEF_GM( return new ChromeGradTextGM2; )
105
106DEF_SIMPLE_GM(gradtext, canvas, 500, 480) {
107 static constexpr float kTextSize = 26.0f;
109
110 canvas->drawRect({0, 0, 500, 240}, SkPaint());
111 canvas->translate(20.0f, kTextSize);
112
113 SkPaint paints[2];
114 paints[0].setShader(make_grad(80.0f));
115 paints[1].setShader(make_grad2(80.0f));
116
117 static const SkFont::Edging edgings[3] = {
121 };
122 for (int i = 0; i < 2; ++i) {
123 for (const SkPaint& paint : paints) {
124 for (SkFont::Edging edging : edgings) {
125 font.setEdging(edging);
126 canvas->drawString("When in the course of human events", 0, 0, font, paint);
127 canvas->translate(0, kTextSize * 4/3);
128 }
129 canvas->translate(0, kTextSize * 2/3);
130 }
131 }
132}
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
Edging
Definition: SkFont.h:39
@ kAntiAlias
may have transparent pixels on glyph edges
@ kAlias
no transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
void setShader(sk_sp< SkShader > shader)
Definition: gm.h:110
virtual SkISize getISize()=0
virtual SkString getName() const =0
virtual DrawResult onDraw(SkCanvas *, SkString *errorMsg)
Definition: gm.cpp:139
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
DEF_SIMPLE_GM(gradtext, canvas, 500, 480)
Definition: gradtext.cpp:106
static sk_sp< SkShader > make_grad(SkScalar width)
Definition: hsl.cpp:202
PODArray< SkColor > colors
Definition: SkRecords.h:276
sk_sp< SkTypeface > DefaultPortableTypeface()
SkFont DefaultPortableFont()
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.
int32_t width
Definition: SkSize.h:16
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609