Flutter Engine
The Flutter Engine
Functions
stroketext.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontArguments.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkPoint.h"
#include "include/core/SkScalar.h"
#include "include/core/SkStream.h"
#include "include/core/SkTextBlob.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkDashPathEffect.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Functions

static void test_nulldev (SkCanvas *canvas)
 
static void draw_text_stroked (SkCanvas *canvas, const SkPaint &paint, const SkFont &font, SkScalar strokeWidth)
 
static void draw_text_set (SkCanvas *canvas, const SkPaint &paint, const SkFont &font)
 
 DEF_SIMPLE_GM (stroketext, canvas, 1200, 480)
 
 DEF_SIMPLE_GM_CAN_FAIL (stroketext_native, canvas, msg, 650, 420)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( stroketext  ,
canvas  ,
1200  ,
480   
)

Definition at line 88 of file stroketext.cpp.

88 {
89 if (true) { test_nulldev(canvas); }
90
92 paint.setAntiAlias(true);
93
94 SkFont font(ToolUtils::DefaultPortableTypeface(), kBelowThreshold_TextSize);
95 draw_text_set(canvas, paint, font);
96
97 canvas->translate(600, 0);
98 font.setSize(kAboveThreshold_TextSize);
99 draw_text_set(canvas, paint, font);
100}
Definition: SkFont.h:35
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkTypeface > DefaultPortableTypeface()
font
Font Metadata and Metrics.
static void draw_text_set(SkCanvas *canvas, const SkPaint &paint, const SkFont &font)
Definition: stroketext.cpp:64
static void test_nulldev(SkCanvas *canvas)
Definition: stroketext.cpp:30

◆ DEF_SIMPLE_GM_CAN_FAIL()

DEF_SIMPLE_GM_CAN_FAIL ( stroketext_native  ,
canvas  ,
msg  ,
650  ,
420   
)

Definition at line 102 of file stroketext.cpp.

102 {
105
106 sk_sp<SkTypeface> overlap = []() -> sk_sp<SkTypeface>{
107 std::unique_ptr<SkStreamAsset> variableStream(GetResourceAsStream("fonts/Variable.ttf"));
108 if (!variableStream) {
109 return nullptr;
110 }
112 { SkSetFourByteTag('w','g','h','t'), 721.0f },
113 };
115 params.setVariationDesignPosition({position, std::size(position)});
116 return ToolUtils::TestFontMgr()->makeFromStream(std::move(variableStream), params);
117 }();
118
119 if (!ttf && !otf && !overlap) {
120 msg->append("No support for ttf or otf.");
122 }
123
124 SkPaint p;
125 p.setAntiAlias(true);
126 p.setStyle(SkPaint::kStroke_Style);
127 p.setStrokeWidth(10);
128 p.setStrokeCap(SkPaint::kRound_Cap);
129 p.setStrokeJoin(SkPaint::kRound_Join);
130 p.setARGB(0xff, 0xbb, 0x00, 0x00);
131
132 if (ttf) {
133 /* Stroking.ttf is structured like:
134 nothing U+25CB ○ (nothing inside)
135 something U+25C9 ◉ (a tiny thing inside)
136 - off (point off / empty quad with implicit end) (before U+207B ⁻ / after U+208B ₋)
137 + on (point on / empty line) (before U+207A ⁺ / after U+208A ₊)
138 0 off off (two implicit quads) (before U+2070 ⁰ / after U+2080 ₀)
139 1 off on (quad with implicit close around) (before U+00B9 ¹ / after U+2081 ₁)
140 2 on off (quad with implicit close) (before U+00B2 ² / after U+2082 ₂)
141 3 on on (empty line) (before U+00B3 ³ / after U+2083 ₃)
142 */
143 SkFont font(ttf, 100);
144 canvas->drawString("○◉ ⁻₋⁺₊", 10, 100, font, p);
145 canvas->drawString("⁰₀¹₁²₂³₃", 10, 200, font, p);
146 }
147
148 if (otf) {
149 /* Stroking.otf is structured like:
150 nothing U+25CB ○
151 something U+25C9 ◉
152 0 moveto, moveto (before U+2070 ⁰) (nothing there, FreeType ignores these)
153 1 moveto, empty line, moveto (before U+00B9 ¹) (degenerate lineto)
154 3 moveto, empty cubic, moveto (before U+00B3 ³) (degenerate cubicto)
155 f moveto, empty flex, moveto (before U+1DA0 ᶠ) (degenerate flex)
156 */
157 SkFont font(otf, 100);
158 canvas->drawString("○◉ ⁰¹³ᶠ", 10, 300, font, p);
159 }
160
161 if (overlap) {
162 /* Variable.ttf is structured like:
163 U+74 t (glyf outline has overlap flag)
164 U+167 ŧ (glyf outline does not have overlap flag)
165 */
166 SkFont font(overlap, 100);
167 p.setStrokeWidth(1);
168 canvas->drawString("tŧ", 10, 400, font, p);
169 }
170
172}
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
Definition: Resources.cpp:31
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, int ttcIndex=0) const
Definition: SkFontMgr.cpp:127
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kRound_Join
adds circle
Definition: SkPaint.h:360
const EmbeddedViewParams * params
sk_sp< SkTypeface > CreateTypefaceFromResource(const char *resource, int ttcIndex)
sk_sp< SkFontMgr > TestFontMgr()
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
fonts Distortable ttf
Definition: fontations.cpp:192

