Skip to content

Commit 123a74d

Browse files
committed
gfx/font: fix harfbuzz type conflict, deduplicate cimport
Signed-off-by: Emi <emi@hexops.com>
1 parent 07b7618 commit 123a74d

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

build.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ pub fn build(b: *std.Build) !void {
228228
if (want_sysgpu) linkSysgpu(b, unit_tests.root_module);
229229
if (want_core) linkCore(b, unit_tests.root_module);
230230
if (want_sysaudio) linkSysaudio(b, unit_tests.root_module);
231+
if (want_mach) {
232+
if (b.lazyDependency("freetype", .{
233+
.target = target,
234+
.optimize = optimize,
235+
})) |dep| unit_tests.root_module.linkLibrary(dep.artifact("freetype"));
236+
if (b.lazyDependency("harfbuzz", .{
237+
.target = target,
238+
.optimize = optimize,
239+
.enable_freetype = true,
240+
})) |dep| unit_tests.root_module.linkLibrary(dep.artifact("harfbuzz"));
241+
}
231242

232243
// Documentation
233244
const docs_obj = b.addObject(.{

src/gfx/font/native/Font.zig

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
const std = @import("std");
2-
const c = @cImport({
3-
@cInclude("ft2build.h");
4-
@cInclude("freetype/freetype.h");
5-
@cInclude("harfbuzz/hb.h");
6-
@cInclude("harfbuzz/hb-ft.h");
7-
});
2+
const c = @import("ft.zig").c;
83
const TextRun = @import("TextRun.zig");
94
const px_per_pt = @import("../main.zig").px_per_pt;
105
const RenderedGlyph = @import("../main.zig").RenderedGlyph;
@@ -112,7 +107,7 @@ pub fn render(f: *Font, allocator: std.mem.Allocator, glyph_index: u32, opt: Ren
112107
if (x < margin or x > (width + margin) or y < margin or y > (height + margin)) {
113108
data.* = RGBA32{ .r = 0, .g = 0, .b = 0, .a = 0 };
114109
} else {
115-
const alpha = buffer.?[((y - margin) * width + (x - margin)) % (glyph_bitmap.pitch * height)];
110+
const alpha = buffer.?[((y - margin) * width + (x - margin)) % (@as(c_uint, @intCast(glyph_bitmap.pitch)) * height)];
116111
data.* = RGBA32{ .r = 0, .g = 0, .b = 0, .a = alpha };
117112
}
118113
}

src/gfx/font/native/TextRun.zig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const std = @import("std");
2-
const c = @cImport({
3-
@cInclude("harfbuzz/hb.h");
4-
});
2+
const c = @import("ft.zig").c;
53
const math = @import("../../../main.zig").math;
64
const vec2 = math.vec2;
75
const Vec2 = math.Vec2;

src/gfx/font/native/ft.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub const c = @cImport({
2+
@cInclude("ft2build.h");
3+
@cInclude("freetype/freetype.h");
4+
@cInclude("harfbuzz/hb.h");
5+
@cInclude("harfbuzz/hb-ft.h");
6+
});

0 commit comments

Comments
 (0)