freetype: implement some functions binding

This commit is contained in:
Ali Chraghi 2022-05-25 17:46:30 +04:30 committed by Stephen Gutekanst
parent 1a082ef5a7
commit 7a8aee8665
5 changed files with 71 additions and 24 deletions

View file

@ -1,16 +1,28 @@
const std = @import("std");
const c = @import("c.zig");
const types = @import("types.zig");
const Glyph = @import("Glyph.zig");
const Error = @import("error.zig").Error;
const convertError = @import("error.zig").convertError;
const Outline = @This();
handle: c.FT_Outline,
handle: *c.FT_Outline,
pub fn init(handle: c.FT_Outline) Outline {
pub fn init(handle: *c.FT_Outline) Outline {
return Outline{ .handle = handle };
}
pub fn numPoints(self: Outline) u15 {
return @intCast(u15, self.handle.*.n_points);
}
pub fn numContours(self: Outline) u15 {
return @intCast(u15, self.handle.*.n_contours);
}
pub fn points(self: Outline) []const types.Vector {
return self.handle.points[0..@intCast(u15, self.handle.n_points)];
return self.handle.*.points[0..self.numPoints()];
}
pub fn tags(self: Outline) []const u8 {
@ -18,5 +30,24 @@ pub fn tags(self: Outline) []const u8 {
}
pub fn contours(self: Outline) []const i16 {
return self.handle.contours[0..@intCast(u15, self.handle.n_contours)];
return self.handle.*.contours[0..self.numContours()];
}
pub fn check(self: Outline) Error!void {
try convertError(c.FT_Outline_Check(self.handle));
}
pub fn transform(self: Outline, matrix: ?types.Matrix) void {
var m = matrix orelse std.mem.zeroes(types.Matrix);
c.FT_Outline_Transform(self.handle, &m);
}
pub fn bbox(self: Outline) Error!types.BBox {
var res = std.mem.zeroes(types.BBox);
try convertError(c.FT_Outline_Get_BBox(self.handle, &res));
return res;
}
pub fn decompose(self: Outline, callbacks_ctx: anytype, callbacks: *c.FT_Outline_Funcs) Error!void {
try convertError(c.FT_Outline_Decompose(self.handle, callbacks, @ptrCast(?*anyopaque, callbacks_ctx)));
}