blob: 1e092a4d876a5f619e751ac1be6412efee985f8e [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;
fmalita6ceef3d2016-07-26 18:46:34 -070017class SkSVGRenderContext;
18class SkSVGValue;
19
20enum class SkSVGTag {
fmalitadc4c2a92016-08-16 15:38:51 -070021 kCircle,
fmalita28d5b722016-09-12 17:06:47 -070022 kDefs,
fmalitadc4c2a92016-08-16 15:38:51 -070023 kEllipse,
fmalita58649cc2016-07-29 08:52:03 -070024 kG,
fmalitad24ee142016-08-17 08:38:15 -070025 kLine,
fmalita28d5b722016-09-12 17:06:47 -070026 kLinearGradient,
fmalita58649cc2016-07-29 08:52:03 -070027 kPath,
fmalita5b31f322016-08-12 12:15:33 -070028 kPolygon,
29 kPolyline,
fmalitabffc2562016-08-03 10:21:11 -070030 kRect,
fmalita28d5b722016-09-12 17:06:47 -070031 kStop,
fmalita58649cc2016-07-29 08:52:03 -070032 kSvg
fmalita6ceef3d2016-07-26 18:46:34 -070033};
34
35class SkSVGNode : public SkRefCnt {
36public:
37 virtual ~SkSVGNode();
38
39 SkSVGTag tag() const { return fTag; }
40
41 virtual void appendChild(sk_sp<SkSVGNode>) = 0;
42
fmalita397a5172016-08-08 11:38:55 -070043 void render(const SkSVGRenderContext&) const;
fmalita28d5b722016-09-12 17:06:47 -070044 bool asPaint(const SkSVGRenderContext&, SkPaint*) const;
fmalita6ceef3d2016-07-26 18:46:34 -070045
46 void setAttribute(SkSVGAttribute, const SkSVGValue&);
47
fmalitaca39d712016-08-12 13:17:11 -070048 void setFill(const SkSVGPaint&);
49 void setFillOpacity(const SkSVGNumberType&);
Florin Malitae932d4b2016-12-01 13:35:11 -050050 void setFillRule(const SkSVGFillRule&);
fmalita6fb06482016-08-15 12:45:11 -070051 void setOpacity(const SkSVGNumberType&);
fmalitaca39d712016-08-12 13:17:11 -070052 void setStroke(const SkSVGPaint&);
53 void setStrokeOpacity(const SkSVGNumberType&);
54 void setStrokeWidth(const SkSVGLength&);
55
fmalita6ceef3d2016-07-26 18:46:34 -070056protected:
57 SkSVGNode(SkSVGTag);
58
fmalita397a5172016-08-08 11:38:55 -070059 // Called before onRender(), to apply local attributes to the context. Unlike onRender(),
60 // onPrepareToRender() bubbles up the inheritance chain: overriders should always call
61 // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering
62 // (return false).
63 // Implementations are expected to return true if rendering is to continue, or false if
64 // the node/subtree rendering is disabled.
65 virtual bool onPrepareToRender(SkSVGRenderContext*) const;
66
67 virtual void onRender(const SkSVGRenderContext&) const = 0;
fmalita6ceef3d2016-07-26 18:46:34 -070068
fmalita28d5b722016-09-12 17:06:47 -070069 virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return false; }
70
fmalita6ceef3d2016-07-26 18:46:34 -070071 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
72
fmalitabef51c22016-09-20 15:45:57 -070073 virtual bool hasChildren() const { return false; }
74
fmalita6ceef3d2016-07-26 18:46:34 -070075private:
76 SkSVGTag fTag;
77
78 // FIXME: this should be sparse
79 SkSVGPresentationAttributes fPresentationAttributes;
80
81 typedef SkRefCnt INHERITED;
82};
83
84#endif // SkSVGNode_DEFINED