From dafc02e29c7138e9b5758c64e4fe0f0d18c2526c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 12 Dec 2023 20:14:02 -0800 Subject: [PATCH] font: adjust cell baseline to center after modification, fix styles Fixes #1064 Fixes #1066 --- src/font/face/Metrics.zig | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/font/face/Metrics.zig b/src/font/face/Metrics.zig index 2e7309dc4..3f4c76d86 100644 --- a/src/font/face/Metrics.zig +++ b/src/font/face/Metrics.zig @@ -32,10 +32,21 @@ pub fn apply(self: *Metrics, mods: ModifierSet) void { .cell_height, => |tag| { const original = @field(self, @tagName(tag)); - @field(self, @tagName(tag)) = @max( - entry.value_ptr.apply(original), - 1, - ); + const new = @max(entry.value_ptr.apply(original), 1); + @field(self, @tagName(tag)) = new; + + // For cell height, we have to also modify some positions + // that are absolute from the top of the cell. The main goal + // here is to center the baseline so that text is vertically + // centered in the cell. + if (comptime tag == .cell_height) { + // We split the difference in half because we want to + // center the baseline in the cell. + const diff = (new - original) / 2; + self.cell_baseline += diff; + self.underline_position += diff; + self.strikethrough_position += diff; + } }, inline else => |tag| {