diff --git a/pkg/macos/text/font.zig b/pkg/macos/text/font.zig index dc27fc281..38577c3dc 100644 --- a/pkg/macos/text/font.zig +++ b/pkg/macos/text/font.zig @@ -112,6 +112,22 @@ pub const Font = opaque { )); } + pub fn getAscent(self: *Font) f64 { + return c.CTFontGetAscent(@ptrCast(c.CTFontRef, self)); + } + + pub fn getDescent(self: *Font) f64 { + return c.CTFontGetDescent(@ptrCast(c.CTFontRef, self)); + } + + pub fn getLeading(self: *Font) f64 { + return c.CTFontGetLeading(@ptrCast(c.CTFontRef, self)); + } + + pub fn getBoundingBox(self: *Font) graphics.Rect { + return @bitCast(graphics.Rect, c.CTFontGetBoundingBox(@ptrCast(c.CTFontRef, self))); + } + pub fn getUnderlinePosition(self: *Font) f64 { return c.CTFontGetUnderlinePosition(@ptrCast(c.CTFontRef, self)); } diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 68fea272a..85d2b6ddc 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -118,7 +118,12 @@ pub const Face = struct { break :cell_width @floatCast(f32, max); }; - std.log.warn("width={}", .{cell_width}); + const cell_height: f32 = cell_height: { + const diff = ct_font.getAscent() + ct_font.getDescent() + ct_font.getLeading(); + break :cell_height @floatCast(f32, diff); + }; + + std.log.warn("width={}, height={}", .{ cell_width, cell_height }); return undefined; } }; diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index 7ba8895e0..5038a2c4d 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -389,7 +389,7 @@ test { var ft_font = try Face.init(lib, testFont, .{ .points = 12 }); defer ft_font.deinit(); - //log.warn("FT WIDTH={}", .{ft_font.metrics.cell_width}); + log.warn("FT={}", .{ft_font.metrics}); try testing.expectEqual(Presentation.text, ft_font.presentation);