Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
count_verbs.cpp File Reference
#include "tools/fiddle/examples.h"
#include "include/utils/SkTextUtils.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (count_verbs, 256, 256, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( count_verbs  ,
256  ,
256  ,
false  ,
 
)

Definition at line 4 of file count_verbs.cpp.

4 {
6
7static SkPath make_path(const SkFont& font) {
9 const char text[] = "SKIA";
10 SkTextUtils::GetPath(text, strlen(text), SkTextEncoding::kUTF8, 0, 0, font, &path);
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);
33 SkPath path = make_path(font);
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 static SkString SkStringPrintf()
Definition SkString.h:287
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
@ kDone_Verb
Definition SkPath.h:1464
static void GetPath(const void *text, size_t length, SkTextEncoding, SkScalar x, SkScalar y, const SkFont &, SkPath *)
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
static constexpr SkPoint Make(float x, float y)
float fY
y-axis value