From b4685feb37d29c950e4e27a160040bed7773885a Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Wed, 5 Apr 2023 16:37:52 +0200 Subject: [PATCH] freetype:harfbuzz: fix type for `shapers` args Non zero-terminated slices of the previous type caused runtime errors. --- libs/freetype/src/harfbuzz/common.zig | 2 ++ libs/freetype/src/harfbuzz/font.zig | 5 +++-- libs/freetype/src/harfbuzz/shape.zig | 7 +++---- libs/freetype/src/harfbuzz/shape_plan.zig | 17 +++++++++-------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/libs/freetype/src/harfbuzz/common.zig b/libs/freetype/src/harfbuzz/common.zig index 82e416d5..8fb4857f 100644 --- a/libs/freetype/src/harfbuzz/common.zig +++ b/libs/freetype/src/harfbuzz/common.zig @@ -276,6 +276,8 @@ pub const Tag = struct { } }; +pub const Shapers = ?[*:null]const ?[*:0]const u8; + pub extern fn hb_feature_from_string(str: [*c]const u8, len: c_int, feature: [*c]Feature) u8; pub extern fn hb_feature_to_string(feature: [*c]Feature, buf: [*c]u8, size: c_uint) void; pub extern fn hb_variation_from_string(str: [*c]const u8, len: c_int, variation: [*c]Variation) u8; diff --git a/libs/freetype/src/harfbuzz/font.zig b/libs/freetype/src/harfbuzz/font.zig index e50e94c4..829af644 100644 --- a/libs/freetype/src/harfbuzz/font.zig +++ b/libs/freetype/src/harfbuzz/font.zig @@ -5,6 +5,7 @@ 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 Shapers = @import("common.zig").Shapers; pub const Font = struct { handle: *c.hb_font_t, @@ -86,13 +87,13 @@ pub const Font = struct { ); } - pub fn shapeFull(self: Font, buf: Buffer, features: ?[]const Feature, shapers: []const []const u8) error{ShapingFailed}!void { + pub fn shapeFull(self: Font, buf: Buffer, features: ?[]const Feature, shapers: Shapers) 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), + shapers, ) < 1) return error.ShapingFailed; } }; diff --git a/libs/freetype/src/harfbuzz/shape.zig b/libs/freetype/src/harfbuzz/shape.zig index 4a2dd85a..71ea655d 100644 --- a/libs/freetype/src/harfbuzz/shape.zig +++ b/libs/freetype/src/harfbuzz/shape.zig @@ -3,7 +3,7 @@ const c = @import("c.zig"); pub const ListShapers = struct { index: usize, - list: [*c][*c]const u8, + list: [*:null]const ?[*:0]const u8, pub fn init() ListShapers { return .{ .index = 0, .list = c.hb_shape_list_shapers() }; @@ -11,9 +11,8 @@ pub const ListShapers = struct { pub fn next(self: *ListShapers) ?[:0]const u8 { self.index += 1; - return std.mem.span(@ptrCast( - ?[*:0]const u8, + return std.mem.span( self.list[self.index - 1] orelse return null, - )); + ); } }; diff --git a/libs/freetype/src/harfbuzz/shape_plan.zig b/libs/freetype/src/harfbuzz/shape_plan.zig index 8dedb5dd..66ec69c0 100644 --- a/libs/freetype/src/harfbuzz/shape_plan.zig +++ b/libs/freetype/src/harfbuzz/shape_plan.zig @@ -5,31 +5,32 @@ const Font = @import("font.zig").Font; const Face = @import("face.zig").Face; const SegmentProps = @import("buffer.zig").SegmentProps; const Feature = @import("common.zig").Feature; +const Shapers = @import("common.zig").Shapers; 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 { + pub fn init(face: Face, props: SegmentProps, features: ?[]const Feature, shapers: Shapers) 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), + shapers, ).? }; } - pub fn initCached(face: Face, props: SegmentProps, features: ?[]const Feature, shapers: []const []const u8) ShapePlan { + pub fn initCached(face: Face, props: SegmentProps, features: ?[]const Feature, shapers: Shapers) 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), + shapers, ).? }; } - pub fn init2(face: Face, props: SegmentProps, features: ?[]const Feature, cords: []const i32, shapers: []const []const u8) ShapePlan { + pub fn init2(face: Face, props: SegmentProps, features: ?[]const Feature, cords: []const i32, shapers: Shapers) ShapePlan { return .{ .handle = hb_shape_plan_create2( face.handle, &props.cast(), @@ -37,11 +38,11 @@ pub const ShapePlan = struct { if (features) |f| @intCast(c_uint, f.len) else 0, cords.ptr, @intCast(c_uint, cords.len), - @ptrCast([*c]const [*c]const u8, shapers), + shapers, ).? }; } - pub fn initCached2(face: Face, props: SegmentProps, features: ?[]const Feature, cords: []const i32, shapers: []const []const u8) ShapePlan { + pub fn initCached2(face: Face, props: SegmentProps, features: ?[]const Feature, cords: []const i32, shapers: Shapers) ShapePlan { return .{ .handle = hb_shape_plan_create_cached2( face.handle, &props.cast(), @@ -49,7 +50,7 @@ pub const ShapePlan = struct { if (features) |f| @intCast(c_uint, f.len) else 0, cords.ptr, @intCast(c_uint, cords.len), - @ptrCast([*c]const [*c]const u8, shapers), + shapers, ).? }; }