Re: NSGraphicsContext restore crashes my xtension
Re: NSGraphicsContext restore crashes my xtension
- Subject: Re: NSGraphicsContext restore crashes my xtension
- From: Jean-Daniel Dupas <email@hidden>
- Date: Mon, 28 Jul 2008 10:40:00 +0200
Le 28 juil. 08 à 10:17, Ken Tozier a écrit :
On Jul 28, 2008, at 2:42 AM, Ken Ferry wrote:
Graham's suggestion is also better because -[NSGraphicsContext
setCurrentContext:] just releases the context that was previously
current, as opposed to autoreleasing it.
So this has a bug:
NSGraphicsContext *originalContext = [NSGraphicsContext
currentContext];
[NSGraphicsContext setCurrentContext:newContext]; // bad!
originalContext may get deallocated here
// do stuff
[NSGraphicsContext setCurrentContext:originalContext];
Maybe I'm just misunderstanding what saveGraphicsState does, behind
the scenes, but I actually need to draw into the passed in
CGPDFContext, not any sort of view/image/winbow context. Best I can
figure, this requires a forced context switch, not just saving and
restoring the graphics state of whatever context happens to be
current.
I couldn't find any way to draw into a CGGraphicsContext with NSxxx
drawing commands without first creating a new context from the
CGContext and second manually setting this context to be the current
one. Is there a better/cleaner way?
Quartz does not have "current context" concept. This is a Cocoa
concept introduced by NSGraphicsContext. All Cocoa drawing methods are
using the current NSGraphocsContext, so you have to set it to the
appropriate value.
If you want to use Cocoa method to draw into a CGContext, you have to
first create a NSGraphicsContext with it, and then setting this
context as current.
save/restore state is used to save the context current state (line
width, shadow, clipping, colors, ...), not to save the current context.
From the Cocoa Drawing Guide:
“To save the current graphics state, you use the saveGraphicsState
method of NSGraphicsContext. This method essentially pushes a copy of
the current state onto a stack, leaving you free to make changes to
the current state. When you want to revert back to the previous state,
you simply call therestoreGraphicsState method to pop the current
graphics state (including all changes since the last save) off of the
stack and restore the previous state.”
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden