Skia
2D Graphics Library
SkSVGText.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 SkSVGText_DEFINED
9 #define SkSVGText_DEFINED
10 
11 #include <vector>
12 
15 
16 class SK_API SkSVGTextContext;
17 
18 // Base class for text-rendering nodes.
20 public:
22 
23 protected:
24  explicit SkSVGTextFragment(SkSVGTag t) : INHERITED(t) {}
25 
26  virtual void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const = 0;
27 
28  // Text nodes other than the root <text> element are not rendered directly.
29  void onRender(const SkSVGRenderContext&) const override {}
30 
31 private:
32  SkPath onAsPath(const SkSVGRenderContext&) const override;
33 
34  using INHERITED = SkSVGTransformableNode;
35 };
36 
37 // Base class for nestable text containers (<text>, <tspan>, etc).
39 public:
40  SVG_ATTR(X, std::vector<SkSVGLength>, {})
41  SVG_ATTR(Y, std::vector<SkSVGLength>, {})
42  SVG_ATTR(Dx, std::vector<SkSVGLength>, {})
43  SVG_ATTR(Dy, std::vector<SkSVGLength>, {})
44  SVG_ATTR(Rotate, std::vector<SkSVGNumberType>, {})
45 
47 
48  void appendChild(sk_sp<SkSVGNode>) final;
49 
50 protected:
52 
54 
55  bool parseAndSetAttribute(const char*, const char*) override;
56 
57 private:
58  std::vector<sk_sp<SkSVGTextFragment>> fChildren;
59 
61 };
62 
63 class SkSVGText final : public SkSVGTextContainer {
64 public:
65  static sk_sp<SkSVGText> Make() { return sk_sp<SkSVGText>(new SkSVGText()); }
66 
67 private:
68  SkSVGText() : INHERITED(SkSVGTag::kText) {}
69 
70  void onRender(const SkSVGRenderContext&) const override;
71 
72  SkRect onObjectBoundingBox(const SkSVGRenderContext&) const override;
73  SkPath onAsPath(const SkSVGRenderContext&) const override;
74 
75  using INHERITED = SkSVGTextContainer;
76 };
77 
78 class SkSVGTSpan final : public SkSVGTextContainer {
79 public:
80  static sk_sp<SkSVGTSpan> Make() { return sk_sp<SkSVGTSpan>(new SkSVGTSpan()); }
81 
82 private:
83  SkSVGTSpan() : INHERITED(SkSVGTag::kTSpan) {}
84 
85  using INHERITED = SkSVGTextContainer;
86 };
87 
88 class SkSVGTextLiteral final : public SkSVGTextFragment {
89 public:
92  }
93 
95 
96 private:
97  SkSVGTextLiteral() : INHERITED(SkSVGTag::kTextLiteral) {}
98 
99  void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override;
100 
101  void appendChild(sk_sp<SkSVGNode>) override {}
102 
103  using INHERITED = SkSVGTextFragment;
104 };
105 
106 class SkSVGTextPath final : public SkSVGTextContainer {
107 public:
109 
110  SVG_ATTR(Href , SkSVGIRI , {} )
111  SVG_ATTR(StartOffset, SkSVGLength, SkSVGLength(0))
112 
113 private:
114  SkSVGTextPath() : INHERITED(SkSVGTag::kTextPath) {}
115 
116  void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override;
117  bool parseAndSetAttribute(const char*, const char*) override;
118 
119  using INHERITED = SkSVGTextContainer;
120 };
121 
122 #endif // SkSVGText_DEFINED
SkSVGTag
Definition: SkSVGNode.h:23
#define SVG_ATTR(attr_name, attr_type, attr_default)
Definition: SkSVGNode.h:203
class SK_API SkSVGTextContext
Definition: SkSVGText.h:16
SkSVGXmlSpace
Definition: SkSVGTypes.h:714
SkString SkSVGStringType
Definition: SkSVGTypes.h:28
SkPath contain geometry.
Definition: SkPath.h:58
Definition: SkRefCnt.h:119
Definition: SkSVGTypes.h:152
Definition: SkSVGTypes.h:116
Definition: SkSVGNode.h:95
Definition: SkSVGRenderContext.h:61
Definition: SkSVGText.h:78
static sk_sp< SkSVGTSpan > Make()
Definition: SkSVGText.h:80
Definition: SkSVGText.h:38
void onShapeText(const SkSVGRenderContext &, SkSVGTextContext *, SkSVGXmlSpace) const override
void appendChild(sk_sp< SkSVGNode >) final
bool parseAndSetAttribute(const char *, const char *) override
SkSVGTextContainer(SkSVGTag t)
Definition: SkSVGText.h:51
Definition: SkSVGText.h:19
void renderText(const SkSVGRenderContext &, SkSVGTextContext *, SkSVGXmlSpace) const
SkSVGTextFragment(SkSVGTag t)
Definition: SkSVGText.h:24
void onRender(const SkSVGRenderContext &) const override
Definition: SkSVGText.h:29
virtual void onShapeText(const SkSVGRenderContext &, SkSVGTextContext *, SkSVGXmlSpace) const =0
Definition: SkSVGText.h:88
static sk_sp< SkSVGTextLiteral > Make()
Definition: SkSVGText.h:90
Definition: SkSVGText.h:106
static sk_sp< SkSVGTextPath > Make()
Definition: SkSVGText.h:108
Definition: SkSVGText.h:63
static sk_sp< SkSVGText > Make()
Definition: SkSVGText.h:65
Definition: SkSVGTransformableNode.h:14
SkSVGTransformableNode(SkSVGTag)
Light weight class for managing strings.
Definition: SkString.h:118
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582