KHtml

SVGComponentTransferFunctionElement.cpp
1 /*
2  Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006 Rob Buis <[email protected]>
4 
5  This file is part of the KDE project
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
24 #include "SVGComponentTransferFunctionElement.h"
25 
26 #include "SVGFEComponentTransferElement.h"
27 #include "SVGNames.h"
28 #include "SVGNumberList.h"
29 
30 namespace WebCore
31 {
32 
33 SVGComponentTransferFunctionElement::SVGComponentTransferFunctionElement(const QualifiedName &tagName, Document *doc)
34  : SVGElement(tagName, doc)
35  , m_type(SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN)
36  , m_tableValues(SVGNumberList::create(SVGNames::tableValuesAttr))
37  , m_slope(1.0f)
38  , m_intercept(0.0f)
39  , m_amplitude(1.0f)
40  , m_exponent(1.0f)
41  , m_offset(0.0f)
42 {
43 }
44 
45 SVGComponentTransferFunctionElement::~SVGComponentTransferFunctionElement()
46 {
47 }
48 
49 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, int, Enumeration, enumeration, Type, type, SVGNames::typeAttr, m_type)
50 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, SVGNumberList *, NumberList, numberList, TableValues, tableValues, SVGNames::tableValuesAttr, m_tableValues.get())
51 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Slope, slope, SVGNames::slopeAttr, m_slope)
52 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Intercept, intercept, SVGNames::interceptAttr, m_intercept)
53 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Amplitude, amplitude, SVGNames::amplitudeAttr, m_amplitude)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Exponent, exponent, SVGNames::exponentAttr, m_exponent)
55 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Offset, offset, SVGNames::offsetAttr, m_offset)
56 
57 void SVGComponentTransferFunctionElement::parseMappedAttribute(MappedAttribute *attr)
58 {
59  const String &value = attr->value();
60  if (attr->name() == SVGNames::typeAttr) {
61  if (value == "identity") {
62  setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
63  } else if (value == "table") {
64  setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_TABLE);
65  } else if (value == "discrete") {
66  setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE);
67  } else if (value == "linear") {
68  setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_LINEAR);
69  } else if (value == "gamma") {
70  setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_GAMMA);
71  }
72  } else if (attr->name() == SVGNames::tableValuesAttr) {
73  tableValuesBaseValue()->parse(value);
74  } else if (attr->name() == SVGNames::slopeAttr) {
75  setSlopeBaseValue(value.toFloat());
76  } else if (attr->name() == SVGNames::interceptAttr) {
77  setInterceptBaseValue(value.toFloat());
78  } else if (attr->name() == SVGNames::amplitudeAttr) {
79  setAmplitudeBaseValue(value.toFloat());
80  } else if (attr->name() == SVGNames::exponentAttr) {
81  setExponentBaseValue(value.toFloat());
82  } else if (attr->name() == SVGNames::offsetAttr) {
83  setOffsetBaseValue(value.toFloat());
84  } else {
85  SVGElement::parseMappedAttribute(attr);
86  }
87 }
88 
89 SVGComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const
90 {
91  SVGComponentTransferFunction func;
92  func.type = (SVGComponentTransferType) type();
93  func.slope = slope();
94  func.intercept = intercept();
95  func.amplitude = amplitude();
96  func.exponent = exponent();
97  func.offset = offset();
98  SVGNumberList *numbers = tableValues();
99 
100  ExceptionCode ec = 0;
101  unsigned int nr = numbers->numberOfItems();
102  for (unsigned int i = 0; i < nr; i++) {
103  func.tableValues.append(numbers->getItem(i, ec));
104  }
105  return func;
106 }
107 
108 }
109 
110 #endif // ENABLE(SVG)
111 
QAction * create(StandardAction id, const QObject *recvr, Func slot, QObject *parent)
Type type(const QSqlDatabase &db)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:22 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.