2016-07-27 01:46:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkSVGNode_DEFINED
|
|
|
|
#define SkSVGNode_DEFINED
|
|
|
|
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkSVGAttribute.h"
|
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
class SkMatrix;
|
2016-09-13 00:06:47 +00:00
|
|
|
class SkPaint;
|
2016-12-08 14:26:47 +00:00
|
|
|
class SkPath;
|
2016-07-27 01:46:34 +00:00
|
|
|
class SkSVGRenderContext;
|
|
|
|
class SkSVGValue;
|
|
|
|
|
|
|
|
enum class SkSVGTag {
|
2016-08-16 22:38:51 +00:00
|
|
|
kCircle,
|
2016-12-08 14:26:47 +00:00
|
|
|
kClipPath,
|
2016-09-13 00:06:47 +00:00
|
|
|
kDefs,
|
2016-08-16 22:38:51 +00:00
|
|
|
kEllipse,
|
2016-07-29 15:52:03 +00:00
|
|
|
kG,
|
2016-08-17 15:38:15 +00:00
|
|
|
kLine,
|
2016-09-13 00:06:47 +00:00
|
|
|
kLinearGradient,
|
2016-07-29 15:52:03 +00:00
|
|
|
kPath,
|
2016-08-12 19:15:33 +00:00
|
|
|
kPolygon,
|
|
|
|
kPolyline,
|
2016-08-03 17:21:11 +00:00
|
|
|
kRect,
|
2016-09-13 00:06:47 +00:00
|
|
|
kStop,
|
2016-07-29 15:52:03 +00:00
|
|
|
kSvg
|
2016-07-27 01:46:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SkSVGNode : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
virtual ~SkSVGNode();
|
|
|
|
|
|
|
|
SkSVGTag tag() const { return fTag; }
|
|
|
|
|
|
|
|
virtual void appendChild(sk_sp<SkSVGNode>) = 0;
|
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
void render(const SkSVGRenderContext&) const;
|
2016-09-13 00:06:47 +00:00
|
|
|
bool asPaint(const SkSVGRenderContext&, SkPaint*) const;
|
2016-12-08 14:26:47 +00:00
|
|
|
SkPath asPath(const SkSVGRenderContext&) const;
|
2016-07-27 01:46:34 +00:00
|
|
|
|
|
|
|
void setAttribute(SkSVGAttribute, const SkSVGValue&);
|
|
|
|
|
2016-12-08 14:26:47 +00:00
|
|
|
void setClipPath(const SkSVGClip&);
|
2016-08-12 20:17:11 +00:00
|
|
|
void setFill(const SkSVGPaint&);
|
|
|
|
void setFillOpacity(const SkSVGNumberType&);
|
2016-12-01 18:35:11 +00:00
|
|
|
void setFillRule(const SkSVGFillRule&);
|
2016-08-15 19:45:11 +00:00
|
|
|
void setOpacity(const SkSVGNumberType&);
|
2016-08-12 20:17:11 +00:00
|
|
|
void setStroke(const SkSVGPaint&);
|
|
|
|
void setStrokeOpacity(const SkSVGNumberType&);
|
|
|
|
void setStrokeWidth(const SkSVGLength&);
|
|
|
|
|
2016-07-27 01:46:34 +00:00
|
|
|
protected:
|
|
|
|
SkSVGNode(SkSVGTag);
|
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
// Called before onRender(), to apply local attributes to the context. Unlike onRender(),
|
|
|
|
// onPrepareToRender() bubbles up the inheritance chain: overriders should always call
|
|
|
|
// INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering
|
|
|
|
// (return false).
|
|
|
|
// Implementations are expected to return true if rendering is to continue, or false if
|
|
|
|
// the node/subtree rendering is disabled.
|
|
|
|
virtual bool onPrepareToRender(SkSVGRenderContext*) const;
|
2016-07-27 01:46:34 +00:00
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
virtual void onRender(const SkSVGRenderContext&) const = 0;
|
2016-07-27 01:46:34 +00:00
|
|
|
|
2016-09-13 00:06:47 +00:00
|
|
|
virtual bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const { return false; }
|
|
|
|
|
2016-12-08 14:26:47 +00:00
|
|
|
virtual SkPath onAsPath(const SkSVGRenderContext&) const = 0;
|
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
|
2016-07-27 01:46:34 +00:00
|
|
|
|
2016-09-20 22:45:57 +00:00
|
|
|
virtual bool hasChildren() const { return false; }
|
|
|
|
|
2016-07-27 01:46:34 +00:00
|
|
|
private:
|
|
|
|
SkSVGTag fTag;
|
|
|
|
|
|
|
|
// FIXME: this should be sparse
|
|
|
|
SkSVGPresentationAttributes fPresentationAttributes;
|
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SkSVGNode_DEFINED
|