00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024
00025 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
00026 #include "SVGComponentTransferFunctionElement.h"
00027
00028 #include "SVGFEComponentTransferElement.h"
00029 #include "SVGNames.h"
00030 #include "SVGNumberList.h"
00031
00032 namespace WebCore {
00033
00034 SVGComponentTransferFunctionElement::SVGComponentTransferFunctionElement(const QualifiedName& tagName, Document* doc)
00035 : SVGElement(tagName, doc)
00036 , m_type(SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN)
00037 , m_tableValues(SVGNumberList::create(SVGNames::tableValuesAttr))
00038 , m_slope(1.0f)
00039 , m_intercept(0.0f)
00040 , m_amplitude(1.0f)
00041 , m_exponent(1.0f)
00042 , m_offset(0.0f)
00043 {
00044 }
00045
00046 SVGComponentTransferFunctionElement::~SVGComponentTransferFunctionElement()
00047 {
00048 }
00049
00050 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, int, Enumeration, enumeration, Type, type, SVGNames::typeAttr, m_type)
00051 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, SVGNumberList*, NumberList, numberList, TableValues, tableValues, SVGNames::tableValuesAttr, m_tableValues.get())
00052 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Slope, slope, SVGNames::slopeAttr, m_slope)
00053 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Intercept, intercept, SVGNames::interceptAttr, m_intercept)
00054 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Amplitude, amplitude, SVGNames::amplitudeAttr, m_amplitude)
00055 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Exponent, exponent, SVGNames::exponentAttr, m_exponent)
00056 ANIMATED_PROPERTY_DEFINITIONS(SVGComponentTransferFunctionElement, float, Number, number, Offset, offset, SVGNames::offsetAttr, m_offset)
00057
00058 void SVGComponentTransferFunctionElement::parseMappedAttribute(MappedAttribute* attr)
00059 {
00060 const String& value = attr->value();
00061 if (attr->name() == SVGNames::typeAttr)
00062 {
00063 if (value == "identity")
00064 setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
00065 else if (value == "table")
00066 setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_TABLE);
00067 else if (value == "discrete")
00068 setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE);
00069 else if (value == "linear")
00070 setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_LINEAR);
00071 else if (value == "gamma")
00072 setTypeBaseValue(SVG_FECOMPONENTTRANSFER_TYPE_GAMMA);
00073 }
00074 else if (attr->name() == SVGNames::tableValuesAttr)
00075 tableValuesBaseValue()->parse(value);
00076 else if (attr->name() == SVGNames::slopeAttr)
00077 setSlopeBaseValue(value.toFloat());
00078 else if (attr->name() == SVGNames::interceptAttr)
00079 setInterceptBaseValue(value.toFloat());
00080 else if (attr->name() == SVGNames::amplitudeAttr)
00081 setAmplitudeBaseValue(value.toFloat());
00082 else if (attr->name() == SVGNames::exponentAttr)
00083 setExponentBaseValue(value.toFloat());
00084 else if (attr->name() == SVGNames::offsetAttr)
00085 setOffsetBaseValue(value.toFloat());
00086 else
00087 SVGElement::parseMappedAttribute(attr);
00088 }
00089
00090 SVGComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const
00091 {
00092 SVGComponentTransferFunction func;
00093 func.type = (SVGComponentTransferType) type();
00094 func.slope = slope();
00095 func.intercept = intercept();
00096 func.amplitude = amplitude();
00097 func.exponent = exponent();
00098 func.offset = offset();
00099 SVGNumberList* numbers = tableValues();
00100
00101 ExceptionCode ec = 0;
00102 unsigned int nr = numbers->numberOfItems();
00103 for (unsigned int i = 0; i < nr; i++)
00104 func.tableValues.append(numbers->getItem(i, ec));
00105 return func;
00106 }
00107
00108 }
00109
00110
00111 #endif // ENABLE(SVG)
00112