diff --git a/IJSVGExample/IJSVGExample.xcodeproj/project.pbxproj b/IJSVGExample/IJSVGExample.xcodeproj/project.pbxproj index 488f192..5587dd1 100644 --- a/IJSVGExample/IJSVGExample.xcodeproj/project.pbxproj +++ b/IJSVGExample/IJSVGExample.xcodeproj/project.pbxproj @@ -42,6 +42,9 @@ 59A0E79D19B72EA7001BA157 /* IJSVGCommandArc.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A0E79C19B72EA7001BA157 /* IJSVGCommandArc.m */; }; 59A0E7A219B7333C001BA157 /* IJSVGLinearGradient.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A0E7A119B7333C001BA157 /* IJSVGLinearGradient.m */; }; 59A0E7A519B7334F001BA157 /* IJSVGDef.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A0E7A419B7334F001BA157 /* IJSVGDef.m */; }; + 59A11E6C19B89CEA00E44498 /* SVGExampleView1.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A11E6B19B89CEA00E44498 /* SVGExampleView1.m */; }; + 59A11E6F19B89D2000E44498 /* SVGExampleView2.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A11E6E19B89D2000E44498 /* SVGExampleView2.m */; }; + 59A11E7219B89D6600E44498 /* SVGExampleView3.m in Sources */ = {isa = PBXBuildFile; fileRef = 59A11E7119B89D6600E44498 /* SVGExampleView3.m */; }; 59B93C6D19B7D1840063E823 /* paperplane.svg in Resources */ = {isa = PBXBuildFile; fileRef = 59B93C6C19B7D1840063E823 /* paperplane.svg */; }; 59B93C6F19B7D32C0063E823 /* products.svg in Resources */ = {isa = PBXBuildFile; fileRef = 59B93C6E19B7D32C0063E823 /* products.svg */; }; 59F799E219B880CE00096CB7 /* htc_one.svg in Resources */ = {isa = PBXBuildFile; fileRef = 59F799E119B880CE00096CB7 /* htc_one.svg */; }; @@ -127,6 +130,12 @@ 59A0E7A119B7333C001BA157 /* IJSVGLinearGradient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IJSVGLinearGradient.m; path = ../../IJSVGLinearGradient.m; sourceTree = ""; }; 59A0E7A319B7334F001BA157 /* IJSVGDef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IJSVGDef.h; path = ../../IJSVGDef.h; sourceTree = ""; }; 59A0E7A419B7334F001BA157 /* IJSVGDef.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IJSVGDef.m; path = ../../IJSVGDef.m; sourceTree = ""; }; + 59A11E6A19B89CEA00E44498 /* SVGExampleView1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGExampleView1.h; sourceTree = ""; }; + 59A11E6B19B89CEA00E44498 /* SVGExampleView1.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGExampleView1.m; sourceTree = ""; }; + 59A11E6D19B89D2000E44498 /* SVGExampleView2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGExampleView2.h; sourceTree = ""; }; + 59A11E6E19B89D2000E44498 /* SVGExampleView2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGExampleView2.m; sourceTree = ""; }; + 59A11E7019B89D6600E44498 /* SVGExampleView3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGExampleView3.h; sourceTree = ""; }; + 59A11E7119B89D6600E44498 /* SVGExampleView3.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGExampleView3.m; sourceTree = ""; }; 59B93C6C19B7D1840063E823 /* paperplane.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = paperplane.svg; sourceTree = ""; }; 59B93C6E19B7D32C0063E823 /* products.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = products.svg; sourceTree = ""; }; 59F799E119B880CE00096CB7 /* htc_one.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = htc_one.svg; sourceTree = ""; }; @@ -179,6 +188,12 @@ 5956657A19B62F4600D805FF /* Supporting Files */, 595665DF19B630B600D805FF /* SVGView.h */, 595665E019B630B600D805FF /* SVGView.m */, + 59A11E6A19B89CEA00E44498 /* SVGExampleView1.h */, + 59A11E6B19B89CEA00E44498 /* SVGExampleView1.m */, + 59A11E6D19B89D2000E44498 /* SVGExampleView2.h */, + 59A11E6E19B89D2000E44498 /* SVGExampleView2.m */, + 59A11E7019B89D6600E44498 /* SVGExampleView3.h */, + 59A11E7119B89D6600E44498 /* SVGExampleView3.m */, ); path = IJSVGExample; sourceTree = ""; @@ -399,15 +414,18 @@ 595665C819B6302600D805FF /* IJSVGBezierPathAdditions.m in Sources */, 59A0E7A219B7333C001BA157 /* IJSVGLinearGradient.m in Sources */, 5956658019B62F4600D805FF /* AppDelegate.m in Sources */, + 59A11E6C19B89CEA00E44498 /* SVGExampleView1.m in Sources */, 595665D419B6302600D805FF /* IJSVGCommandVerticalLine.m in Sources */, 595665CD19B6302600D805FF /* IJSVGCommandCommandSmoothQuadraticCurve.m in Sources */, 595665D019B6302600D805FF /* IJSVGCommandLineTo.m in Sources */, 595665DA19B6302600D805FF /* IJSVGTransform.m in Sources */, 595665D619B6302600D805FF /* IJSVGGroup.m in Sources */, + 59A11E7219B89D6600E44498 /* SVGExampleView3.m in Sources */, 5956657D19B62F4600D805FF /* main.m in Sources */, 595665CC19B6302600D805FF /* IJSVGCommandClose.m in Sources */, 595665D119B6302600D805FF /* IJSVGCommandMove.m in Sources */, 5910114E19B75C9C009F8A35 /* IJSVGGradient.m in Sources */, + 59A11E6F19B89D2000E44498 /* SVGExampleView2.m in Sources */, 595665CA19B6302600D805FF /* IJSVGColor.m in Sources */, 595665DB19B6302600D805FF /* IJSVGUtils.m in Sources */, ); diff --git a/IJSVGExample/IJSVGExample.xcodeproj/project.xcworkspace/xcuserdata/curtishard.xcuserdatad/UserInterfaceState.xcuserstate b/IJSVGExample/IJSVGExample.xcodeproj/project.xcworkspace/xcuserdata/curtishard.xcuserdatad/UserInterfaceState.xcuserstate index 1c016ff..9d2845a 100644 Binary files a/IJSVGExample/IJSVGExample.xcodeproj/project.xcworkspace/xcuserdata/curtishard.xcuserdatad/UserInterfaceState.xcuserstate and b/IJSVGExample/IJSVGExample.xcodeproj/project.xcworkspace/xcuserdata/curtishard.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/IJSVGExample/IJSVGExample/Base.lproj/MainMenu.xib b/IJSVGExample/IJSVGExample/Base.lproj/MainMenu.xib index ff3205d..9e017cd 100644 --- a/IJSVGExample/IJSVGExample/Base.lproj/MainMenu.xib +++ b/IJSVGExample/IJSVGExample/Base.lproj/MainMenu.xib @@ -1,6 +1,7 @@ - + + @@ -669,12 +670,31 @@ - + - - + + + + + + + + + + + + + + + + + + + + + diff --git a/IJSVGExample/IJSVGExample/SVGExampleView1.h b/IJSVGExample/IJSVGExample/SVGExampleView1.h new file mode 100644 index 0000000..5fb0a21 --- /dev/null +++ b/IJSVGExample/IJSVGExample/SVGExampleView1.h @@ -0,0 +1,14 @@ +// +// SVGExampleView1.h +// IJSVGExample +// +// Created by Curtis Hard on 04/09/2014. +// Copyright (c) 2014 Curtis Hard. All rights reserved. +// + +#import +#import "SVGView.h" + +@interface SVGExampleView1 : SVGView + +@end diff --git a/IJSVGExample/IJSVGExample/SVGExampleView1.m b/IJSVGExample/IJSVGExample/SVGExampleView1.m new file mode 100644 index 0000000..82a8b2d --- /dev/null +++ b/IJSVGExample/IJSVGExample/SVGExampleView1.m @@ -0,0 +1,18 @@ +// +// SVGExampleView1.m +// IJSVGExample +// +// Created by Curtis Hard on 04/09/2014. +// Copyright (c) 2014 Curtis Hard. All rights reserved. +// + +#import "SVGExampleView1.h" + +@implementation SVGExampleView1 + +- (IJSVG *)svg +{ + return [[IJSVG svgNamed:@"paperplane"] retain]; +} + +@end diff --git a/IJSVGExample/IJSVGExample/SVGExampleView2.h b/IJSVGExample/IJSVGExample/SVGExampleView2.h new file mode 100644 index 0000000..4d53de6 --- /dev/null +++ b/IJSVGExample/IJSVGExample/SVGExampleView2.h @@ -0,0 +1,14 @@ +// +// SVGExampleView2.h +// IJSVGExample +// +// Created by Curtis Hard on 04/09/2014. +// Copyright (c) 2014 Curtis Hard. All rights reserved. +// + +#import +#import "SVGView.h" + +@interface SVGExampleView2 : SVGView + +@end diff --git a/IJSVGExample/IJSVGExample/SVGExampleView2.m b/IJSVGExample/IJSVGExample/SVGExampleView2.m new file mode 100644 index 0000000..f193a63 --- /dev/null +++ b/IJSVGExample/IJSVGExample/SVGExampleView2.m @@ -0,0 +1,18 @@ +// +// SVGExampleView2.m +// IJSVGExample +// +// Created by Curtis Hard on 04/09/2014. +// Copyright (c) 2014 Curtis Hard. All rights reserved. +// + +#import "SVGExampleView2.h" + +@implementation SVGExampleView2 + +- (IJSVG *)svg +{ + return [[IJSVG svgNamed:@"htc_one"] retain]; +} + +@end diff --git a/IJSVGExample/IJSVGExample/SVGExampleView3.h b/IJSVGExample/IJSVGExample/SVGExampleView3.h new file mode 100644 index 0000000..5418e4f --- /dev/null +++ b/IJSVGExample/IJSVGExample/SVGExampleView3.h @@ -0,0 +1,14 @@ +// +// SVGExampleView3.h +// IJSVGExample +// +// Created by Curtis Hard on 04/09/2014. +// Copyright (c) 2014 Curtis Hard. All rights reserved. +// + +#import +#import "SVGView.h" + +@interface SVGExampleView3 : SVGView + +@end diff --git a/IJSVGExample/IJSVGExample/SVGExampleView3.m b/IJSVGExample/IJSVGExample/SVGExampleView3.m new file mode 100644 index 0000000..e98178d --- /dev/null +++ b/IJSVGExample/IJSVGExample/SVGExampleView3.m @@ -0,0 +1,18 @@ +// +// SVGExampleView3.m +// IJSVGExample +// +// Created by Curtis Hard on 04/09/2014. +// Copyright (c) 2014 Curtis Hard. All rights reserved. +// + +#import "SVGExampleView3.h" + +@implementation SVGExampleView3 + +- (IJSVG *)svg +{ + return [[IJSVG svgNamed:@"products"] retain]; +} + +@end diff --git a/IJSVGExample/IJSVGExample/SVGView.m b/IJSVGExample/IJSVGExample/SVGView.m index 4037a00..4603d8c 100644 --- a/IJSVGExample/IJSVGExample/SVGView.m +++ b/IJSVGExample/IJSVGExample/SVGView.m @@ -16,15 +16,20 @@ [super dealloc]; } -- (id)initWithCoder:(NSCoder *)aDecoder +- (id)initWithFrame:(NSRect)frameRect { - if( ( self = [super initWithCoder:aDecoder] ) != nil ) + if( ( self = [super initWithFrame:frameRect] ) != nil ) { - svg = [[IJSVG svgNamed:@"test"] retain]; + svg = [self svg]; } return self; } +- (IJSVG *)svg +{ + return [[IJSVG svgNamed:@"test"] retain]; +} + - (void)drawRect:(NSRect)dirtyRect { CGContextRef ref = [[NSGraphicsContext currentContext] graphicsPort]; diff --git a/IJSVGNode.h b/IJSVGNode.h index dd630a6..83f38ef 100644 --- a/IJSVGNode.h +++ b/IJSVGNode.h @@ -12,6 +12,22 @@ @class IJSVGDef; @class IJSVGGradient; +typedef NS_OPTIONS( NSInteger, IJSVGNodeType ) { + IJSVGNodeTypeGroup, + IJSVGNodeTypePath, + IJSVGNodeTypeDef, + IJSVGNodeTypePolygon, + IJSVGNodeTypePolyline, + IJSVGNodeTypeRect, + IJSVGNodeTypeLine, + IJSVGNodeTypeCircle, + IJSVGNodeTypeEllipse, + IJSVGNodeTypeUse, + IJSVGNodeTypeLinearGradient, + IJSVGNodeTypeRadialGradient, + IJSVGNodeTypeNotFound +}; + typedef NS_OPTIONS( NSInteger, IJSVGWindingRule ) { IJSVGWindingRuleNonZero, IJSVGWindingRuleEvenOdd, @@ -22,6 +38,7 @@ static CGFloat IJSVGInheritedFloatValue = -99.9999991; @interface IJSVGNode : NSObject { + IJSVGNodeType type; NSString * name; CGFloat x; @@ -50,6 +67,7 @@ static CGFloat IJSVGInheritedFloatValue = -99.9999991; } +@property ( nonatomic, assign ) IJSVGNodeType type; @property ( nonatomic, copy ) NSString * name; @property ( nonatomic, assign ) CGFloat x; @property ( nonatomic, assign ) CGFloat y; @@ -68,6 +86,8 @@ static CGFloat IJSVGInheritedFloatValue = -99.9999991; @property ( nonatomic, retain ) IJSVGDef * def; @property ( nonatomic, retain ) IJSVGGradient * fillGradient; ++ (IJSVGNodeType)typeForString:(NSString *)string; + - (id)initWithDef:(BOOL)flag; - (void)addDef:(IJSVGNode *)aDef; - (IJSVGDef *)defForID:(NSString *)anID; diff --git a/IJSVGNode.m b/IJSVGNode.m index 828f40f..9987f11 100644 --- a/IJSVGNode.m +++ b/IJSVGNode.m @@ -11,6 +11,7 @@ @implementation IJSVGNode +@synthesize type; @synthesize name; @synthesize x; @synthesize y; @@ -31,6 +32,7 @@ - (void)dealloc { + [fillGradient release], fillGradient = nil; [transforms release], transforms = nil; [fillColor release], fillColor = nil; [strokeColor release], strokeColor = nil; @@ -40,6 +42,36 @@ [super dealloc]; } ++ (IJSVGNodeType)typeForString:(NSString *)string +{ + string = [string lowercaseString]; + if( [string isEqualToString:@"defs"] ) + return IJSVGNodeTypeDef; + if( [string isEqualToString:@"g"] ) + return IJSVGNodeTypeGroup; + if( [string isEqualToString:@"path"] ) + return IJSVGNodeTypePath; + if( [string isEqualToString:@"polygon"] ) + return IJSVGNodeTypePolygon; + if( [string isEqualToString:@"polyline"] ) + return IJSVGNodeTypePolyline; + if( [string isEqualToString:@"rect"] ) + return IJSVGNodeTypeRect; + if( [string isEqualToString:@"line"] ) + return IJSVGNodeTypeLine; + if( [string isEqualToString:@"circle"] ) + return IJSVGNodeTypeCircle; + if( [string isEqualToString:@"ellipse"] ) + return IJSVGNodeTypeEllipse; + if( [string isEqualToString:@"use"] ) + return IJSVGNodeTypeUse; + if( [string isEqualToString:@"lineargradient"] ) + return IJSVGNodeTypeLinearGradient; + if( [string isEqualToString:@"radialgradient"] ) + return IJSVGNodeTypeRadialGradient; + return IJSVGNodeTypeNotFound; +} + - (id)init { if( ( self = [self initWithDef:YES] ) != nil ) @@ -52,6 +84,7 @@ { IJSVGNode * node = [[self class] allocWithZone:zone]; node.name = self.name; + node.type = self.type; node.x = self.x; node.y = self.y; diff --git a/IJSVGParser.m b/IJSVGParser.m index fe3acb8..02c4d7b 100644 --- a/IJSVGParser.m +++ b/IJSVGParser.m @@ -229,222 +229,230 @@ intoGroup:(IJSVGGroup*)parentGroup def:(BOOL)flag { - - // if flag is yes, then anything we find inside this - // - for( NSXMLElement * element in [anElement children] ) { - NSString * subName = [[element name] lowercaseString]; - if( [subName isEqualToString:@"defs"] ) + NSString * subName = element.name; + IJSVGNodeType aType = [IJSVGNode typeForString:subName]; + switch( aType ) { - // any defs? - [self _parseBlock:element - intoGroup:parentGroup - def:YES]; - continue; + default: + case IJSVGNodeTypeNotFound: + continue; - } else if( [subName isEqualToString:@"g"] ) { - - // its a group - IJSVGGroup * group = [[[IJSVGGroup alloc] init] autorelease]; - group.name = subName; - group.parentNode = parentGroup; - - // find common attributes - [self _parseElementForCommonAttributes:element - node:group]; - [parentGroup addChild:group]; - - // recursively parse blocks - [self _parseBlock:element - intoGroup:group - def:NO]; - - // could be defined - if( def ) - [parentGroup addDef:group]; - - continue; - - } else if( [subName isEqualToString:@"path"] ) { - - // its a path - IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; - path.name = subName; - path.parentNode = parentGroup; - - // find common attributes - [self _parseElementForCommonAttributes:element - node:path]; - [self _parsePathCommandData:[[element attributeForName:@"d"] stringValue] - intoPath:path]; - [parentGroup addChild:path]; - - // could be defined - if( def ) - [parentGroup addDef:path]; - - continue; - - } else if( [subName isEqualToString:@"polygon"] ) { - - // its a polygon - IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; - path.name = subName; - path.parentNode = parentGroup; - - // find common attributes - [self _parseElementForCommonAttributes:element - node:path]; - [self _parsePolygon:element - intoPath:path]; - [parentGroup addChild:path]; - - // could be defined - if( def ) - [parentGroup addDef:path]; - - continue; - - } else if( [subName isEqualToString:@"polyline"] ) { - - // its a polyline - IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; - path.name = subName; - path.parentNode = parentGroup; - - // find common attributes - [self _parseElementForCommonAttributes:element - node:path]; - [self _parsePolyline:element - intoPath:path]; - [parentGroup addChild:path]; - - // could be defined - if( def ) - [parentGroup addDef:path]; - - continue; - - } else if( [subName isEqualToString:@"rect"] ) { - - // its a rect - IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; - path.name = subName; - path.parentNode = parentGroup; - - // find common attributes - [self _parseElementForCommonAttributes:element - node:path]; - [self _parseRect:element - intoPath:path]; - [parentGroup addChild:path]; - - // could be defined - if( def ) - [parentGroup addDef:path]; - - continue; - - } else if( [subName isEqualToString:@"line"] ) { - - // its a line - IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; - path.name = subName; - path.parentNode = parentGroup; - - // find common attributes - [self _parseElementForCommonAttributes:element - node:path]; - [self _parseLine:element - intoPath:path]; - [parentGroup addChild:path]; - - // could be defined - if( def ) - [parentGroup addDef:path]; - - continue; - - } else if( [subName isEqualToString:@"circle"] ) { - - // its a cirle - IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; - path.name = subName; - path.parentNode = parentGroup; - - // find common attributes - [self _parseElementForCommonAttributes:element - node:path]; - [self _parseCircle:element - intoPath:path]; - [parentGroup addChild:path]; - - // could be defined - if( def ) - [parentGroup addDef:path]; - - continue; - - } else if( [subName isEqualToString:@"ellipse"] ) { - - // its a ellipse - IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; - path.name = subName; - path.parentNode = parentGroup; - - // find common attributes - [self _parseElementForCommonAttributes:element - node:path]; - [self _parseEllipse:element - intoPath:path]; - [parentGroup addChild:path]; - - // could be defined - if( def ) - [parentGroup addDef:path]; - - continue; - - } else if( [subName isEqualToString:@"use"] ) { - - // its a use command - NSString * xlink = [[element attributeForName:@"xlink:href"] stringValue]; - NSString * xlinkID = [xlink substringFromIndex:1]; - IJSVGNode * node = [parentGroup defForID:xlinkID]; - if( node != nil ) - { - // copy the node - node = [[node copy] autorelease]; - node.parentNode = parentGroup; - - // grab the common attributes - [self _parseElementForCommonAttributes:element - node:node]; - [parentGroup addChild:node]; + // def + case IJSVGNodeTypeDef: { + [self _parseBlock:element + intoGroup:parentGroup + def:YES]; + continue; } - } else if( [subName isEqualToString:@"lineargradient"] ) { + // group + case IJSVGNodeTypeGroup: { + IJSVGGroup * group = [[[IJSVGGroup alloc] init] autorelease]; + group.type = aType; + group.name = subName; + group.parentNode = parentGroup; + + // find common attributes + [self _parseElementForCommonAttributes:element + node:group]; + [parentGroup addChild:group]; + + // recursively parse blocks + [self _parseBlock:element + intoGroup:group + def:NO]; + + // could be defined + if( def ) + [parentGroup addDef:group]; + continue; + } + + // path + case IJSVGNodeTypePath: { + IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; + path.type = aType; + path.name = subName; + path.parentNode = parentGroup; + + // find common attributes + [self _parseElementForCommonAttributes:element + node:path]; + [self _parsePathCommandData:[[element attributeForName:@"d"] stringValue] + intoPath:path]; + [parentGroup addChild:path]; + + // could be defined + if( def ) + [parentGroup addDef:path]; + continue; + } + + // polygon + case IJSVGNodeTypePolygon: { + IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; + path.type = aType; + path.name = subName; + path.parentNode = parentGroup; + + // find common attributes + [self _parseElementForCommonAttributes:element + node:path]; + [self _parsePolygon:element + intoPath:path]; + [parentGroup addChild:path]; + + // could be defined + if( def ) + [parentGroup addDef:path]; + continue; + } + + // polyline + case IJSVGNodeTypePolyline: { + IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; + path.type = aType; + path.name = subName; + path.parentNode = parentGroup; + + // find common attributes + [self _parseElementForCommonAttributes:element + node:path]; + [self _parsePolyline:element + intoPath:path]; + [parentGroup addChild:path]; + + // could be defined + if( def ) + [parentGroup addDef:path]; + continue; + } + + // rect + case IJSVGNodeTypeRect: { + IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; + path.type = aType; + path.name = subName; + path.parentNode = parentGroup; + + // find common attributes + [self _parseElementForCommonAttributes:element + node:path]; + [self _parseRect:element + intoPath:path]; + [parentGroup addChild:path]; + + // could be defined + if( def ) + [parentGroup addDef:path]; + continue; + } + + // line + case IJSVGNodeTypeLine: { + IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; + path.type = aType; + path.name = subName; + path.parentNode = parentGroup; + + // find common attributes + [self _parseElementForCommonAttributes:element + node:path]; + [self _parseLine:element + intoPath:path]; + [parentGroup addChild:path]; + + // could be defined + if( def ) + [parentGroup addDef:path]; + continue; + } + + // circle + case IJSVGNodeTypeCircle: { + IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; + path.type = aType; + path.name = subName; + path.parentNode = parentGroup; + + // find common attributes + [self _parseElementForCommonAttributes:element + node:path]; + [self _parseCircle:element + intoPath:path]; + [parentGroup addChild:path]; + + // could be defined + if( def ) + [parentGroup addDef:path]; + continue; + } + + // ellipse + case IJSVGNodeTypeEllipse: { + IJSVGPath * path = [[[IJSVGPath alloc] init] autorelease]; + path.type = aType; + path.name = subName; + path.parentNode = parentGroup; + + // find common attributes + [self _parseElementForCommonAttributes:element + node:path]; + [self _parseEllipse:element + intoPath:path]; + [parentGroup addChild:path]; + + // could be defined + if( def ) + [parentGroup addDef:path]; + continue; + } + + // use + case IJSVGNodeTypeUse: { + NSString * xlink = [[element attributeForName:@"xlink:href"] stringValue]; + NSString * xlinkID = [xlink substringFromIndex:1]; + IJSVGNode * node = [parentGroup defForID:xlinkID]; + if( node != nil ) + { + // copy the node + node = [[node copy] autorelease]; + node.parentNode = parentGroup; + + // grab the common attributes + [self _parseElementForCommonAttributes:element + node:node]; + [parentGroup addChild:node]; + } + continue; + } // linear gradient - IJSVGLinearGradient * gradient = [[[IJSVGLinearGradient alloc] init] autorelease]; - gradient.gradient = [IJSVGLinearGradient parseGradient:element - gradient:gradient]; - [self _parseElementForCommonAttributes:element - node:gradient]; - [parentGroup addDef:gradient]; - continue; - - } else if( [subName isEqualToString:@"radialgradient"] ) { - + case IJSVGNodeTypeLinearGradient: { + IJSVGLinearGradient * gradient = [[[IJSVGLinearGradient alloc] init] autorelease]; + gradient.type = aType; + gradient.gradient = [IJSVGLinearGradient parseGradient:element + gradient:gradient]; + [self _parseElementForCommonAttributes:element + node:gradient]; + [parentGroup addDef:gradient]; + continue; + } + // radial gradient - IJSVGRadialGradient * gradient = [[[IJSVGRadialGradient alloc] init] autorelease]; - gradient.gradient = [IJSVGRadialGradient parseGradient:element - gradient:gradient]; - [self _parseElementForCommonAttributes:element - node:gradient]; - [parentGroup addDef:gradient]; + case IJSVGNodeTypeRadialGradient: { + IJSVGRadialGradient * gradient = [[[IJSVGRadialGradient alloc] init] autorelease]; + gradient.type = aType; + gradient.gradient = [IJSVGRadialGradient parseGradient:element + gradient:gradient]; + [self _parseElementForCommonAttributes:element + node:gradient]; + [parentGroup addDef:gradient]; + continue; + } + } } }