From f7f680b93ec0acb1fd1dd35e2393b5ab13e955b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 6 Feb 2024 22:37:01 +0100 Subject: [PATCH] Fixed multiple HiDPI map render issues --- src/map/bitmapline.cpp | 5 ++++- src/map/textpathitem.cpp | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/map/bitmapline.cpp b/src/map/bitmapline.cpp index ab2189ee..f37f5e3f 100644 --- a/src/map/bitmapline.cpp +++ b/src/map/bitmapline.cpp @@ -7,7 +7,8 @@ static QImage img2line(const QImage &img, int width) { Q_ASSERT(img.format() == QImage::Format_ARGB32_Premultiplied); - QImage res(width, img.height(), QImage::Format_ARGB32_Premultiplied); + QImage res(width * img.devicePixelRatio(), img.height(), + QImage::Format_ARGB32_Premultiplied); const int srcBpl = img.bytesPerLine(); const int dstBpl = res.bytesPerLine(); const uchar *srcBits = img.bits(); @@ -21,6 +22,8 @@ static QImage img2line(const QImage &img, int width) memcpy(dstLine, srcLine, qMin(j, srcBpl)); } + res.setDevicePixelRatio(img.devicePixelRatio()); + return res; } diff --git a/src/map/textpathitem.cpp b/src/map/textpathitem.cpp index c568963e..0062d12a 100644 --- a/src/map/textpathitem.cpp +++ b/src/map/textpathitem.cpp @@ -294,15 +294,16 @@ void TextPathItem::init(const T &line, const QRect &tileRect) if (label && _img) { cw = _font->pixelSize() * CHAR_RATIO; mw = _font->pixelSize() / 2.0; - textWidth = _text->size() * cw + _img->width() + PADDING; + textWidth = _text->size() * cw + + (_img->width() / _img->devicePixelRatioF()) + PADDING; } else if (label) { cw = _font->pixelSize() * CHAR_RATIO; mw = _font->pixelSize() / 2.0; textWidth = _text->size() * cw; } else { - cw = _img->width(); - mw = _img->height() / 2.0; - textWidth = _img->width(); + cw = _img->width() / _img->devicePixelRatioF(); + mw = _img->height() / _img->devicePixelRatioF() / 2.0; + textWidth = _img->width() / _img->devicePixelRatioF(); } _path = textPath(line, textWidth, cw, tileRect.adjusted(mw, mw, -mw, -mw)); @@ -358,7 +359,8 @@ void TextPathItem::paint(QPainter *painter) const if (_text && _font) { QFontMetrics fm(*_font); int textWidth = fm.boundingRect(*_text).width(); - int imgWidth = _img ? _img->width() + PADDING : 0; + int imgWidth = _img + ? (_img->width() / _img->devicePixelRatioF()) + PADDING : 0; qreal imgPercent = imgWidth / _path.length(); qreal factor = textWidth / qMax(_path.length(), (qreal)(textWidth)); qreal percent = ((1.0 - factor) + imgPercent) / 2.0;