blob: 99d07b2cb187b85a15a1df2d0efca8c6502bceb3 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "experimental/svg/model/SkSVGAttribute.h"
12#include "include/core/SkRefCnt.h"
fmalita6ceef3d2016-07-26 18:46:34 -070013
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;
Florin Malitaf4403e72020-04-10 14:14:04 +000019class SkSVGValue;
fmalita6ceef3d2016-07-26 18:46:34 -070020
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,
Xavier Phane29cdaf2020-03-26 16:15:14 +000037 kText,
Florin Malita6a69c052017-10-11 14:02:11 -040038 kUse
fmalita6ceef3d2016-07-26 18:46:34 -070039};
40
41class SkSVGNode : public SkRefCnt {
42public:
Brian Salomond0072812020-07-21 17:03:56 -040043 ~SkSVGNode() override;
fmalita6ceef3d2016-07-26 18:46:34 -070044
45 SkSVGTag tag() const { return fTag; }
46
47 virtual void appendChild(sk_sp<SkSVGNode>) = 0;
48
fmalita397a5172016-08-08 11:38:55 -070049 void render(const SkSVGRenderContext&) const;
fmalita28d5b722016-09-12 17:06:47 -070050 bool asPaint(const SkSVGRenderContext&, SkPaint*) const;
Florin Malitace8840e2016-12-08 09:26:47 -050051 SkPath asPath(const SkSVGRenderContext&) const;
fmalita6ceef3d2016-07-26 18:46:34 -070052
Florin Malitaf4403e72020-04-10 14:14:04 +000053 void setAttribute(SkSVGAttribute, const SkSVGValue&);
Tyler Freemanc9911522020-05-08 13:23:10 -070054 bool setAttribute(const char* attributeName, const char* attributeValue);
fmalita6ceef3d2016-07-26 18:46:34 -070055
Florin Malitace8840e2016-12-08 09:26:47 -050056 void setClipPath(const SkSVGClip&);
Florin Malita57a0edf2017-10-10 11:22:08 -040057 void setClipRule(const SkSVGFillRule&);
Tyler Denniston6c8314e2020-04-09 14:14:10 -040058 void setColor(const SkSVGColorType&);
fmalitaca39d712016-08-12 13:17:11 -070059 void setFill(const SkSVGPaint&);
60 void setFillOpacity(const SkSVGNumberType&);
Florin Malitae932d4b2016-12-01 13:35:11 -050061 void setFillRule(const SkSVGFillRule&);
fmalita6fb06482016-08-15 12:45:11 -070062 void setOpacity(const SkSVGNumberType&);
fmalitaca39d712016-08-12 13:17:11 -070063 void setStroke(const SkSVGPaint&);
Florin Malitaf543a602017-10-13 14:07:44 -040064 void setStrokeDashArray(const SkSVGDashArray&);
Florin Malitae1dadd72017-10-13 18:18:32 -040065 void setStrokeDashOffset(const SkSVGLength&);
fmalitaca39d712016-08-12 13:17:11 -070066 void setStrokeOpacity(const SkSVGNumberType&);
Florin Malita09294252020-04-09 08:54:29 -040067 void setStrokeLineCap(const SkSVGLineCap&);
68 void setStrokeLineJoin(const SkSVGLineJoin&);
69 void setStrokeMiterLimit(const SkSVGNumberType&);
fmalitaca39d712016-08-12 13:17:11 -070070 void setStrokeWidth(const SkSVGLength&);
Florin Malitaffe6ae42017-10-12 11:33:28 -040071 void setVisibility(const SkSVGVisibility&);
fmalitaca39d712016-08-12 13:17:11 -070072
fmalita6ceef3d2016-07-26 18:46:34 -070073protected:
74 SkSVGNode(SkSVGTag);
75
fmalita397a5172016-08-08 11:38:55 -070076 // 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;
fmalita6ceef3d2016-07-26 18:46:34 -070085
fmalita28d5b722016-09-12 17:06:47 -070086 virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return false; }
87
Florin Malitace8840e2016-12-08 09:26:47 -050088 virtual SkPath onAsPath(const SkSVGRenderContext&) const = 0;
89
Florin Malitaf4403e72020-04-10 14:14:04 +000090 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
fmalita6ceef3d2016-07-26 18:46:34 -070091
fmalitabef51c22016-09-20 15:45:57 -070092 virtual bool hasChildren() const { return false; }
93
fmalita6ceef3d2016-07-26 18:46:34 -070094private:
95 SkSVGTag fTag;
96
97 // FIXME: this should be sparse
98 SkSVGPresentationAttributes fPresentationAttributes;
99
John Stiles7571f9e2020-09-02 22:42:33 -0400100 using INHERITED = SkRefCnt;
fmalita6ceef3d2016-07-26 18:46:34 -0700101};
102
103#endif // SkSVGNode_DEFINED