KHtml

SVGFETurbulenceElement.cpp
1 /*
2  Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006 Rob Buis <[email protected]>
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 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
24 #include "SVGFETurbulenceElement.h"
25 
26 #include "SVGParserUtilities.h"
27 #include "SVGResourceFilter.h"
28 
29 namespace WebCore
30 {
31 
32 SVGFETurbulenceElement::SVGFETurbulenceElement(const QualifiedName &tagName, Document *doc)
33  : SVGFilterPrimitiveStandardAttributes(tagName, doc)
34  , m_baseFrequencyX(0.0f)
35  , m_baseFrequencyY(0.0f)
36  , m_numOctaves(1)
37  , m_seed(0.0f)
38  , m_stitchTiles(SVG_STITCHTYPE_NOSTITCH)
39  , m_type(SVG_TURBULENCE_TYPE_TURBULENCE)
40  , m_filterEffect(0)
41 {
42 }
43 
44 SVGFETurbulenceElement::~SVGFETurbulenceElement()
45 {
46  delete m_filterEffect;
47 }
48 
49 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFETurbulenceElement, float, Number, number, BaseFrequencyX, baseFrequencyX, SVGNames::baseFrequencyAttr, "baseFrequencyX", m_baseFrequencyX)
50 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFETurbulenceElement, float, Number, number, BaseFrequencyY, baseFrequencyY, SVGNames::baseFrequencyAttr, "baseFrequencyY", m_baseFrequencyY)
51 ANIMATED_PROPERTY_DEFINITIONS(SVGFETurbulenceElement, float, Number, number, Seed, seed, SVGNames::seedAttr, m_seed)
52 ANIMATED_PROPERTY_DEFINITIONS(SVGFETurbulenceElement, long, Integer, integer, NumOctaves, numOctaves, SVGNames::numOctavesAttr, m_numOctaves)
53 ANIMATED_PROPERTY_DEFINITIONS(SVGFETurbulenceElement, int, Enumeration, enumeration, StitchTiles, stitchTiles, SVGNames::stitchTilesAttr, m_stitchTiles)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGFETurbulenceElement, int, Enumeration, enumeration, Type, type, SVGNames::typeAttr, m_type)
55 
56 void SVGFETurbulenceElement::parseMappedAttribute(MappedAttribute *attr)
57 {
58  const String &value = attr->value();
59  if (attr->name() == SVGNames::typeAttr) {
60  if (value == "fractalNoise") {
61  setTypeBaseValue(SVG_TURBULENCE_TYPE_FRACTALNOISE);
62  } else if (value == "turbulence") {
63  setTypeBaseValue(SVG_TURBULENCE_TYPE_TURBULENCE);
64  }
65  } else if (attr->name() == SVGNames::stitchTilesAttr) {
66  if (value == "stitch") {
67  setStitchTilesBaseValue(SVG_STITCHTYPE_STITCH);
68  } else if (value == "nostitch") {
69  setStitchTilesBaseValue(SVG_STITCHTYPE_NOSTITCH);
70  }
71  } else if (attr->name() == SVGNames::baseFrequencyAttr) {
72  float x, y;
73  if (parseNumberOptionalNumber(value, x, y)) {
74  setBaseFrequencyXBaseValue(x);
75  setBaseFrequencyYBaseValue(y);
76  }
77  } else if (attr->name() == SVGNames::seedAttr) {
78  setSeedBaseValue(value.toFloat());
79  } else if (attr->name() == SVGNames::numOctavesAttr) {
80  setNumOctavesBaseValue(value.toUIntStrict());
81  } else {
82  SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
83  }
84 }
85 
86 SVGFETurbulence *SVGFETurbulenceElement::filterEffect(SVGResourceFilter *filter) const
87 {
88 
89  if (!m_filterEffect) {
90  m_filterEffect = new SVGFETurbulence(filter);
91  }
92 
93  m_filterEffect->setType((SVGTurbulanceType) type());
94  m_filterEffect->setBaseFrequencyX(baseFrequencyX());
95  m_filterEffect->setBaseFrequencyY(baseFrequencyY());
96  m_filterEffect->setNumOctaves(numOctaves());
97  m_filterEffect->setSeed(seed());
98  m_filterEffect->setStitchTiles(stitchTiles() == SVG_STITCHTYPE_STITCH);
99 
100  setStandardAttributes(m_filterEffect);
101  return m_filterEffect;
102 }
103 
104 }
105 
106 #endif // ENABLE(SVG)
107 
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.