cli args fix stage1 miscompilation, add font families

This commit is contained in:
Mitchell Hashimoto
2022-09-29 13:14:20 -07:00
parent 7f45916b89
commit 5567564dd0
3 changed files with 45 additions and 5 deletions

View File

@ -174,9 +174,11 @@ pub fn init(
.size = font_size.points,
});
defer disco_it.deinit();
if (try disco_it.next()) |face|
if (try disco_it.next()) |face| {
log.debug("font regular: {s}", .{try face.name()});
try group.addFace(alloc, .regular, face);
}
}
{
var disco_it = try disco.discover(.{
.family = "Fira Code",
@ -184,10 +186,37 @@ pub fn init(
.bold = true,
});
defer disco_it.deinit();
if (try disco_it.next()) |face|
if (try disco_it.next()) |face| {
log.debug("font bold: {s}", .{try face.name()});
try group.addFace(alloc, .bold, face);
}
}
{
var disco_it = try disco.discover(.{
.family = "Fira Code",
.size = font_size.points,
.italic = true,
});
defer disco_it.deinit();
if (try disco_it.next()) |face| {
log.debug("font italic: {s}", .{try face.name()});
try group.addFace(alloc, .italic, face);
}
}
{
var disco_it = try disco.discover(.{
.family = "Fira Code",
.size = font_size.points,
.bold = true,
.italic = true,
});
defer disco_it.deinit();
if (try disco_it.next()) |face| {
log.debug("font bold+italic: {s}", .{try face.name()});
try group.addFace(alloc, .bold_italic, face);
}
}
}
// Our built-in font will be used as a backup
try group.addFace(

View File

@ -110,15 +110,20 @@ fn parseIntoField(
// No parseCLI, magic the value based on the type
@field(dst, field.name) = switch (Field) {
[]const u8 => if (value) |slice| value: {
[]const u8 => value: {
const slice = value orelse return error.ValueRequired;
const buf = try alloc.alloc(u8, slice.len);
mem.copy(u8, buf, slice);
break :value buf;
} else return error.ValueRequired,
},
bool => try parseBool(value orelse "t"),
u8 => try std.fmt.parseInt(u8, value orelse return error.ValueRequired, 0),
u8 => try std.fmt.parseInt(
u8,
value orelse return error.ValueRequired,
0,
),
else => unreachable,
};

View File

@ -6,6 +6,12 @@ const inputpkg = @import("input.zig");
/// Config is the main config struct. These fields map directly to the
/// CLI flag names hence we use a lot of `@""` syntax to support hyphens.
pub const Config = struct {
/// The font families to use.
@"font-family": ?[]const u8 = null,
@"font-family-bold": ?[]const u8 = null,
@"font-family-italic": ?[]const u8 = null,
@"font-family-bold-italic": ?[]const u8 = null,
/// Font size in points
@"font-size": u8 = 12,