font: begin coretext Face

This commit is contained in:
Mitchell Hashimoto
2022-10-08 09:43:54 -07:00
parent 71ec509930
commit 90f3b9391c
4 changed files with 87 additions and 1 deletions

View File

@@ -18,6 +18,18 @@ pub const Font = opaque {
) orelse Allocator.Error.OutOfMemory;
}
pub fn copyWithAttributes(self: *Font, size: f32, attrs: ?*text.FontDescriptor) Allocator.Error!*Font {
return @intToPtr(
?*Font,
@ptrToInt(c.CTFontCreateCopyWithAttributes(
@ptrCast(c.CTFontRef, self),
size,
null,
@ptrCast(c.CTFontDescriptorRef, attrs),
)),
) orelse Allocator.Error.OutOfMemory;
}
pub fn release(self: *Font) void {
c.CFRelease(self);
}
@@ -129,3 +141,16 @@ test {
);
}
}
test "copy" {
const name = try foundation.String.createWithBytes("Monaco", .utf8, false);
defer name.release();
const desc = try text.FontDescriptor.createWithNameAndSize(name, 12);
defer desc.release();
const font = try Font.createWithFontDescriptor(desc, 12);
defer font.release();
const f2 = try font.copyWithAttributes(14, null);
defer f2.release();
}