1 /* 2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann (at) kde.org> 3 2004, 2005, 2006 Rob Buis <buis (at) 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 "MappedAttribute.h" 27 #include "SVGResourceFilter.h" 28 29 namespace WebCore { 30 31 SVGFEBlendElement::SVGFEBlendElement(const QualifiedName& tagName, Document* doc) 32 : SVGFilterPrimitiveStandardAttributes(tagName, doc) 33 , m_mode(FEBLEND_MODE_NORMAL) 34 { 35 } 36 37 SVGFEBlendElement::~SVGFEBlendElement() 38 { 39 } 40 41 void SVGFEBlendElement::parseMappedAttribute(MappedAttribute* attr) 42 { 43 const String& value = attr->value(); 44 if (attr->name() == SVGNames::modeAttr) { 45 if (value == "normal") 46 setModeBaseValue(FEBLEND_MODE_NORMAL); 47 else if (value == "multiply") 48 setModeBaseValue(FEBLEND_MODE_MULTIPLY); 49 else if (value == "screen") 50 setModeBaseValue(FEBLEND_MODE_SCREEN); 51 else if (value == "darken") 52 setModeBaseValue(FEBLEND_MODE_DARKEN); 53 else if (value == "lighten") 54 setModeBaseValue(FEBLEND_MODE_LIGHTEN); 55 } else if (attr->name() == SVGNames::inAttr) 56 setIn1BaseValue(value); 57 else if (attr->name() == SVGNames::in2Attr) 58 setIn2BaseValue(value); 59 else 60 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); 61 } 62 63 void SVGFEBlendElement::synchronizeProperty(const QualifiedName& attrName) 64 { 65 SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); 66 67 if (attrName == anyQName()) { 68 synchronizeMode(); 69 synchronizeIn1(); 70 synchronizeIn2(); 71 return; 72 } 73 74 if (attrName == SVGNames::modeAttr) 75 synchronizeMode(); 76 else if (attrName == SVGNames::inAttr) 77 synchronizeIn1(); 78 else if (attrName == SVGNames::in2Attr) 79 synchronizeIn2(); 80 } 81 82 bool SVGFEBlendElement::build(SVGResourceFilter* filterResource) 83 { 84 FilterEffect* input1 = filterResource->builder()->getEffectById(in1()); 85 FilterEffect* input2 = filterResource->builder()->getEffectById(in2()); 86 87 if (!input1 || !input2) 88 return false; 89 90 RefPtr<FilterEffect> effect = FEBlend::create(input1, input2, static_cast<BlendModeType>(mode())); 91 filterResource->addFilterEffect(this, effect.release()); 92 93 return true; 94 } 95 96 } 97 98 #endif // ENABLE(SVG) 99 100 // vim:ts=4:noet 101