font/sprite: rect must be smaller than canvas dims

This commit is contained in:
Mitchell Hashimoto
2024-02-24 13:19:49 -08:00
parent 759c8cddb4
commit 796d1312ff
2 changed files with 8 additions and 6 deletions

View File

@ -424,9 +424,6 @@ 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),
@ -436,6 +433,10 @@ const PixmanImpl = struct {
}, },
}; };
assert(boxes[0].x1 >= 0);
assert(boxes[0].y1 >= 0);
assert(boxes[0].x2 <= @as(i32, @intCast(self.image.getWidth())));
assert(boxes[0].y2 <= @as(i32, @intCast(self.image.getHeight())));
self.image.fillBoxes(.src, color.pixmanColor(), boxes) catch {}; self.image.fillBoxes(.src, color.pixmanColor(), boxes) catch {};
} }

View File

@ -80,13 +80,14 @@ 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 -| self.thickness)); const y = bottom -| self.thickness;
const max_height = self.height - y;
canvas.rect(.{ canvas.rect(.{
.x = 0, .x = 0,
.y = y, .y = @intCast(y),
.width = self.width, .width = self.width,
.height = self.thickness, .height = @min(self.thickness, max_height),
}, .on); }, .on);
} }