mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/macos: add many more text APIs
This commit is contained in:
@ -6,6 +6,17 @@ const text = @import("../text.zig");
|
|||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
|
||||||
pub const AttributedString = opaque {
|
pub const AttributedString = opaque {
|
||||||
|
pub fn create(
|
||||||
|
str: *foundation.String,
|
||||||
|
attributes: *foundation.Dictionary,
|
||||||
|
) Allocator.Error!*AttributedString {
|
||||||
|
return @constCast(@ptrCast(c.CFAttributedStringCreate(
|
||||||
|
null,
|
||||||
|
@ptrCast(str),
|
||||||
|
@ptrCast(attributes),
|
||||||
|
) orelse return Allocator.Error.OutOfMemory));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn release(self: *AttributedString) void {
|
pub fn release(self: *AttributedString) void {
|
||||||
foundation.CFRelease(self);
|
foundation.CFRelease(self);
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,31 @@ pub const String = opaque {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const MutableString = opaque {
|
||||||
|
pub fn create(cap: usize) !*MutableString {
|
||||||
|
return @ptrCast(c.CFStringCreateMutable(
|
||||||
|
null,
|
||||||
|
@intCast(cap),
|
||||||
|
) orelse return Allocator.Error.OutOfMemory);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn release(self: *MutableString) void {
|
||||||
|
foundation.CFRelease(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn string(self: *MutableString) *String {
|
||||||
|
return @ptrCast(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn appendCharacters(self: *MutableString, chars: []const u16) void {
|
||||||
|
c.CFStringAppendCharacters(
|
||||||
|
@ptrCast(self),
|
||||||
|
chars.ptr,
|
||||||
|
@intCast(chars.len),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
pub const StringComparison = packed struct {
|
pub const StringComparison = packed struct {
|
||||||
case_insensitive: bool = false,
|
case_insensitive: bool = false,
|
||||||
_unused_2: bool = false,
|
_unused_2: bool = false,
|
||||||
|
@ -51,7 +51,7 @@ pub const Line = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getGlyphRuns(self: *Line) *foundation.Array {
|
pub fn getGlyphRuns(self: *Line) *foundation.Array {
|
||||||
return @ptrCast(c.CTLineGetGlyphRuns(@ptrCast(self)));
|
return @constCast(@ptrCast(c.CTLineGetGlyphRuns(@ptrCast(self))));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,7 +26,11 @@ pub const Run = opaque {
|
|||||||
const len = self.getGlyphCount();
|
const len = self.getGlyphCount();
|
||||||
const ptr = try alloc.alloc(graphics.Glyph, len);
|
const ptr = try alloc.alloc(graphics.Glyph, len);
|
||||||
errdefer alloc.free(ptr);
|
errdefer alloc.free(ptr);
|
||||||
c.CTRunGetGlyphs(@ptrCast(self), .{ .location = 0, .len = 0 }, ptr);
|
c.CTRunGetGlyphs(
|
||||||
|
@ptrCast(self),
|
||||||
|
.{ .location = 0, .length = 0 },
|
||||||
|
@ptrCast(ptr.ptr),
|
||||||
|
);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +45,11 @@ pub const Run = opaque {
|
|||||||
const len = self.getGlyphCount();
|
const len = self.getGlyphCount();
|
||||||
const ptr = try alloc.alloc(graphics.Point, len);
|
const ptr = try alloc.alloc(graphics.Point, len);
|
||||||
errdefer alloc.free(ptr);
|
errdefer alloc.free(ptr);
|
||||||
c.CTRunGetPositions(@ptrCast(self), .{ .location = 0, .len = 0 }, ptr);
|
c.CTRunGetPositions(
|
||||||
|
@ptrCast(self),
|
||||||
|
.{ .location = 0, .length = 0 },
|
||||||
|
@ptrCast(ptr.ptr),
|
||||||
|
);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +64,30 @@ pub const Run = opaque {
|
|||||||
const len = self.getGlyphCount();
|
const len = self.getGlyphCount();
|
||||||
const ptr = try alloc.alloc(graphics.Size, len);
|
const ptr = try alloc.alloc(graphics.Size, len);
|
||||||
errdefer alloc.free(ptr);
|
errdefer alloc.free(ptr);
|
||||||
c.CTRunGetAdvances(@ptrCast(self), .{ .location = 0, .len = 0 }, 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.CTRunGetStringIndicesPtr(@ptrCast(self)) orelse &.{};
|
||||||
|
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;
|
return ptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user