SVGComponentTransferFunctionElementImpl.cpp 5 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

#include "ksvg.h"
#include "svgattrs.h"
#include "SVGHelper.h"
#include "SVGRenderStyle.h"
#include "SVGComponentTransferFunctionElementImpl.h"
#include "SVGAnimatedNumberImpl.h"
#include "SVGAnimatedEnumerationImpl.h"
#include "SVGAnimatedNumberListImpl.h"
#include "SVGDOMImplementationImpl.h"

using namespace KSVG;

eseidel's avatar
eseidel committed
39
SVGComponentTransferFunctionElementImpl::SVGComponentTransferFunctionElementImpl(KDOM::DocumentPtr *doc, KDOM::NodeImpl::Id id, KDOM::DOMStringImpl *prefix) : 
eseidel's avatar
eseidel committed
40
41
SVGElementImpl(doc, id, prefix)
{
eseidel's avatar
eseidel committed
42
43
44
45
46
47
48
    m_type = 0;
    m_tableValues = 0;
    m_slope = 0;
    m_intercept = 0;
    m_amplitude = 0;
    m_exponent = 0;
    m_offset = 0;
eseidel's avatar
eseidel committed
49
50
51
52
}

SVGComponentTransferFunctionElementImpl::~SVGComponentTransferFunctionElementImpl()
{
eseidel's avatar
eseidel committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    if(m_type)
        m_type->deref();
    if(m_tableValues)
        m_tableValues->deref();
    if(m_slope)
        m_slope->deref();
    if(m_intercept)
        m_intercept->deref();
    if(m_amplitude)
        m_amplitude->deref();
    if(m_exponent)
        m_exponent->deref();
    if(m_offset)
        m_offset->deref();
eseidel's avatar
eseidel committed
67
68
69
70
}

SVGAnimatedEnumerationImpl *SVGComponentTransferFunctionElementImpl::type() const
{
eseidel's avatar
eseidel committed
71
72
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedEnumerationImpl>(m_type, dummy);
eseidel's avatar
eseidel committed
73
74
75
76
}

SVGAnimatedNumberListImpl *SVGComponentTransferFunctionElementImpl::tableValues() const
{
eseidel's avatar
eseidel committed
77
78
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberListImpl>(m_tableValues, dummy);
eseidel's avatar
eseidel committed
79
80
81
82
}

SVGAnimatedNumberImpl *SVGComponentTransferFunctionElementImpl::slope() const
{
eseidel's avatar
eseidel committed
83
84
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_slope, dummy);
eseidel's avatar
eseidel committed
85
86
87
88
}

SVGAnimatedNumberImpl *SVGComponentTransferFunctionElementImpl::intercept() const
{
eseidel's avatar
eseidel committed
89
90
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_intercept, dummy);
eseidel's avatar
eseidel committed
91
92
93
94
}

SVGAnimatedNumberImpl *SVGComponentTransferFunctionElementImpl::amplitude() const
{
eseidel's avatar
eseidel committed
95
96
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_amplitude, dummy);
eseidel's avatar
eseidel committed
97
98
99
100
}

SVGAnimatedNumberImpl *SVGComponentTransferFunctionElementImpl::exponent() const
{
eseidel's avatar
eseidel committed
101
102
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_exponent, dummy);
eseidel's avatar
eseidel committed
103
104
105
106
}

SVGAnimatedNumberImpl *SVGComponentTransferFunctionElementImpl::offset() const
{
eseidel's avatar
eseidel committed
107
108
    SVGStyledElementImpl *dummy = 0;
    return lazy_create<SVGAnimatedNumberImpl>(m_offset, dummy);
eseidel's avatar
eseidel committed
109
110
111
112
}

void SVGComponentTransferFunctionElementImpl::parseAttribute(KDOM::AttributeImpl *attr)
{
eseidel's avatar
eseidel committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
    int id = (attr->id() & NodeImpl_IdLocalMask);
    KDOM::DOMString value(attr->value());
    switch(id)
    {
        case ATTR_TYPE:
        {
            if(value == "identity")
                type()->setBaseVal(SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
            else if(value == "table")
                type()->setBaseVal(SVG_FECOMPONENTTRANSFER_TYPE_TABLE);
            else if(value == "discrete")
                type()->setBaseVal(SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE);
            else if(value == "linear")
                type()->setBaseVal(SVG_FECOMPONENTTRANSFER_TYPE_LINEAR);
            else if(value == "gamma")
                type()->setBaseVal(SVG_FECOMPONENTTRANSFER_TYPE_GAMMA);
            break;
        }
        case ATTR_VALUES:
        {
            tableValues()->baseVal()->parse(value.string());
            break;
        }
        case ATTR_SLOPE:
        {
eseidel's avatar
eseidel committed
138
            slope()->setBaseVal(value.string().toDouble());
eseidel's avatar
eseidel committed
139
140
141
142
            break;
        }
        case ATTR_INTERCEPT:
        {
eseidel's avatar
eseidel committed
143
            intercept()->setBaseVal(value.string().toDouble());
eseidel's avatar
eseidel committed
144
145
146
147
            break;
        }
        case ATTR_AMPLITUDE:
        {
eseidel's avatar
eseidel committed
148
            amplitude()->setBaseVal(value.string().toDouble());
eseidel's avatar
eseidel committed
149
150
151
152
            break;
        }
        case ATTR_EXPONENT:
        {
eseidel's avatar
eseidel committed
153
            exponent()->setBaseVal(value.string().toDouble());
eseidel's avatar
eseidel committed
154
155
156
157
            break;
        }
        case ATTR_OFFSET:
        {
eseidel's avatar
eseidel committed
158
            offset()->setBaseVal(value.string().toDouble());
eseidel's avatar
eseidel committed
159
160
161
162
163
164
165
            break;
        }
        default:
        {
            SVGElementImpl::parseAttribute(attr);
        }
    };
eseidel's avatar
eseidel committed
166
167
168
}

// vim:ts=4:noet