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

KHTML

SVGFESpecularLightingElement.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
00003                   2004, 2005, 2006 Rob Buis <buis@kde.org>
00004                   2005 Oliver Hunt <oliver@nerget.com>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "config.h"
00023 
00024 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
00025 #include "SVGFESpecularLightingElement.h"
00026 
00027 #include "RenderObject.h"
00028 #include "SVGColor.h"
00029 #include "SVGNames.h"
00030 #include "SVGFELightElement.h"
00031 #include "SVGParserUtilities.h"
00032 #include "SVGResourceFilter.h"
00033 
00034 namespace WebCore {
00035 
00036 SVGFESpecularLightingElement::SVGFESpecularLightingElement(const QualifiedName& tagName, Document* doc)
00037     : SVGFilterPrimitiveStandardAttributes(tagName, doc)
00038     , m_specularConstant(1.0f)
00039     , m_specularExponent(1.0f)
00040     , m_surfaceScale(1.0f)
00041     , m_kernelUnitLengthX(0.0f)
00042     , m_kernelUnitLengthY(0.0f)
00043     , m_filterEffect(0)
00044 {
00045 }
00046 
00047 SVGFESpecularLightingElement::~SVGFESpecularLightingElement()
00048 {
00049     delete m_filterEffect;
00050 }
00051 
00052 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, String, String, string, In1, in1, SVGNames::inAttr, m_in1)
00053 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SpecularConstant, specularConstant, SVGNames::specularConstantAttr, m_specularConstant)
00054 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SpecularExponent, specularExponent, SVGNames::specularExponentAttr, m_specularExponent)
00055 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SurfaceScale, surfaceScale, SVGNames::surfaceScaleAttr, m_surfaceScale)
00056 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFESpecularLightingElement, float, Number, number, KernelUnitLengthX, kernelUnitLengthX, SVGNames::kernelUnitLengthAttr, "kernelUnitLengthX", m_kernelUnitLengthX)
00057 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFESpecularLightingElement, float, Number, number, KernelUnitLengthY, kernelUnitLengthY, SVGNames::kernelUnitLengthAttr, "kernelUnitLengthY", m_kernelUnitLengthY)
00058 
00059 void SVGFESpecularLightingElement::parseMappedAttribute(MappedAttribute* attr)
00060 {    
00061     const String& value = attr->value();
00062     if (attr->name() == SVGNames::inAttr)
00063         setIn1BaseValue(value);
00064     else if (attr->name() == SVGNames::surfaceScaleAttr)
00065         setSurfaceScaleBaseValue(value.toFloat());
00066     else if (attr->name() == SVGNames::specularConstantAttr)
00067         setSpecularConstantBaseValue(value.toFloat());
00068     else if (attr->name() == SVGNames::specularExponentAttr)
00069         setSpecularExponentBaseValue(value.toFloat());
00070     else if (attr->name() == SVGNames::kernelUnitLengthAttr) {
00071         float x, y;
00072         if (parseNumberOptionalNumber(value, x, y)) {
00073             setKernelUnitLengthXBaseValue(x);
00074             setKernelUnitLengthYBaseValue(y);
00075         }
00076     } else
00077         SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
00078 }
00079 
00080 SVGFESpecularLighting* SVGFESpecularLightingElement::filterEffect(SVGResourceFilter* filter) const
00081 {
00082     if (!m_filterEffect) 
00083         m_filterEffect = new SVGFESpecularLighting(filter);
00084 
00085     m_filterEffect->setIn(in1());
00086     m_filterEffect->setSpecularConstant((specularConstant()));
00087     m_filterEffect->setSpecularExponent((specularExponent()));
00088     m_filterEffect->setSurfaceScale((surfaceScale()));
00089     m_filterEffect->setKernelUnitLengthX((kernelUnitLengthX()));
00090     m_filterEffect->setKernelUnitLengthY((kernelUnitLengthY()));
00091 
00092     SVGFESpecularLightingElement* nonConstThis = const_cast<SVGFESpecularLightingElement*>(this);
00093 
00094     RenderStyle* parentStyle = nonConstThis->styleForRenderer(parent()->renderer());    
00095     RenderStyle* filterStyle = nonConstThis->resolveStyle(parentStyle);
00096     
00097     m_filterEffect->setLightingColor(filterStyle->svgStyle()->lightingColor());
00098     
00099     parentStyle->deref(document()->renderArena());
00100     filterStyle->deref(document()->renderArena());
00101 
00102     setStandardAttributes(m_filterEffect);
00103 
00104     updateLights();
00105     return m_filterEffect;
00106 }
00107 
00108 void SVGFESpecularLightingElement::updateLights() const
00109 {
00110     if (!m_filterEffect)
00111         return;
00112 
00113     SVGLightSource* light = 0;    
00114     for (Node* n = firstChild(); n; n = n->nextSibling()) {
00115         if (n->hasTagName(SVGNames::feDistantLightTag) || 
00116             n->hasTagName(SVGNames::fePointLightTag) ||
00117             n->hasTagName(SVGNames::feSpotLightTag)) {
00118             SVGFELightElement* lightNode = static_cast<SVGFELightElement*>(n); 
00119             light = lightNode->lightSource();
00120             break;
00121         }
00122     }
00123 
00124     m_filterEffect->setLightSource(light);
00125 }
00126 
00127 }
00128 
00129 #endif // ENABLE(SVG)
00130 
00131 // vim:ts=4:noet

KHTML

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal