From cd42d240a2c801ffa8293d4e66ec77a17774fc8c Mon Sep 17 00:00:00 2001 From: ericwa Date: Wed, 20 Apr 2011 21:41:17 +0000 Subject: [PATCH] * Source/NSBitmapImageRep+PNG.m: Read DPI metadata in PNG files and use this to set the point size of the image rep git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@32916 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/NSBitmapImageRep+PNG.m | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/ChangeLog b/ChangeLog index f4d9f67c2..c996d098e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-20 Eric Wasylishen + + * Source/NSBitmapImageRep+PNG.m: Read DPI metadata in PNG files + and use this to set the point size of the image rep + 2011-04-19 Eric Wasylishen * ColorPickers/GSWheelColorPicker.m: Choose the color wheel bitmap size diff --git a/Source/NSBitmapImageRep+PNG.m b/Source/NSBitmapImageRep+PNG.m index 0cb24d79c..e031a34b4 100644 --- a/Source/NSBitmapImageRep+PNG.m +++ b/Source/NSBitmapImageRep+PNG.m @@ -256,6 +256,20 @@ static void reader_func(png_structp png_struct, png_bytep data, //NSLog(@"PNG file gamma: %f", file_gamma); } + if (png_get_valid(png_struct, png_info, PNG_INFO_pHYs)) + { + png_uint_32 xppm = png_get_x_pixels_per_meter(png_struct, png_info); + png_uint_32 yppm = png_get_y_pixels_per_meter(png_struct, png_info); + + if (xppm != 0 && yppm != 0) + { + const CGFloat pointsPerMeter = 39.3700787 * 72.0; + NSSize sizeInPoints = NSMakeSize((width / (CGFloat)xppm) * pointsPerMeter, + (height / (CGFloat)yppm) * pointsPerMeter); + [self setSize: sizeInPoints]; + } + } + png_destroy_read_struct(&png_struct, &png_info, &png_end_info); return self;