diff --git a/src/Window.zig b/src/Window.zig index ebe3b67c7..f5243deab 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -289,6 +289,17 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window { // Pre-calculate our initial cell size ourselves. const cell_size = try renderer.CellSize.init(alloc, font_group); + // Setup our box font + font_group.group.box_font = font.BoxFont{ + .width = @floatToInt(u32, cell_size.width), + .height = @floatToInt(u32, cell_size.height), + .thickness = 2, + }; + + // TEST + const idx = (try font_group.indexForCodepoint(alloc, 0x2500, .regular, null)).?; + _ = try font_group.renderGlyph(alloc, idx, 0x2500, null); + // Convert our padding from points to pixels const padding_x = (@intToFloat(f32, config.@"window-padding-x") * x_dpi) / 72; const padding_y = (@intToFloat(f32, config.@"window-padding-y") * y_dpi) / 72; diff --git a/src/font/Group.zig b/src/font/Group.zig index 6d9766cf8..b2cd242ea 100644 --- a/src/font/Group.zig +++ b/src/font/Group.zig @@ -237,7 +237,19 @@ fn indexForCodepointExact(self: Group, cp: u32, style: Style, p: ?Presentation) return null; } -/// Return the Face represented by a given FontIndex. +/// Returns the presentation for a specific font index. This is useful for +/// determining what atlas is needed. +pub fn presentationFromIndex(self: Group, index: FontIndex) !font.Presentation { + if (index.special()) |sp| switch (sp) { + .box => return .text, + }; + + const face = try self.faceFromIndex(index); + return face.presentation; +} + +/// Return the Face represented by a given FontIndex. Note that special +/// fonts (i.e. box glyphs) do not have a face. pub fn faceFromIndex(self: Group, index: FontIndex) !Face { if (index.special() != null) return error.SpecialHasNoFace; const deferred = &self.faces.get(index.style).items[@intCast(usize, index.idx)]; diff --git a/src/font/GroupCache.zig b/src/font/GroupCache.zig index 4ed68f6dc..77b488bc8 100644 --- a/src/font/GroupCache.zig +++ b/src/font/GroupCache.zig @@ -132,8 +132,10 @@ pub fn renderGlyph( if (gop.found_existing) return gop.value_ptr.*; // Uncached, render it - const face = try self.group.faceFromIndex(index); - const atlas: *Atlas = if (face.presentation == .emoji) &self.atlas_color else &self.atlas_greyscale; + const atlas: *Atlas = switch (try self.group.presentationFromIndex(index)) { + .text => &self.atlas_greyscale, + .emoji => &self.atlas_color, + }; const glyph = self.group.renderGlyph( alloc, atlas, diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index db274a42e..9336c1de7 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -501,6 +501,12 @@ pub fn setFontSize(self: *OpenGL, size: font.face.DesiredSize) !void { if (std.meta.eql(self.cell_size, new_cell_size)) return; self.cell_size = new_cell_size; + // Set the cell size of the box font + if (self.font_group.group.box_font) |*box| { + box.width = @floatToInt(u32, self.cell_size.width); + box.height = @floatToInt(u32, self.cell_size.height); + } + // Notify the window that the cell size changed. _ = self.window_mailbox.push(.{ .cell_size = new_cell_size,