/src/skia/modules/svg/include/SkSVGText.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
13 | | #include "modules/svg/include/SkSVGTransformableNode.h" |
14 | | #include "modules/svg/include/SkSVGTypes.h" |
15 | | |
16 | | class SkSVGTextContext; |
17 | | |
18 | | // Base class for text-rendering nodes. |
19 | | class SkSVGTextFragment : public SkSVGTransformableNode { |
20 | | public: |
21 | | void renderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const; |
22 | | |
23 | | protected: |
24 | 135k | 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 | 70.4k | 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). |
38 | | class SkSVGTextContainer : public SkSVGTextFragment { |
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 | | |
46 | | SVG_ATTR(XmlSpace, SkSVGXmlSpace, SkSVGXmlSpace::kDefault) |
47 | | |
48 | | void appendChild(sk_sp<SkSVGNode>) final; |
49 | | |
50 | | protected: |
51 | 21.3k | explicit SkSVGTextContainer(SkSVGTag t) : INHERITED(t) {} |
52 | | |
53 | | void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override; |
54 | | |
55 | | bool parseAndSetAttribute(const char*, const char*) override; |
56 | | |
57 | | private: |
58 | | std::vector<sk_sp<SkSVGTextFragment>> fChildren; |
59 | | |
60 | | using INHERITED = SkSVGTextFragment; |
61 | | }; |
62 | | |
63 | | class SkSVGText final : public SkSVGTextContainer { |
64 | | public: |
65 | 19.2k | static sk_sp<SkSVGText> Make() { return sk_sp<SkSVGText>(new SkSVGText()); } |
66 | | |
67 | | private: |
68 | 19.2k | 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 | 2.02k | static sk_sp<SkSVGTSpan> Make() { return sk_sp<SkSVGTSpan>(new SkSVGTSpan()); } |
81 | | |
82 | | private: |
83 | 2.02k | SkSVGTSpan() : INHERITED(SkSVGTag::kTSpan) {} |
84 | | |
85 | | using INHERITED = SkSVGTextContainer; |
86 | | }; |
87 | | |
88 | | class SkSVGTextLiteral final : public SkSVGTextFragment { |
89 | | public: |
90 | 114k | static sk_sp<SkSVGTextLiteral> Make() { |
91 | 114k | return sk_sp<SkSVGTextLiteral>(new SkSVGTextLiteral()); |
92 | 114k | } |
93 | | |
94 | | SVG_ATTR(Text, SkSVGStringType, SkSVGStringType()) |
95 | | |
96 | | private: |
97 | 114k | SkSVGTextLiteral() : INHERITED(SkSVGTag::kTextLiteral) {} |
98 | | |
99 | | void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override; |
100 | | |
101 | 0 | void appendChild(sk_sp<SkSVGNode>) override {} |
102 | | |
103 | | using INHERITED = SkSVGTextFragment; |
104 | | }; |
105 | | |
106 | | class SkSVGTextPath final : public SkSVGTextContainer { |
107 | | public: |
108 | 0 | static sk_sp<SkSVGTextPath> Make() { return sk_sp<SkSVGTextPath>(new SkSVGTextPath()); } |
109 | | |
110 | | SVG_ATTR(Href , SkSVGIRI , {} ) |
111 | | SVG_ATTR(StartOffset, SkSVGLength, SkSVGLength(0)) |
112 | | |
113 | | private: |
114 | 0 | 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 |