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 "experimental/svg/model/SkSVGAttribute.h" 12 #include "include/core/SkRefCnt.h" 13 14 class SkCanvas; 15 class SkMatrix; 16 class SkPaint; 17 class SkPath; 18 class SkSVGRenderContext; 19 class SkSVGValue; 20 21 enum class SkSVGTag { 22 kCircle, 23 kClipPath, 24 kDefs, 25 kEllipse, 26 kG, 27 kLine, 28 kLinearGradient, 29 kPath, 30 kPattern, 31 kPolygon, 32 kPolyline, 33 kRadialGradient, 34 kRect, 35 kStop, 36 kSvg, 37 kUse 38 }; 39 40 class SkSVGNode : public SkRefCnt { 41 public: 42 virtual ~SkSVGNode(); 43 tag()44 SkSVGTag tag() const { return fTag; } 45 46 virtual void appendChild(sk_sp<SkSVGNode>) = 0; 47 48 void render(const SkSVGRenderContext&) const; 49 bool asPaint(const SkSVGRenderContext&, SkPaint*) const; 50 SkPath asPath(const SkSVGRenderContext&) const; 51 52 void setAttribute(SkSVGAttribute, const SkSVGValue&); 53 54 void setClipPath(const SkSVGClip&); 55 void setClipRule(const SkSVGFillRule&); 56 void setFill(const SkSVGPaint&); 57 void setFillOpacity(const SkSVGNumberType&); 58 void setFillRule(const SkSVGFillRule&); 59 void setOpacity(const SkSVGNumberType&); 60 void setStroke(const SkSVGPaint&); 61 void setStrokeDashArray(const SkSVGDashArray&); 62 void setStrokeDashOffset(const SkSVGLength&); 63 void setStrokeOpacity(const SkSVGNumberType&); 64 void setStrokeWidth(const SkSVGLength&); 65 void setVisibility(const SkSVGVisibility&); 66 67 protected: 68 SkSVGNode(SkSVGTag); 69 70 // Called before onRender(), to apply local attributes to the context. Unlike onRender(), 71 // onPrepareToRender() bubbles up the inheritance chain: overriders should always call 72 // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering 73 // (return false). 74 // Implementations are expected to return true if rendering is to continue, or false if 75 // the node/subtree rendering is disabled. 76 virtual bool onPrepareToRender(SkSVGRenderContext*) const; 77 78 virtual void onRender(const SkSVGRenderContext&) const = 0; 79 onAsPaint(const SkSVGRenderContext &,SkPaint *)80 virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return false; } 81 82 virtual SkPath onAsPath(const SkSVGRenderContext&) const = 0; 83 84 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&); 85 hasChildren()86 virtual bool hasChildren() const { return false; } 87 88 private: 89 SkSVGTag fTag; 90 91 // FIXME: this should be sparse 92 SkSVGPresentationAttributes fPresentationAttributes; 93 94 typedef SkRefCnt INHERITED; 95 }; 96 97 #endif // SkSVGNode_DEFINED 98