2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 * Copyright (C) 2005 Oliver Hunt <oliver@nerget.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
24 #if ENABLE(SVG) && ENABLE(FILTERS)
25 #include "SVGFESpecularLightingElement.h"
27 #include "Attribute.h"
28 #include "FilterEffect.h"
29 #include "RenderStyle.h"
31 #include "SVGFELightElement.h"
32 #include "SVGFilterBuilder.h"
34 #include "SVGParserUtilities.h"
38 // Animated property definitions
39 DEFINE_ANIMATED_STRING(SVGFESpecularLightingElement, SVGNames::inAttr, In1, in1)
40 DEFINE_ANIMATED_NUMBER(SVGFESpecularLightingElement, SVGNames::specularConstantAttr, SpecularConstant, specularConstant)
41 DEFINE_ANIMATED_NUMBER(SVGFESpecularLightingElement, SVGNames::specularExponentAttr, SpecularExponent, specularExponent)
42 DEFINE_ANIMATED_NUMBER(SVGFESpecularLightingElement, SVGNames::surfaceScaleAttr, SurfaceScale, surfaceScale)
43 DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFESpecularLightingElement, SVGNames::kernelUnitLengthAttr, kernelUnitLengthXIdentifier(), KernelUnitLengthX, kernelUnitLengthX)
44 DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFESpecularLightingElement, SVGNames::kernelUnitLengthAttr, kernelUnitLengthYIdentifier(), KernelUnitLengthY, kernelUnitLengthY)
46 inline SVGFESpecularLightingElement::SVGFESpecularLightingElement(const QualifiedName& tagName, Document* document)
47 : SVGFilterPrimitiveStandardAttributes(tagName, document)
48 , m_specularConstant(1)
49 , m_specularExponent(1)
54 PassRefPtr<SVGFESpecularLightingElement> SVGFESpecularLightingElement::create(const QualifiedName& tagName, Document* document)
56 return adoptRef(new SVGFESpecularLightingElement(tagName, document));
59 const AtomicString& SVGFESpecularLightingElement::kernelUnitLengthXIdentifier()
61 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGKernelUnitLengthX"));
65 const AtomicString& SVGFESpecularLightingElement::kernelUnitLengthYIdentifier()
67 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGKernelUnitLengthY"));
71 void SVGFESpecularLightingElement::parseMappedAttribute(Attribute* attr)
73 const String& value = attr->value();
74 if (attr->name() == SVGNames::inAttr)
75 setIn1BaseValue(value);
76 else if (attr->name() == SVGNames::surfaceScaleAttr)
77 setSurfaceScaleBaseValue(value.toFloat());
78 else if (attr->name() == SVGNames::specularConstantAttr)
79 setSpecularConstantBaseValue(value.toFloat());
80 else if (attr->name() == SVGNames::specularExponentAttr)
81 setSpecularExponentBaseValue(value.toFloat());
82 else if (attr->name() == SVGNames::kernelUnitLengthAttr) {
84 if (parseNumberOptionalNumber(value, x, y)) {
85 setKernelUnitLengthXBaseValue(x);
86 setKernelUnitLengthYBaseValue(y);
89 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
92 void SVGFESpecularLightingElement::svgAttributeChanged(const QualifiedName& attrName)
94 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
96 if (attrName == SVGNames::inAttr
97 || attrName == SVGNames::surfaceScaleAttr
98 || attrName == SVGNames::specularConstantAttr
99 || attrName == SVGNames::specularExponentAttr
100 || attrName == SVGNames::kernelUnitLengthAttr)
104 void SVGFESpecularLightingElement::synchronizeProperty(const QualifiedName& attrName)
106 SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName);
108 if (attrName == anyQName()) {
110 synchronizeSurfaceScale();
111 synchronizeSpecularConstant();
112 synchronizeSpecularExponent();
113 synchronizeKernelUnitLengthX();
114 synchronizeKernelUnitLengthY();
118 if (attrName == SVGNames::inAttr)
120 else if (attrName == SVGNames::surfaceScaleAttr)
121 synchronizeSurfaceScale();
122 else if (attrName == SVGNames::specularConstantAttr)
123 synchronizeSpecularConstant();
124 else if (attrName == SVGNames::specularExponentAttr)
125 synchronizeSpecularExponent();
126 else if (attrName == SVGNames::kernelUnitLengthAttr) {
127 synchronizeKernelUnitLengthX();
128 synchronizeKernelUnitLengthY();
132 AttributeToPropertyTypeMap& SVGFESpecularLightingElement::attributeToPropertyTypeMap()
134 DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
135 return s_attributeToPropertyTypeMap;
138 void SVGFESpecularLightingElement::fillAttributeToPropertyTypeMap()
140 AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
142 SVGFilterPrimitiveStandardAttributes::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap);
143 attributeToPropertyTypeMap.set(SVGNames::inAttr, AnimatedString);
144 attributeToPropertyTypeMap.set(SVGNames::specularConstantAttr, AnimatedNumber);
145 attributeToPropertyTypeMap.set(SVGNames::specularExponentAttr, AnimatedNumber);
146 attributeToPropertyTypeMap.set(SVGNames::surfaceScaleAttr, AnimatedNumber);
147 attributeToPropertyTypeMap.set(SVGNames::kernelUnitLengthAttr, AnimatedNumberOptionalNumber);
150 PassRefPtr<LightSource> SVGFESpecularLightingElement::findLights() const
152 for (Node* node = firstChild(); node; node = node->nextSibling()) {
153 if (node->hasTagName(SVGNames::feDistantLightTag)
154 || node->hasTagName(SVGNames::fePointLightTag)
155 || node->hasTagName(SVGNames::feSpotLightTag)) {
156 SVGFELightElement* lightNode = static_cast<SVGFELightElement*>(node);
157 return lightNode->lightSource();
164 PassRefPtr<FilterEffect> SVGFESpecularLightingElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
166 FilterEffect* input1 = filterBuilder->getEffectById(in1());
171 RefPtr<RenderStyle> filterStyle = styleForRenderer();
173 Color color = filterStyle->svgStyle()->lightingColor();
175 RefPtr<FilterEffect> effect = FESpecularLighting::create(filter, color, surfaceScale(), specularConstant(),
176 specularExponent(), kernelUnitLengthX(), kernelUnitLengthY(), findLights());
177 effect->inputEffects().append(input1);
178 return effect.release();
183 #endif // ENABLE(SVG)