mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-28 07:45:20 +00:00
@cImport is going to disappear in Zig 0.17. Its deprecated in Zig 0.16. Let's remove it now. Replace @cImport with addTranslateC across pkg/ packages. Each package now has a c_import.h header that is translated at build time via addTranslateC and exposed as a "cimport" module import. Converted packages: - dcimgui - fontconfig - freetype - glslang - harfbuzz - macos - oniguruma - opengl - sentry - spirv-cross - wuffs Omitted: - gtk4-layer-shell - This has a bit more complexity with how it interacts with GTK headers, so I need to consider this a bit more. - src/ - It'll be cleaner to do this separately.
45 lines
1.1 KiB
Zig
45 lines
1.1 KiB
Zig
const std = @import("std");
|
|
const assert = std.debug.assert;
|
|
const c = @import("c");
|
|
const Pattern = @import("pattern.zig").Pattern;
|
|
|
|
pub const FontSet = opaque {
|
|
pub fn create() *FontSet {
|
|
return @ptrCast(c.FcFontSetCreate());
|
|
}
|
|
|
|
pub fn destroy(self: *FontSet) void {
|
|
c.FcFontSetDestroy(self.cval());
|
|
}
|
|
|
|
pub fn fonts(self: *FontSet) []*Pattern {
|
|
const empty: [0]*Pattern = undefined;
|
|
const s = self.cval();
|
|
if (s.fonts == null) return ∅
|
|
const ptr: [*]*Pattern = @ptrCast(@alignCast(s.fonts));
|
|
const len: usize = @intCast(s.nfont);
|
|
return ptr[0..len];
|
|
}
|
|
|
|
pub fn add(self: *FontSet, pat: *Pattern) bool {
|
|
return c.FcFontSetAdd(self.cval(), pat.cval()) == c.FcTrue;
|
|
}
|
|
|
|
pub fn print(self: *FontSet) void {
|
|
c.FcFontSetPrint(self.cval());
|
|
}
|
|
|
|
pub inline fn cval(self: *FontSet) *c.struct__FcFontSet {
|
|
return @ptrCast(@alignCast(self));
|
|
}
|
|
};
|
|
|
|
test "create" {
|
|
const testing = std.testing;
|
|
|
|
var fs = FontSet.create();
|
|
defer fs.destroy();
|
|
|
|
try testing.expectEqual(@as(usize, 0), fs.fonts().len);
|
|
}
|