* Source/NSImage.m (GSResolutionOfImageRep): Specify behaviour when the

rep has a size of zero, or is a vector rep. Prevent division by 0.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33742 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Eric Wasylishen 2011-08-15 20:19:21 +00:00
parent e9367ed059
commit 6ec3f1a58b
2 changed files with 27 additions and 2 deletions

View file

@ -1,3 +1,8 @@
2011-08-15 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSImage.m (GSResolutionOfImageRep): Specify behaviour when the
rep has a size of zero, or is a vector rep. Prevent division by 0.
2011-08-15 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSImage.m (-nativeDrawInRect:...): Deal with a zero rep size

View file

@ -1550,10 +1550,30 @@ static BOOL GSSizeIsIntegerMultipleOfSize(NSSize size, NSSize baseSize)
GSIsMultiple(size.height, baseSize.height));
}
/**
* Returns {0, 0} if the image rep doesn't have a size set,
* or the pixelsWide or pixelsHigh are NSImageRepMatchesDevice
*/
static NSSize GSResolutionOfImageRep(NSImageRep *rep)
{
return NSMakeSize(72.0 * (CGFloat)[rep pixelsWide] / [rep size].width,
72.0 * (CGFloat)[rep pixelsHigh] / [rep size].height);
const int pixelsWide = [rep pixelsWide];
const int pixelsHigh = [rep pixelsHigh];
const NSSize repSize = [rep size];
if (repSize.width == 0 || repSize.height == 0)
{
return NSMakeSize(0, 0);
}
else if (pixelsWide == NSImageRepMatchesDevice ||
pixelsHigh == NSImageRepMatchesDevice)
{
return NSMakeSize(0, 0);
}
else
{
return NSMakeSize(72.0 * (CGFloat)pixelsWide / repSize.width,
72.0 * (CGFloat)pixelsHigh / repSize.height);
}
}
/* Find reps that match the resolution (DPI) of the device (including integer