fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 SkSVGNode_DEFINED |
| 9 | #define SkSVGNode_DEFINED |
| 10 | |
| 11 | #include "SkRefCnt.h" |
| 12 | #include "SkSVGAttribute.h" |
| 13 | |
| 14 | class SkCanvas; |
| 15 | class SkMatrix; |
fmalita | 28d5b72 | 2016-09-12 17:06:47 -0700 | [diff] [blame] | 16 | class SkPaint; |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 17 | class SkPath; |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 18 | class SkSVGRenderContext; |
| 19 | class SkSVGValue; |
| 20 | |
| 21 | enum class SkSVGTag { |
fmalita | dc4c2a9 | 2016-08-16 15:38:51 -0700 | [diff] [blame] | 22 | kCircle, |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 23 | kClipPath, |
fmalita | 28d5b72 | 2016-09-12 17:06:47 -0700 | [diff] [blame] | 24 | kDefs, |
fmalita | dc4c2a9 | 2016-08-16 15:38:51 -0700 | [diff] [blame] | 25 | kEllipse, |
fmalita | 58649cc | 2016-07-29 08:52:03 -0700 | [diff] [blame] | 26 | kG, |
fmalita | d24ee14 | 2016-08-17 08:38:15 -0700 | [diff] [blame] | 27 | kLine, |
fmalita | 28d5b72 | 2016-09-12 17:06:47 -0700 | [diff] [blame] | 28 | kLinearGradient, |
fmalita | 58649cc | 2016-07-29 08:52:03 -0700 | [diff] [blame] | 29 | kPath, |
Florin Malita | 1aa1bb6 | 2017-10-11 14:34:33 -0400 | [diff] [blame^] | 30 | kPattern, |
fmalita | 5b31f32 | 2016-08-12 12:15:33 -0700 | [diff] [blame] | 31 | kPolygon, |
| 32 | kPolyline, |
Florin Malita | cc6cc29 | 2017-10-09 16:05:30 -0400 | [diff] [blame] | 33 | kRadialGradient, |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 34 | kRect, |
fmalita | 28d5b72 | 2016-09-12 17:06:47 -0700 | [diff] [blame] | 35 | kStop, |
Florin Malita | 6a69c05 | 2017-10-11 14:02:11 -0400 | [diff] [blame] | 36 | kSvg, |
| 37 | kUse |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | class SkSVGNode : public SkRefCnt { |
| 41 | public: |
| 42 | virtual ~SkSVGNode(); |
| 43 | |
| 44 | SkSVGTag tag() const { return fTag; } |
| 45 | |
| 46 | virtual void appendChild(sk_sp<SkSVGNode>) = 0; |
| 47 | |
fmalita | 397a517 | 2016-08-08 11:38:55 -0700 | [diff] [blame] | 48 | void render(const SkSVGRenderContext&) const; |
fmalita | 28d5b72 | 2016-09-12 17:06:47 -0700 | [diff] [blame] | 49 | bool asPaint(const SkSVGRenderContext&, SkPaint*) const; |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 50 | SkPath asPath(const SkSVGRenderContext&) const; |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 51 | |
| 52 | void setAttribute(SkSVGAttribute, const SkSVGValue&); |
| 53 | |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 54 | void setClipPath(const SkSVGClip&); |
Florin Malita | 57a0edf | 2017-10-10 11:22:08 -0400 | [diff] [blame] | 55 | void setClipRule(const SkSVGFillRule&); |
fmalita | ca39d71 | 2016-08-12 13:17:11 -0700 | [diff] [blame] | 56 | void setFill(const SkSVGPaint&); |
| 57 | void setFillOpacity(const SkSVGNumberType&); |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 58 | void setFillRule(const SkSVGFillRule&); |
fmalita | 6fb0648 | 2016-08-15 12:45:11 -0700 | [diff] [blame] | 59 | void setOpacity(const SkSVGNumberType&); |
fmalita | ca39d71 | 2016-08-12 13:17:11 -0700 | [diff] [blame] | 60 | void setStroke(const SkSVGPaint&); |
| 61 | void setStrokeOpacity(const SkSVGNumberType&); |
| 62 | void setStrokeWidth(const SkSVGLength&); |
| 63 | |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 64 | protected: |
| 65 | SkSVGNode(SkSVGTag); |
| 66 | |
fmalita | 397a517 | 2016-08-08 11:38:55 -0700 | [diff] [blame] | 67 | // Called before onRender(), to apply local attributes to the context. Unlike onRender(), |
| 68 | // onPrepareToRender() bubbles up the inheritance chain: overriders should always call |
| 69 | // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering |
| 70 | // (return false). |
| 71 | // Implementations are expected to return true if rendering is to continue, or false if |
| 72 | // the node/subtree rendering is disabled. |
| 73 | virtual bool onPrepareToRender(SkSVGRenderContext*) const; |
| 74 | |
| 75 | virtual void onRender(const SkSVGRenderContext&) const = 0; |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 76 | |
fmalita | 28d5b72 | 2016-09-12 17:06:47 -0700 | [diff] [blame] | 77 | virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return false; } |
| 78 | |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 79 | virtual SkPath onAsPath(const SkSVGRenderContext&) const = 0; |
| 80 | |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 81 | virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&); |
| 82 | |
fmalita | bef51c2 | 2016-09-20 15:45:57 -0700 | [diff] [blame] | 83 | virtual bool hasChildren() const { return false; } |
| 84 | |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 85 | private: |
| 86 | SkSVGTag fTag; |
| 87 | |
| 88 | // FIXME: this should be sparse |
| 89 | SkSVGPresentationAttributes fPresentationAttributes; |
| 90 | |
| 91 | typedef SkRefCnt INHERITED; |
| 92 | }; |
| 93 | |
| 94 | #endif // SkSVGNode_DEFINED |