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