From ad9f9dc11ee28ca5de2834692d6a2357541b42ee Mon Sep 17 00:00:00 2001 From: Daniel Wennberg Date: Fri, 17 Oct 2025 14:57:10 -0700 Subject: [PATCH] font: Default to light hinting in FreeType --- src/config/Config.zig | 11 ++++++++++- src/font/face/freetype.zig | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index b3085c4c4..d0e086710 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -476,6 +476,11 @@ pub const compatibility = std.StaticStringMap( /// /// * `autohint` - Enable the freetype auto-hinter. Enabled by default. /// +/// * `light` - Use a light hinting style, better preserving glyph shapes. +/// This is the most common setting in GTK apps and therefore also Ghostty's +/// default. This has no effect if `monochrome` is enabled. Enabled by +/// default. +/// /// Example: `hinting`, `no-hinting`, `force-autohint`, `no-force-autohint` @"freetype-load-flags": FreetypeLoadFlags = .{}, @@ -7886,11 +7891,15 @@ pub const BackgroundImageFit = enum { pub const FreetypeLoadFlags = packed struct { // The defaults here at the time of writing this match the defaults // for Freetype itself. Ghostty hasn't made any opinionated changes - // to these defaults. + // to these defaults. (Strictly speaking, `light` isn't FreeType's + // own default, but appears to be the effective default with most + // Fontconfig-aware software using FreeType, so until Ghostty + // implements Fontconfig support we default to `light`.) hinting: bool = true, @"force-autohint": bool = false, monochrome: bool = false, autohint: bool = true, + light: bool = true, }; /// See linux-cgroup diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index 4958c48c8..95f05881b 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -378,6 +378,10 @@ pub const Face = struct { // else it won't look very good at all. .target_mono = self.load_flags.monochrome, + // Otherwise we select hinter based on the `light` flag. + .target_normal = !self.load_flags.light and !self.load_flags.monochrome, + .target_light = self.load_flags.light and !self.load_flags.monochrome, + // NO_SVG set to true because we don't currently support rendering // SVG glyphs under FreeType, since that requires bundling another // dependency to handle rendering the SVG. @@ -1143,7 +1147,7 @@ test { ft_font.glyphIndex('A').?, .{ .grid_metrics = font.Metrics.calc(ft_font.getMetrics()) }, ); - try testing.expectEqual(@as(u32, 20), g2.height); + try testing.expectEqual(@as(u32, 21), g2.height); } }