KHtml

SVGFEDisplacementMapElement.cpp
1 /*
2  Copyright (C) 2006 Oliver Hunt <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 
20 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
21 #include "SVGFEDisplacementMapElement.h"
22 
23 #include "SVGResourceFilter.h"
24 
25 namespace WebCore
26 {
27 
28 SVGFEDisplacementMapElement::SVGFEDisplacementMapElement(const QualifiedName &tagName, Document *doc)
29  : SVGFilterPrimitiveStandardAttributes(tagName, doc)
30  , m_xChannelSelector(SVG_CHANNEL_A)
31  , m_yChannelSelector(SVG_CHANNEL_A)
32  , m_scale(0.0f)
33  , m_filterEffect(0)
34 {
35 }
36 
37 SVGFEDisplacementMapElement::~SVGFEDisplacementMapElement()
38 {
39  delete m_filterEffect;
40 }
41 
42 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, String, String, string, In1, in1, SVGNames::inAttr, m_in1)
43 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, String, String, string, In2, in2, SVGNames::in2Attr, m_in2)
44 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, int, Enumeration, enumeration, XChannelSelector, xChannelSelector, SVGNames::xChannelSelectorAttr, m_xChannelSelector)
45 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, int, Enumeration, enumeration, YChannelSelector, yChannelSelector, SVGNames::yChannelSelectorAttr, m_yChannelSelector)
46 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, float, Number, number, Scale, scale, SVGNames::scaleAttr, m_scale)
47 
48 SVGChannelSelectorType SVGFEDisplacementMapElement::stringToChannel(const String &key)
49 {
50  if (key == "R") {
51  return SVG_CHANNEL_R;
52  } else if (key == "G") {
53  return SVG_CHANNEL_G;
54  } else if (key == "B") {
55  return SVG_CHANNEL_B;
56  } else if (key == "A") {
57  return SVG_CHANNEL_A;
58  }
59 
60  return SVG_CHANNEL_UNKNOWN;
61 }
62 
63 void SVGFEDisplacementMapElement::parseMappedAttribute(MappedAttribute *attr)
64 {
65  const String &value = attr->value();
66  if (attr->name() == SVGNames::xChannelSelectorAttr) {
67  setXChannelSelectorBaseValue(stringToChannel(value));
68  } else if (attr->name() == SVGNames::yChannelSelectorAttr) {
69  setYChannelSelectorBaseValue(stringToChannel(value));
70  } else if (attr->name() == SVGNames::inAttr) {
71  setIn1BaseValue(value);
72  } else if (attr->name() == SVGNames::in2Attr) {
73  setIn2BaseValue(value);
74  } else if (attr->name() == SVGNames::scaleAttr) {
75  setScaleBaseValue(value.toFloat());
76  } else {
77  SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
78  }
79 }
80 
81 SVGFEDisplacementMap *SVGFEDisplacementMapElement::filterEffect(SVGResourceFilter *filter) const
82 {
83  if (!m_filterEffect) {
84  m_filterEffect = new SVGFEDisplacementMap(filter);
85  }
86 
87  m_filterEffect->setXChannelSelector((SVGChannelSelectorType) xChannelSelector());
88  m_filterEffect->setYChannelSelector((SVGChannelSelectorType) yChannelSelector());
89  m_filterEffect->setIn(in1());
90  m_filterEffect->setIn2(in2());
91  m_filterEffect->setScale(scale());
92 
93  setStandardAttributes(m_filterEffect);
94  return m_filterEffect;
95 }
96 
97 }
98 
99 #endif // ENABLE(SVG)
100 
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 22:48:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.