Subversion Repositories public

Rev

Rev 278 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 278 Rev 280
Line 8... Line 8...
8
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
8
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
9
//
9
//
10
// Copyright: See COPYING file that comes with this distribution
10
// Copyright: See COPYING file that comes with this distribution
11
//
11
//
12
//
12
//
-
 
13
#include "config.h"
-
 
14
 
-
 
15
// This module will only exist, if Mapnik is available!
-
 
16
#if defined HAVE_MAPNIK
-
 
17
 
13
#define BOOST_SPIRIT_THREADSAFE
18
#define BOOST_SPIRIT_THREADSAFE
-
 
19
#include <QPixmap>
14
#include <QLabel>
20
#include <QBitmap>
15
#include <QString>
21
#include <QString>
16
#include <QXmlReader>
22
#include <QXmlReader>
17
#include <QDir>
23
#include <QDir>
18
#include <QColor>
24
#include <QColor>
19
#include <QImage>
25
#include <QImage>
Line 23... Line 29...
23
#include <KMessageBox>
29
#include <KMessageBox>
24
#include <KGlobalSettings>
30
#include <KGlobalSettings>
25
#include <KConfigGroup>
31
#include <KConfigGroup>
26
#include <KIconLoader>
32
#include <KIconLoader>
27
 
33
 
28
#include "config.h"
-
 
29
#include "render.h"
34
#include "render.h"
30
#include <iostream>
35
#include <iostream>
31
 
36
 
32
#define CON_MAP			100
37
#define CON_MAP			100
33
#define CON_STYLE		101
38
#define CON_STYLE		101
Line 129... Line 134...
129
	{ 0,				in_root,		QString::null }
134
	{ 0,				in_root,		QString::null }
130
};
135
};
131
 
136
 
132
SRender::SRender()
137
SRender::SRender()
133
{
138
{
134
	label = 0;
139
	_width = _height = 0;
135
	shapePath = QString::null;
140
	shapePath = QString::null;
136
	XmlPath = QString::null;
141
	XmlPath = QString::null;
137
	Lay = firstLayer = lastLayer = 0;
142
	Lay = firstLayer = lastLayer = 0;
138
	Style = firstStyle = lastStyle = 0;
143
	Style = firstStyle = lastStyle = 0;
139
	Rule = 0;
144
	Rule = 0;
Line 190... Line 195...
190
	geographic = sh.readEntry("Geographic", false);
195
	geographic = sh.readEntry("Geographic", false);
191
}
196
}
192
 
197
 
193
SRender::~SRender()
198
SRender::~SRender()
194
{
199
{
-
 
200
	_width = _height = 0;
195
	startDocument();	// Clean everything
201
	startDocument();	// Clean everything
196
	ControlSet = false;
202
	ControlSet = false;
197
}
203
}
198
 
204
 
-
 
205
void SRender::setDrawArea(int w, int h)
-
 
206
{
-
 
207
	_width = w;
-
 
208
	_height = h;
-
 
209
}
-
 
210
 
199
bool SRender::startDocument()
211
bool SRender::startDocument()
200
{
212
{
201
	m.remove_all();		// delete styles and layers from map
213
	m.remove_all();		// delete styles and layers from map
202
 
214
 
203
	if (firstStyle)		// free if allocated
215
	if (firstStyle)		// free if allocated
Line 1475... Line 1487...
1475
	return false;
1487
	return false;
1476
}
1488
}
1477
 
1489
 
1478
bool SRender::getMap (double lx, double ly, double rx, double ry)
1490
bool SRender::getMap (double lx, double ly, double rx, double ry)
1479
{
1491
{
1480
int width, height;
-
 
1481
QXmlSimpleReader reader;
1492
QXmlSimpleReader reader;
1482
QString hv0;
1493
QString hv0;
1483
QFile file(XmlPath);
1494
QFile file(XmlPath);
1484
QDir dir(fontPath);
1495
QDir dir(fontPath);
1485
double plx, ply, prx, pry;
1496
double plx, ply, prx, pry;
1486
 
1497
 
-
 
1498
	if (_width <= 0 || _height <= 0)
-
 
1499
	   return false;
-
 
1500
 
1487
	hv0 = pluginPath;
1501
	hv0 = pluginPath;
1488
 
1502
 
1489
	if (hv0.right(1) != QString("/"))
1503
	if (hv0.right(1) != QString("/"))
1490
	   hv0 += "/";
1504
	   hv0 += "/";
1491
 
1505
 
Line 1515... Line 1529...
1515
	   QFileInfo fileInfo = list.at(i);
1529
	   QFileInfo fileInfo = list.at(i);
1516
	   f = hv0 + fileInfo.fileName();
1530
	   f = hv0 + fileInfo.fileName();
1517
	   freetype_engine::register_font(f.toAscii().data());
1531
	   freetype_engine::register_font(f.toAscii().data());
1518
	}
1532
	}
1519
 
1533
 
1520
//	hv0 += "DejaVuSans.ttf";	// Default font
-
 
1521
//	freetype_engine::register_font(hv0.toAscii().data());
-
 
1522
 
-
 
1523
	width = label->width();
-
 
1524
	height = label->height();
-
 
1525
 
-
 
1526
	m.setWidth(width);
1534
	m.setWidth(_width);
1527
	m.setHeight(height);
1535
	m.setHeight(_height);
1528
 
1536
 
1529
	try
1537
	try
1530
	{
1538
	{
1531
	   if (!ControlSet)	// Initialize the map?
1539
	   if (!ControlSet)	// Initialize the map?
1532
	   {
1540
	   {
Line 1561... Line 1569...
1561
	   agg_renderer<Image32> ren(m, buf);
1569
	   agg_renderer<Image32> ren(m, buf);
1562
	   ren.apply();
1570
	   ren.apply();
1563
 
1571
 
1564
	   // Put the image into a Qt object
1572
	   // Put the image into a Qt object
1565
	   QImage image((uchar*)buf.raw_data(), m.getWidth(), m.getHeight(), QImage::Format_ARGB32);
1573
	   QImage image((uchar*)buf.raw_data(), m.getWidth(), m.getHeight(), QImage::Format_ARGB32);
1566
	   label->setPixmap(QPixmap::fromImage(image.rgbSwapped()));
1574
	   pxmap = QPixmap::fromImage(image.rgbSwapped());
1567
	}
1575
	}
1568
 
1576
 
1569
	catch (const mapnik::config_error &ex)
1577
	catch (const mapnik::config_error &ex)
1570
	{
1578
	{
1571
	   KMessageBox::error(0, i18n("Configuration error: %1").arg(ex.what()));
1579
	   KMessageBox::error(0, i18n("Configuration error: %1").arg(ex.what()));
Line 1954... Line 1962...
1954
	ls->stroke_anz = 0;		// number of entries in dasharray
1962
	ls->stroke_anz = 0;		// number of entries in dasharray
1955
	ls->stroke_opacity = 0.0;
1963
	ls->stroke_opacity = 0.0;
1956
	ls->next = 0;
1964
	ls->next = 0;
1957
	return ls;
1965
	return ls;
1958
}
1966
}
-
 
1967
 
-
 
1968
#endif // HAVE_MAPNIK
1959
 
1969