From 8a72b20af8d3c9d307ac2a31e364be7f3e41f78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Fri, 19 May 2023 01:30:54 +0200 Subject: [PATCH] Added support for all paths scaling modes --- src/map/mapsforge/style.cpp | 22 ++++++++++++++++++++-- src/map/mapsforge/style.h | 6 +++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/map/mapsforge/style.cpp b/src/map/mapsforge/style.cpp index fe43fe7b..32b18538 100644 --- a/src/map/mapsforge/style.cpp +++ b/src/map/mapsforge/style.cpp @@ -154,6 +154,13 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio, return; } } + if (attr.hasAttribute("scale")) { + QString scale(attr.value("scale").toString()); + if (scale == "all") + ri._scale = PathRender::Scale::All; + else if (scale == "none") + ri._scale = PathRender::Scale::None; + } if (attr.hasAttribute("src")) file = resourcePath(attr.value("src").toString(), dir); if (attr.hasAttribute("symbol-height")) { @@ -226,6 +233,13 @@ void Style::line(QXmlStreamReader &reader, const Rule &rule) else if (join == "bevel") ri._strokeJoin = Qt::BevelJoin; } + if (attr.hasAttribute("scale")) { + QString scale(attr.value("scale").toString()); + if (scale == "all") + ri._scale = PathRender::Scale::All; + else if (scale == "none") + ri._scale = PathRender::Scale::None; + } if (attr.hasAttribute("curve")) { QString curve(attr.value("curve").toString()); if (curve == "cubic") @@ -656,14 +670,18 @@ QList Style::areaSymbols(int zoom) const QPen Style::PathRender::pen(int zoom) const { if (_strokeColor.isValid()) { - qreal width = (zoom >= 12) + qreal width = (_scale > None && zoom >= 12) ? pow(1.5, zoom - 12) * _strokeWidth : _strokeWidth; QPen p(QBrush(_strokeColor), width, Qt::SolidLine, _strokeCap, _strokeJoin); if (!_strokeDasharray.isEmpty()) { QVectorpattern(_strokeDasharray); - for (int i = 0; i < _strokeDasharray.size(); i++) + for (int i = 0; i < _strokeDasharray.size(); i++) { + if (_scale > Stroke && zoom >= 12) + pattern[i] = (pow(1.5, zoom - 12) * pattern[i]); + // QPainter pattern is specified in units of the pens width! pattern[i] /= width; + } p.setDashPattern(pattern); } return p; diff --git a/src/map/mapsforge/style.h b/src/map/mapsforge/style.h index 93bc8402..69b11092 100644 --- a/src/map/mapsforge/style.h +++ b/src/map/mapsforge/style.h @@ -136,7 +136,8 @@ public: public: PathRender(const Rule &rule, int zOrder) : Render(rule), _zOrder(zOrder), _strokeWidth(0), _strokeCap(Qt::RoundCap), - _strokeJoin(Qt::RoundJoin), _area(false), _curve(false) {} + _strokeJoin(Qt::RoundJoin), _area(false), _curve(false), + _scale(Stroke) {} int zOrder() const {return _zOrder;} QPen pen(int zoom) const; @@ -147,6 +148,8 @@ public: private: friend class Style; + enum Scale {None, Stroke, All}; + int _zOrder; QColor _strokeColor; qreal _strokeWidth; @@ -155,6 +158,7 @@ public: Qt::PenJoinStyle _strokeJoin; QBrush _brush; bool _area, _curve; + Scale _scale; }; class CircleRender : public Render