mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/harfbuzz: add coretext compilation on macOS
This commit is contained in:
@ -258,13 +258,18 @@ fn addDeps(
|
||||
});
|
||||
|
||||
// Harfbuzz
|
||||
_ = try harfbuzz.link(b, step, .{
|
||||
const harfbuzz_step = try harfbuzz.link(b, step, .{
|
||||
.freetype = .{
|
||||
.enabled = true,
|
||||
.step = freetype_step,
|
||||
.include = &freetype.include_paths,
|
||||
},
|
||||
|
||||
.coretext = .{
|
||||
.enabled = enable_coretext,
|
||||
},
|
||||
});
|
||||
system_sdk.include(b, harfbuzz_step, .{});
|
||||
|
||||
// Libuv
|
||||
const libuv_step = try libuv.link(b, step);
|
||||
|
@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const freetypepkg = @import("../freetype/build.zig");
|
||||
const macospkg = @import("../macos/build.zig");
|
||||
|
||||
/// Directories with our includes.
|
||||
const root = thisDir() ++ "../../../vendor/harfbuzz/";
|
||||
@ -10,7 +11,7 @@ pub const include_paths = .{include_path};
|
||||
pub const pkg = std.build.Pkg{
|
||||
.name = "harfbuzz",
|
||||
.source = .{ .path = thisDir() ++ "/main.zig" },
|
||||
.dependencies = &.{freetypepkg.pkg},
|
||||
.dependencies = &.{ freetypepkg.pkg, macospkg.pkg },
|
||||
};
|
||||
|
||||
fn thisDir() []const u8 {
|
||||
@ -19,12 +20,17 @@ fn thisDir() []const u8 {
|
||||
|
||||
pub const Options = struct {
|
||||
freetype: Freetype = .{},
|
||||
coretext: CoreText = .{},
|
||||
|
||||
pub const Freetype = struct {
|
||||
enabled: bool = false,
|
||||
step: ?*std.build.LibExeObjStep = null,
|
||||
include: ?[]const []const u8 = null,
|
||||
};
|
||||
|
||||
pub const CoreText = struct {
|
||||
enabled: bool = false,
|
||||
};
|
||||
};
|
||||
|
||||
pub fn link(
|
||||
@ -85,6 +91,14 @@ pub fn buildHarfbuzz(
|
||||
"-DHAVE_FT_GET_TRANSFORM=1",
|
||||
});
|
||||
|
||||
if (opt.coretext.enabled) {
|
||||
try flags.appendSlice(&.{
|
||||
"-DHAVE_CORETEXT=1",
|
||||
});
|
||||
|
||||
lib.linkFramework("ApplicationServices");
|
||||
}
|
||||
|
||||
// C files
|
||||
lib.addCSourceFiles(srcs, flags.items);
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub usingnamespace @cImport({
|
||||
@cInclude("hb.h");
|
||||
@cInclude("hb-ft.h");
|
||||
if (builtin.os.tag == .macos) @cInclude("hb-coretext.h");
|
||||
});
|
||||
|
30
pkg/harfbuzz/coretext.zig
Normal file
30
pkg/harfbuzz/coretext.zig
Normal file
@ -0,0 +1,30 @@
|
||||
const macos = @import("macos");
|
||||
const std = @import("std");
|
||||
const c = @import("c.zig");
|
||||
const Face = @import("face.zig").Face;
|
||||
const Font = @import("font.zig").Font;
|
||||
const Error = @import("errors.zig").Error;
|
||||
|
||||
// Use custom extern functions so that the proper CoreText structs are used
|
||||
// without a ptrcast.
|
||||
extern fn hb_coretext_font_create(ct_face: *macos.text.Font) ?*c.hb_font_t;
|
||||
|
||||
/// Creates an hb_font_t font object from the specified CTFontRef.
|
||||
pub fn createFont(face: *macos.text.Font) Error!Font {
|
||||
const handle = hb_coretext_font_create(face) orelse return Error.HarfbuzzFailed;
|
||||
return Font{ .handle = handle };
|
||||
}
|
||||
|
||||
test {
|
||||
if (!@hasDecl(c, "hb_coretext_font_create")) return error.SkipZigTest;
|
||||
|
||||
const name = try macos.foundation.String.createWithBytes("Monaco", .utf8, false);
|
||||
defer name.release();
|
||||
const desc = try macos.text.FontDescriptor.createWithNameAndSize(name, 12);
|
||||
defer desc.release();
|
||||
const font = try macos.text.Font.createWithFontDescriptor(desc, 12);
|
||||
defer font.release();
|
||||
|
||||
var hb_font = try createFont(font);
|
||||
defer hb_font.destroy();
|
||||
}
|
@ -47,6 +47,8 @@ pub fn setFontFuncs(font: Font) void {
|
||||
}
|
||||
|
||||
test {
|
||||
if (!@hasDecl(c, "hb_ft_font_create_referenced")) return error.SkipZigTest;
|
||||
|
||||
const testing = std.testing;
|
||||
const testFont = freetype.testing.font_regular;
|
||||
const ftc = freetype.c;
|
||||
|
@ -8,6 +8,7 @@ pub usingnamespace @import("font.zig");
|
||||
pub usingnamespace @import("shape.zig");
|
||||
pub usingnamespace @import("version.zig");
|
||||
pub const freetype = @import("freetype.zig");
|
||||
pub const coretext = @import("coretext.zig");
|
||||
|
||||
test {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
|
Reference in New Issue
Block a user