• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
14 class SkCanvas;
15 class SkMatrix;
16 class SkPaint;
17 class SkPath;
18 class SkSVGRenderContext;
19 class SkSVGValue;
20 
21 enum class SkSVGTag {
22     kCircle,
23     kClipPath,
24     kDefs,
25     kEllipse,
26     kG,
27     kLine,
28     kLinearGradient,
29     kPath,
30     kPolygon,
31     kPolyline,
32     kRect,
33     kStop,
34     kSvg
35 };
36 
37 class SkSVGNode : public SkRefCnt {
38 public:
39     virtual ~SkSVGNode();
40 
tag()41     SkSVGTag tag() const { return fTag; }
42 
43     virtual void appendChild(sk_sp<SkSVGNode>) = 0;
44 
45     void render(const SkSVGRenderContext&) const;
46     bool asPaint(const SkSVGRenderContext&, SkPaint*) const;
47     SkPath asPath(const SkSVGRenderContext&) const;
48 
49     void setAttribute(SkSVGAttribute, const SkSVGValue&);
50 
51     void setClipPath(const SkSVGClip&);
52     void setFill(const SkSVGPaint&);
53     void setFillOpacity(const SkSVGNumberType&);
54     void setFillRule(const SkSVGFillRule&);
55     void setOpacity(const SkSVGNumberType&);
56     void setStroke(const SkSVGPaint&);
57     void setStrokeOpacity(const SkSVGNumberType&);
58     void setStrokeWidth(const SkSVGLength&);
59 
60 protected:
61     SkSVGNode(SkSVGTag);
62 
63     // Called before onRender(), to apply local attributes to the context.  Unlike onRender(),
64     // onPrepareToRender() bubbles up the inheritance chain: overriders should always call
65     // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering
66     // (return false).
67     // Implementations are expected to return true if rendering is to continue, or false if
68     // the node/subtree rendering is disabled.
69     virtual bool onPrepareToRender(SkSVGRenderContext*) const;
70 
71     virtual void onRender(const SkSVGRenderContext&) const = 0;
72 
onAsPaint(const SkSVGRenderContext &,SkPaint *)73     virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return false; }
74 
75     virtual SkPath onAsPath(const SkSVGRenderContext&) const = 0;
76 
77     virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
78 
hasChildren()79     virtual bool hasChildren() const { return false; }
80 
81 private:
82     SkSVGTag                    fTag;
83 
84     // FIXME: this should be sparse
85     SkSVGPresentationAttributes fPresentationAttributes;
86 
87     typedef SkRefCnt INHERITED;
88 };
89 
90 #endif // SkSVGNode_DEFINED
91