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/SVGComponentTransferFunctionElement.h"
25 #include "core/SVGNames.h"
26 #include "core/dom/Attribute.h"
27 #include "core/svg/SVGFEComponentTransferElement.h"
28 #include "core/svg/SVGNumberList.h"
32 template<> const SVGEnumerationStringEntries& getStaticStringEntries<ComponentTransferType>()
34 DEFINE_STATIC_LOCAL(SVGEnumerationStringEntries, entries, ());
35 if (entries.isEmpty()) {
36 entries.append(std::make_pair(FECOMPONENTTRANSFER_TYPE_IDENTITY, "identity"));
37 entries.append(std::make_pair(FECOMPONENTTRANSFER_TYPE_TABLE, "table"));
38 entries.append(std::make_pair(FECOMPONENTTRANSFER_TYPE_DISCRETE, "discrete"));
39 entries.append(std::make_pair(FECOMPONENTTRANSFER_TYPE_LINEAR, "linear"));
40 entries.append(std::make_pair(FECOMPONENTTRANSFER_TYPE_GAMMA, "gamma"));
45 SVGComponentTransferFunctionElement::SVGComponentTransferFunctionElement(const QualifiedName& tagName, Document& document)
46 : SVGElement(tagName, document)
47 , m_tableValues(SVGAnimatedNumberList::create(this, SVGNames::tableValuesAttr, SVGNumberList::create()))
48 , m_slope(SVGAnimatedNumber::create(this, SVGNames::slopeAttr, SVGNumber::create(1)))
49 , m_intercept(SVGAnimatedNumber::create(this, SVGNames::interceptAttr, SVGNumber::create()))
50 , m_amplitude(SVGAnimatedNumber::create(this, SVGNames::amplitudeAttr, SVGNumber::create(1)))
51 , m_exponent(SVGAnimatedNumber::create(this, SVGNames::exponentAttr, SVGNumber::create(1)))
52 , m_offset(SVGAnimatedNumber::create(this, SVGNames::offsetAttr, SVGNumber::create()))
53 , m_type(SVGAnimatedEnumeration<ComponentTransferType>::create(this, SVGNames::typeAttr, FECOMPONENTTRANSFER_TYPE_IDENTITY))
55 ScriptWrappable::init(this);
57 addToPropertyMap(m_tableValues);
58 addToPropertyMap(m_slope);
59 addToPropertyMap(m_intercept);
60 addToPropertyMap(m_amplitude);
61 addToPropertyMap(m_exponent);
62 addToPropertyMap(m_offset);
63 addToPropertyMap(m_type);
66 bool SVGComponentTransferFunctionElement::isSupportedAttribute(const QualifiedName& attrName)
68 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
69 if (supportedAttributes.isEmpty()) {
70 supportedAttributes.add(SVGNames::typeAttr);
71 supportedAttributes.add(SVGNames::tableValuesAttr);
72 supportedAttributes.add(SVGNames::slopeAttr);
73 supportedAttributes.add(SVGNames::interceptAttr);
74 supportedAttributes.add(SVGNames::amplitudeAttr);
75 supportedAttributes.add(SVGNames::exponentAttr);
76 supportedAttributes.add(SVGNames::offsetAttr);
78 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
81 void SVGComponentTransferFunctionElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
83 parseAttributeNew(name, value);
86 void SVGComponentTransferFunctionElement::svgAttributeChanged(const QualifiedName& attrName)
88 if (!isSupportedAttribute(attrName)) {
89 SVGElement::svgAttributeChanged(attrName);
93 SVGElement::InvalidationGuard invalidationGuard(this);
95 invalidateFilterPrimitiveParent(this);
98 ComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const
100 ComponentTransferFunction func;
101 func.type = m_type->currentValue()->enumValue();
102 func.slope = m_slope->currentValue()->value();
103 func.intercept = m_intercept->currentValue()->value();
104 func.amplitude = m_amplitude->currentValue()->value();
105 func.exponent = m_exponent->currentValue()->value();
106 func.offset = m_offset->currentValue()->value();
107 func.tableValues = m_tableValues->currentValue()->toFloatVector();