• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3                   2004, 2005, 2006 Rob Buis <buis@kde.org>
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 #include "config.h"
24 
25 #if ENABLE(SVG) && ENABLE(FILTERS)
26 #include "SVGFECompositeElement.h"
27 
28 #include "MappedAttribute.h"
29 #include "SVGNames.h"
30 #include "SVGResourceFilter.h"
31 
32 namespace WebCore {
33 
SVGFECompositeElement(const QualifiedName & tagName,Document * doc)34 SVGFECompositeElement::SVGFECompositeElement(const QualifiedName& tagName, Document* doc)
35     : SVGFilterPrimitiveStandardAttributes(tagName, doc)
36     , m_in1(this, SVGNames::inAttr)
37     , m_in2(this, SVGNames::in2Attr)
38     , m__operator(this, SVGNames::operatorAttr, FECOMPOSITE_OPERATOR_OVER)
39     , m_k1(this, SVGNames::k1Attr)
40     , m_k2(this, SVGNames::k2Attr)
41     , m_k3(this, SVGNames::k3Attr)
42     , m_k4(this, SVGNames::k4Attr)
43 {
44 }
45 
~SVGFECompositeElement()46 SVGFECompositeElement::~SVGFECompositeElement()
47 {
48 }
49 
parseMappedAttribute(MappedAttribute * attr)50 void SVGFECompositeElement::parseMappedAttribute(MappedAttribute *attr)
51 {
52     const String& value = attr->value();
53     if (attr->name() == SVGNames::operatorAttr) {
54         if (value == "over")
55             set_operatorBaseValue(FECOMPOSITE_OPERATOR_OVER);
56         else if (value == "in")
57             set_operatorBaseValue(FECOMPOSITE_OPERATOR_IN);
58         else if (value == "out")
59             set_operatorBaseValue(FECOMPOSITE_OPERATOR_OUT);
60         else if (value == "atop")
61             set_operatorBaseValue(FECOMPOSITE_OPERATOR_ATOP);
62         else if (value == "xor")
63             set_operatorBaseValue(FECOMPOSITE_OPERATOR_XOR);
64         else if (value == "arithmetic")
65             set_operatorBaseValue(FECOMPOSITE_OPERATOR_ARITHMETIC);
66     }
67     else if (attr->name() == SVGNames::inAttr)
68         setIn1BaseValue(value);
69     else if (attr->name() == SVGNames::in2Attr)
70         setIn2BaseValue(value);
71     else if (attr->name() == SVGNames::k1Attr)
72         setK1BaseValue(value.toFloat());
73     else if (attr->name() == SVGNames::k2Attr)
74         setK2BaseValue(value.toFloat());
75     else if (attr->name() == SVGNames::k3Attr)
76         setK3BaseValue(value.toFloat());
77     else if (attr->name() == SVGNames::k4Attr)
78         setK4BaseValue(value.toFloat());
79     else
80         SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
81 }
82 
build(SVGResourceFilter * filterResource)83 bool SVGFECompositeElement::build(SVGResourceFilter* filterResource)
84 {
85     FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
86     FilterEffect* input2 = filterResource->builder()->getEffectById(in2());
87 
88     if (!input1 || !input2)
89         return false;
90 
91     RefPtr<FilterEffect> effect = FEComposite::create(input1, input2, static_cast<CompositeOperationType>(_operator()),
92                                         k1(), k2(), k3(), k4());
93     filterResource->addFilterEffect(this, effect.release());
94 
95     return true;
96 }
97 
98 }
99 
100 #endif // ENABLE(SVG)
101