SVGFEOffsetElementImpl.cpp 3.51 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 "SVGFEOffsetElementImpl.h"
#include "SVGAnimatedNumberImpl.h"
#include "SVGAnimatedStringImpl.h"
#include "SVGDOMImplementationImpl.h"

using namespace KSVG;

eseidel's avatar
eseidel committed
44
SVGFEOffsetElementImpl::SVGFEOffsetElementImpl(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_dx = 0;
    m_dy = 0;
    m_filterEffect = 0;
eseidel's avatar
eseidel committed
51
52
53
54
}

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

SVGAnimatedStringImpl *SVGFEOffsetElementImpl::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 *SVGFEOffsetElementImpl::dx() const
{
eseidel's avatar
eseidel committed
71
72
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_dx, dummy);
eseidel's avatar
eseidel committed
73
74
75
76
}

SVGAnimatedNumberImpl *SVGFEOffsetElementImpl::dy() const
{
eseidel's avatar
eseidel committed
77
78
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_dy, dummy);
eseidel's avatar
eseidel committed
79
80
81
82
}

void SVGFEOffsetElementImpl::parseAttribute(KDOM::AttributeImpl *attr)
{
eseidel's avatar
eseidel committed
83
84
85
86
87
88
    int id = (attr->id() & NodeImpl_IdLocalMask);
    KDOM::DOMString value(attr->value());
    switch(id)
    {
        case ATTR_DX:
        {
eseidel's avatar
eseidel committed
89
            dx()->setBaseVal(value.string().toDouble());
eseidel's avatar
eseidel committed
90
91
92
93
            break;
        }
        case ATTR_DY:
        {
eseidel's avatar
eseidel committed
94
            dy()->setBaseVal(value.string().toDouble());
eseidel's avatar
eseidel committed
95
96
97
98
99
100
101
102
103
104
105
106
            break;
        }
        case ATTR_IN:
        {
            in1()->setBaseVal(value.handle());
            break;
        }
        default:
        {
            SVGFilterPrimitiveStandardAttributesImpl::parseAttribute(attr);
        }
    };
eseidel's avatar
eseidel committed
107
108
109
110
}

KCanvasItem *SVGFEOffsetElementImpl::createCanvasItem(KCanvas *canvas, KRenderingStyle *style) const
{
eseidel's avatar
eseidel committed
111
112
113
114
115
116
    m_filterEffect = static_cast<KCanvasFEOffset *>(canvas->renderingDevice()->createFilterEffect(FE_OFFSET));
    m_filterEffect->setIn(KDOM::DOMString(in1()->baseVal()).string());
    setStandardAttributes(m_filterEffect);
    m_filterEffect->setDx(dx()->baseVal());
    m_filterEffect->setDy(dy()->baseVal());
    return 0;
eseidel's avatar
eseidel committed
117
118
119
120
}

KCanvasFilterEffect *SVGFEOffsetElementImpl::filterEffect() const
{
eseidel's avatar
eseidel committed
121
    return m_filterEffect;
eseidel's avatar
eseidel committed
122
123
124
}

// vim:ts=4:noet