Flutter Engine
The Flutter Engine
count_verbs.cpp
Go to the documentation of this file.
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE(count_verbs, 256, 256, false, 0) {
6
7static SkPath make_path(const SkFont& font) {
9 const char text[] = "SKIA";
11 return path;
12}
13
14static void count_verbs(const SkPath& path, int counts[6]) {
15 SkPath::Iter it(path, false);
16 for (int i = 0; i < 6; ++i) {
17 counts[i] = 0;
18 }
19 while (true) {
20 SkPoint pts[4];
21 SkPath::Verb verb = it.next(pts);
22 if (verb == SkPath::kDone_Verb) {
23 break;
24 }
25 if ((unsigned)verb < 6) {
26 counts[(unsigned)verb]++;
27 }
28 }
29}
30
31void draw(SkCanvas* canvas) {
32 SkFont font(fontMgr->matchFamilyStyle("DejaVu Sans Mono", SkFontStyle()), 30);
34 int counts[6];
35 count_verbs(path, counts);
36
37 // output results:
38 const char* verbs[6] = {"Move", "Line", "Quad", "Conic", "Cubic", "Close"};
39 SkPoint pt = SkPoint::Make(10.0f, 5.0f + font.getSpacing());
40 SkPaint p;
41 canvas->clear(SK_ColorWHITE);
42 for (int i = 0; i < 6; ++i) {
43 canvas->drawString(SkStringPrintf("%-5s %3d", verbs[i], counts[i]), pt.fX, pt.fY, font,
44 p);
45 pt.fY += font.getSpacing();
46 }
47}
48} // END FIDDLE
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
@ kUTF8
uses bytes to represent UTF-8 or ASCII
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
Verb next(SkPoint pts[4])
Definition: SkPath.cpp:1901
Definition: SkPath.h:59
@ kDone_Verb
Definition: SkPath.h:1472
static void GetPath(const void *text, size_t length, SkTextEncoding, SkScalar x, SkScalar y, const SkFont &, SkPath *)
Definition: SkTextUtils.cpp:38
REG_FIDDLE(count_verbs, 256, 256, false, 0)
Definition: count_verbs.cpp:4
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
std::u16string text
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
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 counts
Definition: switches.h:239
font
Font Metadata and Metrics.
static SkPath make_path()
float fX
x-axis value
Definition: SkPoint_impl.h:164
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
float fY
y-axis value
Definition: SkPoint_impl.h:165