From d0e1a05afcfd856de280d3b747b5dc5ce5d791ee Mon Sep 17 00:00:00 2001 From: Nigel Babu Date: Wed, 2 Sep 2015 11:34:34 +0530 Subject: [PATCH] Backed out changeset 4a68226609c8 (bug 1092125) for M3 bustage on CLOSED TREE --- dom/svg/SVGLineElement.cpp | 70 ++++++++-------------------------- dom/svg/test/bounds-helper.svg | 12 ------ dom/svg/test/test_bounds.html | 39 ------------------- layout/svg/nsSVGUtils.cpp | 2 +- 4 files changed, 17 insertions(+), 106 deletions(-) diff --git a/dom/svg/SVGLineElement.cpp b/dom/svg/SVGLineElement.cpp index e9f0587e567..eb6d4a3b800 100644 --- a/dom/svg/SVGLineElement.cpp +++ b/dom/svg/SVGLineElement.cpp @@ -153,6 +153,10 @@ SVGLineElement::GetGeometryBounds(Rect* aBounds, const Matrix& aToBoundsSpace, const Matrix* aToNonScalingStrokeSpace) { + if (aToNonScalingStrokeSpace) { + return false; + } + float x1, y1, x2, y2; GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr); @@ -162,53 +166,21 @@ SVGLineElement::GetGeometryBounds(Rect* aBounds, return true; } - // transform from non-scaling-stroke space to the space in which we compute - // bounds - Matrix nonScalingToBounds; - if (aToNonScalingStrokeSpace) { - Matrix nonScalingToUser = aToNonScalingStrokeSpace->Inverse(); - nonScalingToBounds = nonScalingToUser * aToBoundsSpace; - } - if (aStrokeOptions.mLineCap == CapStyle::ROUND) { - if (!aToBoundsSpace.IsRectilinear() || - (aToNonScalingStrokeSpace && - !aToNonScalingStrokeSpace->IsRectilinear())) { + if (!aToBoundsSpace.IsRectilinear()) { // TODO: handle this case. return false; } Rect bounds(Point(x1, y1), Size()); bounds.ExpandToEnclose(Point(x2, y2)); - if (aToNonScalingStrokeSpace) { - bounds = aToNonScalingStrokeSpace->TransformBounds(bounds); - bounds.Inflate(aStrokeOptions.mLineWidth / 2.f); - *aBounds = nonScalingToBounds.TransformBounds(bounds); - } else { - bounds.Inflate(aStrokeOptions.mLineWidth / 2.f); - *aBounds = aToBoundsSpace.TransformBounds(bounds); - } + bounds.Inflate(aStrokeOptions.mLineWidth / 2.f); + *aBounds = aToBoundsSpace.TransformBounds(bounds); return true; } - // Handle butt and square linecap, normal and non-scaling stroke cases - // together: start with endpoints (x1, y1), (x2, y2) in the stroke space, - // compute the four corners of the stroked line, transform the corners to - // bounds space, and compute bounds there. - - if (aToNonScalingStrokeSpace) { - Point nonScalingSpaceP1, nonScalingSpaceP2; - nonScalingSpaceP1 = *aToNonScalingStrokeSpace * Point(x1, y1); - nonScalingSpaceP2 = *aToNonScalingStrokeSpace * Point(x2, y2); - x1 = nonScalingSpaceP1.x; - y1 = nonScalingSpaceP1.y; - x2 = nonScalingSpaceP2.x; - y2 = nonScalingSpaceP2.y; - } - Float length = Float(NS_hypot(x2 - x1, y2 - y1)); Float xDelta; Float yDelta; - Point points[4]; if (aStrokeOptions.mLineCap == CapStyle::BUTT) { if (length == 0.f) { @@ -218,37 +190,27 @@ SVGLineElement::GetGeometryBounds(Rect* aBounds, xDelta = ratio * (y2 - y1); yDelta = ratio * (x2 - x1); } - points[0] = Point(x1 - xDelta, y1 + yDelta); - points[1] = Point(x1 + xDelta, y1 - yDelta); - points[2] = Point(x2 + xDelta, y2 - yDelta); - points[3] = Point(x2 - xDelta, y2 + yDelta); } else { MOZ_ASSERT(aStrokeOptions.mLineCap == CapStyle::SQUARE); if (length == 0.f) { xDelta = yDelta = aStrokeOptions.mLineWidth / 2.f; - points[0] = Point(x1 - xDelta, y1 + yDelta); - points[1] = Point(x1 - xDelta, y1 - yDelta); - points[2] = Point(x1 + xDelta, y1 - yDelta); - points[3] = Point(x1 + xDelta, y1 + yDelta); } else { Float ratio = aStrokeOptions.mLineWidth / 2.f / length; - yDelta = ratio * (x2 - x1); - xDelta = ratio * (y2 - y1); - points[0] = Point(x1 - yDelta - xDelta, y1 - xDelta + yDelta); - points[1] = Point(x1 - yDelta + xDelta, y1 - xDelta - yDelta); - points[2] = Point(x2 + yDelta + xDelta, y2 + xDelta - yDelta); - points[3] = Point(x2 + yDelta - xDelta, y2 + xDelta + yDelta); + xDelta = yDelta = ratio * (fabs(y2 - y1) + fabs(x2 - x1)); } } - const Matrix& toBoundsSpace = aToNonScalingStrokeSpace ? - nonScalingToBounds : aToBoundsSpace; + Point points[4]; - *aBounds = Rect(toBoundsSpace * points[0], Size()); + points[0] = Point(x1 - xDelta, y1 - yDelta); + points[1] = Point(x1 + xDelta, y1 + yDelta); + points[2] = Point(x2 + xDelta, y2 + yDelta); + points[3] = Point(x2 - xDelta, y2 - yDelta); + + *aBounds = Rect(aToBoundsSpace * points[0], Size()); for (uint32_t i = 1; i < 4; ++i) { - aBounds->ExpandToEnclose(toBoundsSpace * points[i]); + aBounds->ExpandToEnclose(aToBoundsSpace * points[i]); } - return true; } diff --git a/dom/svg/test/bounds-helper.svg b/dom/svg/test/bounds-helper.svg index 6fc33b1ecb3..98100ee0cc3 100644 --- a/dom/svg/test/bounds-helper.svg +++ b/dom/svg/test/bounds-helper.svg @@ -47,17 +47,5 @@ text { font: 20px monospace; } transform="matrix(0 3 -2 0 0 0)" fill="none" stroke="steelblue" stroke-width="10" vector-effect="non-scaling-stroke" /> - - - diff --git a/dom/svg/test/test_bounds.html b/dom/svg/test/test_bounds.html index bc1801821ae..7128a97011b 100644 --- a/dom/svg/test/test_bounds.html +++ b/dom/svg/test/test_bounds.html @@ -222,45 +222,6 @@ function runTest() isWithAbsTolerance(nonScalingStrokedEllipse1Bounds.height, 40, 0.15, "nonScalingStrokedEllipse1.getBoundingClientRect().height"); - var nonScalingStrokedLine1Bounds = - doc.getElementById("nonScalingStrokedLine1").getBoundingClientRect(); - isWithAbsTolerance(nonScalingStrokedLine1Bounds.left, 235, 0.1, - "nonScalingStrokedLine1.getBoundingClientRect().left"); - isWithAbsTolerance(nonScalingStrokedLine1Bounds.top, 10, 0.1, - "nonScalingStrokedLine1.getBoundingClientRect().top"); - isWithAbsTolerance(nonScalingStrokedLine1Bounds.width, 10, 0.1, - "nonScalingStrokedLine1.getBoundingClientRect().width"); - isWithAbsTolerance(nonScalingStrokedLine1Bounds.height, 25, 0.1, - "nonScalingStrokedLine1.getBoundingClientRect().height"); - - var nonScalingStrokedLine2Bounds = - doc.getElementById("nonScalingStrokedLine2").getBoundingClientRect(); - var capDelta = 5/Math.SQRT2 + 5/Math.SQRT2; - rect = new Rect(260 - capDelta, 15 - capDelta, 20/Math.SQRT2 + 2 * capDelta, - 20/Math.SQRT2 + 2 * capDelta); - isWithAbsTolerance(nonScalingStrokedLine2Bounds.left, rect.left, 0.1, - "nonScalingStrokedLine2.getBoundingClientRect().left"); - isWithAbsTolerance(nonScalingStrokedLine2Bounds.top, rect.top, 0.1, - "nonScalingStrokedLine2.getBoundingClientRect().top"); - isWithAbsTolerance(nonScalingStrokedLine2Bounds.width, rect.width, 0.1, - "nonScalingStrokedLine2.getBoundingClientRect().width"); - isWithAbsTolerance(nonScalingStrokedLine2Bounds.height, rect.height, 0.1, - "nonScalingStrokedLine2.getBoundingClientRect().height"); - - var nonScalingStrokedLine3Bounds = - doc.getElementById("nonScalingStrokedLine3").getBoundingClientRect(); - var capDelta = 5/Math.SQRT2; - rect = new Rect(280 - capDelta, 15 - capDelta, 20/Math.SQRT2 + 2 * capDelta, - 20/Math.SQRT2 + 2 * capDelta); - isWithAbsTolerance(nonScalingStrokedLine3Bounds.left, rect.left, 0.1, - "nonScalingStrokedLine3.getBoundingClientRect().left"); - isWithAbsTolerance(nonScalingStrokedLine3Bounds.top, rect.top, 0.1, - "nonScalingStrokedLine3.getBoundingClientRect().top"); - isWithAbsTolerance(nonScalingStrokedLine3Bounds.width, rect.width, 0.1, - "nonScalingStrokedLine3.getBoundingClientRect().width"); - isWithAbsTolerance(nonScalingStrokedLine3Bounds.height, rect.height, 0.1, - "nonScalingStrokedLine3.getBoundingClientRect().height"); - SimpleTest.finish(); } diff --git a/layout/svg/nsSVGUtils.cpp b/layout/svg/nsSVGUtils.cpp index e3b50b1f7cf..47776437eed 100644 --- a/layout/svg/nsSVGUtils.cpp +++ b/layout/svg/nsSVGUtils.cpp @@ -1171,7 +1171,7 @@ PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents, gfxMatrix outerSVGToUser; if (nsSVGUtils::GetNonScalingStrokeTransform(aFrame, &outerSVGToUser)) { outerSVGToUser.Invert(); - matrix.PreMultiply(outerSVGToUser); + matrix *= outerSVGToUser; } double dx = style_expansion * (fabs(matrix._11) + fabs(matrix._21));