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 addToPropertyMap(m_tableValues
);
56 addToPropertyMap(m_slope
);
57 addToPropertyMap(m_intercept
);
58 addToPropertyMap(m_amplitude
);
59 addToPropertyMap(m_exponent
);
60 addToPropertyMap(m_offset
);
61 addToPropertyMap(m_type
);
64 DEFINE_TRACE(SVGComponentTransferFunctionElement
)
66 visitor
->trace(m_tableValues
);
67 visitor
->trace(m_slope
);
68 visitor
->trace(m_intercept
);
69 visitor
->trace(m_amplitude
);
70 visitor
->trace(m_exponent
);
71 visitor
->trace(m_offset
);
72 visitor
->trace(m_type
);
73 SVGElement::trace(visitor
);
76 void SVGComponentTransferFunctionElement::svgAttributeChanged(const QualifiedName
& attrName
)
78 if (attrName
== SVGNames::typeAttr
|| attrName
== SVGNames::tableValuesAttr
79 || attrName
== SVGNames::slopeAttr
|| attrName
== SVGNames::interceptAttr
80 || attrName
== SVGNames::amplitudeAttr
|| attrName
== SVGNames::exponentAttr
81 || attrName
== SVGNames::offsetAttr
) {
82 SVGElement::InvalidationGuard
invalidationGuard(this);
84 invalidateFilterPrimitiveParent(this);
88 SVGElement::svgAttributeChanged(attrName
);
91 ComponentTransferFunction
SVGComponentTransferFunctionElement::transferFunction() const
93 ComponentTransferFunction func
;
94 func
.type
= m_type
->currentValue()->enumValue();
95 func
.slope
= m_slope
->currentValue()->value();
96 func
.intercept
= m_intercept
->currentValue()->value();
97 func
.amplitude
= m_amplitude
->currentValue()->value();
98 func
.exponent
= m_exponent
->currentValue()->value();
99 func
.offset
= m_offset
->currentValue()->value();
100 func
.tableValues
= m_tableValues
->currentValue()->toFloatVector();