void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps) { Q_Q(QMacPrintEngine); QSizeF newSize = qt_paperSizeToQSizeF(ps); QCFType<CFArrayRef> formats; 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"); } break; } } } }
QRect QtopiaPrintEngine::paperRect() const { QSizeF s = qt_paperSizeToQSizeF(d_func()->paperSize); s.rwidth() = MM(s.width()); s.rheight() = MM(s.height()); int w = qRound(s.width()*d_func()->resolution/72.); int h = qRound(s.height()*d_func()->resolution/72.); if (d_func()->orientation == QPrinter::Portrait) return QRect(0, 0, w, h); else return QRect(0, 0, h, w); }
QPrinter::PaperSize QMacPrintEnginePrivate::paperSize() const { PMRect paper; PMGetUnadjustedPaperRect(format, &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); for (int i = QPrinter::A4; i < QPrinter::NPaperSize; ++i) { QSizeF s = qt_paperSizeToQSizeF(QPrinter::PaperSize(i)); if (s.width() == wMM && s.height() == hMM) return (QPrinter::PaperSize)i; } return QPrinter::Custom; }