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

Go to the source code of this file.

Functions

 REG_FIDDLE (text_rendering, 256, 256, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( text_rendering  ,
256  ,
256  ,
false  ,
 
)

Definition at line 4 of file text_rendering.cpp.

4 {
5void draw(SkCanvas* canvas) {
6 const char* fontFamily = nullptr; // Default system family, if it exists.
7 SkFontStyle fontStyle; // Default is normal weight, normal width, upright slant.
8
9 sk_sp<SkTypeface> typeface = fontMgr->legacyMakeTypeface(fontFamily, fontStyle);
10
11 SkFont font1(typeface, 64.0f, 1.0f, 0.0f);
12 SkFont font2(typeface, 64.0f, 1.5f, 0.0f);
13 font1.setEdging(SkFont::Edging::kAntiAlias);
14 font2.setEdging(SkFont::Edging::kAntiAlias);
15
16 // Note: MakeFromString may fail to produce expected results if the typeface
17 // does not have glyphs for the characters in the string. The characters
18 // will not be kerned or shaped beyond a simple mapping from one Unicode
19 // code point to one glyph with a default advance.
20 sk_sp<SkTextBlob> blob1 = SkTextBlob::MakeFromString("Skia", font1);
21 sk_sp<SkTextBlob> blob2 = SkTextBlob::MakeFromString("Skia", font2);
22
23 SkPaint paint1, paint2, paint3;
24
25 paint1.setAntiAlias(true);
26 paint1.setColor(SkColorSetARGB(0xFF, 0x42, 0x85, 0xF4));
27
28 paint2.setAntiAlias(true);
29 paint2.setColor(SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37));
31 paint2.setStrokeWidth(3.0f);
32
33 paint3.setAntiAlias(true);
34 paint3.setColor(SkColorSetARGB(0xFF, 0x0F, 0x9D, 0x58));
35
36 canvas->clear(SK_ColorWHITE);
37 canvas->drawTextBlob(blob1.get(), 20.0f, 64.0f, paint1);
38 canvas->drawTextBlob(blob1.get(), 20.0f, 144.0f, paint2);
39 canvas->drawTextBlob(blob2.get(), 20.0f, 224.0f, paint3);
40}
41} // END FIDDLE
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
sk_sp< SkTypeface > legacyMakeTypeface(const char familyName[], SkFontStyle style) const
Definition: SkFontMgr.cpp:150
Definition: SkFont.h:35
@ kAntiAlias
may have transparent pixels on glyph edges
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
static sk_sp< SkTextBlob > MakeFromString(const char *string, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
Definition: SkTextBlob.h:115
T * get() const
Definition: SkRefCnt.h:303
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32