font/coretext: ability to set variation axes

This commit is contained in:
Mitchell Hashimoto
2023-08-27 07:56:17 -07:00
parent fb0f80f9ca
commit 9d0729f17c
7 changed files with 186 additions and 3 deletions

View File

@@ -39,6 +39,14 @@ pub const Font = opaque {
c.CFRelease(self);
}
pub fn retain(self: *Font) void {
_ = c.CFRetain(self);
}
pub fn copyDescriptor(self: *Font) *text.FontDescriptor {
return @ptrCast(@constCast(c.CTFontCopyFontDescriptor(@ptrCast(self))));
}
pub fn getGlyphsForCharacters(self: *Font, chars: []const u16, glyphs: []graphics.Glyph) bool {
assert(chars.len == glyphs.len);
return c.CTFontGetGlyphsForCharacters(

View File

@@ -31,6 +31,21 @@ pub const FontDescriptor = opaque {
) orelse Allocator.Error.OutOfMemory;
}
pub fn createCopyWithVariation(
original: *FontDescriptor,
id: *foundation.Number,
value: f64,
) Allocator.Error!*FontDescriptor {
return @as(
?*FontDescriptor,
@ptrCast(@constCast(c.CTFontDescriptorCreateCopyWithVariation(
@ptrCast(original),
@ptrCast(id),
value,
))),
) orelse Allocator.Error.OutOfMemory;
}
pub fn release(self: *FontDescriptor) void {
c.CFRelease(self);
}