From ac68686036012ad851367946baa884b8fd87be48 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Mon, 23 Sep 2024 22:30:59 -0600 Subject: [PATCH] freetype: fix underline position calculation --- src/font/face/freetype.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index 32664a1fd..f764ac61d 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -668,13 +668,18 @@ pub const Face = struct { // The underline position. This is a value from the top where the // underline should go. const underline_position: f32 = underline_pos: { + // From the FreeType docs: + // > `underline_position` + // > The position, in font units, of the underline line for + // > this face. It is the center of the underlining stem. + const declared_px = @as(f32, @floatFromInt(freetype.mulFix( face.handle.*.underline_position, @intCast(face.handle.*.size.*.metrics.y_scale), ))) / 64; // We use the declared underline position if its available - const declared = cell_height - cell_baseline - declared_px; + const declared = @ceil(cell_height - cell_baseline - declared_px - underline_thickness * 0.5 + 1); if (declared > 0) break :underline_pos declared;