mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/fontconfig: pattern get
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const c = @import("c.zig");
|
||||
const Error = @import("main.zig").Error;
|
||||
|
||||
pub const Weight = enum(c_uint) {
|
||||
thin = c.FC_WEIGHT_THIN,
|
||||
@ -111,6 +112,16 @@ pub const Result = enum(c_uint) {
|
||||
type_mismatch = c.FcResultTypeMismatch,
|
||||
no_id = c.FcResultNoId,
|
||||
out_of_memory = c.FcResultOutOfMemory,
|
||||
|
||||
pub fn toError(self: Result) Error!void {
|
||||
return switch (self) {
|
||||
.match => {},
|
||||
.no_match => Error.FontconfigNoMatch,
|
||||
.type_mismatch => Error.FontconfigTypeMismatch,
|
||||
.no_id => Error.FontconfigNoId,
|
||||
.out_of_memory => Error.OutOfMemory,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const MatchKind = enum(c_uint) {
|
||||
|
@ -1,3 +1,7 @@
|
||||
pub const Error = error{
|
||||
OutOfMemory,
|
||||
FontconfigFailed,
|
||||
FontconfigNoMatch,
|
||||
FontconfigTypeMismatch,
|
||||
FontconfigNoId,
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const c = @import("c.zig");
|
||||
const Error = @import("main.zig").Error;
|
||||
const ObjectSet = @import("main.zig").ObjectSet;
|
||||
const Property = @import("main.zig").Property;
|
||||
const Result = @import("main.zig").Result;
|
||||
@ -34,6 +35,18 @@ pub const Pattern = opaque {
|
||||
) == c.FcTrue;
|
||||
}
|
||||
|
||||
pub fn get(self: *Pattern, prop: Property, id: u32) Error!Value {
|
||||
var val: c.struct__FcValue = undefined;
|
||||
try @intToEnum(Result, c.FcPatternGet(
|
||||
self.cval(),
|
||||
prop.cval(),
|
||||
@intCast(c_int, id),
|
||||
&val,
|
||||
)).toError();
|
||||
|
||||
return Value.init(&val);
|
||||
}
|
||||
|
||||
pub fn delete(self: *Pattern, prop: Property) bool {
|
||||
return c.FcPatternDel(self.cval(), prop.cval()) == c.FcTrue;
|
||||
}
|
||||
@ -142,6 +155,12 @@ test "create" {
|
||||
|
||||
try testing.expect(pat.add(.family, .{ .string = "monospace" }, false));
|
||||
try testing.expect(pat.add(.weight, .{ .integer = @enumToInt(Weight.bold) }, false));
|
||||
|
||||
{
|
||||
const val = try pat.get(.family, 0);
|
||||
try testing.expect(val == .string);
|
||||
try testing.expectEqualStrings("monospace", val.string);
|
||||
}
|
||||
}
|
||||
|
||||
test "name parse" {
|
||||
|
Reference in New Issue
Block a user