From 00b24a55b1897f97b430e5c05c7b730d4cc092e5 Mon Sep 17 00:00:00 2001 From: MacDue Date: Mon, 8 Jan 2024 22:26:37 +0000 Subject: [PATCH] LibWeb: Fix drawing axis-aligned lines Previously, these were clipped by the RecordingPainter, which used the path's bounding box (which in this case is zero width or height). The fix is to expand the bounding box by the stroke width. Fixes #22661 Note: This is unrelated to any recent LibGfx changes :^) --- .../images/svg-axis-aligned-lines-ref.png | Bin 0 -> 196 bytes .../Ref/reference/svg-axis-aligned-lines-ref.html | 9 +++++++++ Tests/LibWeb/Ref/svg-axis-aligned-lines.html | 11 +++++++++++ .../LibWeb/Painting/RecordingPainter.cpp | 4 ++++ 4 files changed, 24 insertions(+) create mode 100644 Tests/LibWeb/Ref/reference/images/svg-axis-aligned-lines-ref.png create mode 100644 Tests/LibWeb/Ref/reference/svg-axis-aligned-lines-ref.html create mode 100644 Tests/LibWeb/Ref/svg-axis-aligned-lines.html diff --git a/Tests/LibWeb/Ref/reference/images/svg-axis-aligned-lines-ref.png b/Tests/LibWeb/Ref/reference/images/svg-axis-aligned-lines-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..2672a5cc5ffb0211141c624b75a03673b78da5b8 GIT binary patch literal 196 zcmeAS@N?(olHy`uVBq!ia0y~yU}#`qV5sC^U|?Xla-!@Q0|P_1r;B4q#=W=KSMwe) z;BmcpU|qPtrIk#~yEAt;h)TM=bbtOSUG`OxZ44s=!w;ziQy1`oG^1hz<_kq{1sA9t zcXo&rfJq(L&1f6m%O`*GqrikUt_}5nSYa{ +* { + margin: 0; +} +body { + background-color: white; +} + + diff --git a/Tests/LibWeb/Ref/svg-axis-aligned-lines.html b/Tests/LibWeb/Ref/svg-axis-aligned-lines.html new file mode 100644 index 0000000000..f37349d900 --- /dev/null +++ b/Tests/LibWeb/Ref/svg-axis-aligned-lines.html @@ -0,0 +1,11 @@ + + + + + + + diff --git a/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp b/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp index c82e55180b..dc3b8c6c69 100644 --- a/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp +++ b/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp @@ -97,6 +97,8 @@ void RecordingPainter::stroke_path(StrokePathUsingColorParams params) { auto aa_translation = state().translation.map(params.translation.value_or(Gfx::FloatPoint {})); auto path_bounding_rect = params.path.bounding_box().translated(aa_translation).to_type(); + // Increase path bounding box by `thickness` to account for stroke. + path_bounding_rect.inflate(params.thickness, params.thickness); push_command(StrokePathUsingColor { .path_bounding_rect = path_bounding_rect, .path = params.path, @@ -110,6 +112,8 @@ void RecordingPainter::stroke_path(StrokePathUsingPaintStyleParams params) { auto aa_translation = state().translation.map(params.translation.value_or(Gfx::FloatPoint {})); auto path_bounding_rect = params.path.bounding_box().translated(aa_translation).to_type(); + // Increase path bounding box by `thickness` to account for stroke. + path_bounding_rect.inflate(params.thickness, params.thickness); push_command(StrokePathUsingPaintStyle { .path_bounding_rect = path_bounding_rect, .path = params.path,