Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 SkSVGPattern_DEFINED |
| 9 | #define SkSVGPattern_DEFINED |
| 10 | |
| 11 | #include "modules/svg/include/SkSVGHiddenContainer.h" |
| 12 | #include "modules/svg/include/SkSVGTypes.h" |
| 13 | |
| 14 | class SkSVGRenderContext; |
| 15 | |
| 16 | class SkSVGPattern final : public SkSVGHiddenContainer { |
| 17 | public: |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 18 | static sk_sp<SkSVGPattern> Make() { |
| 19 | return sk_sp<SkSVGPattern>(new SkSVGPattern()); |
| 20 | } |
| 21 | |
Tyler Denniston | e71f547 | 2021-01-27 13:30:59 -0500 | [diff] [blame^] | 22 | SVG_ATTR(Href, SkSVGIRI, SkSVGIRI()) |
| 23 | |
| 24 | // TODO: change rest of attributes to SVG_OPTIONAL_ATTR |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 25 | void setX(const SkSVGLength&); |
| 26 | void setY(const SkSVGLength&); |
| 27 | void setWidth(const SkSVGLength&); |
| 28 | void setHeight(const SkSVGLength&); |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 29 | void setPatternTransform(const SkSVGTransformType&); |
| 30 | |
| 31 | protected: |
| 32 | SkSVGPattern(); |
| 33 | |
Tyler Denniston | e71f547 | 2021-01-27 13:30:59 -0500 | [diff] [blame^] | 34 | bool parseAndSetAttribute(const char*, const char*) override; |
| 35 | |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 36 | void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override; |
| 37 | |
| 38 | bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const override; |
| 39 | |
| 40 | private: |
| 41 | struct PatternAttributes { |
| 42 | SkTLazy<SkSVGLength> fX, |
| 43 | fY, |
| 44 | fWidth, |
| 45 | fHeight; |
| 46 | SkTLazy<SkSVGTransformType> fPatternTransform; |
| 47 | } fAttributes; |
| 48 | |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 49 | const SkSVGPattern* resolveHref(const SkSVGRenderContext&, PatternAttributes*) const; |
| 50 | const SkSVGPattern* hrefTarget(const SkSVGRenderContext&) const; |
| 51 | |
| 52 | // TODO: |
| 53 | // - patternUnits |
| 54 | // - patternContentUnits |
| 55 | |
| 56 | using INHERITED = SkSVGHiddenContainer; |
| 57 | }; |
| 58 | |
| 59 | #endif // SkSVGPattern_DEFINED |