2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
23 #if ENABLE(SVG) && ENABLE(FILTERS)
24 #include "SVGFETurbulenceElement.h"
26 #include "Attribute.h"
27 #include "SVGParserUtilities.h"
31 inline SVGFETurbulenceElement::SVGFETurbulenceElement(const QualifiedName& tagName, Document* document)
32 : SVGFilterPrimitiveStandardAttributes(tagName, document)
34 , m_stitchTiles(SVG_STITCHTYPE_NOSTITCH)
35 , m_type(FETURBULENCE_TYPE_TURBULENCE)
39 PassRefPtr<SVGFETurbulenceElement> SVGFETurbulenceElement::create(const QualifiedName& tagName, Document* document)
41 return adoptRef(new SVGFETurbulenceElement(tagName, document));
44 const AtomicString& SVGFETurbulenceElement::baseFrequencyXIdentifier()
46 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGBaseFrequencyX"));
50 const AtomicString& SVGFETurbulenceElement::baseFrequencyYIdentifier()
52 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGBaseFrequencyY"));
56 void SVGFETurbulenceElement::parseMappedAttribute(Attribute* attr)
58 const String& value = attr->value();
59 if (attr->name() == SVGNames::typeAttr) {
60 if (value == "fractalNoise")
61 setTypeBaseValue(FETURBULENCE_TYPE_FRACTALNOISE);
62 else if (value == "turbulence")
63 setTypeBaseValue(FETURBULENCE_TYPE_TURBULENCE);
64 } else if (attr->name() == SVGNames::stitchTilesAttr) {
65 if (value == "stitch")
66 setStitchTilesBaseValue(SVG_STITCHTYPE_STITCH);
67 else if (value == "noStitch")
68 setStitchTilesBaseValue(SVG_STITCHTYPE_NOSTITCH);
69 } else if (attr->name() == SVGNames::baseFrequencyAttr) {
71 if (parseNumberOptionalNumber(value, x, y)) {
72 setBaseFrequencyXBaseValue(x);
73 setBaseFrequencyYBaseValue(y);
75 } else if (attr->name() == SVGNames::seedAttr)
76 setSeedBaseValue(value.toFloat());
77 else if (attr->name() == SVGNames::numOctavesAttr)
78 setNumOctavesBaseValue(value.toUIntStrict());
80 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
83 void SVGFETurbulenceElement::svgAttributeChanged(const QualifiedName& attrName)
85 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
87 if (attrName == SVGNames::baseFrequencyAttr
88 || attrName == SVGNames::numOctavesAttr
89 || attrName == SVGNames::seedAttr
90 || attrName == SVGNames::stitchTilesAttr
91 || attrName == SVGNames::typeAttr)
95 void SVGFETurbulenceElement::synchronizeProperty(const QualifiedName& attrName)
97 SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName);
99 if (attrName == anyQName()) {
101 synchronizeStitchTiles();
102 synchronizeBaseFrequencyX();
103 synchronizeBaseFrequencyY();
105 synchronizeNumOctaves();
109 if (attrName == SVGNames::typeAttr)
111 else if (attrName == SVGNames::stitchTilesAttr)
112 synchronizeStitchTiles();
113 else if (attrName == SVGNames::baseFrequencyAttr) {
114 synchronizeBaseFrequencyX();
115 synchronizeBaseFrequencyY();
116 } else if (attrName == SVGNames::seedAttr)
118 else if (attrName == SVGNames::numOctavesAttr)
119 synchronizeNumOctaves();
122 PassRefPtr<FilterEffect> SVGFETurbulenceElement::build(SVGFilterBuilder*)
124 if (baseFrequencyX() < 0 || baseFrequencyY() < 0)
127 return FETurbulence::create(static_cast<TurbulanceType>(type()), baseFrequencyX(),
128 baseFrequencyY(), numOctaves(), seed(), stitchTiles() == SVG_STITCHTYPE_STITCH);
133 #endif // ENABLE(SVG)