00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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