mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 173051. Do transforms consistently. r+sr=dbaron
This commit is contained in:
parent
34a19db7c3
commit
7718916c29
@ -432,14 +432,8 @@ void nsTransform2D :: TransformCoord(nscoord *ptX, nscoord *ptY)
|
||||
break;
|
||||
|
||||
case MG_2DSCALE | MG_2DTRANSLATION:
|
||||
// You can not use a translation that is not rounded to calculate a
|
||||
// final destination and get consistent results. The translation is rounded
|
||||
// separately only for the final coordinate location. Its ok
|
||||
// to keep the tranlation in floating for the matrix.. just don't use it
|
||||
// pre-rounded for coordinate locations. Its not valid to translate 1.333 pixels for example
|
||||
// on output since .33 pixel is not a valid output unit and can cause inconsistencies. (dcone)
|
||||
*ptX = NSToCoordRound(*ptX * m00) + NSToCoordRound(m20);
|
||||
*ptY = NSToCoordRound(*ptY * m11) + NSToCoordRound(m21);
|
||||
*ptX = NSToCoordRound(*ptX * m00 + m20);
|
||||
*ptY = NSToCoordRound(*ptY * m11 + m21);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -517,85 +511,12 @@ void nsTransform2D :: Transform(float *aX, float *aY, float *aWidth, float *aHei
|
||||
|
||||
void nsTransform2D :: TransformCoord(nscoord *aX, nscoord *aY, nscoord *aWidth, nscoord *aHeight)
|
||||
{
|
||||
float x, y;
|
||||
float ex,ey;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case MG_2DIDENTITY:
|
||||
break;
|
||||
|
||||
case MG_2DTRANSLATION:
|
||||
*aX += NSToCoordRound(m20);
|
||||
*aY += NSToCoordRound(m21);
|
||||
break;
|
||||
|
||||
case MG_2DSCALE:
|
||||
*aX = NSToCoordRound(*aX * m00);
|
||||
*aY = NSToCoordRound(*aY * m11);
|
||||
*aWidth = NSToCoordRound(*aWidth * m00);
|
||||
*aHeight = NSToCoordRound(*aHeight * m11);
|
||||
break;
|
||||
|
||||
case MG_2DGENERAL:
|
||||
x = (float)*aX;
|
||||
y = (float)*aY;
|
||||
|
||||
*aX = NSToCoordRound(x * m00 + y * m10);
|
||||
*aY = NSToCoordRound(x * m01 + y * m11);
|
||||
|
||||
x = (float)*aWidth;
|
||||
y = (float)*aHeight;
|
||||
|
||||
*aWidth = NSToCoordRound(x * m00 + y * m10);
|
||||
*aHeight = NSToCoordRound(x * m01 + y * m11);
|
||||
|
||||
break;
|
||||
|
||||
case MG_2DSCALE | MG_2DTRANSLATION:
|
||||
// first transform the X and Y locations
|
||||
x = *aX * m00 + NSToCoordRound(m20);
|
||||
y = *aY * m11 + NSToCoordRound(m21);
|
||||
*aX = NSToCoordRound(x);
|
||||
*aY = NSToCoordRound(y);
|
||||
|
||||
// the starting locations have a direct effect on the width and height if and only if
|
||||
// the width and height are used to calculate positions relative to these locations.
|
||||
// The layout engine does count on the width and height to be so many units away, so an
|
||||
// error can be introduced if you round and then add a rounded width. To compensate, this error
|
||||
// should be added to the width or height before rounding. If the width or height is used as a
|
||||
// measurment, or distance, then use the direct floating point number. This width and height
|
||||
// has an error adjustment for the starting locations inorder to calculate the ending positions.
|
||||
// The error is the fractional difference between the transformed point and the next pixel
|
||||
|
||||
// calculate the error
|
||||
ex = x - float(NSToCoordRound(x));
|
||||
ey = y - float(NSToCoordRound(y));
|
||||
|
||||
// now you can transform with the error added in
|
||||
*aWidth = NSToCoordRound(*aWidth * m00 + ex);
|
||||
*aHeight = NSToCoordRound(*aHeight * m11 + ey);
|
||||
break;
|
||||
|
||||
default:
|
||||
case MG_2DGENERAL | MG_2DTRANSLATION:
|
||||
x = (float)*aX;
|
||||
y = (float)*aY;
|
||||
|
||||
x = x * m00 + y * m10 + m20;
|
||||
y = x * m01 + y * m11 + m21;
|
||||
ex = x - float(NSToCoordRound(x));
|
||||
ey = y - float(NSToCoordRound(y));
|
||||
*aX = NSToCoordRound(x);
|
||||
*aY = NSToCoordRound(y);
|
||||
|
||||
x = (float)*aWidth;
|
||||
y = (float)*aHeight;
|
||||
|
||||
*aWidth = NSToCoordRound((x * m00 + y * m10)+ex);
|
||||
*aHeight = NSToCoordRound((x * m01 + y * m11)+ey);
|
||||
break;
|
||||
}
|
||||
nscoord x2 = *aX + *aWidth;
|
||||
nscoord y2 = *aY + *aHeight;
|
||||
TransformCoord(aX, aY);
|
||||
TransformCoord(&x2, &y2);
|
||||
*aWidth = x2 - *aX;
|
||||
*aHeight = y2 - *aY;
|
||||
}
|
||||
|
||||
void nsTransform2D :: AddTranslation(float ptX, float ptY)
|
||||
|
Loading…
Reference in New Issue
Block a user