pkg/fontconfig: add some error handling

This commit is contained in:
Mitchell Hashimoto
2022-09-17 08:58:42 -07:00
parent 0d80225977
commit 86f7d0e04e
4 changed files with 11 additions and 3 deletions

View File

@ -1,5 +1,6 @@
const std = @import("std");
const c = @import("c.zig");
const Error = @import("main.zig").Error;
const CharSet = @import("char_set.zig").CharSet;
const FontSet = @import("font_set.zig").FontSet;
const ObjectSet = @import("object_set.zig").ObjectSet;
@ -34,8 +35,11 @@ pub const Config = opaque {
return result;
}
pub fn fontRenderPrepare(self: *Config, pat: *Pattern, font: *Pattern) *Pattern {
return @ptrCast(*Pattern, c.FcFontRenderPrepare(self.cval(), pat.cval(), font.cval()));
pub fn fontRenderPrepare(self: *Config, pat: *Pattern, font: *Pattern) Error!*Pattern {
return @ptrCast(
?*Pattern,
c.FcFontRenderPrepare(self.cval(), pat.cval(), font.cval()),
) orelse Error.FontconfigFailed;
}
pub fn substituteWithPat(self: *Config, pat: *Pattern, kind: MatchKind) bool {

3
pkg/fontconfig/error.zig Normal file
View File

@ -0,0 +1,3 @@
pub const Error = error{
FontconfigFailed,
};

View File

@ -3,6 +3,7 @@ pub usingnamespace @import("init.zig");
pub usingnamespace @import("char_set.zig");
pub usingnamespace @import("common.zig");
pub usingnamespace @import("config.zig");
pub usingnamespace @import("error.zig");
pub usingnamespace @import("font_set.zig");
pub usingnamespace @import("lang_set.zig");
pub usingnamespace @import("matrix.zig");

View File

@ -43,7 +43,7 @@ test "fc-match" {
const fonts = result.fs.fonts();
try testing.expect(fonts.len > 0);
for (fonts) |font| {
var pat_prep = cfg.fontRenderPrepare(pat, font);
var pat_prep = try cfg.fontRenderPrepare(pat, font);
try testing.expect(fs.add(pat_prep));
}
result.fs.destroy();