renderer: support font style changing at runtime

This commit is contained in:
Mitchell Hashimoto
2023-09-26 08:51:04 -07:00
parent 08954feb59
commit b1389cbbfe
3 changed files with 19 additions and 1 deletions

View File

@ -34,7 +34,7 @@ const log = std.log.scoped(.font_group);
const StyleArray = std.EnumArray(Style, std.ArrayListUnmanaged(GroupFace));
/// Packed array of booleans to indicate if a style is enabled or not.
const StyleStatus = std.EnumArray(Style, bool);
pub const StyleStatus = std.EnumArray(Style, bool);
/// Map of descriptors to faces. This is used with manual codepoint maps
/// to ensure that we don't load the same font multiple times.

View File

@ -102,6 +102,7 @@ texture_color: objc.Object, // MTLTexture
pub const DerivedConfig = struct {
font_thicken: bool,
font_features: std.ArrayList([]const u8),
font_styles: font.Group.StyleStatus,
cursor_color: ?terminal.color.RGB,
cursor_text: ?terminal.color.RGB,
background: terminal.color.RGB,
@ -121,10 +122,17 @@ pub const DerivedConfig = struct {
};
errdefer font_features.deinit();
// Get our font styles
var font_styles = font.Group.StyleStatus.initFill(true);
font_styles.set(.bold, config.@"font-style-bold" != .false);
font_styles.set(.italic, config.@"font-style-italic" != .false);
font_styles.set(.bold_italic, config.@"font-style-bold-italic" != .false);
return .{
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
.font_thicken = config.@"font-thicken",
.font_features = font_features,
.font_styles = font_styles,
.cursor_color = if (config.@"cursor-color") |col|
col.toTerminalRGB()
@ -981,6 +989,7 @@ pub fn changeConfig(self: *Metal, config: *DerivedConfig) !void {
// when its not necessary but config reloading shouldn't be so
// common to cause a problem.
self.font_group.reset();
self.font_group.group.styles = config.font_styles;
self.font_group.atlas_greyscale.clear();
self.font_group.atlas_color.clear();

View File

@ -216,6 +216,7 @@ const GPUCellMode = enum(u8) {
pub const DerivedConfig = struct {
font_thicken: bool,
font_features: std.ArrayList([]const u8),
font_styles: font.Group.StyleStatus,
cursor_color: ?terminal.color.RGB,
cursor_text: ?terminal.color.RGB,
background: terminal.color.RGB,
@ -235,10 +236,17 @@ pub const DerivedConfig = struct {
};
errdefer font_features.deinit();
// Get our font styles
var font_styles = font.Group.StyleStatus.initFill(true);
font_styles.set(.bold, config.@"font-style-bold" != .false);
font_styles.set(.italic, config.@"font-style-italic" != .false);
font_styles.set(.bold_italic, config.@"font-style-bold-italic" != .false);
return .{
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
.font_thicken = config.@"font-thicken",
.font_features = font_features,
.font_styles = font_styles,
.cursor_color = if (config.@"cursor-color") |col|
col.toTerminalRGB()
@ -1211,6 +1219,7 @@ pub fn changeConfig(self: *OpenGL, config: *DerivedConfig) !void {
// when its not necessary but config reloading shouldn't be so
// common to cause a problem.
self.font_group.reset();
self.font_group.group.styles = config.font_styles;
self.font_group.atlas_greyscale.clear();
self.font_group.atlas_color.clear();