Determining CGContext type at runtime


Graham Cox
 

I need to determine whether I am drawing into a CGPDFContext or a different context at runtime.

In AppKit, I can use [NSGraphicsContext currentContextDrawingToScreen], but this is code that is passed a CGContextRef only, so that higher-level API isn’t appropriate. CGPDFContext doesn’t appear to have an associated CGPDFContextGetTypeID() function to compare with the result of CFGetTypeID(), so it’s unclear how I can do this.

The reason I need to so this is that objects I am drawing can have different states according to whether they are selected in the UI or not, but when capturing the drawing into a PDF, the selection state needs to be ignored, so the drawing code needs to be able to detect what context type is so that it can do this.

—Graham

Join cocoa@apple-dev.groups.io to automatically receive all group messages.