Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing with CGContexts




On Jan 27, 2006, at 1:12 PM, Eric Gorr wrote:

I've including my printing code at the end of this message. The end result is a
blank page.


page&paper bounds looks fine as does destinationRect.

Any idea what might be going on?

CGContextBeginPage and CGContextEndPage are for generating PDFs. I might even argue that they should not be in the abstract CGContextAPI. However they shouldn't affect your drawing.


CGContextSetAntialias is likely to be a no-op for a printer context. Antialiasing only makes sense for bitmap contexts but most printers go through a high-resolution PDF rasterization path where antialiasing doesn't apply.

You never set a stroke color or line width... you might try setting those things explicitly.

It's been a while since I worked with Carbon printing. I have this tickle at the back of my brain which says you don't want to be working with the adjusted page rects. I believe the "adjustment" is already incorporated into the CGContext's transform as is the paper to page transformation. A lot of your code appears to be directed toward adding this transformation.

I would try removing the CTM transform and see if you get a mark on the page.

graphicsContexts = CFArrayCreate( NULL, (const void **) &contextType, 1,
&kCFTypeArrayCallBacks );


stErr = PMSessionSetDocumentFormatGeneration( printSession, kPMDocumentFormatDefault, graphicsContexts, NULL );
stErr = PMSessionBeginDocument( printSession, printSettings, pageFormat );
stErr = PMSessionBeginPage( printSession, pageFormat, NULL );
stErr = PMSessionGetGraphicsContext( printSession,
kPMGraphicsContextCoreGraphics,
(void**)&printingContext );


    PMRect  pageBounds, paperBounds;

    PMGetAdjustedPageRect( pageFormat, &pageBounds );
    float carbonPageWidth   = pageBounds.right - pageBounds.left;
    float carbonPageHeight  = pageBounds.bottom - pageBounds.top;

    PMGetAdjustedPaperRect( pageFormat, &paperBounds );
    float carbonPaperWidth  = paperBounds.right - paperBounds.left;
    float carbonPaperHeight = paperBounds.bottom - paperBounds.top;

    CGRect destinationRect;
    destinationRect.size.height = carbonPageHeight;
    destinationRect.size.width  = carbonPageWidth;
    destinationRect.origin.x    = pageBounds.left;
    destinationRect.origin.y    = pageBounds.top;

double paperToPageYOffset = carbonPaperHeight + paperBounds.top - carbonPageHeight;
double xOffset = -paperBounds.left;


    CGContextBeginPage( printingContext, &destinationRect );

CGContextTranslateCTM( printingContext, xOffset, paperToPageYOffset );
CGContextSetShouldAntialias( printingContext, false );


      CGContextBeginPath( printingContext );
      CGContextMoveToPoint( printingContext, 10, 10 );
      CGContextAddLineToPoint( printingContext, 20, 20 );
      CGContextStrokePath( printingContext );

    CGContextEndPage( printingContext );

stErr = PMSessionEndPage( printSession );
stErr = PMSessionEndDocument( printSession );
stErr = PMSessionError( printSession );

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Carbon-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Printing with CGContexts (From: Eric Gorr <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.