LibGfx: Fix FIXME for dotted lines dash pattern

I realized my previous solution was somewhat wrong; the issue was that
the "off" portion of the pattern needs to be the length of the line
caps * 4, which is generally `thickness * 2`. However, for 1px lines,
the line cap length is 0.5px, but a subpixel length still fills a
pixel, so you need to ceil the cap length for the spacing to look right.
This commit is contained in:
MacDue authored and Nico Weber committed 2025-08-10 13:10:44 -04:00
1 parent 53aefbda84
commit 120bb4f9d8
2 files changed
+1 -3

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 195 KiB

After

Width:  |  Height:  |  Size: 182 KiB

@@ -29,8 +29,7 @@ static Path::StrokeStyle line_style_to_stroke_style(LineStyle style, float thick
case LineStyle::Solid:
return Path::StrokeStyle { .thickness = thickness, .cap_style = Path::CapStyle::Butt, .join_style = Path::JoinStyle::Miter };
case LineStyle::Dotted:
// FIXME: 0.2f is arbitrarily chosen as it still looks okay at 1px thickness. Drawing dots is a little awkward as the round caps don't factor into the dash length.
return Path::StrokeStyle { .thickness = thickness, .cap_style = Path::CapStyle::Round, .join_style = Path::JoinStyle::Round, .dash_pattern = { 0.2f, thickness * 2 } };
return Path::StrokeStyle { .thickness = thickness, .cap_style = Path::CapStyle::Round, .join_style = Path::JoinStyle::Round, .dash_pattern = { 0, ceil(thickness / 2) * 4 } };
case LineStyle::Dashed:
return Path::StrokeStyle { .thickness = thickness, .cap_style = Path::CapStyle::Butt, .join_style = Path::JoinStyle::Miter, .dash_pattern = { thickness, thickness } };
}
@@ -45,7 +44,6 @@ void AntiAliasingPainter::draw_line(FloatPoint actual_from, FloatPoint actual_to
Path line;
line.move_to(actual_from);
line.line_to(actual_to);
stroke_path(line, color, line_style_to_stroke_style(style, thickness));
}