aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/font/backend.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/font/backend.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/font/backend.zig')
-rw-r--r--vendor/libghostty-vt/src/font/backend.zig118
1 files changed, 118 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/font/backend.zig b/vendor/libghostty-vt/src/font/backend.zig
new file mode 100644
index 00000000..d24edec7
--- /dev/null
+++ b/vendor/libghostty-vt/src/font/backend.zig
@@ -0,0 +1,118 @@
+const std = @import("std");
+
+pub const Backend = enum {
+ const WasmTarget = @import("../os/wasm/target.zig").Target;
+
+ /// FreeType for font rendering with no font discovery enabled.
+ freetype,
+
+ /// Fontconfig for font discovery and FreeType for font rendering.
+ fontconfig_freetype,
+
+ /// CoreText for font discovery, rendering, and shaping (macOS).
+ coretext,
+
+ /// CoreText for font discovery, FreeType for rendering, and
+ /// HarfBuzz for shaping (macOS).
+ coretext_freetype,
+
+ /// CoreText for font discovery and rendering, HarfBuzz for shaping
+ coretext_harfbuzz,
+
+ /// CoreText for font discovery and rendering, no shaping.
+ coretext_noshape,
+
+ /// Use the browser font system and the Canvas API (wasm). This limits
+ /// the available fonts to browser fonts (anything Canvas natively
+ /// supports).
+ web_canvas,
+
+ /// Returns the default backend for a build environment. This is
+ /// meant to be called at comptime by the build.zig script. To get the
+ /// backend look at build_options.
+ pub fn default(
+ target: std.Target,
+ wasm_target: WasmTarget,
+ ) Backend {
+ if (target.cpu.arch == .wasm32) {
+ return switch (wasm_target) {
+ .browser => .web_canvas,
+ };
+ }
+
+ if (target.os.tag == .windows) {
+ // Avoid fontconfig on Windows because its libxml2 dependency
+ // may not unpack due to symlinks. Use plain freetype for now
+ // which means no font discovery. Full solution would likely use
+ // DirectWrite which has its own discovery API.
+ return .freetype;
+ }
+
+ // macOS also supports "coretext_freetype" but there is no scenario
+ // that is the default. It is only used by people who want to
+ // self-compile Ghostty and prefer the freetype aesthetic.
+ return if (target.os.tag.isDarwin()) .coretext else .fontconfig_freetype;
+ }
+
+ // All the functions below can be called at comptime or runtime to
+ // determine if we have a certain dependency.
+
+ pub fn hasFreetype(self: Backend) bool {
+ return switch (self) {
+ .freetype,
+ .fontconfig_freetype,
+ .coretext_freetype,
+ => true,
+
+ .coretext,
+ .coretext_harfbuzz,
+ .coretext_noshape,
+ .web_canvas,
+ => false,
+ };
+ }
+
+ pub fn hasCoretext(self: Backend) bool {
+ return switch (self) {
+ .coretext,
+ .coretext_freetype,
+ .coretext_harfbuzz,
+ .coretext_noshape,
+ => true,
+
+ .freetype,
+ .fontconfig_freetype,
+ .web_canvas,
+ => false,
+ };
+ }
+
+ pub fn hasFontconfig(self: Backend) bool {
+ return switch (self) {
+ .fontconfig_freetype => true,
+
+ .freetype,
+ .coretext,
+ .coretext_freetype,
+ .coretext_harfbuzz,
+ .coretext_noshape,
+ .web_canvas,
+ => false,
+ };
+ }
+
+ pub fn hasHarfbuzz(self: Backend) bool {
+ return switch (self) {
+ .freetype,
+ .fontconfig_freetype,
+ .coretext_freetype,
+ .coretext_harfbuzz,
+ => true,
+
+ .coretext,
+ .coretext_noshape,
+ .web_canvas,
+ => false,
+ };
+ }
+};