From 0bb2d22052cb9f796880570935b028a6f9095ca4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 1 Jul 2023 10:01:40 -0700 Subject: [PATCH] renderer: hook up font thickening setting --- src/renderer/Metal.zig | 12 ++++++++++++ src/renderer/OpenGL.zig | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 61e12a55b..760a2813b 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -129,6 +129,7 @@ const GPUCellMode = enum(u8) { /// configuration. This must be exported so that we don't need to /// pass around Config pointers which makes memory management a pain. pub const DerivedConfig = struct { + font_thicken: bool, cursor_color: ?terminal.color.RGB, background: terminal.color.RGB, foreground: terminal.color.RGB, @@ -142,6 +143,8 @@ pub const DerivedConfig = struct { _ = alloc_gpa; return .{ + .font_thicken = config.@"font-thicken", + .cursor_color = if (config.@"cursor-color") |col| col.toTerminalRGB() else @@ -738,6 +741,14 @@ fn drawCells( /// Update the configuration. pub fn changeConfig(self: *Metal, config: *DerivedConfig) !void { + // If font thickening settings change, we need to reset our + // font texture completely because we need to re-render the glyphs. + if (self.config.font_thicken != config.font_thicken) { + self.font_group.reset(); + self.font_group.atlas_greyscale.clear(); + self.font_group.atlas_color.clear(); + } + self.config = config.*; } @@ -998,6 +1009,7 @@ pub fn updateCell( shaper_cell.glyph_index, .{ .max_height = @intFromFloat(@ceil(self.cell_size.height)), + .thicken = self.config.font_thicken, }, ); diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index f130fc6ab..e48c9d9bf 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -226,6 +226,7 @@ const GPUCellMode = enum(u8) { /// configuration. This must be exported so that we don't need to /// pass around Config pointers which makes memory management a pain. pub const DerivedConfig = struct { + font_thicken: bool, cursor_color: ?terminal.color.RGB, background: terminal.color.RGB, foreground: terminal.color.RGB, @@ -239,6 +240,8 @@ pub const DerivedConfig = struct { _ = alloc_gpa; return .{ + .font_thicken = config.@"font-thicken", + .cursor_color = if (config.@"cursor-color") |col| col.toTerminalRGB() else @@ -1144,7 +1147,10 @@ pub fn updateCell( self.alloc, shaper_run.font_index, shaper_cell.glyph_index, - .{ .max_height = @intFromFloat(@ceil(self.cell_size.height)) }, + .{ + .max_height = @intFromFloat(@ceil(self.cell_size.height)), + .thicken = self.config.font_thicken, + }, ); // If we're rendering a color font, we use the color atlas @@ -1254,6 +1260,14 @@ fn gridSize(self: *const OpenGL, screen_size: renderer.ScreenSize) renderer.Grid /// Update the configuration. pub fn changeConfig(self: *OpenGL, config: *DerivedConfig) !void { + // If font thickening settings change, we need to reset our + // font texture completely because we need to re-render the glyphs. + if (self.config.font_thicken != config.font_thicken) { + self.font_group.reset(); + self.font_group.atlas_greyscale.clear(); + self.font_group.atlas_color.clear(); + } + self.config = config.*; }