Skip to content

Commit 00b24a5

Browse files
MacDueawesomekling
authored andcommitted
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 :^)
1 parent fc41c28 commit 00b24a5

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed
196 Bytes
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<style>
2+
* {
3+
margin: 0;
4+
}
5+
body {
6+
background-color: white;
7+
}
8+
</style>
9+
<img src="./images/svg-axis-aligned-lines-ref.png">
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<style>
3+
body {
4+
background-color: white;
5+
}
6+
</style>
7+
<link rel="match" href="reference/svg-axis-aligned-lines-ref.html" />
8+
<svg width="100" height="100" viewBox="0 0 24 24" stroke="black" stroke-width="5">
9+
<line x1="12" y1="0" x2="12" y2="24"></line>
10+
<line x1="0" y1="12" x2="24" y2="12"></line>
11+
</svg>

Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ void RecordingPainter::stroke_path(StrokePathUsingColorParams params)
9797
{
9898
auto aa_translation = state().translation.map(params.translation.value_or(Gfx::FloatPoint {}));
9999
auto path_bounding_rect = params.path.bounding_box().translated(aa_translation).to_type<int>();
100+
// Increase path bounding box by `thickness` to account for stroke.
101+
path_bounding_rect.inflate(params.thickness, params.thickness);
100102
push_command(StrokePathUsingColor {
101103
.path_bounding_rect = path_bounding_rect,
102104
.path = params.path,
@@ -110,6 +112,8 @@ void RecordingPainter::stroke_path(StrokePathUsingPaintStyleParams params)
110112
{
111113
auto aa_translation = state().translation.map(params.translation.value_or(Gfx::FloatPoint {}));
112114
auto path_bounding_rect = params.path.bounding_box().translated(aa_translation).to_type<int>();
115+
// Increase path bounding box by `thickness` to account for stroke.
116+
path_bounding_rect.inflate(params.thickness, params.thickness);
113117
push_command(StrokePathUsingPaintStyle {
114118
.path_bounding_rect = path_bounding_rect,
115119
.path = params.path,

0 commit comments

Comments
 (0)