1 /* 2 * Copyright 2021 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 SkSVGImage_DEFINED 9 #define SkSVGImage_DEFINED 10 11 #include "modules/svg/include/SkSVGTransformableNode.h" 12 #include "modules/svg/include/SkSVGTypes.h" 13 14 namespace skresources { 15 class ResourceProvider; 16 } 17 18 class SkSVGImage final : public SkSVGTransformableNode { 19 public: Make()20 static sk_sp<SkSVGImage> Make() { 21 return sk_sp<SkSVGImage>(new SkSVGImage()); 22 } 23 appendChild(sk_sp<SkSVGNode>)24 void appendChild(sk_sp<SkSVGNode>) override { 25 SkDebugf("cannot append child nodes to this element.\n"); 26 } 27 28 bool onPrepareToRender(SkSVGRenderContext*) const override; 29 void onRender(const SkSVGRenderContext&) const override; 30 SkPath onAsPath(const SkSVGRenderContext&) const override; 31 SkRect onObjectBoundingBox(const SkSVGRenderContext&) const override; 32 33 struct ImageInfo { 34 sk_sp<SkImage> fImage; 35 SkRect fDst; 36 }; 37 static ImageInfo LoadImage(const sk_sp<skresources::ResourceProvider>&, 38 const SkSVGIRI&, 39 const SkRect&, 40 SkSVGPreserveAspectRatio); 41 42 SVG_ATTR(X , SkSVGLength , SkSVGLength(0)) 43 SVG_ATTR(Y , SkSVGLength , SkSVGLength(0)) 44 SVG_ATTR(Width , SkSVGLength , SkSVGLength(0)) 45 SVG_ATTR(Height , SkSVGLength , SkSVGLength(0)) 46 SVG_ATTR(Href , SkSVGIRI , SkSVGIRI()) 47 SVG_ATTR(PreserveAspectRatio, SkSVGPreserveAspectRatio, SkSVGPreserveAspectRatio()) 48 49 protected: 50 bool parseAndSetAttribute(const char*, const char*) override; 51 52 private: SkSVGImage()53 SkSVGImage() : INHERITED(SkSVGTag::kImage) {} 54 55 using INHERITED = SkSVGTransformableNode; 56 }; 57 58 #endif // SkSVGImage_DEFINED 59