OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkSVGNode_DEFINED | 8 #ifndef SkSVGNode_DEFINED |
9 #define SkSVGNode_DEFINED | 9 #define SkSVGNode_DEFINED |
10 | 10 |
11 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
12 #include "SkSVGAttribute.h" | 12 #include "SkSVGAttribute.h" |
13 | 13 |
14 class SkCanvas; | 14 class SkCanvas; |
15 class SkMatrix; | 15 class SkMatrix; |
| 16 class SkPaint; |
16 class SkSVGRenderContext; | 17 class SkSVGRenderContext; |
17 class SkSVGValue; | 18 class SkSVGValue; |
18 | 19 |
19 enum class SkSVGTag { | 20 enum class SkSVGTag { |
20 kCircle, | 21 kCircle, |
| 22 kDefs, |
21 kEllipse, | 23 kEllipse, |
22 kG, | 24 kG, |
23 kLine, | 25 kLine, |
| 26 kLinearGradient, |
24 kPath, | 27 kPath, |
25 kPolygon, | 28 kPolygon, |
26 kPolyline, | 29 kPolyline, |
27 kRect, | 30 kRect, |
| 31 kStop, |
28 kSvg | 32 kSvg |
29 }; | 33 }; |
30 | 34 |
31 class SkSVGNode : public SkRefCnt { | 35 class SkSVGNode : public SkRefCnt { |
32 public: | 36 public: |
33 virtual ~SkSVGNode(); | 37 virtual ~SkSVGNode(); |
34 | 38 |
35 SkSVGTag tag() const { return fTag; } | 39 SkSVGTag tag() const { return fTag; } |
36 | 40 |
37 virtual void appendChild(sk_sp<SkSVGNode>) = 0; | 41 virtual void appendChild(sk_sp<SkSVGNode>) = 0; |
38 | 42 |
39 void render(const SkSVGRenderContext&) const; | 43 void render(const SkSVGRenderContext&) const; |
| 44 bool asPaint(const SkSVGRenderContext&, SkPaint*) const; |
40 | 45 |
41 void setAttribute(SkSVGAttribute, const SkSVGValue&); | 46 void setAttribute(SkSVGAttribute, const SkSVGValue&); |
42 | 47 |
43 void setFill(const SkSVGPaint&); | 48 void setFill(const SkSVGPaint&); |
44 void setFillOpacity(const SkSVGNumberType&); | 49 void setFillOpacity(const SkSVGNumberType&); |
45 void setOpacity(const SkSVGNumberType&); | 50 void setOpacity(const SkSVGNumberType&); |
46 void setStroke(const SkSVGPaint&); | 51 void setStroke(const SkSVGPaint&); |
47 void setStrokeOpacity(const SkSVGNumberType&); | 52 void setStrokeOpacity(const SkSVGNumberType&); |
48 void setStrokeWidth(const SkSVGLength&); | 53 void setStrokeWidth(const SkSVGLength&); |
49 | 54 |
50 protected: | 55 protected: |
51 SkSVGNode(SkSVGTag); | 56 SkSVGNode(SkSVGTag); |
52 | 57 |
53 // Called before onRender(), to apply local attributes to the context. Unli
ke onRender(), | 58 // Called before onRender(), to apply local attributes to the context. Unli
ke onRender(), |
54 // onPrepareToRender() bubbles up the inheritance chain: overriders should a
lways call | 59 // onPrepareToRender() bubbles up the inheritance chain: overriders should a
lways call |
55 // INHERITED::onPrepareToRender(), unless they intend to short-circuit rende
ring | 60 // INHERITED::onPrepareToRender(), unless they intend to short-circuit rende
ring |
56 // (return false). | 61 // (return false). |
57 // Implementations are expected to return true if rendering is to continue,
or false if | 62 // Implementations are expected to return true if rendering is to continue,
or false if |
58 // the node/subtree rendering is disabled. | 63 // the node/subtree rendering is disabled. |
59 virtual bool onPrepareToRender(SkSVGRenderContext*) const; | 64 virtual bool onPrepareToRender(SkSVGRenderContext*) const; |
60 | 65 |
61 virtual void onRender(const SkSVGRenderContext&) const = 0; | 66 virtual void onRender(const SkSVGRenderContext&) const = 0; |
62 | 67 |
| 68 virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return f
alse; } |
| 69 |
63 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&); | 70 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&); |
64 | 71 |
65 private: | 72 private: |
66 SkSVGTag fTag; | 73 SkSVGTag fTag; |
67 | 74 |
68 // FIXME: this should be sparse | 75 // FIXME: this should be sparse |
69 SkSVGPresentationAttributes fPresentationAttributes; | 76 SkSVGPresentationAttributes fPresentationAttributes; |
70 | 77 |
71 typedef SkRefCnt INHERITED; | 78 typedef SkRefCnt INHERITED; |
72 }; | 79 }; |
73 | 80 |
74 #endif // SkSVGNode_DEFINED | 81 #endif // SkSVGNode_DEFINED |
OLD | NEW |