mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-05-17 21:58:39 +03:00
pkg/macos: implement CTRun
This commit is contained in:
@ -5,6 +5,7 @@ pub usingnamespace @import("text/font_manager.zig");
|
|||||||
pub usingnamespace @import("text/frame.zig");
|
pub usingnamespace @import("text/frame.zig");
|
||||||
pub usingnamespace @import("text/framesetter.zig");
|
pub usingnamespace @import("text/framesetter.zig");
|
||||||
pub usingnamespace @import("text/line.zig");
|
pub usingnamespace @import("text/line.zig");
|
||||||
|
pub usingnamespace @import("text/run.zig");
|
||||||
pub usingnamespace @import("text/stylized_strings.zig");
|
pub usingnamespace @import("text/stylized_strings.zig");
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
@ -49,6 +49,10 @@ pub const Line = opaque {
|
|||||||
leading,
|
leading,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getGlyphRuns(self: *Line) *foundation.Array {
|
||||||
|
return @ptrCast(c.CTLineGetGlyphRuns(@ptrCast(self)));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const LineBoundsOptions = packed struct {
|
pub const LineBoundsOptions = packed struct {
|
||||||
|
62
pkg/macos/text/run.zig
Normal file
62
pkg/macos/text/run.zig
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
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 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.CTRunGetGlyphsPtr(@ptrCast(self)) orelse &.{};
|
||||||
|
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, .len = 0 }, ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getPositionsPtr(self: *Run) []const graphics.Point {
|
||||||
|
const len = self.getGlyphCount();
|
||||||
|
if (len == 0) return &.{};
|
||||||
|
const ptr = c.CTRunGetPositionsPtr(@ptrCast(self)) orelse &.{};
|
||||||
|
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, .len = 0 }, ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getAdvancesPtr(self: *Run) []const graphics.Size {
|
||||||
|
const len = self.getGlyphCount();
|
||||||
|
if (len == 0) return &.{};
|
||||||
|
const ptr = c.CTRunGetAdvancesPtr(@ptrCast(self)) orelse &.{};
|
||||||
|
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, .len = 0 }, ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
};
|
Reference in New Issue
Block a user