blob: c9955d16382dfa76908b3c37aa45d6f8f4cd0afa [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&);
61 void setStrokeOpacity(const SkSVGNumberType&);
62 void setStrokeWidth(const SkSVGLength&);
63
fmalita6ceef3d2016-07-26 18:46:34 -070064protected:
65 SkSVGNode(SkSVGTag);
66
fmalita397a5172016-08-08 11:38:55 -070067 // Called before onRender(), to apply local attributes to the context. Unlike onRender(),
68 // onPrepareToRender() bubbles up the inheritance chain: overriders should always call
69 // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering
70 // (return false).
71 // Implementations are expected to return true if rendering is to continue, or false if
72 // the node/subtree rendering is disabled.
73 virtual bool onPrepareToRender(SkSVGRenderContext*) const;
74
75 virtual void onRender(const SkSVGRenderContext&) const = 0;
fmalita6ceef3d2016-07-26 18:46:34 -070076
fmalita28d5b722016-09-12 17:06:47 -070077 virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return false; }
78
Florin Malitace8840e2016-12-08 09:26:47 -050079 virtual SkPath onAsPath(const SkSVGRenderContext&) const = 0;
80
fmalita6ceef3d2016-07-26 18:46:34 -070081 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
82
fmalitabef51c22016-09-20 15:45:57 -070083 virtual bool hasChildren() const { return false; }
84
fmalita6ceef3d2016-07-26 18:46:34 -070085private:
86 SkSVGTag fTag;
87
88 // FIXME: this should be sparse
89 SkSVGPresentationAttributes fPresentationAttributes;
90
91 typedef SkRefCnt INHERITED;
92};
93
94#endif // SkSVGNode_DEFINED