From f42bac6bc4316923ff6e2083a31900bd1bcc2797 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 28 Aug 2022 14:47:47 -0700 Subject: [PATCH] pkg/harfbuzz: use extern funcs for freetype interop --- pkg/harfbuzz/freetype.zig | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/harfbuzz/freetype.zig b/pkg/harfbuzz/freetype.zig index da33107ab..4ae3666a5 100644 --- a/pkg/harfbuzz/freetype.zig +++ b/pkg/harfbuzz/freetype.zig @@ -5,6 +5,13 @@ const Face = @import("face.zig").Face; const Font = @import("font.zig").Font; const Error = @import("errors.zig").Error; +// Use custom extern functions so that the proper freetype structs are used +// without a ptrcast. These are only needed when interacting with freetype +// C structs. +extern fn hb_ft_face_create_referenced(ft_face: freetype.c.FT_Face) ?*c.hb_face_t; +extern fn hb_ft_font_create_referenced(ft_face: freetype.c.FT_Face) ?*c.hb_font_t; +extern fn hb_ft_font_get_face(font: ?*c.hb_font_t) freetype.c.FT_Face; + /// Creates an hb_face_t face object from the specified FT_Face. /// /// This is the preferred variant of the hb_ft_face_create* function @@ -15,17 +22,13 @@ const Error = @import("errors.zig").Error; /// /// Use this version unless you know you have good reasons not to. pub fn createFace(face: freetype.c.FT_Face) Error!Face { - const handle = c.hb_ft_face_create_referenced( - @ptrCast(c.FT_Face, face), - ) orelse return Error.HarfbuzzFailed; + const handle = hb_ft_face_create_referenced(face) orelse return Error.HarfbuzzFailed; return Face{ .handle = handle }; } /// Creates an hb_font_t font object from the specified FT_Face. pub fn createFont(face: freetype.c.FT_Face) Error!Font { - const handle = c.hb_ft_font_create_referenced( - @ptrCast(c.FT_Face, face), - ) orelse return Error.HarfbuzzFailed; + const handle = hb_ft_font_create_referenced(face) orelse return Error.HarfbuzzFailed; return Font{ .handle = handle }; }