1*c8dee2aaSAndroid Build Coastguard Worker // Copyright 2020 Google LLC.
2*c8dee2aaSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3*c8dee2aaSAndroid Build Coastguard Worker #include "tools/fiddle/examples.h"
4*c8dee2aaSAndroid Build Coastguard Worker REG_FIDDLE(SkFontMgr_example2, 1536, 512, false, 0) {
tostr(SkFontStyle::Slant s)5*c8dee2aaSAndroid Build Coastguard Worker const char* tostr(SkFontStyle::Slant s) {
6*c8dee2aaSAndroid Build Coastguard Worker switch (s) {
7*c8dee2aaSAndroid Build Coastguard Worker case SkFontStyle::kUpright_Slant: return "SkFontStyle::kUpright_Slant";
8*c8dee2aaSAndroid Build Coastguard Worker case SkFontStyle::kItalic_Slant: return "SkFontStyle::kItalic_Slant";
9*c8dee2aaSAndroid Build Coastguard Worker case SkFontStyle::kOblique_Slant: return "SkFontStyle::kOblique_Slant";
10*c8dee2aaSAndroid Build Coastguard Worker default: return "";
11*c8dee2aaSAndroid Build Coastguard Worker }
12*c8dee2aaSAndroid Build Coastguard Worker }
13*c8dee2aaSAndroid Build Coastguard Worker
draw(SkCanvas * canvas)14*c8dee2aaSAndroid Build Coastguard Worker void draw(SkCanvas* canvas) {
15*c8dee2aaSAndroid Build Coastguard Worker float x = 10, y = 10;
16*c8dee2aaSAndroid Build Coastguard Worker float textScale = 24;
17*c8dee2aaSAndroid Build Coastguard Worker
18*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < fontMgr->countFamilies(); ++i) {
19*c8dee2aaSAndroid Build Coastguard Worker SkString familyName;
20*c8dee2aaSAndroid Build Coastguard Worker fontMgr->getFamilyName(i, &familyName);
21*c8dee2aaSAndroid Build Coastguard Worker sk_sp<SkFontStyleSet> styleSet(fontMgr->createStyleSet(i));
22*c8dee2aaSAndroid Build Coastguard Worker for (int j = 0; j < styleSet->count(); ++j) {
23*c8dee2aaSAndroid Build Coastguard Worker SkFontStyle fontStyle;
24*c8dee2aaSAndroid Build Coastguard Worker SkString style;
25*c8dee2aaSAndroid Build Coastguard Worker styleSet->getStyle(j, &fontStyle, &style);
26*c8dee2aaSAndroid Build Coastguard Worker auto s = SkStringPrintf(
27*c8dee2aaSAndroid Build Coastguard Worker "SkFont font(fontMgr->legacyMakeTypeface(\"%s\", SkFontStyle(%3d, %1d, %-27s), "
28*c8dee2aaSAndroid Build Coastguard Worker "%g);",
29*c8dee2aaSAndroid Build Coastguard Worker familyName.c_str(),
30*c8dee2aaSAndroid Build Coastguard Worker fontStyle.weight(),
31*c8dee2aaSAndroid Build Coastguard Worker fontStyle.width(),
32*c8dee2aaSAndroid Build Coastguard Worker tostr(fontStyle.slant()),
33*c8dee2aaSAndroid Build Coastguard Worker textScale);
34*c8dee2aaSAndroid Build Coastguard Worker SkFont font(fontMgr->legacyMakeTypeface(familyName.c_str(), fontStyle), textScale);
35*c8dee2aaSAndroid Build Coastguard Worker y += font.getSpacing() * 1.5;
36*c8dee2aaSAndroid Build Coastguard Worker canvas->drawString(s, x, y, font, SkPaint());
37*c8dee2aaSAndroid Build Coastguard Worker }
38*c8dee2aaSAndroid Build Coastguard Worker }
39*c8dee2aaSAndroid Build Coastguard Worker }
40*c8dee2aaSAndroid Build Coastguard Worker } // END FIDDLE
41