Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
skottie::internal::CustomFont::Builder Class Referencefinal

#include <Font.h>

Inheritance diagram for skottie::internal::CustomFont::Builder:
SkNoncopyable

Public Member Functions

bool parseGlyph (const AnimationBuilder *, const skjson::ObjectValue &)
 
std::unique_ptr< CustomFontdetach ()
 

Detailed Description

Definition at line 39 of file Font.h.

Member Function Documentation

◆ detach()

std::unique_ptr< CustomFont > skottie::internal::CustomFont::Builder::detach ( )

Definition at line 200 of file Font.cpp.

200 {
201 return std::unique_ptr<CustomFont>(new CustomFont(std::move(fGlyphComps),
202 fCustomBuilder.detach()));
203}
sk_sp< SkTypeface > detach()

◆ parseGlyph()

bool skottie::internal::CustomFont::Builder::parseGlyph ( const AnimationBuilder abuilder,
const skjson::ObjectValue jchar 
)

Definition at line 26 of file Font.cpp.

27 {
28 // Glyph encoding:
29 // {
30 // "ch": "t",
31 // "data": <glyph data>, // Glyph path or composition data
32 // "size": 50, // apparently ignored
33 // "w": 32.67, // width/advance (1/100 units)
34 // "t": 1 // Marker for composition glyphs only.
35 // }
36 const skjson::StringValue* jch = jchar["ch"];
37 const skjson::ObjectValue* jdata = jchar["data"];
38 if (!jch || !jdata) {
39 return false;
40 }
41
42 const auto* ch_ptr = jch->begin();
43 const auto ch_len = jch->size();
44 if (SkUTF::CountUTF8(ch_ptr, ch_len) != 1) {
45 return false;
46 }
47
48 const auto uni = SkUTF::NextUTF8(&ch_ptr, ch_ptr + ch_len);
49 SkASSERT(uni != -1);
50 if (!SkTFitsIn<SkGlyphID>(uni)) {
51 // Custom font keys are SkGlyphIDs. We could implement a remapping scheme if needed,
52 // but for now direct mapping seems to work well enough.
53 return false;
54 }
55 const auto glyph_id = SkTo<SkGlyphID>(uni);
56
57 // Normalize the path and advance for 1pt.
58 static constexpr float kPtScale = 0.01f;
59 const auto advance = ParseDefault(jchar["w"], 0.0f) * kPtScale;
60
61 // Custom glyphs are either compositions...
62 SkSize glyph_size;
63 if (auto comp_node = ParseGlyphComp(abuilder, *jdata, &glyph_size)) {
64 // With glyph comps, we use the SkCustomTypeface only for shaping -- not for rendering.
65 // We still need accurate glyph bounds though, for visual alignment.
66
67 // TODO: This assumes the glyph origin is always in the lower-left corner.
68 // Lottie may need to add an origin property, to allow designers full control over
69 // glyph comp positioning.
70 const auto glyph_bounds = SkRect::MakeLTRB(0, -glyph_size.fHeight, glyph_size.fWidth, 0);
71 fCustomBuilder.setGlyph(glyph_id, advance, SkPath::Rect(glyph_bounds));
72
73 // Rendering is handled explicitly, post shaping,
74 // based on info tracked in this GlyphCompMap.
75 fGlyphComps.set(glyph_id, std::move(comp_node));
76
77 return true;
78 }
79
80 // ... or paths.
82 if (!ParseGlyphPath(abuilder, *jdata, &path)) {
83 return false;
84 }
85
86 path.transform(SkMatrix::Scale(kPtScale, kPtScale));
87
88 fCustomBuilder.setGlyph(glyph_id, advance, path);
89
90 return true;
91}
#define SkASSERT(cond)
Definition SkAssert.h:116
void setGlyph(SkGlyphID, float advance, const SkPath &)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
Definition SkPath.cpp:3518
V * set(K key, V val)
Definition SkTHash.h:472
const char * begin() const
Definition SkJSON.h:315
size_t size() const
Definition SkJSON.h:300
SK_SPI SkUnichar NextUTF8(const char **ptr, const char *end)
Definition SkUTF.cpp:118
SK_SPI int CountUTF8(const char *utf8, size_t byteLength)
Definition SkUTF.cpp:47
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
T ParseDefault(const skjson::Value &v, const T &defaultValue)
Definition SkottieJson.h:23
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646
SkScalar fHeight
Definition SkSize.h:54
SkScalar fWidth
Definition SkSize.h:53

The documentation for this class was generated from the following files: