summaryrefslogtreecommitdiffstats
path: root/src/plugins/printsupport
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/printsupport')
-rw-r--r--src/plugins/printsupport/windows/qwindowsprintdevice.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/plugins/printsupport/windows/qwindowsprintdevice.cpp b/src/plugins/printsupport/windows/qwindowsprintdevice.cpp
index 54bd9c5c72..b594fe9b34 100644
--- a/src/plugins/printsupport/windows/qwindowsprintdevice.cpp
+++ b/src/plugins/printsupport/windows/qwindowsprintdevice.cpp
@@ -248,8 +248,20 @@ QMarginsF QWindowsPrintDevice::printableMargins(const QPageSize &pageSize,
if (GetPrinter(m_hPrinter, 2, buffer.data(), needed, &needed)) {
PPRINTER_INFO_2 info = reinterpret_cast<PPRINTER_INFO_2>(buffer.data());
DEVMODE *devMode = info->pDevMode;
- if (!devMode)
- return margins;
+ bool separateDevMode = false;
+ if (!devMode) {
+ // GetPrinter() didn't include the DEVMODE. Get it a different way.
+ LONG result = DocumentProperties(NULL, m_hPrinter, (LPWSTR)m_id.utf16(),
+ NULL, NULL, 0);
+ devMode = (DEVMODE *)malloc(result);
+ separateDevMode = true;
+ result = DocumentProperties(NULL, m_hPrinter, (LPWSTR)m_id.utf16(),
+ devMode, NULL, DM_OUT_BUFFER);
+ if (result != IDOK) {
+ free(devMode);
+ return margins;
+ }
+ }
HDC pDC = CreateDC(NULL, (LPWSTR)m_id.utf16(), NULL, devMode);
if (pageSize.id() == QPageSize::Custom || pageSize.windowsId() <= 0 || pageSize.windowsId() > DMPAPER_LAST) {
@@ -275,6 +287,8 @@ QMarginsF QWindowsPrintDevice::printableMargins(const QPageSize &pageSize,
const qreal rightMargin = physicalWidth - leftMargin - printableWidth;
const qreal bottomMargin = physicalHeight - topMargin - printableHeight;
margins = QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin);
+ if (separateDevMode)
+ free(devMode);
DeleteDC(pDC);
}
return margins;