diff options
author | Andy Shaw <andy.shaw@digia.com> | 2013-12-03 22:11:35 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-04 20:47:13 (GMT) |
commit | 0f6438baf5188c69c7c64cca524e2e229b786dab (patch) | |
tree | 44414d597ff5325520102baa40ef9be12a5eba07 | |
parent | 1cd14aeaed5aad718b910da2a3eb64477105af3f (diff) | |
download | Qt-0f6438baf5188c69c7c64cca524e2e229b786dab.zip Qt-0f6438baf5188c69c7c64cca524e2e229b786dab.tar.gz Qt-0f6438baf5188c69c7c64cca524e2e229b786dab.tar.bz2 |
Respect the custom paper size settings on Mac
When the user added a custom paper size then it would be silently
ignored when printing on Mac. This now ensures that it is respected when
appropriate.
Manual cherry-pick from Qt 5: 26a0a3ed85008c3a0edae125fca48c7c36a7437f
[ChangeLog][Platform Specific Changes][OS X][QtPrintSupport] Respect
the custom paper size settings when printing.
Task-number: QTBUG-34700
Change-Id: If2ff9b704a636c94510f826d300e53af99c8e7ab
Reviewed-by: John Layt <jlayt@kde.org>
-rw-r--r-- | src/gui/painting/qprintengine_mac.mm | 70 | ||||
-rw-r--r-- | src/gui/painting/qprintengine_mac_p.h | 1 |
2 files changed, 48 insertions, 23 deletions
diff --git a/src/gui/painting/qprintengine_mac.mm b/src/gui/painting/qprintengine_mac.mm index da8b04b..c633c21 100644 --- a/src/gui/painting/qprintengine_mac.mm +++ b/src/gui/painting/qprintengine_mac.mm @@ -40,8 +40,8 @@ ****************************************************************************/ #include <private/qprintengine_mac_p.h> -#include <qdebug.h> #include <qthread.h> +#include <quuid.h> #include <QtCore/qcoreapplication.h> #ifndef QT_NO_PRINTER @@ -148,30 +148,52 @@ QMacPrintEnginePrivate::~QMacPrintEnginePrivate() void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps) { Q_Q(QMacPrintEngine); - QSize newSize = qt_paperSizeToQSizeF(ps).toSize(); - QCFType<CFArrayRef> formats; + if (hasCustomPaperSize) { + PMRelease(customPaper); + customPaper = 0; + } + hasCustomPaperSize = (ps == QPrinter::Custom); PMPrinter printer; - if (PMSessionGetCurrentPrinter(session, &printer) == noErr - && PMSessionCreatePageFormatList(session, printer, &formats) == noErr) { - CFIndex total = CFArrayGetCount(formats); - PMPageFormat tmp; - PMRect paper; - for (CFIndex idx = 0; idx < total; ++idx) { - tmp = static_cast<PMPageFormat>( - const_cast<void *>(CFArrayGetValueAtIndex(formats, idx))); - PMGetUnadjustedPaperRect(tmp, &paper); - int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5); - int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5); - if (newSize.width() == wMM && newSize.height() == hMM) { - PMCopyPageFormat(tmp, format); - // reset the orientation and resolution as they are lost in the copy. - q->setProperty(QPrintEngine::PPK_Orientation, orient); - if (PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) != noErr) { - // Don't know, warn for the moment. - qWarning("QMacPrintEngine, problem setting format and resolution for this page size"); + if (PMSessionGetCurrentPrinter(session, &printer) == noErr) { + if (ps != QPrinter::Custom) { + QSize newSize = qt_paperSizeToQSizeF(ps).toSize(); + QCFType<CFArrayRef> formats; + if (PMSessionCreatePageFormatList(session, printer, &formats) == noErr) { + CFIndex total = CFArrayGetCount(formats); + PMPageFormat tmp; + PMRect paper; + for (CFIndex idx = 0; idx < total; ++idx) { + tmp = static_cast<PMPageFormat>(const_cast<void *>(CFArrayGetValueAtIndex(formats, idx))); + PMGetUnadjustedPaperRect(tmp, &paper); + int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5); + int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5); + if (newSize.width() == wMM && newSize.height() == hMM) { + PMCopyPageFormat(tmp, format); + // reset the orientation and resolution as they are lost in the copy. + q->setProperty(QPrintEngine::PPK_Orientation, orient); + if (PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) != noErr) { + // Don't know, warn for the moment. + qWarning("QMacPrintEngine, problem setting format and resolution for this page size"); + } + break; + } } - break; + } + } else { + QCFString paperId = QCFString::toCFStringRef(QUuid::createUuid().toString()); + PMPaperMargins paperMargins; + paperMargins.left = leftMargin; + paperMargins.top = topMargin; + paperMargins.right = rightMargin; + paperMargins.bottom = bottomMargin; + PMPaperCreateCustom(printer, paperId, QCFString("Custom size"), customSize.width(), customSize.height(), &paperMargins, &customPaper); + PMPageFormat tmp; + PMCreatePageFormatWithPMPaper(&tmp, customPaper); + PMCopyPageFormat(tmp, format); + if (PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) != noErr) { + // Don't know, warn for the moment. + qWarning("QMacPrintEngine, problem setting paper name"); } } } @@ -492,6 +514,8 @@ void QMacPrintEnginePrivate::releaseSession() PMSessionEndDocumentNoDialog(session); [printInfo release]; #endif + if (hasCustomPaperSize) + PMRelease(customPaper); printInfo = 0; session = 0; } @@ -744,10 +768,10 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va { PMOrientation orientation; PMGetOrientation(d->format, &orientation); - d->hasCustomPaperSize = true; d->customSize = value.toSizeF(); if (orientation != kPMPortrait) d->customSize = QSizeF(d->customSize.height(), d->customSize.width()); + d->setPaperSize(QPrinter::Custom); break; } case PPK_PageMargins: diff --git a/src/gui/painting/qprintengine_mac_p.h b/src/gui/painting/qprintengine_mac_p.h index 5241ad5..5d39587 100644 --- a/src/gui/painting/qprintengine_mac_p.h +++ b/src/gui/painting/qprintengine_mac_p.h @@ -137,6 +137,7 @@ public: qreal rightMargin; qreal bottomMargin; QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant> valueCache; + PMPaper customPaper; QMacPrintEnginePrivate() : mode(QPrinter::ScreenResolution), state(QPrinter::Idle), orient(QPrinter::Portrait), printInfo(0), format(0), settings(0), session(0), paintEngine(0), suppressStatus(false), |