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