Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SkSVGSVG Class Reference

#include <SkSVGSVG.h>

Inheritance diagram for SkSVGSVG:
SkSVGContainer SkSVGTransformableNode SkSVGNode SkRefCnt SkRefCntBase

Public Types

enum class  Type { kRoot , kInner }
 

Public Member Functions

SkSize intrinsicSize (const SkSVGLengthContext &) const
 
void renderNode (const SkSVGRenderContext &, const SkSVGIRI &iri) const
 
- Public Member Functions inherited from SkSVGContainer
void appendChild (sk_sp< SkSVGNode >) override
 
- Public Member Functions inherited from SkSVGTransformableNode
void setTransform (const SkSVGTransformType &t)
 
- Public Member Functions inherited from SkSVGNode
 ~SkSVGNode () override
 
SkSVGTag tag () const
 
virtual void appendChild (sk_sp< SkSVGNode >)=0
 
void render (const SkSVGRenderContext &) const
 
bool asPaint (const SkSVGRenderContext &, SkPaint *) const
 
SkPath asPath (const SkSVGRenderContext &) const
 
SkRect objectBoundingBox (const SkSVGRenderContext &) const
 
void setAttribute (SkSVGAttribute, const SkSVGValue &)
 
bool setAttribute (const char *attributeName, const char *attributeValue)
 
virtual bool parseAndSetAttribute (const char *name, const char *value)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< SkSVGSVGMake (Type t=Type::kInner)
 

Protected Member Functions

bool onPrepareToRender (SkSVGRenderContext *) const override
 
void onSetAttribute (SkSVGAttribute, const SkSVGValue &) override
 
- Protected Member Functions inherited from SkSVGContainer
 SkSVGContainer (SkSVGTag)
 
void onRender (const SkSVGRenderContext &) const override
 
SkPath onAsPath (const SkSVGRenderContext &) const override
 
SkRect onObjectBoundingBox (const SkSVGRenderContext &) const override
 
bool hasChildren () const final
 
template<typename NodeType , typename Func >
void forEachChild (Func func) const
 
- Protected Member Functions inherited from SkSVGTransformableNode
 SkSVGTransformableNode (SkSVGTag)
 
bool onPrepareToRender (SkSVGRenderContext *) const override
 
void onSetAttribute (SkSVGAttribute, const SkSVGValue &) override
 
void mapToParent (SkPath *) const
 
void mapToParent (SkRect *) const
 
- Protected Member Functions inherited from SkSVGNode
 SkSVGNode (SkSVGTag)
 
virtual bool onPrepareToRender (SkSVGRenderContext *) const
 
virtual void onRender (const SkSVGRenderContext &) const =0
 
virtual bool onAsPaint (const SkSVGRenderContext &, SkPaint *) const
 
virtual SkPath onAsPath (const SkSVGRenderContext &) const =0
 
virtual void onSetAttribute (SkSVGAttribute, const SkSVGValue &)
 
virtual bool hasChildren () const
 
virtual SkRect onObjectBoundingBox (const SkSVGRenderContext &) const
 

Additional Inherited Members

- Static Protected Member Functions inherited from SkSVGNode
static SkMatrix ComputeViewboxMatrix (const SkRect &, const SkRect &, SkSVGPreserveAspectRatio)
 
- Protected Attributes inherited from SkSVGContainer
skia_private::STArray< 1, sk_sp< SkSVGNode >, truefChildren
 

Detailed Description

Definition at line 17 of file SkSVGSVG.h.

Member Enumeration Documentation

◆ Type

enum class SkSVGSVG::Type
strong
Enumerator
kRoot 
kInner 

Definition at line 19 of file SkSVGSVG.h.

19 {
20 kRoot,
21 kInner,
22 };
@ kInner
fuzzy inside, nothing outside

Member Function Documentation

◆ intrinsicSize()

SkSize SkSVGSVG::intrinsicSize ( const SkSVGLengthContext lctx) const

Definition at line 102 of file SkSVGSVG.cpp.

102 {
103 // Percentage values do not provide an intrinsic size.
104 if (fWidth.unit() == SkSVGLength::Unit::kPercentage ||
105 fHeight.unit() == SkSVGLength::Unit::kPercentage) {
106 return SkSize::Make(0, 0);
107 }
108
111}
SkScalar resolve(const SkSVGLength &, LengthType) const
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56

◆ Make()

static sk_sp< SkSVGSVG > SkSVGSVG::Make ( Type  t = Type::kInner)
inlinestatic

Definition at line 23 of file SkSVGSVG.h.

23{ return sk_sp<SkSVGSVG>(new SkSVGSVG(t)); }

