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,8 +174,10 @@ pub fn init(
.size = font_size.points, .size = font_size.points,
}); });
defer disco_it.deinit(); 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); try group.addFace(alloc, .regular, face);
}
} }
{ {
var disco_it = try disco.discover(.{ var disco_it = try disco.discover(.{
@ -184,8 +186,35 @@ pub fn init(
.bold = true, .bold = true,
}); });
defer disco_it.deinit(); 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); 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);
}
} }
} }

View File

@ -110,15 +110,20 @@ fn parseIntoField(
// No parseCLI, magic the value based on the type // No parseCLI, magic the value based on the type
@field(dst, field.name) = switch (Field) { @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); const buf = try alloc.alloc(u8, slice.len);
mem.copy(u8, buf, slice); mem.copy(u8, buf, slice);
break :value buf; break :value buf;
} else return error.ValueRequired, },
bool => try parseBool(value orelse "t"), 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, 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 /// 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. /// CLI flag names hence we use a lot of `@""` syntax to support hyphens.
pub const Config = struct { 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 in points
@"font-size": u8 = 12, @"font-size": u8 = 12,