2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
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.
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.
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.
23 #include "core/svg/SVGFECompositeElement.h"
25 #include "core/SVGNames.h"
26 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
27 #include "platform/graphics/filters/FilterEffect.h"
31 template<> const SVGEnumerationStringEntries
& getStaticStringEntries
<CompositeOperationType
>()
33 DEFINE_STATIC_LOCAL(SVGEnumerationStringEntries
, entries
, ());
34 if (entries
.isEmpty()) {
35 entries
.append(std::make_pair(FECOMPOSITE_OPERATOR_OVER
, "over"));
36 entries
.append(std::make_pair(FECOMPOSITE_OPERATOR_IN
, "in"));
37 entries
.append(std::make_pair(FECOMPOSITE_OPERATOR_OUT
, "out"));
38 entries
.append(std::make_pair(FECOMPOSITE_OPERATOR_ATOP
, "atop"));
39 entries
.append(std::make_pair(FECOMPOSITE_OPERATOR_XOR
, "xor"));
40 entries
.append(std::make_pair(FECOMPOSITE_OPERATOR_ARITHMETIC
, "arithmetic"));
41 entries
.append(std::make_pair(FECOMPOSITE_OPERATOR_LIGHTER
, "lighter"));
46 template<> unsigned short getMaxExposedEnumValue
<CompositeOperationType
>()
48 return FECOMPOSITE_OPERATOR_ARITHMETIC
;
51 inline SVGFECompositeElement::SVGFECompositeElement(Document
& document
)
52 : SVGFilterPrimitiveStandardAttributes(SVGNames::feCompositeTag
, document
)
53 , m_k1(SVGAnimatedNumber::create(this, SVGNames::k1Attr
, SVGNumber::create()))
54 , m_k2(SVGAnimatedNumber::create(this, SVGNames::k2Attr
, SVGNumber::create()))
55 , m_k3(SVGAnimatedNumber::create(this, SVGNames::k3Attr
, SVGNumber::create()))
56 , m_k4(SVGAnimatedNumber::create(this, SVGNames::k4Attr
, SVGNumber::create()))
57 , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr
, SVGString::create()))
58 , m_in2(SVGAnimatedString::create(this, SVGNames::in2Attr
, SVGString::create()))
59 , m_svgOperator(SVGAnimatedEnumeration
<CompositeOperationType
>::create(this, SVGNames::operatorAttr
, FECOMPOSITE_OPERATOR_OVER
))
61 addToPropertyMap(m_k1
);
62 addToPropertyMap(m_k2
);
63 addToPropertyMap(m_k3
);
64 addToPropertyMap(m_k4
);
65 addToPropertyMap(m_in1
);
66 addToPropertyMap(m_in2
);
67 addToPropertyMap(m_svgOperator
);
70 DEFINE_TRACE(SVGFECompositeElement
)
76 visitor
->trace(m_in1
);
77 visitor
->trace(m_in2
);
78 visitor
->trace(m_svgOperator
);
79 SVGFilterPrimitiveStandardAttributes::trace(visitor
);
82 DEFINE_NODE_FACTORY(SVGFECompositeElement
)
84 bool SVGFECompositeElement::setFilterEffectAttribute(FilterEffect
* effect
, const QualifiedName
& attrName
)
86 FEComposite
* composite
= static_cast<FEComposite
*>(effect
);
87 if (attrName
== SVGNames::operatorAttr
)
88 return composite
->setOperation(m_svgOperator
->currentValue()->enumValue());
89 if (attrName
== SVGNames::k1Attr
)
90 return composite
->setK1(m_k1
->currentValue()->value());
91 if (attrName
== SVGNames::k2Attr
)
92 return composite
->setK2(m_k2
->currentValue()->value());
93 if (attrName
== SVGNames::k3Attr
)
94 return composite
->setK3(m_k3
->currentValue()->value());
95 if (attrName
== SVGNames::k4Attr
)
96 return composite
->setK4(m_k4
->currentValue()->value());
103 void SVGFECompositeElement::svgAttributeChanged(const QualifiedName
& attrName
)
105 if (attrName
== SVGNames::operatorAttr
106 || attrName
== SVGNames::k1Attr
107 || attrName
== SVGNames::k2Attr
108 || attrName
== SVGNames::k3Attr
109 || attrName
== SVGNames::k4Attr
) {
110 SVGElement::InvalidationGuard
invalidationGuard(this);
111 primitiveAttributeChanged(attrName
);
115 if (attrName
== SVGNames::inAttr
|| attrName
== SVGNames::in2Attr
) {
116 SVGElement::InvalidationGuard
invalidationGuard(this);
121 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName
);
124 PassRefPtrWillBeRawPtr
<FilterEffect
> SVGFECompositeElement::build(SVGFilterBuilder
* filterBuilder
, Filter
* filter
)
126 FilterEffect
* input1
= filterBuilder
->getEffectById(AtomicString(m_in1
->currentValue()->value()));
127 FilterEffect
* input2
= filterBuilder
->getEffectById(AtomicString(m_in2
->currentValue()->value()));
129 if (!input1
|| !input2
)
132 RefPtrWillBeRawPtr
<FilterEffect
> effect
= FEComposite::create(filter
, m_svgOperator
->currentValue()->enumValue(), m_k1
->currentValue()->value(), m_k2
->currentValue()->value(), m_k3
->currentValue()->value(), m_k4
->currentValue()->value());
133 FilterEffectVector
& inputEffects
= effect
->inputEffects();
134 inputEffects
.reserveCapacity(2);
135 inputEffects
.append(input1
);
136 inputEffects
.append(input2
);
137 return effect
.release();