|
@@ -6,6 +6,7 @@
|
|
|
|
|
|
#include <AK/Debug.h>
|
|
#include <AK/Debug.h>
|
|
#include <AK/ExtraMathConstants.h>
|
|
#include <AK/ExtraMathConstants.h>
|
|
|
|
+#include <AK/Optional.h>
|
|
#include <LibGfx/Painter.h>
|
|
#include <LibGfx/Painter.h>
|
|
#include <LibGfx/Path.h>
|
|
#include <LibGfx/Path.h>
|
|
#include <LibWeb/DOM/Document.h>
|
|
#include <LibWeb/DOM/Document.h>
|
|
@@ -102,7 +103,7 @@ void SVGPathElement::parse_attribute(FlyString const& name, DeprecatedString con
|
|
Gfx::Path path_from_path_instructions(Span<PathInstruction const> instructions)
|
|
Gfx::Path path_from_path_instructions(Span<PathInstruction const> instructions)
|
|
{
|
|
{
|
|
Gfx::Path path;
|
|
Gfx::Path path;
|
|
- Gfx::FloatPoint previous_control_point;
|
|
|
|
|
|
+ Optional<Gfx::FloatPoint> previous_control_point;
|
|
PathInstructionType last_instruction = PathInstructionType::Invalid;
|
|
PathInstructionType last_instruction = PathInstructionType::Invalid;
|
|
|
|
|
|
for (auto& instruction : instructions) {
|
|
for (auto& instruction : instructions) {
|
|
@@ -190,13 +191,13 @@ Gfx::Path path_from_path_instructions(Span<PathInstruction const> instructions)
|
|
case PathInstructionType::SmoothQuadraticBezierCurve: {
|
|
case PathInstructionType::SmoothQuadraticBezierCurve: {
|
|
clear_last_control_point = false;
|
|
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))) {
|
|
|| ((last_instruction != PathInstructionType::QuadraticBezierCurve) && (last_instruction != PathInstructionType::SmoothQuadraticBezierCurve))) {
|
|
previous_control_point = last_point;
|
|
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 };
|
|
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] };
|
|
Gfx::FloatPoint end_point = { data[0], data[1] };
|
|
@@ -231,7 +232,7 @@ Gfx::Path path_from_path_instructions(Span<PathInstruction const> instructions)
|
|
case PathInstructionType::SmoothCurve: {
|
|
case PathInstructionType::SmoothCurve: {
|
|
clear_last_control_point = false;
|
|
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))) {
|
|
|| ((last_instruction != PathInstructionType::Curve) && (last_instruction != PathInstructionType::SmoothCurve))) {
|
|
previous_control_point = last_point;
|
|
previous_control_point = last_point;
|
|
}
|
|
}
|
|
@@ -240,8 +241,8 @@ Gfx::Path path_from_path_instructions(Span<PathInstruction const> instructions)
|
|
// If the current point is (curx, cury) and the final control point of the previous path segment is (oldx2, oldy2),
|
|
// 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:
|
|
// 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))
|
|
// (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 c1 = Gfx::FloatPoint { reflected_previous_control_x, reflected_previous_control_y };
|
|
Gfx::FloatPoint c2 = { data[0], data[1] };
|
|
Gfx::FloatPoint c2 = { data[0], data[1] };
|
|
Gfx::FloatPoint p2 = { data[2], data[3] };
|
|
Gfx::FloatPoint p2 = { data[2], data[3] };
|