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 "SVGFECompositeElement.h"
25
26 #include "MappedAttribute.h"
27 #include "SVGNames.h"
28 #include "SVGResourceFilter.h"
29
30 namespace WebCore {
31
SVGFECompositeElement(const QualifiedName & tagName,Document * doc)32 SVGFECompositeElement::SVGFECompositeElement(const QualifiedName& tagName, Document* doc)
33 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
34 , m__operator(FECOMPOSITE_OPERATOR_OVER)
35 {
36 }
37
~SVGFECompositeElement()38 SVGFECompositeElement::~SVGFECompositeElement()
39 {
40 }
41
parseMappedAttribute(MappedAttribute * attr)42 void SVGFECompositeElement::parseMappedAttribute(MappedAttribute *attr)
43 {
44 const String& value = attr->value();
45 if (attr->name() == SVGNames::operatorAttr) {
46 if (value == "over")
47 set_operatorBaseValue(FECOMPOSITE_OPERATOR_OVER);
48 else if (value == "in")
49 set_operatorBaseValue(FECOMPOSITE_OPERATOR_IN);
50 else if (value == "out")
51 set_operatorBaseValue(FECOMPOSITE_OPERATOR_OUT);
52 else if (value == "atop")
53 set_operatorBaseValue(FECOMPOSITE_OPERATOR_ATOP);
54 else if (value == "xor")
55 set_operatorBaseValue(FECOMPOSITE_OPERATOR_XOR);
56 else if (value == "arithmetic")
57 set_operatorBaseValue(FECOMPOSITE_OPERATOR_ARITHMETIC);
58 } else if (attr->name() == SVGNames::inAttr)
59 setIn1BaseValue(value);
60 else if (attr->name() == SVGNames::in2Attr)
61 setIn2BaseValue(value);
62 else if (attr->name() == SVGNames::k1Attr)
63 setK1BaseValue(value.toFloat());
64 else if (attr->name() == SVGNames::k2Attr)
65 setK2BaseValue(value.toFloat());
66 else if (attr->name() == SVGNames::k3Attr)
67 setK3BaseValue(value.toFloat());
68 else if (attr->name() == SVGNames::k4Attr)
69 setK4BaseValue(value.toFloat());
70 else
71 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
72 }
73
synchronizeProperty(const QualifiedName & attrName)74 void SVGFECompositeElement::synchronizeProperty(const QualifiedName& attrName)
75 {
76 SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName);
77
78 if (attrName == anyQName()) {
79 synchronize_operator();
80 synchronizeIn1();
81 synchronizeIn2();
82 synchronizeK1();
83 synchronizeK2();
84 synchronizeK3();
85 synchronizeK4();
86 return;
87 }
88
89 if (attrName == SVGNames::operatorAttr)
90 synchronize_operator();
91 else if (attrName == SVGNames::inAttr)
92 synchronizeIn1();
93 else if (attrName == SVGNames::in2Attr)
94 synchronizeIn2();
95 else if (attrName == SVGNames::k1Attr)
96 synchronizeK1();
97 else if (attrName == SVGNames::k2Attr)
98 synchronizeK2();
99 else if (attrName == SVGNames::k3Attr)
100 synchronizeK3();
101 else if (attrName == SVGNames::k4Attr)
102 synchronizeK4();
103 }
104
build(SVGResourceFilter * filterResource)105 bool SVGFECompositeElement::build(SVGResourceFilter* filterResource)
106 {
107 FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
108 FilterEffect* input2 = filterResource->builder()->getEffectById(in2());
109
110 if (!input1 || !input2)
111 return false;
112
113 RefPtr<FilterEffect> effect = FEComposite::create(input1, input2, static_cast<CompositeOperationType>(_operator()),
114 k1(), k2(), k3(), k4());
115 filterResource->addFilterEffect(this, effect.release());
116
117 return true;
118 }
119
120 }
121
122 #endif // ENABLE(SVG)
123