From 8b3959dceb29b45fda27b46986b7aa97b7e43e9b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 9 Oct 2022 08:07:56 -0700 Subject: [PATCH] macos: frames, attributed strings, stylized strings --- pkg/macos/foundation/attributed_string.zig | 22 +++++++++++++++++++++- pkg/macos/text.zig | 1 + pkg/macos/text/frame.zig | 7 +++++++ pkg/macos/text/stylized_strings.zig | 12 ++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 pkg/macos/text/stylized_strings.zig diff --git a/pkg/macos/foundation/attributed_string.zig b/pkg/macos/foundation/attributed_string.zig index fbe972acf..4c03c2859 100644 --- a/pkg/macos/foundation/attributed_string.zig +++ b/pkg/macos/foundation/attributed_string.zig @@ -5,7 +5,27 @@ const foundation = @import("../foundation.zig"); const text = @import("../text.zig"); const c = @import("c.zig"); -pub const AttributedString = opaque {}; +pub const AttributedString = opaque { + pub fn release(self: *AttributedString) void { + foundation.CFRelease(self); + } + + pub fn getLength(self: *AttributedString) usize { + return @intCast( + usize, + c.CFAttributedStringGetLength(@ptrCast(c.CFAttributedStringRef, self)), + ); + } + + pub fn getString(self: *AttributedString) *foundation.String { + return @intToPtr( + *foundation.String, + @ptrToInt( + c.CFAttributedStringGetString(@ptrCast(c.CFAttributedStringRef, self)), + ), + ); + } +}; pub const MutableAttributedString = opaque { pub fn create(cap: usize) Allocator.Error!*MutableAttributedString { diff --git a/pkg/macos/text.zig b/pkg/macos/text.zig index 6111fd7c5..ee6018312 100644 --- a/pkg/macos/text.zig +++ b/pkg/macos/text.zig @@ -4,6 +4,7 @@ pub usingnamespace @import("text/font_descriptor.zig"); pub usingnamespace @import("text/font_manager.zig"); pub usingnamespace @import("text/frame.zig"); pub usingnamespace @import("text/framesetter.zig"); +pub usingnamespace @import("text/stylized_strings.zig"); test { @import("std").testing.refAllDecls(@This()); diff --git a/pkg/macos/text/frame.zig b/pkg/macos/text/frame.zig index b2a77dd61..08866af50 100644 --- a/pkg/macos/text/frame.zig +++ b/pkg/macos/text/frame.zig @@ -22,6 +22,13 @@ pub const Frame = opaque { @ptrCast(*c.CGPoint, points.ptr), ); } + + pub fn getLines(self: *Frame) *foundation.Array { + return @intToPtr( + *foundation.Array, + @ptrToInt(c.CTFrameGetLines(@ptrCast(c.CTFrameRef, self))), + ); + } }; test { diff --git a/pkg/macos/text/stylized_strings.zig b/pkg/macos/text/stylized_strings.zig new file mode 100644 index 000000000..2e1e8721f --- /dev/null +++ b/pkg/macos/text/stylized_strings.zig @@ -0,0 +1,12 @@ +const foundation = @import("../foundation.zig"); +const c = @import("c.zig"); + +pub const StringAttribute = enum { + font, + + pub fn key(self: StringAttribute) *foundation.String { + return @intToPtr(*foundation.String, @ptrToInt(switch (self) { + .font => c.kCTFontAttributeName, + })); + } +};