From a06388869dab03abda4eab5e4d5f52b4cbfd36ae Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Mon, 16 Dec 2024 15:20:26 -0500 Subject: [PATCH] fix: sCapHeight and sxHeight only exist when OS/2 version >= 2 --- src/font/face/freetype.zig | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index 409b9547f..186ad9e10 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -775,10 +775,13 @@ pub const Face = struct { // available, otherwise we try to measure the `H` and `x` glyphs. const cap_height: ?f64, const ex_height: ?f64 = heights: { if (maybe_os2) |os2| { - break :heights .{ - @as(f64, @floatFromInt(os2.sCapHeight)) * px_per_unit, - @as(f64, @floatFromInt(os2.sxHeight)) * px_per_unit, - }; + // The OS/2 table does not include these metrics in version 1. + if (os2.version >= 2) { + break :heights .{ + @as(f64, @floatFromInt(os2.sCapHeight)) * px_per_unit, + @as(f64, @floatFromInt(os2.sxHeight)) * px_per_unit, + }; + } } break :heights .{ cap: {