From fb0f80f9caf2b16a77f645f4ecb3783f096d3680 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 25 Aug 2023 22:24:45 -0700 Subject: [PATCH] macos: add necessary functions for variation axes querying --- pkg/macos/foundation/array.zig | 2 +- pkg/macos/text/font_descriptor.zig | 37 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pkg/macos/foundation/array.zig b/pkg/macos/foundation/array.zig index 35d3a0aba..4524cda6b 100644 --- a/pkg/macos/foundation/array.zig +++ b/pkg/macos/foundation/array.zig @@ -24,7 +24,7 @@ pub const Array = opaque { /// constness so that further API calls work correctly. The Foundation /// API doesn't properly mark things const/non-const. pub fn getValueAtIndex(self: *Array, comptime T: type, idx: usize) *T { - return @ptrCast(CFArrayGetValueAtIndex(self, idx)); + return @ptrCast(@alignCast(CFArrayGetValueAtIndex(self, idx))); } pub extern "c" fn CFArrayCreate( diff --git a/pkg/macos/text/font_descriptor.zig b/pkg/macos/text/font_descriptor.zig index f7f8097a1..2c1da2b6a 100644 --- a/pkg/macos/text/font_descriptor.zig +++ b/pkg/macos/text/font_descriptor.zig @@ -75,6 +75,9 @@ pub const FontAttribute = enum { downloadable, downloaded, + // https://developer.apple.com/documentation/coretext/core_text_constants?language=objc + variation_axes, + pub fn key(self: FontAttribute) *foundation.String { return @as(*foundation.String, @ptrFromInt(@intFromPtr(switch (self) { .url => c.kCTFontURLAttribute, @@ -101,6 +104,7 @@ pub const FontAttribute = enum { .enabled => c.kCTFontEnabledAttribute, .downloadable => c.kCTFontDownloadableAttribute, .downloaded => c.kCTFontDownloadedAttribute, + .variation_axes => c.kCTFontVariationAxesAttribute, }))); } @@ -130,6 +134,7 @@ pub const FontAttribute = enum { .enabled => *foundation.Number, .downloadable => *anyopaque, // CFBoolean .downloaded => *anyopaque, // CFBoolean + .variation_axes => ?*foundation.Array, }; } }; @@ -159,6 +164,38 @@ pub const FontTraitKey = enum { } }; +// https://developer.apple.com/documentation/coretext/ctfont/font_variation_axis_dictionary_keys?language=objc +pub const FontVariationAxisKey = enum { + identifier, + minimum_value, + maximum_value, + default_value, + name, + hidden, + + pub fn key(self: FontVariationAxisKey) *foundation.String { + return @as(*foundation.String, @ptrFromInt(@intFromPtr(switch (self) { + .identifier => c.kCTFontVariationAxisIdentifierKey, + .minimum_value => c.kCTFontVariationAxisMinimumValueKey, + .maximum_value => c.kCTFontVariationAxisMaximumValueKey, + .default_value => c.kCTFontVariationAxisDefaultValueKey, + .name => c.kCTFontVariationAxisNameKey, + .hidden => c.kCTFontVariationAxisHiddenKey, + }))); + } + + pub fn Value(comptime self: FontVariationAxisKey) type { + return switch (self) { + .identifier => foundation.Number, + .minimum_value => foundation.Number, + .maximum_value => foundation.Number, + .default_value => foundation.Number, + .name => foundation.String, + .hidden => foundation.Number, + }; + } +}; + pub const FontSymbolicTraits = packed struct(u32) { italic: bool = false, bold: bool = false,