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