1 | /* |
2 | * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
3 | * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
4 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public License |
17 | * along with this library; see the file COPYING.LIB. If not, write to |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #pragma once |
23 | |
24 | #include "FETurbulence.h" |
25 | #include "SVGFilterPrimitiveStandardAttributes.h" |
26 | |
27 | namespace WebCore { |
28 | |
29 | enum SVGStitchOptions { |
30 | SVG_STITCHTYPE_UNKNOWN = 0, |
31 | SVG_STITCHTYPE_STITCH = 1, |
32 | SVG_STITCHTYPE_NOSTITCH = 2 |
33 | }; |
34 | |
35 | template<> |
36 | struct SVGPropertyTraits<SVGStitchOptions> { |
37 | static unsigned highestEnumValue() { return SVG_STITCHTYPE_NOSTITCH; } |
38 | |
39 | static String toString(SVGStitchOptions type) |
40 | { |
41 | switch (type) { |
42 | case SVG_STITCHTYPE_UNKNOWN: |
43 | return emptyString(); |
44 | case SVG_STITCHTYPE_STITCH: |
45 | return "stitch"_s ; |
46 | case SVG_STITCHTYPE_NOSTITCH: |
47 | return "noStitch"_s ; |
48 | } |
49 | |
50 | ASSERT_NOT_REACHED(); |
51 | return emptyString(); |
52 | } |
53 | |
54 | static SVGStitchOptions fromString(const String& value) |
55 | { |
56 | if (value == "stitch" ) |
57 | return SVG_STITCHTYPE_STITCH; |
58 | if (value == "noStitch" ) |
59 | return SVG_STITCHTYPE_NOSTITCH; |
60 | return SVG_STITCHTYPE_UNKNOWN; |
61 | } |
62 | }; |
63 | |
64 | template<> |
65 | struct SVGPropertyTraits<TurbulenceType> { |
66 | static unsigned highestEnumValue() { return static_cast<unsigned>(TurbulenceType::Turbulence); } |
67 | |
68 | static String toString(TurbulenceType type) |
69 | { |
70 | switch (type) { |
71 | case TurbulenceType::Unknown: |
72 | return emptyString(); |
73 | case TurbulenceType::FractalNoise: |
74 | return "fractalNoise"_s ; |
75 | case TurbulenceType::Turbulence: |
76 | return "turbulence"_s ; |
77 | } |
78 | |
79 | ASSERT_NOT_REACHED(); |
80 | return emptyString(); |
81 | } |
82 | |
83 | static TurbulenceType fromString(const String& value) |
84 | { |
85 | if (value == "fractalNoise" ) |
86 | return TurbulenceType::FractalNoise; |
87 | if (value == "turbulence" ) |
88 | return TurbulenceType::Turbulence; |
89 | return TurbulenceType::Unknown; |
90 | } |
91 | }; |
92 | |
93 | class SVGFETurbulenceElement final : public SVGFilterPrimitiveStandardAttributes { |
94 | WTF_MAKE_ISO_ALLOCATED(SVGFETurbulenceElement); |
95 | public: |
96 | static Ref<SVGFETurbulenceElement> create(const QualifiedName&, Document&); |
97 | |
98 | float baseFrequencyX() const { return m_baseFrequencyX->currentValue(); } |
99 | float baseFrequencyY() const { return m_baseFrequencyY->currentValue(); } |
100 | int numOctaves() const { return m_numOctaves->currentValue(); } |
101 | float seed() const { return m_seed->currentValue(); } |
102 | SVGStitchOptions stitchTiles() const { return m_stitchTiles->currentValue<SVGStitchOptions>(); } |
103 | TurbulenceType type() const { return m_type->currentValue<TurbulenceType>(); } |
104 | |
105 | SVGAnimatedNumber& baseFrequencyXAnimated() { return m_baseFrequencyX; } |
106 | SVGAnimatedNumber& baseFrequencyYAnimated() { return m_baseFrequencyY; } |
107 | SVGAnimatedInteger& numOctavesAnimated() { return m_numOctaves; } |
108 | SVGAnimatedNumber& seedAnimated() { return m_seed; } |
109 | SVGAnimatedEnumeration& stitchTilesAnimated() { return m_stitchTiles; } |
110 | SVGAnimatedEnumeration& typeAnimated() { return m_type; } |
111 | |
112 | private: |
113 | SVGFETurbulenceElement(const QualifiedName&, Document&); |
114 | |
115 | using PropertyRegistry = SVGPropertyOwnerRegistry<SVGFETurbulenceElement, SVGFilterPrimitiveStandardAttributes>; |
116 | const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; } |
117 | |
118 | void parseAttribute(const QualifiedName&, const AtomicString&) override; |
119 | void svgAttributeChanged(const QualifiedName&) override; |
120 | |
121 | bool setFilterEffectAttribute(FilterEffect*, const QualifiedName& attrName) override; |
122 | RefPtr<FilterEffect> build(SVGFilterBuilder*, Filter&) const override; |
123 | |
124 | PropertyRegistry m_propertyRegistry { *this }; |
125 | Ref<SVGAnimatedNumber> m_baseFrequencyX { SVGAnimatedNumber::create(this) }; |
126 | Ref<SVGAnimatedNumber> m_baseFrequencyY { SVGAnimatedNumber::create(this) }; |
127 | Ref<SVGAnimatedInteger> m_numOctaves { SVGAnimatedInteger::create(this, 1) }; |
128 | Ref<SVGAnimatedNumber> m_seed { SVGAnimatedNumber::create(this) }; |
129 | Ref<SVGAnimatedEnumeration> m_stitchTiles { SVGAnimatedEnumeration::create(this, SVG_STITCHTYPE_NOSTITCH) }; |
130 | Ref<SVGAnimatedEnumeration> m_type { SVGAnimatedEnumeration::create(this, TurbulenceType::Turbulence) }; |
131 | }; |
132 | |
133 | } // namespace WebCore |
134 | |