Files
ghostty/src/font/library.zig
Yasuhiro Matsumoto 61fce4d0a4 font: add Windows font discovery backend
Adds a FreeType-based Discover implementation for Windows that walks
the system (C:\Windows\Fonts) and per-user
(%LOCALAPPDATA%\Microsoft\Windows\Fonts) font directories, matching
descriptors via family_name / SFNT name table and optionally codepoint
presence.

Wired up as a new .freetype_windows backend which Backend.default() now
returns on Windows. Existing freetype-only paths are untouched.

With this in place, standard code paths -- +list-fonts, SharedGridSet
font-family lookup, CodepointResolver fallback -- work on Windows
without any os.tag == .windows branches in the caller.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 14:32:47 +09:00

65 lines
1.6 KiB
Zig

//! A library represents the shared state that the underlying font
//! library implementation(s) require per-process.
const std = @import("std");
const Allocator = std.mem.Allocator;
const options = @import("main.zig").options;
const freetype = @import("freetype");
const font = @import("main.zig");
/// Library implementation for the compile options.
pub const Library = switch (options.backend) {
// Freetype requires a state library
.freetype,
.freetype_windows,
.fontconfig_freetype,
.coretext_freetype,
=> FreetypeLibrary,
// Some backends such as CT and Canvas don't have a "library"
.coretext,
.coretext_harfbuzz,
.coretext_noshape,
.web_canvas,
=> NoopLibrary,
};
pub const FreetypeLibrary = struct {
lib: freetype.Library,
alloc: Allocator,
/// Mutex to be held any time the library is
/// being used to create or destroy a face.
mutex: *std.Thread.Mutex,
pub const InitError = freetype.Error || Allocator.Error;
pub fn init(alloc: Allocator) InitError!Library {
const lib = try freetype.Library.init();
errdefer lib.deinit();
const mutex = try alloc.create(std.Thread.Mutex);
mutex.* = .{};
return Library{ .lib = lib, .alloc = alloc, .mutex = mutex };
}
pub fn deinit(self: *Library) void {
self.alloc.destroy(self.mutex);
self.lib.deinit();
}
};
pub const NoopLibrary = struct {
pub const InitError = error{};
pub fn init(alloc: Allocator) InitError!Library {
_ = alloc;
return Library{};
}
pub fn deinit(self: *Library) void {
_ = self;
}
};