Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
docs
examples
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.
3
#include "
tools/fiddle/examples.h
"
4
REG_FIDDLE
(count_verbs, 256, 256,
false
, 0) {
5
#include "
include/utils/SkTextUtils.h
"
6
7
static
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
14
static
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
31
void
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
SK_ColorWHITE
constexpr SkColor SK_ColorWHITE
Definition
SkColor.h:122
SkTextEncoding::kUTF8
@ kUTF8
uses bytes to represent UTF-8 or ASCII
SkStringPrintf
SK_API SkString static SkString SkStringPrintf()
Definition
SkString.h:287
SkTextUtils.h
draw
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition
aaclip.cpp:27
SkCanvas
Definition
SkCanvas.h:106
SkCanvas::clear
void clear(SkColor color)
Definition
SkCanvas.h:1199
SkCanvas::drawString
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition
SkCanvas.h:1803
SkFontMgr::matchFamilyStyle
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition
SkFontMgr.cpp:109
SkFontStyle
Definition
SkFontStyle.h:16
SkFont
Definition
SkFont.h:35
SkPaint
Definition
SkPaint.h:44
SkPath::Iter
Definition
SkPath.h:1472
SkPath::Iter::next
Verb next(SkPoint pts[4])
Definition
SkPath.cpp:1837
SkPath
Definition
SkPath.h:59
SkPath::Verb
Verb
Definition
SkPath.h:1457
SkPath::kDone_Verb
@ kDone_Verb
Definition
SkPath.h:1464
SkTextUtils::GetPath
static void GetPath(const void *text, size_t length, SkTextEncoding, SkScalar x, SkScalar y, const SkFont &, SkPath *)
Definition
SkTextUtils.cpp:38
fontMgr
sk_sp< SkFontMgr > fontMgr
Definition
examples.cpp:32
examples.h
REG_FIDDLE
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition
examples.h:60
text
std::u16string text
Definition
keyboard_unittests.cc:332
make_path
static SkPath make_path()
Definition
perspshaders.cpp:188
SkPoint
Definition
SkPoint_impl.h:163
SkPoint::fX
float fX
x-axis value
Definition
SkPoint_impl.h:164
SkPoint::Make
static constexpr SkPoint Make(float x, float y)
Definition
SkPoint_impl.h:173
SkPoint::fY
float fY
y-axis value
Definition
SkPoint_impl.h:165
Generated on Fri Apr 26 2024 06:15:37 for Flutter Engine by
1.9.8