From b2bdb8ad76e3e42bf3e459e274f4743ffc773873 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Tue, 15 Jul 2008 20:46:54 +1200 Subject: [PATCH] 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 --- content/svg/content/src/nsSVGSVGElement.cpp | 2 +- layout/svg/base/src/nsSVGGlyphFrame.cpp | 2 +- layout/svg/base/src/nsSVGUtils.cpp | 8 +++++++- layout/svg/base/src/nsSVGUtils.h | 5 +++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/content/svg/content/src/nsSVGSVGElement.cpp b/content/svg/content/src/nsSVGSVGElement.cpp index 46fd5d4aae80..62ef18f80423 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 68d9a834340a..ed5b3533729c 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 cb51290df71e..7d6ff43c0646 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 607af76dd880..b51356459d97 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