font: use explicit error sets where we can

This commit is contained in:
Mitchell Hashimoto
2024-10-15 09:37:44 -07:00
parent bb2c8e479d
commit 8a38c87d90
2 changed files with 14 additions and 5 deletions

View File

@ -83,7 +83,7 @@ pub const Region = extern struct {
height: u32,
};
pub fn init(alloc: Allocator, size: u32, format: Format) !Atlas {
pub fn init(alloc: Allocator, size: u32, format: Format) Allocator.Error!Atlas {
var result = Atlas{
.data = try alloc.alloc(u8, size * size * format.depth()),
.size = size,
@ -111,7 +111,12 @@ pub fn deinit(self: *Atlas, alloc: Allocator) void {
///
/// May allocate to add a new rectangle into the internal list of rectangles.
/// This will not automatically enlarge the texture if it is full.
pub fn reserve(self: *Atlas, alloc: Allocator, width: u32, height: u32) !Region {
pub fn reserve(
self: *Atlas,
alloc: Allocator,
width: u32,
height: u32,
) (Allocator.Error || Error)!Region {
// x, y are populated within :best_idx below
var region: Region = .{ .x = 0, .y = 0, .width = width, .height = height };
@ -310,9 +315,9 @@ pub fn dump(self: Atlas, writer: anytype) !void {
.grayscale => '5',
.rgb => '6',
else => {
log.err("Unsupported format for dump: {}", .{ self.format });
log.err("Unsupported format for dump: {}", .{self.format});
@panic("Cannot dump this atlas format.");
}
},
}),
self.size,
self.size,

View File

@ -102,7 +102,11 @@ pub const Canvas = struct {
}
/// Write the data in this drawing to the atlas.
pub fn writeAtlas(self: *Canvas, alloc: Allocator, atlas: *font.Atlas) !font.Atlas.Region {
pub fn writeAtlas(
self: *Canvas,
alloc: Allocator,
atlas: *font.Atlas,
) (Allocator.Error || font.Atlas.Error)!font.Atlas.Region {
assert(atlas.format == .grayscale);
const width = @as(u32, @intCast(self.sfc.getWidth()));