drawRect: wrong scale in a programmatically created window
drawRect: wrong scale in a programmatically created window
- Subject: drawRect: wrong scale in a programmatically created window
- From: Andreas Höschler <email@hidden>
- Date: Thu, 14 Jan 2016 22:26:47 +0100
Hi all,
I have a command line tool in a Terminal session (service) that generates PNGs via NSBezierPath drawing. In this tool I create the view and corresponding window like so
mapView = [[ESMMapView alloc] initWithFrame:NSMakeRect(0, 0, _imageSize.width, _imageSize.height)];
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0, _imageSize.width, _imageSize.height) styleMask:NSBorderlessWindowMask backing:NSBackingStoreNonretained defer:NO];
[window setContentView:mapView];
and then do
[mapView lockFocus];
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[mapView bounds]];
NSData *data = [[[rep representationUsingType:NSPNGFileType properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:@"NSImageInterlaced"]] retain] autorelease];
[mapView unlockFocus];
to get the PNG with the drawing code in the
- (void)drawRect:(NSRect)rect
method of my ESMMapView.
The stuff drawn is scaled somehow. For test purposes I did
NSPoint pointA = NSMakePoint(10, 10);
NSPoint pointB = NSMakePoint(850, 890);
[[NSColor purpleColor] set];
NSBezierPath *currentBezier = [NSBezierPath bezierPath];
[currentBezier moveToPoint:pointA];
[currentBezier lineToPoint:pointB];
[currentBezier setLineWidth:2.0];
[currentBezier stroke];
This should in a view with size {851, 899} get me a purple line starting close to the lower left corner and ending close to the top right corner. But that's not the case. The picture is drawn zoomed in!?? :-(
I have checked the clipView, the bounds rect of the view, set the transform matrix to unity first thing in drawRect:
NSAffineTransform* xform = [NSAffineTransform transform];
[xform set];
No avail. Everything looks like it should in my opinion but the resulting image is still zoomed in (scaled and incomplete). The exact same code works correctly on GNUstep!
Any idea what might be wrong and how to fix this?
Thanks,
Andreas
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden