QWin32PrintEnginePrivate: Properly initialize flags and fields of DEVMODE

- Set the respective flags of dmFields in
  QWin32PrintEngine::setProperty()
- Properly initialize newly allocated structs

This is merely for completeness, the allocation code paths are
not currently hit since the DEVMODE from the current printer is
used, which also has most dmFields bits set.

Pick-to: 6.6
Task-number: QTBUG-114604
Change-Id: I880d9faef9b1d491db4accd53d0d75b718f7f244
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
This commit is contained in:
Friedemann Kleint 2023-11-07 16:33:15 +01:00
parent 9f7d2fc7f9
commit dc7eb46352
3 changed files with 19 additions and 0 deletions

View File

@ -135,6 +135,7 @@ int QPageSetupDialog::exec()
if (ep->ownsDevMode && ep->devMode)
free(ep->devMode);
ep->devMode = reinterpret_cast<DEVMODE *>(malloc(devModeSize));
QWin32PrintEnginePrivate::initializeDevMode(ep->devMode);
ep->ownsDevMode = true;
// Copy

View File

@ -877,6 +877,7 @@ void QWin32PrintEnginePrivate::initialize()
LONG result = DocumentProperties(nullptr, hPrinter, lpwPrinterName,
nullptr, nullptr, 0);
devMode = reinterpret_cast<DEVMODE *>(malloc(result));
initializeDevMode(devMode);
ownsDevMode = true;
// Get the default DevMode
@ -916,6 +917,13 @@ void QWin32PrintEnginePrivate::initialize()
#endif // QT_DEBUG_DRAW || QT_DEBUG_METRICS
}
void QWin32PrintEnginePrivate::initializeDevMode(DEVMODE *devMode)
{
memset(devMode, 0, sizeof(DEVMODE));
devMode->dmSize = sizeof(DEVMODE);
devMode->dmSpecVersion = DM_SPECVERSION;
}
void QWin32PrintEnginePrivate::initHDC()
{
Q_ASSERT(hdc);
@ -1055,6 +1063,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
if (!d->devMode)
break;
d->devMode->dmCollate = value.toBool() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE;
d->devMode->dmFields |= DM_COLLATE;
d->doReinit();
}
break;
@ -1064,6 +1073,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
if (!d->devMode)
break;
d->devMode->dmColor = (value.toInt() == QPrinter::Color) ? DMCOLOR_COLOR : DMCOLOR_MONOCHROME;
d->devMode->dmFields |= DM_COLOR;
d->doReinit();
}
break;
@ -1089,15 +1099,19 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
switch (mode) {
case QPrint::DuplexNone:
d->devMode->dmDuplex = DMDUP_SIMPLEX;
d->devMode->dmFields |= DM_DUPLEX;
break;
case QPrint::DuplexAuto:
d->devMode->dmDuplex = d->m_pageLayout.orientation() == QPageLayout::Landscape ? DMDUP_HORIZONTAL : DMDUP_VERTICAL;
d->devMode->dmFields |= DM_DUPLEX;
break;
case QPrint::DuplexLongSide:
d->devMode->dmDuplex = DMDUP_VERTICAL;
d->devMode->dmFields |= DM_DUPLEX;
break;
case QPrint::DuplexShortSide:
d->devMode->dmDuplex = DMDUP_HORIZONTAL;
d->devMode->dmFields |= DM_DUPLEX;
break;
default:
// Don't change
@ -1125,6 +1139,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
break;
d->num_copies = value.toInt();
d->devMode->dmCopies = d->num_copies;
d->devMode->dmFields |= DM_COPIES;
d->doReinit();
break;
@ -1133,6 +1148,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
break;
QPageLayout::Orientation orientation = QPageLayout::Orientation(value.toInt());
d->devMode->dmOrientation = orientation == QPageLayout::Landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
d->devMode->dmFields |= DM_ORIENTATION;
d->m_pageLayout.setOrientation(orientation);
d->updateMetrics();
d->doReinit();

View File

@ -111,6 +111,8 @@ public:
is handled in the next begin or newpage. */
void doReinit();
static void initializeDevMode(DEVMODE *);
bool resetDC();
void strokePath(const QPainterPath &path, const QColor &color);