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, end: c_uint,
pub fn fromString(str: []const u8) ?Feature { 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( return if (c.hb_feature_from_string(
str.ptr, str.ptr,
@intCast(c_int, str.len), @intCast(c_int, str.len),
&f, &f,
) > 1) ) > 0)
f @bitCast(Feature, f)
else else
null; null;
} }
@ -243,3 +243,8 @@ pub const Feature = extern struct {
c.hb_feature_to_string(self, buf.ptr, @intCast(c_uint, buf.len)); 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 /// but overlapping ranges the value of the feature with the higher index
/// takes precedence. /// takes precedence.
pub fn shape(font: Font, buf: Buffer, features: ?[]const Feature) void { 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( c.hb_shape(
font.handle, font.handle,
buf.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, if (features) |f| @intCast(c_uint, f.len) else 0,
); );
} }