Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [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 "include/core/SkRefCnt.h" |
| 12 | #include "modules/svg/include/SkSVGAttribute.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 | ~SkSVGNode() override; |
| 44 | |
| 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 | bool setAttribute(const char* attributeName, const char* attributeValue); |
| 55 | |
| 56 | void setClipPath(const SkSVGClip&); |
| 57 | void setClipRule(const SkSVGFillRule&); |
| 58 | void setColor(const SkSVGColorType&); |
| 59 | void setFill(const SkSVGPaint&); |
| 60 | void setFillOpacity(const SkSVGNumberType&); |
| 61 | void setFillRule(const SkSVGFillRule&); |
| 62 | void setOpacity(const SkSVGNumberType&); |
| 63 | void setStroke(const SkSVGPaint&); |
| 64 | void setStrokeDashArray(const SkSVGDashArray&); |
| 65 | void setStrokeDashOffset(const SkSVGLength&); |
| 66 | void setStrokeOpacity(const SkSVGNumberType&); |
| 67 | void setStrokeLineCap(const SkSVGLineCap&); |
| 68 | void setStrokeLineJoin(const SkSVGLineJoin&); |
| 69 | void setStrokeMiterLimit(const SkSVGNumberType&); |
| 70 | void setStrokeWidth(const SkSVGLength&); |
| 71 | void setVisibility(const SkSVGVisibility&); |
| 72 | |
| 73 | protected: |
| 74 | SkSVGNode(SkSVGTag); |
| 75 | |
| 76 | // Called before onRender(), to apply local attributes to the context. Unlike onRender(), |
| 77 | // onPrepareToRender() bubbles up the inheritance chain: overriders should always call |
| 78 | // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering |
| 79 | // (return false). |
| 80 | // Implementations are expected to return true if rendering is to continue, or false if |
| 81 | // the node/subtree rendering is disabled. |
| 82 | virtual bool onPrepareToRender(SkSVGRenderContext*) const; |
| 83 | |
| 84 | virtual void onRender(const SkSVGRenderContext&) const = 0; |
| 85 | |
| 86 | virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return false; } |
| 87 | |
| 88 | virtual SkPath onAsPath(const SkSVGRenderContext&) const = 0; |
| 89 | |
| 90 | virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&); |
| 91 | |
| 92 | virtual bool hasChildren() const { return false; } |
| 93 | |
| 94 | private: |
| 95 | SkSVGTag fTag; |
| 96 | |
| 97 | // FIXME: this should be sparse |
| 98 | SkSVGPresentationAttributes fPresentationAttributes; |
| 99 | |
| 100 | using INHERITED = SkRefCnt; |
| 101 | }; |
| 102 | |
| 103 | #endif // SkSVGNode_DEFINED |