Uibezierpath to Svg

How to encode UIBezierPath to SVG?

I tested yet. but using following steps: Would not it be possible?

1.UIBezierPath to CGPathRef. UIBezierPath to CGPathRef

2.Using a MROGeometry CGPathRef To SVG.

How to import/parse SVG into UIBezierpaths, NSBezierpaths, CGPaths?

Alright folks, if you're willing to pay for it. This tool will solve all your issues. You can import svg or psd and will produce the code for you. I've used it and it is amazing!

http://www.paintcodeapp.com/

UIBezierPath subpaths which forms closed path cannot be represented in SVG

I'm not sure to understand, but you can use as many beziers path as you want in the same curve. Here is a way: http://jsfiddle.net/74os2um3/

Just put it in one <path> and add a Z to close it.

<path  d="M1013.3,1228.7 C1007.1,1238.4 991.4,1242.6 984.2,1242.6 L984.2,1233.6 C995.1,1237.3 1008.3,1231.7 1013.2,1231.7 L1013.2,1221.3 C1018.0,1210.9 1013.8,1197.1 1004.0,1197.1 Z" />

Turn a BezierPath into an SVG file

Here is one solution that solves my problem. But it only works for Bezier paths. Observe that I am only filling out the path data. This has to be preceded with some static text of type below. If anybody has a more general or nicer solution, I would like to hear it.

<?xml version="1.0" encoding="utf-8"?>
...
stroke-linejoin="round

Observe also that I am using a canvas which is 200x200 (hence 200 when flipping y coordinates).

-(NSString *)svgFromBezierPath:(NSBezierPath *)path {
int numElements = (int) [path elementCount];
if (numElements == 0) {
return nil;
}

NSString *result = @"d=\"";
NSPoint points[3];
NSString *xStr;
NSString *yStr;
NSString *xCp1;
NSString *yCp1;
NSString *xCp2;
NSString *yCp2;
NSString *temp;
double yValue;

for (int i=0; i < numElements; i++)
{
switch ([path elementAtIndex:i associatedPoints:points])
{
case NSMoveToBezierPathElement:
xStr = [NSString stringWithFormat:@"%0.2f", points[0].x];
yValue = 200 - points[0].y;
yStr = [NSString stringWithFormat:@"%0.2f", yValue];

temp = [NSString stringWithFormat:@"M%@,%@,",xStr, yStr];
result = [result stringByAppendingString:temp];
break;

case NSLineToBezierPathElement:
xStr = [NSString stringWithFormat:@"%0.2f", points[0].x];
yValue = 200 - points[0].y;
yStr = [NSString stringWithFormat:@"%0.2f", yValue];

temp = [NSString stringWithFormat:@"L%@,%@,",xStr, yStr];
result = [result stringByAppendingString:temp];
break;

case NSCurveToBezierPathElement:
xStr = [NSString stringWithFormat:@"%0.2f", points[0].x];
yValue = 200 - points[0].y;
yStr = [NSString stringWithFormat:@"%0.2f", yValue];

xCp1 = [NSString stringWithFormat:@"%0.2f", points[1].x];
yValue = 200 - points[1].y;
yCp1= [NSString stringWithFormat:@"%0.2f", yValue];

xCp2 = [NSString stringWithFormat:@"%0.2f", points[2].x];
yValue = 200 - points[2].y;
yCp2= [NSString stringWithFormat:@"%0.2f", yValue];

temp = [NSString stringWithFormat:@"C%@,%@,%@,%@,%@,%@,", xStr, yStr, xCp1, yCp1,xCp2, yCp2];
result = [result stringByAppendingString:temp];
break;

case NSClosePathBezierPathElement:
result = [result stringByAppendingString:@"z,"];
break;
}
}

result = [result substringToIndex:result.length-1]; // delete the trailing comma
result = [result stringByAppendingString:@"\"/></svg>"];
return result;
}

How to create a CGPath from a file — i.e. SVG

Seems like there is a more clever solution SVGKit:

SVGKit is a Cocoa framework for rendering SVG files as Core Animation layers. All shapes are represented by instances of the CAShapeLayer class, and are, by design, animatable. SVGKit is compatible with the latest Mac OS X and iOS SDK's.



Related Topics



Leave a reply



Submit