Skia
2D Graphics Library
SkottieProperty.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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 SkottieProperty_DEFINED
9 #define SkottieProperty_DEFINED
10 
11 #include "include/core/SkColor.h"
12 #include "include/core/SkMatrix.h"
13 #include "include/core/SkPaint.h"
14 #include "include/core/SkPoint.h"
15 #include "include/core/SkRect.h"
16 #include "include/core/SkRefCnt.h"
17 #include "include/core/SkSpan.h"
19 #include "include/utils/SkTextUtils.h"
21 
22 #include <functional>
23 #include <vector>
24 
25 class SkCanvas;
26 
27 namespace sksg {
28 
29 class Color;
30 class OpacityEffect;
31 
32 } // namespace sksg
33 
34 namespace skottie {
35 
37 using OpacityPropertyValue = float;
38 
39 enum class TextPaintOrder : uint8_t {
42 };
43 
44 // Optional callback invoked when drawing text layers.
45 // Allows clients to render custom text decorations.
46 class GlyphDecorator : public SkRefCnt {
47 public:
48  struct GlyphInfo {
49  SkRect fBounds; // visual glyph bounds
50  SkMatrix fMatrix; // glyph matrix
51  size_t fCluster; // cluster index in the original text string
52  float fAdvance; // horizontal glyph advance
53  };
54 
55  struct TextInfo {
56  SkSpan<const GlyphInfo> fGlyphs;
57  float fScale; // Additional font scale applied by auto-sizing.
58  };
59 
60  virtual void onDecorate(SkCanvas*, const TextInfo&) = 0;
61 };
62 
66  float fTextSize = 0,
67  fMinTextSize = 0, // when auto-sizing
68  fMaxTextSize = std::numeric_limits<float>::max(), // when auto-sizing
72  fAscent = 0;
73  size_t fMaxLines = 0; // when auto-sizing
74  SkTextUtils::Align fHAlign = SkTextUtils::kLeft_Align;
84  SkPaint::Join fStrokeJoin = SkPaint::Join::kMiter_Join;
85  bool fHasFill = false,
86  fHasStroke = false;
88  // The locale to be used for text shaping, in BCP47 form. This includes
89  // support for RFC6067 extensions, so one can e.g. select strict line
90  // breaking rules for certain scripts: ja-u-lb-strict.
91  // Pass an empty string to use the system locale.
93 
94  bool operator==(const TextPropertyValue& other) const;
95  bool operator!=(const TextPropertyValue& other) const;
96 };
97 
99  SkPoint fAnchorPoint,
101  SkVector fScale;
105 
106  bool operator==(const TransformPropertyValue& other) const;
107  bool operator!=(const TransformPropertyValue& other) const;
108 };
109 
110 namespace internal { class SceneGraphRevalidator; }
111 
116 template <typename ValueT, typename NodeT>
117 class SK_API PropertyHandle final {
118 public:
121  : fNode(std::move(node))
122  , fRevalidator(std::move(revalidator)) {}
124 
126 
127  ValueT get() const;
128  void set(const ValueT&);
129 
130 private:
131  const sk_sp<NodeT> fNode;
132  const sk_sp<internal::SceneGraphRevalidator> fRevalidator;
133 };
134 
135 namespace internal {
136 
137 class TextAdapter;
138 class TransformAdapter2D;
139 
140 } // namespace internal
141 
143  sksg::Color>;
147  internal::TextAdapter>;
149  internal::TransformAdapter2D>;
150 
159 class SK_API PropertyObserver : public SkRefCnt {
160 public:
161  enum class NodeType {COMPOSITION, LAYER, EFFECT, OTHER};
162 
163  template <typename T>
164  using LazyHandle = std::function<std::unique_ptr<T>()>;
165 
166  virtual void onColorProperty (const char node_name[],
168  virtual void onOpacityProperty (const char node_name[],
170  virtual void onTextProperty (const char node_name[],
172  virtual void onTransformProperty(const char node_name[],
174  virtual void onEnterNode(const char node_name[], NodeType node_type);
175  virtual void onLeavingNode(const char node_name[], NodeType node_type);
176 };
177 
178 } // namespace skottie
179 
180 #endif // SkottieProperty_DEFINED
Types, consts, functions, and macros for colors.
uint32_t SkColor
32-bit ARGB color value, unpremultiplied.
Definition: SkColor.h:37
constexpr SkColor SK_ColorTRANSPARENT
Represents fully transparent SkColor.
Definition: SkColor.h:99
float SkScalar
Definition: SkScalar.h:14
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
Join
Definition: SkPaint.h:358
Definition: SkRefCnt.h:119
Light weight class for managing strings.
Definition: SkString.h:118
Definition: SkottieProperty.h:46
virtual void onDecorate(SkCanvas *, const TextInfo &)=0
Property handles are adapters between user-facing AE model/values and the internal scene-graph repres...
Definition: SkottieProperty.h:117
PropertyHandle(sk_sp< NodeT > node, sk_sp< internal::SceneGraphRevalidator > revalidator)
Definition: SkottieProperty.h:120
void set(const ValueT &)
PropertyHandle(const PropertyHandle &)
PropertyHandle(sk_sp< NodeT >)
A PropertyObserver can be used to track and manipulate certain properties of "interesting" Lottie nod...
Definition: SkottieProperty.h:159
virtual void onTransformProperty(const char node_name[], const LazyHandle< TransformPropertyHandle > &)
NodeType
Definition: SkottieProperty.h:161
virtual void onEnterNode(const char node_name[], NodeType node_type)
virtual void onTextProperty(const char node_name[], const LazyHandle< TextPropertyHandle > &)
virtual void onOpacityProperty(const char node_name[], const LazyHandle< OpacityPropertyHandle > &)
std::function< std::unique_ptr< T >()> LazyHandle
Definition: SkottieProperty.h:164
virtual void onLeavingNode(const char node_name[], NodeType node_type)
virtual void onColorProperty(const char node_name[], const LazyHandle< ColorPropertyHandle > &)
Direction
Definition: TextShaper.h:128
ResizePolicy
Definition: TextShaper.h:109
VAlign
Definition: TextShaper.h:82
Capitalization
Definition: TextShaper.h:130
LinebreakPolicy
Definition: TextShaper.h:120
Concrete Paint node, wrapping an SkColor.
Definition: SkSGPaint.h:64
Concrete Effect node, applying opacity to its descendants.
Definition: SkSGOpacityEffect.h:19
SK_API sk_sp< SkShader > Color(SkColor)
Definition: ExternalLayer.h:16
float OpacityPropertyValue
Definition: SkottieProperty.h:37
TextPaintOrder
Definition: SkottieProperty.h:39
SkColor ColorPropertyValue
Definition: SkottieProperty.h:36
Definition: Skottie.h:30
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582
static constexpr SkRect MakeEmpty()
Returns constructed SkRect set to (0, 0, 0, 0).
Definition: SkRect.h:595
Definition: SkottieProperty.h:48
float fAdvance
Definition: SkottieProperty.h:52
size_t fCluster
Definition: SkottieProperty.h:51
SkRect fBounds
Definition: SkottieProperty.h:49
SkMatrix fMatrix
Definition: SkottieProperty.h:50
Definition: SkottieProperty.h:55
float fScale
Definition: SkottieProperty.h:57
SkSpan< const GlyphInfo > fGlyphs
Definition: SkottieProperty.h:56
Definition: SkottieProperty.h:63
float fStrokeWidth
Definition: SkottieProperty.h:69
float fMaxTextSize
Definition: SkottieProperty.h:68
sk_sp< SkTypeface > fTypeface
Definition: SkottieProperty.h:64
SkPaint::Join fStrokeJoin
Definition: SkottieProperty.h:84
Shaper::Direction fDirection
Definition: SkottieProperty.h:78
SkColor fFillColor
Definition: SkottieProperty.h:81
float fLineHeight
Definition: SkottieProperty.h:70
bool fHasFill
Definition: SkottieProperty.h:85
bool operator!=(const TextPropertyValue &other) const
float fTextSize
Definition: SkottieProperty.h:66
float fMinTextSize
Definition: SkottieProperty.h:67
size_t fMaxLines
Definition: SkottieProperty.h:73
bool operator==(const TextPropertyValue &other) const
Shaper::LinebreakPolicy fLineBreak
Definition: SkottieProperty.h:77
SkRect fBox
Definition: SkottieProperty.h:80
SkString fLocale
Definition: SkottieProperty.h:92
sk_sp< GlyphDecorator > fDecorator
Definition: SkottieProperty.h:87
TextPaintOrder fPaintOrder
Definition: SkottieProperty.h:83
float fLineShift
Definition: SkottieProperty.h:71
Shaper::Capitalization fCapitalization
Definition: SkottieProperty.h:79
float fAscent
Definition: SkottieProperty.h:72
Shaper::VAlign fVAlign
Definition: SkottieProperty.h:75
SkColor fStrokeColor
Definition: SkottieProperty.h:82
bool fHasStroke
Definition: SkottieProperty.h:86
SkString fText
Definition: SkottieProperty.h:65
Shaper::ResizePolicy fResize
Definition: SkottieProperty.h:76
SkTextUtils::Align fHAlign
Definition: SkottieProperty.h:74
Definition: SkottieProperty.h:98
SkPoint fPosition
Definition: SkottieProperty.h:100
SkVector fScale
Definition: SkottieProperty.h:101
bool operator!=(const TransformPropertyValue &other) const
SkScalar fSkew
Definition: SkottieProperty.h:103
bool operator==(const TransformPropertyValue &other) const
SkScalar fSkewAxis
Definition: SkottieProperty.h:104
SkPoint fAnchorPoint
Definition: SkottieProperty.h:99
SkScalar fRotation
Definition: SkottieProperty.h:102