mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
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
This commit is contained in:
@ -515,8 +515,17 @@ pub const Face = struct {
|
|||||||
fn calcMetrics(ct_font: *macos.text.Font) CalcMetricsError!font.face.Metrics {
|
fn calcMetrics(ct_font: *macos.text.Font) CalcMetricsError!font.face.Metrics {
|
||||||
// Read the 'head' table out of the font data.
|
// Read the 'head' table out of the font data.
|
||||||
const head: opentype.Head = head: {
|
const head: opentype.Head = head: {
|
||||||
const tag = macos.text.FontTableTag.init("head");
|
// macOS bitmap-only fonts use a 'bhed' tag rather than 'head', but
|
||||||
const data = ct_font.copyTable(tag) orelse return error.CopyTableError;
|
// 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();
|
defer data.release();
|
||||||
const ptr = data.getPointer();
|
const ptr = data.getPointer();
|
||||||
const len = data.getLength();
|
const len = data.getLength();
|
||||||
|
Reference in New Issue
Block a user