• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13 
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19 
20 #include "config.h"
21 
22 #if ENABLE(SVG) && ENABLE(FILTERS)
23 #include "SVGFEMorphologyElement.h"
24 
25 #include "MappedAttribute.h"
26 #include "SVGNames.h"
27 #include "SVGParserUtilities.h"
28 #include "SVGResourceFilter.h"
29 
30 namespace WebCore {
31 
32 char SVGRadiusXAttrIdentifier[] = "SVGRadiusXAttr";
33 char SVGRadiusYAttrIdentifier[] = "SVGRadiusYAttr";
34 
SVGFEMorphologyElement(const QualifiedName & tagName,Document * document)35 SVGFEMorphologyElement::SVGFEMorphologyElement(const QualifiedName& tagName, Document* document)
36     : SVGFilterPrimitiveStandardAttributes(tagName, document)
37     , m__operator(FEMORPHOLOGY_OPERATOR_ERODE)
38 {
39 }
40 
~SVGFEMorphologyElement()41 SVGFEMorphologyElement::~SVGFEMorphologyElement()
42 {
43 }
44 
setRadius(float,float)45 void SVGFEMorphologyElement::setRadius(float, float)
46 {
47     // FIXME: Needs an implementation.
48 }
49 
parseMappedAttribute(MappedAttribute * attr)50 void SVGFEMorphologyElement::parseMappedAttribute(MappedAttribute* attr)
51 {
52     const String& value = attr->value();
53     if (attr->name() == SVGNames::operatorAttr) {
54         if (value == "erode")
55             set_operatorBaseValue(FEMORPHOLOGY_OPERATOR_ERODE);
56         else if (value == "dilate")
57             set_operatorBaseValue(FEMORPHOLOGY_OPERATOR_DILATE);
58     } else if (attr->name() == SVGNames::inAttr)
59         setIn1BaseValue(value);
60     else if (attr->name() == SVGNames::radiusAttr) {
61         float x, y;
62         if (parseNumberOptionalNumber(value, x, y)) {
63             setRadiusXBaseValue(x);
64             setRadiusYBaseValue(y);
65         }
66     } else
67         SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
68 }
69 
synchronizeProperty(const QualifiedName & attrName)70 void SVGFEMorphologyElement::synchronizeProperty(const QualifiedName& attrName)
71 {
72     SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName);
73 
74     if (attrName == anyQName()) {
75         synchronize_operator();
76         synchronizeIn1();
77         synchronizeRadiusX();
78         synchronizeRadiusY();
79         return;
80     }
81 
82     if (attrName == SVGNames::operatorAttr)
83         synchronize_operator();
84     else if (attrName == SVGNames::inAttr)
85         synchronizeIn1();
86     else if (attrName == SVGNames::radiusAttr) {
87         synchronizeRadiusX();
88         synchronizeRadiusY();
89     }
90 }
91 
build(SVGResourceFilter * filterResource)92 bool SVGFEMorphologyElement::build(SVGResourceFilter* filterResource)
93 {
94     FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
95 
96     if (!input1)
97         return false;
98 
99     RefPtr<FilterEffect> effect = FEMorphology::create(input1, static_cast<MorphologyOperatorType>(_operator()), radiusX(), radiusY());
100     filterResource->addFilterEffect(this, effect.release());
101 
102     return true;
103 }
104 
105 } //namespace WebCore
106 
107 #endif // ENABLE(SVG)
108