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 kText, 38 kUse 39 }; 40 41 class SkSVGNode : public SkRefCnt { 42 public: 43 virtual ~SkSVGNode(); 44 tag()45 SkSVGTag tag() const { return fTag; } 46 47 virtual void appendChild(sk_sp<SkSVGNode>) = 0; 48 49 void render(const SkSVGRenderContext&) const; 50 bool asPaint(const SkSVGRenderContext&, SkPaint*) const; 51 SkPath asPath(const SkSVGRenderContext&) const; 52 53 void setAttribute(SkSVGAttribute, const SkSVGValue&); 54 55 void setClipPath(const SkSVGClip&); 56 void setClipRule(const SkSVGFillRule&); 57 void setFill(const SkSVGPaint&); 58 void setFillOpacity(const SkSVGNumberType&); 59 void setFillRule(const SkSVGFillRule&); 60 void setOpacity(const SkSVGNumberType&); 61 void setStroke(const SkSVGPaint&); 62 void setStrokeDashArray(const SkSVGDashArray&); 63 void setStrokeDashOffset(const SkSVGLength&); 64 void setStrokeOpacity(const SkSVGNumberType&); 65 void setStrokeWidth(const SkSVGLength&); 66 void setVisibility(const SkSVGVisibility&); 67 68 protected: 69 SkSVGNode(SkSVGTag); 70 71 // Called before onRender(), to apply local attributes to the context. Unlike onRender(), 72 // onPrepareToRender() bubbles up the inheritance chain: overriders should always call 73 // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering 74 // (return false). 75 // Implementations are expected to return true if rendering is to continue, or false if 76 // the node/subtree rendering is disabled. 77 virtual bool onPrepareToRender(SkSVGRenderContext*) const; 78 79 virtual void onRender(const SkSVGRenderContext&) const = 0; 80 onAsPaint(const SkSVGRenderContext &,SkPaint *)81 virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return false; } 82 83 virtual SkPath onAsPath(const SkSVGRenderContext&) const = 0; 84 85 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&); 86 hasChildren()87 virtual bool hasChildren() const { return false; } 88 89 private: 90 SkSVGTag fTag; 91 92 // FIXME: this should be sparse 93 SkSVGPresentationAttributes fPresentationAttributes; 94 95 typedef SkRefCnt INHERITED; 96 }; 97 98 #endif // SkSVGNode_DEFINED 99