blob: c02fd3a21477702adeb1d246de35db1c730a011f [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;
16class SkSVGRenderContext;
17class SkSVGValue;
18
19enum class SkSVGTag {
fmalitadc4c2a92016-08-16 15:38:51 -070020 kCircle,
21 kEllipse,
fmalita58649cc2016-07-29 08:52:03 -070022 kG,
fmalitad24ee142016-08-17 08:38:15 -070023 kLine,
fmalita58649cc2016-07-29 08:52:03 -070024 kPath,
fmalita5b31f322016-08-12 12:15:33 -070025 kPolygon,
26 kPolyline,
fmalitabffc2562016-08-03 10:21:11 -070027 kRect,
fmalita58649cc2016-07-29 08:52:03 -070028 kSvg
fmalita6ceef3d2016-07-26 18:46:34 -070029};
30
31class SkSVGNode : public SkRefCnt {
32public:
33 virtual ~SkSVGNode();
34
35 SkSVGTag tag() const { return fTag; }
36
37 virtual void appendChild(sk_sp<SkSVGNode>) = 0;
38
fmalita397a5172016-08-08 11:38:55 -070039 void render(const SkSVGRenderContext&) const;
fmalita6ceef3d2016-07-26 18:46:34 -070040
41 void setAttribute(SkSVGAttribute, const SkSVGValue&);
42
fmalitaca39d712016-08-12 13:17:11 -070043 void setFill(const SkSVGPaint&);
44 void setFillOpacity(const SkSVGNumberType&);
fmalita6fb06482016-08-15 12:45:11 -070045 void setOpacity(const SkSVGNumberType&);
fmalitaca39d712016-08-12 13:17:11 -070046 void setStroke(const SkSVGPaint&);
47 void setStrokeOpacity(const SkSVGNumberType&);
48 void setStrokeWidth(const SkSVGLength&);
49
fmalita6ceef3d2016-07-26 18:46:34 -070050protected:
51 SkSVGNode(SkSVGTag);
52
fmalita397a5172016-08-08 11:38:55 -070053 // Called before onRender(), to apply local attributes to the context. Unlike onRender(),
54 // onPrepareToRender() bubbles up the inheritance chain: overriders should always call
55 // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering
56 // (return false).
57 // Implementations are expected to return true if rendering is to continue, or false if
58 // the node/subtree rendering is disabled.
59 virtual bool onPrepareToRender(SkSVGRenderContext*) const;
60
61 virtual void onRender(const SkSVGRenderContext&) const = 0;
fmalita6ceef3d2016-07-26 18:46:34 -070062
63 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
64
fmalita6ceef3d2016-07-26 18:46:34 -070065private:
66 SkSVGTag fTag;
67
68 // FIXME: this should be sparse
69 SkSVGPresentationAttributes fPresentationAttributes;
70
71 typedef SkRefCnt INHERITED;
72};
73
74#endif // SkSVGNode_DEFINED