Skip to content

Commit 949bba0

Browse files
feat(fonts): add font load options
1 parent d2b7356 commit 949bba0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/phantom/fonts/format.zig

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
const std = @import("std");
22
const metap = @import("meta+");
33
const Font = @import("font.zig");
4+
const vizops = @import("vizops");
45
const Self = @This();
56

7+
pub const LoadOptions = struct {
8+
foregroundColor: vizops.color.Any,
9+
backgroundColor: vizops.color.Any,
10+
colorspace: std.meta.DeclEnum(vizops.color.types),
11+
colorFormat: vizops.color.fourcc.Value,
12+
};
13+
614
const BaseVTable = struct {
7-
loadBuffer: *const fn (*anyopaque, []const u8) anyerror!*Font,
15+
loadBuffer: *const fn (*anyopaque, []const u8, LoadOptions) anyerror!*Font,
816
deinit: ?*const fn (*anyopaque) void = null,
917
};
1018

1119
const FsVTable = struct {
12-
loadFile: ?*const fn (*anyopaque, std.fs.File) anyerror!*Font = null,
20+
loadFile: ?*const fn (*anyopaque, std.fs.File, LoadOptions) anyerror!*Font = null,
1321
};
1422

1523
pub const VTable = metap.structs.fields.mix(BaseVTable, if (@hasDecl(std.os.system, "fd_t")) FsVTable else struct {});
1624

1725
ptr: *anyopaque,
1826
vtable: *const VTable,
1927

20-
pub inline fn loadBuffer(self: *Self, buff: []const u8) !*Font {
21-
return self.vtable.loadBuffer(self.ptr, buff);
28+
pub inline fn loadBuffer(self: *Self, buff: []const u8, options: LoadOptions) !*Font {
29+
return self.vtable.loadBuffer(self.ptr, buff, options);
2230
}
2331

24-
pub inline fn loadFile(self: *Self, file: std.fs.File) !*Font {
32+
pub inline fn loadFile(self: *Self, file: std.fs.File, options: LoadOptions) !*Font {
2533
if (@hasDecl(std.os.system, "fd_t")) {
26-
if (self.vtable.loadFile) |f| return f(self.ptr, file);
34+
if (self.vtable.loadFile) |f| return f(self.ptr, file, options);
2735
return error.NotImplemented;
2836
}
2937
return error.NotSupported;

0 commit comments

Comments
 (0)