mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
pkg/macos: some font metrics functions
This commit is contained in:
@ -76,6 +76,22 @@ pub const Font = opaque {
|
||||
));
|
||||
}
|
||||
|
||||
pub fn getAdvancesForGlyphs(
|
||||
self: *Font,
|
||||
orientation: FontOrientation,
|
||||
glyphs: []const graphics.Glyph,
|
||||
advances: ?[]graphics.Size,
|
||||
) f64 {
|
||||
if (advances) |s| assert(glyphs.len == s.len);
|
||||
return c.CTFontGetAdvancesForGlyphs(
|
||||
@ptrCast(c.CTFontRef, self),
|
||||
@enumToInt(orientation),
|
||||
glyphs.ptr,
|
||||
@ptrCast(?[*]c.struct_CGSize, if (advances) |s| s.ptr else null),
|
||||
@intCast(c_long, glyphs.len),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn copyAttribute(self: *Font, comptime attr: text.FontAttribute) attr.Value() {
|
||||
return @intToPtr(attr.Value(), @ptrToInt(c.CTFontCopyAttribute(
|
||||
@ptrCast(c.CTFontRef, self),
|
||||
@ -95,6 +111,14 @@ pub const Font = opaque {
|
||||
@ptrCast(c.CTFontRef, self),
|
||||
));
|
||||
}
|
||||
|
||||
pub fn getUnderlinePosition(self: *Font) f64 {
|
||||
return c.CTFontGetUnderlinePosition(@ptrCast(c.CTFontRef, self));
|
||||
}
|
||||
|
||||
pub fn getUnderlineThickness(self: *Font) f64 {
|
||||
return c.CTFontGetUnderlineThickness(@ptrCast(c.CTFontRef, self));
|
||||
}
|
||||
};
|
||||
|
||||
pub const FontOrientation = enum(c_uint) {
|
||||
@ -138,6 +162,17 @@ test {
|
||||
try testing.expect(singles[0].size.width > 0);
|
||||
}
|
||||
|
||||
// Advances
|
||||
{
|
||||
var advance = font.getAdvancesForGlyphs(.horizontal, &glyphs, null);
|
||||
try testing.expect(advance > 0);
|
||||
|
||||
var singles: [1]graphics.Size = undefined;
|
||||
advance = font.getAdvancesForGlyphs(.horizontal, &glyphs, &singles);
|
||||
try testing.expect(advance > 0);
|
||||
try testing.expect(singles[0].width > 0);
|
||||
}
|
||||
|
||||
// Draw
|
||||
{
|
||||
const cs = try graphics.ColorSpace.createDeviceGray();
|
||||
|
Reference in New Issue
Block a user