font: Default to light hinting in FreeType

pull/9253/head
Daniel Wennberg 2025-10-17 14:57:10 -07:00
parent 3b8e683d96
commit ad9f9dc11e
2 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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);
}
}