freetype: ziggify C structs

This commit is contained in:
Ali Chraghi 2022-05-26 02:00:18 +04:30 committed by Stephen Gutekanst
parent b5737af9cd
commit 18369e8c9b
5 changed files with 39 additions and 19 deletions

View file

@ -9,7 +9,16 @@ const utils = @import("utils.zig");
const Face = @This();
pub const SizeMetrics = c.FT_Size_Metrics;
pub const SizeMetrics = extern struct {
x_ppem: u16,
y_ppem: u16,
x_scale: c_long,
y_scale: c_long,
ascender: c_long,
descender: c_long,
height: c_long,
max_advance: c_long,
};
pub const KerningMode = enum(u2) {
default = c.FT_KERNING_DEFAULT,
unfitted = c.FT_KERNING_UNFITTED,
@ -131,7 +140,7 @@ pub fn loadChar(self: Face, char: u32, flags: LoadFlags) Error!void {
pub fn setTransform(self: Face, matrix: ?types.Matrix, delta: ?types.Vector) Error!void {
var m = matrix orelse std.mem.zeroes(types.Matrix);
var d = delta orelse std.mem.zeroes(types.Vector);
return c.FT_Set_Transform(self.handle, &m, &d);
return c.FT_Set_Transform(self.handle, @ptrCast(*c.FT_Matrix, &m), @ptrCast(*c.FT_Vector, &d));
}
pub fn getCharIndex(self: Face, index: u32) ?u32 {
@ -141,7 +150,7 @@ pub fn getCharIndex(self: Face, index: u32) ?u32 {
pub fn getKerning(self: Face, left_char_index: u32, right_char_index: u32, mode: KerningMode) Error!types.Vector {
var vec = std.mem.zeroes(types.Vector);
try convertError(c.FT_Get_Kerning(self.handle, left_char_index, right_char_index, @enumToInt(mode), &vec));
try convertError(c.FT_Get_Kerning(self.handle, left_char_index, right_char_index, @enumToInt(mode), @ptrCast(*c.FT_Vector, &vec)));
return vec;
}
@ -251,11 +260,10 @@ pub fn styleFlags(self: Face) StyleFlags {
}
pub fn sizeMetrics(self: Face) ?SizeMetrics {
const size = self.handle.*.size;
return if (size == null)
null
return if (self.handle.*.size) |size|
@ptrCast(*SizeMetrics, &size.*.metrics).*
else
size.*.metrics;
null;
}
pub fn postscriptName(self: Face) ?[:0]const u8 {

View file

@ -45,19 +45,19 @@ pub fn clone(self: Glyph) Error!Glyph {
pub fn transform(self: Glyph, matrix: ?types.Matrix, delta: ?types.Vector) Error!void {
var m = matrix orelse std.mem.zeroes(types.Matrix);
var d = delta orelse std.mem.zeroes(types.Vector);
try convertError(c.FT_Glyph_Transform(self.handle, &m, &d));
try convertError(c.FT_Glyph_Transform(self.handle, @ptrCast(*c.FT_Matrix, &m), @ptrCast(*c.FT_Vector, &d)));
}
pub fn getCBox(self: Glyph, bbox_mode: BBoxMode) types.BBox {
var res = std.mem.zeroes(types.BBox);
c.FT_Glyph_Get_CBox(self.handle, @enumToInt(bbox_mode), &res);
c.FT_Glyph_Get_CBox(self.handle, @enumToInt(bbox_mode), @ptrCast(*c.FT_BBox, &res));
return res;
}
pub fn toBitmap(self: Glyph, render_mode: types.RenderMode, origin: ?types.Vector) Error!BitmapGlyph {
var res = self.handle;
var o = origin orelse std.mem.zeroes(types.Vector);
try convertError(c.FT_Glyph_To_Bitmap(&res, @enumToInt(render_mode), &o, 0));
try convertError(c.FT_Glyph_To_Bitmap(&res, @enumToInt(render_mode), @ptrCast(*c.FT_Vector, &o), 0));
return BitmapGlyph.init(@ptrCast(c.FT_BitmapGlyph, self.handle));
}

View file

@ -29,7 +29,7 @@ pub fn render(self: GlyphSlot, render_mode: types.RenderMode) Error!void {
pub fn subGlyphInfo(self: GlyphSlot, sub_index: u32) Error!SubGlyphInfo {
var info = std.mem.zeroes(SubGlyphInfo);
try convertError(c.FT_Get_SubGlyph_Info(self.handle, sub_index, &info.index, &info.flags, &info.arg1, &info.arg2, &info.transform));
try convertError(c.FT_Get_SubGlyph_Info(self.handle, sub_index, &info.index, &info.flags, &info.arg1, &info.arg2, @ptrCast(*c.FT_Matrix, &info.transform)));
return info;
}
@ -67,7 +67,7 @@ pub fn linearVertAdvance(self: GlyphSlot) i64 {
}
pub fn advance(self: GlyphSlot) types.Vector {
return self.handle.*.advance;
return @ptrCast(*types.Vector, &self.handle.*.advance).*;
}
pub fn format(self: GlyphSlot) Glyph.GlyphFormat {

View file

@ -22,7 +22,7 @@ pub fn numContours(self: Outline) u15 {
}
pub fn points(self: Outline) []const types.Vector {
return self.handle.*.points[0..self.numPoints()];
return @ptrCast([]types.Vector, self.handle.*.points[0..self.numPoints()]);
}
pub fn tags(self: Outline) []const u8 {
@ -39,12 +39,12 @@ pub fn check(self: Outline) Error!void {
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);
c.FT_Outline_Transform(self.handle, @ptrCast(*c.FT_Matrix, &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));
try convertError(c.FT_Outline_Get_BBox(self.handle, @ptrCast(*c.FT_BBox, &res)));
return res;
}

View file

@ -2,10 +2,22 @@ const std = @import("std");
const c = @import("c.zig");
const utils = @import("utils.zig");
pub const Vector = c.FT_Vector;
pub const Matrix = c.FT_Matrix;
pub const Pos = c.FT_Pos;
pub const BBox = c.FT_BBox;
pub const Vector = extern struct {
x: c_long,
y: c_long,
};
pub const Matrix = extern struct {
xx: c_long,
xy: c_long,
yx: c_long,
yy: c_long,
};
pub const BBox = extern struct {
xMin: c_long,
yMin: c_long,
xMax: c_long,
yMax: c_long,
};
pub const RenderMode = enum(u3) {
normal = c.FT_RENDER_MODE_NORMAL,