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"
4REG_FIDDLE(SkFontMgr_example, 1280, 512, true, 0) {
5const 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
14void draw(SkCanvas* canvas) {
15    SkDebugf("sk_sp<SkFontMgr> mgr(SkFontMgr::RefDefault());\n\n");
16
17    sk_sp<SkFontMgr> mgr(SkFontMgr::RefDefault());
18    for (int i = 0; i < mgr->countFamilies(); ++i) {
19        SkString familyName;
20        mgr->getFamilyName(i, &familyName);
21        sk_sp<SkFontStyleSet> styleSet(mgr->createStyleSet(i));
22        int N = styleSet->count();
23        for (int j = 0; j < N; ++j) {
24            SkFontStyle fontStyle;
25            SkString style;
26            styleSet->getStyle(j, &fontStyle, &style);
27            SkDebugf("SkFont font(mgr->legacyMakeTypeface(\"%s\",\n"
28                     "                                    SkFontStyle(%3d, %1d, %-27s));\n",
29                     familyName.c_str(), fontStyle.weight(), fontStyle.width(),
30                     tostr(fontStyle.slant()));
31        }
32        SkDebugf("\n");
33    }
34}
35}  // END FIDDLE
36