• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
SVGFESpecularLightingElement.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  2004, 2005, 2006 Rob Buis <buis@kde.org>
4  2005 Oliver Hunt <oliver@nerget.com>
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 #include "config.h"
23 
24 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
25 #include "SVGFESpecularLightingElement.h"
26 
27 #include "RenderObject.h"
28 #include "SVGColor.h"
29 #include "SVGNames.h"
30 #include "SVGFELightElement.h"
31 #include "SVGParserUtilities.h"
32 #include "SVGResourceFilter.h"
33 
34 namespace WebCore {
35 
36 SVGFESpecularLightingElement::SVGFESpecularLightingElement(const QualifiedName& tagName, Document* doc)
37  : SVGFilterPrimitiveStandardAttributes(tagName, doc)
38  , m_specularConstant(1.0f)
39  , m_specularExponent(1.0f)
40  , m_surfaceScale(1.0f)
41  , m_kernelUnitLengthX(0.0f)
42  , m_kernelUnitLengthY(0.0f)
43  , m_filterEffect(0)
44 {
45 }
46 
47 SVGFESpecularLightingElement::~SVGFESpecularLightingElement()
48 {
49  delete m_filterEffect;
50 }
51 
52 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, String, String, string, In1, in1, SVGNames::inAttr, m_in1)
53 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SpecularConstant, specularConstant, SVGNames::specularConstantAttr, m_specularConstant)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SpecularExponent, specularExponent, SVGNames::specularExponentAttr, m_specularExponent)
55 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SurfaceScale, surfaceScale, SVGNames::surfaceScaleAttr, m_surfaceScale)
56 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFESpecularLightingElement, float, Number, number, KernelUnitLengthX, kernelUnitLengthX, SVGNames::kernelUnitLengthAttr, "kernelUnitLengthX", m_kernelUnitLengthX)
57 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFESpecularLightingElement, float, Number, number, KernelUnitLengthY, kernelUnitLengthY, SVGNames::kernelUnitLengthAttr, "kernelUnitLengthY", m_kernelUnitLengthY)
58 
59 void SVGFESpecularLightingElement::parseMappedAttribute(MappedAttribute* attr)
60 {
61  const String& value = attr->value();
62  if (attr->name() == SVGNames::inAttr)
63  setIn1BaseValue(value);
64  else if (attr->name() == SVGNames::surfaceScaleAttr)
65  setSurfaceScaleBaseValue(value.toFloat());
66  else if (attr->name() == SVGNames::specularConstantAttr)
67  setSpecularConstantBaseValue(value.toFloat());
68  else if (attr->name() == SVGNames::specularExponentAttr)
69  setSpecularExponentBaseValue(value.toFloat());
70  else if (attr->name() == SVGNames::kernelUnitLengthAttr) {
71  float x, y;
72  if (parseNumberOptionalNumber(value, x, y)) {
73  setKernelUnitLengthXBaseValue(x);
74  setKernelUnitLengthYBaseValue(y);
75  }
76  } else
77  SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
78 }
79 
80 SVGFESpecularLighting* SVGFESpecularLightingElement::filterEffect(SVGResourceFilter* filter) const
81 {
82  if (!m_filterEffect)
83  m_filterEffect = new SVGFESpecularLighting(filter);
84 
85  m_filterEffect->setIn(in1());
86  m_filterEffect->setSpecularConstant((specularConstant()));
87  m_filterEffect->setSpecularExponent((specularExponent()));
88  m_filterEffect->setSurfaceScale((surfaceScale()));
89  m_filterEffect->setKernelUnitLengthX((kernelUnitLengthX()));
90  m_filterEffect->setKernelUnitLengthY((kernelUnitLengthY()));
91 
92  SVGFESpecularLightingElement* nonConstThis = const_cast<SVGFESpecularLightingElement*>(this);
93 
94  RenderStyle* parentStyle = nonConstThis->styleForRenderer(parent()->renderer());
95  RenderStyle* filterStyle = nonConstThis->resolveStyle(parentStyle);
96 
97  m_filterEffect->setLightingColor(filterStyle->svgStyle()->lightingColor());
98 
99  parentStyle->deref(document()->renderArena());
100  filterStyle->deref(document()->renderArena());
101 
102  setStandardAttributes(m_filterEffect);
103 
104  updateLights();
105  return m_filterEffect;
106 }
107 
108 void SVGFESpecularLightingElement::updateLights() const
109 {
110  if (!m_filterEffect)
111  return;
112 
113  SVGLightSource* light = 0;
114  for (Node* n = firstChild(); n; n = n->nextSibling()) {
115  if (n->hasTagName(SVGNames::feDistantLightTag) ||
116  n->hasTagName(SVGNames::fePointLightTag) ||
117  n->hasTagName(SVGNames::feSpotLightTag)) {
118  SVGFELightElement* lightNode = static_cast<SVGFELightElement*>(n);
119  light = lightNode->lightSource();
120  break;
121  }
122  }
123 
124  m_filterEffect->setLightSource(light);
125 }
126 
127 }
128 
129 #endif // ENABLE(SVG)
130 
131 // vim:ts=4:noet
WebCore::SVGNames::feSpotLightTag
DOM::QualifiedName feSpotLightTag
Definition: SVGNames.cpp:59
WebCore::SVGNames::fePointLightTag
DOM::QualifiedName fePointLightTag
Definition: SVGNames.cpp:57
WebCore::SVGNames::specularConstantAttr
DOM::QualifiedName specularConstantAttr
Definition: SVGNames.cpp:279
SVGParserUtilities.h
WebCore::SVGNames::specularExponentAttr
DOM::QualifiedName specularExponentAttr
Definition: SVGNames.cpp:280
WebCore::SVGNames::surfaceScaleAttr
DOM::QualifiedName surfaceScaleAttr
Definition: SVGNames.cpp:300
WebCore::SVGNames::kernelUnitLengthAttr
DOM::QualifiedName kernelUnitLengthAttr
Definition: SVGNames.cpp:201
SVGFESpecularLightingElement.h
SVGNames.h
WebCore::SVGNames::inAttr
DOM::QualifiedName inAttr
Definition: SVGNames.cpp:192
WebCore::SVGNames::feDistantLightTag
DOM::QualifiedName feDistantLightTag
Definition: SVGNames.cpp:45
SVGResourceFilter.h
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
RenderObject.h
SVGFELightElement.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal