diff --git a/freetype/src/harfbuzz/font.zig b/freetype/src/harfbuzz/font.zig index 03a716a2..7a2f6144 100644 --- a/freetype/src/harfbuzz/font.zig +++ b/freetype/src/harfbuzz/font.zig @@ -1,3 +1,58 @@ const c = @import("c.zig"); +const Face = @import("face.zig").Face; -pub const Font = c.hb_font_t; +pub const Font = struct { + handle: *c.hb_font_t, + + pub fn init(face: Face) Font { + return .{ .handle = c.hb_font_create(face.handle).? }; + } + + pub fn createSubFont(self: Font) Font { + return .{ + .handle = c.hb_font_create_sub_font(self.handle).?, + }; + } + + pub fn deinit(self: Font) void { + c.hb_font_destroy(self.handle); + } + + pub fn getFace(self: Font) Face { + return .{ .handle = c.hb_font_get_face(self.handle).? }; + } + + pub fn getGlyph(self: Font, unicode: u32, variation_selector: u32) ?u32 { + var g: u32 = 0; + return if (c.hb_font_get_glyph(self.handle, unicode, variation_selector, &g) > 0) + g + else + null; + } + + pub fn getParent(self: Font) ?Font { + return Font{ .handle = c.hb_font_get_parent(self.handle) orelse return null }; + } + + pub fn getPPEM(self: Font) @Vector(2, u32) { + var x: u32 = 0; + var y: u32 = 0; + c.hb_font_get_ppem(self.handle, &@intCast(c_uint, x), &@intCast(c_uint, y)); + return @Vector(2, u32){ x, y }; + } + + pub fn getPTEM(self: Font) f32 { + return c.hb_font_get_ptem(self.handle); + } + + pub fn getScale(self: Font) @Vector(2, u32) { + var x: u32 = 0; + var y: u32 = 0; + c.hb_font_get_scale(self.handle, &@intCast(c_int, x), &@intCast(c_int, y)); + return @Vector(2, u32){ x, y }; + } + + pub fn setFace(self: Font, face: Face) void { + return c.hb_font_set_face(self.handle, face.handle); + } +}; diff --git a/freetype/src/harfbuzz/main.zig b/freetype/src/harfbuzz/main.zig index e6533eac..332dd713 100644 --- a/freetype/src/harfbuzz/main.zig +++ b/freetype/src/harfbuzz/main.zig @@ -2,6 +2,7 @@ pub usingnamespace @import("blob.zig"); pub usingnamespace @import("buffer.zig"); pub usingnamespace @import("common.zig"); pub usingnamespace @import("face.zig"); +pub usingnamespace @import("font.zig"); pub const c = @import("c.zig"); const utils = @import("utils"); @@ -11,4 +12,5 @@ test { utils.refAllDecls(@import("buffer.zig")); utils.refAllDecls(@import("common.zig")); utils.refAllDecls(@import("face.zig")); + utils.refAllDecls(@import("font.zig")); }