1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-28 12:09:15 +02:00

Improved text layout/rendering on IMG maps

This commit is contained in:
2019-06-07 20:33:08 +02:00
parent f2d32b30d3
commit 06e1685f85
11 changed files with 144 additions and 85 deletions

View File

@ -75,10 +75,11 @@ void Style::defaultPolygonStyle()
<< TYPE(0x42) << TYPE(0x43) << TYPE(0x44) << TYPE(0x45) << TYPE(0x46)
<< TYPE(0x47) << TYPE(0x48) << TYPE(0x49) << TYPE(0x4c) << TYPE(0x4d)
<< TYPE(0x4e) << TYPE(0x4f) << TYPE(0x50) << TYPE(0x51) << TYPE(0x52)
<< TYPE(0x14) << TYPE(0x15) << TYPE(0x1e) << TYPE(0x1f) << TYPE(0x04)
<< TYPE(0x05) << TYPE(0x06) << TYPE(0x07) << TYPE(0x08) << TYPE(0x09)
<< TYPE(0x0a) << TYPE(0x0b) << TYPE(0x0c) << TYPE(0x0d) << TYPE(0x0e)
<< TYPE(0x0f) << TYPE(0x10) << TYPE(0x11) << TYPE(0x12) << TYPE(0x13);
<< TYPE(0x14) << TYPE(0x15) << TYPE(0x16) << TYPE(0x1e) << TYPE(0x1f)
<< TYPE(0x04) << TYPE(0x05) << TYPE(0x06) << TYPE(0x07) << TYPE(0x08)
<< TYPE(0x09) << TYPE(0x0a) << TYPE(0x0b) << TYPE(0x0c) << TYPE(0x0d)
<< TYPE(0x0e) << TYPE(0x0f) << TYPE(0x10) << TYPE(0x11) << TYPE(0x12)
<< TYPE(0x13);
}
void Style::defaultLineStyle()
@ -962,6 +963,11 @@ bool Style::isSpot(quint32 type)
return (type == TYPE(0x62) || type == TYPE(0x63));
}
bool Style::isSummit(quint32 type)
{
return (type == 0x6616);
}
Style::POIClass Style::poiClass(quint32 type)
{
if ((type >= 0x2a00 && type < 0x2b00) || type == 0x2c0a || type == 0x2d02)

View File

@ -105,6 +105,7 @@ public:
static bool isContourLine(quint32 type);
static bool isSpot(quint32 type);
static bool isSummit(quint32 type);
static POIClass poiClass(quint32 type);
private:

17
src/map/IMG/textitem.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "textitem.h"
bool TextItem::collides(const QList<TextItem*> &list) const
{
QRectF r1(boundingRect());
for (int i = 0; i < list.size(); i++) {
const TextItem* other = list.at(i);
QRectF r2(other->boundingRect());
if (!(r1.isEmpty() || r2.isEmpty() || !r1.intersects(r2)))
if (other->shape().intersects(shape()))
return true;
}
return false;
}

22
src/map/IMG/textitem.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef TEXTITEM_H
#define TEXTITEM_H
#include <QList>
#include <QRectF>
#include <QPainterPath>
class QPainter;
class TextItem
{
public:
virtual ~TextItem() {}
virtual QPainterPath shape() const = 0;
virtual QRectF boundingRect() const = 0;
virtual void paint(QPainter *painter) const = 0;
bool collides(const QList<TextItem*> &list) const;
};
#endif // TEXTITEM_H

View File

@ -154,23 +154,6 @@ TextPathItem::TextPathItem(const QPolygonF &line, const QString *label,
_rect = _shape.boundingRect();
}
bool TextPathItem::collides(const QVector<TextPathItem> &list) const
{
if (_rect.isEmpty())
return false;
for (int i = 0; i < list.size(); i++) {
const TextPathItem &other = list.at(i);
if (other._rect.isEmpty() || !_rect.intersects(other._rect))
continue;
if (other._shape.intersects(_shape))
return true;
}
return false;
}
void TextPathItem::paint(QPainter *painter) const
{
QFontMetrics fm(*_font);

View File

@ -3,9 +3,9 @@
#include <QVector>
#include <QPainterPath>
#include "img.h"
#include "textitem.h"
class TextPathItem
class TextPathItem : public TextItem
{
public:
TextPathItem() : _text(0), _font(0), _color(0) {}
@ -13,7 +13,9 @@ public:
const QRect &tileRect, const QFont *font, const QColor *color);
bool isValid() const {return !_path.isEmpty();}
bool collides(const QVector<TextPathItem> &list) const;
QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _rect;}
void paint(QPainter *painter) const;
private:

View File

@ -28,15 +28,7 @@ TextPointItem::TextPointItem(const QPoint &point, const QString *text,
_textRect.moveCenter(point);
_rect = _textRect | iconRect;
}
bool TextPointItem::collides(const QVector<TextPointItem> &list) const
{
for (int i = 0; i < list.size(); i++)
if (list.at(i)._rect.intersects(_rect))
return true;
return false;
_shape.addRect(_rect);
}
void TextPointItem::paint(QPainter *painter) const

View File

@ -4,20 +4,24 @@
#include <QRect>
#include <QString>
#include <QVector>
#include "textitem.h"
class QPainter;
class QFont;
class QImage;
class QColor;
class TextPointItem
class TextPointItem : public TextItem
{
public:
TextPointItem() : _text(0), _font(0), _img(0) {}
TextPointItem(const QPoint &point, const QString *text, const QFont *font,
const QImage *img, const QColor *color);
bool collides(const QVector<TextPointItem> &list) const;
bool isValid() const {return !_rect.isEmpty();}
QRectF boundingRect() const {return _rect;}
QPainterPath shape() const {return _shape;}
void paint(QPainter *painter) const;
private:
@ -26,6 +30,7 @@ private:
const QImage *_img;
const QColor *_color;
QRect _rect, _textRect;
QPainterPath _shape;
};
#endif // TEXTPOINTITEM_H