test rendering box glyphs, looks OKAY

This commit is contained in:
Mitchell Hashimoto
2022-11-24 08:46:33 -08:00
parent 4b8b5c5fc1
commit 9bc8d85d67
4 changed files with 34 additions and 3 deletions

View File

@ -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;

View File

@ -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)];

View File

@ -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,

View File

@ -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,