◆ draw_text_set()

static void draw_text_set ( SkCanvas canvas,
const SkPaint paint,
const SkFont font 
)
static

Definition at line 64 of file stroketext.cpp.

64 {
65 SkAutoCanvasRestore acr(canvas, true);
66
67 draw_text_stroked(canvas, paint, font, 10);
68
69 canvas->translate(200, 0);
70 draw_text_stroked(canvas, paint, font, 0);
71
72 const SkScalar intervals[] = { 20, 10, 5, 10 };
73 const SkScalar phase = 0;
74
75 canvas->translate(200, 0);
77 p.setPathEffect(SkDashPathEffect::Make(intervals, std::size(intervals), phase));
78 draw_text_stroked(canvas, p, font, 10);
79}
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
float SkScalar
Definition: extension.cpp:12
static void draw_text_stroked(SkCanvas *canvas, const SkPaint &paint, const SkFont &font, SkScalar strokeWidth)
Definition: stroketext.cpp:45

◆ draw_text_stroked()

static void draw_text_stroked ( SkCanvas canvas,
const SkPaint paint,
const SkFont font,
SkScalar  strokeWidth 
)
static

Definition at line 45 of file stroketext.cpp.

46 {
48 SkPoint loc = { 20, 435 };
49
50 if (strokeWidth > 0) {
51 p.setStyle(SkPaint::kFill_Style);
52 canvas->drawSimpleText("P", 1, SkTextEncoding::kUTF8, loc.fX, loc.fY - 225, font, p);
53 canvas->drawTextBlob(SkTextBlob::MakeFromPosText("P", 1, &loc, font), 0, 0, p);
54 }
55
56 p.setColor(SK_ColorRED);
57 p.setStyle(SkPaint::kStroke_Style);
58 p.setStrokeWidth(strokeWidth);
59
60 canvas->drawSimpleText("P", 1, SkTextEncoding::kUTF8, loc.fX, loc.fY - 225, font, p);
61 canvas->drawTextBlob(SkTextBlob::MakeFromPosText("P", 1, &loc, font), 0, 0, p);
62}
static const int strokeWidth
Definition: BlurTest.cpp:60
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
@ kUTF8
uses bytes to represent UTF-8 or ASCII
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 drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
static sk_sp< SkTextBlob > MakeFromPosText(const void *text, size_t byteLength, const SkPoint pos[], const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
Definition: SkTextBlob.cpp:803
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ test_nulldev()

static void test_nulldev ( SkCanvas canvas)
static

Definition at line 30 of file stroketext.cpp.

30 {
31 SkBitmap bm;
33 // notice: no pixels mom! be sure we don't crash
34 // https://code.google.com/p/chromium/issues/detail?id=352616
35 SkCanvas c(bm);
36
38 src.allocN32Pixels(10, 10);
39 src.eraseColor(SK_ColorRED);
40
41 // ensure we don't crash
42 c.writePixels(src, 0, 0);
43}
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Definition: SkBitmap.cpp:114
static SkImageInfo MakeN32Premul(int width, int height)