File indexing completed on 2024-04-28 15:24:28

0001 /*
0002     Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
0003                   2004, 2005, 2006 Rob Buis <buis@kde.org>
0004 
0005     This file is part of the KDE project
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This library is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015     Library General Public License for more details.
0016 
0017     You should have received a copy of the GNU Library General Public License
0018     along with this library; see the file COPYING.LIB.  If not, write to
0019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020     Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
0024 #include "SVGComponentTransferFunctionElement.h"
0025 
0026 #include "SVGFEComponentTransferElement.h"
0027 #include "SVGNames.h"
0028 #include "SVGNumberList.h"
0029 
0030 namespace WebCore
0031 {
0032 
0033 SVGComponentTransferFunctionElement::SVGComponentTransferFunctionElement(const QualifiedName &tagName, Document *doc)
0034     : SVGElement(tagName, doc)
0035     , m_type(SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN)
0036     , m_tableValues(SVGNumberList::create(SVGNames::tableValuesAttr))
0037     , m_slope(1.0f)
0038     , m_intercept(0.0f)
0039     , m_amplitude(1.0f)
0040     , m_exponent(1.0f)
0041     , m_offset(0.0f)
0042 {
0043 }
0044 
0045 SVGComponentTransferFunctionElement::~SVGComponentTransferFunctionElement()
0046 {
0047 }
0048 
0049 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, int, Enumeration, enumeration, Type, type, SVGNames::typeAttr, m_type)
0050 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, SVGNumberList *, NumberList, numberList, TableValues, tableValues, SVGNames::tableValuesAttr, m_tableValues.get())
0051 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Slope, slope, SVGNames::slopeAttr, m_slope)
0052 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Intercept, intercept, SVGNames::interceptAttr, m_intercept)
0053 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Amplitude, amplitude, SVGNames::amplitudeAttr, m_amplitude)
0054 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Exponent, exponent, SVGNames::exponentAttr, m_exponent)
0055 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Offset, offset, SVGNames::offsetAttr, m_offset)
0056 
0057 void SVGComponentTransferFunctionElement::parseMappedAttribute(MappedAttribute *attr)
0058 {
0059     const String &value = attr->value();
0060     if (attr->name() == SVGNames::typeAttr) {
0061         if (value == "identity") {
0062             setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
0063         } else if (value == "table") {
0064             setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_TABLE);
0065         } else if (value == "discrete") {
0066             setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE);
0067         } else if (value == "linear") {
0068             setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_LINEAR);
0069         } else if (value == "gamma") {
0070             setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_GAMMA);
0071         }
0072     } else if (attr->name() == SVGNames::tableValuesAttr) {
0073         tableValuesBaseValue()->parse(value);
0074     } else if (attr->name() == SVGNames::slopeAttr) {
0075         setSlopeBaseValue(value.toFloat());
0076     } else if (attr->name() == SVGNames::interceptAttr) {
0077         setInterceptBaseValue(value.toFloat());
0078     } else if (attr->name() == SVGNames::amplitudeAttr) {
0079         setAmplitudeBaseValue(value.toFloat());
0080     } else if (attr->name() == SVGNames::exponentAttr) {
0081         setExponentBaseValue(value.toFloat());
0082     } else if (attr->name() == SVGNames::offsetAttr) {
0083         setOffsetBaseValue(value.toFloat());
0084     } else {
0085         SVGElement::parseMappedAttribute(attr);
0086     }
0087 }
0088 
0089 SVGComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const
0090 {
0091     SVGComponentTransferFunction func;
0092     func.type = (SVGComponentTransferType) type();
0093     func.slope = slope();
0094     func.intercept = intercept();
0095     func.amplitude = amplitude();
0096     func.exponent = exponent();
0097     func.offset = offset();
0098     SVGNumberList *numbers = tableValues();
0099 
0100     ExceptionCode ec = 0;
0101     unsigned int nr = numbers->numberOfItems();
0102     for (unsigned int i = 0; i < nr; i++) {
0103         func.tableValues.append(numbers->getItem(i, ec));
0104     }
0105     return func;
0106 }
0107 
0108 }
0109 
0110 #endif // ENABLE(SVG)
0111