From fd49fb7338249291217be35bf830a1dcf36287e8 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Sat, 5 Oct 2024 22:08:17 -0400 Subject: [PATCH] font/sprite: improve double underline legibility with min 2px gap At small thicknesses, the legibility of the double underline is not great when it's a 1px line, a 1px gap, and another 1px line. --- src/font/sprite/underline.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index 50a2a2868..3648fb976 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -81,7 +81,11 @@ fn drawSingle(alloc: Allocator, width: u32, thickness: u32) !CanvasAndOffset { /// Draw a double underline. fn drawDouble(alloc: Allocator, width: u32, thickness: u32) !CanvasAndOffset { - const height: u32 = thickness * 3; + // Our gap between lines will be at least 2px. + // (i.e. if our thickness is 1, we still have a gap of 2) + const gap = @max(2, thickness); + + const height: u32 = thickness * 2 * gap; var canvas = try font.sprite.Canvas.init(alloc, width, height); canvas.rect(.{ @@ -93,7 +97,7 @@ fn drawDouble(alloc: Allocator, width: u32, thickness: u32) !CanvasAndOffset { canvas.rect(.{ .x = 0, - .y = @intCast(thickness * 2), + .y = @intCast(thickness + gap), .width = width, .height = thickness, }, .on);