forked from fjolnir/SVGPathSerializing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pathscaler.m
27 lines (23 loc) · 1.26 KB
/
pathscaler.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Example program that reads in an svg, scales it by a
// factor passed to it and writes the scaled SVG to stdout
#import "SVGPathSerializer.h"
int main(int argc, char *argv[])
{
NSCAssert(argc == 3, @"USAGE: pathscaler <scale> <svgPath>");
float const scale = [[NSString stringWithUTF8String:argv[1]] floatValue];
NSString * const svgPath = [NSString stringWithUTF8String:argv[2]];
NSString * const svg = [NSString stringWithContentsOfFile:svgPath usedEncoding:NULL error:NULL];
NSCAssert(svg, @"Failed to open SVG!");
NSMapTable *attributes;
NSArray * const inPaths = CGPathsFromSVGString(svg, &attributes);
NSMutableArray * const outPaths = [NSMutableArray arrayWithCapacity:[inPaths count]];
NSMapTable * const outAttributes = [NSMapTable strongToStrongObjectsMapTable];
CGAffineTransform const transform = CGAffineTransformMakeScale(scale, scale);
for(id path in inPaths) {
CGPathRef scaledPath = CGPathCreateCopyByTransformingPath((__bridge CGPathRef)path, &transform);
[outPaths addObject:(__bridge id)scaledPath];
[outAttributes setObject:[attributes objectForKey:path] forKey:(__bridge id)scaledPath];
}
printf("%s\n", [SVGStringFromCGPaths(outPaths, outAttributes) UTF8String]);
return 0;
}