diff --git a/content/svg/content/src/nsSVGSVGElement.cpp b/content/svg/content/src/nsSVGSVGElement.cpp index 46fd5d4aae8..62ef18f8042 100644 --- a/content/svg/content/src/nsSVGSVGElement.cpp +++ b/content/svg/content/src/nsSVGSVGElement.cpp @@ -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; } diff --git a/layout/svg/base/src/nsSVGGlyphFrame.cpp b/layout/svg/base/src/nsSVGGlyphFrame.cpp index 68d9a834340..ed5b3533729 100644 --- a/layout/svg/base/src/nsSVGGlyphFrame.cpp +++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp @@ -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(); diff --git a/layout/svg/base/src/nsSVGUtils.cpp b/layout/svg/base/src/nsSVGUtils.cpp index cb51290df71..7d6ff43c064 100644 --- a/layout/svg/base/src/nsSVGUtils.cpp +++ b/layout/svg/base/src/nsSVGUtils.cpp @@ -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)); } } diff --git a/layout/svg/base/src/nsSVGUtils.h b/layout/svg/base/src/nsSVGUtils.h index 607af76dd88..b51356459d9 100644 --- a/layout/svg/base/src/nsSVGUtils.h +++ b/layout/svg/base/src/nsSVGUtils.h @@ -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