| 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 (auto rec = it.next()) { |
| 20 |
counts[(unsigned)rec->fVerb]++; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
void draw(SkCanvas* canvas) { |
| 25 |
SkFont font(fontMgr->matchFamilyStyle("DejaVu Sans Mono", SkFontStyle()), 30); |
| 26 |
SkPath path = make_path(font); |
| 27 |
int counts[6]; |
| 28 |
count_verbs(path, counts); |
| 29 |
|
| 30 |
// output results: |
| 31 |
const char* verbs[6] = {"Move", "Line", "Quad", "Conic", "Cubic", "Close"}; |
| 32 |
SkPoint pt = SkPoint::Make(10.0f, 5.0f + font.getSpacing()); |
| 33 |
SkPaint p; |
| 34 |
canvas->clear(SK_ColorWHITE); |
| 35 |
for (int i = 0; i < 6; ++i) { |
| 36 |
canvas->drawString(SkStringPrintf("%-5s %3d", verbs[i], counts[i]), pt.fX, pt.fY, font, |
| 37 |
p); |
| 38 |
pt.fY += font.getSpacing(); |
| 39 |
} |
| 40 |
} |
| 41 |
} // END FIDDLE |