Re: Quartz2D paths from vector?
Re: Quartz2D paths from vector?
- Subject: Re: Quartz2D paths from vector?
- From: Graham Cox <email@hidden>
- Date: Thu, 18 Feb 2010 11:20:40 +1100
On 18/02/2010, at 6:02 AM, Paul Reilly wrote:
> shapes
> in something like Illustrator or Photoshop and then export the Path as a
> vector path,
> .AI or .EPS, and then convert that in to a set of points for NSBezier Path
> to use.
>
> Is anyone aware of a tool that will do that?
> Or is there any other way to import a curve path in to Quartz, without
> having to define
> it manually in code?
Hi Paul,
Since you asked much the same question on the DrawKit list, I assume you had no luck taking that approach?
As DK uses NSBezierPath internally to represent its paths, it's a simple matter to extract them. As NSBezierPath supports NSCoding, they can be archived and then loaded into another app where they can be used, perhaps as a resource. Note that NSBezierPath is just a wrapper around the CGContext... path methods you mentioned, though unfortunately NSBezierPath is not currently part of the iPhone OS (though I think a UIBezierPath class was added to the latest version, not sure how compatible it is with NSBezierPath).
You could use the DK Demo to draw the path, but you have the advantage that you have all the source code so adding a method to export a path in the form you want it would be easy to add. Getting that data from Illustrator is going to be hard work!
If you contact me off-list I can help you with adding a method to export a selected shape's path to a file if you want.
You can convert NSBezierPath to its CGPathRef counterpart as follows:
@implementation NSBezierPath (ExtraBezierUtilitiesCategory)
- (CGMutablePathRef) newMutableQuartzPath
{
NSInteger i, numElements;
// If there are elements to draw, create a CGMutablePathRef and draw.
numElements = [self elementCount];
if (numElements > 0)
{
CGMutablePathRef path = CGPathCreateMutable();
NSPoint points[3];
for (i = 0; i < numElements; ++i)
{
switch ([self elementAtIndex:i associatedPoints:points])
{
case NSMoveToBezierPathElement:
CGPathMoveToPoint(path, NULL, points[0].x, points[0].y);
break;
case NSLineToBezierPathElement:
CGPathAddLineToPoint(path, NULL, points[0].x, points[0].y);
break;
case NSCurveToBezierPathElement:
CGPathAddCurveToPoint(path, NULL, points[0].x, points[0].y,
points[1].x, points[1].y,
points[2].x, points[2].y);
break;
case NSClosePathBezierPathElement:
CGPathCloseSubpath(path);
break;
default:
break;
}
}
// the caller is responsible for releasing this ref when done
return path;
}
return nil;
}
@end
--Graham
_______________________________________________
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