From 953f1aeb296b741316e438f706ac6317b875e0e4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 30 Aug 2022 10:02:40 -0700 Subject: [PATCH] pkg/harfbuzz: fixing some APIs --- pkg/harfbuzz/common.zig | 11 ++++++++--- pkg/harfbuzz/shape.zig | 12 +++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pkg/harfbuzz/common.zig b/pkg/harfbuzz/common.zig index 84b4d000f..a4cff17b5 100644 --- a/pkg/harfbuzz/common.zig +++ b/pkg/harfbuzz/common.zig @@ -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); +} diff --git a/pkg/harfbuzz/shape.zig b/pkg/harfbuzz/shape.zig index 260fbc85d..3567c8b11 100644 --- a/pkg/harfbuzz/shape.zig +++ b/pkg/harfbuzz/shape.zig @@ -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, ); }