summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYigit Akcay <yigit.akcay@qt.io>2023-04-19 12:10:59 +0200
committerYigit Akcay <yigit.akcay@qt.io>2023-04-20 14:31:34 +0000
commit421d3c4e0b57170343df57de0b222d0f57a7bcb7 (patch)
treef8273f8370a4c40b6834fa23f818509b10179e91
parent479d9d965acaff3fc08412d56ce205e8c8822dbf (diff)
downloadqtwebengine-421d3c4e0b57170343df57de0b222d0f57a7bcb7.tar.gz
Use paintRect instead of pageRect when printing to account for margins
Currently, when printing via QWebEngineView::print(), the margins are handled by QPainter and not Chromium, unlike QWebEngineView::printToPdf() or QWebEnginePage::printToPdf(). The changes in this patch don't affect the latter two. QPainter handles margins by making a distinction between pageRect and paintRect, where paintRect == pageRect - margins. Furthermore, to actually apply the top and left margin, QPainter moves paintRect by (marginLeft, marginTop). This means that we have to draw what is to be printed in the size of paintRect and QPainter will move it to apply top and left margins. Right now, this is not the case, as we draw what is to be printed in the size of pageRect. QPainter then moves it, thereby the result contains the top and left margins, but overflows the page on the right and bottom, effectively cropping the final result. In this patch we fix this by using the size of paintRect instead of pageRect to draw what is to be printed when printing via QWebEngineView::print(). Pick-to: 6.5 Fixes: QTBUG-111909 Change-Id: Ibc7a9035e654e92d84a594c6dd1ec2efc6e108ff Reviewed-by: Michal Klocek <michal.klocek@qt.io>
-rw-r--r--src/core/printing/printer_worker.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/core/printing/printer_worker.cpp b/src/core/printing/printer_worker.cpp
index 9eb82c590..da7165623 100644
--- a/src/core/printing/printer_worker.cpp
+++ b/src/core/printing/printer_worker.cpp
@@ -65,8 +65,8 @@ void PrinterWorker::print()
bool isLandscape = documentSize.width() > documentSize.height();
m_device->setPageOrientation(isLandscape ? QPageLayout::Landscape
: QPageLayout::Portrait);
- QRectF pageRect = m_device->pageLayout().pageSize().rectPixels(m_deviceResolution);
- documentSize = documentSize.scaled(pageRect.size(), Qt::KeepAspectRatio);
+ QRectF paintRect = m_device->pageLayout().paintRectPixels(m_deviceResolution);
+ documentSize = documentSize.scaled(paintRect.size(), Qt::KeepAspectRatio);
// setPageOrientation has to be called before qpainter.begin() or before
// qprinter.newPage() so correct metrics is used, therefore call begin now for only