2 Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>
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.
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.
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.
22 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
23 #include "SVGFEDiffuseLightingElement.h"
26 #include "RenderObject.h"
28 #include "SVGFELightElement.h"
30 #include "SVGParserUtilities.h"
31 #include "SVGRenderStyle.h"
32 #include "SVGFEDiffuseLighting.h"
33 #include "SVGResourceFilter.h"
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
)
47 SVGFEDiffuseLightingElement::~SVGFEDiffuseLightingElement()
49 delete m_filterEffect
;
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
)
58 void SVGFEDiffuseLightingElement::parseMappedAttribute(MappedAttribute
*attr
)
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
) {
69 if (parseNumberOptionalNumber(value
, x
, y
)) {
70 setKernelUnitLengthXBaseValue(x
);
71 setKernelUnitLengthYBaseValue(y
);
74 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr
);
77 SVGFilterEffect
* SVGFEDiffuseLightingElement::filterEffect(SVGResourceFilter
* filter
) const
80 m_filterEffect
= new SVGFEDiffuseLighting(filter
);
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());
88 SVGFEDiffuseLightingElement
* nonConstThis
= const_cast<SVGFEDiffuseLightingElement
*>(this);
90 RenderStyle
* parentStyle
= nonConstThis
->styleForRenderer(parent()->renderer());
91 RenderStyle
* filterStyle
= nonConstThis
->resolveStyle(parentStyle
);
93 m_filterEffect
->setLightingColor(filterStyle
->svgStyle()->lightingColor());
94 setStandardAttributes(m_filterEffect
);
96 parentStyle
->deref(document()->renderArena());
97 filterStyle
->deref(document()->renderArena());
100 return m_filterEffect
;
103 void SVGFEDiffuseLightingElement::updateLights() const
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();
119 m_filterEffect
->setLightSource(light
);
124 #endif // ENABLE(SVG)