font(coretext): add metrics test case for CT, fix variable font init

Variable font init used to just select the first available predefined
instance, if there were any, which is often not desirable- using
createFontDescriptorFromData instead of createFontDescritorsFromData
ensures that the default variation config is selected. In the future we
should probably allow selection of predefined instances, but for now
this is the correct behavior.

I found this bug when adding the metrics calculation test case for
CoreText, hence why fixing it is part of the same commit.
This commit is contained in:
Qwerasd
2024-12-11 21:14:21 -05:00
parent bd18452310
commit fb50143cec
3 changed files with 65 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ pub const FontVariationAxisKey = font_descriptor.FontVariationAxisKey;
pub const FontSymbolicTraits = font_descriptor.FontSymbolicTraits;
pub const createFontDescriptorsFromURL = font_manager.createFontDescriptorsFromURL;
pub const createFontDescriptorsFromData = font_manager.createFontDescriptorsFromData;
pub const createFontDescriptorFromData = font_manager.createFontDescriptorFromData;
pub const Frame = frame.Frame;
pub const Framesetter = framesetter.Framesetter;
pub const Line = line.Line;

View File

@@ -1,6 +1,7 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const foundation = @import("../foundation.zig");
const FontDescriptor = @import("./font_descriptor.zig").FontDescriptor;
const c = @import("c.zig").c;
pub fn createFontDescriptorsFromURL(url: *foundation.URL) ?*foundation.Array {
@@ -14,3 +15,9 @@ pub fn createFontDescriptorsFromData(data: *foundation.Data) ?*foundation.Array
@ptrCast(data),
)));
}
pub fn createFontDescriptorFromData(data: *foundation.Data) ?*FontDescriptor {
return @ptrFromInt(@intFromPtr(c.CTFontManagerCreateFontDescriptorFromData(
@ptrCast(data),
)));
}