pkg/macos: add CoreText

This commit is contained in:
Mitchell Hashimoto
2022-09-30 14:48:06 -07:00
parent b0d9933249
commit f9e1127317
7 changed files with 73 additions and 1 deletions

View File

@ -184,7 +184,12 @@ fn addDeps(
step.addPackage(glfw.pkg);
step.addPackage(libuv.pkg);
step.addPackage(utf8proc.pkg);
if (step.target.isDarwin()) step.addPackage(macos.pkg);
// Mac Stuff
if (step.target.isDarwin()) {
step.addPackage(macos.pkg);
_ = try macos.link(b, step, .{});
}
// We always statically compile glad
step.addIncludePath("vendor/glad/include/");

View File

@ -20,5 +20,6 @@ pub fn link(
_ = opt;
const lib = b.addStaticLibrary("macos", null);
step.linkFramework("CoreFoundation");
step.linkFramework("CoreText");
return lib;
}

View File

@ -1,3 +1,4 @@
pub usingnamespace @import("foundation/dictionary.zig");
pub usingnamespace @import("foundation/string.zig");
pub usingnamespace @import("foundation/type.zig");

View File

@ -0,0 +1,37 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const cftype = @import("type.zig");
pub const Dictionary = opaque {
pub fn create() Allocator.Error!*Dictionary {
return CFDictionaryCreate(
null,
null,
null,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks,
) orelse Allocator.Error.OutOfMemory;
}
pub fn release(self: *Dictionary) void {
cftype.CFRelease(self);
}
pub extern "c" fn CFDictionaryCreate(
allocator: ?*anyopaque,
keys: ?[*]*const anyopaque,
values: ?[*]*const anyopaque,
num_values: usize,
key_callbacks: *const anyopaque,
value_callbacks: *const anyopaque,
) ?*Dictionary;
extern "c" var kCFTypeDictionaryKeyCallBacks: anyopaque;
extern "c" var kCFTypeDictionaryValueCallBacks: anyopaque;
};
test "dictionary" {
const dict = try Dictionary.create();
defer dict.release();
}

View File

@ -1,4 +1,5 @@
pub const foundation = @import("foundation.zig");
pub const text = @import("text.zig");
test {
@import("std").testing.refAllDecls(@This());

5
pkg/macos/text.zig Normal file
View File

@ -0,0 +1,5 @@
pub usingnamespace @import("text/font_collection.zig");
test {
@import("std").testing.refAllDecls(@This());
}

View File

@ -0,0 +1,22 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const foundation = @import("../foundation.zig");
pub const FontCollection = opaque {
pub fn createFromAvailableFonts() Allocator.Error!*FontCollection {
return CTFontCollectionCreateFromAvailableFonts(null) orelse Allocator.Error.OutOfMemory;
}
pub fn release(self: *FontCollection) void {
foundation.CFRelease(self);
}
pub extern "c" fn CTFontCollectionCreateFromAvailableFonts(
options: ?*foundation.Dictionary,
) ?*FontCollection;
};
test "collection" {
const v = try FontCollection.createFromAvailableFonts();
defer v.release();
}