a cell is empty only if it also has no styling

Previously we only checked if it had no character. With text shaping,
this was causing runs of only empty backgrounds to not render.
This commit is contained in:
Mitchell Hashimoto
2022-09-13 10:12:44 -07:00
parent b5f9e8abf0
commit 7bde20a43d
3 changed files with 46 additions and 3 deletions

View File

@ -579,8 +579,8 @@ pub fn updateCell(
}); });
} }
// If the cell is empty then we draw nothing in the box. // If the cell has a character, draw it
if (!cell.empty()) { if (cell.char > 0) {
// Render // Render
const face = self.font_group.group.faceFromIndex(shaper_run.font_index); const face = self.font_group.group.faceFromIndex(shaper_run.font_index);
const glyph = try self.font_group.renderGlyph( const glyph = try self.font_group.renderGlyph(

View File

@ -276,6 +276,42 @@ test "run iterator" {
} }
} }
test "run iterator: empty cells with background set" {
const testing = std.testing;
const alloc = testing.allocator;
var testdata = try testShaper(alloc);
defer testdata.deinit();
{
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 5, 0);
defer screen.deinit();
try screen.testWriteString("A");
// Get our first row
const row = screen.getRow(.{ .active = 0 });
row.getCellPtr(1).bg = try terminal.color.Name.cyan.default();
row.getCellPtr(1).attrs.has_bg = true;
row.getCellPtr(2).fg = try terminal.color.Name.yellow.default();
row.getCellPtr(2).attrs.has_fg = true;
// Get our run iterator
var shaper = testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }));
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
// The run should have length 3 because of the two background
// cells.
try testing.expectEqual(@as(u32, 3), shaper.hb_buf.getLength());
const cells = try shaper.shape(run);
try testing.expectEqual(@as(usize, 3), cells.len);
}
try testing.expectEqual(@as(usize, 1), count);
}
}
test "shape" { test "shape" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;

View File

@ -183,7 +183,14 @@ pub const Cell = struct {
/// True if the cell should be skipped for drawing /// True if the cell should be skipped for drawing
pub fn empty(self: Cell) bool { pub fn empty(self: Cell) bool {
return self.char == 0; // Get our backing integer for our packed struct of attributes
const AttrInt = @Type(.{ .Int = .{
.signedness = .unsigned,
.bits = @bitSizeOf(@TypeOf(self.attrs)),
} });
// We're empty if we have no char AND we have no styling
return self.char == 0 and @bitCast(AttrInt, self.attrs) == 0;
} }
/// The width of the cell. /// The width of the cell.