font/sprite: test for thick underline, assertion on x/y for rect

This commit is contained in:
Mitchell Hashimoto
2024-02-24 09:30:04 -08:00
parent 0f19251aa6
commit 759c8cddb4
2 changed files with 24 additions and 1 deletions

View File

@ -424,6 +424,9 @@ const PixmanImpl = struct {
/// Draw and fill a rectangle. This is the main primitive for drawing /// Draw and fill a rectangle. This is the main primitive for drawing
/// lines as well (which are just generally skinny rectangles...) /// lines as well (which are just generally skinny rectangles...)
pub fn rect(self: *Canvas, v: Rect, color: Color) void { pub fn rect(self: *Canvas, v: Rect, color: Color) void {
assert(v.x >= 0);
assert(v.y >= 0);
const boxes = &[_]pixman.Box32{ const boxes = &[_]pixman.Box32{
.{ .{
.x1 = @intCast(v.x), .x1 = @intCast(v.x),

View File

@ -80,7 +80,7 @@ const Draw = struct {
// Ensure we never overflow out of bounds on the canvas // Ensure we never overflow out of bounds on the canvas
const y_max = self.height -| 1; const y_max = self.height -| 1;
const bottom = @min(self.pos + self.thickness, y_max); const bottom = @min(self.pos + self.thickness, y_max);
const y = @as(i32, @intCast(bottom)) - @as(i32, @intCast(self.thickness)); const y = @as(i32, @intCast(bottom -| self.thickness));
canvas.rect(.{ canvas.rect(.{
.x = 0, .x = 0,
@ -224,6 +224,26 @@ test "single" {
); );
} }
test "single large thickness" {
const testing = std.testing;
const alloc = testing.allocator;
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
defer atlas_greyscale.deinit(alloc);
// unrealistic thickness but used to cause a crash
// https://github.com/mitchellh/ghostty/pull/1548
_ = try renderGlyph(
alloc,
&atlas_greyscale,
.underline,
36,
18,
9,
200,
);
}
test "curly" { test "curly" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;