Subversion Repositories public

Rev

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

Rev 277 Rev 278
Line 185... Line 185...
185
	   fontPath = sh.readEntry("FontPath", QString("/usr/share/fonts/truetype/ttf-dejavu"));
185
	   fontPath = sh.readEntry("FontPath", QString("/usr/share/fonts/truetype/ttf-dejavu"));
186
	else
186
	else
187
	   fontPath = sh.readEntry("FontPath", QString(""));
187
	   fontPath = sh.readEntry("FontPath", QString(""));
188
#endif
188
#endif
189
	XmlPath = sh.readEntry("XmlFile", basePath + "/shapefiles/osm.xml");
189
	XmlPath = sh.readEntry("XmlFile", basePath + "/shapefiles/osm.xml");
-
 
190
	geographic = sh.readEntry("Geographic", false);
190
}
191
}
191
 
192
 
192
SRender::~SRender()
193
SRender::~SRender()
193
{
194
{
194
	startDocument();	// Clean everything
195
	startDocument();	// Clean everything
195
	ControlSet = false;
196
	ControlSet = false;
196
 
-
 
197
	if (!OutBuf.isEmpty())
-
 
198
	   unlink (OutBuf.toAscii().data());
-
 
199
}
197
}
200
 
198
 
201
bool SRender::startDocument()
199
bool SRender::startDocument()
202
{
200
{
203
	m.remove_all();		// delete styles and layers from map
201
	m.remove_all();		// delete styles and layers from map
Line 345... Line 343...
345
		       return false;
343
		       return false;
346
		    }
344
		    }
347
 
345
 
348
		    if ((index = att.index(QString("bgcolor"))) != -1)
346
		    if ((index = att.index(QString("bgcolor"))) != -1)
349
		    {
347
		    {
350
		    color col;
-
 
351
 
-
 
352
		       MapPars.bgcolor = colorToUInt(att.value(index));
348
		       MapPars.bgcolor = colorToUInt(att.value(index));
353
		       col.set_bgr(MapPars.bgcolor);
349
		       m.set_background(setColor(MapPars.bgcolor));
354
		       m.set_background(col);
-
 
355
		    }
350
		    }
356
 
351
 
357
		    if ((index = att.index(QString("buffer_size"))) != -1)
352
		    if ((index = att.index(QString("buffer_size"))) != -1)
358
		    {
353
		    {
359
		       MapPars.buf_size = att.value(index).toInt();
354
		       MapPars.buf_size = att.value(index).toInt();
Line 1042... Line 1037...
1042
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of LINESYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1037
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of LINESYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1043
	      return false;
1038
	      return false;
1044
	   }
1039
	   }
1045
 
1040
 
1046
	   stroke st;
1041
	   stroke st;
1047
	   color col;
-
 
1048
	   col.set_bgr(LineSymbolizer->stroke);
1042
	   st.set_color (setColor(LineSymbolizer->stroke));
1049
 
-
 
1050
	   st.set_color (col);
-
 
1051
 
1043
 
1052
	   if (LineSymbolizer->stroke_width != 0.0)
1044
	   if (LineSymbolizer->stroke_width != 0.0)
1053
	      st.set_width (LineSymbolizer->stroke_width);
1045
	      st.set_width (LineSymbolizer->stroke_width);
1054
 
1046
 
1055
	   if (!LineSymbolizer->stroke_linejoin.isEmpty())
1047
	   if (!LineSymbolizer->stroke_linejoin.isEmpty())
Line 1095... Line 1087...
1095
	   {
1087
	   {
1096
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of POLYGONSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1088
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of POLYGONSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1097
	      return false;
1089
	      return false;
1098
	   }
1090
	   }
1099
 
1091
 
1100
	   color col;
-
 
1101
	   col.set_bgr(PolygonSymbolizer->fill);
1092
	   polygon_symbolizer ps(setColor(PolygonSymbolizer->fill));
1102
 
-
 
1103
	   polygon_symbolizer ps(col);
-
 
1104
 
1093
 
1105
	   if (PolygonSymbolizer->fill_opacity > 0.0)
1094
	   if (PolygonSymbolizer->fill_opacity > 0.0)
1106
	      ps.set_opacity(PolygonSymbolizer->fill_opacity);
