SVGFEColorMatrixElement.cpp [plain text]
#include "config.h"
#if SVG_SUPPORT
#include "DeprecatedStringList.h"
#include "Attr.h"
#include <kcanvas/KCanvasResources.h>
#include <kcanvas/KCanvasFilters.h>
#include <kcanvas/device/KRenderingDevice.h>
#include <kcanvas/device/KRenderingPaintServerGradient.h>
#include "ksvg.h"
#include "SVGNames.h"
#include "SVGHelper.h"
#include "SVGRenderStyle.h"
#include "SVGFEColorMatrixElement.h"
#include "SVGAnimatedString.h"
#include "SVGAnimatedEnumeration.h"
#include "SVGAnimatedNumberList.h"
#include "SVGDOMImplementation.h"
using namespace WebCore;
SVGFEColorMatrixElement::SVGFEColorMatrixElement(const QualifiedName& tagName, Document *doc) :
SVGFilterPrimitiveStandardAttributes(tagName, doc)
{
m_filterEffect = 0;
}
SVGFEColorMatrixElement::~SVGFEColorMatrixElement()
{
delete m_filterEffect;
}
SVGAnimatedString *SVGFEColorMatrixElement::in1() const
{
SVGStyledElement *dummy = 0;
return lazy_create<SVGAnimatedString>(m_in1, dummy);
}
SVGAnimatedEnumeration *SVGFEColorMatrixElement::type() const
{
SVGStyledElement *dummy = 0;
return lazy_create<SVGAnimatedEnumeration>(m_type, dummy);
}
SVGAnimatedNumberList *SVGFEColorMatrixElement::values() const
{
SVGStyledElement *dummy = 0;
return lazy_create<SVGAnimatedNumberList>(m_values, dummy);
}
void SVGFEColorMatrixElement::parseMappedAttribute(MappedAttribute *attr)
{
const String& value = attr->value();
if (attr->name() == SVGNames::typeAttr)
{
if(value == "matrix")
type()->setBaseVal(SVG_FECOLORMATRIX_TYPE_MATRIX);
else if(value == "saturate")
type()->setBaseVal(SVG_FECOLORMATRIX_TYPE_SATURATE);
else if(value == "hueRotate")
type()->setBaseVal(SVG_FECOLORMATRIX_TYPE_HUEROTATE);
else if(value == "luminanceToAlpha")
type()->setBaseVal(SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA);
}
else if (attr->name() == SVGNames::inAttr)
in1()->setBaseVal(value.impl());
else if (attr->name() == SVGNames::valuesAttr)
values()->baseVal()->parse(value.deprecatedString(), this);
else
SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
}
KCanvasFEColorMatrix *SVGFEColorMatrixElement::filterEffect() const
{
if (!m_filterEffect)
m_filterEffect = static_cast<KCanvasFEColorMatrix *>(renderingDevice()->createFilterEffect(FE_COLOR_MATRIX));
if (!m_filterEffect)
return 0;
m_filterEffect->setIn(String(in1()->baseVal()).deprecatedString());
setStandardAttributes(m_filterEffect);
DeprecatedValueList<float> _values;
SVGNumberList *numbers = values()->baseVal();
unsigned int nr = numbers->numberOfItems();
for(unsigned int i = 0;i < nr;i++)
_values.append(numbers->getItem(i)->value());
m_filterEffect->setValues(_values);
m_filterEffect->setType((KCColorMatrixType)(type()->baseVal() - 1));
return m_filterEffect;
}
#endif // SVG_SUPPORT