static boolean shellcheckprinterror (boolean flopening) { /* returns false if there was a print error. 1/18/93 dmb: take flopening parameter, & special case this error */ OSErr x; bigstring bserror; # ifdef MACVERSION //Code change by Timothy Paustian Friday, June 16, 2000 3:50:52 PM //Changed to Opaque call for Carbon // this is pointless --- explicitly excluded # if TARGET_API_MAC_CARBON == 1 x = PMSessionError(shellprintinfo.printhandle); # else x = PrError (); # endif if (x == noErr) /*no error, keep going*/ return (true); if (x != iPrAbort) { if (flopening) { GetIndString (bserror, interfacelistnumber, trychooserstring); } else { getsystemerrorstring (x, bserror); parsedialogstring (bserror, "\x06" ".Print", nil, nil, nil, bserror); } shellerrormessage (bserror); } # endif #ifdef WIN95VERSION x = GetLastError(); if (x == 0) return (true); getsystemerrorstring (x, bserror); shellerrormessage (bserror); #endif return (false); /*there was an error*/ } /*shellcheckprinterror*/
bool QMacPrintEnginePrivate::newPage_helper() { Q_Q(QMacPrintEngine); Q_ASSERT(state == QPrinter::Active); if (PMSessionError(session) != noErr) { q->abort(); return false; } OSStatus status = shouldSuppressStatus() ? PMSessionBeginPageNoDialog(session, format, 0) : PMSessionBeginPage(session, format, 0); if(status != noErr) { state = QPrinter::Error; return false; } QRect page = q->property(QPrintEngine::PPK_PageRect).toRect(); QRect paper = q->property(QPrintEngine::PPK_PaperRect).toRect(); CGContextRef cgContext; OSStatus err = noErr; #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { err = PMSessionGetCGGraphicsContext(session, &cgContext); } else #endif { #ifndef Q_OS_MAC64 err = PMSessionGetGraphicsContext(session, kPMGraphicsContextCoreGraphics, reinterpret_cast<void **>(&cgContext)); #endif } if(err != noErr) { qWarning("QMacPrintEngine::newPage: Cannot retrieve CoreGraphics context: %ld", long(err)); state = QPrinter::Error; return false; } QCoreGraphicsPaintEngine *cgEngine = static_cast<QCoreGraphicsPaintEngine*>(paintEngine); cgEngine->d_func()->hd = cgContext; // Set the resolution as a scaling ration of 72 (the default). CGContextScaleCTM(cgContext, 72 / resolution.hRes, 72 / resolution.vRes); CGContextScaleCTM(cgContext, 1, -1); CGContextTranslateCTM(cgContext, 0, -paper.height()); if (!fullPage) CGContextTranslateCTM(cgContext, page.x() - paper.x(), page.y() - paper.y()); cgEngine->d_func()->orig_xform = CGContextGetCTM(cgContext); cgEngine->d_func()->setClip(0); cgEngine->state->dirtyFlags = QPaintEngine::AllDirty; cgEngine->syncState(); return true; }
bool QPrinter::cmd(int c, QPainter *, QPDevCmdParam *) { if (!psession && PMCreateSession(&psession) != noErr) return FALSE; if (c == PdcBegin) { // begin; start printing if (state != PST_IDLE) { qDebug("Qt: internal: printer: two PdcBegin(s)."); return FALSE; } //just to be sure they've been setup prepare(&pformat); prepare(&psettings); //validate the settings if (PMSessionValidatePrintSettings(psession, psettings, kPMDontWantBoolean) != noErr) return FALSE; if (PMSessionValidatePageFormat(psession, pformat, kPMDontWantBoolean) != noErr) return FALSE; if (PMSessionBeginDocument(psession, psettings, pformat) != noErr) //begin the document return FALSE; if (PMSessionBeginPage(psession, pformat, 0) != noErr) //begin the page return FALSE; if (PMSessionGetGraphicsContext(psession, kPMGraphicsContextQuickdraw, &hd) != noErr) //get the gworld return FALSE; state = PST_ACTIVE; if (fullPage()) { uint top, left, bottom, right; qt_get_margins(pformat, &top, &left, &bottom, &right); QMacSavedPortInfo mp(this); SetOrigin(top, left); } else { QMacSavedPortInfo mp(this); SetOrigin(0, 0); } } else if (c == PdcEnd) { if (hd && state != PST_IDLE) { PMSessionEndPage(psession); PMSessionEndDocument(psession); hd = NULL; } state = PST_IDLE; } else { // all other commands... if (state == PST_ABORTED || ((state == PST_ACTIVE || state == PST_ERROR) && PMSessionError(psession) != noErr)) return FALSE; } return TRUE; }
/*------------------------------------------------------------------------------ Function: DoPrintLoop Parameters: Description: DoPrintLoop calculates which pages to print and executes the print loop, calling DrawPage for each page. ------------------------------------------------------------------------------*/ OSStatus DoPrintLoop(PrintingLogicPtr printJob) { OSStatus status = noErr, tempErr; CGContextRef printingContext; // Note, we don't have to worry about the number of copies. The printing // manager handles this. So we just iterate through the document from the // first page to be printed, to the last. // Note, we don't have to deal with the classic Printing Manager's // 128-page boundary limit. // Set up a page for printing. Under the classic Printing Manager, applications // could provide a page rect different from the one in the print record to achieve // scaling. This is no longer recommended and on Mac OS X, the PageRect argument // is ignored. // Now you are ready to request the printing context status = PMSessionGetGraphicsContext (printJob->printSession, kPMGraphicsContextCoreGraphics, (void **) &printingContext); if (status == noErr) { // Draw the page. status = DrawPage(printJob,printingContext); } // Only report a printing error once we have completed the print loop. This // ensures that every PMBeginXXX call that returns no error is followed by // a matching PMEndXXX call, so the Printing Manager can release all temporary // memory and close properly. tempErr = PMSessionError(printJob->printSession); if(status == noErr) status = tempErr; if (status == kPMCancel) status = noErr; return status; } // DoPrintLoop
//----------------------------------------------------------------------------------------------------------------------- static OSStatus DoPrintLoop(DocStoragePtr docStP, PMPrintSession printSession, PMPageFormat pageFormat, PMPrintSettings printSettings) { OSStatus status = noErr, tempErr; CGContextRef printingCtx; UInt32 realNumberOfPagesinDoc, pageNumber, firstPage, lastPage; CFStringRef jobName; // use window title status = CopyWindowTitleAsCFString(docStP->ownerWindow, &jobName); status = PMPrintSettingsSetJobName(printSettings, jobName); CFRelease (jobName); // Get the user's Print dialog selection for first and last pages to print. if (status == noErr) { status = PMGetFirstPage(printSettings, &firstPage); if (status == noErr) status = PMGetLastPage(printSettings, &lastPage); } // Check that the selected page range does not exceed the actual number of pages in the document. if (status == noErr) { status = DetermineNumberOfPagesInDoc(pageFormat, &realNumberOfPagesinDoc); if (realNumberOfPagesinDoc < lastPage) lastPage = realNumberOfPagesinDoc; } // Before executing the print loop, tell the Carbon Printing Manager which pages // will be spooled so that the progress dialog can reflect an accurate page count. if (status == noErr) status = PMSetFirstPage(printSettings, firstPage, false); if (status == noErr) status = PMSetLastPage(printSettings, lastPage, false); // Note, we don't have to worry about the number of copies. The printing // manager handles this. So we just iterate through the document from the // first page to be printed, to the last. if (status == noErr) { // Now, tell the printing system that we promise never to use any Quickdraw calls: status = PMSessionBeginCGDocument(printSession, printSettings, pageFormat); check(status == noErr); if (status == noErr) { pageNumber = firstPage; // Note that we check PMSessionError immediately before beginning a new page. // This handles user cancelling appropriately. Also, if we got an error on // any previous iteration of the print loop, we break out of the loop. while ( (pageNumber <= lastPage) && (status == noErr) && (PMSessionError(printSession) == noErr) ) { status = PMSessionBeginPage(printSession, pageFormat, NULL); check(status == noErr); if (status == noErr) { status = PMSessionGetCGGraphicsContext(printSession, &printingCtx); check(status == noErr); if (status == noErr) { DrawThePage(printingCtx, docStP); } tempErr = PMSessionEndPage(printSession); if(status == noErr) status = tempErr; } pageNumber++; } // end while loop // Close the print job. This dismisses the progress dialog on Mac OS X. tempErr = PMSessionEndDocument(printSession); if (status == noErr) status = tempErr; } } // Only report a printing error once we have completed the print loop. This ensures // that every PMBeginXXX call that returns no error is followed by a matching PMEndXXX // call, so the Printing Manager can release all temporary memory and close properly. tempErr = PMSessionError(printSession); if(status == noErr) status = tempErr; /* if ((status != noErr) && (status != kPMCancel)) PostPrintingErrors(status); */ return status; } // DoPrintLoop
// -------------------------------------------------------------------------------------- static OSStatus MyDoPrintLoop(PMPrintSession printSession, PMPageFormat pageFormat, PMPrintSettings printSettings, const void *ourDataP, const PrintingProcs *printingProcsP) { OSStatus err = noErr; OSStatus tempErr = noErr; UInt32 firstPage, lastPage, totalDocPages = MyGetDocumentNumPagesInDoc(ourDataP); if(!err) err = PMGetFirstPage(printSettings, &firstPage); if (!err) err = PMGetLastPage(printSettings, &lastPage); if(!err && lastPage > totalDocPages){ // don't draw more than the number of pages in our document lastPage = totalDocPages; } if (!err) // tell the printing system the number of pages we are going to print err = PMSetLastPage(printSettings, lastPage, false); // Note: we don't have to worry about the number of copies. The printing // manager handles this. So we just iterate through the document from the // first page to be printed, to the last. if (!err) { PageDrawProc *drawProc = GetMyDrawPageProc(ourDataP); err = printingProcsP->BeginDocumentProc(printSession, printSettings, pageFormat); if (!err){ UInt32 pageNumber = firstPage; // need to check errors from our print loop and errors from the session for each // time around our print loop before calling our BeginPageProc while(pageNumber <= lastPage && err == noErr && PMSessionError(printSession) == noErr) { err = printingProcsP->BeginPageProc(printSession, pageFormat, NULL); if (!err){ GrafPtr oldPort = NULL; void *printingContext = NULL; GetPort(&oldPort); // preserve the existing port err = PMSessionGetGraphicsContext(printSession, kPMGraphicsContextQuickdraw, (void **)&printingContext); if(!err){ Rect pageRect; SetPort((CGrafPtr)printingContext); GetPortBounds(printingContext, &pageRect); err = drawProc(ourDataP, &pageRect, pageNumber); // image the correct page SetPort(oldPort); // restore the prior port } // we must call EndPage if BeginPage returned noErr tempErr = printingProcsP->EndPageProc(printSession); if(!err)err = tempErr; } pageNumber++; } // end while loop // we must call EndDocument if BeginDocument returned noErr tempErr = printingProcsP->EndDocumentProc(printSession); if(!err)err = tempErr; if(!err) err = PMSessionError(printSession); } } return err; }
// -------------------------------------------------------------------------------------------------------------- static OSStatus MyDoPrintLoop(PMPrintSession printSession, PMPageFormat pageFormat, PMPrintSettings printSettings, const void *ourDataP) { OSStatus err = noErr; OSStatus tempErr = noErr; UInt32 firstPage, lastPage, totalDocPages = MyGetDocumentNumPagesInDoc(ourDataP); PMResolution res; float ourAppScaling = 1.; err = PMGetResolution(pageFormat, &res); if(!err){ ourAppScaling = res.hRes/72.; // the scale factor we are applying } if(!err) err = PMGetFirstPage(printSettings, &firstPage); if (!err) err = PMGetLastPage(printSettings, &lastPage); if(!err && lastPage > totalDocPages){ // don't draw more than the number of pages in our document lastPage = totalDocPages; } if (!err) // tell the printing system the number of pages we are going to print err = PMSetLastPage(printSettings, lastPage, false); if (!err) { PageDrawProc *drawProc = GetMyDrawPageProc(ourDataP); err = PMSessionBeginDocument(printSession, printSettings, pageFormat); if (!err){ UInt32 pageNumber; for(pageNumber = firstPage; err == noErr && (err = PMSessionError(printSession)) == noErr && pageNumber <= lastPage; pageNumber++ ){ err = PMSessionBeginPage(printSession, pageFormat, NULL); if (!err){ GrafPtr oldPort = NULL; void *printingContext = NULL; GetPort(&oldPort); // preserve the existing port err = PMSessionGetGraphicsContext(printSession, kPMGraphicsContextQuickdraw, (void **)&printingContext); if(!err){ SetPort((CGrafPtr)printingContext); err = drawProc(ourDataP, ourAppScaling); // supply app drawing resolution SetPort(oldPort); // restore the prior port } tempErr = PMSessionEndPage(printSession); if(!err)err = tempErr; } } // end for loop tempErr = PMSessionEndDocument(printSession); if(!err)err = tempErr; } } return err; }