• 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
SVGFEDiffuseLightingElement.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>
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 #include "config.h"
21 
22 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
23 #include "SVGFEDiffuseLightingElement.h"
24 
25 #include "Attr.h"
26 #include "RenderObject.h"
27 #include "SVGColor.h"
28 #include "SVGFELightElement.h"
29 #include "SVGNames.h"
30 #include "SVGParserUtilities.h"
31 #include "SVGRenderStyle.h"
32 #include "SVGFEDiffuseLighting.h"
33 #include "SVGResourceFilter.h"
34 
35 namespace WebCore {
36 
37 SVGFEDiffuseLightingElement::SVGFEDiffuseLightingElement(const QualifiedName& tagName, Document* doc)
38  : SVGFilterPrimitiveStandardAttributes(tagName, doc)
39  , m_diffuseConstant(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 SVGFEDiffuseLightingElement::~SVGFEDiffuseLightingElement()
48 {
49  delete m_filterEffect;
50 }
51 
52 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDiffuseLightingElement, String, String, string, In1, in1, SVGNames::inAttr, m_in1)
53 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDiffuseLightingElement, float, Number, number, DiffuseConstant, diffuseConstant, SVGNames::diffuseConstantAttr, m_diffuseConstant)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDiffuseLightingElement, float, Number, number, SurfaceScale, surfaceScale, SVGNames::surfaceScaleAttr, m_surfaceScale)
55 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFEDiffuseLightingElement, float, Number, number, KernelUnitLengthX, kernelUnitLengthX, SVGNames::kernelUnitLengthAttr, "kernelUnitLengthX", m_kernelUnitLengthX)
56 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFEDiffuseLightingElement, float, Number, number, KernelUnitLengthY, kernelUnitLengthY, SVGNames::kernelUnitLengthAttr, "kernelUnitLengthY", m_kernelUnitLengthY)
57 
58 void SVGFEDiffuseLightingElement::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::diffuseConstantAttr)
66  setDiffuseConstantBaseValue(value.toInt());
67  else if (attr->name() == SVGNames::kernelUnitLengthAttr) {
68  float x, y;
69  if (parseNumberOptionalNumber(value, x, y)) {
70  setKernelUnitLengthXBaseValue(x);
71  setKernelUnitLengthYBaseValue(y);
72  }
73  } else
74  SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
75 }
76 
77 SVGFilterEffect* SVGFEDiffuseLightingElement::filterEffect(SVGResourceFilter* filter) const
78 {
79  if (!m_filterEffect)
80  m_filterEffect = new SVGFEDiffuseLighting(filter);
81 
82  m_filterEffect->setIn(in1());
83  m_filterEffect->setDiffuseConstant(diffuseConstant());
84  m_filterEffect->setSurfaceScale(surfaceScale());
85  m_filterEffect->setKernelUnitLengthX(kernelUnitLengthX());
86  m_filterEffect->setKernelUnitLengthY(kernelUnitLengthY());
87 
88  SVGFEDiffuseLightingElement* nonConstThis = const_cast<SVGFEDiffuseLightingElement*>(this);
89 
90  RenderStyle* parentStyle = nonConstThis->styleForRenderer(parent()->renderer());
91  RenderStyle* filterStyle = nonConstThis->resolveStyle(parentStyle);
92 
93  m_filterEffect->setLightingColor(filterStyle->svgStyle()->lightingColor());
94  setStandardAttributes(m_filterEffect);
95 
96  parentStyle->deref(document()->renderArena());
97  filterStyle->deref(document()->renderArena());
98 
99  updateLights();
100  return m_filterEffect;
101 }
102 
103 void SVGFEDiffuseLightingElement::updateLights() const
104 {
105  if (!m_filterEffect)
106  return;
107 
108  SVGLightSource* light = 0;
109  for (Node* n = firstChild(); n; n = n->nextSibling()) {
110  if (n->hasTagName(SVGNames::feDistantLightTag) ||
111  n->hasTagName(SVGNames::fePointLightTag) ||
112  n->hasTagName(SVGNames::feSpotLightTag)) {
113  SVGFELightElement* lightNode = static_cast<SVGFELightElement*>(n);
114  light = lightNode->lightSource();
115  break;
116  }
117  }
118 
119  m_filterEffect->setLightSource(light);
120 }
121 
122 }
123 
124 #endif // ENABLE(SVG)
125 
126 // vim:ts=4:noet
WebCore::SVGNames::feSpotLightTag
DOM::QualifiedName feSpotLightTag
Definition: SVGNames.cpp:59
WebCore::SVGNames::fePointLightTag
DOM::QualifiedName fePointLightTag
Definition: SVGNames.cpp:57
SVGParserUtilities.h
WebCore::SVGNames::surfaceScaleAttr
DOM::QualifiedName surfaceScaleAttr
Definition: SVGNames.cpp:300
WebCore::SVGNames::kernelUnitLengthAttr
DOM::QualifiedName kernelUnitLengthAttr
Definition: SVGNames.cpp:201
WebCore::SVGNames::diffuseConstantAttr
DOM::QualifiedName diffuseConstantAttr
Definition: SVGNames.cpp:139
SVGNames.h
WebCore::SVGNames::inAttr
DOM::QualifiedName inAttr
Definition: SVGNames.cpp:192
WebCore::SVGNames::feDistantLightTag
DOM::QualifiedName feDistantLightTag
Definition: SVGNames.cpp:45
SVGResourceFilter.h
SVGFEDiffuseLighting.h
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
RenderObject.h
SVGFELightElement.h
SVGFEDiffuseLightingElement.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