mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/macos: starting frames
This commit is contained in:
@ -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 {
|
||||
|
29
pkg/macos/text/frame.zig
Normal file
29
pkg/macos/text/frame.zig
Normal file
@ -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...
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user