1095
	      ps.set_opacity(PolygonSymbolizer->fill_opacity);
1107
 
1096
 
1108
	   Rule->rl.append(ps);
1097
	   Rule->rl.append(ps);
Line 1115... Line 1104...
1115
	   {
1104
	   {
1116
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of TEXTSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1105
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of TEXTSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1117
	      return false;
1106
	      return false;
1118
	   }
1107
	   }
1119
 
1108
 
1120
	   color col;
-
 
1121
	   col.set_bgr(TextSymbolizer->fill);
-
 
1122
 
-
 
1123
	   if (TextSymbolizer->name.length() <= 0 || TextSymbolizer->face_name.length() <= 0 || TextSymbolizer->size <= 0)
1109
	   if (TextSymbolizer->name.length() <= 0 || TextSymbolizer->face_name.length() <= 0 || TextSymbolizer->size <= 0)
1124
	      cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Empty TEXTSYMBOLIZER found --> ignoring!" << endl;
1110
	      cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Empty TEXTSYMBOLIZER found --> ignoring!" << endl;
1125
	   else
1111
	   else
1126
	   {
1112
	   {
1127
	      text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, col);
1113
	      text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, setColor(TextSymbolizer->fill));
1128
 
1114
 
1129
	      if (TextSymbolizer->halo_radius != 0.0)
1115
	      if (TextSymbolizer->halo_radius != 0.0)
1130
		 ts.set_halo_radius((unsigned int)TextSymbolizer->halo_radius);
1116
		 ts.set_halo_radius((unsigned int)TextSymbolizer->halo_radius);
1131
 
1117
 
1132
	      if (TextSymbolizer->wrap_width != 0.0)
1118
	      if (TextSymbolizer->wrap_width != 0.0)
Line 1191... Line 1177...
1191
	   {
1177
	   {
1192
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of SHIELDSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1178
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of SHIELDSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1193
	      return false;
1179
	      return false;
1194
	   }
1180
	   }
1195
 
1181
 
1196
	   color col;
-
 
1197
	   col.set_bgr(ShieldSymbolizer->fill);
-
 
1198
	   shield_symbolizer ss(ShieldSymbolizer->name.toAscii().data(),
1182
	   shield_symbolizer ss(ShieldSymbolizer->name.toAscii().data(),
1199
				ShieldSymbolizer->face_name.toAscii().data(),
1183
				ShieldSymbolizer->face_name.toAscii().data(),
1200
				ShieldSymbolizer->size, col,
1184
				ShieldSymbolizer->size, setColor(ShieldSymbolizer->fill),
1201
				findIcon(ShieldSymbolizer->file).toAscii().data(),
1185
				findIcon(ShieldSymbolizer->file).toAscii().data(),
1202
				getTypeText(ShieldSymbolizer->type),
1186
				getTypeText(ShieldSymbolizer->type),
1203
				ShieldSymbolizer->width, ShieldSymbolizer->height);
1187
				ShieldSymbolizer->width, ShieldSymbolizer->height);
1204
 
1188
 
1205
	   if (!ShieldSymbolizer->placement.isEmpty())
1189
	   if (!ShieldSymbolizer->placement.isEmpty())
