Subversion Repositories public

Rev

Rev 274 | Rev 276 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
273 andreas 1
//
274 andreas 2
// C++ Implementation: SRender
273 andreas 3
//
4
// Description: Renders a map from some shape files. This class assumes,
5
//              that the shape files are in open street map format!
6
//
7
//
8
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
9
//
10
// Copyright: See COPYING file that comes with this distribution
11
//
12
//
13
 
14
#define BOOST_SPIRIT_THREADSAFE
274 andreas 15
#include <QLabel>
16
#include <QString>
17
#include <QXmlReader>
18
#include <QDir>
19
#include <QColor>
275 andreas 20
#include <QImage>
274 andreas 21
#include <KStandardDirs>
22
#include <KConfig>
23
#include <KLocale>
24
#include <KMessageBox>
25
#include <KGlobalSettings>
26
#include <KConfigGroup>
275 andreas 27
#include <KIconLoader>
273 andreas 28
 
29
#include "config.h"
30
#include "render.h"
274 andreas 31
#include <iostream>
273 andreas 32
 
33
#define CON_MAP			100
34
#define CON_STYLE		101
35
#define CON_RULE		102
36
#define CON_LINESYMBOLIZER	103
37
#define CON_POINTSYMBOLIZER	104
38
#define CON_POLYGONSYMBOLIZER	105
39
#define CON_TEXTSYMBOLIZER	106
40
#define CON_POLYGONPATTERNSYMBOLIZER	107
41
#define CON_LAYER		108
42
#define CON_DATASOURCE		109
274 andreas 43
#define CON_SHIELDSYMBOLIZER	110
44
#define CON_LINEPATTERNSYMBOLIZER	111
273 andreas 45
 
46
#define FLD_FILTER		200
47
#define FLD_CSSPARAMETER	201
48
#define FLD_MINSCALE		202
49
#define FLD_MAXSCALE		203
50
#define FLD_STYLENAME		204
51
#define FLD_PARAMETER		205
52
 
53
#define ATT_FILL		300
54
#define ATT_FILE		301
55
#define ATT_TYPE		302
56
#define ATT_WIDTH		303
57
#define ATT_HEIGHT		304
58
#define ATT_SIZE		305
59
#define ATT_NAME		306
60
#define ATT_FACENAME		307
61
#define ATT_DY			308
62
#define ATT_HALORADIUS		309
63
#define ATT_WRAPWIDTH		310
64
#define ATT_MINDISTANCE		311
65
#define ATT_MAXDISTANCE		312
66
#define ATT_PLACEMENT		313
67
#define ATT_ALLOWOVERLAP	314
68
#define ATT_STATUS		315
69
#define ATT_SRS			316
275 andreas 70
#define ATT_DX			317
273 andreas 71
 
72
#define FIRST_CON		100
274 andreas 73
#define LAST_CON		111
273 andreas 74
 
75
#define FIRST_FLD		200
76
#define LAST_FLD		205
77
 
78
#define FIRST_ATT		300
275 andreas 79
#define LAST_ATT		317
273 andreas 80
 
274 andreas 81
using std::cout;
82
using std::cerr;
83
using std::clog;
84
using std::endl;
85
 
86
TOKEN token[] = {
273 andreas 87
	// Containers
274 andreas 88
	{ CON_MAP,			in_map,			QString("Map") },
89
	{ CON_STYLE,			in_style,		QString("Style") },
90
	{ CON_RULE,			in_rule,		QString("Rule") },
91
	{ CON_LINESYMBOLIZER,		in_linesymbolizer,	QString("LineSymbolizer") },
92
	{ CON_POINTSYMBOLIZER,		in_pointsymbolizer,	QString("PointSymbolizer") },
93
	{ CON_POLYGONSYMBOLIZER,	in_polygonsymbolizer,	QString("PolygonSymbolizer") },
94
	{ CON_TEXTSYMBOLIZER,		in_textsymbolizer,	QString("TextSymbolizer") },
95
	{ CON_POLYGONPATTERNSYMBOLIZER,	in_polygonpatternsymbolizer,	QString("PolygonPatternSymbolizer") },
96
	{ CON_LAYER,			in_layer,		QString("Layer") },
97
	{ CON_DATASOURCE,		in_datasource,		QString("Datasource") },
98
	{ CON_SHIELDSYMBOLIZER,		in_shieldsymbolizer,	QString("ShieldSymbolizer") },
275 andreas 99
	{ CON_LINEPATTERNSYMBOLIZER,	in_linepatternsymbolizer, QString("LinePatternSymbolizer") },
273 andreas 100
	// Fields
274 andreas 101
	{ FLD_FILTER,			in_rule,		QString("Filter") },
102
	{ FLD_CSSPARAMETER,		in_symbolizer,		QString("CSSParameter") },
103
	{ FLD_MINSCALE,			in_rule,		QString("MinScaleDenominator") },
104
	{ FLD_MAXSCALE,			in_rule,		QString("MaxScaleDenominator") },
105
	{ FLD_STYLENAME,		in_style,		QString("StyleName") },
106
	{ FLD_PARAMETER,		in_datasource,		QString("Parameter") },
273 andreas 107
	// Attributes
274 andreas 108
	{ ATT_FILL,			in_symbolizer,		QString("fill") },
109
	{ ATT_NAME,			in_symbolizer,		QString("name") },
110
	{ ATT_FILE,			in_symbolizer,		QString("file") },
111
	{ ATT_TYPE,			in_symbolizer,		QString("type") },
112
	{ ATT_WIDTH,			in_symbolizer,		QString("width") },
113
	{ ATT_HEIGHT,			in_symbolizer,		QString("height") },
114
	{ ATT_SIZE,			in_symbolizer,		QString("size") },
115
	{ ATT_FACENAME,			in_symbolizer,		QString("face_name") },
275 andreas 116
	{ ATT_DX,			in_symbolizer,		QString("dx") },
274 andreas 117
	{ ATT_DY,			in_symbolizer,		QString("dy") },
118
	{ ATT_HALORADIUS,		in_symbolizer,		QString("halo_radius") },
119
	{ ATT_WRAPWIDTH,		in_symbolizer,		QString("wrap_width") },
120
	{ ATT_MINDISTANCE,		in_symbolizer,		QString("min_distance") },
121
	{ ATT_MAXDISTANCE,		in_symbolizer,		QString("max_distance") },
122
	{ ATT_PLACEMENT,		in_symbolizer,		QString("placement") },
123
	{ ATT_ALLOWOVERLAP,		in_symbolizer,		QString("allow_overlap") },
124
	{ ATT_STATUS,			in_layer,		QString("status") },
125
	{ ATT_SRS,			in_layer,		QString("srs") },
126
	{ 0,				in_root,		QString::null }
273 andreas 127
};
128
 
274 andreas 129
SRender::SRender()
273 andreas 130
{
274 andreas 131
	label = 0;
132
	shapePath = QString::null;
133
	XmlPath = QString::null;
134
	Lay = firstLayer = lastLayer = 0;
135
	Style = firstStyle = lastStyle = 0;
273 andreas 136
	Rule = 0;
137
	LineSymbolizer = 0;
138
	PolygonSymbolizer = 0;
139
	TextSymbolizer = 0;
140
	PointSymbolizer = 0;
141
	PolygonPatternSymbolizer = 0;
142
	ShieldSymbolizer = 0;
143
	LinePatternSymbolizer = 0;
275 andreas 144
	_lx = _ly = 180.0;
145
	_rx = _ry = -180.0;
274 andreas 146
	// This is true, when a XML file was parsed successfully
147
	ControlSet = false;
148
 
149
	// Read settings from config file
150
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
151
	KConfigGroup ic (&cfg, "SportWatcher");
152
	KConfigGroup sh (&cfg, "ShapeFile");
153
	QString basePath = ic.readEntry("Data", QDir::home().absolutePath() + "/.sportwatcher");
154
	shapePath = ic.readEntry("MAP", basePath + "/shapefiles");
155
	// Read the shape specific informations
156
#ifdef MAPNIK_PLUGINS
157
	pluginPath = QString(MAPNIK_PLUGINS);
158
#else
159
	// Test some default path
160
	if (dir.exists(QString("/usr/lib/mapnik/input")))
161
	   pluginPath = sh.readEntry("PluginPath", QString("/usr/lib/mapnik/input"));
162
	else if (dir.exists(QString("/usr/local/lib/mapnik/input")))
163
	   pluginPath = sh.readEntry("PluginPath", QString("/usr/local/lib/mapnik/input"));
164
	else if (dir.exists(QString("/usr/lib/mapnik/0.6/input")))
165
	   pluginPath = sh.readEntry("PluginPath", QString("/usr/lib/mapnik/0.6/input"));
166
	else
167
	   pluginPath = sh.readEntry("PluginPath", QString(""));
168
#endif
169
#ifdef MAPNIK_FONTS
170
	fontPath = QString(MAPNIK_FONTS);
171
#else
172
	// Test some default path
173
	if (dir.exists(QString("/usr/lib/mapnik/fonts")))
174
	   fontPath = sh.readEntry("FontPath", QString("/usr/lib/mapnik/fonts"));
175
	else if (dir.exists(QString("/usr/local/lib/mapnik/fonts")))
176
	   fontPath = sh.readEntry("FontPath", QString("/usr/local/lib/mapnik/fonts"));
177
	else if (dir.exists(QString("/usr/share/mapnik/fonts")))
178
	   fontPath = sh.readEntry("FontPath", QString("/usr/share/mapnik/fonts"));
179
	else if (dir.exists(QString("/usr/share/fonts/truetype/ttf-dejavu")))
180
	   fontPath = sh.readEntry("FontPath", QString("/usr/share/fonts/truetype/ttf-dejavu"));
181
	else
182
	   fontPath = sh.readEntry("FontPath", QString(""));
183
#endif
184
	XmlPath = sh.readEntry("XmlFile", basePath + "/shapefiles/osm.xml");
273 andreas 185
}
186
 
