From 1e44df46070cc69b7b38b9525967b60c5af2ad24 Mon Sep 17 00:00:00 2001 From: Ali Chraghi <63465728+alichraghi@users.noreply.github.com> Date: Tue, 14 Jun 2022 02:59:02 +0430 Subject: [PATCH] freetype/harfbuzz: compelete face binding --- freetype/src/harfbuzz/face.zig | 75 ++++++++++++++++++++++++++++++++++ freetype/src/harfbuzz/main.zig | 2 + 2 files changed, 77 insertions(+) create mode 100644 freetype/src/harfbuzz/face.zig diff --git a/freetype/src/harfbuzz/face.zig b/freetype/src/harfbuzz/face.zig new file mode 100644 index 00000000..900d1937 --- /dev/null +++ b/freetype/src/harfbuzz/face.zig @@ -0,0 +1,75 @@ +const c = @import("c.zig"); +const Blob = @import("blob.zig").Blob; + +pub const UnicodeIterator = struct { + set: *c.hb_set_t, + prev_codepoint: u32 = 0, + + pub fn next(self: *UnicodeIterator) ?u32 { + var codepoint: u32 = c.HB_SET_VALUE_INVALID; + return if (c.hb_set_next(self.set, &codepoint) > 1) b: { + self.prev_codepoint = codepoint; + break :b codepoint; + } else null; + } +}; + +pub const Face = struct { + handle: *c.hb_face_t, + + pub fn init(blob: Blob, index: u16) Face { + return .{ .handle = c.hb_face_create(blob.handle, index).? }; + } + + pub fn initEmpty() Face { + return .{ .handle = c.hb_face_get_empty().? }; + } + + pub fn getCount(blob: Blob) u32 { + return c.hb_face_count(blob.handle); + } + + pub fn deinit(self: Face) void { + c.hb_face_destroy(self.handle); + } + + pub fn getGlyphcount(self: Face) u32 { + return c.hb_face_get_glyph_count(self.handle); + } + + pub fn setGlyphcount(self: Face, count: u32) void { + return c.hb_face_set_glyph_count(self.handle, count); + } + + pub fn getUnitsPerEM(self: Face) u32 { + return c.hb_face_get_upem(self.handle); + } + + pub fn setUnitsPerEM(self: Face, upem: u32) void { + return c.hb_face_set_upem(self.handle, upem); + } + + pub fn setIndex(self: Face, index: u32) void { + return c.hb_face_set_index(self.handle, index); + } + + pub fn isImmutable(self: Face) bool { + return c.hb_face_is_immutable(self.handle) > 0; + } + + pub fn makeImmutable(self: Face) void { + c.hb_face_make_immutable(self.handle); + } + + pub fn reference(self: Face) Face { + return .{ + .handle = c.hb_face_reference(self.handle).?, + }; + } + + pub fn collectUnicodes(self: Face) UnicodeIterator { + var set: *c.hb_set_t = undefined; + c.hb_face_collect_unicodes(self.handle, set); + return .{ .set = set }; + } +}; diff --git a/freetype/src/harfbuzz/main.zig b/freetype/src/harfbuzz/main.zig index f6a82eb8..e6533eac 100644 --- a/freetype/src/harfbuzz/main.zig +++ b/freetype/src/harfbuzz/main.zig @@ -1,6 +1,7 @@ pub usingnamespace @import("blob.zig"); pub usingnamespace @import("buffer.zig"); pub usingnamespace @import("common.zig"); +pub usingnamespace @import("face.zig"); pub const c = @import("c.zig"); const utils = @import("utils"); @@ -9,4 +10,5 @@ test { utils.refAllDecls(@import("blob.zig")); utils.refAllDecls(@import("buffer.zig")); utils.refAllDecls(@import("common.zig")); + utils.refAllDecls(@import("face.zig")); }