From 8a38c87d90a4dd2d6db3bcab06cbb92495e2627b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 15 Oct 2024 09:37:44 -0700 Subject: [PATCH] font: use explicit error sets where we can --- src/font/Atlas.zig | 13 +++++++++---- src/font/sprite/canvas.zig | 6 +++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/font/Atlas.zig b/src/font/Atlas.zig index 938946655..4c8694b1e 100644 --- a/src/font/Atlas.zig +++ b/src/font/Atlas.zig @@ -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, diff --git a/src/font/sprite/canvas.zig b/src/font/sprite/canvas.zig index 8e04c402b..81f9095b3 100644 --- a/src/font/sprite/canvas.zig +++ b/src/font/sprite/canvas.zig @@ -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()));