From 5553f7bf688b69b006f437223724d6cf33f969ce Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Thu, 3 Jul 2025 16:49:51 -0600 Subject: [PATCH] font: always maximize size of emoji and center them --- src/font/SharedGrid.zig | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/font/SharedGrid.zig b/src/font/SharedGrid.zig index dcfa0a551..48c7239b2 100644 --- a/src/font/SharedGrid.zig +++ b/src/font/SharedGrid.zig @@ -265,13 +265,36 @@ pub fn renderGlyph( .emoji => &self.atlas_color, }; + var render_opts = opts; + + // Always use these constraints for emoji. + if (p == .emoji) { + render_opts.constraint = .{ + // Make the emoji as wide as possible, scaling proportionally, + // but then scale it down as necessary if its new size exceeds + // the cell height. + .size_horizontal = .cover, + .size_vertical = .fit, + + // Center the emoji in its cells. + .align_horizontal = .center, + .align_vertical = .center, + + // Add a small bit of padding so the emoji + // doesn't quite touch the edges of the cells. + .pad_left = 0.025, + .pad_right = 0.025, + }; + } + + // Render into the atlas const glyph = self.resolver.renderGlyph( alloc, atlas, index, glyph_index, - opts, + render_opts, ) catch |err| switch (err) { // If the atlas is full, we resize it error.AtlasFull => blk: { @@ -281,7 +304,7 @@ pub fn renderGlyph( atlas, index, glyph_index, - opts, + render_opts, ); },