From f46496602e855dccccb6052de0f7ccbc74db40cd Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 19 Jan 2017 10:44:43 +0100 Subject: Windows: Support custom sizes entered via the print dialog When going via the advanced settings for a printer in the print dialog it is possible to specify a custom page size directly. This needs to be picked up via the POSTSCRIPT_IDENTIFY ExtEscape identifier to see if it is supported at all and then queried to see if a custom size is set. Change-Id: Id5e94c1b25be1c6e28d9e26d8001cd1c96d8f5d9 Reviewed-by: Friedemann Kleint --- src/printsupport/kernel/qprintengine_win.cpp | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/printsupport/kernel/qprintengine_win.cpp') diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 5a48e92a3a..f1ccbaa90a 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -1659,9 +1659,33 @@ void QWin32PrintEnginePrivate::updatePageLayout() m_pageLayout.setOrientation(devMode->dmOrientation == DMORIENT_LANDSCAPE ? QPageLayout::Landscape : QPageLayout::Portrait); if (devMode->dmPaperSize >= DMPAPER_LAST) { // Is a custom size - QPageSize pageSize = QPageSize(QSizeF(devMode->dmPaperWidth / 10.0f, devMode->dmPaperLength / 10.0f), - QPageSize::Millimeter); - setPageSize(pageSize); + // Check if it is using the Postscript Custom Size first + bool hasCustom = false; + int feature = PSIDENT_GDICENTRIC; + if (ExtEscape(hdc, POSTSCRIPT_IDENTIFY, + sizeof(DWORD), reinterpret_cast(&feature), 0, 0) >= 0) { + PSFEATURE_CUSTPAPER custPaper; + feature = FEATURESETTING_CUSTPAPER; + if (ExtEscape(hdc, GET_PS_FEATURESETTING, sizeof(INT), reinterpret_cast(&feature), + sizeof(custPaper), reinterpret_cast(&custPaper)) > 0) { + // If orientation is 1 and width/height is 0 then it's not really custom + if (!(custPaper.lOrientation == 1 && custPaper.lWidth == 0 && custPaper.lHeight == 0)) { + if (custPaper.lOrientation == 0 || custPaper.lOrientation == 2) + m_pageLayout.setOrientation(QPageLayout::Portrait); + else + m_pageLayout.setOrientation(QPageLayout::Landscape); + QPageSize pageSize = QPageSize(QSizeF(custPaper.lWidth, custPaper.lHeight), + QPageSize::Point); + setPageSize(pageSize); + hasCustom = true; + } + } + } + if (!hasCustom) { + QPageSize pageSize = QPageSize(QSizeF(devMode->dmPaperWidth / 10.0f, devMode->dmPaperLength / 10.0f), + QPageSize::Millimeter); + setPageSize(pageSize); + } } else { // Is a supported size setPageSize(QPageSize(QPageSize::id(devMode->dmPaperSize))); -- cgit v1.2.3