2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 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 "MappedAttribute.h"
27 #include "SVGParserUtilities.h"
28 #include "SVGResourceFilter.h"
32 char SVGBaseFrequencyXIdentifier
[] = "SVGBaseFrequencyX";
33 char SVGBaseFrequencyYIdentifier
[] = "SVGBaseFrequencyY";
35 SVGFETurbulenceElement::SVGFETurbulenceElement(const QualifiedName
& tagName
, Document
* doc
)
36 : SVGFilterPrimitiveStandardAttributes(tagName
, doc
)
37 , m_baseFrequencyX(this, SVGNames::baseFrequencyAttr
)
38 , m_baseFrequencyY(this, SVGNames::baseFrequencyAttr
)
39 , m_numOctaves(this, SVGNames::numOctavesAttr
, 1)
40 , m_seed(this, SVGNames::seedAttr
)
41 , m_stitchTiles(this, SVGNames::stitchTilesAttr
, SVG_STITCHTYPE_NOSTITCH
)
42 , m_type(this, SVGNames::typeAttr
, FETURBULENCE_TYPE_TURBULENCE
)
46 SVGFETurbulenceElement::~SVGFETurbulenceElement()
50 void SVGFETurbulenceElement::parseMappedAttribute(MappedAttribute
* attr
)
52 const String
& value
= attr
->value();
53 if (attr
->name() == SVGNames::typeAttr
) {
54 if (value
== "fractalNoise")
55 setTypeBaseValue(FETURBULENCE_TYPE_FRACTALNOISE
);
56 else if (value
== "turbulence")
57 setTypeBaseValue(FETURBULENCE_TYPE_TURBULENCE
);
58 } else if (attr
->name() == SVGNames::stitchTilesAttr
) {
59 if (value
== "stitch")
60 setStitchTilesBaseValue(SVG_STITCHTYPE_STITCH
);
61 else if (value
== "nostitch")
62 setStitchTilesBaseValue(SVG_STITCHTYPE_NOSTITCH
);
63 } else if (attr
->name() == SVGNames::baseFrequencyAttr
) {
65 if (parseNumberOptionalNumber(value
, x
, y
)) {
66 setBaseFrequencyXBaseValue(x
);
67 setBaseFrequencyYBaseValue(y
);
69 } else if (attr
->name() == SVGNames::seedAttr
)
70 setSeedBaseValue(value
.toFloat());
71 else if (attr
->name() == SVGNames::numOctavesAttr
)
72 setNumOctavesBaseValue(value
.toUIntStrict());
74 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr
);
77 bool SVGFETurbulenceElement::build(SVGResourceFilter
* filterResource
)
79 RefPtr
<FilterEffect
> effect
= FETurbulence::create(static_cast<TurbulanceType
>(type()), baseFrequencyX(),
80 baseFrequencyY(), numOctaves(), seed(), stitchTiles() == SVG_STITCHTYPE_STITCH
);
81 filterResource
->addFilterEffect(this, effect
.release());