From a10c0bceab59a64fa4594948953d3f303ea27728 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Fri, 26 Mar 2021 17:19:27 +0000 Subject: [PATCH] Issue #1754 - Fix clip path overflow. Resolves #1754. --- .../clip-path/clip-path-circle-021-ref.html | 16 +++++++++++++++ .../clip-path/clip-path-circle-021.html | 20 +++++++++++++++++++ .../svg-integration/clip-path/reftest.list | 1 + layout/svg/nsCSSClipPathInstance.cpp | 10 +++++++--- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 layout/reftests/svg/svg-integration/clip-path/clip-path-circle-021-ref.html create mode 100644 layout/reftests/svg/svg-integration/clip-path/clip-path-circle-021.html diff --git a/layout/reftests/svg/svg-integration/clip-path/clip-path-circle-021-ref.html b/layout/reftests/svg/svg-integration/clip-path/clip-path-circle-021-ref.html new file mode 100644 index 0000000000..c87ded532f --- /dev/null +++ b/layout/reftests/svg/svg-integration/clip-path/clip-path-circle-021-ref.html @@ -0,0 +1,16 @@ + + + + + CSS Masking: Test clip-path property and circle function on circle 021 + + + + +

The test passes if there is a green circle.

+
+ + diff --git a/layout/reftests/svg/svg-integration/clip-path/clip-path-circle-021.html b/layout/reftests/svg/svg-integration/clip-path/clip-path-circle-021.html new file mode 100644 index 0000000000..a9229e6ea7 --- /dev/null +++ b/layout/reftests/svg/svg-integration/clip-path/clip-path-circle-021.html @@ -0,0 +1,20 @@ + + + + + CSS Masking: Test clip-path property and circle function on circle 021 + + + + + + + + +

The test passes if there is a green circle.

+
+ + diff --git a/layout/reftests/svg/svg-integration/clip-path/reftest.list b/layout/reftests/svg/svg-integration/clip-path/reftest.list index fbc0f37f79..a54e8cbf71 100644 --- a/layout/reftests/svg/svg-integration/clip-path/reftest.list +++ b/layout/reftests/svg/svg-integration/clip-path/reftest.list @@ -38,6 +38,7 @@ default-preferences pref(layout.css.clip-path-shapes.enabled,true) == clip-path-circle-018.html clip-path-circle-010-ref.html == clip-path-circle-019.html clip-path-circle-002-ref.html == clip-path-circle-020.html clip-path-circle-002-ref.html +== clip-path-circle-021.html clip-path-circle-021-ref.html == clip-path-ellipse-001.html clip-path-ellipse-001-ref.html == clip-path-ellipse-002.html clip-path-ellipse-001-ref.html diff --git a/layout/svg/nsCSSClipPathInstance.cpp b/layout/svg/nsCSSClipPathInstance.cpp index e923eaa0e7..ac522c91fa 100644 --- a/layout/svg/nsCSSClipPathInstance.cpp +++ b/layout/svg/nsCSSClipPathInstance.cpp @@ -12,6 +12,7 @@ #include "mozilla/gfx/PathHelpers.h" #include "nsCSSRendering.h" #include "nsIFrame.h" +#include "nsMathUtils.h" #include "nsRenderingContext.h" #include "nsRuleNode.h" @@ -135,8 +136,6 @@ nsCSSClipPathInstance::CreateClipPathCircle(DrawTarget* aDrawTarget, const nsTArray& coords = basicShape->Coordinates(); MOZ_ASSERT(coords.Length() == 1, "wrong number of arguments"); - float referenceLength = sqrt((aRefBox.width * aRefBox.width + - aRefBox.height * aRefBox.height) / 2.0); nscoord r = 0; if (coords[0].GetUnit() == eStyleUnit_Enumerated) { nscoord horizontal, vertical; @@ -150,7 +149,12 @@ nsCSSClipPathInstance::CreateClipPathCircle(DrawTarget* aDrawTarget, r = horizontal < vertical ? horizontal : vertical; } } else { - r = nsRuleNode::ComputeCoordPercentCalc(coords[0], referenceLength); + // We resolve percent value for circle() as defined here: + // https://drafts.csswg.org/css-shapes/#funcdef-circle + const double sqrt2 = std::sqrt(2.0); + double referenceLength = NS_hypot(aRefBox.width, aRefBox.height) / sqrt2; + r = nsRuleNode::ComputeCoordPercentCalc(coords[0], + NSToCoordRound(referenceLength)); } nscoord appUnitsPerDevPixel =