Tyler Denniston | 8ca4626 | 2021-02-02 16:16:21 -0500 | [diff] [blame] | 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 | |
Tyler Denniston | 2992fb0 | 2021-05-04 14:17:27 -0400 | [diff] [blame] | 14 | namespace skresources { |
| 15 | class ResourceProvider; |
| 16 | } |
| 17 | |
Tyler Denniston | 8ca4626 | 2021-02-02 16:16:21 -0500 | [diff] [blame] | 18 | class SkSVGImage final : public SkSVGTransformableNode { |
| 19 | public: |
| 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 Denniston | 2992fb0 | 2021-05-04 14:17:27 -0400 | [diff] [blame] | 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 | |
Tyler Denniston | 1f4cd07 | 2021-02-05 09:08:33 -0500 | [diff] [blame] | 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()) |
Tyler Denniston | 8ca4626 | 2021-02-02 16:16:21 -0500 | [diff] [blame] | 48 | |
| 49 | protected: |
| 50 | bool parseAndSetAttribute(const char*, const char*) override; |
| 51 | |
| 52 | private: |
| 53 | SkSVGImage() : INHERITED(SkSVGTag::kImage) {} |
| 54 | |
Tyler Denniston | 8ca4626 | 2021-02-02 16:16:21 -0500 | [diff] [blame] | 55 | using INHERITED = SkSVGTransformableNode; |
| 56 | }; |
| 57 | |
| 58 | #endif // SkSVGImage_DEFINED |