From 6d65abc489cc015fa4958567c86c10eb05cf09c3 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Mon, 24 Nov 2025 17:42:02 -0700 Subject: [PATCH] fix(pkg/freetype): fully correct load flags These now properly match the FreeType API- compared directly in the unit tests against the values provided by the FreeType header itself. This was ridiculously wrong before, like... wow. --- pkg/freetype/face.zig | 20 ++++++++++---------- src/font/face/freetype.zig | 14 +++++++++----- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pkg/freetype/face.zig b/pkg/freetype/face.zig index e4c17cf92..d4f74b7ee 100644 --- a/pkg/freetype/face.zig +++ b/pkg/freetype/face.zig @@ -252,8 +252,12 @@ pub const RenderMode = enum(c_uint) { sdf = c.FT_RENDER_MODE_SDF, }; -/// A list of bit field constants for FT_Load_Glyph to indicate what kind of -/// operations to perform during glyph loading. +/// A collection of flags for FT_Load_Glyph that indicate +/// what kind of operations to perform during glyph loading. +/// +/// Some of these flags are not included in the official FreeType +/// documentation, but are nevertheless present and named in the +/// header, so the names have been copied from there. pub const LoadFlags = packed struct(c_int) { no_scale: bool = false, no_hinting: bool = false, @@ -263,7 +267,7 @@ pub const LoadFlags = packed struct(c_int) { force_autohint: bool = false, crop_bitmap: bool = false, pedantic: bool = false, - _padding1: u1 = 0, + advance_only: bool = false, ignore_global_advance_width: bool = false, no_recurse: bool = false, ignore_transform: bool = false, @@ -271,17 +275,13 @@ pub const LoadFlags = packed struct(c_int) { linear_design: bool = false, sbits_only: bool = false, no_autohint: bool = false, - target_normal: bool = false, - target_light: bool = false, - target_mono: bool = false, - target_lcd: bool = false, + target: Target = .normal, color: bool = false, - target_lcd_v: bool = false, compute_metrics: bool = false, bitmap_metrics_only: bool = false, - _padding2: u1 = 0, + svg_only: bool = false, no_svg: bool = false, - _padding3: u6 = 0, + _padding: u7 = 0, pub const Target = enum(u4) { normal = 0, diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index ced313a94..fe3dcf707 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -376,11 +376,15 @@ pub const Face = struct { // If we're gonna be rendering this glyph in monochrome, // then we should use the monochrome hinter as well, or // 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, + // + // Otherwise if the user asked for light hinting we + // use that, otherwise we just use the normal target. + .target = if (self.load_flags.monochrome) + .mono + else if (self.load_flags.light) + .light + else + .normal, // NO_SVG set to true because we don't currently support rendering // SVG glyphs under FreeType, since that requires bundling another