Title: [278271] trunk
Revision
278271
Author
[email protected]
Date
2021-05-30 23:39:50 -0700 (Sun, 30 May 2021)

Log Message

REGRESSION (r258118): SVG paths that contain a single move command incorrect client bounding rects
https://bugs.webkit.org/show_bug.cgi?id=226447
rdar://72112744

Reviewed by Alan Bujtas.

Source/WebCore:

r258118 introduced a fast path for computing the bounding rect of a `WebCore::Path` without having to
materialize a platform path object (e.g. `CGPathRef` on platforms that use CoreGraphics). To do this, we
introduce `InlinePathData` -- a variant capable of representing several types of simple `Path` objects without
allocating a platform path.

However, in the case where a `Path` only consists of a single `moveTo` command, this fast path for computing the
bounding rect currently returns the zero rect (an empty rect at the origin), rather than an empty rect at the
location we've moved to. This causes the offset of the bounding rect of an SVG path element that contains only a
single `M` drawing command to be incorrect.

Simply fix this by returning an empty rect that is offset by the `moveTo` location, rather than the origin.

Test: fast/svg/bounding-rect-for-path-with-only-move-command.html

* platform/graphics/Path.cpp:
(WebCore::Path::boundingRectFromInlineData const):

LayoutTests:

Add a layout test to exercise the bug.

* fast/svg/bounding-rect-for-path-with-only-move-command-expected.txt: Added.
* fast/svg/bounding-rect-for-path-with-only-move-command.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (278270 => 278271)


--- trunk/LayoutTests/ChangeLog	2021-05-31 06:20:28 UTC (rev 278270)
+++ trunk/LayoutTests/ChangeLog	2021-05-31 06:39:50 UTC (rev 278271)
@@ -1,3 +1,16 @@
+2021-05-30  Wenson Hsieh  <[email protected]>
+
+        REGRESSION (r258118): SVG paths that contain a single move command incorrect client bounding rects
+        https://bugs.webkit.org/show_bug.cgi?id=226447
+        rdar://72112744
+
+        Reviewed by Alan Bujtas.
+
+        Add a layout test to exercise the bug.
+
+        * fast/svg/bounding-rect-for-path-with-only-move-command-expected.txt: Added.
+        * fast/svg/bounding-rect-for-path-with-only-move-command.html: Added.
+
 2021-05-30  Sam Weinig  <[email protected]>
 
         Remove support for no longer specific color(lab ...) syntax

Added: trunk/LayoutTests/fast/svg/bounding-rect-for-path-with-only-move-command-expected.txt (0 => 278271)


--- trunk/LayoutTests/fast/svg/bounding-rect-for-path-with-only-move-command-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/svg/bounding-rect-for-path-with-only-move-command-expected.txt	2021-05-31 06:39:50 UTC (rev 278271)
@@ -0,0 +1,8 @@
+PASS rect.top is 108
+PASS rect.left is 108
+PASS rect.width is 0
+PASS rect.height is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/svg/bounding-rect-for-path-with-only-move-command.html (0 => 278271)


--- trunk/LayoutTests/fast/svg/bounding-rect-for-path-with-only-move-command.html	                        (rev 0)
+++ trunk/LayoutTests/fast/svg/bounding-rect-for-path-with-only-move-command.html	2021-05-31 06:39:50 UTC (rev 278271)
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<svg><path d="M 100,100"></path></svg>
+<script>
+rect = document.querySelector("path").getBoundingClientRect();
+shouldBe("rect.top", "108");
+shouldBe("rect.left", "108");
+shouldBe("rect.width", "0");
+shouldBe("rect.height", "0");
+</script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (278270 => 278271)


--- trunk/Source/WebCore/ChangeLog	2021-05-31 06:20:28 UTC (rev 278270)
+++ trunk/Source/WebCore/ChangeLog	2021-05-31 06:39:50 UTC (rev 278271)
@@ -1,3 +1,28 @@
+2021-05-30  Wenson Hsieh  <[email protected]>
+
+        REGRESSION (r258118): SVG paths that contain a single move command incorrect client bounding rects
+        https://bugs.webkit.org/show_bug.cgi?id=226447
+        rdar://72112744
+
+        Reviewed by Alan Bujtas.
+
+        r258118 introduced a fast path for computing the bounding rect of a `WebCore::Path` without having to
+        materialize a platform path object (e.g. `CGPathRef` on platforms that use CoreGraphics). To do this, we
+        introduce `InlinePathData` -- a variant capable of representing several types of simple `Path` objects without
+        allocating a platform path.
+
+        However, in the case where a `Path` only consists of a single `moveTo` command, this fast path for computing the
+        bounding rect currently returns the zero rect (an empty rect at the origin), rather than an empty rect at the
+        location we've moved to. This causes the offset of the bounding rect of an SVG path element that contains only a
+        single `M` drawing command to be incorrect.
+
+        Simply fix this by returning an empty rect that is offset by the `moveTo` location, rather than the origin.
+
+        Test: fast/svg/bounding-rect-for-path-with-only-move-command.html
+
+        * platform/graphics/Path.cpp:
+        (WebCore::Path::boundingRectFromInlineData const):
+
 2021-05-30  Youenn Fablet  <[email protected]>
 
         Add logging to allow relating a HTMLMediaElement to a MediaStream

Modified: trunk/Source/WebCore/platform/graphics/Path.cpp (278270 => 278271)


--- trunk/Source/WebCore/platform/graphics/Path.cpp	2021-05-31 06:20:28 UTC (rev 278270)
+++ trunk/Source/WebCore/platform/graphics/Path.cpp	2021-05-31 06:39:50 UTC (rev 278271)
@@ -490,7 +490,7 @@
     }
 
     if (hasInlineData<MoveData>())
-        return FloatRect { };
+        return {{ inlineData<MoveData>().location, FloatSize { } }};
 
     if (hasInlineData<LineData>()) {
         FloatRect result;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to