summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEirik Aavitsland <[email protected]>2023-01-11 10:45:23 +0100
committerEirik Aavitsland <[email protected]>2023-01-24 11:00:16 +0000
commitb44f222dbe7886b9504a4af9f09521132d2262b2 (patch)
treeaa3ff3766a6214bcbe5f56f9d0d499520a5b9982
parent025659a18c45308c9219532fe7c2961f786d4e1a (diff)
Support the scaling factor of some Windows pdf print devices
The printer drivers of some pdf printers allows the user to set a global scaling factor, scaling up or down the number of device pixels available for the same paper size and dpi. Make sure to update the Qt print device metrics accordingly so that QPainter will see the entire page, and not more than the page. Fixes: QTBUG-106659 Pick-to: 6.5 Change-Id: Icb90c1aa742f56b2a2043ef7070530beebe541d5 Reviewed-by: Oliver Wolff <[email protected]>
-rw-r--r--src/printsupport/platform/windows/qprintengine_win.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/printsupport/platform/windows/qprintengine_win.cpp b/src/printsupport/platform/windows/qprintengine_win.cpp
index cd3e03d88e3..99075f4ec3c 100644
--- a/src/printsupport/platform/windows/qprintengine_win.cpp
+++ b/src/printsupport/platform/windows/qprintengine_win.cpp
@@ -1586,7 +1586,7 @@ void QWin32PrintEngine::setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalD
#if defined QT_DEBUG_DRAW || defined QT_DEBUG_METRICS
qDebug("QWin32PrintEngine::setGlobalDevMode()");
- debugMetrics();
+ d->debugMetrics();
#endif // QT_DEBUG_DRAW || QT_DEBUG_METRICS
}
@@ -1675,13 +1675,22 @@ void QWin32PrintEnginePrivate::updatePageLayout()
void QWin32PrintEnginePrivate::updateMetrics()
{
m_paintRectPixels = m_pageLayout.paintRectPixels(resolution);
+ // Some print devices allow scaling, so that "virtual" page size != current paper size
+ const int devWidth = GetDeviceCaps(hdc, PHYSICALWIDTH);
+ const int devHeight = GetDeviceCaps(hdc, PHYSICALHEIGHT);
+ const int pageWidth = m_pageLayout.fullRectPixels(dpi_x).width();
+ const int pageHeight = m_pageLayout.fullRectPixels(dpi_y).height();
+ const qreal pageScaleX = (devWidth && pageWidth) ? qreal(devWidth) / pageWidth : 1;
+ const qreal pageScaleY = (devHeight && pageHeight) ? qreal(devHeight) / pageHeight : 1;
+ m_paintRectPixels = QTransform::fromScale(pageScaleX, pageScaleY).mapRect(m_paintRectPixels);
+
QSizeF sizeMM = m_pageLayout.paintRect(QPageLayout::Millimeter).size();
m_paintSizeMM = QSize(qRound(sizeMM.width()), qRound(sizeMM.height()));
// Calculate the origin using the physical device pixels, not our paint pixels
// Origin is defined as User Margins - Device Margins
QMarginsF margins = m_pageLayout.margins(QPageLayout::Millimeter) / 25.4;
- origin_x = qRound(margins.left() * dpi_x) - GetDeviceCaps(hdc, PHYSICALOFFSETX);
- origin_y = qRound(margins.top() * dpi_y) - GetDeviceCaps(hdc, PHYSICALOFFSETY);
+ origin_x = qRound(pageScaleX * margins.left() * dpi_x) - GetDeviceCaps(hdc, PHYSICALOFFSETX);
+ origin_y = qRound(pageScaleY * margins.top() * dpi_y) - GetDeviceCaps(hdc, PHYSICALOFFSETY);
}
void QWin32PrintEnginePrivate::debugMetrics() const