diff --git a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp index 8fa4e33e40..1a856cb2f6 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -102,7 +103,7 @@ void SVGPathElement::parse_attribute(FlyString const& name, DeprecatedString con Gfx::Path path_from_path_instructions(Span instructions) { Gfx::Path path; - Gfx::FloatPoint previous_control_point; + Optional previous_control_point; PathInstructionType last_instruction = PathInstructionType::Invalid; for (auto& instruction : instructions) { @@ -190,13 +191,13 @@ Gfx::Path path_from_path_instructions(Span instructions) case PathInstructionType::SmoothQuadraticBezierCurve: { clear_last_control_point = false; - if (previous_control_point.is_null() + if (!previous_control_point.has_value() || ((last_instruction != PathInstructionType::QuadraticBezierCurve) && (last_instruction != PathInstructionType::SmoothQuadraticBezierCurve))) { previous_control_point = last_point; } - auto dx_end_control = last_point.dx_relative_to(previous_control_point); - auto dy_end_control = last_point.dy_relative_to(previous_control_point); + auto dx_end_control = last_point.dx_relative_to(previous_control_point.value()); + auto dy_end_control = last_point.dy_relative_to(previous_control_point.value()); auto control_point = Gfx::FloatPoint { last_point.x() + dx_end_control, last_point.y() + dy_end_control }; Gfx::FloatPoint end_point = { data[0], data[1] }; @@ -231,7 +232,7 @@ Gfx::Path path_from_path_instructions(Span instructions) case PathInstructionType::SmoothCurve: { clear_last_control_point = false; - if (previous_control_point.is_null() + if (!previous_control_point.has_value() || ((last_instruction != PathInstructionType::Curve) && (last_instruction != PathInstructionType::SmoothCurve))) { previous_control_point = last_point; } @@ -240,8 +241,8 @@ Gfx::Path path_from_path_instructions(Span instructions) // 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() - previous_control_point.dx_relative_to(last_point); - auto reflected_previous_control_y = last_point.y() - previous_control_point.dy_relative_to(last_point); + auto reflected_previous_control_x = last_point.x() - previous_control_point.value().dx_relative_to(last_point); + auto reflected_previous_control_y = last_point.y() - previous_control_point.value().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] };