diff --git a/freetype/src/harfbuzz/font.zig b/freetype/src/harfbuzz/font.zig index 7a2f6144..3f8bbfd7 100644 --- a/freetype/src/harfbuzz/font.zig +++ b/freetype/src/harfbuzz/font.zig @@ -1,5 +1,9 @@ const c = @import("c.zig"); const Face = @import("face.zig").Face; +const Buffer = @import("buffer.zig").Buffer; +const Feature = @import("common.zig").Feature; +const SegmentProps = @import("buffer.zig").SegmentProps; +const ShapePlan = @import("shape_plan.zig").ShapePlan; pub const Font = struct { handle: *c.hb_font_t, @@ -55,4 +59,26 @@ pub const Font = struct { pub fn setFace(self: Font, face: Face) void { return c.hb_font_set_face(self.handle, face.handle); } + + pub fn shape(self: Font, buf: Buffer, features: ?[]const Feature) void { + hb_shape( + self.handle, + buf.handle, + if (features) |f| f.ptr else null, + if (features) |f| @intCast(c_uint, f.len) else 0, + ); + } + + pub fn shapeFull(self: Font, buf: Buffer, features: ?[]const Feature, shapers: []const []const u8) error{ShapingFailed}!void { + if (hb_shape_full( + self.handle, + buf.handle, + if (features) |f| f.ptr else null, + if (features) |f| @intCast(c_uint, f.len) else 0, + @ptrCast([*c]const [*c]const u8, shapers), + ) < 1) return error.ShapingFailed; + } }; + +pub extern fn hb_shape(font: ?*c.hb_font_t, buffer: ?*c.hb_buffer_t, features: [*c]const Feature, num_features: c_uint) void; +pub extern fn hb_shape_full(font: ?*c.hb_font_t, buffer: ?*c.hb_buffer_t, features: [*c]const Feature, num_features: c_uint, shaper_list: [*c]const [*c]const u8) u8; diff --git a/freetype/src/harfbuzz/main.zig b/freetype/src/harfbuzz/main.zig index 332dd713..5d971ba5 100644 --- a/freetype/src/harfbuzz/main.zig +++ b/freetype/src/harfbuzz/main.zig @@ -3,6 +3,8 @@ pub usingnamespace @import("buffer.zig"); pub usingnamespace @import("common.zig"); pub usingnamespace @import("face.zig"); pub usingnamespace @import("font.zig"); +pub usingnamespace @import("shape.zig"); +pub usingnamespace @import("shape_plan.zig"); pub const c = @import("c.zig"); const utils = @import("utils"); @@ -13,4 +15,6 @@ test { utils.refAllDecls(@import("common.zig")); utils.refAllDecls(@import("face.zig")); utils.refAllDecls(@import("font.zig")); + utils.refAllDecls(@import("shape.zig")); + utils.refAllDecls(@import("shape_plan.zig")); } diff --git a/freetype/src/harfbuzz/shape.zig b/freetype/src/harfbuzz/shape.zig new file mode 100644 index 00000000..e57ce0c8 --- /dev/null +++ b/freetype/src/harfbuzz/shape.zig @@ -0,0 +1,18 @@ +const std = @import("std"); +const c = @import("c.zig"); + +pub const ListShapers = struct { + index: usize, + list: [*c][*c]const u8, + + pub fn init() ListShapers { + return .{ .index = 0, .list = c.hb_shape_list_shapers() }; + } + + pub fn next(self: *ListShapers) ?[]const u8 { + self.index += 1; + return std.mem.span( + self.list[self.index - 1] orelse return null, + ); + } +}; diff --git a/freetype/src/harfbuzz/shape_plan.zig b/freetype/src/harfbuzz/shape_plan.zig new file mode 100644 index 00000000..e9c5d116 --- /dev/null +++ b/freetype/src/harfbuzz/shape_plan.zig @@ -0,0 +1,2 @@ +const c = @import("c.zig"); +pub const ShapePlan = *c.hb_shape_plan_t;