On Jul 8, 2009, at 6:03 PM, David Alter wrote:

I have CGContextRef that I use for some quartz calls. It is a bitmap
context. I would like to set it as the current context so that I can use
NSString drawAtPoint: withAttributes:. I do not see how to do this.
NSGraphicContext setCurrentContext: takes a NSGraphicContext and not an
CGContextRef. I do not see a way to create a NSGraphicContext with a
CGContextRef. Nor do I see anything in the C API. So I'm a little unclear how I can set my bitmap Context to the current context so I can draw my
string. Anyone have any ideas.
thanks for the help.

In the world of NSGraphicsContext, a CGContextRef is known as a "graphicsPort".

So the routine you are looking for is:

+ (NSGraphicsContext *)graphicsContextWithGraphicsPort:(void *) graphicsPort flipped:(BOOL)initialFlippedState;

You should typecast your CGContext to (void *) and pass it as the graphicsPort argument.

Ater doing that you can use setCurrentContext. The whole thing looks something like this

[NSGraphicsContext saveGraphicsState];
[[NSGraphicsContext graphicsContextWithGraphicsPort: (void *) yourCGContextHere flipped: isFlipped] setCurrentContext];

... draw here...

[NSGraphicsContext restoreGraphicsState];

"Flipped" refers to the location of your origin and the orientation of your coordinate system. Set flipped to YES if you've moved the origin to the top left of the context and are using a left handed coordinate system (x axis to the right, y axis pointing down).

You are likely going to want the flipped coordinate system to draw text.

Scott

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to