1 /* 2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis (at) kde.org> 4 * 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. 9 * 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. 14 * 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. 19 */ 20 21 #include "config.h" 22 23 #include "core/svg/SVGComponentTransferFunctionElement.h" 24 25 #include "core/SVGNames.h" 26 #include "core/dom/Attribute.h" 27 #include "core/svg/SVGFEComponentTransferElement.h" 28 #include "core/svg/SVGNumberList.h" 29 30 namespace WebCore { 31 32 template<> const SVGEnumerationStringEntries& getStaticStringEntries<ComponentTransferType>() 33 { 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")); 41 } 42 return entries; 43 } 44 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)) 54 { 55 ScriptWrappable::init(this); 56 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); 64 } 65 66 bool SVGComponentTransferFunctionElement::isSupportedAttribute(const QualifiedName& attrName) 67 { 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); 77 } 78 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 79 } 80 81 void SVGComponentTransferFunctionElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 82 { 83 if (!isSupportedAttribute(name)) { 84 SVGElement::parseAttribute(name, value); 85 return; 86 } 87 88 SVGParsingError parseError = NoError; 89 90 if (name == SVGNames::tableValuesAttr) 91 m_tableValues->setBaseValueAsString(value, parseError); 92 else if (name == SVGNames::typeAttr) 93 m_type->setBaseValueAsString(value, parseError); 94 else if (name == SVGNames::slopeAttr) 95 m_slope->setBaseValueAsString(value, parseError); 96 else if (name == SVGNames::interceptAttr) 97 m_intercept->setBaseValueAsString(value, parseError); 98 else if (name == SVGNames::amplitudeAttr) 99 m_amplitude->setBaseValueAsString(value, parseError); 100 else if (name == SVGNames::exponentAttr) 101 m_exponent->setBaseValueAsString(value, parseError); 102 else if (name == SVGNames::offsetAttr) 103 m_offset->setBaseValueAsString(value, parseError); 104 105 reportAttributeParsingError(parseError, name, value); 106 } 107 108 void SVGComponentTransferFunctionElement::svgAttributeChanged(const QualifiedName& attrName) 109 { 110 if (!isSupportedAttribute(attrName)) { 111 SVGElement::svgAttributeChanged(attrName); 112 return; 113 } 114 115 SVGElement::InvalidationGuard invalidationGuard(this); 116 117 invalidateFilterPrimitiveParent(this); 118 } 119 120 ComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const 121 { 122 ComponentTransferFunction func; 123 func.type = m_type->currentValue()->enumValue(); 124 func.slope = m_slope->currentValue()->value(); 125 func.intercept = m_intercept->currentValue()->value(); 126 func.amplitude = m_amplitude->currentValue()->value(); 127 func.exponent = m_exponent->currentValue()->value(); 128 func.offset = m_offset->currentValue()->value(); 129 func.tableValues = m_tableValues->currentValue()->toFloatVector(); 130 return func; 131 } 132 133 } 134