1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/*
Copyright (C) 2001-2003 KSVG Team
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <kdebug.h>
#include <tdelocale.h>
#include "Glyph.h"
#include "SVGDocumentImpl.h"
#include "SVGTextPathElement.h"
#include "SVGAnimatedLengthImpl.h"
#include "SVGTextPathElementImpl.h"
#include "SVGAnimatedEnumerationImpl.h"
using namespace KSVG;
#include "SVGTextPathElementImpl.lut.h"
#include "ksvg_scriptinterpreter.h"
#include "ksvg_ecma.h"
#include "ksvg_cacheimpl.h"
SVGTextPathElementImpl::SVGTextPathElementImpl(DOM::ElementImpl *impl) : SVGTextContentElementImpl(impl), SVGURIReferenceImpl()
{
KSVG_EMPTY_FLAGS
m_startOffset = new SVGAnimatedLengthImpl();
m_startOffset->ref();
m_method = new SVGAnimatedEnumerationImpl();
m_method->ref();
m_spacing = new SVGAnimatedEnumerationImpl();
m_spacing->ref();
}
SVGTextPathElementImpl::~SVGTextPathElementImpl()
{
if(m_startOffset)
m_startOffset->deref();
if(m_method)
m_method->deref();
if(m_spacing)
m_spacing->deref();
}
SVGAnimatedLengthImpl *SVGTextPathElementImpl::startOffset() const
{
return m_startOffset;
}
SVGAnimatedEnumerationImpl *SVGTextPathElementImpl::method() const
{
return m_method;
}
SVGAnimatedEnumerationImpl *SVGTextPathElementImpl::spacing() const
{
return m_spacing;
}
TQString SVGTextPathElementImpl::text()
{
// Otherwhise some js scripts which require a child, don't work (Niko)
if(!hasChildNodes())
{
DOM::Text impl = static_cast<DOM::Document *>(ownerDoc())->createTextNode(DOM::DOMString(""));
appendChild(impl);
}
return textDirectionAwareText();
}
void SVGTextPathElementImpl::setAttributes()
{
SVGElementImpl::setAttributes();
// Spec: if not specified, effect is as if a value of "0" were specified
if(KSVG_TOKEN_NOT_PARSED(StartOffset))
KSVG_SET_ALT_ATTRIBUTE(StartOffset, "0")
// Spec: if not specified, effect is as if a value of "align" were specified
if(KSVG_TOKEN_NOT_PARSED(Method))
KSVG_SET_ALT_ATTRIBUTE(Method, "align")
// Spec: if not specified, effect is as if a value of "exact" were specified
if(KSVG_TOKEN_NOT_PARSED(Spacing))
KSVG_SET_ALT_ATTRIBUTE(Spacing, "exact")
}
T2P::GlyphLayoutParams *SVGTextPathElementImpl::layoutParams() const
{
T2P::GlyphLayoutParams *params = SVGTextContentElementImpl::layoutParams();
params->setTextPathStartOffset(startOffset()->baseVal()->value());
return params;
}
// Ecma stuff
/*
@namespace KSVG
@begin SVGTextPathElementImpl::s_hashTable 5
startOffset SVGTextPathElementImpl::StartOffset DontDelete|ReadOnly
method SVGTextPathElementImpl::Method DontDelete|ReadOnly
spacing SVGTextPathElementImpl::Spacing DontDelete|ReadOnly
@end
*/
Value SVGTextPathElementImpl::getValueProperty(ExecState *exec, int token) const
{
KSVG_CHECK_ATTRIBUTE
switch(token)
{
case StartOffset:
if(!attributeMode)
return m_startOffset->cache(exec);
else
return Number(m_startOffset->baseVal()->value());
case Method:
if(!attributeMode)
return m_method->cache(exec);
else
return Number(m_method->baseVal());
case Spacing:
if(!attributeMode)
return m_spacing->cache(exec);
else
return Number(m_spacing->baseVal());
default:
kdWarning() << "Unhandled token in " << k_funcinfo << " : " << token << endl;
return Undefined();
}
}
void SVGTextPathElementImpl::putValueProperty(ExecState *exec, int token, const Value &value, int attr)
{
// This class has just ReadOnly properties, only with the Internal flag set
// it's allowed to modify those.
if(!(attr & KJS::Internal))
return;
switch(token)
{
case StartOffset:
{
TQString param = value.toString(exec).qstring();
if(param.endsWith("%"))
{
TQString value = param.left(param.length() - 1);
bool ok = false;
double dValue = value.toDouble(&ok);
if(ok)
startOffset()->baseVal()->setValue(dValue / 100.0);
else
kdDebug() << "Couldn't parse startOffset: " << value << endl;
}
else
startOffset()->baseVal()->setValueAsString(value.toString(exec).qstring());
if(startOffset()->baseVal()->value() < 0) // A negative value is an error
gotError(i18n("Negative value for attribute startOffset of element <textPath> is illegal"));
break;
}
case Method:
{
TQString param = value.toString(exec).qstring();
if(param == "align")
method()->setBaseVal(TEXTPATH_METHODTYPE_ALIGN);
else if(param == "stretch")
method()->setBaseVal(TEXTPATH_METHODTYPE_STRETCH);
else
method()->setBaseVal(TEXTPATH_METHODTYPE_UNKNOWN);
break;
}
case Spacing:
{
TQString param = value.toString(exec).qstring();
if(param == "auto")
spacing()->setBaseVal(TEXTPATH_SPACINGTYPE_AUTO);
else if(param == "exact")
spacing()->setBaseVal(TEXTPATH_SPACINGTYPE_EXACT);
else
spacing()->setBaseVal(TEXTPATH_SPACINGTYPE_UNKNOWN);
break;
}
default:
kdWarning() << "Unhandled token in " << k_funcinfo << " : " << token << endl;
}
}
// CONSTANTS
/*
@namespace KSVG
@begin SVGTextPathElementImplConstructor::s_hashTable 7
TEXTPATH_METHODTYPE_UNKNOWN KSVG::TEXTPATH_METHODTYPE_UNKNOWN DontDelete|ReadOnly
TEXTPATH_METHODTYPE_ALIGN KSVG::TEXTPATH_METHODTYPE_ALIGN DontDelete|ReadOnly
TEXTPATH_METHODTYPE_STRETCH KSVG::TEXTPATH_METHODTYPE_STRETCH DontDelete|ReadOnly
TEXTPATH_SPACINGTYPE_UNKNOWN KSVG::TEXTPATH_SPACINGTYPE_UNKNOWN DontDelete|ReadOnly
TEXTPATH_SPACINGTYPE_AUTO KSVG::TEXTPATH_SPACINGTYPE_AUTO DontDelete|ReadOnly
TEXTPATH_SPACINGTYPE_EXACT KSVG::TEXTPATH_SPACINGTYPE_EXACT DontDelete|ReadOnly
@end
*/
using namespace KJS;
Value SVGTextPathElementImplConstructor::getValueProperty(ExecState *, int token) const
{
return Number(token);
}
Value KSVG::getSVGTextPathElementImplConstructor(ExecState *exec)
{
return cacheGlobalBridge<SVGTextPathElementImplConstructor>(exec, "[[svgtextpathelement.constructor]]");
}
// vim:ts=4:noet
|