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 #if ENABLE(SVG) && ENABLE(FILTERS)
24 #include "SVGComponentTransferFunctionElement.h"
26 #include "Attribute.h"
27 #include "SVGFEComponentTransferElement.h"
29 #include "SVGNumberList.h"
33 // Animated property definitions
34 DEFINE_ANIMATED_ENUMERATION(SVGComponentTransferFunctionElement, SVGNames::typeAttr, Type, type, ComponentTransferType)
35 DEFINE_ANIMATED_NUMBER_LIST(SVGComponentTransferFunctionElement, SVGNames::tableValuesAttr, TableValues, tableValues)
36 DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::slopeAttr, Slope, slope)
37 DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::interceptAttr, Intercept, intercept)
38 DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::amplitudeAttr, Amplitude, amplitude)
39 DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::exponentAttr, Exponent, exponent)
40 DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::offsetAttr, Offset, offset)
42 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGComponentTransferFunctionElement)
43 REGISTER_LOCAL_ANIMATED_PROPERTY(type)
44 REGISTER_LOCAL_ANIMATED_PROPERTY(tableValues)
45 REGISTER_LOCAL_ANIMATED_PROPERTY(slope)
46 REGISTER_LOCAL_ANIMATED_PROPERTY(intercept)
47 REGISTER_LOCAL_ANIMATED_PROPERTY(amplitude)
48 REGISTER_LOCAL_ANIMATED_PROPERTY(exponent)
49 REGISTER_LOCAL_ANIMATED_PROPERTY(offset)
50 END_REGISTER_ANIMATED_PROPERTIES
52 SVGComponentTransferFunctionElement::SVGComponentTransferFunctionElement(const QualifiedName& tagName, Document* document)
53 : SVGElement(tagName, document)
54 , m_type(FECOMPONENTTRANSFER_TYPE_IDENTITY)
59 registerAnimatedPropertiesForSVGComponentTransferFunctionElement();
62 bool SVGComponentTransferFunctionElement::isSupportedAttribute(const QualifiedName& attrName)
64 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
65 if (supportedAttributes.isEmpty()) {
66 supportedAttributes.add(SVGNames::typeAttr);
67 supportedAttributes.add(SVGNames::tableValuesAttr);
68 supportedAttributes.add(SVGNames::slopeAttr);
69 supportedAttributes.add(SVGNames::interceptAttr);
70 supportedAttributes.add(SVGNames::amplitudeAttr);
71 supportedAttributes.add(SVGNames::exponentAttr);
72 supportedAttributes.add(SVGNames::offsetAttr);
74 return supportedAttributes.contains(attrName);
77 void SVGComponentTransferFunctionElement::parseMappedAttribute(Attribute* attr)
79 if (!isSupportedAttribute(attr->name())) {
80 SVGElement::parseMappedAttribute(attr);
84 const AtomicString& value = attr->value();
85 if (attr->name() == SVGNames::typeAttr) {
86 ComponentTransferType propertyValue = SVGPropertyTraits<ComponentTransferType>::fromString(value);
87 if (propertyValue > 0)
88 setTypeBaseValue(propertyValue);
92 if (attr->name() == SVGNames::tableValuesAttr) {
93 SVGNumberList newList;
95 detachAnimatedTableValuesListWrappers(newList.size());
96 setTableValuesBaseValue(newList);
100 if (attr->name() == SVGNames::slopeAttr) {
101 setSlopeBaseValue(value.toFloat());
105 if (attr->name() == SVGNames::interceptAttr) {
106 setInterceptBaseValue(value.toFloat());
110 if (attr->name() == SVGNames::amplitudeAttr) {
111 setAmplitudeBaseValue(value.toFloat());
115 if (attr->name() == SVGNames::exponentAttr) {
116 setExponentBaseValue(value.toFloat());
120 if (attr->name() == SVGNames::offsetAttr) {
121 setOffsetBaseValue(value.toFloat());
125 ASSERT_NOT_REACHED();
128 ComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const
130 ComponentTransferFunction func;
132 func.slope = slope();
133 func.intercept = intercept();
134 func.amplitude = amplitude();
135 func.exponent = exponent();
136 func.offset = offset();
137 func.tableValues = tableValues();
143 #endif // ENABLE(SVG)