SVGFETurbulenceElementImpl.cpp 5.6 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
44
45

#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 "ksvg.h"
#include "svgattrs.h"
#include "SVGHelper.h"
#include "SVGRenderStyle.h"
#include "SVGFETurbulenceElementImpl.h"
#include "SVGAnimatedNumberImpl.h"
#include "SVGAnimatedEnumerationImpl.h"
#include "SVGAnimatedIntegerImpl.h"
#include "SVGDOMImplementationImpl.h"

using namespace KSVG;

eseidel's avatar
eseidel committed
46
SVGFETurbulenceElementImpl::SVGFETurbulenceElementImpl(KDOM::DocumentPtr *doc, KDOM::NodeImpl::Id id, KDOM::DOMStringImpl *prefix) : 
eseidel's avatar
eseidel committed
47
48
SVGFilterPrimitiveStandardAttributesImpl(doc, id, prefix)
{
eseidel's avatar
eseidel committed
49
50
51
52
    m_baseFrequencyX = m_baseFrequencyY = m_seed = 0;
    m_numOctaves = 0;
    m_stitchTiles = m_type = 0;
    m_filterEffect = 0;
eseidel's avatar
eseidel committed
53
54
55
56
}

SVGFETurbulenceElementImpl::~SVGFETurbulenceElementImpl()
{
eseidel's avatar
eseidel committed
57
58
59
60
61
62
63
64
65
66
67
68
    if(m_baseFrequencyX)
        m_baseFrequencyX->deref();
    if(m_baseFrequencyY)
        m_baseFrequencyY->deref();
    if(m_numOctaves)
        m_numOctaves->deref();
    if(m_seed)
        m_seed->deref();
    if(m_stitchTiles)
        m_stitchTiles->deref();
    if(m_type)
        m_type->deref();
eseidel's avatar
eseidel committed
69
70
71
72
}

SVGAnimatedNumberImpl *SVGFETurbulenceElementImpl::baseFrequencyX() const
{
eseidel's avatar
eseidel committed
73
74
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_baseFrequencyX, dummy);
eseidel's avatar
eseidel committed
75
76
77
78
}

SVGAnimatedNumberImpl *SVGFETurbulenceElementImpl::baseFrequencyY() const
{
eseidel's avatar
eseidel committed
79
80
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_baseFrequencyY, dummy);
eseidel's avatar
eseidel committed
81
82
83
84
}

SVGAnimatedNumberImpl *SVGFETurbulenceElementImpl::seed() const
{
eseidel's avatar
eseidel committed
85
86
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_seed, dummy);
eseidel's avatar
eseidel committed
87
88
89
90
}

SVGAnimatedIntegerImpl *SVGFETurbulenceElementImpl::numOctaves() const
{
eseidel's avatar
eseidel committed
91
92
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedIntegerImpl>(m_numOctaves, dummy);
eseidel's avatar
eseidel committed
93
94
95
96
}

SVGAnimatedEnumerationImpl *SVGFETurbulenceElementImpl::stitchTiles() const
{
eseidel's avatar
eseidel committed
97
98
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedEnumerationImpl>(m_stitchTiles, dummy);
eseidel's avatar
eseidel committed
99
100
101
102
}

SVGAnimatedEnumerationImpl *SVGFETurbulenceElementImpl::type() const
{
eseidel's avatar
eseidel committed
103
104
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedEnumerationImpl>(m_type, dummy);
eseidel's avatar
eseidel committed
105
106
107
108
}

void SVGFETurbulenceElementImpl::parseAttribute(KDOM::AttributeImpl *attr)
{
eseidel's avatar
eseidel committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    int id = (attr->id() & NodeImpl_IdLocalMask);
    KDOM::DOMString value(attr->value());
    switch(id)
    {
        case ATTR_TYPE:
        {
            if(value == "fractalNoise")
                type()->setBaseVal(SVG_TURBULENCE_TYPE_FRACTALNOISE);
            else if(value == "turbulence")
                type()->setBaseVal(SVG_TURBULENCE_TYPE_TURBULENCE);
            break;
        }
        case ATTR_STITCHTILES:
        {
            if(value == "stitch")
                stitchTiles()->setBaseVal(SVG_STITCHTYPE_STITCH);
            else if(value == "nostitch")
                stitchTiles()->setBaseVal(SVG_STITCHTYPE_NOSTITCH);
            break;
        }
        case ATTR_BASEFREQUENCY:
        {
            QStringList numbers = QStringList::split(' ', value.string());
eseidel's avatar
eseidel committed
132
            baseFrequencyX()->setBaseVal(numbers[0].toDouble());
eseidel's avatar
eseidel committed
133
            if(numbers.count() == 1)
eseidel's avatar
eseidel committed
134
                baseFrequencyY()->setBaseVal(numbers[0].toDouble());
eseidel's avatar
eseidel committed
135
            else
eseidel's avatar
eseidel committed
136
                baseFrequencyY()->setBaseVal(numbers[1].toDouble());
eseidel's avatar
eseidel committed
137
138
139
140
141

            break;
        }
        case ATTR_SEED:
        {
eseidel's avatar
eseidel committed
142
            seed()->setBaseVal(value.string().toDouble());
eseidel's avatar
eseidel committed
143
144
145
146
147
148
149
150
151
152
153
154
            break;
        }
        case ATTR_NUMOCTAVES:
        {
            numOctaves()->setBaseVal(value.string().toUInt());
            break;
        }
        default:
        {
            SVGFilterPrimitiveStandardAttributesImpl::parseAttribute(attr);
        }
    };
eseidel's avatar
eseidel committed
155
156
157
158
159
}

KCanvasItem *SVGFETurbulenceElementImpl::createCanvasItem(KCanvas *canvas, KRenderingStyle *style) const
{

eseidel's avatar
eseidel committed
160
    m_filterEffect = static_cast<KCanvasFETurbulence *>(canvas->renderingDevice()->createFilterEffect(FE_TURBULENCE));
eseidel's avatar
eseidel committed
161
162
163
    if (!m_filterEffect)
        return 0;
    
eseidel's avatar
eseidel committed
164
165
166
167
168
169
170
    m_filterEffect->setType((KCTurbulanceType)(type()->baseVal() - 1));
    setStandardAttributes(m_filterEffect);
    m_filterEffect->setBaseFrequencyX(baseFrequencyX()->baseVal());
    m_filterEffect->setBaseFrequencyY(baseFrequencyY()->baseVal());
    m_filterEffect->setNumOctaves(numOctaves()->baseVal());
    m_filterEffect->setSeed(seed()->baseVal());
    m_filterEffect->setStitchTiles(stitchTiles()->baseVal() == SVG_STITCHTYPE_STITCH);
eseidel's avatar
eseidel committed
171
    return 0;
eseidel's avatar
eseidel committed
172
173
174
175
}

KCanvasFilterEffect *SVGFETurbulenceElementImpl::filterEffect() const
{
eseidel's avatar
eseidel committed
176
    return m_filterEffect;
eseidel's avatar
eseidel committed
177
178
179
}

// vim:ts=4:noet