From ee1233bb0c99d75e81f2558a402b91554e5098dc Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Fri, 14 Sep 2018 20:54:19 +0200 Subject: [PATCH] Fix wrong SVG sizes with non-integer values for viewBox width/height. Includes a standalone reftest. --- dom/svg/test/reftest_viewport_noninteger.html | 175 ++++++++++++++++++ layout/svg/nsSVGOuterSVGFrame.cpp | 9 +- 2 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 dom/svg/test/reftest_viewport_noninteger.html diff --git a/dom/svg/test/reftest_viewport_noninteger.html b/dom/svg/test/reftest_viewport_noninteger.html new file mode 100644 index 0000000000..3f4852b539 --- /dev/null +++ b/dom/svg/test/reftest_viewport_noninteger.html @@ -0,0 +1,175 @@ + + + + + SVG size test + + + +

SVG size test

+ +

The grey boxes below are <svg> elements.

+

All SVGs in each row should have the exact same size.

+

Each row has its own viewBox width and height: viewBox="0 0 width height".

+

Each column has its own width/height styling. For example, style="width: 200px; height: auto;".

+

The first column has both an explicit widht and an explicit height, so there's not much that can go wrong there. It acts as a reference.

+

The first row has integer viewBox width and height. Firefox then sizes all SVGs correctly.

+

The remaining rows have at least one non-integer viewBox width and height. Firefox then sizes the SVGs a bit wrong.

+

Chrome, Safari and Edge seem to pass all tests.

+ +

+ +
+ + + + diff --git a/layout/svg/nsSVGOuterSVGFrame.cpp b/layout/svg/nsSVGOuterSVGFrame.cpp index aeadccbc55..e1b97bb40b 100644 --- a/layout/svg/nsSVGOuterSVGFrame.cpp +++ b/layout/svg/nsSVGOuterSVGFrame.cpp @@ -241,8 +241,9 @@ nsSVGOuterSVGFrame::GetIntrinsicRatio() nsSVGLength2 &height = content->mLengthAttributes[SVGSVGElement::ATTR_HEIGHT]; if (!width.IsPercentage() && !height.IsPercentage()) { - nsSize ratio(NSToCoordRoundWithClamp(width.GetAnimValue(content)), - NSToCoordRoundWithClamp(height.GetAnimValue(content))); + nsSize ratio( + nsPresContext::CSSPixelsToAppUnits(width.GetAnimValue(content)), + nsPresContext::CSSPixelsToAppUnits(height.GetAnimValue(content))); if (ratio.width < 0) { ratio.width = 0; } @@ -272,8 +273,8 @@ nsSVGOuterSVGFrame::GetIntrinsicRatio() if (viewBoxHeight < 0.0f) { viewBoxHeight = 0.0f; } - return nsSize(NSToCoordRoundWithClamp(viewBoxWidth), - NSToCoordRoundWithClamp(viewBoxHeight)); + return nsSize(nsPresContext::CSSPixelsToAppUnits(viewBoxWidth), + nsPresContext::CSSPixelsToAppUnits(viewBoxHeight)); } return nsSVGDisplayContainerFrame::GetIntrinsicRatio();