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 <Friedemann.Kleint@qt.io>
This commit is contained in:
Andy Shaw 2017-01-19 10:44:43 +01:00
parent d2a589e1f0
commit f46496602e

View File

@ -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<LPCSTR>(&feature), 0, 0) >= 0) {
PSFEATURE_CUSTPAPER custPaper;
feature = FEATURESETTING_CUSTPAPER;
if (ExtEscape(hdc, GET_PS_FEATURESETTING, sizeof(INT), reinterpret_cast<LPCSTR>(&feature),
sizeof(custPaper), reinterpret_cast<LPSTR>(&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)));