Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 SkSVGSVG_DEFINED |
| 9 | #define SkSVGSVG_DEFINED |
| 10 | |
| 11 | #include "modules/svg/include/SkSVGContainer.h" |
| 12 | #include "modules/svg/include/SkSVGTypes.h" |
| 13 | #include "src/core/SkTLazy.h" |
| 14 | |
| 15 | class SkSVGLengthContext; |
| 16 | |
| 17 | class SkSVGSVG : public SkSVGContainer { |
| 18 | public: |
Florin Malita | cdeabca | 2021-01-20 13:21:20 -0500 | [diff] [blame] | 19 | enum class Type { |
| 20 | kRoot, |
| 21 | kInner, |
| 22 | }; |
| 23 | static sk_sp<SkSVGSVG> Make(Type t = Type::kInner) { return sk_sp<SkSVGSVG>(new SkSVGSVG(t)); } |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 24 | |
Florin Malita | 385e744 | 2020-10-21 16:55:46 -0400 | [diff] [blame] | 25 | SVG_ATTR(X , SkSVGLength, SkSVGLength(0)) |
| 26 | SVG_ATTR(Y , SkSVGLength, SkSVGLength(0)) |
| 27 | SVG_ATTR(Width , SkSVGLength, SkSVGLength(100, SkSVGLength::Unit::kPercentage)) |
| 28 | SVG_ATTR(Height , SkSVGLength, SkSVGLength(100, SkSVGLength::Unit::kPercentage)) |
| 29 | SVG_ATTR(PreserveAspectRatio, SkSVGPreserveAspectRatio, SkSVGPreserveAspectRatio()) |
| 30 | |
Florin Malita | cdeabca | 2021-01-20 13:21:20 -0500 | [diff] [blame] | 31 | SVG_OPTIONAL_ATTR(ViewBox, SkSVGViewBoxType) |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 32 | |
| 33 | SkSize intrinsicSize(const SkSVGLengthContext&) const; |
| 34 | |
| 35 | protected: |
| 36 | bool onPrepareToRender(SkSVGRenderContext*) const override; |
| 37 | |
| 38 | void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override; |
| 39 | |
| 40 | private: |
Florin Malita | cdeabca | 2021-01-20 13:21:20 -0500 | [diff] [blame] | 41 | explicit SkSVGSVG(Type t) |
| 42 | : INHERITED(SkSVGTag::kSvg) |
| 43 | , fType(t) |
| 44 | {} |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 45 | |
Florin Malita | cdeabca | 2021-01-20 13:21:20 -0500 | [diff] [blame] | 46 | // Some attributes behave differently for the outermost svg element. |
| 47 | const Type fType; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 48 | |
| 49 | using INHERITED = SkSVGContainer; |
| 50 | }; |
| 51 | |
| 52 | #endif // SkSVGSVG_DEFINED |