From 003b100707a7125f1e84ce44b42e0b1bd8b3484d Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Wed, 25 Sep 2024 12:01:24 -0600 Subject: [PATCH] font: remove fudge factors in ul and st position calculations These were present because of an incorrect calculation in the underline sprite renderer, and are no longer necessary. --- src/font/face/coretext.zig | 7 +++---- src/font/face/freetype.zig | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index ee2460572..dacb79476 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -612,9 +612,8 @@ pub const Face = struct { // we subtract half of the ex height to go back up to the // correct height that should evenly split lowercase text. const pos = layout_metrics.ascent - - ex_height * 0.5 + - strikethrough_thickness * 0.5 + - 1; + ex_height * 0.5 - + strikethrough_thickness * 0.5; break :strikethrough_position @ceil(pos); }; @@ -625,7 +624,7 @@ pub const Face = struct { // The final underline position is +y from the TOP (confusing) // so we have to subtract from the cell height. const underline_position = @ceil(layout_metrics.ascent - - @as(f32, @floatCast(ct_font.getUnderlinePosition())) + 1); + @as(f32, @floatCast(ct_font.getUnderlinePosition()))); // Note: is this useful? // const units_per_em = ct_font.getUnitsPerEm(); diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index f764ac61d..dae46d6d6 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -678,8 +678,8 @@ pub const Face = struct { @intCast(face.handle.*.size.*.metrics.y_scale), ))) / 64; - // We use the declared underline position if its available - const declared = @ceil(cell_height - cell_baseline - declared_px - underline_thickness * 0.5 + 1); + // We use the declared underline position if its available. + const declared = @ceil(cell_height - cell_baseline - declared_px - underline_thickness * 0.5); if (declared > 0) break :underline_pos declared; @@ -702,13 +702,13 @@ pub const Face = struct { ))) / 64; break :st .{ - .pos = @ceil(cell_height - cell_baseline - pos + thickness + 1), + .pos = @ceil(cell_height - cell_baseline - pos), .thickness = thickness, }; } else .{ // Exactly 50% of the ex height so that our strikethrough is // centered through lowercase text. This is a common choice. - .pos = @ceil(cell_height - cell_baseline - ex_height * 0.5 + underline_thickness), + .pos = @ceil(cell_height - cell_baseline - ex_height * 0.5 - underline_thickness * 0.5), .thickness = underline_thickness, };