KHtml

SVGFESpecularLightingElement.cpp
1 /*
2  Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006 Rob Buis <[email protected]>
4  2005 Oliver Hunt <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
23 #include "SVGFESpecularLightingElement.h"
24 
25 #include "RenderObject.h"
26 #include "SVGColor.h"
27 #include "SVGNames.h"
28 #include "SVGFELightElement.h"
29 #include "SVGParserUtilities.h"
30 #include "SVGResourceFilter.h"
31 
32 namespace WebCore
33 {
34 
35 SVGFESpecularLightingElement::SVGFESpecularLightingElement(const QualifiedName &tagName, Document *doc)
36  : SVGFilterPrimitiveStandardAttributes(tagName, doc)
37  , m_specularConstant(1.0f)
38  , m_specularExponent(1.0f)
39  , m_surfaceScale(1.0f)
40  , m_kernelUnitLengthX(0.0f)
41  , m_kernelUnitLengthY(0.0f)
42  , m_filterEffect(0)
43 {
44 }
45 
46 SVGFESpecularLightingElement::~SVGFESpecularLightingElement()
47 {
48  delete m_filterEffect;
49 }
50 
51 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, String, String, string, In1, in1, SVGNames::inAttr, m_in1)
52 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SpecularConstant, specularConstant, SVGNames::specularConstantAttr, m_specularConstant)
53 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SpecularExponent, specularExponent, SVGNames::specularExponentAttr, m_specularExponent)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SurfaceScale, surfaceScale, SVGNames::surfaceScaleAttr, m_surfaceScale)
55 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFESpecularLightingElement, float, Number, number, KernelUnitLengthX, kernelUnitLengthX, SVGNames::kernelUnitLengthAttr, "kernelUnitLengthX", m_kernelUnitLengthX)
56 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFESpecularLightingElement, float, Number, number, KernelUnitLengthY, kernelUnitLengthY, SVGNames::kernelUnitLengthAttr, "kernelUnitLengthY", m_kernelUnitLengthY)
57 
58 void SVGFESpecularLightingElement::parseMappedAttribute(MappedAttribute *attr)
59 {
60  const String &value = attr->value();
61  if (attr->name() == SVGNames::inAttr) {
62  setIn1BaseValue(value);
63  } else if (attr->name() == SVGNames::surfaceScaleAttr) {
64  setSurfaceScaleBaseValue(value.toFloat());
65  } else if (attr->name() == SVGNames::specularConstantAttr) {
66  setSpecularConstantBaseValue(value.toFloat());
67  } else if (attr->name() == SVGNames::specularExponentAttr) {
68  setSpecularExponentBaseValue(value.toFloat());
69  } else if (attr->name() == SVGNames::kernelUnitLengthAttr) {
70  float x, y;
71  if (parseNumberOptionalNumber(value, x, y)) {
72  setKernelUnitLengthXBaseValue(x);
73  setKernelUnitLengthYBaseValue(y);
74  }
75  } else {
76  SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
77  }
78 }
79 
80 SVGFESpecularLighting *SVGFESpecularLightingElement::filterEffect(SVGResourceFilter *filter) const
81 {
82  if (!m_filterEffect) {
83  m_filterEffect = new SVGFESpecularLighting(filter);
84  }
85 
86  m_filterEffect->setIn(in1());
87  m_filterEffect->setSpecularConstant((specularConstant()));
88  m_filterEffect->setSpecularExponent((specularExponent()));
89  m_filterEffect->setSurfaceScale((surfaceScale()));
90  m_filterEffect->setKernelUnitLengthX((kernelUnitLengthX()));
91  m_filterEffect->setKernelUnitLengthY((kernelUnitLengthY()));
92 
93  SVGFESpecularLightingElement *nonConstThis = const_cast<SVGFESpecularLightingElement *>(this);
94 
95  RenderStyle *parentStyle = nonConstThis->styleForRenderer(parent()->renderer());
96  RenderStyle *filterStyle = nonConstThis->resolveStyle(parentStyle);
97 
98  m_filterEffect->setLightingColor(filterStyle->svgStyle()->lightingColor());
99 
100  parentStyle->deref(document()->renderArena());
101  filterStyle->deref(document()->renderArena());
102 
103  setStandardAttributes(m_filterEffect);
104 
105  updateLights();
106  return m_filterEffect;
107 }
108 
109 void SVGFESpecularLightingElement::updateLights() const
110 {
111  if (!m_filterEffect) {
112  return;
113  }
114 
115  SVGLightSource *light = 0;
116  for (Node *n = firstChild(); n; n = n->nextSibling()) {
117  if (n->hasTagName(SVGNames::feDistantLightTag) ||
118  n->hasTagName(SVGNames::fePointLightTag) ||
119  n->hasTagName(SVGNames::feSpotLightTag)) {
120  SVGFELightElement *lightNode = static_cast<SVGFELightElement *>(n);
121  light = lightNode->lightSource();
122  break;
123  }
124  }
125 
126  m_filterEffect->setLightSource(light);
127 }
128 
129 }
130 
131 #endif // ENABLE(SVG)
132 
MESSAGECORE_EXPORT KMime::Content * firstChild(const KMime::Content *node)
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.