274 andreas 187
SRender::~SRender()
273 andreas 188
{
274 andreas 189
	startDocument();	// Clean everything
190
	ControlSet = false;
275 andreas 191
 
192
	if (!OutBuf.isEmpty())
193
	   unlink (OutBuf.toAscii().data());
274 andreas 194
}
273 andreas 195
 
274 andreas 196
bool SRender::startDocument()
197
{
198
	m.remove_all();		// delete styles and layers from map
199
 
273 andreas 200
	if (firstStyle)		// free if allocated
201
	{
202
	   Style = firstStyle;
203
 
204
	   while (Style)
205
	   {
274 andreas 206
	      STYLE *sakt = Style->next;
207
 
273 andreas 208
	      if (Style->rule)
209
	      {
210
		 RULE *rule = Style->rule;
211
 
212
		 while (rule)
213
		 {
214
		    RULE *rakt = rule->next;
215
		    LINESYMBOLIZER *LineSymbolizer = rule->LineSymbolizer;
216
		    POLYGONSYMBOLIZER *PolygonSymbolizer = rule->PolygonSymbolizer;
217
		    TEXTSYMBOLIZER *TextSymbolizer = rule->TextSymbolizer;
218
		    POINTSYMBOLIZER *PointSymbolizer = rule->PointSymbolizer;
219
		    POLYGONPATTERNSYMBOLIZER *PolygonPatternSymbolizer = rule->PolygonPatternSymbolizer;
274 andreas 220
		    SHIELDSYMBOLIZER *ShieldSymbolizer = rule->ShieldSymbolizer;
273 andreas 221
		    LINEPATTERNSYMBOLIZER *LinePatternSymbolizer = rule->LinePatternSymbolizer;
222
 
223
		    while (LineSymbolizer)
224
		    {
225
		       LINESYMBOLIZER *akt = LineSymbolizer->next;
226
		       delete LineSymbolizer;
227
		       LineSymbolizer = akt;
228
		    }
229
 
230
		    while (PolygonSymbolizer)
231
		    {
232
		       POLYGONSYMBOLIZER *akt = PolygonSymbolizer->next;
233
		       delete PolygonSymbolizer;
234
		       PolygonSymbolizer = akt;
235
		    }
236
 
237
		    while (TextSymbolizer)
238
		    {
239
		       TEXTSYMBOLIZER *akt = TextSymbolizer->next;
240
		       delete TextSymbolizer;
241
		       TextSymbolizer = akt;
242
		    }
243
 
244
		    while (PointSymbolizer)
245
		    {
246
		       POINTSYMBOLIZER *akt = PointSymbolizer->next;
247
		       delete PointSymbolizer;
248
		       PointSymbolizer = akt;
249
		    }
250
 
251
		    while (PolygonPatternSymbolizer)
252
		    {
253
		       POLYGONPATTERNSYMBOLIZER *akt = PolygonPatternSymbolizer->next;
254
		       delete PolygonPatternSymbolizer;
255
		       PolygonPatternSymbolizer = akt;
256
		    }
257
 
258
		    while (ShieldSymbolizer)
259
		    {
260
		       SHIELDSYMBOLIZER *akt = ShieldSymbolizer->next;
261
		       delete ShieldSymbolizer;
262
		       ShieldSymbolizer = akt;
263
		    }
264
 
265
		    while (LinePatternSymbolizer)
266
		    {
267
		       LINEPATTERNSYMBOLIZER *akt = LinePatternSymbolizer->next;
268
		       delete LinePatternSymbolizer;
269
		       LinePatternSymbolizer = akt;
270
		    }
271
 
272
		    delete rule;
273
		    rule = rakt;
274
		 }
275
	      }
276
 
277
	      delete Style;
278
	      Style = sakt;
279
	   }
280
	}
281
 
282
	Style = firstStyle = lastStyle = 0;
274 andreas 283
 
284
	if (firstLayer)
285
	{
286
	   Lay = firstLayer;
287
 
288
	   while (Lay)
289
	   {
290
	   LAYER *akt;
291
 
292
	      akt = Lay->next;
293
	      delete Lay;
294
	      Lay = akt;
295
	   }
296
	}
297
 
298
	Lay = firstLayer = lastLayer = 0;
275 andreas 299
	Rule = 0;
300
	LineSymbolizer = 0;
301
	PolygonSymbolizer = 0;
302
	TextSymbolizer = 0;
303
	PointSymbolizer = 0;
304
	PolygonPatternSymbolizer = 0;
305
	ShieldSymbolizer = 0;
306
	LinePatternSymbolizer = 0;
307
	_lx = _ly = 180.0;
308
	_rx = _ry = -180.0;
309
	ControlSet = false;
310
	XmlLine = 1;
274 andreas 311
	Container = in_root;
273 andreas 312
	return true;
313
}
314
 
315
/*
316
 * This is called every time a new start element was parsed.
317
 */
274 andreas 318
bool SRender::startElement( const QString&, const QString&,
273 andreas 319
                                    const QString& qName,
320
                                    const QXmlAttributes& att)
