Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc )
{
    if ( m_err )
        return ;

    wxPrinterDCImpl *impl = (wxPrinterDCImpl*) dc->GetImpl();
    wxOSXPrintData *native = (wxOSXPrintData*) impl->GetPrintData().GetNativeData() ;

    m_err = PMSessionBeginPageNoDialog(native->GetPrintSession(),
                 native->GetPageFormat(),
                 NULL);

    CGContextRef pageContext;

    if ( m_err == noErr )
    {
        m_err = PMSessionGetCGGraphicsContext(native->GetPrintSession(),
                                            &pageContext );
    }

    if ( m_err != noErr )
    {
        PMSessionEndPageNoDialog(native->GetPrintSession());
        PMSessionEndDocumentNoDialog(native->GetPrintSession());
    }
    else
    {
        PMRect paperRect ;
        m_err = PMGetAdjustedPaperRect( native->GetPageFormat() , &paperRect ) ;
        // make sure (0,0) is at the upper left of the printable area (wx conventions)
        // Core Graphics initially has the lower left of the paper as 0,0
        if ( !m_err )
            CGContextTranslateCTM( pageContext , (CGFloat) -paperRect.left , (CGFloat) paperRect.bottom ) ;
        
        // since this is a non-critical error, we set the flag back
        m_err = noErr ;

        // Leopard deprecated PMSetResolution() which will not be available in 64 bit mode, so we avoid using it.
        // To set the proper drawing resolution, the docs suggest the use of CGContextScaleCTM(), so here we go; as a
        // consequence though, PMGetAdjustedPaperRect() and PMGetAdjustedPageRect() return unscaled rects, so we
        // have to manually scale them later.
        CGContextScaleCTM( pageContext, 72.0 / (double)m_ppi.x, -72.0 / (double)m_ppi.y);

        impl->SetGraphicsContext( wxGraphicsContext::CreateFromNative( pageContext ) );
    }
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------------------------------------------------
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
Ejemplo n.º 4
0
void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc )
{
    if ( m_err )
        return ;

    wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().GetNativeData() ;

    m_err = PMSessionBeginPage(native->m_macPrintSession,
                 native->m_macPageFormat,
                 nil);

#if wxMAC_USE_CORE_GRAPHICS
    CGContextRef pageContext;
#endif
    if ( m_err == noErr )
    {
#if wxMAC_USE_CORE_GRAPHICS
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
        m_err = PMSessionGetCGGraphicsContext(native->m_macPrintSession,
                                            &pageContext );

#else
        m_err = PMSessionGetGraphicsContext(native->m_macPrintSession,
                                            kPMGraphicsContextCoreGraphics,
                                            (void**) &pageContext );
#endif
#else
        m_err = PMSessionGetGraphicsContext(native->m_macPrintSession,
                                            kPMGraphicsContextQuickdraw,
                                            (void**) &dc->m_macPort );
#endif
    }

    if ( m_err != noErr )
    {
        PMSessionEndPage(native->m_macPrintSession);
        PMSessionEndDocument(native->m_macPrintSession);
    }
    else
    {
        PMRect rPage;

        m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
        if ( !m_err )
        {
#if wxMAC_USE_CORE_GRAPHICS
            PMRect paperRect ;
            PMGetAdjustedPaperRect( native->m_macPageFormat , &paperRect ) ;
            // make sure (0,0) is at the upper left of the printable area (wx conventions)
            // Core Graphics initially has the lower left of the paper as 0,0
            CGContextTranslateCTM( pageContext , -paperRect.left , paperRect.bottom ) ;
            CGContextScaleCTM( pageContext , 1 , -1 ) ;
#else
            dc->m_macLocalOrigin.x = (int) rPage.left;
            dc->m_macLocalOrigin.y = (int) rPage.top;
#endif
        }
        // since this is a non-critical error, we set the flag back
        m_err = noErr ;
    }
#if wxMAC_USE_CORE_GRAPHICS
    dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( pageContext ) );
#endif
}