1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qprintengine_mac_p.h"
45 #include <QtCore/qcoreapplication.h>
46 #include <QtPrintSupport/QPlatformPrinterSupport>
48 #include "qcocoaautoreleasepool.h"
54 QMacPrintEngine::QMacPrintEngine(QPrinter::PrinterMode mode) : QPaintEngine(*(new QMacPrintEnginePrivate))
61 bool QMacPrintEngine::begin(QPaintDevice *dev)
65 Q_ASSERT(dev && dev->devType() == QInternal::Printer);
66 if (!static_cast<QPrinter *>(dev)->isValid())
69 if (d->state == QPrinter::Idle && !d->isPrintSessionInitialized()) // Need to reinitialize
72 d->paintEngine->state = state;
73 d->paintEngine->begin(dev);
74 Q_ASSERT_X(d->state == QPrinter::Idle, "QMacPrintEngine", "printer already active");
76 if (PMSessionValidatePrintSettings(d->session, d->settings, kPMDontWantBoolean) != noErr
77 || PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean) != noErr) {
78 d->state = QPrinter::Error;
82 if (!d->outputFilename.isEmpty()) {
83 QCFType<CFURLRef> outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault,
84 QCFString(d->outputFilename),
87 if (PMSessionSetDestination(d->session, d->settings, kPMDestinationFile,
88 kPMDocumentFormatPDF, outFile) != noErr) {
89 qWarning("QMacPrintEngine::begin: Problem setting file [%s]", d->outputFilename.toUtf8().constData());
94 OSStatus status = PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format);
95 if (status != noErr) {
96 d->state = QPrinter::Error;
100 d->state = QPrinter::Active;
106 bool QMacPrintEngine::end()
108 Q_D(QMacPrintEngine);
109 if (d->state == QPrinter::Aborted)
110 return true; // I was just here a function call ago :)
111 if (d->paintEngine->type() == QPaintEngine::CoreGraphics) {
112 // We dont need the paint engine to call restoreGraphicsState()
113 static_cast<QCoreGraphicsPaintEngine*>(d->paintEngine)->d_func()->stackCount = 0;
114 static_cast<QCoreGraphicsPaintEngine*>(d->paintEngine)->d_func()->hd = 0;
116 d->paintEngine->end();
117 if (d->state != QPrinter::Idle)
119 d->state = QPrinter::Idle;
124 QMacPrintEngine::paintEngine() const
126 return d_func()->paintEngine;
129 Qt::HANDLE QMacPrintEngine::handle() const
131 QCoreGraphicsPaintEngine *cgEngine = static_cast<QCoreGraphicsPaintEngine*>(paintEngine());
132 return cgEngine->d_func()->hd;
135 QMacPrintEnginePrivate::~QMacPrintEnginePrivate()
141 void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps)
143 Q_Q(QMacPrintEngine);
144 QSizeF newSize = QPlatformPrinterSupport::convertPaperSizeToQSizeF(ps);
145 QCFType<CFArrayRef> formats;
148 if (PMSessionGetCurrentPrinter(session, &printer) == noErr
149 && PMSessionCreatePageFormatList(session, printer, &formats) == noErr) {
150 CFIndex total = CFArrayGetCount(formats);
153 for (CFIndex idx = 0; idx < total; ++idx) {
154 tmp = static_cast<PMPageFormat>(
155 const_cast<void *>(CFArrayGetValueAtIndex(formats, idx)));
156 PMGetUnadjustedPaperRect(tmp, &paper);
157 int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5);
158 int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5);
159 if (newSize.width() == wMM && newSize.height() == hMM) {
160 PMCopyPageFormat(tmp, format);
161 // reset the orientation and resolution as they are lost in the copy.
162 q->setProperty(QPrintEngine::PPK_Orientation, orient);
163 if (PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) != noErr) {
164 // Don't know, warn for the moment.
165 qWarning("QMacPrintEngine, problem setting format and resolution for this page size");
173 QPrinter::PaperSize QMacPrintEnginePrivate::paperSize() const
175 if (hasCustomPaperSize)
176 return QPrinter::Custom;
178 PMGetUnadjustedPaperRect(format, &paper);
179 QSizeF sizef((paper.right - paper.left) / 72.0 * 25.4, (paper.bottom - paper.top) / 72.0 * 25.4);
180 return QPlatformPrinterSupport::convertQSizeFToPaperSize(sizef);
183 QList<QVariant> QMacPrintEnginePrivate::supportedResolutions() const
185 Q_ASSERT_X(session, "QMacPrinterEngine::supportedResolutions",
186 "must have a valid printer session");
188 QList<QVariant> resolutions;
190 if (PMSessionGetCurrentPrinter(session, &printer) == noErr) {
192 OSStatus status = PMPrinterGetPrinterResolutionCount(printer, &resCount);
193 if (status == kPMNotImplemented) {
194 #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
195 // *Sigh* we have to use the non-indexed version.
196 if (PMPrinterGetPrinterResolution(printer, kPMMinSquareResolution, &res) == noErr)
197 resolutions.append(int(res.hRes));
198 if (PMPrinterGetPrinterResolution(printer, kPMMaxSquareResolution, &res) == noErr) {
199 QVariant var(int(res.hRes));
200 if (!resolutions.contains(var))
201 resolutions.append(var);
203 if (PMPrinterGetPrinterResolution(printer, kPMDefaultResolution, &res) == noErr) {
204 QVariant var(int(res.hRes));
205 if (!resolutions.contains(var))
206 resolutions.append(var);
209 } else if (status == noErr) {
210 // According to the docs, index start at 1.
211 for (UInt32 i = 1; i <= resCount; ++i) {
212 if (PMPrinterGetIndexedPrinterResolution(printer, i, &res) == noErr)
213 resolutions.append(QVariant(int(res.hRes)));
216 qWarning("QMacPrintEngine::supportedResolutions: Unexpected error: %ld", long(status));
222 QPrinter::PrinterState QMacPrintEngine::printerState() const
224 return d_func()->state;
227 bool QMacPrintEngine::newPage()
229 Q_D(QMacPrintEngine);
230 Q_ASSERT(d->state == QPrinter::Active);
232 PMSessionEndPageNoDialog(d->session);
234 if (err == kPMCancel) {
235 // User canceled, we need to abort!
238 // Not sure what the problem is...
239 qWarning("QMacPrintEngine::newPage: Cannot end current page. %ld", long(err));
240 d->state = QPrinter::Error;
244 return d->newPage_helper();
247 bool QMacPrintEngine::abort()
249 Q_D(QMacPrintEngine);
250 if (d->state != QPrinter::Active)
253 d->state = QPrinter::Aborted;
257 static inline int qt_get_PDMWidth(PMPageFormat pformat, bool fullPage,
258 const PMResolution &resolution)
262 qreal hRatio = resolution.hRes / 72;
264 if (PMGetAdjustedPaperRect(pformat, &r) == noErr)
265 val = qRound((r.right - r.left) * hRatio);
267 if (PMGetAdjustedPageRect(pformat, &r) == noErr)
268 val = qRound((r.right - r.left) * hRatio);
273 static inline int qt_get_PDMHeight(PMPageFormat pformat, bool fullPage,
274 const PMResolution &resolution)
278 qreal vRatio = resolution.vRes / 72;
280 if (PMGetAdjustedPaperRect(pformat, &r) == noErr)
281 val = qRound((r.bottom - r.top) * vRatio);
283 if (PMGetAdjustedPageRect(pformat, &r) == noErr)
284 val = qRound((r.bottom - r.top) * vRatio);
290 int QMacPrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const
292 Q_D(const QMacPrintEngine);
295 case QPaintDevice::PdmWidth:
296 if (d->hasCustomPaperSize) {
297 val = qRound(d->customSize.width());
298 if (d->hasCustomPageMargins) {
299 val -= qRound(d->leftMargin + d->rightMargin);
301 QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList();
302 val -= qRound(margins.at(0).toDouble() + margins.at(2).toDouble());
305 val = qt_get_PDMWidth(d->format, property(PPK_FullPage).toBool(), d->resolution);
308 case QPaintDevice::PdmHeight:
309 if (d->hasCustomPaperSize) {
310 val = qRound(d->customSize.height());
311 if (d->hasCustomPageMargins) {
312 val -= qRound(d->topMargin + d->bottomMargin);
314 QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList();
315 val -= qRound(margins.at(1).toDouble() + margins.at(3).toDouble());
318 val = qt_get_PDMHeight(d->format, property(PPK_FullPage).toBool(), d->resolution);
321 case QPaintDevice::PdmWidthMM:
322 val = metric(QPaintDevice::PdmWidth);
323 val = int((val * 254 + 5 * d->resolution.hRes) / (10 * d->resolution.hRes));
325 case QPaintDevice::PdmHeightMM:
326 val = metric(QPaintDevice::PdmHeight);
327 val = int((val * 254 + 5 * d->resolution.vRes) / (10 * d->resolution.vRes));
329 case QPaintDevice::PdmPhysicalDpiX:
330 case QPaintDevice::PdmPhysicalDpiY: {
332 if (PMSessionGetCurrentPrinter(d->session, &printer) == noErr) {
333 PMResolution resolution;
334 PMPrinterGetOutputResolution(printer, d->settings, &resolution);
335 val = (int)resolution.vRes;
338 //otherwise fall through
340 case QPaintDevice::PdmDpiY:
341 val = (int)d->resolution.vRes;
343 case QPaintDevice::PdmDpiX:
344 val = (int)d->resolution.hRes;
346 case QPaintDevice::PdmNumColors:
347 val = (1 << metric(QPaintDevice::PdmDepth));
349 case QPaintDevice::PdmDepth:
354 qWarning("QPrinter::metric: Invalid metric command");
359 void QMacPrintEnginePrivate::initialize()
361 Q_Q(QMacPrintEngine);
363 Q_ASSERT(!printInfo);
366 paintEngine = new QCoreGraphicsPaintEngine();
368 q->gccaps = paintEngine->gccaps;
372 QCocoaAutoReleasePool pool;
373 printInfo = [[NSPrintInfo alloc] initWithDictionary:[NSDictionary dictionary]];
374 session = static_cast<PMPrintSession>([printInfo PMPrintSession]);
377 if (session && PMSessionGetCurrentPrinter(session, &printer) == noErr) {
378 QList<QVariant> resolutions = supportedResolutions();
379 if (!resolutions.isEmpty() && mode != QPrinter::ScreenResolution) {
380 if (resolutions.count() > 1 && mode == QPrinter::HighResolution) {
382 for (int i = 0; i < resolutions.count(); ++i) {
383 int value = resolutions.at(i).toInt();
387 resolution.hRes = resolution.vRes = max;
389 resolution.hRes = resolution.vRes = resolutions.at(0).toInt();
391 if (resolution.hRes == 0)
392 resolution.hRes = resolution.vRes = 600;
394 resolution.hRes = resolution.vRes = qt_defaultDpi();
398 settings = static_cast<PMPrintSettings>([printInfo PMPrintSettings]);
399 format = static_cast<PMPageFormat>([printInfo PMPageFormat]);
401 QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant>::const_iterator propC;
402 for (propC = valueCache.constBegin(); propC != valueCache.constEnd(); propC++) {
403 q->setProperty(propC.key(), propC.value());
407 void QMacPrintEnginePrivate::releaseSession()
409 PMSessionEndPageNoDialog(session);
410 PMSessionEndDocumentNoDialog(session);
416 bool QMacPrintEnginePrivate::newPage_helper()
418 Q_Q(QMacPrintEngine);
419 Q_ASSERT(state == QPrinter::Active);
421 if (PMSessionError(session) != noErr) {
426 // pop the stack of saved graphic states, in case we get the same
427 // context back - either way, the stack count should be 0 when we
429 QCoreGraphicsPaintEngine *cgEngine = static_cast<QCoreGraphicsPaintEngine*>(paintEngine);
430 while (cgEngine->d_func()->stackCount > 0)
431 cgEngine->d_func()->restoreGraphicsState();
433 OSStatus status = PMSessionBeginPageNoDialog(session, format, 0);
434 if (status != noErr) {
435 state = QPrinter::Error;
439 QRect page = q->property(QPrintEngine::PPK_PageRect).toRect();
440 QRect paper = q->property(QPrintEngine::PPK_PaperRect).toRect();
442 CGContextRef cgContext;
443 OSStatus err = noErr;
444 err = PMSessionGetCGGraphicsContext(session, &cgContext);
446 qWarning("QMacPrintEngine::newPage: Cannot retrieve CoreGraphics context: %ld", long(err));
447 state = QPrinter::Error;
450 cgEngine->d_func()->hd = cgContext;
452 // Set the resolution as a scaling ration of 72 (the default).
453 CGContextScaleCTM(cgContext, 72 / resolution.hRes, 72 / resolution.vRes);
455 CGContextScaleCTM(cgContext, 1, -1);
456 CGContextTranslateCTM(cgContext, 0, -paper.height());
458 CGContextTranslateCTM(cgContext, page.x() - paper.x(), page.y() - paper.y());
459 cgEngine->d_func()->orig_xform = CGContextGetCTM(cgContext);
460 cgEngine->d_func()->setClip(0);
461 cgEngine->state->dirtyFlags = QPaintEngine::DirtyFlag(QPaintEngine::AllDirty
462 & ~(QPaintEngine::DirtyClipEnabled
463 | QPaintEngine::DirtyClipRegion
464 | QPaintEngine::DirtyClipPath));
465 if (cgEngine->painter()->hasClipping())
466 cgEngine->state->dirtyFlags |= QPaintEngine::DirtyClipEnabled;
467 cgEngine->syncState();
472 void QMacPrintEngine::updateState(const QPaintEngineState &state)
474 d_func()->paintEngine->updateState(state);
477 void QMacPrintEngine::drawRects(const QRectF *r, int num)
479 Q_D(QMacPrintEngine);
480 Q_ASSERT(d->state == QPrinter::Active);
481 d->paintEngine->drawRects(r, num);
484 void QMacPrintEngine::drawPoints(const QPointF *points, int pointCount)
486 Q_D(QMacPrintEngine);
487 Q_ASSERT(d->state == QPrinter::Active);
488 d->paintEngine->drawPoints(points, pointCount);
491 void QMacPrintEngine::drawEllipse(const QRectF &r)
493 Q_D(QMacPrintEngine);
494 Q_ASSERT(d->state == QPrinter::Active);
495 d->paintEngine->drawEllipse(r);
498 void QMacPrintEngine::drawLines(const QLineF *lines, int lineCount)
500 Q_D(QMacPrintEngine);
501 Q_ASSERT(d->state == QPrinter::Active);
502 d->paintEngine->drawLines(lines, lineCount);
505 void QMacPrintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
507 Q_D(QMacPrintEngine);
508 Q_ASSERT(d->state == QPrinter::Active);
509 d->paintEngine->drawPolygon(points, pointCount, mode);
512 void QMacPrintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
514 Q_D(QMacPrintEngine);
515 Q_ASSERT(d->state == QPrinter::Active);
516 d->paintEngine->drawPixmap(r, pm, sr);
519 void QMacPrintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
521 Q_D(QMacPrintEngine);
522 Q_ASSERT(d->state == QPrinter::Active);
523 d->paintEngine->drawImage(r, pm, sr, flags);
526 void QMacPrintEngine::drawTextItem(const QPointF &p, const QTextItem &ti)
528 Q_D(QMacPrintEngine);
529 Q_ASSERT(d->state == QPrinter::Active);
530 d->paintEngine->drawTextItem(p, ti);
533 void QMacPrintEngine::drawTiledPixmap(const QRectF &dr, const QPixmap &pixmap, const QPointF &sr)
535 Q_D(QMacPrintEngine);
536 Q_ASSERT(d->state == QPrinter::Active);
537 d->paintEngine->drawTiledPixmap(dr, pixmap, sr);
540 void QMacPrintEngine::drawPath(const QPainterPath &path)
542 Q_D(QMacPrintEngine);
543 Q_ASSERT(d->state == QPrinter::Active);
544 d->paintEngine->drawPath(path);
548 void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value)
550 Q_D(QMacPrintEngine);
552 d->valueCache.insert(key, value);
557 case PPK_CollateCopies:
563 case PPK_DocumentName:
567 case PPK_PaperSource:
569 case PPK_SelectionOption:
571 case PPK_Resolution: {
574 if (PMSessionGetCurrentPrinter(d->session, &printer) != noErr)
576 if (PMPrinterGetPrinterResolutionCount(printer, &count) != noErr)
578 PMResolution resolution = { 0.0, 0.0 };
579 PMResolution bestResolution = { 0.0, 0.0 };
580 int dpi = value.toInt();
581 int bestDistance = INT_MAX;
582 for (UInt32 i = 1; i <= count; ++i) { // Yes, it starts at 1
583 if (PMPrinterGetIndexedPrinterResolution(printer, i, &resolution) == noErr) {
584 if (dpi == int(resolution.hRes)) {
585 bestResolution = resolution;
588 int distance = qAbs(dpi - int(resolution.hRes));
589 if (distance < bestDistance) {
590 bestDistance = distance;
591 bestResolution = resolution;
596 PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean);
601 d->fullPage = value.toBool();
603 case PPK_CopyCount: // fallthrough
604 case PPK_NumberOfCopies:
605 PMSetCopies(d->settings, value.toInt(), false);
607 case PPK_Orientation: {
608 if (d->state == QPrinter::Active) {
609 qWarning("QMacPrintEngine::setOrientation: Orientation cannot be changed during a print job, ignoring change");
611 QPrinter::Orientation newOrientation = QPrinter::Orientation(value.toInt());
612 if (d->hasCustomPaperSize && (d->orient != newOrientation))
613 d->customSize = QSizeF(d->customSize.height(), d->customSize.width());
614 d->orient = newOrientation;
615 PMOrientation o = d->orient == QPrinter::Portrait ? kPMPortrait : kPMLandscape;
616 PMSetOrientation(d->format, o, false);
617 PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean);
620 case PPK_OutputFileName:
621 d->outputFilename = value.toString();
624 d->setPaperSize(QPrinter::PaperSize(value.toInt()));
626 case PPK_PrinterName: {
627 bool printerNameSet = false;
628 OSStatus status = noErr;
629 QCFType<CFArrayRef> printerList;
630 status = PMServerCreatePrinterList(kPMServerLocal, &printerList);
631 if (status == noErr) {
632 CFIndex count = CFArrayGetCount(printerList);
633 for (CFIndex i=0; i<count; ++i) {
634 PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
635 QString name = QCFString::toQString(PMPrinterGetName(printer));
636 if (name == value.toString()) {
637 status = PMSessionSetCurrentPMPrinter(d->session, printer);
638 printerNameSet = true;
644 qWarning("QMacPrintEngine::setPrinterName: Error setting printer: %ld", long(status));
645 if (!printerNameSet) {
646 qWarning("QMacPrintEngine::setPrinterName: Failed to set printer named '%s'.", qPrintable(value.toString()));
648 d->state = QPrinter::Idle;
651 case PPK_SuppressSystemPrintStatus:
653 case PPK_CustomPaperSize:
655 PMOrientation orientation;
656 PMGetOrientation(d->format, &orientation);
657 d->hasCustomPaperSize = true;
658 d->customSize = value.toSizeF();
659 if (orientation != kPMPortrait)
660 d->customSize = QSizeF(d->customSize.height(), d->customSize.width());
663 case PPK_PageMargins:
665 QList<QVariant> margins(value.toList());
666 Q_ASSERT(margins.size() == 4);
667 d->leftMargin = margins.at(0).toDouble();
668 d->topMargin = margins.at(1).toDouble();
669 d->rightMargin = margins.at(2).toDouble();
670 d->bottomMargin = margins.at(3).toDouble();
671 d->hasCustomPageMargins = true;
680 QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const
682 Q_D(const QMacPrintEngine);
685 if (!d->session && d->valueCache.contains(key))
686 return *d->valueCache.find(key);
689 case PPK_CollateCopies:
693 ret = QPrinter::Color;
697 case PPK_DocumentName:
702 case PPK_NumberOfCopies:
705 case PPK_CopyCount: {
707 PMGetCopies(d->settings, &copies);
711 case PPK_SupportsMultipleCopies:
714 case PPK_Orientation:
715 PMOrientation orientation;
716 PMGetOrientation(d->format, &orientation);
717 ret = orientation == kPMPortrait ? QPrinter::Portrait : QPrinter::Landscape;
719 case PPK_OutputFileName:
720 ret = d->outputFilename;
724 case PPK_PaperSource:
727 // PageRect is returned in device pixels
729 PMRect macrect, macpaper;
730 qreal hRatio = d->resolution.hRes / 72;
731 qreal vRatio = d->resolution.vRes / 72;
732 if (d->hasCustomPaperSize) {
733 r = QRect(0, 0, qRound(d->customSize.width() * hRatio), qRound(d->customSize.height() * vRatio));
734 if (d->hasCustomPageMargins) {
735 r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio),
736 -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio));
738 QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList();
739 r.adjust(qRound(margins.at(0).toDouble() * hRatio),
740 qRound(margins.at(1).toDouble() * vRatio),
741 -qRound(margins.at(2).toDouble() * hRatio),
742 -qRound(margins.at(3).toDouble()) * vRatio);
744 } else if (PMGetAdjustedPageRect(d->format, ¯ect) == noErr
745 && PMGetAdjustedPaperRect(d->format, &macpaper) == noErr)
747 if (d->fullPage || d->hasCustomPageMargins) {
748 r.setCoords(int(macpaper.left * hRatio), int(macpaper.top * vRatio),
749 int(macpaper.right * hRatio), int(macpaper.bottom * vRatio));
750 r.translate(-r.x(), -r.y());
751 if (d->hasCustomPageMargins) {
752 r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio),
753 -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio));
756 r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio),
757 int(macrect.right * hRatio), int(macrect.bottom * vRatio));
758 r.translate(int(-macpaper.left * hRatio), int(-macpaper.top * vRatio));
764 ret = d->paperSize();
766 case PPK_PaperRect: {
769 qreal hRatio = d->resolution.hRes / 72;
770 qreal vRatio = d->resolution.vRes / 72;
771 if (d->hasCustomPaperSize) {
772 r = QRect(0, 0, qRound(d->customSize.width() * hRatio), qRound(d->customSize.height() * vRatio));
773 } else if (PMGetAdjustedPaperRect(d->format, ¯ect) == noErr) {
774 r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio),
775 int(macrect.right * hRatio), int(macrect.bottom * vRatio));
776 r.translate(-r.x(), -r.y());
780 case PPK_PrinterName: {
782 OSStatus status = PMSessionGetCurrentPrinter(d->session, &printer);
784 qWarning("QMacPrintEngine::printerName: Failed getting current PMPrinter: %ld", long(status));
786 ret = QCFString::toQString(PMPrinterGetName(printer));
788 case PPK_Resolution: {
789 ret = d->resolution.hRes;
792 case PPK_SupportedResolutions:
793 ret = d->supportedResolutions();
795 case PPK_CustomPaperSize:
798 case PPK_PageMargins:
800 QList<QVariant> margins;
801 if (d->hasCustomPageMargins) {
802 margins << d->leftMargin << d->topMargin
803 << d->rightMargin << d->bottomMargin;
805 PMPaperMargins paperMargins;
807 PMGetPageFormatPaper(d->format, &paper);
808 PMPaperGetMargins(paper, &paperMargins);
809 margins << paperMargins.left << paperMargins.top
810 << paperMargins.right << paperMargins.bottom;
823 #endif // QT_NO_PRINTER