Skip to content

Commit

Permalink
Merge pull request #14 from JagieChen/master
Browse files Browse the repository at this point in the history
To support the SVG files  exported by Sketch/omniGraffle
  • Loading branch information
arielelkin committed May 14, 2013
2 parents 79c0c61 + 21445fc commit c89fe04
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
14 changes: 11 additions & 3 deletions PocketSVG.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
NSInteger const maxPathComplexity = 1000;
NSInteger const maxParameters = 64;
NSInteger const maxTokenLength = 64;
NSString* const separatorCharString = @"-,CcMmLlHhVvZzqQaAsS";
NSString* const separatorCharString = @"-, CcMmLlHhVvZzqQaAsS";
NSString* const commandCharString = @"CcMmLlHhVvZzqQaAsS";
unichar const invalidCommand = '*';

Expand Down Expand Up @@ -143,8 +143,9 @@ -(NSString *)parseSVGNamed:(NSString *)nameOfSVG{
dString = [dString substringFromIndex:1];
NSRange d = [dString rangeOfString:@"\""];
dString = [dString substringToIndex:d.location];
// dString = [dString stringByReplacingOccurrencesOfString:@" " withString:@"-"];

NSArray *dStringWithPossibleWhiteSpace = [dString componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSArray *dStringWithPossibleWhiteSpace = [dString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

dString = [dStringWithPossibleWhiteSpace componentsJoinedByString:@""];

Expand Down Expand Up @@ -194,9 +195,15 @@ - (NSMutableArray *)parsePath:(NSString *)attr

NSInteger index = 0;
while (index < [attr length]) {
unichar charAtIndex = [attr characterAtIndex:index];
//Jagie:Skip whitespace
if (charAtIndex == 32) {
index ++;
continue;
}
NSMutableString *stringToken = [[NSMutableString alloc] initWithCapacity:maxTokenLength];
[stringToken setString:@""];
unichar charAtIndex = [attr characterAtIndex:index];

if (charAtIndex != ',') {
[stringToken appendString:[NSString stringWithFormat:@"%c", charAtIndex]];
}
Expand All @@ -208,6 +215,7 @@ - (NSMutableArray *)parsePath:(NSString *)attr
else {
index++;
}

if ([stringToken length]) {
[stringTokens addObject:stringToken];
}
Expand Down
3 changes: 3 additions & 0 deletions exportedFromSketch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions iOS Example/PocketSVG.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
18DEF6DE17428A01006BD8BB /* exportedFromSketch.svg in Resources */ = {isa = PBXBuildFile; fileRef = 18DEF6DD17428A01006BD8BB /* exportedFromSketch.svg */; };
B039268D163F072100EF033B /* PocketSVG.m in Sources */ = {isa = PBXBuildFile; fileRef = B039268C163F072100EF033B /* PocketSVG.m */; };
B0392691163F072800EF033B /* BezierCurve1.svg in Resources */ = {isa = PBXBuildFile; fileRef = B039268E163F072800EF033B /* BezierCurve1.svg */; };
B0392692163F072800EF033B /* BezierCurve2.svg in Resources */ = {isa = PBXBuildFile; fileRef = B039268F163F072800EF033B /* BezierCurve2.svg */; };
Expand All @@ -24,6 +25,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
18DEF6DD17428A01006BD8BB /* exportedFromSketch.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = exportedFromSketch.svg; path = ../../exportedFromSketch.svg; sourceTree = "<group>"; };
B039268B163F072100EF033B /* PocketSVG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PocketSVG.h; path = ../../PocketSVG.h; sourceTree = "<group>"; };
B039268C163F072100EF033B /* PocketSVG.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PocketSVG.m; path = ../../PocketSVG.m; sourceTree = "<group>"; };
B039268E163F072800EF033B /* BezierCurve1.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = BezierCurve1.svg; path = ../../BezierCurve1.svg; sourceTree = "<group>"; };
Expand Down Expand Up @@ -92,6 +94,7 @@
B0A9DB9615CA9B340095DFAF /* PocketSVG */ = {
isa = PBXGroup;
children = (
18DEF6DD17428A01006BD8BB /* exportedFromSketch.svg */,
B039268E163F072800EF033B /* BezierCurve1.svg */,
B039268F163F072800EF033B /* BezierCurve2.svg */,
B0392690163F072800EF033B /* BezierCurve3.svg */,
Expand Down Expand Up @@ -175,6 +178,7 @@
B0392691163F072800EF033B /* BezierCurve1.svg in Resources */,
B0392692163F072800EF033B /* BezierCurve2.svg in Resources */,
B0392693163F072800EF033B /* BezierCurve3.svg in Resources */,
18DEF6DE17428A01006BD8BB /* exportedFromSketch.svg in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion iOS Example/PocketSVG/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (void)viewDidLoad
[super viewDidLoad];

//1: Create a PocketSVG object from your SVG file:
PocketSVG *myVectorDrawing = [[PocketSVG alloc] initFromSVGFileNamed:@"BezierCurve3"];
PocketSVG *myVectorDrawing = [[PocketSVG alloc] initFromSVGFileNamed:@"exportedFromSketch"];


//2: Its bezier property is the corresponding UIBezierPath:
Expand Down

0 comments on commit c89fe04

Please sign in to comment.