blob: ffc4411bdeb959f6137c70bc12369909da6262fa [file] [log] [blame]
fmalita6ceef3d2016-07-26 18:46:34 -07001/*
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 "SkRefCnt.h"
12#include "SkSVGAttribute.h"
13
14class SkCanvas;
15class SkMatrix;
fmalita28d5b722016-09-12 17:06:47 -070016class SkPaint;
Florin Malitace8840e2016-12-08 09:26:47 -050017class SkPath;
fmalita6ceef3d2016-07-26 18:46:34 -070018class SkSVGRenderContext;
19class SkSVGValue;
20
21enum class SkSVGTag {
fmalitadc4c2a92016-08-16 15:38:51 -070022 kCircle,
Florin Malitace8840e2016-12-08 09:26:47 -050023 kClipPath,
fmalita28d5b722016-09-12 17:06:47 -070024 kDefs,
fmalitadc4c2a92016-08-16 15:38:51 -070025 kEllipse,
fmalita58649cc2016-07-29 08:52:03 -070026 kG,
fmalitad24ee142016-08-17 08:38:15 -070027 kLine,
fmalita28d5b722016-09-12 17:06:47 -070028 kLinearGradient,
fmalita58649cc2016-07-29 08:52:03 -070029 kPath,
Florin Malita1aa1bb62017-10-11 14:34:33 -040030 kPattern,
fmalita5b31f322016-08-12 12:15:33 -070031 kPolygon,
32 kPolyline,
Florin Malitacc6cc292017-10-09 16:05:30 -040033 kRadialGradient,
fmalitabffc2562016-08-03 10:21:11 -070034 kRect,
fmalita28d5b722016-09-12 17:06:47 -070035 kStop,
Florin Malita6a69c052017-10-11 14:02:11 -040036 kSvg,
37 kUse
fmalita6ceef3d2016-07-26 18:46:34 -070038};
39
40class SkSVGNode : public SkRefCnt {
41public:
42 virtual ~SkSVGNode();
43
44 SkSVGTag tag() const { return fTag; }
45
46 virtual void appendChild(sk_sp<SkSVGNode>) = 0;
47
fmalita397a5172016-08-08 11:38:55 -070048 void render(const SkSVGRenderContext&) const;
fmalita28d5b722016-09-12 17:06:47 -070049 bool asPaint(const SkSVGRenderContext&, SkPaint*) const;
Florin Malitace8840e2016-12-08 09:26:47 -050050 SkPath asPath(const SkSVGRenderContext&) const;
fmalita6ceef3d2016-07-26 18:46:34 -070051
52 void setAttribute(SkSVGAttribute, const SkSVGValue&);
53
Florin Malitace8840e2016-12-08 09:26:47 -050054 void setClipPath(const SkSVGClip&);
Florin Malita57a0edf2017-10-10 11:22:08 -040055 void setClipRule(const SkSVGFillRule&);
fmalitaca39d712016-08-12 13:17:11 -070056 void setFill(const SkSVGPaint&);
57 void setFillOpacity(const SkSVGNumberType&);
Florin Malitae932d4b2016-12-01 13:35:11 -050058 void setFillRule(const SkSVGFillRule&);
fmalita6fb06482016-08-15 12:45:11 -070059 void setOpacity(const SkSVGNumberType&);
fmalitaca39d712016-08-12 13:17:11 -070060 void setStroke(const SkSVGPaint&);
Florin Malitaf543a602017-10-13 14:07:44 -040061 void setStrokeDashArray(const SkSVGDashArray&);
Florin Malitae1dadd72017-10-13 18:18:32 -040062 void setStrokeDashOffset(const SkSVGLength&);
fmalitaca39d712016-08-12 13:17:11 -070063 void setStrokeOpacity(const SkSVGNumberType&);
64 void setStrokeWidth(const SkSVGLength&);
Florin Malitaffe6ae42017-10-12 11:33:28 -040065 void setVisibility(const SkSVGVisibility&);
fmalitaca39d712016-08-12 13:17:11 -070066
fmalita6ceef3d2016-07-26 18:46:34 -070067protected:
68 SkSVGNode(SkSVGTag);
69
fmalita397a5172016-08-08 11:38:55 -070070 // 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;
fmalita6ceef3d2016-07-26 18:46:34 -070079
fmalita28d5b722016-09-12 17:06:47 -070080 virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return false; }
81
Florin Malitace8840e2016-12-08 09:26:47 -050082 virtual SkPath onAsPath(const SkSVGRenderContext&) const = 0;
83
fmalita6ceef3d2016-07-26 18:46:34 -070084 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
85
fmalitabef51c22016-09-20 15:45:57 -070086 virtual bool hasChildren() const { return false; }
87
fmalita6ceef3d2016-07-26 18:46:34 -070088private:
89 SkSVGTag fTag;
90
91 // FIXME: this should be sparse
92 SkSVGPresentationAttributes fPresentationAttributes;
93
94 typedef SkRefCnt INHERITED;
95};
96
97#endif // SkSVGNode_DEFINED