macos: test listing fonts

This commit is contained in:
Mitchell Hashimoto
2022-10-01 11:06:07 -07:00
parent cb02bab89e
commit 49c9c21d52
2 changed files with 19 additions and 3 deletions

View File

@ -20,8 +20,11 @@ pub const Array = opaque {
return CFArrayGetCount(self); return CFArrayGetCount(self);
} }
pub fn getValueAtIndex(self: *Array, comptime T: type, idx: usize) *const T { /// Note the return type is actually a `*const T` but we strip the
return @ptrCast(*const T, CFArrayGetValueAtIndex(self, idx)); /// 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(*T, CFArrayGetValueAtIndex(self, idx));
} }
pub extern "c" fn CFArrayCreate( pub extern "c" fn CFArrayCreate(
@ -31,7 +34,7 @@ pub const Array = opaque {
callbacks: ?*const anyopaque, callbacks: ?*const anyopaque,
) ?*Array; ) ?*Array;
pub extern "c" fn CFArrayGetCount(*Array) usize; pub extern "c" fn CFArrayGetCount(*Array) usize;
pub extern "c" fn CFArrayGetValueAtIndex(*Array, usize) *const anyopaque; pub extern "c" fn CFArrayGetValueAtIndex(*Array, usize) *anyopaque;
extern "c" var kCFTypeArrayCallBacks: anyopaque; extern "c" var kCFTypeArrayCallBacks: anyopaque;
}; };

View File

@ -1,6 +1,7 @@
const std = @import("std"); const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const foundation = @import("../foundation.zig"); const foundation = @import("../foundation.zig");
const text = @import("../text.zig");
pub const FontCollection = opaque { pub const FontCollection = opaque {
pub fn createFromAvailableFonts() Allocator.Error!*FontCollection { pub fn createFromAvailableFonts() Allocator.Error!*FontCollection {
@ -33,4 +34,16 @@ test "collection" {
defer list.release(); defer list.release();
try testing.expect(list.getCount() > 0); try testing.expect(list.getCount() > 0);
// var i: usize = 0;
// while (i < list.getCount()) : (i += 1) {
// const desc = list.getValueAtIndex(text.FontDescriptor, i);
// {
// var buf: [128]u8 = undefined;
// const name = desc.copyAttribute(.name);
// defer name.release();
// const cstr = name.cstring(&buf, .utf8).?;
// std.log.warn("i={d} v={s}", .{ i, cstr });
// }
// }
} }