blob: bef8c1f5e43a9d6a4c4210c02e4084a8d11c5b9c [file] [log] [blame]
Tyler Denniston8ca46262021-02-02 16:16:21 -05001/*
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
Tyler Denniston2992fb02021-05-04 14:17:27 -040014namespace skresources {
15class ResourceProvider;
16}
17
Tyler Denniston8ca46262021-02-02 16:16:21 -050018class SkSVGImage final : public SkSVGTransformableNode {
19public:
20 static sk_sp<SkSVGImage> Make() {
21 return sk_sp<SkSVGImage>(new SkSVGImage());
22 }
23
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
Tyler Denniston2992fb02021-05-04 14:17:27 -040033 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
Tyler Denniston1f4cd072021-02-05 09:08:33 -050042 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())
Tyler Denniston8ca46262021-02-02 16:16:21 -050048
49protected:
50 bool parseAndSetAttribute(const char*, const char*) override;
51
52private:
53 SkSVGImage() : INHERITED(SkSVGTag::kImage) {}
54
Tyler Denniston8ca46262021-02-02 16:16:21 -050055 using INHERITED = SkSVGTransformableNode;
56};
57
58#endif // SkSVGImage_DEFINED