1/* 2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21#include "config.h" 22 23#if ENABLE(SVG) && ENABLE(FILTERS) 24#include "SVGFEBlendElement.h" 25 26#include "Attribute.h" 27#include "FilterEffect.h" 28#include "SVGFilterBuilder.h" 29#include "SVGNames.h" 30 31namespace WebCore { 32 33// Animated property definitions 34DEFINE_ANIMATED_STRING(SVGFEBlendElement, SVGNames::inAttr, In1, in1) 35DEFINE_ANIMATED_STRING(SVGFEBlendElement, SVGNames::in2Attr, In2, in2) 36DEFINE_ANIMATED_ENUMERATION(SVGFEBlendElement, SVGNames::modeAttr, Mode, mode) 37 38inline SVGFEBlendElement::SVGFEBlendElement(const QualifiedName& tagName, Document* document) 39 : SVGFilterPrimitiveStandardAttributes(tagName, document) 40 , m_mode(FEBLEND_MODE_NORMAL) 41{ 42} 43 44PassRefPtr<SVGFEBlendElement> SVGFEBlendElement::create(const QualifiedName& tagName, Document* document) 45{ 46 return adoptRef(new SVGFEBlendElement(tagName, document)); 47} 48 49void SVGFEBlendElement::parseMappedAttribute(Attribute* attr) 50{ 51 const String& value = attr->value(); 52 if (attr->name() == SVGNames::modeAttr) { 53 if (value == "normal") 54 setModeBaseValue(FEBLEND_MODE_NORMAL); 55 else if (value == "multiply") 56 setModeBaseValue(FEBLEND_MODE_MULTIPLY); 57 else if (value == "screen") 58 setModeBaseValue(FEBLEND_MODE_SCREEN); 59 else if (value == "darken") 60 setModeBaseValue(FEBLEND_MODE_DARKEN); 61 else if (value == "lighten") 62 setModeBaseValue(FEBLEND_MODE_LIGHTEN); 63 } else if (attr->name() == SVGNames::inAttr) 64 setIn1BaseValue(value); 65 else if (attr->name() == SVGNames::in2Attr) 66 setIn2BaseValue(value); 67 else 68 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); 69} 70 71bool SVGFEBlendElement::setFilterEffectAttribute(FilterEffect* effect, const QualifiedName& attrName) 72{ 73 FEBlend* blend = static_cast<FEBlend*>(effect); 74 if (attrName == SVGNames::modeAttr) 75 return blend->setBlendMode(static_cast<BlendModeType>(mode())); 76 77 ASSERT_NOT_REACHED(); 78 return false; 79} 80 81void SVGFEBlendElement::svgAttributeChanged(const QualifiedName& attrName) 82{ 83 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); 84 85 if (attrName == SVGNames::modeAttr) 86 primitiveAttributeChanged(attrName); 87 88 if (attrName == SVGNames::inAttr 89 || attrName == SVGNames::in2Attr) 90 invalidate(); 91} 92 93void SVGFEBlendElement::synchronizeProperty(const QualifiedName& attrName) 94{ 95 SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); 96 97 if (attrName == anyQName()) { 98 synchronizeMode(); 99 synchronizeIn1(); 100 synchronizeIn2(); 101 return; 102 } 103 104 if (attrName == SVGNames::modeAttr) 105 synchronizeMode(); 106 else if (attrName == SVGNames::inAttr) 107 synchronizeIn1(); 108 else if (attrName == SVGNames::in2Attr) 109 synchronizeIn2(); 110} 111 112AttributeToPropertyTypeMap& SVGFEBlendElement::attributeToPropertyTypeMap() 113{ 114 DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ()); 115 return s_attributeToPropertyTypeMap; 116} 117 118void SVGFEBlendElement::fillAttributeToPropertyTypeMap() 119{ 120 AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap(); 121 122 SVGFilterPrimitiveStandardAttributes::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap); 123 attributeToPropertyTypeMap.set(SVGNames::inAttr, AnimatedString); 124 attributeToPropertyTypeMap.set(SVGNames::in2Attr, AnimatedString); 125 attributeToPropertyTypeMap.set(SVGNames::modeAttr, AnimatedEnumeration); 126} 127 128PassRefPtr<FilterEffect> SVGFEBlendElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) 129{ 130 FilterEffect* input1 = filterBuilder->getEffectById(in1()); 131 FilterEffect* input2 = filterBuilder->getEffectById(in2()); 132 133 if (!input1 || !input2) 134 return 0; 135 136 RefPtr<FilterEffect> effect = FEBlend::create(filter, static_cast<BlendModeType>(mode())); 137 FilterEffectVector& inputEffects = effect->inputEffects(); 138 inputEffects.reserveCapacity(2); 139 inputEffects.append(input1); 140 inputEffects.append(input2); 141 return effect.release(); 142} 143 144} 145 146#endif // ENABLE(SVG) 147 148// vim:ts=4:noet 149