321
{
322
int i = FIRST_CON;
323
int index;
274 andreas 324
QString hv0;
273 andreas 325
 
274 andreas 326
	while (i <= LAST_CON)
273 andreas 327
	{
328
	   if (qName.toLower() == getKey(i).toLower())
329
	   {
274 andreas 330
	      Container = token[i].con;
331
 
273 andreas 332
	      switch (i)
333
	      {
334
		 case CON_MAP:
274 andreas 335
		    Container = in_map;
336
 
337
		    if (ControlSet)	// Must be false here!
338
		    {
275 andreas 339
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: There is another MAP! Only one map information is allowed!").arg(XmlPath).arg(XmlLine));
274 andreas 340
		       return false;
341
		    }
342
 
273 andreas 343
		    if ((index = att.index(QString("bgcolor"))) != -1)
275 andreas 344
		    {
345
		    color col;
346
 
274 andreas 347
		       MapPars.bgcolor = colorToUInt(att.value(index));
275 andreas 348
		       col.set_bgr(MapPars.bgcolor);
349
		       m.set_background(col);
350
		    }
273 andreas 351
 
352
		    if ((index = att.index(QString("buffer_size"))) != -1)
275 andreas 353
		    {
273 andreas 354
		       MapPars.buf_size = att.value(index).toInt();
275 andreas 355
		       m.set_buffer_size(MapPars.buf_size);
356
		    }
273 andreas 357
 
358
		    if ((index = att.index(QString("srs"))) != -1)
275 andreas 359
		    {
273 andreas 360
		       MapPars.srs = att.value(index);
275 andreas 361
		       m.set_srs(MapPars.srs.toAscii().data());
362
		    }
273 andreas 363
		 break;
364
 
365
		 case CON_STYLE:
274 andreas 366
		    Container = in_style;
367
 
273 andreas 368
		    if (!lastStyle)
369
		    {
274 andreas 370
		       Style = allocStyle();
371
		       firstStyle = lastStyle = Style;
273 andreas 372
		    }
373
		    else
374
		    {
274 andreas 375
		       Style = allocStyle();
273 andreas 376
		       lastStyle->next = Style;
377
		       lastStyle = Style;
378
		    }
379
 
380
		    if ((index = att.index(QString("name"))) != -1)
381
		       Style->name = att.value(index);
382
		    else
383
		    {
275 andreas 384
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: Open STYLE without a name!").arg(XmlPath).arg(XmlLine));
273 andreas 385
		       return false;
386
		    }
387
		 break;
388
 
389
		 case CON_RULE:
274 andreas 390
		    Container = in_rule;
391
 
273 andreas 392
		    if (!Style)
393
		    {
275 andreas 394
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: Open RULE outside of a STYLE!").arg(XmlPath).arg(XmlLine));
273 andreas 395
		       return false;
396
		    }
397
 
398
		    Rule = getLastRule (Style->rule);
399
 
400
		    if (!Rule)
401
		    {
274 andreas 402
		       Rule = allocRule();
273 andreas 403
		       Style->rule = Rule;
404
		    }
405
		    else
406
		    {
274 andreas 407
		       Rule->next = allocRule();
273 andreas 408
		       Rule = Rule->next;
409
		    }
410
		 break;
411
 
274 andreas 412
		 case CON_LAYER:
413
		    Container = in_layer;
414
 
415
		    if (!firstLayer)
416
		    {
417
		       Lay = allocLayer();
418
		       firstLayer = lastLayer = Lay;
419
		    }
420
		    else
421
		    {
422
		       Lay = allocLayer();
423
		       lastLayer->next = Lay;
424
		       lastLayer = Lay;
425
		    }
426
 
427
		    if ((index = att.index(QString("name"))) != -1)
428
		       Lay->name = att.value(index);
429
 
430
		    if ((index = att.index(QString("status"))) != -1)
431
		       Lay->status = getBool(att.value(index));
432
 
433
		    if ((index = att.index(QString("srs"))) != -1)
434
		       Lay->srs = att.value(index);
275 andreas 435
 
436
		    if ((index = att.index(QString("minzoom"))) != -1)
437
		       Lay->minzoom = att.value(index).toDouble();
438
 
439
		    if ((index = att.index(QString("maxzoom"))) != -1)
440
		       Lay->maxzoom = att.value(index).toDouble();
274 andreas 441
		 break;
442
 
443
		 case CON_DATASOURCE:
444
		    Container = in_datasource;
445
		 break;
446
 
273 andreas 447
		 case CON_POINTSYMBOLIZER:
274 andreas 448
		    Container = in_pointsymbolizer;
449
 
273 andreas 450
		    if (!Rule)
451
		    {
275 andreas 452
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: Open POINTSYMBOLIZER outside of a RULE!").arg(XmlPath).arg(XmlLine));
273 andreas 453
		       return false;
454
		    }
455
 
456
		    PointSymbolizer = getLastPointSymbolizer(Rule->PointSymbolizer);
457
 
458
		    if (!PointSymbolizer)
459
		    {
274 andreas 460
		       PointSymbolizer = allocPointSymbolizer();
273 andreas 461
		       Rule->PointSymbolizer = PointSymbolizer;
462
		    }
463
		    else
464
		    {
274 andreas 465
		       PointSymbolizer->next = allocPointSymbolizer();
273 andreas 466
		       PointSymbolizer = PointSymbolizer->next;
467
		    }
468
 
469
		    if ((index = att.index(QString("file"))) != -1)
470
		       PointSymbolizer->file = att.value(index);
471
 
472
		    if ((index = att.index(QString("type"))) != -1)
274 andreas 473
		       PointSymbolizer->type = getType(att.value(index));
273 andreas 474
 
274 andreas 475
		    if ((index = att.index(QString("width"))) != -1)
273 andreas 476
		       PointSymbolizer->width = att.value(index).toDouble();
477
 
274 andreas 478
		    if ((index = att.index(QString("height"))) != -1)
273 andreas 479
		       PointSymbolizer->height = att.value(index).toDouble();
480
 
274 andreas 481
		    if ((index = att.index(QString("allow_overlap"))) != -1)
273 andreas 482
		    {
483
		       if (att.value(index).toLower() == QString("true"))
484
			  PointSymbolizer->allow_overlap = true;
485
		       else
486
			  PointSymbolizer->allow_overlap = false;
487
		    }
488
		 break;
489
 
490
		 break;
491
 
492
		 case CON_LINESYMBOLIZER:
274 andreas 493
		    Container = in_linesymbolizer;
494
 
273 andreas 495
		    if (!Rule)
496
		    {
275 andreas 497
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: Open LINESYMBOLIZER outside of a RULE!").arg(XmlPath).arg(XmlLine));
273 andreas 498
		       return false;
499
		    }
500
 
501
		    LineSymbolizer = getLastLineSymbolizer(Rule->LineSymbolizer);
502
 
503
		    if (!LineSymbolizer)
504
		    {
274 andreas 505
		       LineSymbolizer = allocLineSymbolizer();
273 andreas 506
		       Rule->LineSymbolizer = LineSymbolizer;
507
		    }
508
		    else
509
		    {
274 andreas 510
		       LineSymbolizer->next = allocLineSymbolizer();
273 andreas 511
		       LineSymbolizer = LineSymbolizer->next;
512
		    }
513
		 break;
514
 
515
		 case CON_POLYGONSYMBOLIZER:
274 andreas 516
		    Container = in_polygonsymbolizer;
517
 
273 andreas 518
		    if (!Rule)
519
		    {
275 andreas 520
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: Open POLYGONSYMBOLIZER outside of a RULE!").arg(XmlPath).arg(XmlLine));
273 andreas 521
		       return false;
522
		    }
523
 
524
		    PolygonSymbolizer = getLastPolygonSymbolizer(Rule->PolygonSymbolizer);
525
 
526
		    if (!PolygonSymbolizer)
527
		    {
274 andreas 528
		       PolygonSymbolizer = allocPolygonSymbolizer();
273 andreas 529
		       Rule->PolygonSymbolizer = PolygonSymbolizer;
530
		    }
531
		    else
532
		    {
274 andreas 533
		       PolygonSymbolizer->next = allocPolygonSymbolizer();
273 andreas 534
		       PolygonSymbolizer = PolygonSymbolizer->next;
535
		    }
536
		 break;
537
 
538
		 case CON_TEXTSYMBOLIZER:
274 andreas 539
		    Container = in_textsymbolizer;
540
 
273 andreas 541
		    if (!Rule)
542
		    {
275 andreas 543
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: Open TEXTSYMBOLIZER outside of a RULE!").arg(XmlPath).arg(XmlLine));
273 andreas 544
		       return false;
545
		    }
546
 
547
		    TextSymbolizer = getLastTextSymbolizer(Rule->TextSymbolizer);
548
 
549
		    if (!TextSymbolizer)
550
		    {
274 andreas 551
		       TextSymbolizer = allocTextSymbolizer();
273 andreas 552
		       Rule->TextSymbolizer = TextSymbolizer;
553
		    }
554
		    else
555
		    {
274 andreas 556
		       TextSymbolizer->next = allocTextSymbolizer();
273 andreas 557
		       TextSymbolizer = TextSymbolizer->next;
558
		    }
559
 
560
		    if ((index = att.index(QString("name"))) != -1)
561
		       TextSymbolizer->name = att.value(index);
562
 
563
		    if ((index = att.index(QString("face_name"))) != -1)
564
		       TextSymbolizer->face_name = att.value(index);
565
 
566
		    if ((index = att.index(QString("size"))) != -1)
567
		       TextSymbolizer->size = att.value(index).toDouble();
568
 
569
		    if ((index = att.index(QString("fill"))) != -1)
274 andreas 570
		       TextSymbolizer->fill = colorToUInt(att.value(index));
571
 
572
		    if ((index = att.index(QString("halo_radius"))) != -1)
573
		       TextSymbolizer->halo_radius = att.value(index).toDouble();
574
 
575
		    if ((index = att.index(QString("wrap_width"))) != -1)
576
		       TextSymbolizer->wrap_width = att.value(index).toDouble();
577
 
275 andreas 578
		    if ((index = att.index(QString("dx"))) != -1)
579
		       TextSymbolizer->dx = att.value(index).toDouble();
580
 
274 andreas 581
		    if ((index = att.index(QString("dy"))) != -1)
582
		       TextSymbolizer->dy = att.value(index).toDouble();
583
 
584
		    if ((index = att.index(QString("max_distance"))) != -1)
585
		       TextSymbolizer->maxdistance = att.value(index).toDouble();
586
 
587
		    if ((index = att.index(QString("min_distance"))) != -1)
588
		       TextSymbolizer->mindistance = att.value(index).toDouble();
273 andreas 589
		 break;
274 andreas 590
 
591
		 case CON_POLYGONPATTERNSYMBOLIZER:
592
		    Container = in_polygonpatternsymbolizer;
593
 
594
		    if (!Rule)
595
		    {
275 andreas 596
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: Open POLYGONPATTERNSYMBOLIZER outside of a RULE!").arg(XmlPath).arg(XmlLine));
274 andreas 597
		       return false;
598
		    }
599
 
600
		    PolygonPatternSymbolizer = getLastPolygonPatternSymbolizer(Rule->PolygonPatternSymbolizer);
601
 
602
		    if (!PolygonPatternSymbolizer)
603
		    {
604
		       PolygonPatternSymbolizer = allocPolygonPatternSymbolizer();
605
		       Rule->PolygonPatternSymbolizer = PolygonPatternSymbolizer;
606
		    }
607
		    else
608
		    {
609
		       PolygonPatternSymbolizer->next = allocPolygonPatternSymbolizer();
610
		       PolygonPatternSymbolizer = PolygonPatternSymbolizer->next;
611
		    }
612
 
613
		    if ((index = att.index(QString("file"))) != -1)
614
		       PolygonPatternSymbolizer->file = att.value(index);
615
 
616
		    if ((index = att.index(QString("type"))) != -1)
617
		       PolygonPatternSymbolizer->type = getType(att.value(index));
618
 
619
		    if ((index = att.index(QString("width"))) != -1)
620
		       PolygonPatternSymbolizer->width = att.value(index).toDouble();
621
 
622
		    if ((index = att.index(QString("height"))) != -1)
623
		       PolygonPatternSymbolizer->height = att.value(index).toDouble();
624
 
625
		    if ((index = att.index(QString("allow_overlap"))) != -1)
626
		       PolygonPatternSymbolizer->allow_overlap = getBool(att.value(index));
627
		 break;
628
 
629
		 case CON_SHIELDSYMBOLIZER:
630
		    Container = in_shieldsymbolizer;
631
 
632
		    if (!Rule)
633
		    {
275 andreas 634
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: Open SHIELDSYMBOLIZER outside of a RULE!").arg(XmlPath).arg(XmlLine));
274 andreas 635
		       return false;
636
		    }
637
 
638
		    ShieldSymbolizer = getLastShieldSymbolizer(Rule->ShieldSymbolizer);
639
 
640
		    if (!ShieldSymbolizer)
641
		    {
642
		       ShieldSymbolizer = allocShieldSymbolizer();
643
		       Rule->ShieldSymbolizer = ShieldSymbolizer;
644
		    }
645
		    else
646
		    {
647
		       ShieldSymbolizer->next = allocShieldSymbolizer();
648
		       ShieldSymbolizer = ShieldSymbolizer->next;
649
		    }
650
 
651
		    if ((index = att.index(QString("name"))) != -1)
652
		       ShieldSymbolizer->name = att.value(index);
653
 
654
		    if ((index = att.index(QString("face_name"))) != -1)
655
		       ShieldSymbolizer->face_name = att.value(index);
656
 
657
		    if ((index = att.index(QString("fill"))) != -1)
658
		       ShieldSymbolizer->fill = colorToUInt(att.value(index));
659
 
660
		    if ((index = att.index(QString("placement"))) != -1)
661
		       ShieldSymbolizer->placement = att.value(index);
662
 
663
		    if ((index = att.index(QString("file"))) != -1)
664
		       ShieldSymbolizer->file = att.value(index);
665
 
666
		    if ((index = att.index(QString("type"))) != -1)
667
		       ShieldSymbolizer->type = getType(att.value(index));
668
 
669
		    if ((index = att.index(QString("size"))) != -1)
670
		       ShieldSymbolizer->size = att.value(index).toDouble();
671
 
672
		    if ((index = att.index(QString("width"))) != -1)
673
		       ShieldSymbolizer->width = att.value(index).toDouble();
674
 
675
		    if ((index = att.index(QString("height"))) != -1)
676
		       ShieldSymbolizer->height = att.value(index).toDouble();
677
 
275 andreas 678
		    if ((index = att.index(QString("dx"))) != -1)
679
		       ShieldSymbolizer->dx = att.value(index).toDouble();
680
 
681
		    if ((index = att.index(QString("dy"))) != -1)
682
		       ShieldSymbolizer->dy = att.value(index).toDouble();
683
 
274 andreas 684
		    if ((index = att.index(QString("min_distance"))) != -1)
685
		       ShieldSymbolizer->mindistance = att.value(index).toDouble();
686
 
687
		    if ((index = att.index(QString("max_distance"))) != -1)
688
		       ShieldSymbolizer->maxdistance = att.value(index).toDouble();
689
		 break;
690
 
691
		 case CON_LINEPATTERNSYMBOLIZER:
692
		    Container = in_linepatternsymbolizer;
693
 
694
		    if (!Rule)
695
		    {
275 andreas 696
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: Open LINEPATTERNSYMBOLIZER outside of a RULE!").arg(XmlPath).arg(XmlLine));
274 andreas 697
		       return false;
698
		    }
699
 
700
		    LinePatternSymbolizer = getLastLinePatternSymbolizer(Rule->LinePatternSymbolizer);
701
 
702
		    if (!LinePatternSymbolizer)
703
		    {
704
		       LinePatternSymbolizer = allocLinePatternSymbolizer();
705
		       Rule->LinePatternSymbolizer = LinePatternSymbolizer;
706
		    }
707
		    else
708
		    {
709
		       LinePatternSymbolizer->next = allocLinePatternSymbolizer();
710
		       LinePatternSymbolizer = LinePatternSymbolizer->next;
711
		    }
712
 
713
		    if ((index = att.index(QString("file"))) != -1)
714
		       LinePatternSymbolizer->file = att.value(index);
715
 
716
		    if ((index = att.index(QString("type"))) != -1)
717
		       LinePatternSymbolizer->type = getType(att.value(index));
718
 
719
		    if ((index = att.index(QString("width"))) != -1)
720
		       LinePatternSymbolizer->width = att.value(index).toDouble();
721
 
722
		    if ((index = att.index(QString("height"))) != -1)
723
		       LinePatternSymbolizer->height = att.value(index).toDouble();
724
		 break;
725
	      }
726
	   }
727
 
728
	   i++;
273 andreas 729
	}
274 andreas 730
 
731
	i = FIRST_FLD;
732
 
733
	while (i <= LAST_FLD)
734
	{
735
	   if (qName.toLower() == getKey(i).toLower())
736
	   {
737
	      Field = i;
738
 
739
	      switch(Container)
740
	      {
741
		 case in_linesymbolizer:
742
		    Names = empty;
743
 
744
		    if (i == FLD_CSSPARAMETER)
745
		    {
746
		       if ((index = att.index(QString("name"))) != -1)
747
		       {
748
			  if (att.value(index).toLower() == QString("stroke"))
749
			     Names = stroke_stroke;
750
			  else if (att.value(index).toLower() == QString("stroke-width"))
751
			     Names = stroke_width;
752
			  else if (att.value(index).toLower() == QString("stroke-opacity"))
753
			     Names = stroke_opacity;
754
			  else if (att.value(index).toLower() == QString("stroke-linejoin"))
755
			     Names = stroke_linejoin;
756
			  else if (att.value(index).toLower() == QString("stroke-linecap"))
757
			     Names = stroke_linecap;
758
			  else if (att.value(index).toLower() == QString("stroke-dasharray"))
759
			     Names = stroke_dasharray;
760
		       }
761
		       else
762
		       {
275 andreas 763
			  KMessageBox::error(0, i18n("Error parsing %1, line %2: Required attribute NAME is missing in CSSPARAMETER inside LINESYMBOLIZER!").arg(XmlPath).arg(XmlLine));
274 andreas 764
			  return false;
765
		       }
766
		    }
767
		 break;
768
 
769
		 case in_polygonsymbolizer:
770
		    Names = empty;
771
 
772
		    if (i == FLD_CSSPARAMETER)
773
		    {
774
		       if ((index = att.index(QString("name"))) != -1)
775
		       {
776
			  if (att.value(index).toLower() == QString("fill"))
777
			     Names = fill;
778
			  else if (att.value(index).toLower() == QString("fill-opacity"))
779
			     Names = fill_opacity;
780
		       }
781
		       else
782
		       {
275 andreas 783
			  KMessageBox::error(0, i18n("Error parsing %1, line %2: Required attribute NAME is missing in CSSPARAMETER inside POLYGONSYMBOLIZER!").arg(XmlPath).arg(XmlLine));
274 andreas 784
			  return false;
785
		       }
786
		    }
787
		 break;
788
 
789
		 case in_datasource:
790
		    Names = empty;
791
 
792
		    if (i == FLD_PARAMETER)
793
		    {
794
		       if ((index = att.index(QString("name"))) != -1)
795
		       {
796
			  if (att.value(index).toLower() == QString("type"))
797
			     Names = type;
798
			  else if (att.value(index).toLower() == QString("file"))
799
			     Names = file;
800
			  else if (att.value(index).toLower() == QString("host"))
801
			     Names = host;
802
			  else if (att.value(index).toLower() == QString("user"))
803
			     Names = user;
804
			  else if (att.value(index).toLower() == QString("dbname"))
805
			     Names = dbname;
806
			  else if (att.value(index).toLower() == QString("table"))
807
			     Names = table;
808
			  else if (att.value(index).toLower() == QString("estimate_extent"))
809
			     Names = estimate_extent;
810
			  else if (att.value(index).toLower() == QString("extent"))
811
			     Names = extent;
812
		       }
813
		       else
814
		       {
275 andreas 815
			  KMessageBox::error(0, i18n("Error parsing %1, line %2: Required attribute NAME is missing in PARAMETER inside DATASOURCE!").arg(XmlPath).arg(XmlLine));
274 andreas 816
			  return false;
817
		       }
818
		    }
819
		 break;
820
 
821
		 case in_root:
822
		    Names = empty;
823
		 break;
824
		 case in_map:
825
		    Names = empty;
826
		 break;
827
		 case in_style:
828
		    Names = empty;
829
		 break;
830
		 case in_rule:
831
		    Names = empty;
832
		 break;
833
		 case in_pointsymbolizer:
834
		    Names = empty;
835
		 break;
836
		 case in_textsymbolizer:
837
		    Names = empty;
838
		 break;
839
		 case in_polygonpatternsymbolizer:
840
		    Names = empty;
841
		 break;
842
		 case in_layer:
843
		    Names = empty;
844
		 break;
845
		 case in_symbolizer:
846
		    Names = empty;
847
		 break;
848
		 case in_shieldsymbolizer:
849
		    Names = empty;
850
		 break;
851
		 case in_linepatternsymbolizer:
852
		    Names = empty;
853
		 break;
854
	      }
855
	   }
856
 
857
	   i++;
858
	}
859
 
860
	return true;
273 andreas 861
}
862
 
