For my Cocoa app I need to know whether a given CGContextRef is a PDF context (as opposed to a bitmap or screen context) in order to take a different rendering path in my CALayer’s drawInContext implementation. With the iOS SDK, I can do this with:
BOOL isPDF = !CGRectIsEmpty(UIGraphicsGetPDFContextBounds());
But UIGraphics* functions aren’t available in the OS X SDK. I was hoping to be able to use:
BOOL isPDf = CFGetTypeID(currentContext) != CGContextGetTypeID();
But it doesn’t seem to hold true, and there is no CGPDFContextGetTypeID() function that returns a type ID specific to PDFs.
Is there any way to identify the type of a given CGContextRef without doing anything nasty like setting static variables?
There is no public API for getting the type of a
CGContextRef, so you will have to keep this information outside of the context ref itself.There is an undocumented CGContextGetType() function that returns the type of the context, see the CGContextType enum for a list of possible values. But you should really not use this.