diff --git a/IJSVGExample/IJSVGExample.xcodeproj/project.xcworkspace/xcshareddata/IJSVGExample.xcscmblueprint b/IJSVGExample/IJSVGExample.xcodeproj/project.xcworkspace/xcshareddata/IJSVGExample.xcscmblueprint new file mode 100644 index 0000000..df978bb --- /dev/null +++ b/IJSVGExample/IJSVGExample.xcodeproj/project.xcworkspace/xcshareddata/IJSVGExample.xcscmblueprint @@ -0,0 +1,30 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "D72EFE5A8E718DCC42CFCBCE6A16E2165A4F6596", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "D72EFE5A8E718DCC42CFCBCE6A16E2165A4F6596" : 0, + "91965C60FB9217304DAC6A57C88233440365843F" : 9223372036854775807 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "83EE8FFF-CAF0-4D33-92A0-4CA5D3A6A33C", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "D72EFE5A8E718DCC42CFCBCE6A16E2165A4F6596" : "IJSVG\/", + "91965C60FB9217304DAC6A57C88233440365843F" : "..\/..\/.." + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "IJSVGExample", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "IJSVGExample\/IJSVGExample.xcodeproj", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/daveyheuser\/Iconjar-mac.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "91965C60FB9217304DAC6A57C88233440365843F" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/curthard89\/IJSVG.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "D72EFE5A8E718DCC42CFCBCE6A16E2165A4F6596" + } + ] +} \ No newline at end of file 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 dc0824c..112f13b 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/SVGView.m b/IJSVGExample/IJSVGExample/SVGView.m index 49bac61..8578532 100644 --- a/IJSVGExample/IJSVGExample/SVGView.m +++ b/IJSVGExample/IJSVGExample/SVGView.m @@ -31,15 +31,7 @@ - (IJSVG *)svg { - - IJSVG * anSVG = [IJSVG svgNamed:@"test"]; - IJSVGExporter * exporter = [[IJSVGExporter alloc] initWithSVG:anSVG - options:IJSVGExporterOptionAll]; - - [exporter.SVGData writeToFile:@"/users/curtishard/Desktop/omg.svg" atomically:YES]; - [exporter release]; - - return [anSVG retain]; + return [IJSVG svgNamed:@"test"]; } - (void)drawRect:(NSRect)dirtyRect diff --git a/source/IJSVGLayerTree.m b/source/IJSVGLayerTree.m index 6c8bc41..86fc5c9 100644 --- a/source/IJSVGLayerTree.m +++ b/source/IJSVGLayerTree.m @@ -270,6 +270,7 @@ fromNode:path]; // reset the node + BOOL moveStrokeLayer = NO; if(self.strokeColor == nil && path.strokeGradient != nil) { // force reset of the mask colour as we need to use the stroke layer @@ -277,10 +278,11 @@ strokeLayer.strokeColor = [NSColor blackColor].CGColor; // create the gradient - IJSVGGradientLayer * gradLayer = [self gradientLayerForLayer:layer - gradient:path.strokeGradient - fromNode:path]; - // set the mask for it + IJSVGGradientLayer * gradLayer = [self gradientStrokeLayerForLayer:layer + gradient:path.strokeGradient + fromNode:path]; + + moveStrokeLayer = YES; gradLayer.mask = strokeLayer; gradLayer.opacity = strokeLayer.opacity; @@ -295,11 +297,12 @@ strokeLayer.strokeColor = [NSColor blackColor].CGColor; // create the pattern - IJSVGPatternLayer * patternLayer = [self patternLayerForLayer:layer - pattern:path.strokePattern - fromNode:path]; + IJSVGPatternLayer * patternLayer = [self patternStrokeLayerForLayer:layer + pattern:path.strokePattern + fromNode:path]; // set the mask for it + moveStrokeLayer = YES; patternLayer.mask = strokeLayer; patternLayer.opacity = strokeLayer.opacity; @@ -313,6 +316,18 @@ [layer addSublayer:strokeLayer]; layer.strokeLayer = (IJSVGStrokeLayer *)strokeLayer; } + + // if we required to move the stroke layer + // then move it in based on half of what the stroke + // width is, as strokes are draw on the center + if(moveStrokeLayer) { + CGFloat strokeWidth = path.strokeWidth.value; + CGRect rect = strokeLayer.frame; + rect.origin.x += (strokeWidth*.5f); + rect.origin.y += (strokeWidth*.5f); + strokeLayer.frame = rect; + } + } // apply masking @@ -322,6 +337,51 @@ return (IJSVGLayer *)layer; } +- (CGRect)correctBounds:(CGRect)bounds + forStrokedPath:(IJSVGNode *)path +{ + CGFloat val = path.strokeWidth.value; + bounds.origin.x -= (val*.5f); + bounds.origin.y -= (val*.5f); + bounds.size.width += val; + bounds.size.height += val; + return bounds; +} + +- (IJSVGGradientLayer *)gradientStrokeLayerForLayer:(IJSVGShapeLayer *)layer + gradient:(IJSVGGradient *)gradient + fromNode:(IJSVGNode *)path +{ + // the gradient drawing layer + IJSVGGradientLayer * gradLayer = [[[IJSVGGradientLayer alloc] init] autorelease]; + gradLayer.gradient = gradient; + + // is there a fill opacity? + if(path.fillOpacity.value != 0.f) { + gradLayer.opacity = path.fillOpacity.value; + } + + // set the bounds + CGRect bounds = CGPathGetBoundingBox(layer.path); + bounds = [self correctBounds:bounds forStrokedPath:path]; + gradLayer.frame = bounds; + + // display it + [gradLayer setNeedsDisplay]; + + if(path.fillGradient.units == IJSVGUnitUserSpaceOnUse) { + // move back if needed + gradLayer.frame = (CGRect){ + .size = gradLayer.frame.size, + .origin = CGPointMake(-fabs(gradLayer.frame.origin.x), + -fabs(gradLayer.frame.origin.y)) + }; + } + + return gradLayer; +} + + - (IJSVGGradientLayer *)gradientLayerForLayer:(IJSVGShapeLayer *)layer gradient:(IJSVGGradient *)gradient fromNode:(IJSVGNode *)path @@ -348,14 +408,39 @@ // move back if needed gradLayer.frame = (CGRect){ .size = gradLayer.frame.size, - .origin = CGPointMake(-(gradLayer.frame.origin.x), - -(gradLayer.frame.origin.y)) + .origin = CGPointMake(-fabs(gradLayer.frame.origin.x), + -fabs(gradLayer.frame.origin.y)) }; } return gradLayer; } +- (IJSVGPatternLayer *)patternStrokeLayerForLayer:(IJSVGShapeLayer *)layer + pattern:(IJSVGPattern *)pattern + fromNode:(IJSVGNode *)path +{ + // create the pattern, this is actually not as easy as it may seem + IJSVGPatternLayer * patternLayer = [[[IJSVGPatternLayer alloc] init] autorelease]; + patternLayer.patternNode = pattern; + patternLayer.pattern = [self layerForNode:pattern]; + + // is there a fill opacity? + if(path.fillOpacity.value != 0.f) { + patternLayer.opacity = path.fillOpacity.value; + } + + // set the bounds + CGRect bounds = CGPathGetBoundingBox(layer.path); + bounds = [self correctBounds:bounds forStrokedPath:path]; + patternLayer.frame = bounds; + + // display + [patternLayer setNeedsDisplay]; + + return patternLayer; +} + - (IJSVGPatternLayer *)patternLayerForLayer:(IJSVGShapeLayer *)layer pattern:(IJSVGPattern *)pattern fromNode:(IJSVGNode *)path diff --git a/source/IJSVGParser.m b/source/IJSVGParser.m index bc78463..6d1e205 100644 --- a/source/IJSVGParser.m +++ b/source/IJSVGParser.m @@ -838,7 +838,7 @@ NSString * xlink = [[element attributeForName:(NSString *)IJSVGAttributeXLink] stringValue]; NSString * xlinkID = [xlink substringFromIndex:1]; - IJSVGNode * node = [parentGroup defForID:xlinkID]; + IJSVGNode * node = [self definedObjectForID:xlinkID]; if( node != nil ) { // we are a clone IJSVGLinearGradient * grad = [[[IJSVGLinearGradient alloc] init] autorelease]; @@ -884,7 +884,7 @@ NSString * xlink = [[element attributeForName:(NSString *)IJSVGAttributeXLink] stringValue]; NSString * xlinkID = [xlink substringFromIndex:1]; - IJSVGNode * node = [parentGroup defForID:xlinkID]; + IJSVGNode * node = [self definedObjectForID:xlinkID]; if( node != nil ) { // we are a clone