Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 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 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 11 | #include "modules/svg/include/SkSVGContainer.h" |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 12 | #include "modules/svg/include/SkSVGTypes.h" |
| 13 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 14 | // Base class for nestable text containers (<text>, <tspan>, etc). |
| 15 | class SkSVGTextContainer : public SkSVGContainer { |
| 16 | public: |
| 17 | // TODO: these should be arrays |
| 18 | SVG_ATTR(X, SkSVGLength, SkSVGLength(0)) |
| 19 | SVG_ATTR(Y, SkSVGLength, SkSVGLength(0)) |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 20 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 21 | protected: |
| 22 | explicit SkSVGTextContainer(SkSVGTag t) : INHERITED(t) {} |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 23 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 24 | private: |
| 25 | void appendChild(sk_sp<SkSVGNode>) final; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 26 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 27 | bool parseAndSetAttribute(const char*, const char*) override; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 28 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 29 | using INHERITED = SkSVGContainer; |
| 30 | }; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 31 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 32 | class SkSVGText final : public SkSVGTextContainer { |
| 33 | public: |
| 34 | static sk_sp<SkSVGText> Make() { return sk_sp<SkSVGText>(new SkSVGText()); } |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 35 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 36 | private: |
| 37 | SkSVGText() : INHERITED(SkSVGTag::kText) {} |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 38 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 39 | void onRender(const SkSVGRenderContext&) const override; |
Florin Malita | 39fe8c8 | 2020-10-20 10:43:03 -0400 | [diff] [blame] | 40 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 41 | using INHERITED = SkSVGTextContainer; |
| 42 | }; |
Florin Malita | 39fe8c8 | 2020-10-20 10:43:03 -0400 | [diff] [blame] | 43 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 44 | class SkSVGTSpan final : public SkSVGTextContainer { |
| 45 | public: |
| 46 | static sk_sp<SkSVGTSpan> Make() { return sk_sp<SkSVGTSpan>(new SkSVGTSpan()); } |
| 47 | |
| 48 | private: |
| 49 | SkSVGTSpan() : INHERITED(SkSVGTag::kTSpan) {} |
| 50 | |
| 51 | using INHERITED = SkSVGTextContainer; |
| 52 | }; |
| 53 | |
| 54 | class SkSVGTextLiteral final : public SkSVGNode { |
| 55 | public: |
| 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 | |
| 64 | private: |
| 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 Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | #endif // SkSVGText_DEFINED |