Home | History | Annotate | Download | only in svg
      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 "SVGComponentTransferFunctionElement.h"
     25 
     26 #include "MappedAttribute.h"
     27 #include "SVGFEComponentTransferElement.h"
     28 #include "SVGNames.h"
     29 #include "SVGNumberList.h"
     30 
     31 namespace WebCore {
     32 
     33 SVGComponentTransferFunctionElement::SVGComponentTransferFunctionElement(const QualifiedName& tagName, Document* doc)
     34     : SVGElement(tagName, doc)
     35     , m_type(FECOMPONENTTRANSFER_TYPE_UNKNOWN)
     36     , m_tableValues(SVGNumberList::create(SVGNames::tableValuesAttr))
     37     , m_slope(1.0f)
     38     , m_amplitude(1.0f)
     39     , m_exponent(1.0f)
     40 {
     41 }
     42 
     43 SVGComponentTransferFunctionElement::~SVGComponentTransferFunctionElement()
     44 {
     45 }
     46 
     47 void SVGComponentTransferFunctionElement::parseMappedAttribute(MappedAttribute* attr)
     48 {
     49     const String& value = attr->value();
     50     if (attr->name() == SVGNames::typeAttr) {
     51         if (value == "identity")
     52             setTypeBaseValue(FECOMPONENTTRANSFER_TYPE_IDENTITY);
     53         else if (value == "table")
     54             setTypeBaseValue(FECOMPONENTTRANSFER_TYPE_TABLE);
     55         else if (value == "discrete")
     56             setTypeBaseValue(FECOMPONENTTRANSFER_TYPE_DISCRETE);
     57         else if (value == "linear")
     58             setTypeBaseValue(FECOMPONENTTRANSFER_TYPE_LINEAR);
     59         else if (value == "gamma")
     60             setTypeBaseValue(FECOMPONENTTRANSFER_TYPE_GAMMA);
     61     }
     62     else if (attr->name() == SVGNames::tableValuesAttr)
     63         tableValuesBaseValue()->parse(value);
     64     else if (attr->name() == SVGNames::slopeAttr)
     65         setSlopeBaseValue(value.toFloat());
     66     else if (attr->name() == SVGNames::interceptAttr)
     67         setInterceptBaseValue(value.toFloat());
     68     else if (attr->name() == SVGNames::amplitudeAttr)
     69         setAmplitudeBaseValue(value.toFloat());
     70     else if (attr->name() == SVGNames::exponentAttr)
     71         setExponentBaseValue(value.toFloat());
     72     else if (attr->name() == SVGNames::offsetAttr)
     73         setOffsetBaseValue(value.toFloat());
     74     else
     75         SVGElement::parseMappedAttribute(attr);
     76 }
     77 
     78 void SVGComponentTransferFunctionElement::synchronizeProperty(const QualifiedName& attrName)
     79 {
     80     SVGElement::synchronizeProperty(attrName);
     81 
     82     if (attrName == anyQName()) {
     83         synchronizeType();
     84         synchronizeTableValues();
     85         synchronizeSlope();
     86         synchronizeIntercept();
     87         synchronizeAmplitude();
     88         synchronizeExponent();
     89         synchronizeOffset();
     90         return;
     91     }
     92 
     93     if (attrName == SVGNames::typeAttr)
     94         synchronizeType();
     95     else if (attrName == SVGNames::tableValuesAttr)
     96         synchronizeTableValues();
     97     else if (attrName == SVGNames::slopeAttr)
     98         synchronizeSlope();
     99     else if (attrName == SVGNames::interceptAttr)
    100         synchronizeIntercept();
    101     else if (attrName == SVGNames::amplitudeAttr)
    102         synchronizeAmplitude();
    103     else if (attrName == SVGNames::exponentAttr)
    104         synchronizeExponent();
    105     else if (attrName == SVGNames::offsetAttr)
    106         synchronizeOffset();
    107 }
    108 
    109 ComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const
    110 {
    111     ComponentTransferFunction func;
    112     func.type = (ComponentTransferType) type();
    113     func.slope = slope();
    114     func.intercept = intercept();
    115     func.amplitude = amplitude();
    116     func.exponent = exponent();
    117     func.offset = offset();
    118     SVGNumberList* numbers = tableValues();
    119 
    120     ExceptionCode ec = 0;
    121     unsigned int nr = numbers->numberOfItems();
    122     for (unsigned int i = 0; i < nr; i++)
    123         func.tableValues.append(numbers->getItem(i, ec));
    124     return func;
    125 }
    126 
    127 }
    128 
    129 #endif // ENABLE(SVG)
    130