863
/*
864
 * This is called every time an element is closed.
865
 */
274 andreas 866
bool SRender::endElement( const QString&, const QString&, const QString& qName)
273 andreas 867
{
274 andreas 868
	if (qName.toLower() == QString("datasource"))
869
	   Container = in_layer;
870
	else if (qName.toLower() == QString("layer"))
871
	{
872
	   parameters p;
873
	   Container = in_map;
874
 
875
	   if (Lay->Datasource.type.toLower() == QString("shape"))
876
	   {
877
	      p["type"] = "shape";
878
	      p["file"] = Lay->Datasource.file.toAscii().constData();
879
	   }
880
	   else if (Lay->Datasource.type.toLower() == QString("postgis"))
881
	   {
882
	      p["type"] = "postgis";
883
	      p["host"] = Lay->Datasource.host.toAscii().constData();
884
	      p["user"] = Lay->Datasource.user.toAscii().constData();
885
	      p["dbname"] = Lay->Datasource.dbname.toAscii().constData();
886
	      p["table"] = Lay->Datasource.table.toAscii().constData();
887
	      p["estimate_extent"] = (Lay->Datasource.estimate_extent) ? "true" : "false";
888
	      p["extent"] = QString("%1,%2,%3,%4").arg(Lay->Datasource.ext_lx).arg(Lay->Datasource.ext_ly).arg(Lay->Datasource.ext_rx).arg(Lay->Datasource.ext_ry).toAscii().data();
889
	   }
890
	   else
891
	   {
275 andreas 892
	      cerr << "Warning file " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Layer with no source! Ingnoring!" << endl;
274 andreas 893
	      return true;
894
	   }
895
 
896
	   Layer lyr(Lay->name.toAscii().data());
275 andreas 897
	   lyr.set_title(Lay->name.toAscii().data());
274 andreas 898
	   lyr.set_datasource(datasource_cache::instance()->create(p));
899
 
275 andreas 900
	   if (Lay->minzoom > 0.0)
901
	      lyr.setMinZoom(Lay->minzoom);
902
 
903
	   if (Lay->maxzoom > 0.0)
904
	      lyr.setMaxZoom(Lay->maxzoom);
905
 
274 andreas 906
	   if (!Lay->srs.isEmpty())
907
	      lyr.set_srs(Lay->srs.toAscii().constData());
908
 
909
	   // Add the styles
910
	   for (int i = 0; i < Lay->Styles.size(); i++)
275 andreas 911
	   {
912
	      if (findStyle (Lay->Styles.at(i)) != 0)
913
		 lyr.add_style(Lay->Styles.at(i).toAscii().constData());
914
	      else
915
		 cerr << "Warning file " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Style \"" << Lay->Styles.at(i).toAscii().data() << "\" does not exist!" << endl;
916
	   }
274 andreas 917
 
275 andreas 918
	   lyr.setActive(Lay->status);
274 andreas 919
	   m.addLayer(lyr);
275 andreas 920
	   Envelope <double>le(lyr.envelope());
921
	   setMaxExtent(le.minx(), le.miny(), le.maxx(), le.maxy());
274 andreas 922
	}
923
	else if (qName.toLower() == QString("map"))
924
	{
925
	   Container = in_root;
926
	   ControlSet = true;
927
	}
275 andreas 928
	else if (qName.toLower() == QString("pointsymbolizer"))
929
	{
274 andreas 930
	   Container = in_rule;
275 andreas 931
 
932
	   if (!Rule || !PointSymbolizer)
933
	   {
934
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of POINTSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
935
	      return false;
936
	   }
937
 
938
	   if (PointSymbolizer->file.length() == 0 || PointSymbolizer->width == 0 || PointSymbolizer->height == 0)
939
	   {
940
	      cerr << "Warning file " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Empty POINTSYMBOLIZER!" << endl;
941
	      point_symbolizer psym;
942
	      Rule->rl.append(psym);
943
	   }
944
	   else
945
	   {
946
	      point_symbolizer ps(PointSymbolizer->file.toAscii().data(), getTypeText(PointSymbolizer->type), PointSymbolizer->width, PointSymbolizer->height);
947
	      ps.set_allow_overlap (PointSymbolizer->allow_overlap);
948
	      Rule->rl.append(ps);
949
	   }
950
	}
951
	else if (qName.toLower() == QString("linesymbolizer"))
274 andreas 952
	{
275 andreas 953
	   Container = in_rule;
274 andreas 954
 
275 andreas 955
	   if (!Rule || !LineSymbolizer)
274 andreas 956
	   {
275 andreas 957
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of LINESYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
958
	      return false;
959
	   }
274 andreas 960
 
275 andreas 961
	   stroke st;
962
	   color col;
963
	   col.set_bgr(LineSymbolizer->stroke);
274 andreas 964
 
275 andreas 965
	   st.set_color (col);
274 andreas 966
 
275 andreas 967
	   if (LineSymbolizer->stroke_width != 0.0)
968
	      st.set_width (LineSymbolizer->stroke_width);
274 andreas 969
 
275 andreas 970
	   if (!LineSymbolizer->stroke_linejoin.isEmpty())
971
	   {
972
	      if (LineSymbolizer->stroke_linejoin.toLower() == QString("miter"))
973
		 st.set_line_join (mapnik::MITER_JOIN);
974
	      else if (LineSymbolizer->stroke_linejoin.toLower() == QString("miter_revert") ||
975
			 LineSymbolizer->stroke_linejoin.toLower() == QString("miter-revert"))
976
		 st.set_line_join (mapnik::MITER_REVERT_JOIN);
977
	      else if (LineSymbolizer->stroke_linejoin.toLower() == QString("round"))
978
		 st.set_line_join (mapnik::ROUND_JOIN);
979
	      else if (LineSymbolizer->stroke_linejoin.toLower() == QString("bevel"))
980
		 st.set_line_join (mapnik::BEVEL_JOIN);
981
	      else
982
		 cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Unknown >>line_join<< \"" << LineSymbolizer->stroke_linejoin.toAscii().data() << "\" --> ignoring!" << endl;
983
	   }
274 andreas 984
 
275 andreas 985
	   if (!LineSymbolizer->stroke_linecap.isEmpty())
986
	   {
987
	      if (LineSymbolizer->stroke_linecap.toLower() == QString("butt"))
988
		st.set_line_cap (mapnik::BUTT_CAP);
989
	      else if (LineSymbolizer->stroke_linecap.toLower() == QString("square"))
990
		st.set_line_cap (mapnik::SQUARE_CAP);
991
	      else if (LineSymbolizer->stroke_linecap.toLower() == QString("round"))
992
		st.set_line_cap (mapnik::ROUND_CAP);
993
	      else
994
		 cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Unknown >>line_cap<< \"" << LineSymbolizer->stroke_linecap.toAscii().data() << "\" --> ignoring!" << endl;
995
	   }
274 andreas 996
 
275 andreas 997
	   if (LineSymbolizer->stroke_dasharray[0] > 0 || LineSymbolizer->stroke_dasharray[1] > 0)
998
	      st.add_dash(LineSymbolizer->stroke_dasharray[0], LineSymbolizer->stroke_dasharray[1]);
274 andreas 999
 
275 andreas 1000
	   if (LineSymbolizer->stroke_opacity != 0)
1001
	      st.set_opacity(LineSymbolizer->stroke_opacity);
274 andreas 1002
 
275 andreas 1003
	   Rule->rl.append(line_symbolizer(st));
1004
	}
1005
	else if (qName.toLower() == QString("polygonsymbolizer"))
1006
	{
1007
	   Container = in_rule;
274 andreas 1008
 
275 andreas 1009
	   if (!Rule || !PolygonSymbolizer)
1010
	   {
1011
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of POLYGONSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1012
	      return false;
1013
	   }
274 andreas 1014
 
275 andreas 1015
	   color col;
1016
	   col.set_bgr(PolygonSymbolizer->fill);
274 andreas 1017
 
275 andreas 1018
	   polygon_symbolizer ps(col);
274 andreas 1019
 
275 andreas 1020
	   if (PolygonSymbolizer->fill_opacity > 0.0)
1021
	      ps.set_opacity(PolygonSymbolizer->fill_opacity);
274 andreas 1022
 
275 andreas 1023
	   Rule->rl.append(ps);
1024
	}
1025
	else if (qName.toLower() == QString("textsymbolizer"))
1026
	{
1027
	   Container = in_rule;
274 andreas 1028
 
275 andreas 1029
	   if (!Rule || !TextSymbolizer)
1030
	   {
1031
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of TEXTSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1032
	      return false;
1033
	   }
274 andreas 1034
 
275 andreas 1035
	   color col;
1036
	   col.set_bgr(TextSymbolizer->fill);
274 andreas 1037
 
275 andreas 1038
	   text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, col);
274 andreas 1039
 
275 andreas 1040
	   if (TextSymbolizer->halo_radius != 0.0)
1041
	      ts.set_halo_radius((unsigned int)TextSymbolizer->halo_radius);
274 andreas 1042
 
275 andreas 1043
	   if (TextSymbolizer->wrap_width != 0.0)
1044
	      ts.set_wrap_width((unsigned int)TextSymbolizer->wrap_width);
274 andreas 1045
 
275 andreas 1046
	   if (TextSymbolizer->mindistance != 0)
1047
	      ts.set_label_spacing(TextSymbolizer->mindistance);
274 andreas 1048
 
275 andreas 1049
	   if (TextSymbolizer->dx != 0 || TextSymbolizer->dy != 0)
1050
	      ts.set_displacement(TextSymbolizer->dx, TextSymbolizer->dy);
274 andreas 1051
 
275 andreas 1052
	   Rule->rl.append(ts);
1053
	}
