Skip to content

Commit

Permalink
Use SVGKImageRep for the SVGKImage's NSImage getter.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddTheSane committed Jun 29, 2013
1 parent 930c1ce commit 80539ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
18 changes: 16 additions & 2 deletions Source/AppKit additions/SVGKImageRep.m
Expand Up @@ -246,16 +246,23 @@ - (BOOL)drawInRect:(NSRect)rect
CGLayerRelease(layerRef);
} else {
//...But should the method be removed in a future version, fall back to the old method
NSImage *tmpImage = self.image.NSImage;
NSImage *tmpImage = [[NSImage alloc] initWithSize:scaledSize];
if (!tmpImage) {
return NO;
}

NSBitmapImageRep *bitRep = self.image.bitmapImageRep;
if (!bitRep) {
return NO;
}
[tmpImage addRepresentation:bitRep];

NSRect imageRect;
imageRect.size = rect.size;
imageRect.origin = NSZeroPoint;

[tmpImage drawAtPoint:rect.origin fromRect:imageRect operation:NSCompositeCopy fraction:1];
[tmpImage release];
}

return YES;
Expand Down Expand Up @@ -285,16 +292,23 @@ - (BOOL)draw
CGLayerRelease(layerRef);
} else {
//...But should the method be removed in a future version, fall back to the old method
NSImage *tmpImage = self.image.NSImage;
NSImage *tmpImage = [[NSImage alloc] initWithSize:scaledSize];
if (!tmpImage) {
return NO;
}

NSBitmapImageRep *bitRep = self.image.bitmapImageRep;
if (!bitRep) {
return NO;
}
[tmpImage addRepresentation:bitRep];

NSRect imageRect;
imageRect.size = self.size;
imageRect.origin = NSZeroPoint;

[tmpImage drawAtPoint:NSZeroPoint fromRect:imageRect operation:NSCompositeCopy fraction:1];
[tmpImage release];
}

return YES;
Expand Down
11 changes: 10 additions & 1 deletion Source/SVGKImage.m
Expand Up @@ -15,6 +15,9 @@
#import "SVGKSourceLocalFile.h"
#import "SVGKSourceURL.h"
#import "SVGKSourceData.h"
#if !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
#import "SVGKImageRep.h"
#endif

#import "BlankSVG.h"

Expand Down Expand Up @@ -383,7 +386,13 @@ - (CIImage*)CIImage

- (NSImage*)NSImage
{
return [self exportNSImageAntiAliased:YES curveFlatnessFactor:1.0 interpolationQuality:kCGInterpolationDefault];
SVGKImageRep *imRep = [SVGKImageRep imageRepWithSVGImage:self];
if (!imRep) {
return [self exportNSImageAntiAliased:YES curveFlatnessFactor:1.0 interpolationQuality:kCGInterpolationDefault];
}
NSImage *retImage = [[NSImage alloc] initWithSize:self.size];
[retImage addRepresentation:imRep];
return [retImage autorelease];
}

- (NSBitmapImageRep *)bitmapImageRep
Expand Down

0 comments on commit 80539ed

Please sign in to comment.