summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qprintengine_mac.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/cocoa/qprintengine_mac.mm')
-rw-r--r--src/plugins/platforms/cocoa/qprintengine_mac.mm521
1 files changed, 158 insertions, 363 deletions
diff --git a/src/plugins/platforms/cocoa/qprintengine_mac.mm b/src/plugins/platforms/cocoa/qprintengine_mac.mm
index 3e92a45a62..fb968f31e9 100644
--- a/src/plugins/platforms/cocoa/qprintengine_mac.mm
+++ b/src/plugins/platforms/cocoa/qprintengine_mac.mm
@@ -40,9 +40,11 @@
****************************************************************************/
#include "qprintengine_mac_p.h"
+#include "qcocoaprintersupport.h"
#include <quuid.h>
+#include <QtGui/qpagelayout.h>
#include <QtCore/qcoreapplication.h>
-#include <qpa/qplatformprintersupport.h>
+#include <QtCore/qdebug.h>
#include "qcocoaautoreleasepool.h"
@@ -50,10 +52,14 @@
QT_BEGIN_NAMESPACE
+extern QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits);
+
QMacPrintEngine::QMacPrintEngine(QPrinter::PrinterMode mode) : QPaintEngine(*(new QMacPrintEnginePrivate))
{
Q_D(QMacPrintEngine);
d->mode = mode;
+ d->m_printDevice = new QCocoaPrintDevice(QCocoaPrinterSupport().defaultPrintDeviceId());
+ d->m_pageLayout.setPageSize(d->m_printDevice->defaultPageSize());
d->initialize();
}
@@ -137,126 +143,6 @@ QMacPrintEnginePrivate::~QMacPrintEnginePrivate()
delete paintEngine;
}
-void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps)
-{
- 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);
- 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;
- }
- }
- }
- } 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
-{
- if (hasCustomPaperSize)
- return QPrinter::Custom;
- PMRect paper;
- PMGetUnadjustedPaperRect(format(), &paper);
- QSizeF sizef((paper.right - paper.left) / 72.0 * 25.4, (paper.bottom - paper.top) / 72.0 * 25.4);
- return QPlatformPrinterSupport::convertQSizeFToPaperSize(sizef);
-}
-
-void QMacPrintEnginePrivate::setPaperName(const QString &name)
-{
- Q_Q(QMacPrintEngine);
- if (hasCustomPaperSize) {
- PMRelease(customPaper);
- customPaper = 0;
- hasCustomPaperSize = false;
- }
- PMPrinter printer;
-
- if (PMSessionGetCurrentPrinter(session(), &printer) == noErr) {
- CFArrayRef array;
- if (PMPrinterGetPaperList(printer, &array) != noErr)
- return;
- int count = CFArrayGetCount(array);
- for (int i = 0; i < count; ++i) {
- PMPaper paper = static_cast<PMPaper>(const_cast<void *>(CFArrayGetValueAtIndex(array, i)));
- QCFString paperName;
- if (PMPaperCreateLocalizedName(paper, printer, &paperName) == noErr) {
- if (QString(paperName) == name) {
- PMPageFormat tmp;
- PMCreatePageFormatWithPMPaper(&tmp, paper);
- PMCopyPageFormat(tmp, format());
- q->setProperty(QPrintEngine::PPK_Orientation, orient);
- if (PMSessionValidatePageFormat(session(), format(), kPMDontWantBoolean) != noErr) {
- // Don't know, warn for the moment.
- qWarning("QMacPrintEngine, problem setting paper name");
- }
- }
- }
- }
- }
-}
-
-QList<QVariant> QMacPrintEnginePrivate::supportedResolutions() const
-{
- Q_ASSERT_X(printInfo, "QMacPrinterEngine::supportedResolutions",
- "must have a valid printer session");
- UInt32 resCount;
- QList<QVariant> resolutions;
- PMPrinter printer;
- if (PMSessionGetCurrentPrinter(session(), &printer) == noErr) {
- PMResolution res;
- OSStatus status = PMPrinterGetPrinterResolutionCount(printer, &resCount);
- if (status == noErr) {
- // According to the docs, index start at 1.
- for (UInt32 i = 1; i <= resCount; ++i) {
- if (PMPrinterGetIndexedPrinterResolution(printer, i, &res) == noErr)
- resolutions.append(QVariant(int(res.hRes)));
- }
- } else {
- qWarning("QMacPrintEngine::supportedResolutions: Unexpected error: %ld", long(status));
- }
- }
- return resolutions;
-}
-
QPrinter::PrinterState QMacPrintEngine::printerState() const
{
return d_func()->state;
@@ -291,77 +177,22 @@ bool QMacPrintEngine::abort()
return ret;
}
-static inline int qt_get_PDMWidth(PMPageFormat pformat, bool fullPage,
- const PMResolution &resolution)
-{
- int val = 0;
- PMRect r;
- qreal hRatio = resolution.hRes / 72;
- if (fullPage) {
- if (PMGetAdjustedPaperRect(pformat, &r) == noErr)
- val = qRound((r.right - r.left) * hRatio);
- } else {
- if (PMGetAdjustedPageRect(pformat, &r) == noErr)
- val = qRound((r.right - r.left) * hRatio);
- }
- return val;
-}
-
-static inline int qt_get_PDMHeight(PMPageFormat pformat, bool fullPage,
- const PMResolution &resolution)
-{
- int val = 0;
- PMRect r;
- qreal vRatio = resolution.vRes / 72;
- if (fullPage) {
- if (PMGetAdjustedPaperRect(pformat, &r) == noErr)
- val = qRound((r.bottom - r.top) * vRatio);
- } else {
- if (PMGetAdjustedPageRect(pformat, &r) == noErr)
- val = qRound((r.bottom - r.top) * vRatio);
- }
- return val;
-}
-
-
int QMacPrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const
{
Q_D(const QMacPrintEngine);
int val = 1;
switch (m) {
case QPaintDevice::PdmWidth:
- if (d->hasCustomPaperSize) {
- val = qRound(d->customSize.width());
- if (d->hasCustomPageMargins) {
- val -= qRound(d->leftMargin + d->rightMargin);
- } else {
- QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList();
- val -= qRound(margins.at(0).toDouble() + margins.at(2).toDouble());
- }
- } else {
- val = qt_get_PDMWidth(d->format(), property(PPK_FullPage).toBool(), d->resolution);
- }
+ val = d->m_pageLayout.paintRectPixels(d->resolution.hRes).width();
break;
case QPaintDevice::PdmHeight:
- if (d->hasCustomPaperSize) {
- val = qRound(d->customSize.height());
- if (d->hasCustomPageMargins) {
- val -= qRound(d->topMargin + d->bottomMargin);
- } else {
- QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList();
- val -= qRound(margins.at(1).toDouble() + margins.at(3).toDouble());
- }
- } else {
- val = qt_get_PDMHeight(d->format(), property(PPK_FullPage).toBool(), d->resolution);
- }
+ val = d->m_pageLayout.paintRectPixels(d->resolution.hRes).height();
break;
case QPaintDevice::PdmWidthMM:
- val = metric(QPaintDevice::PdmWidth);
- val = int((val * 254 + 5 * d->resolution.hRes) / (10 * d->resolution.hRes));
+ val = qRound(d->m_pageLayout.paintRect(QPageLayout::Millimeter).width());
break;
case QPaintDevice::PdmHeightMM:
- val = metric(QPaintDevice::PdmHeight);
- val = int((val * 254 + 5 * d->resolution.vRes) / (10 * d->resolution.vRes));
+ val = qRound(d->m_pageLayout.paintRect(QPageLayout::Millimeter).height());
break;
case QPaintDevice::PdmPhysicalDpiX:
case QPaintDevice::PdmPhysicalDpiY: {
@@ -407,33 +238,24 @@ void QMacPrintEnginePrivate::initialize()
q->gccaps = paintEngine->gccaps;
- fullPage = false;
-
QCocoaAutoReleasePool pool;
printInfo = [[NSPrintInfo alloc] initWithDictionary:[NSDictionary dictionary]];
- PMPrinter printer;
- if (printInfo && PMSessionGetCurrentPrinter(session(), &printer) == noErr) {
- QList<QVariant> resolutions = supportedResolutions();
- if (!resolutions.isEmpty() && mode != QPrinter::ScreenResolution) {
- if (resolutions.count() > 1 && mode == QPrinter::HighResolution) {
- int max = 0;
- for (int i = 0; i < resolutions.count(); ++i) {
- int value = resolutions.at(i).toInt();
- if (value > max)
- max = value;
- }
- resolution.hRes = resolution.vRes = max;
- } else {
- resolution.hRes = resolution.vRes = resolutions.at(0).toInt();
- }
- if (resolution.hRes == 0)
- resolution.hRes = resolution.vRes = 600;
- } else {
- resolution.hRes = resolution.vRes = qt_defaultDpi();
- }
+ QList<int> resolutions = m_printDevice->supportedResolutions();
+ if (!resolutions.isEmpty() && mode != QPrinter::ScreenResolution) {
+ qSort(resolutions);
+ if (resolutions.count() > 1 && mode == QPrinter::HighResolution)
+ resolution.hRes = resolution.vRes = resolutions.last();
+ else
+ resolution.hRes = resolution.vRes = resolutions.first();
+ if (resolution.hRes == 0)
+ resolution.hRes = resolution.vRes = 600;
+ } else {
+ resolution.hRes = resolution.vRes = qt_defaultDpi();
}
+ setPageSize(m_pageLayout.pageSize());
+
QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant>::const_iterator propC;
for (propC = valueCache.constBegin(); propC != valueCache.constEnd(); propC++) {
q->setProperty(propC.key(), propC.value());
@@ -444,8 +266,6 @@ void QMacPrintEnginePrivate::releaseSession()
{
PMSessionEndPageNoDialog(session());
PMSessionEndDocumentNoDialog(session());
- if (hasCustomPaperSize)
- PMRelease(customPaper);
[printInfo release];
printInfo = 0;
}
@@ -473,8 +293,8 @@ bool QMacPrintEnginePrivate::newPage_helper()
return false;
}
- QRect page = q->property(QPrintEngine::PPK_PageRect).toRect();
- QRect paper = q->property(QPrintEngine::PPK_PaperRect).toRect();
+ QRect page = m_pageLayout.paintRectPixels(resolution.hRes);
+ QRect paper = m_pageLayout.fullRectPixels(resolution.hRes);
CGContextRef cgContext;
OSStatus err = noErr;
@@ -491,7 +311,7 @@ bool QMacPrintEnginePrivate::newPage_helper()
CGContextScaleCTM(cgContext, 1, -1);
CGContextTranslateCTM(cgContext, 0, -paper.height());
- if (!fullPage)
+ if (m_pageLayout.mode() != QPageLayout::FullPageMode)
CGContextTranslateCTM(cgContext, page.x() - paper.x(), page.y() - paper.y());
cgEngine->d_func()->orig_xform = CGContextGetCTM(cgContext);
cgEngine->d_func()->setClip(0);
@@ -505,6 +325,34 @@ bool QMacPrintEnginePrivate::newPage_helper()
return true;
}
+void QMacPrintEnginePrivate::setPageSize(const QPageSize &pageSize)
+{
+ if (!pageSize.isValid())
+ return;
+
+ // Get the matching printer paper
+ QPageSize printerPageSize = m_printDevice->supportedPageSize(pageSize);
+ QPageSize usePageSize = printerPageSize.isValid() ? printerPageSize : pageSize;
+
+ // Get the PMPaper and check it is valid
+ PMPaper macPaper = m_printDevice->macPaper(usePageSize);
+ if (macPaper == 0) {
+ qWarning() << "QMacPrintEngine: Invalid PMPaper returned for " << pageSize;
+ return;
+ }
+
+ QMarginsF printable = m_printDevice->printableMargins(usePageSize, m_pageLayout.orientation(), resolution.hRes);
+ m_pageLayout.setPageSize(usePageSize, qt_convertMargins(printable, QPageLayout::Point, m_pageLayout.units()));
+
+ // You cannot set the page size on a PMPageFormat, you must create a new PMPageFormat
+ PMPageFormat pageFormat;
+ PMCreatePageFormatWithPMPaper(&pageFormat, macPaper);
+ PMSetOrientation(pageFormat, m_pageLayout.orientation() == QPageLayout::Landscape ? kPMLandscape : kPMPortrait, kPMUnlocked);
+ PMCopyPageFormat(pageFormat, format());
+ if (PMSessionValidatePageFormat(session(), format(), kPMDontWantBoolean) != noErr)
+ qWarning("QMacPrintEngine: Invalid page format");
+ PMRelease(pageFormat);
+}
void QMacPrintEngine::updateState(const QPaintEngineState &state)
{
@@ -624,32 +472,22 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
break;
case PPK_SelectionOption:
break;
- case PPK_WindowsPageSize:
- break;
// The following keys are properties and settings that are supported by the Mac PrintEngine
case PPK_Resolution: {
- PMPrinter printer;
- UInt32 count;
- if (PMSessionGetCurrentPrinter(d->session(), &printer) != noErr)
- break;
- if (PMPrinterGetPrinterResolutionCount(printer, &count) != noErr)
- break;
- PMResolution resolution = { 0.0, 0.0 };
- PMResolution bestResolution = { 0.0, 0.0 };
+ // 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;
- for (UInt32 i = 1; i <= count; ++i) { // Yes, it starts at 1
- if (PMPrinterGetIndexedPrinterResolution(printer, i, &resolution) == noErr) {
- if (dpi == int(resolution.hRes)) {
+ foreach (int resolution, d->m_printDevice->supportedResolutions()) {
+ if (dpi == resolution) {
+ bestResolution = resolution;
+ break;
+ } else {
+ int distance = qAbs(dpi - resolution);
+ if (distance < bestDistance) {
+ bestDistance = distance;
bestResolution = resolution;
- break;
- } else {
- int distance = qAbs(dpi - int(resolution.hRes));
- if (distance < bestDistance) {
- bestDistance = distance;
- bestResolution = resolution;
- }
}
}
}
@@ -666,75 +504,80 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
PMPrintSettingsSetJobName(d->settings(), QCFString(value.toString()));
break;
case PPK_FullPage:
- d->fullPage = value.toBool();
+ if (value.toBool())
+ d->m_pageLayout.setMode(QPageLayout::FullPageMode);
+ else
+ d->m_pageLayout.setMode(QPageLayout::StandardMode);
break;
case PPK_CopyCount: // fallthrough
case PPK_NumberOfCopies:
PMSetCopies(d->settings(), value.toInt(), false);
break;
case PPK_Orientation: {
- QPrinter::Orientation newOrientation = QPrinter::Orientation(value.toInt());
- if (d->hasCustomPaperSize && (d->orient != newOrientation))
- d->customSize = QSizeF(d->customSize.height(), d->customSize.width());
- d->orient = newOrientation;
- PMOrientation o = d->orient == QPrinter::Portrait ? kPMPortrait : kPMLandscape;
- PMSetOrientation(d->format(), o, false);
+ // First try set the Mac format orientation, then set our orientation to match result
+ QPageLayout::Orientation newOrientation = QPageLayout::Orientation(value.toInt());
+ PMOrientation macOrientation = (newOrientation == QPageLayout::Landscape) ? kPMLandscape : kPMPortrait;
+ PMSetOrientation(d->format(), macOrientation, kPMUnlocked);
PMSessionValidatePageFormat(d->session(), d->format(), kPMDontWantBoolean);
+ PMGetOrientation(d->format(), &macOrientation);
+ d->m_pageLayout.setOrientation(macOrientation == kPMLandscape ? QPageLayout::Landscape : QPageLayout::Portrait);
break;
}
case PPK_OutputFileName:
d->outputFilename = value.toString();
break;
- case PPK_PaperSize:
- d->setPaperSize(QPrinter::PaperSize(value.toInt()));
+ case PPK_PageSize:
+ d->setPageSize(QPageSize(QPageSize::PageSizeId(value.toInt())));
break;
case PPK_PaperName:
- d->setPaperName(value.toString());
+ // Get the named page size from the printer if supported
+ d->setPageSize(d->m_printDevice->supportedPageSize(value.toString()));
+ break;
+ case PPK_WindowsPageSize:
+ d->setPageSize(QPageSize(QPageSize::id(value.toInt())));
break;
case PPK_PrinterName: {
- bool printerNameSet = false;
- OSStatus status = noErr;
- QCFType<CFArrayRef> printerList;
- status = PMServerCreatePrinterList(kPMServerLocal, &printerList);
- if (status == noErr) {
- CFIndex count = CFArrayGetCount(printerList);
- for (CFIndex i=0; i<count; ++i) {
- PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
- QString name = QCFString::toQString(PMPrinterGetID(printer));
- if (name == value.toString()) {
- status = PMSessionSetCurrentPMPrinter(d->session(), printer);
- printerNameSet = true;
- break;
- }
- }
- }
- if (status != noErr)
- qWarning("QMacPrintEngine::setPrinterName: Error setting printer: %ld", long(status));
- if (!printerNameSet) {
- qWarning("QMacPrintEngine::setPrinterName: Failed to set printer named '%s'.", qPrintable(value.toString()));
- d->releaseSession();
- d->state = QPrinter::Idle;
- }
- break; }
- case PPK_CustomPaperSize:
- {
- PMOrientation orientation;
- PMGetOrientation(d->format(), &orientation);
- d->customSize = value.toSizeF();
- if (orientation != kPMPortrait)
- d->customSize = QSizeF(d->customSize.height(), d->customSize.width());
- d->setPaperSize(QPrinter::Custom);
+ QString id = value.toString();
+ if (id.isEmpty())
+ id = QCocoaPrinterSupport().defaultPrintDeviceId();
+ else if (!QCocoaPrinterSupport().availablePrintDeviceIds().contains(id))
+ break;
+ d->m_printDevice = new QCocoaPrintDevice(id);
+ PMPrinter printer = d->m_printDevice->macPrinter();
+ PMRetain(printer);
+ PMSessionSetCurrentPMPrinter(d->session(), printer);
+ // TODO Do we need to check if the page size, etc, are valid on new printer?
break;
}
+ case PPK_CustomPaperSize:
+ d->setPageSize(QPageSize(value.toSizeF(), QPageSize::Point));
+ break;
case PPK_PageMargins:
{
QList<QVariant> margins(value.toList());
Q_ASSERT(margins.size() == 4);
- d->leftMargin = margins.at(0).toDouble();
- d->topMargin = margins.at(1).toDouble();
- d->rightMargin = margins.at(2).toDouble();
- d->bottomMargin = margins.at(3).toDouble();
- d->hasCustomPageMargins = true;
+ d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
+ margins.at(2).toReal(), margins.at(3).toReal()));
+ break;
+ }
+ case PPK_QPageSize:
+ d->setPageSize(value.value<QPageSize>());
+ break;
+ case PPK_QPageMargins: {
+ QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >();
+ d->m_pageLayout.setUnits(pair.second);
+ d->m_pageLayout.setMargins(pair.first);
+ break;
+ }
+ case PPK_QPageLayout: {
+ QPageLayout pageLayout = value.value<QPageLayout>();
+ if (pageLayout.isValid() && d->m_printDevice->isValidPageLayout(pageLayout, d->resolution.hRes)) {
+ setProperty(PPK_QPageSize, QVariant::fromValue(pageLayout.pageSize()));
+ setProperty(PPK_FullPage, pageLayout.mode() == QPageLayout::FullPageMode);
+ setProperty(PPK_Orientation, QVariant::fromValue(pageLayout.orientation()));
+ d->m_pageLayout.setUnits(pageLayout.units());
+ d->m_pageLayout.setMargins(pageLayout.margins());
+ }
break;
}
// No default so that compiler will complain if new keys added and not handled in this engine
@@ -787,9 +630,6 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const
case PPK_SelectionOption:
ret = QString();
break;
- case PPK_WindowsPageSize:
- // Special case, leave null
- break;
// The following keys are properties and settings that are supported by the Mac PrintEngine
case PPK_CollateCopies: {
@@ -808,7 +648,7 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const
break;
}
case PPK_FullPage:
- ret = d->fullPage;
+ ret = d->m_pageLayout.mode() == QPageLayout::FullPageMode;
break;
case PPK_NumberOfCopies:
ret = 1;
@@ -823,107 +663,62 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const
ret = true;
break;
case PPK_Orientation:
- PMOrientation orientation;
- PMGetOrientation(d->format(), &orientation);
- ret = orientation == kPMPortrait ? QPrinter::Portrait : QPrinter::Landscape;
+ ret = d->m_pageLayout.orientation();
break;
case PPK_OutputFileName:
ret = d->outputFilename;
break;
- case PPK_PageRect: {
+ case PPK_PageRect:
// PageRect is returned in device pixels
- QRect r;
- PMRect macrect, macpaper;
- qreal hRatio = d->resolution.hRes / 72;
- qreal vRatio = d->resolution.vRes / 72;
- if (d->hasCustomPaperSize) {
- r = QRect(0, 0, qRound(d->customSize.width() * hRatio), qRound(d->customSize.height() * vRatio));
- if (d->hasCustomPageMargins) {
- r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio),
- -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio));
- } else {
- QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList();
- r.adjust(qRound(margins.at(0).toDouble() * hRatio),
- qRound(margins.at(1).toDouble() * vRatio),
- -qRound(margins.at(2).toDouble() * hRatio),
- -qRound(margins.at(3).toDouble()) * vRatio);
- }
- } else if (PMGetAdjustedPageRect(d->format(), &macrect) == noErr
- && PMGetAdjustedPaperRect(d->format(), &macpaper) == noErr)
- {
- if (d->fullPage || d->hasCustomPageMargins) {
- r.setCoords(int(macpaper.left * hRatio), int(macpaper.top * vRatio),
- int(macpaper.right * hRatio), int(macpaper.bottom * vRatio));
- r.translate(-r.x(), -r.y());
- if (d->hasCustomPageMargins) {
- r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio),
- -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio));
- }
- } else {
- r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio),
- int(macrect.right * hRatio), int(macrect.bottom * vRatio));
- r.translate(int(-macpaper.left * hRatio), int(-macpaper.top * vRatio));
- }
- }
- ret = r;
- break; }
- case PPK_PaperSize:
- ret = d->paperSize();
+ ret = d->m_pageLayout.paintRectPixels(d->resolution.hRes);
+ break;
+ case PPK_PageSize:
+ ret = d->m_pageLayout.pageSize().id();
break;
case PPK_PaperName:
- ret = QCFString::toQString([d->printInfo localizedPaperName]);
- break;
- case PPK_PaperRect: {
- QRect r;
- PMRect macrect;
- qreal hRatio = d->resolution.hRes / 72;
- qreal vRatio = d->resolution.vRes / 72;
- if (d->hasCustomPaperSize) {
- r = QRect(0, 0, qRound(d->customSize.width() * hRatio), qRound(d->customSize.height() * vRatio));
- } else if (PMGetAdjustedPaperRect(d->format(), &macrect) == noErr) {
- r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio),
- int(macrect.right * hRatio), int(macrect.bottom * vRatio));
- r.translate(-r.x(), -r.y());
- }
- ret = r;
- break; }
- case PPK_PrinterName: {
- PMPrinter printer;
- OSStatus status = PMSessionGetCurrentPrinter(d->session(), &printer);
- if (status != noErr)
- qWarning("QMacPrintEngine::printerName: Failed getting current PMPrinter: %ld", long(status));
- if (printer)
- ret = QCFString::toQString(PMPrinterGetID(printer));
- break; }
+ ret = d->m_pageLayout.pageSize().name();
+ break;
+ case PPK_WindowsPageSize:
+ ret = d->m_pageLayout.pageSize().windowsId();
+ break;
+ case PPK_PaperRect:
+ // PaperRect is returned in device pixels
+ ret = d->m_pageLayout.fullRectPixels(d->resolution.hRes);
+ break;
+ case PPK_PrinterName:
+ return d->m_printDevice->id();
+ break;
case PPK_Resolution: {
ret = d->resolution.hRes;
break;
}
- case PPK_SupportedResolutions:
- ret = d->supportedResolutions();
+ case PPK_SupportedResolutions: {
+ QList<QVariant> list;
+ foreach (int resolution, d->m_printDevice->supportedResolutions())
+ list << resolution;
+ ret = list;
break;
+ }
case PPK_CustomPaperSize:
- ret = d->customSize;
+ ret = d->m_pageLayout.fullRectPoints().size();
break;
- case PPK_PageMargins:
- {
- QList<QVariant> margins;
- if (d->hasCustomPageMargins) {
- margins << d->leftMargin << d->topMargin
- << d->rightMargin << d->bottomMargin;
- } else if (!d->hasCustomPaperSize) {
- PMPaperMargins paperMargins;
- PMPaper paper;
- PMGetPageFormatPaper(d->format(), &paper);
- PMPaperGetMargins(paper, &paperMargins);
- margins << paperMargins.left << paperMargins.top
- << paperMargins.right << paperMargins.bottom;
- } else {
- margins << 0 << 0 << 0 << 0;
- }
- ret = margins;
+ case PPK_PageMargins: {
+ QList<QVariant> list;
+ QMarginsF margins = d->m_pageLayout.margins(QPageLayout::Point);
+ list << margins.left() << margins.top() << margins.right() << margins.bottom();
+ ret = list;
+ break;
+ }
+ case PPK_QPageSize:
+ ret.setValue(d->m_pageLayout.pageSize());
+ break;
+ case PPK_QPageMargins: {
+ QPair<QMarginsF, QPageLayout::Unit> pair = qMakePair(d->m_pageLayout.margins(), d->m_pageLayout.units());
+ ret.setValue(pair);
break;
}
+ case PPK_QPageLayout:
+ ret.setValue(d->m_pageLayout);
// No default so that compiler will complain if new keys added and not handled in this engine
}
return ret;