blob: 2e92c6bd4d54d36248af6e591a6dd5a8141be4f8 [file] [log] [blame]
Florin Malitab3418102020-10-15 18:10:29 -04001/*
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
14class SkCanvas;
15class SkMatrix;
16class SkPaint;
17class SkPath;
18class SkSVGRenderContext;
19class SkSVGValue;
20
21enum 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
41class SkSVGNode : public SkRefCnt {
42public:
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
73protected:
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
94private:
95 SkSVGTag fTag;
96
97 // FIXME: this should be sparse
98 SkSVGPresentationAttributes fPresentationAttributes;
99
100 using INHERITED = SkRefCnt;
101};
102
103#endif // SkSVGNode_DEFINED