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 7f784b5..fe0baa3 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/source/IJSVG.m b/source/IJSVG.m index df94b08..334453c 100644 --- a/source/IJSVG.m +++ b/source/IJSVG.m @@ -303,6 +303,35 @@ static NSColor * _baseColor = nil; error:error]; } +- (NSRect)computeRectDrawingInRect:(NSRect)rect + isValid:(BOOL *)valid +{ + // we also need to calculate the viewport so we can clip + // the drawing if needed + NSRect viewPort = NSZeroRect; + viewPort.origin.x = round(rect.size.width/2-(_group.proposedViewSize.width/2)*_clipScale); + viewPort.origin.y = round(rect.size.height/2-(_group.proposedViewSize.height/2)*_clipScale);; + viewPort.size.width = _group.proposedViewSize.width*_clipScale; + viewPort.size.height = _group.proposedViewSize.height*_clipScale; + + // check the viewport + if( NSEqualRects( _group.viewBox, NSZeroRect ) + || _group.viewBox.size.width <= 0 + || _group.viewBox.size.height <= 0 + || NSEqualRects( NSZeroRect, viewPort) + || CGRectIsEmpty(viewPort) + || CGRectIsNull(viewPort) + || viewPort.size.width <= 0 + || viewPort.size.height <= 0 ) + { + *valid = NO; + return NSZeroRect; + } + + *valid = YES; + return viewPort; +} + - (BOOL)_drawInRect:(NSRect)rect context:(CGContextRef)ref error:(NSError **)error @@ -320,11 +349,19 @@ static NSColor * _baseColor = nil; // we also need to calculate the viewport so we can clip // the drawing if needed - NSRect viewPort = NSZeroRect; - viewPort.origin.x = round(rect.size.width/2-(_group.proposedViewSize.width/2)*_clipScale); - viewPort.origin.y = round(rect.size.height/2-(_group.proposedViewSize.height/2)*_clipScale);; - viewPort.size.width = _group.proposedViewSize.width*_clipScale; - viewPort.size.height = _group.proposedViewSize.height*_clipScale; + BOOL canDraw = NO; + NSRect viewPort = [self computeRectDrawingInRect:rect + isValid:&canDraw]; + // check the viewport + if( !canDraw ) + { + if( error != NULL ) + *error = [[[NSError alloc] initWithDomain:IJSVGErrorDomain + code:IJSVGErrorDrawing + userInfo:nil] autorelease]; + CGContextRestoreGState(ref); + return NO; + } // clip any drawing to the view port [[NSBezierPath bezierPathWithRect:viewPort] addClip]; diff --git a/source/IJSVGBezierPathAdditions.h b/source/IJSVGBezierPathAdditions.h index eec06d8..d0d2929 100644 --- a/source/IJSVGBezierPathAdditions.h +++ b/source/IJSVGBezierPathAdditions.h @@ -13,6 +13,4 @@ - (void)addQuadCurveToPoint:(NSPoint)aPoint controlPoint:(NSPoint)cp; -- (CGPathRef)CGPath; - @end diff --git a/source/IJSVGBezierPathAdditions.m b/source/IJSVGBezierPathAdditions.m index a27f34b..bb15699 100644 --- a/source/IJSVGBezierPathAdditions.m +++ b/source/IJSVGBezierPathAdditions.m @@ -23,56 +23,4 @@ controlPoint2:CP2]; } -- (CGPathRef)CGPath -{ - int i, numElements; - - // Need to begin a path here. - CGPathRef immutablePath = NULL; - - // Then draw the path elements. - numElements = (int)[self elementCount]; - if (numElements > 0) - { - CGMutablePathRef path = CGPathCreateMutable(); - NSPoint points[3]; - BOOL didClosePath = YES; - - for (i = 0; i < numElements; i++) - { - switch ([self elementAtIndex:i associatedPoints:points]) - { - case NSMoveToBezierPathElement: - CGPathMoveToPoint(path, NULL, points[0].x, points[0].y); - break; - - case NSLineToBezierPathElement: - CGPathAddLineToPoint(path, NULL, points[0].x, points[0].y); - didClosePath = NO; - break; - - case NSCurveToBezierPathElement: - CGPathAddCurveToPoint(path, NULL, points[0].x, points[0].y, - points[1].x, points[1].y, - points[2].x, points[2].y); - didClosePath = NO; - break; - - case NSClosePathBezierPathElement: - CGPathCloseSubpath(path); - didClosePath = YES; - break; - } - } - - // Be sure the path is closed or Quartz may not do valid hit detection. - if (!didClosePath) - CGPathCloseSubpath(path); - - immutablePath = CGPathCreateCopy(path); - CGPathRelease(path); - } - return immutablePath; -} - @end diff --git a/source/IJSVGParser.h b/source/IJSVGParser.h index 13026e9..1dad48d 100644 --- a/source/IJSVGParser.h +++ b/source/IJSVGParser.h @@ -49,10 +49,6 @@ handleForeignObject:(IJSVGForeignObject *)foreignObject - (id)initWithFileURL:(NSURL *)aURL error:(NSError **)error delegate:(id)delegate; -- (id)initWithFileURL:(NSURL *)aURL - encoding:(NSStringEncoding)encoding - error:(NSError **)error - delegate:(id)delegate;; + (IJSVGParser *)groupForFileURL:(NSURL *)aURL; + (IJSVGParser *)groupForFileURL:(NSURL *)aURL delegate:(id)delegate; diff --git a/source/IJSVGParser.m b/source/IJSVGParser.m index 424a425..af7bc41 100644 --- a/source/IJSVGParser.m +++ b/source/IJSVGParser.m @@ -97,8 +97,8 @@ if( ![self _validateParse:&anError] ) { *error = anError; - [self release], self = nil; [_document release], _document = nil; + [self release], self = nil; return nil; } diff --git a/source/IJSVGPath.m b/source/IJSVGPath.m index bd18e94..50b0cae 100644 --- a/source/IJSVGPath.m +++ b/source/IJSVGPath.m @@ -17,7 +17,8 @@ - (void)dealloc { - [subpath release], subpath = nil; + if(subpath!=nil) + [subpath release], subpath = nil; [super dealloc]; }