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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
/*
Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
2004, 2005, 2007 Rob Buis <buis@kde.org>
Copyright (C) 2005, 2006 Apple Computer, Inc.
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 "config.h"
#if ENABLE(SVG)
#include "CSSInheritedValue.h"
#include "CSSInitialValue.h"
#include "CSSParser.h"
#include "CSSProperty.h"
#include "CSSPropertyNames.h"
#include "CSSQuirkPrimitiveValue.h"
#include "CSSValueKeywords.h"
#include "CSSValueList.h"
#include "SVGPaint.h"
using namespace std;
namespace WebCore {
bool CSSParser::parseSVGValue(int propId, bool important)
{
Value* value = valueList->current();
if (!value)
return false;
int id = value->id;
bool valid_primitive = false;
RefPtr<CSSValue> parsedValue;
switch (propId) {
/* The comment to the right defines all valid value of these
* properties as defined in SVG 1.1, Appendix N. Property index */
case CSS_PROP_ALIGNMENT_BASELINE:
// auto | baseline | before-edge | text-before-edge | middle |
// central | after-edge | text-after-edge | ideographic | alphabetic |
// hanging | mathematical | inherit
if (id == CSS_VAL_AUTO || id == CSS_VAL_BASELINE || id == CSS_VAL_MIDDLE ||
(id >= CSS_VAL_BEFORE_EDGE && id <= CSS_VAL_MATHEMATICAL))
valid_primitive = true;
break;
case CSS_PROP_BASELINE_SHIFT:
// baseline | super | sub | <percentage> | <length> | inherit
if (id == CSS_VAL_BASELINE || id == CSS_VAL_SUB ||
id >= CSS_VAL_SUPER)
valid_primitive = true;
else
valid_primitive = validUnit(value, FLength|FPercent, false);
break;
case CSS_PROP_DOMINANT_BASELINE:
// auto | use-script | no-change | reset-size | ideographic |
// alphabetic | hanging | mathematical | central | middle |
// text-after-edge | text-before-edge | inherit
if (id == CSS_VAL_AUTO || id == CSS_VAL_MIDDLE ||
(id >= CSS_VAL_USE_SCRIPT && id <= CSS_VAL_RESET_SIZE) ||
(id >= CSS_VAL_CENTRAL && id <= CSS_VAL_MATHEMATICAL))
valid_primitive = true;
break;
case CSS_PROP_ENABLE_BACKGROUND:
// accumulate | new [x] [y] [width] [height] | inherit
if (id == CSS_VAL_ACCUMULATE) // TODO : new
valid_primitive = true;
break;
case CSS_PROP_MARKER_START:
case CSS_PROP_MARKER_MID:
case CSS_PROP_MARKER_END:
case CSS_PROP_MASK:
if (id == CSS_VAL_NONE)
valid_primitive = true;
else if (value->unit == CSSPrimitiveValue::CSS_URI) {
parsedValue = new CSSPrimitiveValue(value->string, CSSPrimitiveValue::CSS_URI);
if (parsedValue)
valueList->next();
}
break;
case CSS_PROP_CLIP_RULE: // nonzero | evenodd | inherit
case CSS_PROP_FILL_RULE:
if (id == CSS_VAL_NONZERO || id == CSS_VAL_EVENODD)
valid_primitive = true;
break;
case CSS_PROP_STROKE_MITERLIMIT: // <miterlimit> | inherit
valid_primitive = validUnit(value, FNumber|FNonNeg, false);
break;
case CSS_PROP_STROKE_LINEJOIN: // miter | round | bevel | inherit
if (id == CSS_VAL_MITER || id == CSS_VAL_ROUND || id == CSS_VAL_BEVEL)
valid_primitive = true;
break;
case CSS_PROP_STROKE_LINECAP: // butt | round | square | inherit
if (id == CSS_VAL_BUTT || id == CSS_VAL_ROUND || id == CSS_VAL_SQUARE)
valid_primitive = true;
break;
case CSS_PROP_STROKE_OPACITY: // <opacity-value> | inherit
case CSS_PROP_FILL_OPACITY:
case CSS_PROP_STOP_OPACITY:
case CSS_PROP_FLOOD_OPACITY:
valid_primitive = (!id && validUnit(value, FNumber|FPercent, false));
break;
case CSS_PROP_SHAPE_RENDERING:
// auto | optimizeSpeed | crispEdges | geometricPrecision | inherit
if (id == CSS_VAL_AUTO || id == CSS_VAL_OPTIMIZESPEED ||
id == CSS_VAL_CRISPEDGES || id == CSS_VAL_GEOMETRICPRECISION)
valid_primitive = true;
break;
case CSS_PROP_TEXT_RENDERING: // auto | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit
if (id == CSS_VAL_AUTO || id == CSS_VAL_OPTIMIZESPEED || id == CSS_VAL_OPTIMIZELEGIBILITY ||
id == CSS_VAL_GEOMETRICPRECISION)
valid_primitive = true;
break;
case CSS_PROP_IMAGE_RENDERING: // auto | optimizeSpeed |
case CSS_PROP_COLOR_RENDERING: // optimizeQuality | inherit
if (id == CSS_VAL_AUTO || id == CSS_VAL_OPTIMIZESPEED ||
id == CSS_VAL_OPTIMIZEQUALITY)
valid_primitive = true;
break;
case CSS_PROP_COLOR_PROFILE: // auto | sRGB | <name> | <uri> inherit
if (id == CSS_VAL_AUTO || id == CSS_VAL_SRGB)
valid_primitive = true;
break;
case CSS_PROP_COLOR_INTERPOLATION: // auto | sRGB | linearRGB | inherit
case CSS_PROP_COLOR_INTERPOLATION_FILTERS:
if (id == CSS_VAL_AUTO || id == CSS_VAL_SRGB || id == CSS_VAL_LINEARRGB)
valid_primitive = true;
break;
/* Start of supported CSS properties with validation. This is needed for parseShortHand to work
* correctly and allows optimization in applyRule(..)
*/
case CSS_PROP_POINTER_EVENTS:
// none | visiblePainted | visibleFill | visibleStroke | visible |
// painted | fill | stroke | none | all | inherit
if (id == CSS_VAL_VISIBLE || id == CSS_VAL_NONE ||
(id >= CSS_VAL_VISIBLEPAINTED && id <= CSS_VAL_ALL))
valid_primitive = true;
break;
case CSS_PROP_TEXT_ANCHOR: // start | middle | end | inherit
if (id == CSS_VAL_START || id == CSS_VAL_MIDDLE || id == CSS_VAL_END)
valid_primitive = true;
break;
case CSS_PROP_GLYPH_ORIENTATION_VERTICAL: // auto | <angle> | inherit
if (id == CSS_VAL_AUTO) {
valid_primitive = true;
break;
}
/* fallthrough intentional */
case CSS_PROP_GLYPH_ORIENTATION_HORIZONTAL: // <angle> (restricted to _deg_ per SVG 1.1 spec) | inherit
if (value->unit == CSSPrimitiveValue::CSS_DEG || value->unit == CSSPrimitiveValue::CSS_NUMBER) {
parsedValue = new CSSPrimitiveValue(value->fValue, CSSPrimitiveValue::CSS_DEG);
if (parsedValue)
valueList->next();
}
break;
case CSS_PROP_FILL: // <paint> | inherit
case CSS_PROP_STROKE: // <paint> | inherit
{
if (id == CSS_VAL_NONE)
parsedValue = new SVGPaint(SVGPaint::SVG_PAINTTYPE_NONE);
else if (id == CSS_VAL_CURRENTCOLOR)
parsedValue = new SVGPaint(SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR);
else if (value->unit == CSSPrimitiveValue::CSS_URI) {
RGBA32 c = Color::transparent;
if (valueList->next() && parseColorFromValue(valueList->current(), c, true)) {
parsedValue = new SVGPaint(value->string, c);
} else
parsedValue = new SVGPaint(SVGPaint::SVG_PAINTTYPE_URI, value->string);
} else
parsedValue = parseSVGPaint();
if (parsedValue)
valueList->next();
}
break;
case CSS_PROP_COLOR: // <color> | inherit
if ((id >= CSS_VAL_AQUA && id <= CSS_VAL_WINDOWTEXT) ||
(id >= CSS_VAL_ALICEBLUE && id <= CSS_VAL_YELLOWGREEN))
parsedValue = new SVGColor(value->string);
else
parsedValue = parseSVGColor();
if (parsedValue)
valueList->next();
break;
case CSS_PROP_STOP_COLOR: // TODO : icccolor
case CSS_PROP_FLOOD_COLOR:
case CSS_PROP_LIGHTING_COLOR:
if ((id >= CSS_VAL_AQUA && id <= CSS_VAL_WINDOWTEXT) ||
(id >= CSS_VAL_ALICEBLUE && id <= CSS_VAL_YELLOWGREEN))
parsedValue = new SVGColor(value->string);
else if (id == CSS_VAL_CURRENTCOLOR)
parsedValue = new SVGColor(SVGColor::SVG_COLORTYPE_CURRENTCOLOR);
else // TODO : svgcolor (iccColor)
parsedValue = parseSVGColor();
if (parsedValue)
valueList->next();
break;
case CSS_PROP_WRITING_MODE:
// lr-tb | rl_tb | tb-rl | lr | rl | tb | inherit
if (id >= CSS_VAL_LR_TB && id <= CSS_VAL_TB)
valid_primitive = true;
break;
case CSS_PROP_STROKE_WIDTH: // <length> | inherit
case CSS_PROP_STROKE_DASHOFFSET:
valid_primitive = validUnit(value, FLength | FPercent, false);
break;
case CSS_PROP_STROKE_DASHARRAY: // none | <dasharray> | inherit
if (id == CSS_VAL_NONE)
valid_primitive = true;
else
parsedValue = parseSVGStrokeDasharray();
break;
case CSS_PROP_KERNING: // auto | normal | <length> | inherit
if (id == CSS_VAL_AUTO || id == CSS_VAL_NORMAL)
valid_primitive = true;
else
valid_primitive = validUnit(value, FLength, false);
break;
case CSS_PROP_CLIP_PATH: // <uri> | none | inherit
case CSS_PROP_FILTER:
if (id == CSS_VAL_NONE)
valid_primitive = true;
else if (value->unit == CSSPrimitiveValue::CSS_URI) {
parsedValue = new CSSPrimitiveValue(value->string, (CSSPrimitiveValue::UnitTypes) value->unit);
if (parsedValue)
valueList->next();
}
break;
/* shorthand properties */
case CSS_PROP_MARKER:
{
if (!parseValue(CSS_PROP_MARKER_START, important))
return false;
CSSValue *value = parsedProperties[numParsedProperties - 1]->value();
m_implicitShorthand = true;
addProperty(CSS_PROP_MARKER_MID, value, important);
addProperty(CSS_PROP_MARKER_END, value, important);
m_implicitShorthand = false;
return true;
}
default:
// If you crash here, it's because you added a css property and are not handling it
// in either this switch statement or the one in CSSParser::parseValue
ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propId);
return false;
}
if (valid_primitive) {
if (id != 0)
parsedValue = new CSSPrimitiveValue(id);
else if (value->unit == CSSPrimitiveValue::CSS_STRING)
parsedValue = new CSSPrimitiveValue(value->string, (CSSPrimitiveValue::UnitTypes) value->unit);
else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
parsedValue = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
else if (value->unit >= Value::Q_EMS)
parsedValue = new CSSQuirkPrimitiveValue(value->fValue, CSSPrimitiveValue::CSS_EMS);
valueList->next();
}
if (!parsedValue || (valueList->current() && !inShorthand()))
return false;
addProperty(propId, parsedValue.release(), important);
return true;
}
PassRefPtr<CSSValue> CSSParser::parseSVGStrokeDasharray()
{
CSSValueList* ret = new CSSValueList;
Value* value = valueList->current();
bool valid_primitive = true;
while (value) {
valid_primitive = validUnit(value, FLength | FPercent |FNonNeg, false);
if (!valid_primitive)
break;
if (value->id != 0)
ret->append(new CSSPrimitiveValue(value->id));
else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
ret->append(new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit));
value = valueList->next();
if (value && value->unit == Value::Operator && value->iValue == ',')
value = valueList->next();
}
if (!valid_primitive) {
delete ret;
ret = 0;
}
return ret;
}
PassRefPtr<CSSValue> CSSParser::parseSVGPaint()
{
RGBA32 c = Color::transparent;
if (!parseColorFromValue(valueList->current(), c, true))
return new SVGPaint();
return new SVGPaint(Color(c));
}
PassRefPtr<CSSValue> CSSParser::parseSVGColor()
{
RGBA32 c = Color::transparent;
if (!parseColorFromValue(valueList->current(), c, true))
return 0;
return new SVGColor(Color(c));
}
}
#endif // ENABLE(SVG)
// vim:ts=4:noet
|