Bug 445081. Refactor code to use ComputeNormalizedHypotenuse ... relanding with a fix so that we don't lose precision and break SVG text mochitests. r=longsonr,sr=mats

This commit is contained in:
Robert O'Callahan 2008-07-15 20:46:54 +12:00
parent af30232ff4
commit bfe75b2156
4 changed files with 14 additions and 3 deletions

View File

@ -1401,7 +1401,7 @@ nsSVGSVGElement::GetLength(PRUint8 aCtxType)
case nsSVGUtils::Y:
return h;
case nsSVGUtils::XY:
return (float)sqrt((w*w+h*h)/2.0);
return float(nsSVGUtils::ComputeNormalizedHypotenuse(w, h));
}
return 0;
}

View File

@ -1230,7 +1230,7 @@ nsSVGGlyphFrame::EnsureTextRun(float *aDrawScale, float *aMetricsScale,
// diagonal vector (1,1) to the length of the untransformed diagonal
// (which is sqrt(2)).
gfxPoint p = m.Transform(gfxPoint(1, 1)) - m.Transform(gfxPoint(0, 0));
double contextScale = sqrt((p.x*p.x + p.y*p.y)/2);
double contextScale = nsSVGUtils::ComputeNormalizedHypotenuse(p.x, p.y);
nsCAutoString langGroup;
nsIAtom *langGroupAtom = presContext->GetLangGroup();

View File

@ -944,6 +944,12 @@ nsSVGUtils::NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame)
}
}
double
nsSVGUtils::ComputeNormalizedHypotenuse(double aWidth, double aHeight)
{
return sqrt((aWidth*aWidth + aHeight*aHeight)/2);
}
float
nsSVGUtils::ObjectSpace(nsIDOMSVGRect *aRect, nsSVGLength2 *aLength)
{
@ -961,7 +967,7 @@ nsSVGUtils::ObjectSpace(nsIDOMSVGRect *aRect, nsSVGLength2 *aLength)
float width, height;
aRect->GetWidth(&width);
aRect->GetHeight(&height);
axis = sqrt(width * width + height * height)/sqrt(2.0f);
axis = float(ComputeNormalizedHypotenuse(width, height));
}
}

View File

@ -283,6 +283,11 @@ public:
/* enum for specifying coordinate direction for ObjectSpace/UserSpace */
enum ctxDirection { X, Y, XY };
/**
* Computes sqrt((aWidth^2 + aHeight^2)/2);
*/
static double ComputeNormalizedHypotenuse(double aWidth, double aHeight);
/* Computes the input length in terms of object space coordinates.
Input: rect - bounding box
length - length to be converted