Search code examples
objective-cquartz-graphicsquartz-2dcgpath

CGPath as a string


Is there any way to get at the actual data of a CGPath, so it can be saved to a file and restored later?

And is there any documentation on how that data is structured?

I would like to write it as a string (like a SVG path string), or some way with the dictionary object and PList XML files, but I'll take what I can get!


Solution

  • There is a post about saving CGPathRefs here. The guy is using CGPathApply function to enumerate through the elements of the path:

    static void saveApplier(void* info, const CGPathElement* element) {
        ...
    }
    
    ...
    
    NSMutableArray* a = [NSMutableArray arrayWithObject:[NSNumber numberWithBool:YES]];
    CGPathApply(path, a, saveApplier);