1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-27 21:24:47 +01:00

Added missing rendering of lines with image-based pens

This commit is contained in:
Martin Tůma 2024-08-08 08:51:33 +02:00
parent cc20a9cd59
commit 8990f2cfcf
2 changed files with 40 additions and 5 deletions

View File

@ -241,11 +241,13 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
reader.skipCurrentElement(); reader.skipCurrentElement();
} }
void Style::line(QXmlStreamReader &reader, qreal baseStrokeWidth, void Style::line(QXmlStreamReader &reader, const QString &dir, qreal ratio,
const Rule &rule) qreal baseStrokeWidth, const Rule &rule)
{ {
PathRender ri(rule, _paths.size() + _circles.size() + _hillShading.isValid()); PathRender ri(rule, _paths.size() + _circles.size() + _hillShading.isValid());
const QXmlStreamAttributes &attr = reader.attributes(); const QXmlStreamAttributes &attr = reader.attributes();
QString file;
int height = 0, width = 0, percent = 100;
bool ok; bool ok;
ri._brush = Qt::NoBrush; ri._brush = Qt::NoBrush;
@ -309,6 +311,32 @@ void Style::line(QXmlStreamReader &reader, qreal baseStrokeWidth,
} }
} }
if (attr.hasAttribute("src"))
file = resourcePath(attr.value("src").toString(), dir);
if (attr.hasAttribute("symbol-height")) {
height = attr.value("symbol-height").toInt(&ok);
if (!ok || height < 0) {
reader.raiseError("invalid symbol-height value");
return;
}
}
if (attr.hasAttribute("symbol-width")) {
width = attr.value("symbol-width").toInt(&ok);
if (!ok || width < 0) {
reader.raiseError("invalid symbol-width value");
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())
ri._img = image(file, width, height, percent, ratio);
if (ri.rule()._type == Rule::AnyType || ri.rule()._type == Rule::WayType) if (ri.rule()._type == Rule::AnyType || ri.rule()._type == Rule::WayType)
_paths.append(ri); _paths.append(ri);
@ -549,7 +577,7 @@ void Style::rule(QXmlStreamReader &reader, const QString &dir,
else if (reader.name() == QLatin1String("area")) else if (reader.name() == QLatin1String("area"))
area(reader, dir, ratio, baseStrokeWidth, r); area(reader, dir, ratio, baseStrokeWidth, r);
else if (reader.name() == QLatin1String("line")) else if (reader.name() == QLatin1String("line"))
line(reader, baseStrokeWidth, r); line(reader, dir, ratio, baseStrokeWidth, r);
else if (reader.name() == QLatin1String("circle")) else if (reader.name() == QLatin1String("circle"))
circle(reader, baseStrokeWidth, r); circle(reader, baseStrokeWidth, r);
else if (reader.name() == QLatin1String("pathText")) { else if (reader.name() == QLatin1String("pathText")) {
@ -852,7 +880,12 @@ QList<const Style::Symbol*> Style::areaSymbols(int zoom) const
QPen Style::PathRender::pen(int zoom) const QPen Style::PathRender::pen(int zoom) const
{ {
if (_strokeColor.isValid()) { if (!_img.isNull()) {
qreal width = (_scale > None && zoom >= 12)
? pow(1.5, zoom - 12) * _strokeWidth : _strokeWidth;
return QPen(QBrush(_img), width, Qt::SolidLine, _strokeCap,
_strokeJoin);
} else if (_strokeColor.isValid()) {
qreal width = (_scale > None && zoom >= 12) qreal width = (_scale > None && zoom >= 12)
? pow(1.5, zoom - 12) * _strokeWidth : _strokeWidth; ? pow(1.5, zoom - 12) * _strokeWidth : _strokeWidth;
QPen p(QBrush(_strokeColor), width, Qt::SolidLine, _strokeCap, QPen p(QBrush(_strokeColor), width, Qt::SolidLine, _strokeCap,

View File

@ -173,6 +173,7 @@ public:
QVector<qreal> _strokeDasharray; QVector<qreal> _strokeDasharray;
Qt::PenCapStyle _strokeCap; Qt::PenCapStyle _strokeCap;
Qt::PenJoinStyle _strokeJoin; Qt::PenJoinStyle _strokeJoin;
QImage _img;
QBrush _brush; QBrush _brush;
bool _area, _curve; bool _area, _curve;
Scale _scale; Scale _scale;
@ -320,7 +321,8 @@ private:
const Rule &parent); const Rule &parent);
void area(QXmlStreamReader &reader, const QString &dir, qreal ratio, void area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
qreal baseStrokeWidth, const Rule &rule); qreal baseStrokeWidth, const Rule &rule);
void line(QXmlStreamReader &reader, qreal baseStrokeWidth, const Rule &rule); void line(QXmlStreamReader &reader, const QString &dir, qreal ratio,
qreal baseStrokeWidth, const Rule &rule);
void circle(QXmlStreamReader &reader, qreal baseStrokeWidth, void circle(QXmlStreamReader &reader, qreal baseStrokeWidth,
const Rule &rule); const Rule &rule);
void hillshading(QXmlStreamReader &reader, const QSet<QString> &cats); void hillshading(QXmlStreamReader &reader, const QSet<QString> &cats);