Bug 624781. When converting from app units to pixels use an intermediate double to do the calculation so no precision is lost. r=roc a=blocking

This commit is contained in:
Timothy Nikkel 2011-02-08 13:29:26 -06:00
Родитель 0c00357f68
Коммит 40cfc259a0
3 изменённых файлов: 18 добавлений и 8 удалений

Просмотреть файл

@ -411,6 +411,11 @@ inline PRInt32 NSToIntRoundUp(float aValue)
return PRInt32(NS_floorf(aValue + 0.5f));
}
inline PRInt32 NSToIntRoundUp(double aValue)
{
return PRInt32(NS_floor(aValue + 0.5));
}
/*
* App Unit/Pixel conversions
*/
@ -433,6 +438,11 @@ inline float NSAppUnitsToFloatPixels(nscoord aAppUnits, float aAppUnitsPerPixel)
return (float(aAppUnits) / aAppUnitsPerPixel);
}
inline double NSAppUnitsToDoublePixels(nscoord aAppUnits, nscoord aAppUnitsPerPixel)
{
return (double(aAppUnits) / double(aAppUnitsPerPixel));
}
inline PRInt32 NSAppUnitsToIntPixels(nscoord aAppUnits, float aAppUnitsPerPixel)
{
return NSToIntRound(float(aAppUnits) / aAppUnitsPerPixel);

Просмотреть файл

@ -127,8 +127,8 @@ struct nsIntPoint {
inline nsIntPoint
nsPoint::ToNearestPixels(nscoord aAppUnitsPerPixel) const {
return nsIntPoint(
NSToIntRoundUp(NSAppUnitsToFloatPixels(x, float(aAppUnitsPerPixel))),
NSToIntRoundUp(NSAppUnitsToFloatPixels(y, float(aAppUnitsPerPixel))));
NSToIntRoundUp(NSAppUnitsToDoublePixels(x, aAppUnitsPerPixel)),
NSToIntRoundUp(NSAppUnitsToDoublePixels(y, aAppUnitsPerPixel)));
}
inline nsPoint

Просмотреть файл

@ -391,12 +391,12 @@ inline nsIntRect
nsRect::ToNearestPixels(nscoord aAppUnitsPerPixel) const
{
nsIntRect rect;
rect.x = NSToIntRoundUp(NSAppUnitsToFloatPixels(x, float(aAppUnitsPerPixel)));
rect.y = NSToIntRoundUp(NSAppUnitsToFloatPixels(y, float(aAppUnitsPerPixel)));
rect.width = NSToIntRoundUp(NSAppUnitsToFloatPixels(XMost(),
float(aAppUnitsPerPixel))) - rect.x;
rect.height = NSToIntRoundUp(NSAppUnitsToFloatPixels(YMost(),
float(aAppUnitsPerPixel))) - rect.y;
rect.x = NSToIntRoundUp(NSAppUnitsToDoublePixels(x, aAppUnitsPerPixel));
rect.y = NSToIntRoundUp(NSAppUnitsToDoublePixels(y, aAppUnitsPerPixel));
rect.width = NSToIntRoundUp(NSAppUnitsToDoublePixels(XMost(),
aAppUnitsPerPixel)) - rect.x;
rect.height = NSToIntRoundUp(NSAppUnitsToDoublePixels(YMost(),
aAppUnitsPerPixel)) - rect.y;
return rect;
}