freetype/harfbuzz: shape and partial shape_plan binding
This commit is contained in:
parent
09a8b1afac
commit
58d10a816a
4 changed files with 50 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
|||
18
freetype/src/harfbuzz/shape.zig
Normal file
18
freetype/src/harfbuzz/shape.zig
Normal file
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
};
|
||||
2
freetype/src/harfbuzz/shape_plan.zig
Normal file
2
freetype/src/harfbuzz/shape_plan.zig
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
const c = @import("c.zig");
|
||||
pub const ShapePlan = *c.hb_shape_plan_t;
|
||||
Loading…
Add table
Add a link
Reference in a new issue