bool QMacPrintEngine::begin(QPaintDevice *dev) { Q_D(QMacPrintEngine); if (d->state == QPrinter::Idle && d->session == 0) // Need to reinitialize d->initialize(); d->paintEngine->state = state; d->paintEngine->begin(dev); Q_ASSERT_X(d->state == QPrinter::Idle, "QMacPrintEngine", "printer already active"); if (PMSessionValidatePrintSettings(d->session, d->settings, kPMDontWantBoolean) != noErr || PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean) != noErr) { d->state = QPrinter::Error; return false; } if (!d->outputFilename.isEmpty()) { QCFType<CFURLRef> outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, QCFString(d->outputFilename), kCFURLPOSIXPathStyle, false); if (PMSessionSetDestination(d->session, d->settings, kPMDestinationFile, kPMDocumentFormatPDF, outFile) != noErr) { qWarning("QMacPrintEngine::begin: Problem setting file [%s]", d->outputFilename.toUtf8().constData()); return false; } } OSStatus status = noErr; #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { status = d->shouldSuppressStatus() ? PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format) : PMSessionBeginCGDocument(d->session, d->settings, d->format); } else #endif { #ifndef Q_OS_MAC64 status = d->shouldSuppressStatus() ? PMSessionBeginDocumentNoDialog(d->session, d->settings, d->format) : PMSessionBeginDocument(d->session, d->settings, d->format); #endif } if (status != noErr) { d->state = QPrinter::Error; return false; } d->state = QPrinter::Active; setActive(true); d->newPage_helper(); return true; }
bool QPrinter::prepare(PMPrintSettings *s) { if (!psession && PMCreateSession(&psession) != noErr) return FALSE; if (*s == kPMNoPrintSettings) { if (PMCreatePrintSettings(s) != noErr) return FALSE; if (PMSessionDefaultPrintSettings(psession, *s) != noErr) return FALSE; } else { if (PMSessionValidatePrintSettings(psession, *s, kPMDontWantBoolean) != noErr) return FALSE; } if (minPage() != 0 || maxPage() != 0) PMSetPageRange(*s, minPage(), maxPage()); if (d->printRange != AllPages) { PMSetFirstPage(*s, fromPage(), TRUE); PMSetLastPage(*s, toPage(), TRUE); } PMSetColorMode(*s, colorMode() == GrayScale ? kPMGray : kPMColor); PMSetCopies(*s, numCopies(), TRUE); if (outputToFile()) { CFStringRef cfstring = qstring2cfstring(outputFileName()); CFURLRef outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, cfstring, kCFURLPOSIXPathStyle, false); PMSessionSetDestination(psession, *s, kPMDestinationFile, kPMDocumentFormatPDF, outFile); CFRelease(outFile); CFRelease(cfstring); } QString printName = printerName(); if (!printName.isEmpty()) { CFStringRef pname = qstring2cfstring(printName); PMSessionSetCurrentPrinter(psession, pname); CFRelease(pname); } return TRUE; }