1054
	else if (qName.toLower() == QString("polygonpatternsymbolizer"))
1055
	{
1056
	   Container = in_rule;
274 andreas 1057
 
275 andreas 1058
	   if (!Rule || !PolygonPatternSymbolizer)
1059
	   {
1060
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Endin of POLYGONPATTERNSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1061
	      return false;
1062
	   }
274 andreas 1063
 
275 andreas 1064
	   Rule->rl.append(polygon_pattern_symbolizer(findIcon(PolygonPatternSymbolizer->file).toAscii().data(),
1065
						getTypeText(PolygonPatternSymbolizer->type),
1066
						PolygonPatternSymbolizer->width,
1067
						PolygonPatternSymbolizer->height));
1068
	   PolygonPatternSymbolizer = PolygonPatternSymbolizer->next;
1069
	}
1070
	else if (qName.toLower() == QString("shieldsymbolizer"))
1071
	{
1072
	   Container = in_rule;
274 andreas 1073
 
275 andreas 1074
	   if (!Rule || !ShieldSymbolizer)
1075
	   {
1076
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of SHIELDSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1077
	      return false;
1078
	   }
274 andreas 1079
 
275 andreas 1080
	   color col;
1081
	   col.set_bgr(ShieldSymbolizer->fill);
1082
	   shield_symbolizer ss(ShieldSymbolizer->name.toAscii().data(),
1083
				ShieldSymbolizer->face_name.toAscii().data(),
1084
				ShieldSymbolizer->size, col,
1085
				findIcon(ShieldSymbolizer->file).toAscii().data(),
1086
				getTypeText(ShieldSymbolizer->type),
1087
				ShieldSymbolizer->width, ShieldSymbolizer->height);
1088
 
1089
	   if (!ShieldSymbolizer->placement.isEmpty())
1090
	      ss.set_label_placement((ShieldSymbolizer->placement.toLower() == QString("point")) ? mapnik::POINT_PLACEMENT : mapnik::LINE_PLACEMENT);
1091
 
1092
	   if (ShieldSymbolizer->dx != 0 || ShieldSymbolizer->dy != 0)
1093
	      ss.set_displacement(ShieldSymbolizer->dx, ShieldSymbolizer->dy);
1094
 
1095
	   if (ShieldSymbolizer->mindistance != 0)
1096
	      ss.set_label_spacing(ShieldSymbolizer->mindistance);
1097
 
1098
	   Rule->rl.append(ss);
1099
	}
