diff options
author | Kai Pastor <dg0yt@darc.de> | 2015-09-11 01:22:14 +0200 |
---|---|---|
committer | Kai Pastor <dg0yt@darc.de> | 2016-02-25 18:42:47 +0000 |
commit | 44357dbe423d430246504d977f4422ed0e2e7a5a (patch) | |
tree | 2ac646155768ec7fbb5b7bdd448e0503189bc33b | |
parent | debc44cf1106fb20065aab7848759eace3211c65 (diff) |
QMacPrintEngine: Really set the printer resolution
As already reported in 2009 (Qt 4.6) QPrinter never actually set the
printer resolution. This change adds the necessary call to
PMPrinterSetOutputResolution (available since OS X 10.5).
[ChangeLog][QtPrintSupport][OS X] QMacPrintEngine now really sets the
printer resolution.
Task-number: QTBUG-7000
Change-Id: I3e851b62e1a7ed78564a8a6fd576b0a18d7eff63
Reviewed-by: Andy Shaw <andy.shaw@theqtcompany.com>
-rw-r--r-- | src/plugins/platforms/cocoa/qprintengine_mac.mm | 13 | ||||
-rw-r--r-- | tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp | 19 |
2 files changed, 29 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/qprintengine_mac.mm b/src/plugins/platforms/cocoa/qprintengine_mac.mm index edd1d656f0..000a9c46c8 100644 --- a/src/plugins/platforms/cocoa/qprintengine_mac.mm +++ b/src/plugins/platforms/cocoa/qprintengine_mac.mm @@ -470,7 +470,6 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va d->embedFonts = value.toBool(); break; case PPK_Resolution: { - // TODO It appears the old code didn't actually set the resolution??? Can we delete all this??? int bestResolution = 0; int dpi = value.toInt(); int bestDistance = INT_MAX; @@ -486,7 +485,17 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va } } } - PMSessionValidatePageFormat(d->session(), d->format(), kPMDontWantBoolean); + PMResolution resolution; + resolution.hRes = resolution.vRes = bestResolution; + if (PMPrinterSetOutputResolution(d->m_printDevice->macPrinter(), d->settings(), &resolution) == noErr) { + // Setting the resolution succeeded. + // Now try to read the actual resolution selected by the OS. + if (PMPrinterGetOutputResolution(d->m_printDevice->macPrinter(), d->settings(), &d->resolution) != noErr) { + // Reading the resolution somehow failed; d->resolution is in undefined state. + // So use the value which was acceptable to PMPrinterSetOutputResolution. + d->resolution = resolution; + } + } break; } case PPK_CollateCopies: diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp index aa72be3ea8..5e7a40d3b5 100644 --- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp +++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp @@ -1628,7 +1628,24 @@ void tst_QPrinter::resolution() // Test set/get int expected = 333; #ifdef Q_OS_MAC - // Set resolution does nothing on OSX, see QTBUG-7000 + // QMacPrintEngine chooses the closest supported resolution. + const QList<int> all_supported = native.supportedResolutions(); + foreach (int supported, all_supported) { + // Test setting a supported resolution + int requested = supported; + native.setResolution(requested); + QCOMPARE(native.resolution(), requested); + + // Test setting an unsupported resolution + do { + requested += 5; + } while (all_supported.contains(requested)); + native.setResolution(requested); + int result = native.resolution(); + QVERIFY(all_supported.contains(result)); + QVERIFY(qAbs(result - requested) <= qAbs(supported - requested)); + } + expected = native.resolution(); #endif // Q_OS_MAC native.setResolution(expected); |