mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/macos: text framesetter
This commit is contained in:
@ -5,6 +5,8 @@ const foundation = @import("../foundation.zig");
|
||||
const text = @import("../text.zig");
|
||||
const c = @import("c.zig");
|
||||
|
||||
pub const AttributedString = opaque {};
|
||||
|
||||
pub const MutableAttributedString = opaque {
|
||||
pub fn create(cap: usize) Allocator.Error!*MutableAttributedString {
|
||||
return @intToPtr(
|
||||
|
@ -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/framesetter.zig");
|
||||
|
||||
test {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
|
35
pkg/macos/text/framesetter.zig
Normal file
35
pkg/macos/text/framesetter.zig
Normal file
@ -0,0 +1,35 @@
|
||||
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 Framesetter = opaque {
|
||||
pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Framesetter {
|
||||
return @intToPtr(
|
||||
?*Framesetter,
|
||||
@ptrToInt(c.CTFramesetterCreateWithAttributedString(
|
||||
@ptrCast(c.CFAttributedStringRef, str),
|
||||
)),
|
||||
) orelse Allocator.Error.OutOfMemory;
|
||||
}
|
||||
|
||||
pub fn release(self: *Framesetter) void {
|
||||
foundation.CFRelease(self);
|
||||
}
|
||||
};
|
||||
|
||||
test {
|
||||
const str = try foundation.MutableAttributedString.create(0);
|
||||
defer str.release();
|
||||
{
|
||||
const rep = try foundation.String.createWithBytes("hello", .utf8, false);
|
||||
defer rep.release();
|
||||
str.replaceString(foundation.Range.init(0, 0), rep);
|
||||
}
|
||||
|
||||
const fs = try Framesetter.createWithAttributedString(@ptrCast(*foundation.AttributedString, str));
|
||||
defer fs.release();
|
||||
}
|
Reference in New Issue
Block a user