address review: Discover.init takes a Library across all backends

Per review feedback, drop the `if (Discover == Windows)` comptime
branches in SharedGridSet and list_fonts by making every backend's
`init` take a Library and ignore it when unused. Call sites just do
`Discover.init(self.font_lib)` now.

Also adds a discovery test for the Windows backend that looks up
Arial and checks the returned face has the 'A' codepoint.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yasuhiro Matsumoto
2026-04-23 23:06:21 +09:00
parent fe2a909782
commit 5aef2541b0
3 changed files with 52 additions and 24 deletions

View File

@@ -4,7 +4,6 @@ const ArenaAllocator = std.heap.ArenaAllocator;
const Action = @import("ghostty.zig").Action;
const args = @import("args.zig");
const font = @import("../font/main.zig");
const discovery = @import("../font/discovery.zig");
const log = std.log.scoped(.list_fonts);
@@ -101,18 +100,12 @@ fn runArgs(alloc_gpa: Allocator, argsIter: anytype) !u8 {
var families: std.ArrayList([]const u8) = .empty;
var map: std.StringHashMap(std.ArrayListUnmanaged([]const u8)) = .init(alloc);
// Look up all available fonts. The Windows backend needs a FreeType
// library handle so it can open candidate font files while scanning
// the system/user font directories.
var font_lib = if (comptime font.Discover == discovery.Windows)
try font.Library.init(alloc)
else {};
defer if (comptime font.Discover == discovery.Windows) font_lib.deinit();
var disco = if (comptime font.Discover == discovery.Windows)
font.Discover.init(font_lib)
else
font.Discover.init();
// Look up all available fonts. The library is only used by backends
// that need it (the Windows backend opens candidate font files with
// FreeType); other backends ignore it.
var font_lib = try font.Library.init(alloc);
defer font_lib.deinit();
var disco = font.Discover.init(font_lib);
defer disco.deinit();
var disco_it = try disco.discover(alloc, .{
.family = config.family,