SVGFEGaussianBlurElementImpl.cpp 3.99 KB
Newer Older
eseidel's avatar
eseidel committed
1
/*
eseidel's avatar
eseidel committed
2
    Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
eseidel's avatar
eseidel committed
3
                  2004, 2005 Rob Buis <buis@kde.org>
eseidel's avatar
eseidel committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

    This file is part of the KDE project

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <qstringlist.h>

eseidel's avatar
eseidel committed
25
#include <kdom/core/AttrImpl.h>
eseidel's avatar
eseidel committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#include <kcanvas/KCanvas.h>
#include <kcanvas/KCanvasRegistry.h>
#include <kcanvas/KCanvasResources.h>
#include <kcanvas/KCanvasFilters.h>
#include <kcanvas/device/KRenderingDevice.h>
#include <kcanvas/device/KRenderingPaintServerGradient.h>

#include "svgattrs.h"
#include "SVGHelper.h"
#include "SVGRenderStyle.h"
#include "SVGFEGaussianBlurElementImpl.h"
#include "SVGAnimatedNumberImpl.h"
#include "SVGAnimatedStringImpl.h"
#include "SVGDOMImplementationImpl.h"

using namespace KSVG;

eseidel's avatar
eseidel committed
44
SVGFEGaussianBlurElementImpl::SVGFEGaussianBlurElementImpl(KDOM::DocumentPtr *doc, KDOM::NodeImpl::Id id, KDOM::DOMStringImpl *prefix) : 
eseidel's avatar
eseidel committed
45
46
SVGFilterPrimitiveStandardAttributesImpl(doc, id, prefix)
{
eseidel's avatar
eseidel committed
47
48
49
50
    m_in1 = 0;
    m_stdDeviationX = 0;
    m_stdDeviationY = 0;
    m_filterEffect = 0;
eseidel's avatar
eseidel committed
51
52
53
54
}

SVGFEGaussianBlurElementImpl::~SVGFEGaussianBlurElementImpl()
{
eseidel's avatar
eseidel committed
55
56
57
58
59
60
    if(m_in1)
        m_in1->deref();
    if(m_stdDeviationX)
        m_stdDeviationX->deref();
    if(m_stdDeviationY)
        m_stdDeviationY->deref();
eseidel's avatar
eseidel committed
61
62
63
64
}

SVGAnimatedStringImpl *SVGFEGaussianBlurElementImpl::in1() const
{
eseidel's avatar
eseidel committed
65
66
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedStringImpl>(m_in1, dummy);
eseidel's avatar
eseidel committed
67
68
69
70
}

SVGAnimatedNumberImpl *SVGFEGaussianBlurElementImpl::stdDeviationX() const
{
eseidel's avatar
eseidel committed
71
72
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_stdDeviationX, dummy);
eseidel's avatar
eseidel committed
73
74
75
76
}

SVGAnimatedNumberImpl *SVGFEGaussianBlurElementImpl::stdDeviationY() const
{
eseidel's avatar
eseidel committed
77
78
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_stdDeviationY, dummy);
eseidel's avatar
eseidel committed
79
80
81
82
83
84
85
86
}

void SVGFEGaussianBlurElementImpl::setStdDeviation(float stdDeviationX, float stdDeviationY)
{
}

void SVGFEGaussianBlurElementImpl::parseAttribute(KDOM::AttributeImpl *attr)
{
eseidel's avatar
eseidel committed
87
88
89
90
91
92
93
    int id = (attr->id() & NodeImpl_IdLocalMask);
    KDOM::DOMString value(attr->value());
    switch(id)
    {
        case ATTR_STDDEVIATION:
        {
            QStringList numbers = QStringList::split(' ', value.string());
eseidel's avatar
eseidel committed
94
            stdDeviationX()->setBaseVal(numbers[0].toDouble());
eseidel's avatar
eseidel committed
95
            if(numbers.count() == 1)
eseidel's avatar
eseidel committed
96
                stdDeviationY()->setBaseVal(numbers[0].toDouble());
eseidel's avatar
eseidel committed
97
            else
eseidel's avatar
eseidel committed
98
                stdDeviationY()->setBaseVal(numbers[1].toDouble());
eseidel's avatar
eseidel committed
99
100
101
102
103
104
105
106
107
108
109
110
111

            break;
        }
        case ATTR_IN:
        {
            in1()->setBaseVal(value.handle());
            break;
        }
        default:
        {
            SVGFilterPrimitiveStandardAttributesImpl::parseAttribute(attr);
        }
    };
eseidel's avatar
eseidel committed
112
113
114
115
}

KCanvasItem *SVGFEGaussianBlurElementImpl::createCanvasItem(KCanvas *canvas, KRenderingStyle *style) const
{
eseidel's avatar
eseidel committed
116
117
118
119
120
121
    m_filterEffect = static_cast<KCanvasFEGaussianBlur *>(canvas->renderingDevice()->createFilterEffect(FE_GAUSSIAN_BLUR));
    m_filterEffect->setIn(KDOM::DOMString(in1()->baseVal()).string());
    setStandardAttributes(m_filterEffect);
    m_filterEffect->setStdDeviationX(stdDeviationX()->baseVal());
    m_filterEffect->setStdDeviationY(stdDeviationY()->baseVal());
    return 0;
eseidel's avatar
eseidel committed
122
123
124
125
}

KCanvasFilterEffect *SVGFEGaussianBlurElementImpl::filterEffect() const
{
eseidel's avatar
eseidel committed
126
    return m_filterEffect;
eseidel's avatar
eseidel committed
127
128
129
}

// vim:ts=4:noet