Flutter Engine
The Flutter Engine
Functions
SkFontMgr_example2.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (SkFontMgr_example2, 1536, 512, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( SkFontMgr_example2  ,
1536  ,
512  ,
false  ,
 
)

Definition at line 4 of file SkFontMgr_example2.cpp.

4 {
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 float x = 10, y = 10;
16 float textScale = 24;
17
18 for (int i = 0; i < fontMgr->countFamilies(); ++i) {
19 SkString familyName;
20 fontMgr->getFamilyName(i, &familyName);
22 for (int j = 0; j < styleSet->count(); ++j) {
23 SkFontStyle fontStyle;
24 SkString style;
25 styleSet->getStyle(j, &fontStyle, &style);
26 auto s = SkStringPrintf(
27 "SkFont font(fontMgr->legacyMakeTypeface(\"%s\", SkFontStyle(%3d, %1d, %-27s), "
28 "%g);",
29 familyName.c_str(),
30 fontStyle.weight(),
31 fontStyle.width(),
32 tostr(fontStyle.slant()),
33 textScale);
34 SkFont font(fontMgr->legacyMakeTypeface(familyName.c_str(), fontStyle), textScale);
35 y += font.getSpacing() * 1.5;
36 canvas->drawString(s, x, y, font, SkPaint());
37 }
38 }
39}
40} // END FIDDLE
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
sk_sp< SkFontStyleSet > createStyleSet(int index) const
Definition: SkFontMgr.cpp:101
void getFamilyName(int index, SkString *familyName) const
Definition: SkFontMgr.cpp:97
int countFamilies() const
Definition: SkFontMgr.cpp:93
sk_sp< SkTypeface > legacyMakeTypeface(const char familyName[], SkFontStyle style) const
Definition: SkFontMgr.cpp:150
Slant slant() const
Definition: SkFontStyle.h:64
int width() const
Definition: SkFontStyle.h:63
int weight() const
Definition: SkFontStyle.h:62
Definition: SkFont.h:35
const char * c_str() const
Definition: SkString.h:133
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
struct MyStruct s
double y
double x
font
Font Metadata and Metrics.