1100
	else if (qName.toLower() == QString("linepatternsymbolizer"))
1101
	{
1102
	   Container = in_rule;
1103
 
1104
	   if (!Rule || !LinePatternSymbolizer)
1105
	   {
1106
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of LINEPATTERNSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1107
	      return false;
1108
	   }
1109
 
1110
	   Rule->rl.append(line_pattern_symbolizer(findIcon(LinePatternSymbolizer->file).toAscii().data(),
1111
						getTypeText(LinePatternSymbolizer->type),
1112
						LinePatternSymbolizer->width,
1113
						LinePatternSymbolizer->height));
1114
	}
1115
	else if (qName.toLower() == QString("filter") ||
1116
		 qName.toLower() == QString("maxscaledenominator") ||
1117
		 qName.toLower() == QString("minscaledenominator"))
1118
	   Container = in_rule;
1119
	else if (qName.toLower() == QString("rule"))
1120
	   Container = in_style;
1121
	else if (qName.toLower() == QString("style"))
1122
	{
1123
	   Container = in_map;
1124
	   feature_type_style style;
1125
 
1126
	   if (Style->rule)
1127
	   {
1128
	      Rule = Style->rule;
1129
 
1130
	      while (Rule)
1131
	      {
1132
		 style.add_rule(Rule->rl);
274 andreas 1133
		 Rule = Rule->next;
1134
	      }
1135
	   }
1136
 
1137
	   // Add style to map
1138
	   m.insert_style(Style->name.toAscii().data(), style);
1139
	}
1140
 
1141
	return true;
273 andreas 1142
}
1143
 
1144
/*
1145
 * The reader calls this function when it has parsed a chunk of character data
1146
 * - either normal character data or character data inside a CDATA section.
1147
 */
275 andreas 1148
bool SRender::characters (const QString& chraw)
273 andreas 1149
{
275 andreas 1150
	QString ch = chraw.trimmed();
1151
 
1152
	if (ch.length() == 0)
274 andreas 1153
	   return true;
1154
 
275 andreas 1155
	if (ch.at(0) == QChar('\n'))
1156
	{
1157
	   XmlLine++;
1158
	   return true;
1159
	}
1160
 
274 andreas 1161
	if (Container == in_rule && Rule)
1162
	{
1163
	   if (Field == FLD_FILTER)
275 andreas 1164
	   {
274 andreas 1165
	      Rule->filter = ch;
275 andreas 1166
 
1167
	      if (!Rule->filter.isEmpty())
1168
		 Rule->rl.set_filter(create_filter(Rule->filter.toAscii().data()));
1169
	      else
1170
		 cerr << "Warning in file " << XmlPath.toAscii().data() << " at line " << XmlLine << ": Ignoring empty filter!" << endl;
1171
	   }
274 andreas 1172
	   else if (Field == FLD_MAXSCALE)
275 andreas 1173
	   {
274 andreas 1174
	      Rule->maxscale = ch.toDouble();
275 andreas 1175
	      Rule->rl.set_max_scale(Rule->maxscale);
1176
	   }
274 andreas 1177
	   else if (Field == FLD_MINSCALE)
275 andreas 1178
	   {
274 andreas 1179
	      Rule->minscale = ch.toDouble();
275 andreas 1180
	      Rule->rl.set_min_scale(Rule->minscale);
1181
	   }
274 andreas 1182
	}
1183
	else if (Container == in_linesymbolizer && LineSymbolizer)
1184
	{
1185
	   if (Field == FLD_CSSPARAMETER)
1186
	   {
1187
	      if (Names == stroke_stroke)
1188
		 LineSymbolizer->stroke = colorToUInt(ch);
1189
	      else if (Names == stroke_width)
1190
		 LineSymbolizer->stroke_width = ch.toDouble();
1191
	      else if (Names == stroke_linejoin)
1192
		 LineSymbolizer->stroke_linejoin = ch;
1193
	      else if (Names == stroke_linecap)
1194
		 LineSymbolizer->stroke_linecap = ch;
1195
	      else if (Names == stroke_opacity)
1196
		 LineSymbolizer->stroke_opacity = ch.toDouble();
1197
	      else if (Names == stroke_dasharray)
1198
	      {
1199
	      int pos;
1200
	      QString arr = ch;
1201
	      QStringList list;
1202
 
1203
		 list = arr.split(",", QString::SkipEmptyParts);
1204
 
1205
		 for (pos = 0; pos < list.size() && pos < 10; pos++)
1206
		    LineSymbolizer->stroke_dasharray[pos] = list.at(pos).toDouble();
1207
 
1208
		 LineSymbolizer->stroke_anz = pos;
1209
	      }
1210
	   }
1211
	}
1212
	else if (Container == in_polygonsymbolizer && PolygonSymbolizer)
1213
	{
1214
	   if (Field == FLD_CSSPARAMETER)
1215
	   {
1216
	      if (Names == fill)
1217
		 PolygonSymbolizer->fill = colorToUInt(ch);
1218
	      else if (Names == fill_opacity)
1219
		 PolygonSymbolizer->fill_opacity = ch.toDouble();
1220
	   }
1221
	}
1222
	else if (Container == in_layer && Lay)
1223
	{
1224
	   if (Field == FLD_STYLENAME)
1225
	      Lay->Styles << ch;
1226
	}
1227
	else if (Container == in_datasource && Lay)
1228
	{
1229
	   if (Field == FLD_PARAMETER)
1230
	   {
1231
	      if (Names == type)
1232
		 Lay->Datasource.type = ch;
1233
	      else if (Names == file)
275 andreas 1234
	      {
1235
	      QFileInfo qf(ch);
1236
	      QString hv0;
1237
 
1238
		 hv0 = shapePath;
1239
 
1240
		 if (hv0.right(1) != QString("/"))
1241
		    hv0 += "/";
1242
 
1243
		 hv0 += qf.fileName();
1244
		 qf.setFile (hv0 + ".shp");
1245
 
1246
		 if (!qf.exists())
1247
		 {
1248
		    KMessageBox::error(0, i18n("The shape file \"%1\" at line %2 does not exist!").arg(hv0+".shp").arg(XmlLine));
1249
		    return false;
1250
		 }
1251
 
1252
		 Lay->Datasource.file = hv0;
1253
	      }
274 andreas 1254
	      else if (Names == host)
1255
		 Lay->Datasource.host = ch;
1256
	      else if (Names == user)
1257
		 Lay->Datasource.user = ch;
1258
	      else if (Names == dbname)
1259
		 Lay->Datasource.dbname = ch;
1260
	      else if (Names == table)
1261
		 Lay->Datasource.table = ch;
1262
	      else if (Names == estimate_extent)
1263
		 Lay->Datasource.estimate_extent = getBool(ch);
1264
	      else if (Names == extent)
1265
	      {
1266
		 QString arr = ch;
1267
		 QStringList list;
1268
		 list = arr.split(",");
275 andreas 1269
 
1270
		 if (list.size() >= 1)
1271
		    Lay->Datasource.ext_lx = list.at(0).toDouble();
1272
 
1273
		 if (list.size() >= 2)
1274
		    Lay->Datasource.ext_ly = list.at(1).toDouble();
1275
 
1276
		 if (list.size() >= 3)
1277
		    Lay->Datasource.ext_rx = list.at(2).toDouble();
1278
 
1279
		 if (list.size() >= 4)
1280
		    Lay->Datasource.ext_ry = list.at(3).toDouble();
274 andreas 1281
	      }
1282
	   }
1283
	}
1284
 
1285
	return true;
273 andreas 1286
}
1287
 
274 andreas 1288
QString SRender::getKey (int pos)
273 andreas 1289
{
1290
int i = 0;
1291
 
274 andreas 1292
	while (token[i].id > 0)
273 andreas 1293
	{
274 andreas 1294
	   if (token[i].id == pos)
1295
	      return token[i].name;
273 andreas 1296
 
1297
	   i++;
1298
	}
1299
 
1300
	return QString::null;
1301
}
1302
 
