In the creation of Lens•Lab, we had to figure out a way to create an art asset that contained visual detail that would scale from 10cm to 100m. we know Adobe Illustrator very well so we were hoping we could create the art asset there. The problem was this: we had to take this path in Illustrator and scale it programmatically in realtime over 4 orders of magnitude.
The solution we came up with is an Objective-C method that parses a specially prepared chunk of an Illustrator EPS file and creates a Cocoa CGPathRef object which one can then manipulate to one’s heart’s content.
Step 1: create your path in Illustrator. Since this is going to end up as a CGPathRef object, we won’t be getting any color or stroke data from Illustrator. So basically, limit yourself to one single shape (compound paths are fine), fill it with black, and then you’re done. Oh, and you have to flip it vertically because of differences in coordinate systems between Illustrator and Core Graphics. Save this artwork as an Illustrator 3 EPS with no preview.
Step 2: Open this EPS in your favorite text editor. Find the chunk between %%EndSetup and %%PageTrailer. Copy and paste this into either an NSString or a text file for reading in later.
Step 3: In your code,
CGPathRef yourPath = [ShapeUtilities createCGPathRefFromEPSString:yourString];
Oh look! I made you a zip archive with an Xcode 4 iPhone project all set up! And here’s what it looks like!
I’m sure this class could be extended to do much better (read: any) error checking and I suppose you could even try to parse appearance stuff as well. Perhaps even wrap up the CGPathRefs in an array if there are multiple shapes. Just go for it!