diff --git a/pkg/macos/text.zig b/pkg/macos/text.zig index 5875441ec..6111fd7c5 100644 --- a/pkg/macos/text.zig +++ b/pkg/macos/text.zig @@ -2,6 +2,7 @@ pub usingnamespace @import("text/font.zig"); pub usingnamespace @import("text/font_collection.zig"); 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"); test { diff --git a/pkg/macos/text/frame.zig b/pkg/macos/text/frame.zig new file mode 100644 index 000000000..b2a77dd61 --- /dev/null +++ b/pkg/macos/text/frame.zig @@ -0,0 +1,29 @@ +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"); + +pub const Frame = opaque { + pub fn release(self: *Frame) void { + foundation.CFRelease(self); + } + + pub fn getLineOrigins( + self: *Frame, + range: foundation.Range, + points: []graphics.Point, + ) void { + c.CTFrameGetLineOrigins( + @ptrCast(c.CTFrameRef, self), + @bitCast(c.CFRange, range), + @ptrCast(*c.CGPoint, points.ptr), + ); + } +}; + +test { + // See framesetter tests... +} diff --git a/pkg/macos/text/framesetter.zig b/pkg/macos/text/framesetter.zig index e62ff125b..ee3c4edd9 100644 --- a/pkg/macos/text/framesetter.zig +++ b/pkg/macos/text/framesetter.zig @@ -19,6 +19,23 @@ pub const Framesetter = opaque { pub fn release(self: *Framesetter) void { foundation.CFRelease(self); } + + pub fn createFrame( + self: *Framesetter, + range: foundation.Range, + path: *graphics.Path, + attrs: ?*foundation.Dictionary, + ) !*text.Frame { + return @intToPtr( + ?*text.Frame, + @ptrToInt(c.CTFramesetterCreateFrame( + @ptrCast(c.CTFramesetterRef, self), + @bitCast(c.CFRange, range), + @ptrCast(c.CGPathRef, path), + @ptrCast(c.CFDictionaryRef, attrs), + )), + ) orelse error.FrameCreateFailed; + } }; test { @@ -32,4 +49,18 @@ test { const fs = try Framesetter.createWithAttributedString(@ptrCast(*foundation.AttributedString, str)); defer fs.release(); + + const path = try graphics.Path.createWithRect(graphics.Rect.init(0, 0, 100, 200), null); + defer path.release(); + const frame = try fs.createFrame( + foundation.Range.init(0, 0), + path, + null, + ); + defer frame.release(); + + { + var points: [1]graphics.Point = undefined; + frame.getLineOrigins(foundation.Range.init(0, 1), &points); + } }