blob: e2683876fa842a68d2b030323ff053d663ed5f48 [file] [log] [blame]
Florin Malitab3418102020-10-15 18:10:29 -04001/*
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
14class SkSVGRenderContext;
15
16class SkSVGPattern final : public SkSVGHiddenContainer {
17public:
Florin Malitab3418102020-10-15 18:10:29 -040018 static sk_sp<SkSVGPattern> Make() {
19 return sk_sp<SkSVGPattern>(new SkSVGPattern());
20 }
21
Tyler Dennistone71f5472021-01-27 13:30:59 -050022 SVG_ATTR(Href, SkSVGIRI, SkSVGIRI())
23
24 // TODO: change rest of attributes to SVG_OPTIONAL_ATTR
Florin Malitab3418102020-10-15 18:10:29 -040025 void setX(const SkSVGLength&);
26 void setY(const SkSVGLength&);
27 void setWidth(const SkSVGLength&);
28 void setHeight(const SkSVGLength&);
Florin Malitab3418102020-10-15 18:10:29 -040029 void setPatternTransform(const SkSVGTransformType&);
30
31protected:
32 SkSVGPattern();
33
Tyler Dennistone71f5472021-01-27 13:30:59 -050034 bool parseAndSetAttribute(const char*, const char*) override;
35
Florin Malitab3418102020-10-15 18:10:29 -040036 void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
37
38 bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const override;
39
40private:
41 struct PatternAttributes {
42 SkTLazy<SkSVGLength> fX,
43 fY,
44 fWidth,
45 fHeight;
46 SkTLazy<SkSVGTransformType> fPatternTransform;
47 } fAttributes;
48
Florin Malitab3418102020-10-15 18:10:29 -040049 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