Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SkSVGImage Class Referencefinal

#include <SkSVGImage.h>

Inheritance diagram for SkSVGImage:
SkSVGTransformableNode SkSVGNode SkRefCnt SkRefCntBase

Classes

struct  ImageInfo
 

Public Member Functions

void appendChild (sk_sp< SkSVGNode >) override
 
bool onPrepareToRender (SkSVGRenderContext *) const override
 
void onRender (const SkSVGRenderContext &) const override
 
SkPath onAsPath (const SkSVGRenderContext &) const override
 
SkRect onObjectBoundingBox (const SkSVGRenderContext &) const 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< SkSVGImageMake ()
 
static ImageInfo LoadImage (const sk_sp< skresources::ResourceProvider > &, const SkSVGIRI &, const SkRect &, SkSVGPreserveAspectRatio)
 

Protected Member Functions

bool parseAndSetAttribute (const char *, const char *) override
 
- 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)
 

Detailed Description

Definition at line 18 of file SkSVGImage.h.

Member Function Documentation

◆ appendChild()

void SkSVGImage::appendChild ( sk_sp< SkSVGNode )
inlineoverridevirtual

Implements SkSVGNode.

Definition at line 24 of file SkSVGImage.h.

24 {
25 SkDebugf("cannot append child nodes to this element.\n");
26 }
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1

◆ LoadImage()

SkSVGImage::ImageInfo SkSVGImage::LoadImage ( const sk_sp< skresources::ResourceProvider > &  rp,
const SkSVGIRI iri,
const SkRect viewPort,
SkSVGPreserveAspectRatio  par 
)
static

Definition at line 57 of file SkSVGImage.cpp.

60 {
61 SkASSERT(rp);
62
63 // TODO: svg sources
65 if (!image) {
66 return {};
67 }
68
69 // Per spec: raster content has implicit viewbox of '0 0 width height'.
70 const SkRect viewBox = SkRect::Make(image->bounds());
71
72 // Map and place at x, y specified by viewport
73 const SkMatrix m = ComputeViewboxMatrix(viewBox, viewPort, par);
74 const SkRect dst = m.mapRect(viewBox).makeOffset(viewPort.fLeft, viewPort.fTop);
75
76 return {std::move(image), dst};
77}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkIRect bounds() const
Definition: SkImage.h:303
static ImageInfo LoadImage(const sk_sp< skresources::ResourceProvider > &, const SkSVGIRI &, const SkRect &, SkSVGPreserveAspectRatio)
Definition: SkSVGImage.cpp:57
static SkMatrix ComputeViewboxMatrix(const SkRect &, const SkRect &, SkSVGPreserveAspectRatio)
Definition: SkSVGNode.cpp:132
sk_sp< const SkImage > image
Definition: SkRecords.h:269
dst
Definition: cp.py:12
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ Make()

static sk_sp< SkSVGImage > SkSVGImage::Make ( )
inlinestatic

Definition at line 20 of file SkSVGImage.h.

20 {
21 return sk_sp<SkSVGImage>(new SkSVGImage());
22 }

◆ onAsPath()

SkPath SkSVGImage::onAsPath ( const SkSVGRenderContext ) const
overridevirtual

Implements SkSVGNode.

Definition at line 95 of file SkSVGImage.cpp.

95{ return {}; }

◆ onObjectBoundingBox()

SkRect SkSVGImage::onObjectBoundingBox ( const SkSVGRenderContext ctx) const
overridevirtual

Reimplemented from SkSVGNode.

Definition at line 97 of file SkSVGImage.cpp.

97 {
98 const SkSVGLengthContext& lctx = ctx.lengthContext();
99 return lctx.resolveRect(fX, fY, fWidth, fHeight);
100}
SkRect resolveRect(const SkSVGLength &x, const SkSVGLength &y, const SkSVGLength &w, const SkSVGLength &h) const
const SkSVGLengthContext & lengthContext() const

◆ onPrepareToRender()

bool SkSVGImage::onPrepareToRender ( SkSVGRenderContext ctx) const
overridevirtual

Reimplemented from SkSVGNode.

Definition at line 27 of file SkSVGImage.cpp.

27 {
28 // Width or height of 0 disables rendering per spec:
29 // https://www.w3.org/TR/SVG11/struct.html#ImageElement
30 return !fHref.iri().isEmpty() && fWidth.value() > 0 && fHeight.value() > 0 &&
32}
bool onPrepareToRender(SkSVGRenderContext *) const override

◆ onRender()

void SkSVGImage::onRender ( const SkSVGRenderContext ctx) const
overridevirtual

Implements SkSVGNode.

Definition at line 79 of file SkSVGImage.cpp.

79 {
80 // Per spec: x, w, width, height attributes establish the new viewport.
81 const SkSVGLengthContext& lctx = ctx.lengthContext();
82 const SkRect viewPort = lctx.resolveRect(fX, fY, fWidth, fHeight);
83
84 const auto imgInfo = LoadImage(ctx.resourceProvider(), fHref, viewPort, fPreserveAspectRatio);
85 if (!imgInfo.fImage) {
86 SkDebugf("can't render image: load image failed\n");
87 return;
88 }
89
90 // TODO: image-rendering property
91 ctx.canvas()->drawImageRect(
92 imgInfo.fImage, imgInfo.fDst, SkSamplingOptions(SkFilterMode::kLinear));
93}
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
SkCanvas * canvas() const
const sk_sp< skresources::ResourceProvider > & resourceProvider() const

◆ parseAndSetAttribute()

bool SkSVGImage::parseAndSetAttribute ( const char *  n,
const char *  v 
)
overrideprotectedvirtual

Reimplemented from SkSVGNode.

Definition at line 16 of file SkSVGImage.cpp.

16 {
18 this->setX(SkSVGAttributeParser::parse<SkSVGLength>("x", n, v)) ||
19 this->setY(SkSVGAttributeParser::parse<SkSVGLength>("y", n, v)) ||
20 this->setWidth(SkSVGAttributeParser::parse<SkSVGLength>("width", n, v)) ||
21 this->setHeight(SkSVGAttributeParser::parse<SkSVGLength>("height", n, v)) ||
22 this->setHref(SkSVGAttributeParser::parse<SkSVGIRI>("xlink:href", n, v)) ||
23 this->setPreserveAspectRatio(SkSVGAttributeParser::parse<SkSVGPreserveAspectRatio>(
24 "preserveAspectRatio", n, v));
25}
virtual bool parseAndSetAttribute(const char *name, const char *value)
Definition: SkSVGNode.cpp:90

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