mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
Merge pull request #1093 from mitchellh/coretext-font-family
font/coretext: use `CTFontCopyFamilyName`
This commit is contained in:
@ -120,6 +120,10 @@ pub const Font = opaque {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn copyFamilyName(self: *Font) *foundation.String {
|
||||||
|
return @ptrFromInt(@intFromPtr(c.CTFontCopyFamilyName(@ptrCast(self))));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn copyDisplayName(self: *Font) *foundation.String {
|
pub fn copyDisplayName(self: *Font) *foundation.String {
|
||||||
return @ptrFromInt(@intFromPtr(c.CTFontCopyDisplayName(@ptrCast(self))));
|
return @ptrFromInt(@intFromPtr(c.CTFontCopyDisplayName(@ptrCast(self))));
|
||||||
}
|
}
|
||||||
|
@ -160,13 +160,13 @@ pub const Face = struct {
|
|||||||
/// but sometimes allocation isn't required and a static string is
|
/// but sometimes allocation isn't required and a static string is
|
||||||
/// returned.
|
/// returned.
|
||||||
pub fn name(self: *const Face, buf: []u8) Allocator.Error![]const u8 {
|
pub fn name(self: *const Face, buf: []u8) Allocator.Error![]const u8 {
|
||||||
const display_name = self.font.copyDisplayName();
|
const family_name = self.font.copyFamilyName();
|
||||||
if (display_name.cstringPtr(.utf8)) |str| return str;
|
if (family_name.cstringPtr(.utf8)) |str| return str;
|
||||||
|
|
||||||
// "NULL if the internal storage of theString does not allow
|
// "NULL if the internal storage of theString does not allow
|
||||||
// this to be returned efficiently." In this case, we need
|
// this to be returned efficiently." In this case, we need
|
||||||
// to allocate.
|
// to allocate.
|
||||||
return display_name.cstring(buf, .utf8) orelse error.OutOfMemory;
|
return family_name.cstring(buf, .utf8) orelse error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resize the font in-place. If this succeeds, the caller is responsible
|
/// Resize the font in-place. If this succeeds, the caller is responsible
|
||||||
@ -549,6 +549,26 @@ test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "name" {
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
const name = try macos.foundation.String.createWithBytes("Menlo", .utf8, false);
|
||||||
|
defer name.release();
|
||||||
|
const desc = try macos.text.FontDescriptor.createWithNameAndSize(name, 12);
|
||||||
|
defer desc.release();
|
||||||
|
const ct_font = try macos.text.Font.createWithFontDescriptor(desc, 12);
|
||||||
|
defer ct_font.release();
|
||||||
|
|
||||||
|
var face = try Face.initFontCopy(ct_font, .{ .size = .{ .points = 12 } });
|
||||||
|
defer face.deinit();
|
||||||
|
|
||||||
|
try testing.expectEqual(font.Presentation.text, face.presentation);
|
||||||
|
|
||||||
|
var buf: [1024]u8 = undefined;
|
||||||
|
const font_name = try face.name(&buf);
|
||||||
|
try testing.expect(std.mem.eql(u8, font_name, "Menlo"));
|
||||||
|
}
|
||||||
|
|
||||||
test "emoji" {
|
test "emoji" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user