freetype/harfbuzz: shape_plan binding

This commit is contained in:
Ali Chraghi 2022-06-18 02:26:30 +04:30 committed by Stephen Gutekanst
parent 58d10a816a
commit 997328ddc6
3 changed files with 79 additions and 3 deletions

View file

@ -3,7 +3,6 @@ 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,

View file

@ -9,7 +9,7 @@ pub const ListShapers = struct {
return .{ .index = 0, .list = c.hb_shape_list_shapers() };
}
pub fn next(self: *ListShapers) ?[]const u8 {
pub fn next(self: *ListShapers) ?[:0]const u8 {
self.index += 1;
return std.mem.span(
self.list[self.index - 1] orelse return null,

View file

@ -1,2 +1,79 @@
const std = @import("std");
const c = @import("c.zig");
pub const ShapePlan = *c.hb_shape_plan_t;
const Buffer = @import("buffer.zig").Buffer;
const Font = @import("font.zig").Font;
const Face = @import("face.zig").Face;
const SegmentProps = @import("buffer.zig").SegmentProps;
const Feature = @import("common.zig").Feature;
pub const ShapePlan = struct {
handle: *c.hb_shape_plan_t,
pub fn init(face: Face, props: SegmentProps, features: ?[]const Feature, shapers: []const []const u8) ShapePlan {
return .{ .handle = hb_shape_plan_create(
face.handle,
&props.cast(),
if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0,
@ptrCast([*c]const [*c]const u8, shapers),
).? };
}
pub fn initCached(face: Face, props: SegmentProps, features: ?[]const Feature, shapers: []const []const u8) ShapePlan {
return .{ .handle = hb_shape_plan_create_cached(
face.handle,
&props.cast(),
if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0,
@ptrCast([*c]const [*c]const u8, shapers),
).? };
}
pub fn init2(face: Face, props: SegmentProps, features: ?[]const Feature, cords: []const i32, shapers: []const []const u8) ShapePlan {
return .{ .handle = hb_shape_plan_create2(
face.handle,
&props.cast(),
if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0,
cords.ptr,
@intCast(c_uint, cords.len),
@ptrCast([*c]const [*c]const u8, shapers),
).? };
}
pub fn initCached2(face: Face, props: SegmentProps, features: ?[]const Feature, cords: []const i32, shapers: []const []const u8) ShapePlan {
return .{ .handle = hb_shape_plan_create_cached2(
face.handle,
&props.cast(),
if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0,
cords.ptr,
@intCast(c_uint, cords.len),
@ptrCast([*c]const [*c]const u8, shapers),
).? };
}
pub fn deinit(self: ShapePlan) void {
c.hb_shape_plan_destroy(self.handle);
}
pub fn execute(self: ShapePlan, font: Font, buffer: Buffer, features: ?[]Feature) error{ShapingFailed}!void {
if (hb_shape_plan_execute(
self.handle,
font.handle,
buffer.handle,
if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0,
) < 1) return error.ShapingFailed;
}
pub fn getShaper(self: ShapePlan) [:0]const u8 {
return std.mem.span(c.hb_shape_plan_get_shaper(self.handle));
}
};
pub extern fn hb_shape_plan_create(face: ?*c.hb_face_t, props: [*c]const c.hb_segment_properties_t, user_features: [*c]const Feature, num_user_features: c_uint, shaper_list: [*c]const [*c]const u8) ?*c.hb_shape_plan_t;
pub extern fn hb_shape_plan_create_cached(face: ?*c.hb_face_t, props: [*c]const c.hb_segment_properties_t, user_features: [*c]const Feature, num_user_features: c_uint, shaper_list: [*c]const [*c]const u8) ?*c.hb_shape_plan_t;
pub extern fn hb_shape_plan_create2(face: ?*c.hb_face_t, props: [*c]const c.hb_segment_properties_t, user_features: [*c]const Feature, num_user_features: c_uint, coords: [*c]const c_int, num_coords: c_uint, shaper_list: [*c]const [*c]const u8) ?*c.hb_shape_plan_t;
pub extern fn hb_shape_plan_create_cached2(face: ?*c.hb_face_t, props: [*c]const c.hb_segment_properties_t, user_features: [*c]const Feature, num_user_features: c_uint, coords: [*c]const c_int, num_coords: c_uint, shaper_list: [*c]const [*c]const u8) ?*c.hb_shape_plan_t;
pub extern fn hb_shape_plan_execute(shape_plan: ?*c.hb_shape_plan_t, font: ?*c.hb_font_t, buffer: ?*c.hb_buffer_t, features: [*c]const Feature, num_features: c_uint) u8;