1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-04-21 12:49:10 +02:00

Compare commits

..

No commits in common. "5ddd63e69702b407868d81cc041642f909682ca0" and "1233d20a215f681a72a8ce6a36c858eb29e3b07d" have entirely different histories.

9 changed files with 64 additions and 111 deletions

View File

@ -23,21 +23,17 @@ using namespace Mapsforge;
static void copyPaths(const RectC &rect, const QList<MapData::Path> *src, static void copyPaths(const RectC &rect, const QList<MapData::Path> *src,
QList<MapData::Path> *dst) QList<MapData::Path> *dst)
{ {
for (int i = 0; i < src->size(); i++) { for (int i = 0; i < src->size(); i++)
const MapData::Path &path = src->at(i); if (rect.intersects(src->at(i).poly.boundingRect()))
if (rect.intersects(path.poly.boundingRect())) dst->append(src->at(i));
dst->append(path);
}
} }
static void copyPoints(const RectC &rect, const QList<MapData::Point> *src, static void copyPoints(const RectC &rect, const QList<MapData::Point> *src,
QList<MapData::Point> *dst) QList<MapData::Point> *dst)
{ {
for (int i = 0; i < src->size(); i++) { for (int i = 0; i < src->size(); i++)
const MapData::Point &point = src->at(i); if (rect.contains(src->at(i).coordinates))
if (rect.contains(point.coordinates)) dst->append(src->at(i));
dst->append(point);
}
} }
static double distance(const Coordinates &c1, const Coordinates &c2) static double distance(const Coordinates &c1, const Coordinates &c2)
@ -544,20 +540,19 @@ void MapData::points(const VectorTile *tile, const RectC &rect, int zoom,
_pointLock.unlock(); _pointLock.unlock();
} }
void MapData::paths(const RectC &searchRect, const RectC &boundsRect, int zoom, void MapData::paths(const RectC &rect, int zoom, QList<Path> *list)
QList<Path> *list)
{ {
if (!searchRect.isValid()) if (!rect.isValid())
return; return;
int l(level(zoom)); int l(level(zoom));
PathCTX ctx(this, boundsRect, zoom, list); PathCTX ctx(this, rect, zoom, list);
double min[2], max[2]; double min[2], max[2];
min[0] = searchRect.left(); min[0] = rect.left();
min[1] = searchRect.bottom(); min[1] = rect.bottom();
max[0] = searchRect.right(); max[0] = rect.right();
max[1] = searchRect.top(); max[1] = rect.top();
_tiles.at(l)->Search(min, max, pathCb, &ctx); _tiles.at(l)->Search(min, max, pathCb, &ctx);
} }

View File

@ -62,8 +62,7 @@ public:
int tileSize() const {return _tileSize;} int tileSize() const {return _tileSize;}
void points(const RectC &rect, int zoom, QList<Point> *list); void points(const RectC &rect, int zoom, QList<Point> *list);
void paths(const RectC &searchRect, const RectC &boundsRect, int zoom, void paths(const RectC &rect, int zoom, QList<Path> *set);
QList<Path> *set);
unsigned tagId(const QByteArray &name) const {return _keys.value(name);} unsigned tagId(const QByteArray &name) const {return _keys.value(name);}
void load(); void load();

View File

