Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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) {
8 SkPath path;
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
Verb next(SkPoint pts[4])
Definition SkPath.cpp:1837
@ 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
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
std::u16string text
static SkPath make_path()
float fX
x-axis value
static constexpr SkPoint Make(float x, float y)
float fY
y-axis value