File indexing completed on 2024-04-28 11:39:13

0001 /*
0002     Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
0003                   2004, 2005, 2006 Rob Buis <buis@kde.org>
0004 
0005     This file is part of the KDE project
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This library is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015     Library General Public License for more details.
0016 
0017     You should have received a copy of the GNU Library General Public License
0018     along with this library; see the file COPYING.LIB.  If not, write to
0019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020     Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
0024 #include "SVGFETurbulenceElement.h"
0025 
0026 #include "SVGParserUtilities.h"
0027 #include "SVGResourceFilter.h"
0028 
0029 namespace WebCore
0030 {
0031 
0032 SVGFETurbulenceElement::SVGFETurbulenceElement(const QualifiedName &tagName, Document *doc)
0033     : SVGFilterPrimitiveStandardAttributes(tagName, doc)
0034     , m_baseFrequencyX(0.0f)
0035     , m_baseFrequencyY(0.0f)
0036     , m_numOctaves(1)
0037     , m_seed(0.0f)
0038     , m_stitchTiles(SVG_STITCHTYPE_NOSTITCH)
0039     , m_type(SVG_TURBULENCE_TYPE_TURBULENCE)
0040     , m_filterEffect(0)
0041 {
0042 }
0043 
0044 SVGFETurbulenceElement::~SVGFETurbulenceElement()
0045 {
0046     delete m_filterEffect;
0047 }
0048 
0049 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFETurbulenceElement, float, Number, number, BaseFrequencyX, baseFrequencyX, SVGNames::baseFrequencyAttr, "baseFrequencyX", m_baseFrequencyX)
0050 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFETurbulenceElement, float, Number, number, BaseFrequencyY, baseFrequencyY, SVGNames::baseFrequencyAttr, "baseFrequencyY", m_baseFrequencyY)
0051 ANIMATED_PROPERTY_DEFINITIONS(SVGFETurbulenceElement, float, Number, number, Seed, seed, SVGNames::seedAttr, m_seed)
0052 ANIMATED_PROPERTY_DEFINITIONS(SVGFETurbulenceElement, long, Integer, integer, NumOctaves, numOctaves, SVGNames::numOctavesAttr, m_numOctaves)
0053 ANIMATED_PROPERTY_DEFINITIONS(SVGFETurbulenceElement, int, Enumeration, enumeration, StitchTiles, stitchTiles, SVGNames::stitchTilesAttr, m_stitchTiles)
0054 ANIMATED_PROPERTY_DEFINITIONS(SVGFETurbulenceElement, int, Enumeration, enumeration, Type, type, SVGNames::typeAttr, m_type)
0055 
0056 void SVGFETurbulenceElement::parseMappedAttribute(MappedAttribute *attr)
0057 {
0058     const String &value = attr->value();
0059     if (attr->name() == SVGNames::typeAttr) {
0060         if (value == "fractalNoise") {
0061             setTypeBaseValue(SVG_TURBULENCE_TYPE_FRACTALNOISE);
0062         } else if (value == "turbulence") {
0063             setTypeBaseValue(SVG_TURBULENCE_TYPE_TURBULENCE);
0064         }
0065     } else if (attr->name() == SVGNames::stitchTilesAttr) {
0066         if (value == "stitch") {
0067             setStitchTilesBaseValue(SVG_STITCHTYPE_STITCH);
0068         } else if (value == "nostitch") {
0069             setStitchTilesBaseValue(SVG_STITCHTYPE_NOSTITCH);
0070         }
0071     } else if (attr->name() == SVGNames::baseFrequencyAttr) {
0072         float x, y;
0073         if (parseNumberOptionalNumber(value, x, y)) {
0074             setBaseFrequencyXBaseValue(x);
0075             setBaseFrequencyYBaseValue(y);
0076         }
0077     } else if (attr->name() == SVGNames::seedAttr) {
0078         setSeedBaseValue(value.toFloat());
0079     } else if (attr->name() == SVGNames::numOctavesAttr) {
0080         setNumOctavesBaseValue(value.toUIntStrict());
0081     } else {
0082         SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
0083     }
0084 }
0085 
0086 SVGFETurbulence *SVGFETurbulenceElement::filterEffect(SVGResourceFilter *filter) const
0087 {
0088 
0089     if (!m_filterEffect) {
0090         m_filterEffect = new SVGFETurbulence(filter);
0091     }
0092 
0093     m_filterEffect->setType((SVGTurbulanceType) type());
0094     m_filterEffect->setBaseFrequencyX(baseFrequencyX());
0095     m_filterEffect->setBaseFrequencyY(baseFrequencyY());
0096     m_filterEffect->setNumOctaves(numOctaves());
0097     m_filterEffect->setSeed(seed());
0098     m_filterEffect->setStitchTiles(stitchTiles() == SVG_STITCHTYPE_STITCH);
0099 
0100     setStandardAttributes(m_filterEffect);
0101     return m_filterEffect;
0102 }
0103 
0104 }
0105 
0106 #endif // ENABLE(SVG)
0107