mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/macos: add mutable dictionaries, flesh out font descriptor
This commit is contained in:
@ -41,6 +41,29 @@ pub const Dictionary = opaque {
|
||||
}
|
||||
};
|
||||
|
||||
pub const MutableDictionary = opaque {
|
||||
pub fn create(cap: usize) Allocator.Error!*MutableDictionary {
|
||||
return @intToPtr(?*MutableDictionary, @ptrToInt(c.CFDictionaryCreateMutable(
|
||||
null,
|
||||
@intCast(c.CFIndex, cap),
|
||||
&c.kCFTypeDictionaryKeyCallBacks,
|
||||
&c.kCFTypeDictionaryValueCallBacks,
|
||||
))) orelse Allocator.Error.OutOfMemory;
|
||||
}
|
||||
|
||||
pub fn release(self: *MutableDictionary) void {
|
||||
foundation.CFRelease(self);
|
||||
}
|
||||
|
||||
pub fn setValue(self: *MutableDictionary, key: ?*const anyopaque, value: ?*const anyopaque) void {
|
||||
c.CFDictionarySetValue(
|
||||
@ptrCast(c.CFMutableDictionaryRef, self),
|
||||
key,
|
||||
value,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
test "dictionary" {
|
||||
const testing = std.testing;
|
||||
|
||||
@ -56,3 +79,22 @@ test "dictionary" {
|
||||
try testing.expect(dict.getValue(foundation.String, c.kCFURLIsPurgeableKey) != null);
|
||||
try testing.expect(dict.getValue(foundation.String, c.kCFURLIsVolumeKey) == null);
|
||||
}
|
||||
|
||||
test "mutable dictionary" {
|
||||
const testing = std.testing;
|
||||
|
||||
const dict = try MutableDictionary.create(0);
|
||||
defer dict.release();
|
||||
|
||||
const str = try foundation.String.createWithBytes("hello", .unicode, false);
|
||||
defer str.release();
|
||||
|
||||
dict.setValue(c.kCFURLIsPurgeableKey, str);
|
||||
|
||||
{
|
||||
const imm = @ptrCast(*Dictionary, dict);
|
||||
try testing.expectEqual(@as(usize, 1), imm.getCount());
|
||||
try testing.expect(imm.getValue(foundation.String, c.kCFURLIsPurgeableKey) != null);
|
||||
try testing.expect(imm.getValue(foundation.String, c.kCFURLIsVolumeKey) == null);
|
||||
}
|
||||
}
|
||||
|
3
pkg/macos/text/c.zig
Normal file
3
pkg/macos/text/c.zig
Normal file
@ -0,0 +1,3 @@
|
||||
pub usingnamespace @cImport({
|
||||
@cInclude("CoreText/CoreText.h");
|
||||
});
|
@ -11,6 +11,13 @@ pub const FontDescriptor = opaque {
|
||||
) orelse Allocator.Error.OutOfMemory;
|
||||
}
|
||||
|
||||
pub fn createWithAttributes(dict: *foundation.Dictionary) Allocator.Error!*FontDescriptor {
|
||||
return @intToPtr(
|
||||
?*FontDescriptor,
|
||||
@ptrToInt(c.CTFontDescriptorCreateWithAttributes(@ptrCast(c.CFDictionaryRef, dict))),
|
||||
) orelse Allocator.Error.OutOfMemory;
|
||||
}
|
||||
|
||||
pub fn release(self: *FontDescriptor) void {
|
||||
c.CFRelease(self);
|
||||
}
|
||||
|
Reference in New Issue
Block a user