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