mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
fontconfig: font sets
This commit is contained in:
39
pkg/fontconfig/font_set.zig
Normal file
39
pkg/fontconfig/font_set.zig
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const assert = std.debug.assert;
|
||||||
|
const c = @import("c.zig");
|
||||||
|
const Pattern = @import("pattern.zig").Pattern;
|
||||||
|
|
||||||
|
pub const FontSet = opaque {
|
||||||
|
pub fn create() *FontSet {
|
||||||
|
return @ptrCast(*FontSet, c.FcFontSetCreate());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn destroy(self: *FontSet) void {
|
||||||
|
c.FcFontSetDestroy(self.cval());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn len(self: *FontSet) u32 {
|
||||||
|
return @intCast(u32, self.cval().nfont);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get(self: *FontSet, idx: usize) *Pattern {
|
||||||
|
assert(idx < self.len());
|
||||||
|
return @ptrCast(*Pattern, self.cval().fonts[idx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn cval(self: *FontSet) *c.struct__FcFontSet {
|
||||||
|
return @ptrCast(
|
||||||
|
*c.struct__FcFontSet,
|
||||||
|
@alignCast(@alignOf(c.struct__FcFontSet), self),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
test "create" {
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
var fs = FontSet.create();
|
||||||
|
defer fs.destroy();
|
||||||
|
|
||||||
|
try testing.expectEqual(@as(u32, 0), fs.len());
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
pub const c = @import("c.zig");
|
pub const c = @import("c.zig");
|
||||||
pub usingnamespace @import("init.zig");
|
pub usingnamespace @import("init.zig");
|
||||||
pub usingnamespace @import("config.zig");
|
pub usingnamespace @import("config.zig");
|
||||||
|
pub usingnamespace @import("font_set.zig");
|
||||||
pub usingnamespace @import("object_set.zig");
|
pub usingnamespace @import("object_set.zig");
|
||||||
pub usingnamespace @import("pattern.zig");
|
pub usingnamespace @import("pattern.zig");
|
||||||
|
|
||||||
|
@ -11,10 +11,15 @@ pub const Pattern = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *Pattern) void {
|
pub fn destroy(self: *Pattern) void {
|
||||||
c.FcPatternDestroy(@ptrCast(
|
c.FcPatternDestroy(self.cval());
|
||||||
*c.struct__FcPattern,
|
}
|
||||||
self,
|
|
||||||
));
|
pub fn print(self: *Pattern) void {
|
||||||
|
c.FcPatternPrint(self.cval());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn cval(self: *Pattern) *c.struct__FcPattern {
|
||||||
|
return @ptrCast(*c.struct__FcPattern, self);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user