1 /*
2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
4
5 This file is part of the KDE project
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21 */
22
23 #include "config.h"
24
25 #if ENABLE(SVG) && ENABLE(FILTERS)
26 #include "SVGFETurbulenceElement.h"
27
28 #include "MappedAttribute.h"
29 #include "SVGParserUtilities.h"
30 #include "SVGResourceFilter.h"
31
32 namespace WebCore {
33
34 char SVGBaseFrequencyXIdentifier[] = "SVGBaseFrequencyX";
35 char SVGBaseFrequencyYIdentifier[] = "SVGBaseFrequencyY";
36
SVGFETurbulenceElement(const QualifiedName & tagName,Document * doc)37 SVGFETurbulenceElement::SVGFETurbulenceElement(const QualifiedName& tagName, Document* doc)
38 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
39 , m_baseFrequencyX(this, SVGNames::baseFrequencyAttr)
40 , m_baseFrequencyY(this, SVGNames::baseFrequencyAttr)
41 , m_numOctaves(this, SVGNames::numOctavesAttr, 1)
42 , m_seed(this, SVGNames::seedAttr)
43 , m_stitchTiles(this, SVGNames::stitchTilesAttr, SVG_STITCHTYPE_NOSTITCH)
44 , m_type(this, SVGNames::typeAttr, FETURBULENCE_TYPE_TURBULENCE)
45 {
46 }
47
~SVGFETurbulenceElement()48 SVGFETurbulenceElement::~SVGFETurbulenceElement()
49 {
50 }
51
parseMappedAttribute(MappedAttribute * attr)52 void SVGFETurbulenceElement::parseMappedAttribute(MappedAttribute* attr)
53 {
54 const String& value = attr->value();
55 if (attr->name() == SVGNames::typeAttr) {
56 if (value == "fractalNoise")
57 setTypeBaseValue(FETURBULENCE_TYPE_FRACTALNOISE);
58 else if (value == "turbulence")
59 setTypeBaseValue(FETURBULENCE_TYPE_TURBULENCE);
60 } else if (attr->name() == SVGNames::stitchTilesAttr) {
61 if (value == "stitch")
62 setStitchTilesBaseValue(SVG_STITCHTYPE_STITCH);
63 else if (value == "nostitch")
64 setStitchTilesBaseValue(SVG_STITCHTYPE_NOSTITCH);
65 } else if (attr->name() == SVGNames::baseFrequencyAttr) {
66 float x, y;
67 if (parseNumberOptionalNumber(value, x, y)) {
68 setBaseFrequencyXBaseValue(x);
69 setBaseFrequencyYBaseValue(y);
70 }
71 } else if (attr->name() == SVGNames::seedAttr)
72 setSeedBaseValue(value.toFloat());
73 else if (attr->name() == SVGNames::numOctavesAttr)
74 setNumOctavesBaseValue(value.toUIntStrict());
75 else
76 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
77 }
78
build(SVGResourceFilter * filterResource)79 bool SVGFETurbulenceElement::build(SVGResourceFilter* filterResource)
80 {
81 RefPtr<FilterEffect> effect = FETurbulence::create(static_cast<TurbulanceType>(type()), baseFrequencyX(),
82 baseFrequencyY(), numOctaves(), seed(), stitchTiles() == SVG_STITCHTYPE_STITCH);
83 filterResource->addFilterEffect(this, effect.release());
84
85 return true;
86 }
87
88 }
89
90 #endif // ENABLE(SVG)
91