xref: /aosp_15_r20/external/skia/docs/examples/SkFontMgr_example.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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(SkFontMgr_example, 1280, 512, true, 0) {
tostr(SkFontStyle::Slant s)5 const char* tostr(SkFontStyle::Slant s) {
6     switch (s) {
7         case SkFontStyle::kUpright_Slant: return "SkFontStyle::kUpright_Slant";
8         case SkFontStyle::kItalic_Slant:  return "SkFontStyle::kItalic_Slant";
9         case SkFontStyle::kOblique_Slant: return "SkFontStyle::kOblique_Slant";
10         default: return "";
11     }
12 }
13 
draw(SkCanvas * canvas)14 void draw(SkCanvas* canvas) {
15     SkDebugf("Using a platform specific fontMgr;\n\n");
16 
17     for (int i = 0; i < fontMgr->countFamilies(); ++i) {
18         SkString familyName;
19         fontMgr->getFamilyName(i, &familyName);
20         sk_sp<SkFontStyleSet> styleSet(fontMgr->createStyleSet(i));
21         int N = styleSet->count();
22         for (int j = 0; j < N; ++j) {
23             SkFontStyle fontStyle;
24             SkString style;
25             styleSet->getStyle(j, &fontStyle, &style);
26             SkDebugf(
27                     "SkFont font(fontMgr->legacyMakeTypeface(\"%s\",\n"
28                     "                                        SkFontStyle(%3d, %1d, %-27s));\n",
29                     familyName.c_str(),
30                     fontStyle.weight(),
31                     fontStyle.width(),
32                     tostr(fontStyle.slant()));
33         }
34         SkDebugf("\n");
35     }
36 }
37 }  // END FIDDLE
38