KHtml

SVGFEColorMatrixElement.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 "SVGFEColorMatrixElement.h"
25 
26 #include "SVGNames.h"
27 #include "SVGNumberList.h"
28 #include "SVGResourceFilter.h"
29 
30 namespace WebCore
31 {
32 
33 SVGFEColorMatrixElement::SVGFEColorMatrixElement(const QualifiedName &tagName, Document *doc)
34  : SVGFilterPrimitiveStandardAttributes(tagName, doc)
35  , m_type(SVG_FECOLORMATRIX_TYPE_UNKNOWN)
36  , m_values(SVGNumberList::create(SVGNames::valuesAttr))
37  , m_filterEffect(0)
38 {
39 }
40 
41 SVGFEColorMatrixElement::~SVGFEColorMatrixElement()
42 {
43  delete m_filterEffect;
44 }
45 
46 ANIMATED_PROPERTY_DEFINITIONS(SVGFEColorMatrixElement, String, String, string, In1, in1, SVGNames::inAttr, m_in1)
47 ANIMATED_PROPERTY_DEFINITIONS(SVGFEColorMatrixElement, int, Enumeration, enumeration, Type, type, SVGNames::typeAttr, m_type)
48 ANIMATED_PROPERTY_DEFINITIONS(SVGFEColorMatrixElement, SVGNumberList *, NumberList, numberList, Values, values, SVGNames::valuesAttr, m_values.get())
49 
50 void SVGFEColorMatrixElement::parseMappedAttribute(MappedAttribute *attr)
51 {
52  const String &value = attr->value();
53  if (attr->name() == SVGNames::typeAttr) {
54  if (value == "matrix") {
55  setTypeBaseValue(SVG_FECOLORMATRIX_TYPE_MATRIX);
56  } else if (value == "saturate") {
57  setTypeBaseValue(SVG_FECOLORMATRIX_TYPE_SATURATE);
58  } else if (value == "hueRotate") {
59  setTypeBaseValue(SVG_FECOLORMATRIX_TYPE_HUEROTATE);
60  } else if (value == "luminanceToAlpha") {
61  setTypeBaseValue(SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA);
62  }
63  } else if (attr->name() == SVGNames::inAttr) {
64  setIn1BaseValue(value);
65  } else if (attr->name() == SVGNames::valuesAttr) {
66  valuesBaseValue()->parse(value);
67  } else {
68  SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
69  }
70 }
71 
72 SVGFEColorMatrix *SVGFEColorMatrixElement::filterEffect(SVGResourceFilter *filter) const
73 {
74  if (!m_filterEffect) {
75  m_filterEffect = new SVGFEColorMatrix(filter);
76  }
77 
78  m_filterEffect->setIn(in1());
79  setStandardAttributes(m_filterEffect);
80 
81  Vector<float> _values;
82  SVGNumberList *numbers = values();
83 
84  ExceptionCode ec = 0;
85  unsigned int nr = numbers->numberOfItems();
86  for (unsigned int i = 0; i < nr; i++) {
87  _values.append(numbers->getItem(i, ec));
88  }
89 
90  m_filterEffect->setValues(_values);
91  m_filterEffect->setType((SVGColorMatrixType) type());
92 
93  return m_filterEffect;
94 }
95 
96 }
97 
98 #endif // ENABLE(SVG)
99 
QAction * create(StandardAction id, const QObject *recvr, Func slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:09 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.