Line 1495... Line 1479...
1495
{
1479
{
1496
int width, height;
1480
int width, height;
1497
QXmlSimpleReader reader;
1481
QXmlSimpleReader reader;
1498
QString hv0;
1482
QString hv0;
1499
QFile file(XmlPath);
1483
QFile file(XmlPath);
-
 
1484
QDir dir(fontPath);
1500
double plx, ply, prx, pry;
1485
double plx, ply, prx, pry;
1501
 
1486
 
1502
	OutBuf.clear();
-
 
1503
	hv0 = pluginPath;
1487
	hv0 = pluginPath;
1504
 
1488
 
1505
	if (hv0.right(1) != QString("/"))
1489
	if (hv0.right(1) != QString("/"))
1506
	   hv0 += "/";
1490
	   hv0 += "/";
1507
 
1491
 
Line 1509... Line 1493...
1509
	hv0 = fontPath;
1493
	hv0 = fontPath;
1510
 
1494
 
1511
	if (hv0.right(1) != QString("/"))
1495
	if (hv0.right(1) != QString("/"))
1512
	   hv0 += "/";
1496
	   hv0 += "/";
1513
 
1497
 
-
 
1498
	// Load all fonts in directory
-
 
1499
	if (!dir.exists())
-
 
1500
	{
-
 
1501
	   KMessageBox::error(0, i18n("The font directory does not exist! Please select a valid directory with at least one true type font in it!"));
-
 
1502
	   return false;
-
 
1503
	}
-
 
1504
 
-
 
1505
	QStringList filters;
-
 
1506
	filters << "*.ttf";
-
 
1507
	dir.setNameFilters(filters);
-
 
1508
	dir.setFilter(QDir::Readable | QDir::Files);
-
 
1509
	QFileInfoList list = dir.entryInfoList();
-
 
1510
 
-
 
1511
	for (int i = 0; i < list.size(); ++i)
-
 
1512
	{
-
 
1513
	QString f;
-
 
1514
 
-
 
1515
	   QFileInfo fileInfo = list.at(i);
-
 
1516
	   f = hv0 + fileInfo.fileName();
-
 
1517
	   freetype_engine::register_font(f.toAscii().data());
-
 
1518
	}
-
 
1519
 
1514
	hv0 += "DejaVuSans.ttf";
1520
//	hv0 += "DejaVuSans.ttf";	// Default font
1515
	freetype_engine::register_font(hv0.toAscii().data());
1521
//	freetype_engine::register_font(hv0.toAscii().data());
1516
 
1522
 
1517
	width = label->width();
1523
	width = label->width();
1518
	height = label->height();
1524
	height = label->height();
1519
 
1525
 
1520
	m.setWidth(width);
1526
	m.setWidth(width);
1521
	m.setHeight(height);
1527
	m.setHeight(height);
1522
//	load_map(m, XmlPath.toAscii().data());
-
 
1523
 
1528
 
1524
	try
1529
	try
1525
	{
1530
	{
1526
	   if (!ControlSet)	// Initialize the map?
1531
	   if (!ControlSet)	// Initialize the map?
1527
	   {
1532
	   {
1528
	      QXmlInputSource source (&file);
1533
	      QXmlInputSource source (&file);
1529
	      reader.setContentHandler (this);
1534
	      reader.setContentHandler (this);
1530
	      reader.parse (source);
1535
	      reader.parse (source);
1531
	   }
1536
	   }
1532
 
1537
 
1533
	   save_map(m, "/home/andreas/.sportwatcher/spw.xml");
-
 
1534
//	   save_map(m, "/home/andreas/.sportwatcher/spw1.xml");
-
 
1535
	   plx = lx;
1538
	   plx = lx;
1536
	   ply = ly;
1539
	   ply = ly;
1537
	   prx = rx;
1540
	   prx = rx;
1538
	   pry = ry;
1541
	   pry = ry;
1539
	   projection pj(m.srs());
1542
	   projection pj(m.srs());
1540
 
1543
 
1541
	   if (pj.is_geographic())
1544
	   if (!geographic && pj.is_geographic())
1542
	   {
1545
	   {
1543
	      pj.inverse(plx, ply);
1546
	      pj.inverse(plx, ply);
1544
	      pj.inverse(prx, pry);
1547
	      pj.inverse(prx, pry);
1545
cout << "Geographic! Inverse projection." << endl;
-
 
1546
	   }
1548
	   }
-
 
1549
 
1547
	   else
1550
	   if (geographic && pj.is_geographic())
1548
	   {
1551
	   {
1549
//	      pj.forward(plx, ply);
1552
	      pj.forward(plx, ply);
1550
//	      pj.forward(prx, pry);
1553
	      pj.forward(prx, pry);
1551
cout << "NOT geographic!" << endl;
-
 
1552
	   }
1554
	   }
1553
 
1555
 
1554
for (unsigned i = 0; i < m.layerCount(); i++)
-
 
1555
{
-
 
1556
   bool vis = m.getLayer(i).isVisible(m.scale_denominator());
-
 
1557
//   bool vis = m.getLayer(i).isVisible(m.scale());
-
 
1558
   cout << "Layer " << i << ": " << m.getLayer(i).name();
-
 
1559
   cout << ", Visible: " << vis;
-
 
1560
   cout << ", Active: " << m.getLayer(i).isActive();
-
 
1561
   Envelope <double>e(m.getLayer(i).envelope());
-
 
1562
   cout << ", Extent: " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl;
-
 
1563
}
-
 
1564
 
-
 
1565
	   // First we use Mapnik to create the map
1556
	   // First we use Mapnik to create the map
1566
	   m.zoomToBox(Envelope<double>(plx, ply, prx, pry));
1557
	   m.zoomToBox(Envelope<double>(plx, ply, prx, pry));
1567
 
1558
 
1568
Envelope <double>e(m.getCurrentExtent());
1559
	   // Here we render the map to an image buffer
1569
cout << std::setprecision(16) << "Parameter envelope: " << lx << ", " << ly << ", " << rx << ", " << ry << endl;
-
 
1570
cout << std::setprecision(16) << "Converted envelope: " << plx << ", " << ply << ", " << prx << ", " << pry << endl;
-
 
1571
cout << std::setprecision(16) << "Current extent:     " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl;
-
 
1572
Envelope <double>x(m.get_buffered_extent());
-
 
1573
cout << std::setprecision(16) << "Current buf.extent: " << x.minx() << ", " << x.miny() << ", " << x.maxx() << ", " << x.maxy() << endl;
-
 
1574
cout << "SRS: " << m.srs() << endl;
-
 
1575
cout << std::setprecision(16) << "Scale: " << m.scale() << ", scale denominator: " << m.scale_denominator() << endl;
-
 
1576
cout << "width=" << m.getWidth() << ", height=" << m.getHeight() << endl;
-
 
1577
 
-
 
1578
	   Image32 buf(m.getWidth(), m.getHeight());
1560
	   Image32 buf(m.getWidth(), m.getHeight());
1579
	   agg_renderer<Image32> ren(m, buf);
1561
	   agg_renderer<Image32> ren(m, buf);
1580
	   ren.apply();
1562
	   ren.apply();
1581
 
1563
 
1582
	   // Put the image into a Qt object
1564
	   // Put the image into a Qt object
1583
	   QImage image((uchar*)buf.raw_data(), m.getWidth(), m.getHeight(), QImage::Format_ARGB32);
1565
	   QImage image((uchar*)buf.raw_data(), m.getWidth(), m.getHeight(), QImage::Format_ARGB32);
1584
	   label->setPixmap(QPixmap::fromImage(image.rgbSwapped()));
1566
	   label->setPixmap(QPixmap::fromImage(image.rgbSwapped()));
1585
	   // Create a unique file name
-
 
1586
//	   pid = getpid();
-
 
1587
//	   OutBuf.sprintf("/var/tmp/SportWatcher_%d.png", pid);
-
 
1588
//	   save_to_file<ImageData32>(buf.data(), OutBuf.toAscii().data(), "png");
-
 
1589
	}
1567
	}
1590
 
1568
 
1591
	catch (const mapnik::config_error &ex)
1569
	catch (const mapnik::config_error &ex)
1592
	{
1570
	{
1593
	   KMessageBox::error(0, i18n("Configuration error: %1").arg(ex.what()));
1571
	   KMessageBox::error(0, i18n("Configuration error: %1").arg(ex.what()));
Line 1651... Line 1629...
1651
	}
1629
	}
1652
 
1630
 
1653
	return ptf;
1631
	return ptf;
1654
}
1632
}
1655
 
1633
 
-
 
1634
color SRender::setColor(unsigned col)
-
 
1635
{
-
 
1636
color c;
-
 
1637
#if MAPNIK_VERSION == 600
-
 
1638
	c.set_bgr(col);
-
 
1639
#else
-
 
1640
	int r, g, b;
-
 
1641
	b = col / 65536;
-
 
1642
	g = (col - (b * 65536)) / 256;
-
 
1643
	r = col - ((b* 65536) + (g * 256));
-
 
1644
	c.set_red(r);
-
 
1645
	c.set_green(g);
-
 
1646
	c.set_blue(b);
-
 
1647
#endif
-
 
1648
	return c;
-
 
1649
}
-
 
1650
 
1656
RULE *SRender::getLastRule(RULE *first)
1651
RULE *SRender::getLastRule(RULE *first)
1657
{
1652
{
1658
RULE *akt = first;
1653
RULE *akt = first;
1659
 
1654
 
1660
	while (akt)
1655
	while (akt)