Skip to content

Commit e7fb500

Browse files
feat: init fonts
1 parent 0efe1e9 commit e7fb500

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/phantom.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const root = @import("root");
22

33
pub const display = @import("phantom/display.zig");
4+
pub const fonts = @import("phantom/fonts.zig");
45
pub const gpu = @import("phantom/gpu.zig");
56
pub const math = @import("phantom/math.zig");
67
pub const painting = @import("phantom/painting.zig");

src/phantom/fonts.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub const Font = @import("fonts/font.zig");

src/phantom/fonts/font.zig

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const std = @import("std");
2+
const painting = @import("../painting.zig");
3+
const vizops = @import("vizops");
4+
const Self = @This();
5+
6+
pub const Glyph = struct {
7+
index: u32,
8+
fb: *painting.fb.Base,
9+
size: vizops.vector.Uint8Vector,
10+
bearing: vizops.vector.Int8Vector,
11+
advance: vizops.vector.Int8Vector,
12+
};
13+
14+
pub const VTable = struct {
15+
lookupGlyph: *const fn (*anyopaque, u21) anyerror!Glyph = null,
16+
getSize: *const fn (*anyopaque) vizops.vector.UsizeVector2,
17+
deinit: ?*const fn (*anyopaque) void = null,
18+
};
19+
20+
vtable: *const VTable,
21+
ptr: *anyopaque,
22+
23+
pub inline fn lookupGlyph(self: *Self, codepoint: u21) !Glyph {
24+
return self.vtable.lookupGlyph(self.ptr, codepoint);
25+
}
26+
27+
pub inline fn getSize(self: *Self) vizops.vector.UsizeVector2 {
28+
return self.vtable.getSize(self.ptr);
29+
}
30+
31+
pub inline fn deinit(self: *Self) void {
32+
return if (self.vtable.deinit) |f| f(self.ptr) else {};
33+
}

0 commit comments

Comments
 (0)