diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-04-04 19:22:04 +0300 |
|---|---|---|
| committer | Can Celik <ogulcancelik@gmail.com> | 2026-04-05 01:23:06 +0300 |
| commit | 41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch) | |
| tree | 3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/font/library.zig | |
| parent | 55c138263e190a1e79d4b997bfb9397306c0ec1f (diff) | |
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/font/library.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/font/library.zig | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/font/library.zig b/vendor/libghostty-vt/src/font/library.zig new file mode 100644 index 00000000..dce6dbd5 --- /dev/null +++ b/vendor/libghostty-vt/src/font/library.zig @@ -0,0 +1,63 @@ +//! 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, + .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; + } +}; |
