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 | 9c1f1be | 2020-12-09 13:02:50 -0500 | [diff] [blame^] | 21 | SVG_ATTR(XmlSpace, SkSVGXmlSpace, SkSVGXmlSpace::kDefault) |
| 22 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 23 | protected: |
| 24 | explicit SkSVGTextContainer(SkSVGTag t) : INHERITED(t) {} |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 25 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 26 | private: |
| 27 | void appendChild(sk_sp<SkSVGNode>) final; |
Florin Malita | 9c1f1be | 2020-12-09 13:02:50 -0500 | [diff] [blame^] | 28 | bool onPrepareToRender(SkSVGRenderContext*) const final; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 29 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 30 | bool parseAndSetAttribute(const char*, const char*) override; |
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 | using INHERITED = SkSVGContainer; |
| 33 | }; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 34 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 35 | class SkSVGText final : public SkSVGTextContainer { |
| 36 | public: |
| 37 | static sk_sp<SkSVGText> Make() { return sk_sp<SkSVGText>(new SkSVGText()); } |
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 | private: |
| 40 | SkSVGText() : INHERITED(SkSVGTag::kText) {} |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 41 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 42 | void onRender(const SkSVGRenderContext&) const override; |
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 | using INHERITED = SkSVGTextContainer; |
| 45 | }; |
Florin Malita | 39fe8c8 | 2020-10-20 10:43:03 -0400 | [diff] [blame] | 46 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 47 | class SkSVGTSpan final : public SkSVGTextContainer { |
| 48 | public: |
| 49 | static sk_sp<SkSVGTSpan> Make() { return sk_sp<SkSVGTSpan>(new SkSVGTSpan()); } |
| 50 | |
| 51 | private: |
| 52 | SkSVGTSpan() : INHERITED(SkSVGTag::kTSpan) {} |
| 53 | |
| 54 | using INHERITED = SkSVGTextContainer; |
| 55 | }; |
| 56 | |
| 57 | class SkSVGTextLiteral final : public SkSVGNode { |
| 58 | public: |
| 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 | |
| 67 | private: |
| 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 Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | #endif // SkSVGText_DEFINED |