blob: 4fbdc1cd54fff062f4f231dc639cd6b625769427 [file] [log] [blame]
Florin Malitab3418102020-10-15 18:10:29 -04001/*
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
Florin Malitaadc68892020-12-15 10:52:26 -050011#include <vector>
12
13#include "modules/svg/include/SkSVGTransformableNode.h"
Florin Malitab3418102020-10-15 18:10:29 -040014#include "modules/svg/include/SkSVGTypes.h"
15
Florin Malitaadc68892020-12-15 10:52:26 -050016class SkSVGTextContext;
17
18// Base class for text-rendering nodes.
19class SkSVGTextFragment : public SkSVGTransformableNode {
20public:
21 void renderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const;
22
23protected:
24 explicit SkSVGTextFragment(SkSVGTag t) : INHERITED(t) {}
25
26 virtual void onRenderText(const SkSVGRenderContext&, SkSVGTextContext*,
27 SkSVGXmlSpace) const = 0;
28
29private:
30 SkPath onAsPath(const SkSVGRenderContext&) const final;
31
32 using INHERITED = SkSVGTransformableNode;
33};
34
Florin Malita512ff752020-12-06 11:50:52 -050035// Base class for nestable text containers (<text>, <tspan>, etc).
Florin Malitaadc68892020-12-15 10:52:26 -050036class SkSVGTextContainer : public SkSVGTextFragment {
Florin Malita512ff752020-12-06 11:50:52 -050037public:
Florin Malitadec78022020-12-17 16:36:54 -050038 SVG_ATTR(X, std::vector<SkSVGLength>, {})
39 SVG_ATTR(Y, std::vector<SkSVGLength>, {})
Florin Malita735ac972020-12-22 11:23:32 -050040 SVG_ATTR(Dx, std::vector<SkSVGLength>, {})
41 SVG_ATTR(Dy, std::vector<SkSVGLength>, {})
Florin Malita2d059fc2021-01-05 11:53:15 -050042 SVG_ATTR(Rotate, std::vector<SkSVGNumberType>, {})
Florin Malitab3418102020-10-15 18:10:29 -040043
Florin Malita9c1f1be2020-12-09 13:02:50 -050044 SVG_ATTR(XmlSpace, SkSVGXmlSpace, SkSVGXmlSpace::kDefault)
45
Florin Malitadec78022020-12-17 16:36:54 -050046 void appendChild(sk_sp<SkSVGNode>) final;
47
Florin Malita512ff752020-12-06 11:50:52 -050048protected:
49 explicit SkSVGTextContainer(SkSVGTag t) : INHERITED(t) {}
Florin Malitab3418102020-10-15 18:10:29 -040050
Florin Malita512ff752020-12-06 11:50:52 -050051private:
Florin Malitaadc68892020-12-15 10:52:26 -050052 void onRender(const SkSVGRenderContext&) const final;
53 void onRenderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const final;
Florin Malitab3418102020-10-15 18:10:29 -040054
Florin Malita512ff752020-12-06 11:50:52 -050055 bool parseAndSetAttribute(const char*, const char*) override;
Florin Malitab3418102020-10-15 18:10:29 -040056
Florin Malitaadc68892020-12-15 10:52:26 -050057 std::vector<sk_sp<SkSVGTextFragment>> fChildren;
58
59 using INHERITED = SkSVGTextFragment;
Florin Malita512ff752020-12-06 11:50:52 -050060};
Florin Malitab3418102020-10-15 18:10:29 -040061
Florin Malita512ff752020-12-06 11:50:52 -050062class SkSVGText final : public SkSVGTextContainer {
63public:
64 static sk_sp<SkSVGText> Make() { return sk_sp<SkSVGText>(new SkSVGText()); }
Florin Malitab3418102020-10-15 18:10:29 -040065
Florin Malita512ff752020-12-06 11:50:52 -050066private:
67 SkSVGText() : INHERITED(SkSVGTag::kText) {}
Florin Malitab3418102020-10-15 18:10:29 -040068
Florin Malita512ff752020-12-06 11:50:52 -050069 using INHERITED = SkSVGTextContainer;
70};
Florin Malita39fe8c82020-10-20 10:43:03 -040071
Florin Malita512ff752020-12-06 11:50:52 -050072class SkSVGTSpan final : public SkSVGTextContainer {
73public:
74 static sk_sp<SkSVGTSpan> Make() { return sk_sp<SkSVGTSpan>(new SkSVGTSpan()); }
75
76private:
77 SkSVGTSpan() : INHERITED(SkSVGTag::kTSpan) {}
78
79 using INHERITED = SkSVGTextContainer;
80};
81
Florin Malitaadc68892020-12-15 10:52:26 -050082class SkSVGTextLiteral final : public SkSVGTextFragment {
Florin Malita512ff752020-12-06 11:50:52 -050083public:
Florin Malita512ff752020-12-06 11:50:52 -050084 static sk_sp<SkSVGTextLiteral> Make() {
85 return sk_sp<SkSVGTextLiteral>(new SkSVGTextLiteral());
86 }
87
88 SVG_ATTR(Text, SkSVGStringType, SkSVGStringType())
89
90private:
91 SkSVGTextLiteral() : INHERITED(SkSVGTag::kTextLiteral) {}
92
Florin Malitaadc68892020-12-15 10:52:26 -050093 void onRender(const SkSVGRenderContext&) const override {}
94 void onRenderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override;
Florin Malita512ff752020-12-06 11:50:52 -050095
96 void appendChild(sk_sp<SkSVGNode>) override {}
97
Florin Malitaadc68892020-12-15 10:52:26 -050098 using INHERITED = SkSVGTextFragment;
Florin Malitab3418102020-10-15 18:10:29 -040099};
100
101#endif // SkSVGText_DEFINED