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 | adc6889 | 2020-12-15 10:52:26 -0500 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
| 13 | #include "modules/svg/include/SkSVGTransformableNode.h" |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 14 | #include "modules/svg/include/SkSVGTypes.h" |
| 15 | |
Florin Malita | adc6889 | 2020-12-15 10:52:26 -0500 | [diff] [blame] | 16 | class SkSVGTextContext; |
| 17 | |
| 18 | // Base class for text-rendering nodes. |
| 19 | class SkSVGTextFragment : public SkSVGTransformableNode { |
| 20 | public: |
| 21 | void renderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const; |
| 22 | |
| 23 | protected: |
| 24 | explicit SkSVGTextFragment(SkSVGTag t) : INHERITED(t) {} |
| 25 | |
| 26 | virtual void onRenderText(const SkSVGRenderContext&, SkSVGTextContext*, |
| 27 | SkSVGXmlSpace) const = 0; |
| 28 | |
| 29 | private: |
| 30 | SkPath onAsPath(const SkSVGRenderContext&) const final; |
| 31 | |
| 32 | using INHERITED = SkSVGTransformableNode; |
| 33 | }; |
| 34 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 35 | // Base class for nestable text containers (<text>, <tspan>, etc). |
Florin Malita | adc6889 | 2020-12-15 10:52:26 -0500 | [diff] [blame] | 36 | class SkSVGTextContainer : public SkSVGTextFragment { |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 37 | public: |
Florin Malita | dec7802 | 2020-12-17 16:36:54 -0500 | [diff] [blame] | 38 | SVG_ATTR(X, std::vector<SkSVGLength>, {}) |
| 39 | SVG_ATTR(Y, std::vector<SkSVGLength>, {}) |
Florin Malita | 735ac97 | 2020-12-22 11:23:32 -0500 | [diff] [blame^] | 40 | SVG_ATTR(Dx, std::vector<SkSVGLength>, {}) |
| 41 | SVG_ATTR(Dy, std::vector<SkSVGLength>, {}) |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 42 | |
Florin Malita | 9c1f1be | 2020-12-09 13:02:50 -0500 | [diff] [blame] | 43 | SVG_ATTR(XmlSpace, SkSVGXmlSpace, SkSVGXmlSpace::kDefault) |
| 44 | |
Florin Malita | dec7802 | 2020-12-17 16:36:54 -0500 | [diff] [blame] | 45 | void appendChild(sk_sp<SkSVGNode>) final; |
| 46 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 47 | protected: |
| 48 | explicit SkSVGTextContainer(SkSVGTag t) : INHERITED(t) {} |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 49 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 50 | private: |
Florin Malita | adc6889 | 2020-12-15 10:52:26 -0500 | [diff] [blame] | 51 | void onRender(const SkSVGRenderContext&) const final; |
| 52 | void onRenderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const final; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 53 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 54 | bool parseAndSetAttribute(const char*, const char*) override; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 55 | |
Florin Malita | adc6889 | 2020-12-15 10:52:26 -0500 | [diff] [blame] | 56 | std::vector<sk_sp<SkSVGTextFragment>> fChildren; |
| 57 | |
| 58 | using INHERITED = SkSVGTextFragment; |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 59 | }; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 60 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 61 | class SkSVGText final : public SkSVGTextContainer { |
| 62 | public: |
| 63 | static sk_sp<SkSVGText> Make() { return sk_sp<SkSVGText>(new SkSVGText()); } |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 64 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 65 | private: |
| 66 | SkSVGText() : INHERITED(SkSVGTag::kText) {} |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 67 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 68 | using INHERITED = SkSVGTextContainer; |
| 69 | }; |
Florin Malita | 39fe8c8 | 2020-10-20 10:43:03 -0400 | [diff] [blame] | 70 | |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 71 | class SkSVGTSpan final : public SkSVGTextContainer { |
| 72 | public: |
| 73 | static sk_sp<SkSVGTSpan> Make() { return sk_sp<SkSVGTSpan>(new SkSVGTSpan()); } |
| 74 | |
| 75 | private: |
| 76 | SkSVGTSpan() : INHERITED(SkSVGTag::kTSpan) {} |
| 77 | |
| 78 | using INHERITED = SkSVGTextContainer; |
| 79 | }; |
| 80 | |
Florin Malita | adc6889 | 2020-12-15 10:52:26 -0500 | [diff] [blame] | 81 | class SkSVGTextLiteral final : public SkSVGTextFragment { |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 82 | public: |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 83 | static sk_sp<SkSVGTextLiteral> Make() { |
| 84 | return sk_sp<SkSVGTextLiteral>(new SkSVGTextLiteral()); |
| 85 | } |
| 86 | |
| 87 | SVG_ATTR(Text, SkSVGStringType, SkSVGStringType()) |
| 88 | |
| 89 | private: |
| 90 | SkSVGTextLiteral() : INHERITED(SkSVGTag::kTextLiteral) {} |
| 91 | |
Florin Malita | adc6889 | 2020-12-15 10:52:26 -0500 | [diff] [blame] | 92 | void onRender(const SkSVGRenderContext&) const override {} |
| 93 | void onRenderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override; |
Florin Malita | 512ff75 | 2020-12-06 11:50:52 -0500 | [diff] [blame] | 94 | |
| 95 | void appendChild(sk_sp<SkSVGNode>) override {} |
| 96 | |
Florin Malita | adc6889 | 2020-12-15 10:52:26 -0500 | [diff] [blame] | 97 | using INHERITED = SkSVGTextFragment; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | #endif // SkSVGText_DEFINED |