◆ onPrepareToRender()

bool SkSVGSVG::onPrepareToRender ( SkSVGRenderContext ctx) const
overrideprotectedvirtual

Reimplemented from SkSVGNode.

Definition at line 29 of file SkSVGSVG.cpp.

29 {
30 // x/y are ignored for outermost svg elements
31 const auto x = fType == Type::kInner ? fX : SkSVGLength(0);
32 const auto y = fType == Type::kInner ? fY : SkSVGLength(0);
33
34 auto viewPortRect = ctx->lengthContext().resolveRect(x, y, fWidth, fHeight);
35 auto contentMatrix = SkMatrix::Translate(viewPortRect.x(), viewPortRect.y());
36 auto viewPort = SkSize::Make(viewPortRect.width(), viewPortRect.height());
37
38 if (fViewBox.isValid()) {
39 const SkRect& viewBox = *fViewBox;
40
41 // An empty viewbox disables rendering.
42 if (viewBox.isEmpty()) {
43 return false;
44 }
45
46 // A viewBox overrides the intrinsic viewport.
47 viewPort = SkSize::Make(viewBox.width(), viewBox.height());
48
49 contentMatrix.preConcat(ComputeViewboxMatrix(viewBox, viewPortRect, fPreserveAspectRatio));
50 }
51
52 if (!contentMatrix.isIdentity()) {
53 ctx->saveOnce();
54 ctx->canvas()->concat(contentMatrix);
55 }
56
57 if (viewPort != ctx->lengthContext().viewPort()) {
58 ctx->writableLengthContext()->setViewPort(viewPort);
59 }
60
61 return this->INHERITED::onPrepareToRender(ctx);
62}
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
void setViewPort(const SkSize &viewport)
SkRect resolveRect(const SkSVGLength &x, const SkSVGLength &y, const SkSVGLength &w, const SkSVGLength &h) const
const SkSize & viewPort() const
static SkMatrix ComputeViewboxMatrix(const SkRect &, const SkRect &, SkSVGPreserveAspectRatio)
Definition: SkSVGNode.cpp:132
SkSVGLengthContext * writableLengthContext()
SkCanvas * canvas() const
const SkSVGLengthContext & lengthContext() const
bool onPrepareToRender(SkSVGRenderContext *) const override
double y
double x
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
bool isEmpty() const
Definition: SkRect.h:693

◆ onSetAttribute()

void SkSVGSVG::onSetAttribute ( SkSVGAttribute  attr,
const SkSVGValue v 
)
overrideprotectedvirtual

Reimplemented from SkSVGNode.

Definition at line 64 of file SkSVGSVG.cpp.

64 {
65 switch (attr) {
67 if (const auto* x = v.as<SkSVGLengthValue>()) {
68 this->setX(*x);
69 }
70 break;
72 if (const auto* y = v.as<SkSVGLengthValue>()) {
73 this->setY(*y);
74 }
75 break;
77 if (const auto* w = v.as<SkSVGLengthValue>()) {
78 this->setWidth(*w);
79 }
80 break;
82 if (const auto* h = v.as<SkSVGLengthValue>()) {
83 this->setHeight(*h);
84 }
85 break;
87 if (const auto* vb = v.as<SkSVGViewBoxValue>()) {
88 this->setViewBox(*vb);
89 }
90 break;
92 if (const auto* par = v.as<SkSVGPreserveAspectRatioValue>()) {
93 this->setPreserveAspectRatio(*par);
94 }
95 break;
96 default:
97 this->INHERITED::onSetAttribute(attr, v);
98 }
99}
void onSetAttribute(SkSVGAttribute, const SkSVGValue &) override
const T * as() const
Definition: SkSVGValue.h:36
SkScalar w
SkScalar h

◆ renderNode()

void SkSVGSVG::renderNode ( const SkSVGRenderContext ctx,
const SkSVGIRI iri 
) const

Definition at line 13 of file SkSVGSVG.cpp.

13 {
14 SkSVGRenderContext localContext(ctx, this);
15 SkSVGRenderContext::BorrowedNode node = localContext.findNodeById(iri);
16 if (!node) {
17 return;
18 }
19
20 if (this->onPrepareToRender(&localContext)) {
21 if (this == node.get()) {
22 this->onRender(ctx);
23 } else {
24 node->render(localContext);
25 }
26 }
27}
void onRender(const SkSVGRenderContext &) const override
void render(const SkSVGRenderContext &) const
Definition: SkSVGNode.cpp:28
const SkSVGNode * get() const
bool onPrepareToRender(SkSVGRenderContext *) const override
Definition: SkSVGSVG.cpp:29

The documentation for this class was generated from the following files: