diff --git a/src/Grid.zig b/src/Grid.zig index a53d245c6..5e23d4d29 100644 --- a/src/Grid.zig +++ b/src/Grid.zig @@ -106,6 +106,7 @@ pub fn init(alloc: Allocator) !Grid { var fam = try font.Family.init(atlas); errdefer fam.deinit(alloc); try fam.loadFaceFromMemory(.regular, face_ttf, 32); + try fam.loadFaceFromMemory(.bold, face_bold_ttf, 32); // Load all visible ASCII characters and build our cell width based on // the widest character that we see. @@ -310,13 +311,19 @@ pub fn updateCells(self: *Grid, term: Terminal) !void { // If the cell is empty then we draw nothing in the box. if (cell.empty()) continue; + // Determine our glyph styling + const style: font.Style = if (cell.attrs.bold == 1) + .bold + else + .regular; + // Get our glyph // TODO: if we add a glyph, I think we need to rerender the texture. - const glyph = if (self.font_atlas.getGlyph(cell.char, .regular)) |glyph| + const glyph = if (self.font_atlas.getGlyph(cell.char, style)) |glyph| glyph else glyph: { self.atlas_dirty = true; - break :glyph try self.font_atlas.addGlyph(self.alloc, cell.char, .regular); + break :glyph try self.font_atlas.addGlyph(self.alloc, cell.char, style); }; const fg = cell.fg orelse self.foreground; @@ -509,4 +516,4 @@ test "GridSize update rounding" { } const face_ttf = @embedFile("../fonts/FiraCode-Regular.ttf"); -//const face_ttf = @embedFile("../fonts/Inconsolata-Regular.ttf"); +const face_bold_ttf = @embedFile("../fonts/FiraCode-Bold.ttf"); diff --git a/src/font/Family.zig b/src/font/Family.zig index 6a419026f..8a81e21cc 100644 --- a/src/font/Family.zig +++ b/src/font/Family.zig @@ -32,6 +32,7 @@ glyphs: std.AutoHashMapUnmanaged(GlyphKey, Glyph) = .{}, /// The font faces representing all the styles in this family. /// These should be set directly or via various loader functions. regular: ?Face = null, +bold: ?Face = null, /// This struct is used for the hash key for glyphs. const GlyphKey = struct { @@ -55,6 +56,7 @@ pub fn deinit(self: *Family, alloc: Allocator) void { self.glyphs.deinit(alloc); if (self.regular) |*face| face.deinit(); + if (self.bold) |*face| face.deinit(); if (ftc.FT_Done_FreeType(self.ft_library) != ftok) log.err("failed to clean up FreeType", .{}); @@ -77,7 +79,7 @@ pub fn loadFaceFromMemory( @field(self, switch (style) { .regular => "regular", - .bold => unreachable, + .bold => "bold", .italic => unreachable, .bold_italic => unreachable, }) = face; @@ -106,7 +108,7 @@ pub fn addGlyph(self: *Family, alloc: Allocator, v: anytype, style: Style) !*Gly // Real is the face we SHOULD use for this style. var real = switch (style) { .regular => self.regular, - .bold => unreachable, + .bold => self.bold, .italic => unreachable, .bold_italic => unreachable, }; diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 920ad1335..315ee203b 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -23,6 +23,7 @@ pub const Cell = struct { /// On/off attributes that can be set /// TODO: pack it attrs: struct { + bold: u1 = 0, inverse: u1 = 0, } = .{}, diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 8e20ea1c5..4e0c982fd 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -150,6 +150,10 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void { self.cursor.pen.attrs = .{}; }, + .bold => { + self.cursor.pen.attrs.bold = 1; + }, + .inverse => { self.cursor.pen.attrs.inverse = 1; },