blob: ae284f671b630e5de5b33da85e00aaa18833527a [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 Malita512ff752020-12-06 11:50:52 -050011#include "modules/svg/include/SkSVGContainer.h"
Florin Malitab3418102020-10-15 18:10:29 -040012#include "modules/svg/include/SkSVGTypes.h"
13
Florin Malita512ff752020-12-06 11:50:52 -050014// Base class for nestable text containers (<text>, <tspan>, etc).
15class SkSVGTextContainer : public SkSVGContainer {
16public:
17 // TODO: these should be arrays
18 SVG_ATTR(X, SkSVGLength, SkSVGLength(0))
19 SVG_ATTR(Y, SkSVGLength, SkSVGLength(0))
Florin Malitab3418102020-10-15 18:10:29 -040020
Florin Malita512ff752020-12-06 11:50:52 -050021protected:
22 explicit SkSVGTextContainer(SkSVGTag t) : INHERITED(t) {}
Florin Malitab3418102020-10-15 18:10:29 -040023
Florin Malita512ff752020-12-06 11:50:52 -050024private:
25 void appendChild(sk_sp<SkSVGNode>) final;
Florin Malitab3418102020-10-15 18:10:29 -040026
Florin Malita512ff752020-12-06 11:50:52 -050027 bool parseAndSetAttribute(const char*, const char*) override;
Florin Malitab3418102020-10-15 18:10:29 -040028
Florin Malita512ff752020-12-06 11:50:52 -050029 using INHERITED = SkSVGContainer;
30};
Florin Malitab3418102020-10-15 18:10:29 -040031
Florin Malita512ff752020-12-06 11:50:52 -050032class SkSVGText final : public SkSVGTextContainer {
33public:
34 static sk_sp<SkSVGText> Make() { return sk_sp<SkSVGText>(new SkSVGText()); }
Florin Malitab3418102020-10-15 18:10:29 -040035
Florin Malita512ff752020-12-06 11:50:52 -050036private:
37 SkSVGText() : INHERITED(SkSVGTag::kText) {}
Florin Malitab3418102020-10-15 18:10:29 -040038
Florin Malita512ff752020-12-06 11:50:52 -050039 void onRender(const SkSVGRenderContext&) const override;
Florin Malita39fe8c82020-10-20 10:43:03 -040040
Florin Malita512ff752020-12-06 11:50:52 -050041 using INHERITED = SkSVGTextContainer;
42};
Florin Malita39fe8c82020-10-20 10:43:03 -040043
Florin Malita512ff752020-12-06 11:50:52 -050044class SkSVGTSpan final : public SkSVGTextContainer {
45public:
46 static sk_sp<SkSVGTSpan> Make() { return sk_sp<SkSVGTSpan>(new SkSVGTSpan()); }
47
48private:
49 SkSVGTSpan() : INHERITED(SkSVGTag::kTSpan) {}
50
51 using INHERITED = SkSVGTextContainer;
52};
53
54class SkSVGTextLiteral final : public SkSVGNode {
55public:
56 ~SkSVGTextLiteral() override;
57
58 static sk_sp<SkSVGTextLiteral> Make() {
59 return sk_sp<SkSVGTextLiteral>(new SkSVGTextLiteral());
60 }
61
62 SVG_ATTR(Text, SkSVGStringType, SkSVGStringType())
63
64private:
65 SkSVGTextLiteral() : INHERITED(SkSVGTag::kTextLiteral) {}
66
67 void onRender(const SkSVGRenderContext&) const override;
68 SkPath onAsPath(const SkSVGRenderContext&) const override;
69
70 void appendChild(sk_sp<SkSVGNode>) override {}
71
72 using INHERITED = SkSVGNode;
Florin Malitab3418102020-10-15 18:10:29 -040073};
74
75#endif // SkSVGText_DEFINED