274 andreas 1303
TYPES SRender::getType(QString ty)
273 andreas 1304
{
274 andreas 1305
	if (ty.toLower() == QString("png"))
1306
	   return type_png;
1307
	else if (ty.toLower() == QString("gif"))
1308
	   return type_gif;
1309
	else if (ty.toLower() == QString("jpg"))
1310
	   return type_jpg;
1311
	else if (ty.toLower() == QString("xpm"))
1312
	   return type_xpm;
1313
	else if (ty.toLower() == QString("bmp"))
1314
	   return type_bmp;
1315
	else if (ty.toLower() == QString("tif") || ty.toLower() == QString("tiff"))
1316
	   return type_tif;
273 andreas 1317
 
274 andreas 1318
	return type_png;
1319
}
273 andreas 1320
 
274 andreas 1321
char *grTypes[] = { (char *)"png", (char *)"gif", (char *)"jpg", (char*)"xpm",
1322
		    (char *)"bmp", (char *)"tif" };
273 andreas 1323
 
274 andreas 1324
char *SRender::getTypeText(TYPES type)
1325
{
1326
	switch (type)
1327
	{
1328
	   case type_png: return grTypes[0]; break;
1329
	   case type_gif: return grTypes[1]; break;
1330
	   case type_jpg: return grTypes[2]; break;
1331
	   case type_xpm: return grTypes[3]; break;
1332
	   case type_bmp: return grTypes[4]; break;
1333
	   case type_tif: return grTypes[5]; break;
1334
	}
273 andreas 1335
 
274 andreas 1336
	return 0;
1337
}
273 andreas 1338
 
274 andreas 1339
bool SRender::getBool(QString b)
1340
{
1341
	if (b.toLower() == QString("true") ||
1342
	    b.toLower() == QString("on") ||
1343
	    b.toLower() == QString("1") ||
1344
	    b.toLower() == QString("yes") ||
1345
	    b.toLower() == QString("t") ||
1346
	    b.toLower() == QString("y"))
1347
	   return true;
273 andreas 1348
 
274 andreas 1349
	return false;
1350
}
273 andreas 1351
 
274 andreas 1352
bool SRender::getMap (double lx, double ly, double rx, double ry)
1353
{
275 andreas 1354
int width, height;
274 andreas 1355
QXmlSimpleReader reader;
1356
QString hv0;
1357
QFile file(XmlPath);
275 andreas 1358
double plx, ply, prx, pry;
273 andreas 1359
 
275 andreas 1360
	OutBuf.clear();
1361
	hv0 = pluginPath;
1362
 
1363
	if (hv0.right(1) != QString("/"))
1364
	   hv0 += "/";
1365
 
274 andreas 1366
	datasource_cache::instance()->register_datasources(hv0.toAscii().data());
275 andreas 1367
	hv0 = fontPath;
1368
 
1369
	if (hv0.right(1) != QString("/"))
1370
	   hv0 += "/";
1371
 
1372
	hv0 += "DejaVuSans.ttf";
274 andreas 1373
	freetype_engine::register_font(hv0.toAscii().data());
273 andreas 1374
 
274 andreas 1375
	width = label->width();
1376
	height = label->height();
273 andreas 1377
 
274 andreas 1378
	m.setWidth(width);
1379
	m.setHeight(height);
275 andreas 1380
//	load_map(m, XmlPath.toAscii().data());
273 andreas 1381
 
274 andreas 1382
	if (!ControlSet)	// Initialize the map?
1383
	{
1384
	   QXmlInputSource source (&file);
1385
	   reader.setContentHandler (this);
1386
	   reader.parse (source);
1387
	}
273 andreas 1388
 
275 andreas 1389
	save_map(m, "/home/andreas/.sportwatcher/spw.xml");
1390
//	save_map(m, "/home/andreas/.sportwatcher/spw1.xml");
1391
	plx = lx;
1392
	ply = ly;
1393
	prx = rx;
1394
	pry = ry;
1395
	projection pj(m.srs());
1396
 
1397
	if (pj.is_geographic())
1398
	{
1399
	   pj.inverse(plx, ply);
1400
	   pj.inverse(prx, pry);
1401
cout << "Geographic! Inverse projection." << endl;
1402
	}
1403
	else
1404
	{
1405
//	   pj.forward(plx, ply);
1406
//	   pj.forward(prx, pry);
1407
cout << "NOT geographic!" << endl;
1408
	}
1409
 
1410
for (unsigned i = 0; i < m.layerCount(); i++)
1411
{
1412
   bool vis = m.getLayer(i).isVisible(m.scale_denominator());
1413
   cout << "Layer " << i << ": " << m.getLayer(i).name();
1414
   cout << ", Visible: " << vis;
1415
   Envelope <double>e(m.getLayer(i).envelope());
1416
   cout << ", Extent: " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl;
1417
}
1418
 
274 andreas 1419
	// First we use Mapnik to create the map
275 andreas 1420
	m.zoomToBox(Envelope<double>(plx, ply, prx, pry));
1421
 
1422
Envelope <double>e(m.getCurrentExtent());
1423
cout << std::setprecision(16) << "Parameter envelope: " << lx << ", " << ly << ", " << rx << ", " << ry << endl;
1424
cout << std::setprecision(16) << "Converted envelope: " << plx << ", " << ply << ", " << prx << ", " << pry << endl;
1425
cout << std::setprecision(16) << "Current extent:     " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl;
1426
cout << "SRS: " << m.srs() << endl;
1427
cout << std::setprecision(16) << "Scale: " << m.scale() << ", scale denominator: " << m.scale_denominator() << endl;
1428
cout << "width=" << m.getWidth() << ", height=" << m.getHeight() << endl;
1429
 
274 andreas 1430
	Image32 buf(m.getWidth(), m.getHeight());
1431
	agg_renderer<Image32> ren(m, buf);
1432
	ren.apply();
275 andreas 1433
	// Put the image into a Qt object
1434
	QImage image((uchar*)buf.raw_data(), m.getWidth(), m.getHeight(), QImage::Format_ARGB32);
1435
	label->setPixmap(QPixmap::fromImage(image.rgbSwapped()));
274 andreas 1436
	// Create a unique file name
275 andreas 1437
//	pid = getpid();
1438
//	OutBuf.sprintf("/var/tmp/SportWatcher_%d.png", pid);
1439
//	save_to_file<ImageData32>(buf.data(), OutBuf.toAscii().data(), "png");
273 andreas 1440
 
274 andreas 1441
	return true;
1442
}
273 andreas 1443
 
275 andreas 1444
void SRender::setMaxExtent(double lx, double ly, double rx, double ry)
1445
{
1446
	if (lx > 0 && _lx > lx)
1447
	   _lx = lx;
1448
 
1449
	if (lx < 0 && _lx < lx)
1450
	   _lx = lx;
1451
 
1452
	if (ly > 0 && _ly > ly)
1453
	   _ly = ly;
1454
 
1455
	if (ly < 0 && _ly < ly)
1456
	   _ly = ly;
1457
 
1458
	if (rx > 0 && _rx < rx)
1459
	   _rx = rx;
1460
 
1461
	if (rx < 0 && _rx > rx)
1462
	   _rx = rx;
1463
 
1464
	if (ry > 0 && _ry < ry)
1465
	   _ry = ry;
1466
 
1467
	if (ry < 0 && _ry > ry)
1468
	   _ry = ry;
1469
}
1470
 
1471
QString SRender::findIcon(QString ic)
1472
{
1473
QString ptf, icon;
1474
QFileInfo fi(ic);
1475
 
1476
	icon = fi.fileName();
1477
	ptf = KStandardDirs::locate("data", QString("sportwatcher/icons/%1").arg(icon));
1478
 
1479
	if (ptf.length() < icon.length())
1480
	{
1481
	   KMessageBox::error(0, i18n("The icon %1 was not found!").arg(icon));
1482
	   ptf.clear();
1483
	}
1484
 
1485
	return ptf;
1486
}
1487
 
274 andreas 1488
RULE *SRender::getLastRule(RULE *first)
1489
{
1490
RULE *akt = first;
273 andreas 1491
 
274 andreas 1492
	while (akt)
1493
	{
1494
	   if (!akt->next)
1495
	      return akt;
1496
 
1497
	   akt = akt->next;
1498
	}
1499
 
1500
	return 0;
273 andreas 1501
}
1502
 
274 andreas 1503
POINTSYMBOLIZER *SRender::getLastPointSymbolizer(POINTSYMBOLIZER *first)
273 andreas 1504
{
274 andreas 1505
POINTSYMBOLIZER *akt = first;
273 andreas 1506
 
274 andreas 1507
	while (akt)
1508
	{
1509
	   if (!akt->next)
1510
	      return akt;
273 andreas 1511
 
274 andreas 1512
	   akt = akt->next;
1513
	}
273 andreas 1514
 
274 andreas 1515
	return 0;
1516
}
1517
 
1518
LINESYMBOLIZER *SRender::getLastLineSymbolizer(LINESYMBOLIZER *first)
1519
{
1520
LINESYMBOLIZER *akt = first;
1521
 
1522
	while (akt)
273 andreas 1523
	{
274 andreas 1524
	   if (!akt->next)
1525
	      return akt;
273 andreas 1526
 
274 andreas 1527
	   akt = akt->next;
273 andreas 1528
	}
1529
 
274 andreas 1530
	return 0;
1531
}
273 andreas 1532
 
