| 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 "include/core/SkRefCnt.h" |
| 12 |
#include "include/private/base/SkAPI.h" |
| 13 |
#include "modules/svg/include/SkSVGHiddenContainer.h" |
| 14 |
#include "modules/svg/include/SkSVGNode.h" |
| 15 |
#include "modules/svg/include/SkSVGTypes.h" |
| 16 |
|
| 17 |
#include <optional> |
| 18 |
|
| 19 |
class SkPaint; |
| 20 |
class SkSVGRenderContext; |
| 21 |
|
| 22 |
class SK_API SkSVGPattern final : public SkSVGHiddenContainer { |
| 23 |
public: |
| 24 |
static sk_sp<SkSVGPattern> Make() { |
| 25 |
return sk_sp<SkSVGPattern>(new SkSVGPattern()); |
| 26 |
} |
| 27 |
|
| 28 |
SVG_ATTR(Href, SkSVGIRI, SkSVGIRI()) |
| 29 |
SVG_OPTIONAL_ATTR(X , SkSVGLength) |
| 30 |
SVG_OPTIONAL_ATTR(Y , SkSVGLength) |
| 31 |
SVG_OPTIONAL_ATTR(Width , SkSVGLength) |
| 32 |
SVG_OPTIONAL_ATTR(Height , SkSVGLength) |
| 33 |
SVG_OPTIONAL_ATTR(PatternTransform, SkSVGTransformType) |
| 34 |
|
| 35 |
protected: |
| 36 |
SkSVGPattern(); |
| 37 |
|
| 38 |
bool parseAndSetAttribute(const char*, const char*) override; |
| 39 |
|
| 40 |
bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const override; |
| 41 |
|
| 42 |
private: |
| 43 |
struct PatternAttributes { |
| 44 |
std::optional<SkSVGLength> fX, |
| 45 |
fY, |
| 46 |
fWidth, |
| 47 |
fHeight; |
| 48 |
std::optional<SkSVGTransformType> fPatternTransform; |
| 49 |
}; |
| 50 |
|
| 51 |
const SkSVGPattern* resolveHref(const SkSVGRenderContext&, PatternAttributes*) const; |
| 52 |
const SkSVGPattern* hrefTarget(const SkSVGRenderContext&) const; |
| 53 |
|
| 54 |
// TODO: |
| 55 |
// - patternUnits |
| 56 |
// - patternContentUnits |
| 57 |
|
| 58 |
using INHERITED = SkSVGHiddenContainer; |
| 59 |
}; |
| 60 |
|
| 61 |
#endif // SkSVGPattern_DEFINED |