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. [ChangeLog][Platform Specific Changes][OS X][QtPrintSupport] Respect the custom paper size settings when printing. Task-number: QTBUG-34700 Change-Id: I08afe24e0e67a50e9301abf4642c6f65bb0df1fe Reviewed-by: John Layt <jlayt@kde.org>
This commit is contained in:
parent
a774aa69db
commit
26a0a3ed85
@ -40,8 +40,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "qprintengine_mac_p.h"
|
#include "qprintengine_mac_p.h"
|
||||||
#include <qdebug.h>
|
#include <quuid.h>
|
||||||
#include <qthread.h>
|
|
||||||
#include <QtCore/qcoreapplication.h>
|
#include <QtCore/qcoreapplication.h>
|
||||||
#include <qpa/qplatformprintersupport.h>
|
#include <qpa/qplatformprintersupport.h>
|
||||||
|
|
||||||
@ -141,18 +140,22 @@ QMacPrintEnginePrivate::~QMacPrintEnginePrivate()
|
|||||||
void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps)
|
void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps)
|
||||||
{
|
{
|
||||||
Q_Q(QMacPrintEngine);
|
Q_Q(QMacPrintEngine);
|
||||||
|
if (hasCustomPaperSize) {
|
||||||
|
PMRelease(customPaper);
|
||||||
|
customPaper = 0;
|
||||||
|
}
|
||||||
|
hasCustomPaperSize = (ps == QPrinter::Custom);
|
||||||
|
PMPrinter printer;
|
||||||
|
if (PMSessionGetCurrentPrinter(session(), &printer) == noErr) {
|
||||||
|
if (ps != QPrinter::Custom) {
|
||||||
QSizeF newSize = QPlatformPrinterSupport::convertPaperSizeToQSizeF(ps);
|
QSizeF newSize = QPlatformPrinterSupport::convertPaperSizeToQSizeF(ps);
|
||||||
QCFType<CFArrayRef> formats;
|
QCFType<CFArrayRef> formats;
|
||||||
PMPrinter printer;
|
if (PMSessionCreatePageFormatList(session(), printer, &formats) == noErr) {
|
||||||
|
|
||||||
if (PMSessionGetCurrentPrinter(session(), &printer) == noErr
|
|
||||||
&& PMSessionCreatePageFormatList(session(), printer, &formats) == noErr) {
|
|
||||||
CFIndex total = CFArrayGetCount(formats);
|
CFIndex total = CFArrayGetCount(formats);
|
||||||
PMPageFormat tmp;
|
PMPageFormat tmp;
|
||||||
PMRect paper;
|
PMRect paper;
|
||||||
for (CFIndex idx = 0; idx < total; ++idx) {
|
for (CFIndex idx = 0; idx < total; ++idx) {
|
||||||
tmp = static_cast<PMPageFormat>(
|
tmp = static_cast<PMPageFormat>(const_cast<void *>(CFArrayGetValueAtIndex(formats, idx)));
|
||||||
const_cast<void *>(CFArrayGetValueAtIndex(formats, idx)));
|
|
||||||
PMGetUnadjustedPaperRect(tmp, &paper);
|
PMGetUnadjustedPaperRect(tmp, &paper);
|
||||||
int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5);
|
int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5);
|
||||||
int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5);
|
int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5);
|
||||||
@ -168,6 +171,23 @@ void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPrinter::PaperSize QMacPrintEnginePrivate::paperSize() const
|
QPrinter::PaperSize QMacPrintEnginePrivate::paperSize() const
|
||||||
@ -183,6 +203,11 @@ QPrinter::PaperSize QMacPrintEnginePrivate::paperSize() const
|
|||||||
void QMacPrintEnginePrivate::setPaperName(const QString &name)
|
void QMacPrintEnginePrivate::setPaperName(const QString &name)
|
||||||
{
|
{
|
||||||
Q_Q(QMacPrintEngine);
|
Q_Q(QMacPrintEngine);
|
||||||
|
if (hasCustomPaperSize) {
|
||||||
|
PMRelease(customPaper);
|
||||||
|
customPaper = 0;
|
||||||
|
hasCustomPaperSize = false;
|
||||||
|
}
|
||||||
PMPrinter printer;
|
PMPrinter printer;
|
||||||
|
|
||||||
if (PMSessionGetCurrentPrinter(session(), &printer) == noErr) {
|
if (PMSessionGetCurrentPrinter(session(), &printer) == noErr) {
|
||||||
@ -419,6 +444,8 @@ void QMacPrintEnginePrivate::releaseSession()
|
|||||||
{
|
{
|
||||||
PMSessionEndPageNoDialog(session());
|
PMSessionEndPageNoDialog(session());
|
||||||
PMSessionEndDocumentNoDialog(session());
|
PMSessionEndDocumentNoDialog(session());
|
||||||
|
if (hasCustomPaperSize)
|
||||||
|
PMRelease(customPaper);
|
||||||
[printInfo release];
|
[printInfo release];
|
||||||
printInfo = 0;
|
printInfo = 0;
|
||||||
}
|
}
|
||||||
@ -665,10 +692,10 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
|
|||||||
{
|
{
|
||||||
PMOrientation orientation;
|
PMOrientation orientation;
|
||||||
PMGetOrientation(d->format(), &orientation);
|
PMGetOrientation(d->format(), &orientation);
|
||||||
d->hasCustomPaperSize = true;
|
|
||||||
d->customSize = value.toSizeF();
|
d->customSize = value.toSizeF();
|
||||||
if (orientation != kPMPortrait)
|
if (orientation != kPMPortrait)
|
||||||
d->customSize = QSizeF(d->customSize.height(), d->customSize.width());
|
d->customSize = QSizeF(d->customSize.height(), d->customSize.width());
|
||||||
|
d->setPaperSize(QPrinter::Custom);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PPK_PageMargins:
|
case PPK_PageMargins:
|
||||||
|
@ -135,6 +135,7 @@ public:
|
|||||||
qreal rightMargin;
|
qreal rightMargin;
|
||||||
qreal bottomMargin;
|
qreal bottomMargin;
|
||||||
QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant> valueCache;
|
QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant> valueCache;
|
||||||
|
PMPaper customPaper;
|
||||||
QMacPrintEnginePrivate() : mode(QPrinter::ScreenResolution), state(QPrinter::Idle),
|
QMacPrintEnginePrivate() : mode(QPrinter::ScreenResolution), state(QPrinter::Idle),
|
||||||
orient(QPrinter::Portrait), printInfo(0), paintEngine(0),
|
orient(QPrinter::Portrait), printInfo(0), paintEngine(0),
|
||||||
hasCustomPaperSize(false), hasCustomPageMargins(false) {}
|
hasCustomPaperSize(false), hasCustomPageMargins(false) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user