274 andreas 1533
POLYGONSYMBOLIZER *SRender::getLastPolygonSymbolizer(POLYGONSYMBOLIZER *first)
1534
{
1535
POLYGONSYMBOLIZER *akt = first;
273 andreas 1536
 
274 andreas 1537
	while (akt)
273 andreas 1538
	{
274 andreas 1539
	   if (!akt->next)
1540
	      return akt;
273 andreas 1541
 
274 andreas 1542
	   akt = akt->next;
273 andreas 1543
	}
1544
 
274 andreas 1545
	return 0;
273 andreas 1546
}
1547
 
274 andreas 1548
TEXTSYMBOLIZER *SRender::getLastTextSymbolizer(TEXTSYMBOLIZER *first)
273 andreas 1549
{
274 andreas 1550
TEXTSYMBOLIZER *akt = first;
273 andreas 1551
 
274 andreas 1552
	while (akt)
273 andreas 1553
	{
274 andreas 1554
	   if (!akt->next)
1555
	      return akt;
273 andreas 1556
 
274 andreas 1557
	   akt = akt->next;
273 andreas 1558
	}
1559
 
274 andreas 1560
	return 0;
1561
}
273 andreas 1562
 
274 andreas 1563
POLYGONPATTERNSYMBOLIZER *SRender::getLastPolygonPatternSymbolizer(POLYGONPATTERNSYMBOLIZER *first)
1564
{
1565
POLYGONPATTERNSYMBOLIZER *akt = first;
273 andreas 1566
 
274 andreas 1567
	while (akt)
273 andreas 1568
	{
274 andreas 1569
	   if (!akt->next)
1570
	      return akt;
273 andreas 1571
 
274 andreas 1572
	   akt = akt->next;
273 andreas 1573
	}
1574
 
274 andreas 1575
	return 0;
273 andreas 1576
}
1577
 
274 andreas 1578
SHIELDSYMBOLIZER *SRender::getLastShieldSymbolizer(SHIELDSYMBOLIZER *first)
273 andreas 1579
{
274 andreas 1580
SHIELDSYMBOLIZER *akt = first;
273 andreas 1581
 
274 andreas 1582
	while (akt)
273 andreas 1583
	{
274 andreas 1584
	   if (!akt->next)
1585
	      return akt;
1586
 
1587
	   akt = akt->next;
273 andreas 1588
	}
1589
 
274 andreas 1590
	return 0;
273 andreas 1591
}
1592
 
274 andreas 1593
LINEPATTERNSYMBOLIZER *SRender::getLastLinePatternSymbolizer(LINEPATTERNSYMBOLIZER *first)
273 andreas 1594
{
274 andreas 1595
LINEPATTERNSYMBOLIZER *akt = first;
273 andreas 1596
 
1597
	while (akt)
1598
	{
1599
	   if (!akt->next)
1600
	      return akt;
1601
 
1602
	   akt = akt->next;
1603
	}
1604
 
1605
	return 0;
1606
}
1607
 
274 andreas 1608
STYLE *SRender::findStyle(QString name)
273 andreas 1609
{
274 andreas 1610
STYLE *akt = firstStyle;
273 andreas 1611
 
1612
	while (akt)
1613
	{
274 andreas 1614
	   if (akt->name.toLower() == name.toLower())
273 andreas 1615
	      return akt;
1616
 
1617
	   akt = akt->next;
1618
	}
1619
 
1620
	return 0;
1621
}
274 andreas 1622
 
1623
unsigned SRender::colorToUInt(QString col)
1624
{
1625
QColor qc(col);
1626
 
275 andreas 1627
	return (qc.blue() * 65536) + (qc.green() * 256) + qc.red();
274 andreas 1628
}
1629
 
1630
STYLE *SRender::allocStyle()
1631
{
1632
STYLE *St = new STYLE;
1633
 
1634
	St->name.clear();
1635
	St->rule = 0;
1636
	St->next = 0;
1637
	return St;
1638
}
1639
 
1640
RULE *SRender::allocRule()
1641
{
1642
RULE *Ru = new RULE;
1643
 
1644
	Ru->maxscale = 0;
1645
	Ru->minscale = 0;
1646
	Ru->filter.clear();
1647
	Ru->LineSymbolizer = 0;
1648
	Ru->PolygonSymbolizer = 0;
1649
	Ru->TextSymbolizer = 0;
1650
	Ru->PointSymbolizer = 0;
1651
	Ru->PolygonPatternSymbolizer = 0;
1652
	Ru->ShieldSymbolizer = 0;
1653
	Ru->LinePatternSymbolizer = 0;
1654
	Ru->next = 0;
1655
	return Ru;
1656
}
1657
 
1658
LAYER *SRender::allocLayer()
1659
{
1660
LAYER *La = new LAYER;
1661
 
1662
	La->name.clear();	// The unique name
1663
	La->status = false;	// Is it active?
1664
	La->srs.clear();	// Projection
275 andreas 1665
	La->minzoom = 0.0;
1666
	La->maxzoom = 0.0;
274 andreas 1667
	La->Datasource.type.clear();
1668
	La->Datasource.file.clear();
1669
	La->Datasource.host.clear();
1670
	La->Datasource.user.clear();
1671
	La->Datasource.dbname.clear();
1672
	La->Datasource.table.clear();
1673
	La->Datasource.estimate_extent = false;
1674
	La->Datasource.ext_lx = 0.0;
1675
	La->Datasource.ext_ly = 0.0;
1676
	La->Datasource.ext_rx = 0.0;
1677
	La->Datasource.ext_ry = 0.0;
1678
	La->next = 0;
1679
	return La;
1680
}
1681
 
1682
LINEPATTERNSYMBOLIZER *SRender::allocLinePatternSymbolizer()
1683
{
1684
LINEPATTERNSYMBOLIZER *lps = new LINEPATTERNSYMBOLIZER;
1685
 
1686
	lps->file.clear();
1687
	lps->type = type_png;		// enum TYPES
1688
	lps->width = 0.0;
1689
	lps->height = 0.0;
1690
	lps->next = 0;
1691
	return lps;
1692
}
1693
 
1694
SHIELDSYMBOLIZER *SRender::allocShieldSymbolizer()
1695
{
1696
SHIELDSYMBOLIZER *ss = new SHIELDSYMBOLIZER;
1697
 
1698
	ss->name.clear();
1699
	ss->face_name.clear();
1700
	ss->size = 0.0;
275 andreas 1701
	ss->fill = 0;			// Color
274 andreas 1702
	ss->placement.clear();
1703
	ss->file.clear();
1704
	ss->type = type_png;		// enum TYPES
1705
	ss->width = 0.0;
1706
	ss->height = 0.0;
275 andreas 1707
	ss->dx = 0.0;
1708
	ss->dy = 0.0;
274 andreas 1709
	ss->mindistance = 0.0;
1710
	ss->maxdistance = 0.0;
1711
	ss->next = 0;
1712
	return ss;
1713
}
1714
 
1715
POLYGONPATTERNSYMBOLIZER *SRender::allocPolygonPatternSymbolizer()
1716
{
1717
POLYGONPATTERNSYMBOLIZER *pps = new POLYGONPATTERNSYMBOLIZER;
1718
 
1719
	pps->file.clear();
1720
	pps->type = type_png;		// enum TYPES
1721
	pps->width = 0.0;
1722
	pps->height = 0.0;
1723
	pps->allow_overlap = false;
1724
	pps->next = 0;
1725
	return pps;
1726
}
1727
 
1728
POINTSYMBOLIZER *SRender::allocPointSymbolizer()
1729
{
1730
POINTSYMBOLIZER *ps = new POINTSYMBOLIZER;
1731
 
1732
	ps->file.clear();
1733
	ps->type = type_png;		// enum TYPES
1734
	ps->width = 0.0;
1735
	ps->height = 0.0;
1736
	ps->allow_overlap = false;
1737
	ps->next = 0;
1738
	return ps;
1739
}
1740
 
1741
TEXTSYMBOLIZER *SRender::allocTextSymbolizer()
1742
{
1743
TEXTSYMBOLIZER *ts = new TEXTSYMBOLIZER;
1744
 
1745
	ts->name.clear();
1746
	ts->face_name.clear();
1747
	ts->size = 0;
1748
	ts->fill = 0;			// Color
1749
	ts->halo_radius = 0;
1750
	ts->wrap_width = 0;
275 andreas 1751
	ts->dx = 0.0;
274 andreas 1752
	ts->dy = 0.0;
1753
	ts->mindistance = 0.0;
1754
	ts->maxdistance = 0.0;
1755
	ts->next = 0;
1756
	return ts;
1757
}
1758
 
1759
POLYGONSYMBOLIZER *SRender::allocPolygonSymbolizer()
1760
{
1761
POLYGONSYMBOLIZER *ps = new POLYGONSYMBOLIZER;
1762
 
1763
	memset (ps, 0, sizeof(POLYGONSYMBOLIZER));
1764
	return ps;
1765
}
1766
 
1767
LINESYMBOLIZER *SRender::allocLineSymbolizer()
1768
{
1769
LINESYMBOLIZER *ls = new LINESYMBOLIZER;
1770
 
1771
	ls->stroke = 0;		// Color
1772
	ls->stroke_width = 0.0;
1773
	ls->stroke_linejoin.clear();
1774
	ls->stroke_linecap.clear();
1775
 
1776
	for (int i = 0; i < 10; i++)
1777
	   ls->stroke_dasharray[i] = 0.0;
1778
 
1779
	ls->stroke_anz = 0;		// number of entries in dasharray
1780
	ls->stroke_opacity = 0.0;
1781
	ls->next = 0;
1782
	return ls;
1783
}