From 63f82119cd7ecd7fac632fc52a865a0a67a04ad9 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Mon, 14 Oct 2024 14:46:43 -0400 Subject: [PATCH 1/2] font/sprite(underline): add thickness correction to undercurl --- src/font/sprite/underline.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index 67bc38b41..3a7d5cb98 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -163,7 +163,9 @@ fn drawDashed(alloc: Allocator, width: u32, thickness: u32) !CanvasAndOffset { /// geometry. fn drawCurly(alloc: Allocator, width: u32, thickness: u32) !CanvasAndOffset { const float_width: f64 = @floatFromInt(width); - const float_thick: f64 = @floatFromInt(thickness); + // Because of we way we draw the undercurl, we end up making it around 1px + // thicker than it should be, to fix this we just reduce the thickness by 1. + const float_thick: f64 = @floatFromInt(@max(1, thickness -| 1)); // Calculate the wave period for a single character // `2 * pi...` = 1 peak per character From 2462921681d7967d4f9079e5ba050a1a044ad087 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Mon, 14 Oct 2024 14:53:09 -0400 Subject: [PATCH 2/2] font/sprite(underline): make undercurl segment symmetrical Previously was biased half a pixel to one side. --- src/font/sprite/underline.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index 3a7d5cb98..29bf7b251 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -187,7 +187,9 @@ fn drawCurly(alloc: Allocator, width: u32, thickness: u32) !CanvasAndOffset { // follow Xiaolin Wu's antialias algorithm to draw the curve var x: u32 = 0; while (x < width) : (x += 1) { - const t: f64 = @as(f64, @floatFromInt(x)) * wave_period; + // We sample the wave function at the *middle* of each + // pixel column, to ensure that it renders symmetrically. + const t: f64 = (@as(f64, @floatFromInt(x)) + 0.5) * wave_period; // Use the slope at this location to add thickness to // the line on this column, counteracting the thinning // caused by the slope.