@ -8,8 +8,6 @@
using namespace Mapsforge; using namespace Mapsforge;
#define TEXT_EXTENT 160 #define TEXT_EXTENT 160
#define PATHS_EXTENT 20
#define SEARCH_EXTENT -0.5
static double limit = cos(deg2rad(170)); static double limit = cos(deg2rad(170));
@ -252,26 +250,15 @@ void RasterTile::processLineLabels(const QVector<PainterPath> &paths,
const QFont *font = ti ? &ti->font() : 0; const QFont *font = ti ? &ti->font() : 0;
const QColor *color = ti ? &ti->fillColor() : 0; const QColor *color = ti ? &ti->fillColor() : 0;
const QColor *hColor = ti ? haloColor(ti) : 0; const QColor *hColor = ti ? haloColor(ti) : 0;
bool rotate = si ? si->rotate() : false;
PathItem *item = new PathItem(path.pp, lbl, img, _rect, font, color, PathItem *item = new PathItem(path.pp, lbl, img, _rect, font, color,
hColor, rotate); hColor);
if (item->isValid() && !item->collides(textItems)) { if (item->isValid() && !item->collides(textItems)) {
textItems.append(item); textItems.append(item);
if (limit) if (limit)
set.insert(*lbl); set.insert(*lbl);
} else { } else
delete item; delete item;
if (img && lbl) {
PathItem *item = new PathItem(path.pp, 0, img, _rect, 0, 0, 0,
rotate);
if (item->isValid() && !item->collides(textItems))
textItems.append(item);
else
delete item;
}
}
} }
} }
@ -395,7 +382,6 @@ void RasterTile::drawPaths(QPainter *painter, const QList<MapData::Path> &paths,
painter->setPen(ri->pen(_zoom)); painter->setPen(ri->pen(_zoom));
painter->setBrush(ri->brush()); painter->setBrush(ri->brush());
if (dy != 0) if (dy != 0)
painter->drawPath(parallelPath(path->pp, dy)); painter->drawPath(parallelPath(path->pp, dy));
else else
@ -416,18 +402,14 @@ void RasterTile::fetchData(QList<MapData::Path> &paths,
{ {
QPoint ttl(_rect.topLeft()); QPoint ttl(_rect.topLeft());
QRectF pathRect(QPointF(ttl.x() - PATHS_EXTENT, ttl.y() - PATHS_EXTENT), /* Add a "sub-pixel" margin to assure the tile areas do not
QPointF(ttl.x() + _rect.width() + PATHS_EXTENT, ttl.y() + _rect.height() overlap on the border lines. This prevents areas overlap
+ PATHS_EXTENT)); artifacts at least when using the EPSG:3857 projection. */
QRectF searchRect(QPointF(ttl.x() - SEARCH_EXTENT, ttl.y() - SEARCH_EXTENT), QRectF pathRect(QPointF(ttl.x() + 0.5, ttl.y() + 0.5),
QPointF(ttl.x() + _rect.width() + SEARCH_EXTENT, ttl.y() + _rect.height() QPointF(ttl.x() + _rect.width() - 0.5, ttl.y() + _rect.height() - 0.5));
+ SEARCH_EXTENT));
RectD pathRectD(_transform.img2proj(pathRect.topLeft()), RectD pathRectD(_transform.img2proj(pathRect.topLeft()),
_transform.img2proj(pathRect.bottomRight())); _transform.img2proj(pathRect.bottomRight()));
RectD searchRectD(_transform.img2proj(searchRect.topLeft()), _data->paths(pathRectD.toRectC(_proj, 20), _zoom, &paths);
_transform.img2proj(searchRect.bottomRight()));
_data->paths(searchRectD.toRectC(_proj, 20), pathRectD.toRectC(_proj, 20),
_zoom, &paths);
QRectF pointRect(QPointF(ttl.x() - TEXT_EXTENT, ttl.y() - TEXT_EXTENT), QRectF pointRect(QPointF(ttl.x() - TEXT_EXTENT, ttl.y() - TEXT_EXTENT),
QPointF(ttl.x() + _rect.width() + TEXT_EXTENT, ttl.y() + _rect.height() QPointF(ttl.x() + _rect.width() + TEXT_EXTENT, ttl.y() + _rect.height()

View File

@ -138,9 +138,9 @@ private:
public: public:
PathItem(const QPainterPath &line, const QByteArray *label, PathItem(const QPainterPath &line, const QByteArray *label,
const QImage *img, const QRect &tileRect, const QFont *font, const QImage *img, const QRect &tileRect, const QFont *font,
const QColor *color, const QColor *haloColor, bool rotate) const QColor *color, const QColor *haloColor) : TextPathItem(line,
: TextPathItem(line, label ? new QString(*label) : 0, tileRect, font, label ? new QString(*label) : 0, tileRect, font, color, haloColor,
color, haloColor, img, rotate) {} img) {}
~PathItem() {delete _text;} ~PathItem() {delete _text;}
}; };

View File

@ -17,26 +17,18 @@ static QString resourcePath(const QString &src, const QString &dir)
return dir + "/" + url.toLocalFile(); return dir + "/" + url.toLocalFile();
} }
static QImage image(const QString &path, int width, int height, int percent, static QImage image(const QString &path, int width, int height, qreal ratio)
qreal ratio)
{ {
QImageReader ir(path, "svg"); QImageReader ir(path, "svg");
if (ir.canRead()) { if (ir.canRead()) {
QSize s(ir.size());
if (!height && !width) { if (!height && !width) {
height = 20; height = 20;
width = 20; width = 20;
} else if (!width) { } else if (!width) {
width = s.height() / (s.height() / (double)height); width = ir.size().height() / (ir.size().height() / (double)height);
} else if (!height) } else if (!height)
height = s.width() / (s.width() / (double)width); height = ir.size().width() / (ir.size().width() / (double)width);
if (percent != 100) {
width *= percent / 100.0;
height *= percent / 100.0;
}
ir.setScaledSize(QSize(width * ratio, height * ratio)); ir.setScaledSize(QSize(width * ratio, height * ratio));
QImage img(ir.read()); QImage img(ir.read());
@ -183,7 +175,7 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
const QXmlStreamAttributes &attr = reader.attributes(); const QXmlStreamAttributes &attr = reader.attributes();
QString file; QString file;
QColor fillColor; QColor fillColor;
int height = 0, width = 0, percent = 100; int height = 0, width = 0;
bool ok; bool ok;
ri._area = true; ri._area = true;
@ -221,16 +213,9 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
return; return;
} }
} }
if (attr.hasAttribute("symbol-percent")) {
percent = attr.value("symbol-percent").toInt(&ok);
if (!ok || percent < 0) {
reader.raiseError("invalid symbol-percent value");
return;
}
}
if (!file.isNull()) if (!file.isNull())
ri._brush = QBrush(image(file, width, height, percent, ratio)); ri._brush = QBrush(image(file, width, height, ratio));
else if (fillColor.isValid()) else if (fillColor.isValid())
ri._brush = QBrush(fillColor); ri._brush = QBrush(fillColor);
@ -246,8 +231,6 @@ void Style::line(QXmlStreamReader &reader, const Rule &rule)
const QXmlStreamAttributes &attr = reader.attributes(); const QXmlStreamAttributes &attr = reader.attributes();
bool ok; bool ok;
ri._brush = Qt::NoBrush;
if (attr.hasAttribute("stroke")) if (attr.hasAttribute("stroke"))
ri._strokeColor = QColor(attr.value("stroke").toString()); ri._strokeColor = QColor(attr.value("stroke").toString());
if (attr.hasAttribute("stroke-width")) { if (attr.hasAttribute("stroke-width")) {
@ -441,7 +424,7 @@ void Style::symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
Symbol ri(rule); Symbol ri(rule);
const QXmlStreamAttributes &attr = reader.attributes(); const QXmlStreamAttributes &attr = reader.attributes();
QString file; QString file;
int height = 0, width = 0, percent = 100; int height = 0, width = 0;
bool ok; bool ok;
if (attr.hasAttribute("src")) if (attr.hasAttribute("src"))
@ -464,13 +447,6 @@ void Style::symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
return; return;
} }
} }
if (attr.hasAttribute("symbol-percent")) {
percent = attr.value("symbol-percent").toInt(&ok);
if (!ok || percent < 0) {
reader.raiseError("invalid symbol-percent value");
return;
}
}
if (attr.hasAttribute("priority")) { if (attr.hasAttribute("priority")) {
ri._priority = attr.value("priority").toInt(&ok); ri._priority = attr.value("priority").toInt(&ok);
if (!ok) { if (!ok) {
@ -478,12 +454,8 @@ void Style::symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
return; return;
} }
} }
if (attr.hasAttribute("rotate")) {
if (attr.value("rotate").toString() == "false")
ri._rotate = false;
}
ri._img = image(file, width, height, percent, ratio); ri._img = image(file, width, height, ratio);
list.append(ri); list.append(ri);

View File

@ -212,17 +212,15 @@ public:
class Symbol : public Render class Symbol : public Render
{ {
public: public:
Symbol(const Rule &rule) : Render(rule), _priority(0), _rotate(true) {} Symbol(const Rule &rule) : Render(rule), _priority(0) {}
const QImage &img() const {return _img;} const QImage &img() const {return _img;}
int priority() const {return _priority;} int priority() const {return _priority;}
bool rotate() const {return _rotate;}
private: private:
friend class Style; friend class Style;
int _priority; int _priority;
bool _rotate;
QImage _img; QImage _img;
}; };
@ -284,7 +282,8 @@ private:
QList<PathRender> _paths; QList<PathRender> _paths;
QList<CircleRender> _circles; QList<CircleRender> _circles;
QList<TextRender> _pathLabels, _pointLabels, _areaLabels; QList<TextRender> _pathLabels, _pointLabels, _areaLabels;
QList<Symbol> _symbols, _lineSymbols; QList<Symbol> _symbols;
QList<Symbol> _lineSymbols;
bool loadXml(const QString &path, const MapData &data, qreal ratio); bool loadXml(const QString &path, const MapData &data, qreal ratio);
void rendertheme(QXmlStreamReader &reader, const QString &dir, void rendertheme(QXmlStreamReader &reader, const QString &dir,

View File

@ -266,15 +266,15 @@ void TextPathItem::init(const T &line, const QRect &tileRect)
if (_text && _img) { if (_text && _img) {
cw = _font->pixelSize() * CHAR_RATIO; cw = _font->pixelSize() * CHAR_RATIO;
mw = _font->pixelSize() / 2.0; mw = _font->pixelSize() / 2;
textWidth = _text->size() * cw + _img->width() + PADDING; textWidth = _text->size() * cw + _img->width() + PADDING;
} else if (_text) { } else if (_text) {
cw = _font->pixelSize() * CHAR_RATIO; cw = _font->pixelSize() * CHAR_RATIO;
mw = _font->pixelSize() / 2.0; mw = _font->pixelSize() / 2;
textWidth = _text->size() * cw; textWidth = _text->size() * cw;
} else { } else {
cw = _img->width(); cw = _img->width();
mw = _img->height() / 2.0; mw = _img->height() / 2;
textWidth = _img->width(); textWidth = _img->width();
} }
@ -296,18 +296,16 @@ void TextPathItem::init(const T &line, const QRect &tileRect)
TextPathItem::TextPathItem(const QPolygonF &line, const QString *label, TextPathItem::TextPathItem(const QPolygonF &line, const QString *label,
const QRect &tileRect, const QFont *font, const QColor *color, const QRect &tileRect, const QFont *font, const QColor *color,
const QColor *haloColor, const QImage *img, bool rotate) const QColor *haloColor, const QImage *img) : TextItem(label), _font(font),
: TextItem(label), _font(font), _color(color), _haloColor(haloColor), _color(color), _haloColor(haloColor), _img(img), _reverse(false)
_img(img), _rotate(rotate), _reverse(false)
{ {
init(line, tileRect); init(line, tileRect);
} }
TextPathItem::TextPathItem(const QPainterPath &line, const QString *label, TextPathItem::TextPathItem(const QPainterPath &line, const QString *label,
const QRect &tileRect, const QFont *font, const QColor *color, const QRect &tileRect, const QFont *font, const QColor *color,
const QColor *haloColor, const QImage *img, bool rotate) const QColor *haloColor, const QImage *img) : TextItem(label), _font(font),
: TextItem(label), _font(font), _color(color), _haloColor(haloColor), _color(color), _haloColor(haloColor), _img(img), _reverse(false)
_img(img), _rotate(rotate), _reverse(false)
{ {
init(line, tileRect); init(line, tileRect);
} }
@ -320,11 +318,13 @@ void TextPathItem::paint(QPainter *painter) const
painter->save(); painter->save();
painter->translate(QPointF(_path.elementAt(0).x, _path.elementAt(0).y)); painter->translate(QPointF(_path.elementAt(0).x, _path.elementAt(0).y));
painter->rotate(360 - _path.angleAtPercent(0)); painter->rotate(360 - _path.angleAtPercent(0));
if (_reverse && _rotate) {
painter->rotate(180); if (_reverse)
painter->translate(-s.width(), 0); painter->drawImage(QPointF(0, -s.height()/2),
} _img->transformed(QTransform().rotate(180.0)));
else
painter->drawImage(QPointF(0, -s.height()/2), *_img); painter->drawImage(QPointF(0, -s.height()/2), *_img);
painter->restore(); painter->restore();
} }

View File

@ -1,21 +1,20 @@
#ifndef TEXTPATHITEM_H #ifndef TEXTPATHITEM_H
#define TEXTPATHITEM_H #define TEXTPATHITEM_H
#include <QVector>
#include <QPainterPath>
#include "textitem.h" #include "textitem.h"
class QFont;
class QImage;
class QColor;
class TextPathItem : public TextItem class TextPathItem : public TextItem
{ {
public: public:
TextPathItem() : TextItem(0), _font(0), _color(0) {}
TextPathItem(const QPolygonF &line, const QString *label, TextPathItem(const QPolygonF &line, const QString *label,
const QRect &tileRect, const QFont *font, const QColor *color, const QRect &tileRect, const QFont *font, const QColor *color,
const QColor *haloColor, const QImage *img = 0, bool rotate = true); const QColor *haloColor, const QImage *img = 0);
TextPathItem(const QPainterPath &line, const QString *label, TextPathItem(const QPainterPath &line, const QString *label,
const QRect &tileRect, const QFont *font, const QColor *color, const QRect &tileRect, const QFont *font, const QColor *color,
const QColor *haloColor, const QImage *img = 0, bool rotate = true); const QColor *haloColor, const QImage *img = 0);
bool isValid() const {return !_path.isEmpty();} bool isValid() const {return !_path.isEmpty();}
@ -27,11 +26,13 @@ private:
template<class T> void init(const T &line, const QRect &tileRect); template<class T> void init(const T &line, const QRect &tileRect);
const QFont *_font; const QFont *_font;
const QColor *_color, *_haloColor; const QColor *_color;
const QColor *_haloColor;
const QImage *_img; const QImage *_img;
QPainterPath _path;
QRectF _rect; QRectF _rect;
QPainterPath _path, _shape; QPainterPath _shape;
bool _rotate, _reverse; bool _reverse;
}; };
#endif // TEXTPATHITEM_H #endif // TEXTPATHITEM_H

View File

@ -1,8 +1,12 @@
#ifndef TEXTPOINTITEM_H #ifndef TEXTPOINTITEM_H
#define TEXTPOINTITEM_H #define TEXTPOINTITEM_H
#include <QRect>
#include <QString>
#include <QVector>
#include "textitem.h" #include "textitem.h"
class QPainter;
class QFont; class QFont;
class QImage; class QImage;
class QColor; class QColor;
@ -10,6 +14,7 @@ class QColor;
class TextPointItem : public TextItem class TextPointItem : public TextItem
{ {
public: public:
TextPointItem() : TextItem(0), _font(0), _img(0) {}
TextPointItem(const QPoint &point, const QString *text, const QFont *font, TextPointItem(const QPoint &point, const QString *text, const QFont *font,
const QImage *img, const QColor *color, const QColor *haloColor, const QImage *img, const QColor *color, const QColor *haloColor,
const QColor *bgColor = 0, int padding = 0, double rotate = NAN); const QColor *bgColor = 0, int padding = 0, double rotate = NAN);