From 50df8ad877a51d479f602c3a519382cda02009c4 Mon Sep 17 00:00:00 2001 From: David Hurka Date: Fri, 31 Jul 2020 00:04:21 +0000 Subject: [PATCH] Fix misplacement of some non-PDF annotations on hiDPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PagePainter::drawShapeOnImage() and drawEllipseOnImage() didn’t respect the image’s device pixel ratio. Steps to reproduce: * Set your screen scale to e. g. 1.25. * Open e. g. a .txt document. * Draw e. g. an arrow annotation or a text markup annotation. --- ui/pagepainter.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp index 91140d840..4ee883e68 100644 --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -963,10 +963,9 @@ void PagePainter::drawShapeOnImage(QImage &image, const NormalizedPath &normPath if (pointsNumber < 2) return; - int imageWidth = image.width(); - int imageHeight = image.height(); - double fImageWidth = (double)imageWidth; - double fImageHeight = (double)imageHeight; + const double dpr = image.devicePixelRatio(); + const double fImageWidth = image.width() / dpr; + const double fImageHeight = image.height() / dpr; // stroke outline double penWidth = (double)pen.width() * penWidthMultiplier; @@ -1009,8 +1008,9 @@ void PagePainter::drawShapeOnImage(QImage &image, const NormalizedPath &normPath void PagePainter::drawEllipseOnImage(QImage &image, const NormalizedPath &rect, const QPen &pen, const QBrush &brush, double penWidthMultiplier, RasterOperation op) { - const double fImageWidth = (double)image.width(); - const double fImageHeight = (double)image.height(); + const double dpr = image.devicePixelRatio(); + const double fImageWidth = image.width() / dpr; + const double fImageHeight = image.height() / dpr; // stroke outline const double penWidth = (double)pen.width() * penWidthMultiplier;