summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-03-04 20:53:32 +0200
committerAndreas Kling <kling@serenityos.org>2022-03-04 20:08:58 +0100
commit55c247d04412bbf0ae44a48ab17705af1b145e0d (patch)
tree3eee39c72a0ac3b33d007bc5bcb289fc2996145a /Userland
parent6608812e4b24ceff1b84c095b24e7c249085e317 (diff)
downloadserenity-55c247d04412bbf0ae44a48ab17705af1b145e0d.zip
LibWeb: Correct SVG smooth curve reflected control point calculation
We were calculating the reflected control points in the svg smooth curve instructions incorrectly, and this issue was masked by the fact that we were treating it as a relative coordinate in relative mode.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp
index 3b3e5cd362..b7a8effc18 100644
--- a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp
+++ b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp
@@ -237,14 +237,17 @@ Gfx::Path& SVGPathElement::get_path()
m_previous_control_point = last_point;
}
- auto reflected_previous_control_x = last_point.dx_relative_to(m_previous_control_point);
- auto reflected_previous_control_y = last_point.dy_relative_to(m_previous_control_point);
+ // 9.5.2. Reflected control points https://svgwg.org/svg2-draft/paths.html#ReflectedControlPoints
+ // If the current point is (curx, cury) and the final control point of the previous path segment is (oldx2, oldy2),
+ // then the reflected point (i.e., (newx1, newy1), the first control point of the current path segment) is:
+ // (newx1, newy1) = (curx - (oldx2 - curx), cury - (oldy2 - cury))
+ auto reflected_previous_control_x = last_point.x() - m_previous_control_point.dx_relative_to(last_point);
+ auto reflected_previous_control_y = last_point.y() - m_previous_control_point.dy_relative_to(last_point);
Gfx::FloatPoint c1 = Gfx::FloatPoint { reflected_previous_control_x, reflected_previous_control_y };
Gfx::FloatPoint c2 = { data[0], data[1] };
Gfx::FloatPoint p2 = { data[2], data[3] };
if (!absolute) {
p2 += last_point;
- c1 += last_point;
c2 += last_point;
}
path.cubic_bezier_curve_to(c1, c2, p2);