mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
fontconfig: font list
This commit is contained in:
@ -1,8 +1,19 @@
|
||||
const std = @import("std");
|
||||
const c = @import("c.zig");
|
||||
const FontSet = @import("font_set.zig").FontSet;
|
||||
const ObjectSet = @import("object_set.zig").ObjectSet;
|
||||
const Pattern = @import("pattern.zig").Pattern;
|
||||
|
||||
pub const Config = opaque {
|
||||
pub fn destroy(self: *Config) void {
|
||||
c.FcConfigDestroy(@ptrCast(*c.struct__FcConfig, self));
|
||||
}
|
||||
|
||||
pub fn list(self: *Config, pat: *Pattern, os: *ObjectSet) *FontSet {
|
||||
return @ptrCast(*FontSet, c.FcFontList(self.cval(), pat.cval(), os.cval()));
|
||||
}
|
||||
|
||||
pub inline fn cval(self: *Config) *c.struct__FcConfig {
|
||||
return @ptrCast(*c.struct__FcConfig, self);
|
||||
}
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ pub const FontSet = opaque {
|
||||
return @ptrCast(*Pattern, self.cval().fonts[idx]);
|
||||
}
|
||||
|
||||
inline fn cval(self: *FontSet) *c.struct__FcFontSet {
|
||||
pub inline fn cval(self: *FontSet) *c.struct__FcFontSet {
|
||||
return @ptrCast(
|
||||
*c.struct__FcFontSet,
|
||||
@alignCast(@alignOf(c.struct__FcFontSet), self),
|
||||
|
@ -8,3 +8,7 @@ pub usingnamespace @import("pattern.zig");
|
||||
test {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
}
|
||||
|
||||
test {
|
||||
_ = @import("test.zig");
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ pub const ObjectSet = opaque {
|
||||
return c.FcObjectSetAdd(self.cval(), p.cval().ptr) == c.FcTrue;
|
||||
}
|
||||
|
||||
fn cval(self: *ObjectSet) *c.struct__FcObjectSet {
|
||||
pub inline fn cval(self: *ObjectSet) *c.struct__FcObjectSet {
|
||||
return @ptrCast(
|
||||
*c.struct__FcObjectSet,
|
||||
@alignCast(@alignOf(c.struct__FcObjectSet), self),
|
||||
|
@ -18,7 +18,7 @@ pub const Pattern = opaque {
|
||||
c.FcPatternPrint(self.cval());
|
||||
}
|
||||
|
||||
inline fn cval(self: *Pattern) *c.struct__FcPattern {
|
||||
pub inline fn cval(self: *Pattern) *c.struct__FcPattern {
|
||||
return @ptrCast(*c.struct__FcPattern, self);
|
||||
}
|
||||
};
|
||||
|
22
pkg/fontconfig/test.zig
Normal file
22
pkg/fontconfig/test.zig
Normal file
@ -0,0 +1,22 @@
|
||||
const std = @import("std");
|
||||
const fontconfig = @import("main.zig");
|
||||
|
||||
test "fc-list" {
|
||||
const testing = std.testing;
|
||||
|
||||
var cfg = fontconfig.initLoadConfigAndFonts();
|
||||
defer cfg.destroy();
|
||||
|
||||
var pat = fontconfig.Pattern.create();
|
||||
defer pat.destroy();
|
||||
|
||||
var os = fontconfig.ObjectSet.create();
|
||||
defer os.destroy();
|
||||
|
||||
var fs = cfg.list(pat, os);
|
||||
defer fs.destroy();
|
||||
|
||||
// Note: this is environmental, but in general we expect all our
|
||||
// testing environments to have at least one font.
|
||||
try testing.expect(fs.len() > 0);
|
||||
}
|
Reference in New Issue
Block a user