aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/pkg/macos/text/run.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/pkg/macos/text/run.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/pkg/macos/text/run.zig')
-rw-r--r--vendor/libghostty-vt/pkg/macos/text/run.zig117
1 files changed, 117 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/pkg/macos/text/run.zig b/vendor/libghostty-vt/pkg/macos/text/run.zig
new file mode 100644
index 00000000..2895bfe3
--- /dev/null
+++ b/vendor/libghostty-vt/pkg/macos/text/run.zig
@@ -0,0 +1,117 @@
+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").c;
+
+pub const Run = opaque {
+ pub fn release(self: *Run) void {
+ foundation.CFRelease(self);
+ }
+
+ pub fn getGlyphCount(self: *Run) usize {
+ return @intCast(c.CTRunGetGlyphCount(@ptrCast(self)));
+ }
+
+ pub fn getGlyphsPtr(self: *Run) ?[]const graphics.Glyph {
+ const len = self.getGlyphCount();
+ if (len == 0) return &.{};
+ const ptr: [*c]const graphics.Glyph = @ptrCast(
+ c.CTRunGetGlyphsPtr(@ptrCast(self)),
+ );
+ if (ptr == null) return null;
+ return ptr[0..len];
+ }
+
+ pub fn getGlyphs(self: *Run, alloc: Allocator) ![]const graphics.Glyph {
+ const len = self.getGlyphCount();
+ const ptr = try alloc.alloc(graphics.Glyph, len);
+ errdefer alloc.free(ptr);
+ c.CTRunGetGlyphs(
+ @ptrCast(self),
+ .{ .location = 0, .length = 0 },
+ @ptrCast(ptr.ptr),
+ );
+ return ptr;
+ }
+
+ pub fn getPositionsPtr(self: *Run) ?[]const graphics.Point {
+ const len = self.getGlyphCount();
+ if (len == 0) return &.{};
+ const ptr: [*c]const graphics.Point = @ptrCast(
+ c.CTRunGetPositionsPtr(@ptrCast(self)),
+ );
+ if (ptr == null) return null;
+ return ptr[0..len];
+ }
+
+ pub fn getPositions(self: *Run, alloc: Allocator) ![]const graphics.Point {
+ const len = self.getGlyphCount();
+ const ptr = try alloc.alloc(graphics.Point, len);
+ errdefer alloc.free(ptr);
+ c.CTRunGetPositions(
+ @ptrCast(self),
+ .{ .location = 0, .length = 0 },
+ @ptrCast(ptr.ptr),
+ );
+ return ptr;
+ }
+
+ pub fn getAdvancesPtr(self: *Run) ?[]const graphics.Size {
+ const len = self.getGlyphCount();
+ if (len == 0) return &.{};
+ const ptr: [*c]const graphics.Size = @ptrCast(
+ c.CTRunGetAdvancesPtr(@ptrCast(self)),
+ );
+ if (ptr == null) return null;
+ return ptr[0..len];
+ }
+
+ pub fn getAdvances(self: *Run, alloc: Allocator) ![]const graphics.Size {
+ const len = self.getGlyphCount();
+ const ptr = try alloc.alloc(graphics.Size, len);
+ errdefer alloc.free(ptr);
+ c.CTRunGetAdvances(
+ @ptrCast(self),
+ .{ .location = 0, .length = 0 },
+ @ptrCast(ptr.ptr),
+ );
+ return ptr;
+ }
+
+ pub fn getStringIndicesPtr(self: *Run) ?[]const usize {
+ const len = self.getGlyphCount();
+ if (len == 0) return &.{};
+ const ptr: [*c]const usize = @ptrCast(
+ c.CTRunGetStringIndicesPtr(@ptrCast(self)),
+ );
+ if (ptr == null) return null;
+ return ptr[0..len];
+ }
+
+ pub fn getStringIndices(self: *Run, alloc: Allocator) ![]const usize {
+ const len = self.getGlyphCount();
+ const ptr = try alloc.alloc(usize, len);
+ errdefer alloc.free(ptr);
+ c.CTRunGetStringIndices(
+ @ptrCast(self),
+ .{ .location = 0, .length = 0 },
+ @ptrCast(ptr.ptr),
+ );
+ return ptr;
+ }
+
+ pub fn getStatus(self: *Run) Status {
+ return @bitCast(c.CTRunGetStatus(@ptrCast(self)));
+ }
+};
+
+/// https://developer.apple.com/documentation/coretext/ctrunstatus?language=objc
+pub const Status = packed struct(u32) {
+ right_to_left: bool,
+ non_monotonic: bool,
+ has_non_identity_matrix: bool,
+ _pad: u29 = 0,
+};