@@ -3509,16 +3509,16 @@ static void _data_provider_release(void* info, const void* data, size_t size)
3509
3509
int n;
3510
3510
const unichar* characters;
3511
3511
NSSize size;
3512
- double width, height;
3512
+ double width, height, dpi ;
3513
3513
3514
3514
if(!view)
3515
3515
{
3516
3516
PyErr_SetString(PyExc_RuntimeError, "NSView* is NULL");
3517
3517
return NULL;
3518
3518
}
3519
3519
/* NSSize contains CGFloat; cannot use size directly */
3520
- if(!PyArg_ParseTuple(args, "u#dd ",
3521
- &characters, &n, &width, &height)) return NULL;
3520
+ if(!PyArg_ParseTuple(args, "u#ddd ",
3521
+ &characters, &n, &width, &height, &dpi )) return NULL;
3522
3522
size.width = width;
3523
3523
size.height = height;
3524
3524
@@ -3543,16 +3543,24 @@ static void _data_provider_release(void* info, const void* data, size_t size)
3543
3543
if (invalid) [view setNeedsDisplay: YES];
3544
3544
3545
3545
NSImage* image = [[NSImage alloc] initWithData: data];
3546
- [image setScalesWhenResized: YES];
3547
- [image setSize: size];
3548
- data = [image TIFFRepresentation];
3549
- [image release];
3546
+ NSImage *resizedImage = [[NSImage alloc] initWithSize:size];
3547
+
3548
+ [resizedImage lockFocus];
3549
+ [image drawInRect:NSMakeRect(0, 0, width, height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
3550
+ [resizedImage unlockFocus];
3551
+ data = [resizedImage TIFFRepresentation];
3552
+
3553
+ NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:data];
3554
+
3555
+ NSSize pxlSize = NSMakeSize(rep.pixelsWide, rep.pixelsHigh);
3556
+ NSSize newSize = NSMakeSize(72.0 * pxlSize.width / dpi, 72.0 * pxlSize.height / dpi);
3557
+
3558
+ [rep setSize:newSize];
3550
3559
3551
3560
if (! [extension isEqualToString: @"tiff"] &&
3552
3561
! [extension isEqualToString: @"tif"])
3553
3562
{
3554
3563
NSBitmapImageFileType filetype;
3555
- NSBitmapImageRep* bitmapRep = [NSBitmapImageRep imageRepWithData: data];
3556
3564
if ([extension isEqualToString: @"bmp"])
3557
3565
filetype = NSBMPFileType;
3558
3566
else if ([extension isEqualToString: @"gif"])
@@ -3567,9 +3575,10 @@ static void _data_provider_release(void* info, const void* data, size_t size)
3567
3575
return NULL;
3568
3576
}
3569
3577
3570
- data = [bitmapRep representationUsingType:filetype properties:nil];
3578
+ data = [rep representationUsingType:filetype properties:nil];
3571
3579
}
3572
3580
3581
+ data = [rep representationUsingType:NSTIFFFileType properties:nil];
3573
3582
[data writeToFile: filename atomically: YES];
3574
3583
[pool release];
3575
3584
0 commit comments