1 /* 2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann (at) kde.org> 3 2004, 2005, 2006 Rob Buis <buis (at) kde.org> 4 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. 9 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. 14 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. 19 */ 20 21 #include "config.h" 22 23 #if ENABLE(SVG) && ENABLE(FILTERS) 24 #include "SVGFETurbulenceElement.h" 25 26 #include "MappedAttribute.h" 27 #include "SVGParserUtilities.h" 28 #include "SVGResourceFilter.h" 29 30 namespace WebCore { 31 32 char SVGBaseFrequencyXIdentifier[] = "SVGBaseFrequencyX"; 33 char SVGBaseFrequencyYIdentifier[] = "SVGBaseFrequencyY"; 34 35 SVGFETurbulenceElement::SVGFETurbulenceElement(const QualifiedName& tagName, Document* doc) 36 : SVGFilterPrimitiveStandardAttributes(tagName, doc) 37 , m_numOctaves(1) 38 , m_stitchTiles(SVG_STITCHTYPE_NOSTITCH) 39 , m_type(FETURBULENCE_TYPE_TURBULENCE) 40 { 41 } 42 43 SVGFETurbulenceElement::~SVGFETurbulenceElement() 44 { 45 } 46 47 void SVGFETurbulenceElement::parseMappedAttribute(MappedAttribute* attr) 48 { 49 const String& value = attr->value(); 50 if (attr->name() == SVGNames::typeAttr) { 51 if (value == "fractalNoise") 52 setTypeBaseValue(FETURBULENCE_TYPE_FRACTALNOISE); 53 else if (value == "turbulence") 54 setTypeBaseValue(FETURBULENCE_TYPE_TURBULENCE); 55 } else if (attr->name() == SVGNames::stitchTilesAttr) { 56 if (value == "stitch") 57 setStitchTilesBaseValue(SVG_STITCHTYPE_STITCH); 58 else if (value == "nostitch") 59 setStitchTilesBaseValue(SVG_STITCHTYPE_NOSTITCH); 60 } else if (attr->name() == SVGNames::baseFrequencyAttr) { 61 float x, y; 62 if (parseNumberOptionalNumber(value, x, y)) { 63 setBaseFrequencyXBaseValue(x); 64 setBaseFrequencyYBaseValue(y); 65 } 66 } else if (attr->name() == SVGNames::seedAttr) 67 setSeedBaseValue(value.toFloat()); 68 else if (attr->name() == SVGNames::numOctavesAttr) 69 setNumOctavesBaseValue(value.toUIntStrict()); 70 else 71 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); 72 } 73 74 void SVGFETurbulenceElement::synchronizeProperty(const QualifiedName& attrName) 75 { 76 SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); 77 78 if (attrName == anyQName()) { 79 synchronizeType(); 80 synchronizeStitchTiles(); 81 synchronizeBaseFrequencyX(); 82 synchronizeBaseFrequencyY(); 83 synchronizeSeed(); 84 synchronizeNumOctaves(); 85 return; 86 } 87 88 if (attrName == SVGNames::typeAttr) 89 synchronizeType(); 90 else if (attrName == SVGNames::stitchTilesAttr) 91 synchronizeStitchTiles(); 92 else if (attrName == SVGNames::baseFrequencyAttr) { 93 synchronizeBaseFrequencyX(); 94 synchronizeBaseFrequencyY(); 95 } else if (attrName == SVGNames::seedAttr) 96 synchronizeSeed(); 97 else if (attrName == SVGNames::numOctavesAttr) 98 synchronizeNumOctaves(); 99 } 100 101 bool SVGFETurbulenceElement::build(SVGResourceFilter* filterResource) 102 { 103 RefPtr<FilterEffect> effect = FETurbulence::create(static_cast<TurbulanceType>(type()), baseFrequencyX(), 104 baseFrequencyY(), numOctaves(), seed(), stitchTiles() == SVG_STITCHTYPE_STITCH); 105 filterResource->addFilterEffect(this, effect.release()); 106 107 return true; 108 } 109 110 } 111 112 #endif // ENABLE(SVG) 113