pkg/harfbuzz: fixing some APIs

This commit is contained in:
Mitchell Hashimoto
2022-08-30 10:02:40 -07:00
parent 36140d3ee9
commit 953f1aeb29
2 changed files with 19 additions and 4 deletions

View File

@ -228,13 +228,13 @@ pub const Feature = extern struct {
end: c_uint,
pub fn fromString(str: []const u8) ?Feature {
var f: Feature = undefined;
var f: c.hb_feature_t = undefined;
return if (c.hb_feature_from_string(
str.ptr,
@intCast(c_int, str.len),
&f,
) > 1)
f
) > 0)
@bitCast(Feature, f)
else
null;
}
@ -243,3 +243,8 @@ pub const Feature = extern struct {
c.hb_feature_to_string(self, buf.ptr, @intCast(c_uint, buf.len));
}
};
test "feature from string" {
const testing = std.testing;
try testing.expect(Feature.fromString("dlig") != null);
}

View File

@ -10,10 +10,20 @@ const Feature = @import("common.zig").Feature;
/// but overlapping ranges the value of the feature with the higher index
/// takes precedence.
pub fn shape(font: Font, buf: Buffer, features: ?[]const Feature) void {
const hb_feats: [*c]const c.hb_feature_t = feats: {
if (features) |fs| {
if (fs.len > 0) {
break :feats @ptrCast([*]const c.hb_feature_t, fs.ptr);
}
}
break :feats null;
};
c.hb_shape(
font.handle,
buf.handle,
if (features) |f| @ptrCast([*]const c.hb_feature_t, f.ptr) else null,
hb_feats,
if (features) |f| @intCast(c_uint, f.len) else 0,
);
}