blob: 037444d81fc053f4fa3fa3a8819047e5ae878c7a [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 Malita9c1f1be2020-12-09 13:02:50 -050021 SVG_ATTR(XmlSpace, SkSVGXmlSpace, SkSVGXmlSpace::kDefault)
22
Florin Malita512ff752020-12-06 11:50:52 -050023protected:
24 explicit SkSVGTextContainer(SkSVGTag t) : INHERITED(t) {}
Florin Malitab3418102020-10-15 18:10:29 -040025
Florin Malita512ff752020-12-06 11:50:52 -050026private:
27 void appendChild(sk_sp<SkSVGNode>) final;
Florin Malita9c1f1be2020-12-09 13:02:50 -050028 bool onPrepareToRender(SkSVGRenderContext*) const final;
Florin Malitab3418102020-10-15 18:10:29 -040029
Florin Malita512ff752020-12-06 11:50:52 -050030 bool parseAndSetAttribute(const char*, const char*) override;
Florin Malitab3418102020-10-15 18:10:29 -040031
Florin Malita512ff752020-12-06 11:50:52 -050032 using INHERITED = SkSVGContainer;
33};
Florin Malitab3418102020-10-15 18:10:29 -040034
Florin Malita512ff752020-12-06 11:50:52 -050035class SkSVGText final : public SkSVGTextContainer {
36public:
37 static sk_sp<SkSVGText> Make() { return sk_sp<SkSVGText>(new SkSVGText()); }
Florin Malitab3418102020-10-15 18:10:29 -040038
Florin Malita512ff752020-12-06 11:50:52 -050039private:
40 SkSVGText() : INHERITED(SkSVGTag::kText) {}
Florin Malitab3418102020-10-15 18:10:29 -040041
Florin Malita512ff752020-12-06 11:50:52 -050042 void onRender(const SkSVGRenderContext&) const override;
Florin Malita39fe8c82020-10-20 10:43:03 -040043
Florin Malita512ff752020-12-06 11:50:52 -050044 using INHERITED = SkSVGTextContainer;
45};
Florin Malita39fe8c82020-10-20 10:43:03 -040046
Florin Malita512ff752020-12-06 11:50:52 -050047class SkSVGTSpan final : public SkSVGTextContainer {
48public:
49 static sk_sp<SkSVGTSpan> Make() { return sk_sp<SkSVGTSpan>(new SkSVGTSpan()); }
50
51private:
52 SkSVGTSpan() : INHERITED(SkSVGTag::kTSpan) {}
53
54 using INHERITED = SkSVGTextContainer;
55};
56
57class SkSVGTextLiteral final : public SkSVGNode {
58public:
59 ~SkSVGTextLiteral() override;
60
61 static sk_sp<SkSVGTextLiteral> Make() {
62 return sk_sp<SkSVGTextLiteral>(new SkSVGTextLiteral());
63 }
64
65 SVG_ATTR(Text, SkSVGStringType, SkSVGStringType())
66
67private:
68 SkSVGTextLiteral() : INHERITED(SkSVGTag::kTextLiteral) {}
69
70 void onRender(const SkSVGRenderContext&) const override;
71 SkPath onAsPath(const SkSVGRenderContext&) const override;
72
73 void appendChild(sk_sp<SkSVGNode>) override {}
74
75 using INHERITED = SkSVGNode;
Florin Malitab3418102020-10-15 18:10:29 -040076};
77
78#endif // SkSVGText_DEFINED