mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-02 11:54:41 +00:00
pkg/fontconfig: add weights/slants enum
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const c = @import("c.zig");
|
||||
const Property = @import("main.zig").Property;
|
||||
|
||||
pub const ObjectSet = opaque {
|
||||
pub fn create() *ObjectSet {
|
||||
@@ -22,89 +23,6 @@ pub const ObjectSet = opaque {
|
||||
}
|
||||
};
|
||||
|
||||
pub const Property = enum {
|
||||
family,
|
||||
style,
|
||||
slant,
|
||||
weight,
|
||||
size,
|
||||
aspect,
|
||||
pixel_size,
|
||||
spacing,
|
||||
foundry,
|
||||
antialias,
|
||||
hinting,
|
||||
hint_style,
|
||||
vertical_layout,
|
||||
autohint,
|
||||
global_advance,
|
||||
width,
|
||||
file,
|
||||
index,
|
||||
ft_face,
|
||||
rasterizer,
|
||||
outline,
|
||||
scalable,
|
||||
color,
|
||||
variable,
|
||||
scale,
|
||||
symbol,
|
||||
dpi,
|
||||
rgba,
|
||||
minspace,
|
||||
source,
|
||||
charset,
|
||||
lang,
|
||||
fontversion,
|
||||
fullname,
|
||||
familylang,
|
||||
stylelang,
|
||||
fullnamelang,
|
||||
capability,
|
||||
embolden,
|
||||
embedded_bitmap,
|
||||
decorative,
|
||||
lcd_filter,
|
||||
font_features,
|
||||
font_variations,
|
||||
namelang,
|
||||
prgname,
|
||||
hash,
|
||||
postscript_name,
|
||||
font_has_hint,
|
||||
order,
|
||||
|
||||
pub fn cval(self: Property) [:0]const u8 {
|
||||
@setEvalBranchQuota(10_000);
|
||||
inline for (@typeInfo(Property).Enum.fields) |field| {
|
||||
if (self == @field(Property, field.name)) {
|
||||
// Build our string in a comptime context so it is a binary
|
||||
// constant and not stack allocated.
|
||||
return comptime name: {
|
||||
// Replace _ with ""
|
||||
var buf: [field.name.len]u8 = undefined;
|
||||
const count = std.mem.replace(u8, field.name, "_", "", &buf);
|
||||
const replaced = buf[0 .. field.name.len - count];
|
||||
|
||||
// Build our string
|
||||
var name: [replaced.len:0]u8 = undefined;
|
||||
std.mem.copy(u8, &name, replaced);
|
||||
name[replaced.len] = 0;
|
||||
break :name &name;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
unreachable;
|
||||
}
|
||||
|
||||
test "cval" {
|
||||
const testing = std.testing;
|
||||
try testing.expectEqualStrings("family", Property.family.cval());
|
||||
try testing.expectEqualStrings("pixelsize", Property.pixel_size.cval());
|
||||
}
|
||||
};
|
||||
|
||||
test "create" {
|
||||
const testing = std.testing;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user