File indexing completed on 2024-04-28 15:24:30
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 "SVGFEColorMatrixElement.h" 0025 0026 #include "SVGNames.h" 0027 #include "SVGNumberList.h" 0028 #include "SVGResourceFilter.h" 0029 0030 namespace WebCore 0031 { 0032 0033 SVGFEColorMatrixElement::SVGFEColorMatrixElement(const QualifiedName &tagName, Document *doc) 0034 : SVGFilterPrimitiveStandardAttributes(tagName, doc) 0035 , m_type(SVG_FECOLORMATRIX_TYPE_UNKNOWN) 0036 , m_values(SVGNumberList::create(SVGNames::valuesAttr)) 0037 , m_filterEffect(0) 0038 { 0039 } 0040 0041 SVGFEColorMatrixElement::~SVGFEColorMatrixElement() 0042 { 0043 delete m_filterEffect; 0044 } 0045 0046 ANIMATED_PROPERTY_DEFINITIONS(SVGFEColorMatrixElement, String, String, string, In1, in1, SVGNames::inAttr, m_in1) 0047 ANIMATED_PROPERTY_DEFINITIONS(SVGFEColorMatrixElement, int, Enumeration, enumeration, Type, type, SVGNames::typeAttr, m_type) 0048 ANIMATED_PROPERTY_DEFINITIONS(SVGFEColorMatrixElement, SVGNumberList *, NumberList, numberList, Values, values, SVGNames::valuesAttr, m_values.get()) 0049 0050 void SVGFEColorMatrixElement::parseMappedAttribute(MappedAttribute *attr) 0051 { 0052 const String &value = attr->value(); 0053 if (attr->name() == SVGNames::typeAttr) { 0054 if (value == "matrix") { 0055 setTypeBaseValue(SVG_FECOLORMATRIX_TYPE_MATRIX); 0056 } else if (value == "saturate") { 0057 setTypeBaseValue(SVG_FECOLORMATRIX_TYPE_SATURATE); 0058 } else if (value == "hueRotate") { 0059 setTypeBaseValue(SVG_FECOLORMATRIX_TYPE_HUEROTATE); 0060 } else if (value == "luminanceToAlpha") { 0061 setTypeBaseValue(SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA); 0062 } 0063 } else if (attr->name() == SVGNames::inAttr) { 0064 setIn1BaseValue(value); 0065 } else if (attr->name() == SVGNames::valuesAttr) { 0066 valuesBaseValue()->parse(value); 0067 } else { 0068 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); 0069 } 0070 } 0071 0072 SVGFEColorMatrix *SVGFEColorMatrixElement::filterEffect(SVGResourceFilter *filter) const 0073 { 0074 if (!m_filterEffect) { 0075 m_filterEffect = new SVGFEColorMatrix(filter); 0076 } 0077 0078 m_filterEffect->setIn(in1()); 0079 setStandardAttributes(m_filterEffect); 0080 0081 Vector<float> _values; 0082 SVGNumberList *numbers = values(); 0083 0084 ExceptionCode ec = 0; 0085 unsigned int nr = numbers->numberOfItems(); 0086 for (unsigned int i = 0; i < nr; i++) { 0087 _values.append(numbers->getItem(i, ec)); 0088 } 0089 0090 m_filterEffect->setValues(_values); 0091 m_filterEffect->setType((SVGColorMatrixType) type()); 0092 0093 return m_filterEffect; 0094 } 0095 0096 } 0097 0098 #endif // ENABLE(SVG) 0099