From a300c0c1531f1087a2e020c41aa4fb0636e4802f Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Mon, 30 Dec 2024 14:44:30 -0500 Subject: [PATCH] font/coretext: properly resolve metrics for bitmap-only fonts macOS bitmap-only fonts are a poorly documented format, which are often distributed as `.dfont` or `.dfon` files. They use a 'bhed' table in place of the usual 'head', but the table format is byte-identical, so enabling the use of bitmap-only fonts only requires us to properly fetch this table while calculating metrics. ref: https://fontforge.org/docs/techref/bitmaponlysfnt.html --- src/font/face/coretext.zig | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 92ab4d396..dd4f6432e 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -515,8 +515,17 @@ pub const Face = struct { fn calcMetrics(ct_font: *macos.text.Font) CalcMetricsError!font.face.Metrics { // Read the 'head' table out of the font data. const head: opentype.Head = head: { - const tag = macos.text.FontTableTag.init("head"); - const data = ct_font.copyTable(tag) orelse return error.CopyTableError; + // macOS bitmap-only fonts use a 'bhed' tag rather than 'head', but + // the table format is byte-identical to the 'head' table, so if we + // can't find 'head' we try 'bhed' instead before failing. + // + // ref: https://fontforge.org/docs/techref/bitmaponlysfnt.html + const head_tag = macos.text.FontTableTag.init("head"); + const bhed_tag = macos.text.FontTableTag.init("bhed"); + const data = + ct_font.copyTable(head_tag) orelse + ct_font.copyTable(bhed_tag) orelse + return error.CopyTableError; defer data.release(); const ptr = data.getPointer(); const len = data.getLength();