diff --git a/pkg/macos/build.zig.zon b/pkg/macos/build.zig.zon index 45ab2fa2b..49defbed9 100644 --- a/pkg/macos/build.zig.zon +++ b/pkg/macos/build.zig.zon @@ -1,6 +1,7 @@ .{ .name = "macos", .version = "0.1.0", + .paths = .{""}, .dependencies = .{ .apple_sdk = .{ .path = "../apple-sdk" }, }, diff --git a/pkg/macos/text.zig b/pkg/macos/text.zig index 2d5de91db..6a57c19b2 100644 --- a/pkg/macos/text.zig +++ b/pkg/macos/text.zig @@ -6,6 +6,7 @@ pub usingnamespace @import("text/font_manager.zig"); pub usingnamespace @import("text/frame.zig"); pub usingnamespace @import("text/framesetter.zig"); pub usingnamespace @import("text/line.zig"); +pub usingnamespace @import("text/paragraph_style.zig"); pub usingnamespace @import("text/run.zig"); pub usingnamespace @import("text/stylized_strings.zig"); diff --git a/pkg/macos/text/paragraph_style.zig b/pkg/macos/text/paragraph_style.zig new file mode 100644 index 000000000..3f7a9bbfb --- /dev/null +++ b/pkg/macos/text/paragraph_style.zig @@ -0,0 +1,46 @@ +const std = @import("std"); +const assert = std.debug.assert; +const Allocator = std.mem.Allocator; +const foundation = @import("../foundation.zig"); +const graphics = @import("../graphics.zig"); +const text = @import("../text.zig"); +const c = @import("c.zig"); + +// https://developer.apple.com/documentation/coretext/ctparagraphstyle?language=objc +pub const ParagraphStyle = opaque { + pub fn create( + settings: []const ParagraphStyleSetting, + ) Allocator.Error!*ParagraphStyle { + return @ptrCast(@constCast(c.CTParagraphStyleCreate( + @ptrCast(settings.ptr), + settings.len, + ))); + } + + pub fn release(self: *ParagraphStyle) void { + foundation.CFRelease(self); + } +}; + +/// https://developer.apple.com/documentation/coretext/ctparagraphstylesetting?language=objc +pub const ParagraphStyleSetting = extern struct { + spec: ParagraphStyleSpecifier, + value_size: usize, + value: *const anyopaque, +}; + +/// https://developer.apple.com/documentation/coretext/ctparagraphstylespecifier?language=objc +pub const ParagraphStyleSpecifier = enum(c_uint) { + base_writing_direction = 13, +}; + +pub const WritingDirection = enum(i8) { + natural = -1, + left_to_right = 0, + right_to_left = 1, +}; + +test ParagraphStyle { + const p = try ParagraphStyle.create(&.{}); + defer p.release(); +} diff --git a/pkg/macos/text/stylized_strings.zig b/pkg/macos/text/stylized_strings.zig index b922a8650..119d655dd 100644 --- a/pkg/macos/text/stylized_strings.zig +++ b/pkg/macos/text/stylized_strings.zig @@ -3,10 +3,12 @@ const c = @import("c.zig"); pub const StringAttribute = enum { font, + paragraph_style, pub fn key(self: StringAttribute) *foundation.String { return @ptrFromInt(@intFromPtr(switch (self) { .font => c.kCTFontAttributeName, + .paragraph_style => c.kCTParagraphStyleAttributeName, })); } };