mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/macos: fix zig C ABI issue
This commit is contained in:
@ -18,7 +18,11 @@ pub fn link(
|
|||||||
opt: Options,
|
opt: Options,
|
||||||
) !*std.build.LibExeObjStep {
|
) !*std.build.LibExeObjStep {
|
||||||
_ = opt;
|
_ = opt;
|
||||||
|
var flags = std.ArrayList([]const u8).init(b.allocator);
|
||||||
|
defer flags.deinit();
|
||||||
|
|
||||||
const lib = b.addStaticLibrary("macos", null);
|
const lib = b.addStaticLibrary("macos", null);
|
||||||
|
step.addCSourceFile(thisDir() ++ "/text/ext.c", flags.items);
|
||||||
step.linkFramework("CoreFoundation");
|
step.linkFramework("CoreFoundation");
|
||||||
step.linkFramework("CoreText");
|
step.linkFramework("CoreText");
|
||||||
return lib;
|
return lib;
|
||||||
|
10
pkg/macos/text/ext.c
Normal file
10
pkg/macos/text/ext.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <CoreText/CoreText.h>
|
||||||
|
|
||||||
|
// A wrapper to fix a Zig C ABI issue.
|
||||||
|
void zig_cabi_CTLineGetBoundsWithOptions(
|
||||||
|
CTLineRef line,
|
||||||
|
CTLineBoundsOptions options,
|
||||||
|
CGRect *result
|
||||||
|
) {
|
||||||
|
*result = CTLineGetBoundsWithOptions(line, options);
|
||||||
|
}
|
@ -30,12 +30,30 @@ pub const Line = opaque {
|
|||||||
self: *Line,
|
self: *Line,
|
||||||
opts: LineBoundsOptions,
|
opts: LineBoundsOptions,
|
||||||
) graphics.Rect {
|
) graphics.Rect {
|
||||||
return @bitCast(c.CGRect, c.CTLineGetBoundsWithOptions(
|
// return @bitCast(c.CGRect, c.CTLineGetBoundsWithOptions(
|
||||||
|
// @ptrCast(c.CTLineRef, self),
|
||||||
|
// opts.cval(),
|
||||||
|
// ));
|
||||||
|
|
||||||
|
// We have to use a custom C wrapper here because there is some
|
||||||
|
// C ABI issue happening.
|
||||||
|
var result: graphics.Rect = undefined;
|
||||||
|
zig_cabi_CTLineGetBoundsWithOptions(
|
||||||
@ptrCast(c.CTLineRef, self),
|
@ptrCast(c.CTLineRef, self),
|
||||||
opts.cval(),
|
opts.cval(),
|
||||||
));
|
@ptrCast(*c.CGRect, &result),
|
||||||
|
);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See getBoundsWithOptions
|
||||||
|
extern "c" fn zig_cabi_CTLineGetBoundsWithOptions(
|
||||||
|
c.CTLineRef,
|
||||||
|
c.CTLineBoundsOptions,
|
||||||
|
*c.CGRect,
|
||||||
|
) void;
|
||||||
|
|
||||||
pub fn getTypographicBounds(
|
pub fn getTypographicBounds(
|
||||||
self: *Line,
|
self: *Line,
|
||||||
ascent: ?*f64,
|
ascent: ?*f64,
|
||||||
|
Reference in New Issue
Block a user