1 /*
2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@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 "SVGFEGaussianBlurElement.h"
25
26 #include "MappedAttribute.h"
27 #include "SVGNames.h"
28 #include "SVGParserUtilities.h"
29 #include "SVGResourceFilter.h"
30
31 namespace WebCore {
32
33 char SVGStdDeviationXAttrIdentifier[] = "SVGStdDeviationXAttr";
34 char SVGStdDeviationYAttrIdentifier[] = "SVGStdDeviationYAttr";
35
SVGFEGaussianBlurElement(const QualifiedName & tagName,Document * doc)36 SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(const QualifiedName& tagName, Document* doc)
37 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
38 {
39 }
40
~SVGFEGaussianBlurElement()41 SVGFEGaussianBlurElement::~SVGFEGaussianBlurElement()
42 {
43 }
44
setStdDeviation(float,float)45 void SVGFEGaussianBlurElement::setStdDeviation(float, float)
46 {
47 // FIXME: Needs an implementation.
48 }
49
parseMappedAttribute(MappedAttribute * attr)50 void SVGFEGaussianBlurElement::parseMappedAttribute(MappedAttribute* attr)
51 {
52 const String& value = attr->value();
53 if (attr->name() == SVGNames::stdDeviationAttr) {
54 float x, y;
55 if (parseNumberOptionalNumber(value, x, y)) {
56 setStdDeviationXBaseValue(x);
57 setStdDeviationYBaseValue(y);
58 }
59 } else if (attr->name() == SVGNames::inAttr)
60 setIn1BaseValue(value);
61 else
62 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
63 }
64
synchronizeProperty(const QualifiedName & attrName)65 void SVGFEGaussianBlurElement::synchronizeProperty(const QualifiedName& attrName)
66 {
67 SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName);
68
69 if (attrName == anyQName()) {
70 synchronizeStdDeviationX();
71 synchronizeStdDeviationY();
72 synchronizeIn1();
73 return;
74 }
75
76 if (attrName == SVGNames::stdDeviationAttr) {
77 synchronizeStdDeviationX();
78 synchronizeStdDeviationY();
79 } else if (attrName == SVGNames::inAttr)
80 synchronizeIn1();
81 }
82
build(SVGResourceFilter * filterResource)83 bool SVGFEGaussianBlurElement::build(SVGResourceFilter* filterResource)
84 {
85 FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
86
87 if (!input1)
88 return false;
89
90 RefPtr<FilterEffect> effect = FEGaussianBlur::create(input1, stdDeviationX(), stdDeviationY());
91 filterResource->addFilterEffect(this, effect.release());
92
93 return true;
94 }
95
96 }
97
98 #endif // ENABLE(SVG)
99