Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TextAdapter.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkottieTextAdapter_DEFINED
9#define SkottieTextAdapter_DEFINED
10
11#include "include/core/SkM44.h"
23
24#include <cstdint>
25#include <memory>
26#include <vector>
27
28class SkFontMgr;
29
30namespace skjson {
31class ObjectValue;
32}
33namespace skottie {
34class Logger;
35}
36namespace sksg {
37class Group;
38class RenderNode;
39} // namespace sksg
40
41namespace SkShapers { class Factory; }
42
43namespace skottie {
44namespace internal {
45class AnimationBuilder;
46
48public:
50 const AnimationBuilder*,
55
56 ~TextAdapter() override;
57
58 const sk_sp<sksg::Group>& node() const { return fRoot; }
59
60 const TextValue& getText() const { return fText.fCurrentValue; }
61 void setText(const TextValue&);
62
63protected:
64 void onSync() override;
65
66private:
67 class GlyphDecoratorNode;
68
69 enum class AnchorPointGrouping : uint8_t {
70 kCharacter,
71 kWord,
72 kLine,
73 kAll,
74 };
75
76 TextAdapter(sk_sp<SkFontMgr>,
80 AnchorPointGrouping);
81
82 struct FragmentRec {
83 SkPoint fOrigin; // fragment position
84
85 const Shaper::ShapedGlyphs* fGlyphs = nullptr;
86 sk_sp<sksg::Matrix<SkM44>> fMatrixNode;
87 sk_sp<sksg::Color> fFillColorNode,
88 fStrokeColorNode;
90
91 float fAdvance, // used for transform anchor point calculations
92 fAscent; // ^
93 };
94
95 void reshape();
96 void addFragment(Shaper::Fragment&, sksg::Group* container);
97 void buildDomainMaps(const Shaper::Result&);
98 std::vector<sk_sp<sksg::RenderNode>> buildGlyphCompNodes(Shaper::ShapedGlyphs&) const;
99
100 void pushPropsToFragment(const TextAnimator::ResolvedProps&, const FragmentRec&,
101 const SkV2& frag_offset, const SkV2& grouping_alignment,
102 const TextAnimator::DomainSpan*) const;
103
104 SkV2 fragmentAnchorPoint(const FragmentRec&, const SkV2&,
105 const TextAnimator::DomainSpan*) const;
106 uint32_t shaperFlags() const;
107
108 SkM44 fragmentMatrix(const TextAnimator::ResolvedProps&, const FragmentRec&, const SkV2&) const;
109
110 const sk_sp<sksg::Group> fRoot;
111 const sk_sp<SkFontMgr> fFontMgr;
112 const sk_sp<CustomFont::GlyphCompMapper> fCustomGlyphMapper;
113 sk_sp<Logger> fLogger;
114 sk_sp<SkShapers::Factory> fShapingFactory;
115 const AnchorPointGrouping fAnchorPointGrouping;
116
117 std::vector<sk_sp<TextAnimator>> fAnimators;
118 std::vector<FragmentRec> fFragments;
119 TextAnimator::DomainMaps fMaps;
120
121 // Helps detect external value changes.
122 struct TextValueTracker {
123 TextValue fCurrentValue;
124
125 bool hasChanged() const {
126 if (fCurrentValue != fPrevValue) {
127 fPrevValue = fCurrentValue;
128 return true;
129 }
130 return false;
131 }
132
133 const TextValue* operator->() const { return &fCurrentValue; }
134
135 private:
136 mutable TextValue fPrevValue;
137 };
138
139 TextValueTracker fText;
140 Vec2Value fGroupingAlignment = {0,0};
141 float fTextShapingScale = 1; // size adjustment from auto-scaling
142
143 // Optional text path.
144 struct PathInfo;
145 std::unique_ptr<PathInfo> fPathInfo;
146
147 bool fHasBlurAnimator : 1,
148 fRequiresAnchorPoint : 1,
149 fRequiresLineAdjustments : 1;
150};
151
152} // namespace internal
153} // namespace skottie
154
155#endif // SkottieTextAdapter_DEFINED
@ kLine
SkPath::RawIter returns 2 points.
Definition SkM44.h:150
const TextValue & getText() const
Definition TextAdapter.h:60
static sk_sp< TextAdapter > Make(const skjson::ObjectValue &, const AnimationBuilder *, sk_sp< SkFontMgr >, sk_sp< CustomFont::GlyphCompMapper >, sk_sp< Logger >, sk_sp<::SkShapers::Factory >)
const sk_sp< sksg::Group > & node() const
Definition TextAdapter.h:58
void setText(const TextValue &)
SKSHAPER_API sk_sp< Factory > Factory()
TextPropertyValue TextValue
Definition TextValue.h:16
SkV2 Vec2Value
Definition Skottie.h:32
Definition SkM44.h:19