1 #import "RCGImageDevice.h"
3 @implementation RCGImageDevice
5 [RDevice registerDevice:self forDisplay:@"jpeg"];
6 [RDevice registerDevice:self forDisplay:@"png"];
7 [RDevice registerDevice:self forDisplay:@"tiff"];
8 [RDevice registerDevice:self forDisplay:@""];
12 //Dispose of old context if needed
13 if(context != NULL && bitmap != NULL) {
14 CGContextRelease(context);
19 NSSize size = [self size];
20 size_t width = 1*size.width;
21 size_t height = 1*size.height;
22 size_t rowBytes = (width*8*4+7)/8;
24 bitmapSize = rowBytes*height;
25 bitmap = malloc(bitmapSize);
26 memset(bitmap,0,bitmapSize);
27 context = CGBitmapContextCreate(bitmap,width,height,8,rowBytes,CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB),kCGImageAlphaPremultipliedLast);
28 CGContextTranslateCTM(context,0,1*size.height);
29 CGContextScaleCTM(context,1.0,-1.0);
30 CGContextSetShouldAntialias(context,RDevice_GetAntialias(desc) ? true : false);
31 RDevice_ResetGDepth(desc);
34 - (void)finishOpening {
35 RDevice_SetScale(desc,1.0);
39 - (void)drawInRect:(NSRect)rect {
41 CGImageRef image = CGBitmapContextCreateImage(context);
42 CGContextDrawImage([[NSGraphicsContext currentContext] graphicsPort],CGRectMake(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height),image);
43 CGImageRelease(image);
47 - (CGContextRef)context {
51 - (BOOL)canDrawInView { return YES; }
52 - (BOOL)canResize { return YES; }
55 if(nil != [self display] && nil != [self target]) {
56 NSData *data = [self deviceRepresentationOfType:[self display]];
59 [data writeToURL:[NSURL URLWithString:[self target]] atomically:YES];
66 - (NSData*)deviceRepresentationOfType:(NSString*)aType {
67 if((nil == aType || [aType isEqual:@""])) {
68 NSString *aDisplay = [self display];
69 //If we don't have a display just return the raw bitmap
70 if(nil == aDisplay || [aDisplay isEqual:@""])
71 return [[[NSData alloc] initWithBytes:bitmap length:bitmapSize] autorelease];
72 else aType = aDisplay;
74 if([aType isEqual:@"tiff"] || [aType isEqual:NSTIFFPboardType]) {
80 - (NSData*)deviceRepresentation { return [self deviceRepresentationOfType:nil]; }