From 2a1cbb4f21f133764cbeefef7b4e521717ca71b9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 4 Mar 2023 11:29:40 -0800 Subject: [PATCH] coretext: calculate units per em/point --- pkg/macos/text/font.zig | 8 ++++++++ src/font/face/coretext.zig | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/pkg/macos/text/font.zig b/pkg/macos/text/font.zig index 6db9fa5c9..5ff031183 100644 --- a/pkg/macos/text/font.zig +++ b/pkg/macos/text/font.zig @@ -130,6 +130,14 @@ pub const Font = opaque { pub fn getUnderlineThickness(self: *Font) f64 { return c.CTFontGetUnderlineThickness(@ptrCast(self)); } + + pub fn getUnitsPerEm(self: *Font) u32 { + return c.CTFontGetUnitsPerEm(@ptrCast(c.CTFontRef, self)); + } + + pub fn getSize(self: *Font) f64 { + return c.CTFontGetSize(@ptrCast(c.CTFontRef, self)); + } }; pub const FontOrientation = enum(c_uint) { diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index a95fcb70a..c551e3bd3 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -317,6 +317,10 @@ pub const Face = struct { const strikethrough_position = cell_baseline * 0.6; const strikethrough_thickness = underline_thickness; + // Note: is this useful? + // const units_per_em = ct_font.getUnitsPerEm(); + // const units_per_point = @intToFloat(f64, units_per_em) / ct_font.getSize(); + // std.log.warn("width={d}, height={d} baseline={d} underline_pos={d} underline_thickness={d}", .{ // cell_width, // cell_height,