freetype: ~99% Core-API Coverage
- breaking structure changes - optimazed examples - more tests
This commit is contained in:
parent
db377459c4
commit
04a0a79ef6
21 changed files with 1176 additions and 549 deletions
|
|
@ -1,19 +1,15 @@
|
|||
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 intToError = @import("error.zig").intToError;
|
||||
const errorToInt = @import("error.zig").errorToInt;
|
||||
const Error = @import("error.zig").Error;
|
||||
const Matrix = @import("types.zig").Matrix;
|
||||
const BBox = @import("types.zig").BBox;
|
||||
const Vector = @import("image.zig").Vector;
|
||||
|
||||
const Outline = @This();
|
||||
|
||||
handle: *c.FT_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);
|
||||
}
|
||||
|
|
@ -22,8 +18,8 @@ pub fn numContours(self: Outline) u15 {
|
|||
return @intCast(u15, self.handle.*.n_contours);
|
||||
}
|
||||
|
||||
pub fn points(self: Outline) []const types.Vector {
|
||||
return @ptrCast([]types.Vector, self.handle.*.points[0..self.numPoints()]);
|
||||
pub fn points(self: Outline) []const Vector {
|
||||
return self.handle.*.points[0..self.numPoints()];
|
||||
}
|
||||
|
||||
pub fn tags(self: Outline) []const u8 {
|
||||
|
|
@ -38,25 +34,24 @@ pub fn check(self: Outline) Error!void {
|
|||
try intToError(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, @ptrCast(*c.FT_Matrix, &m));
|
||||
pub fn transform(self: Outline, matrix: ?Matrix) void {
|
||||
c.FT_Outline_Transform(self.handle, if (matrix) |m| &m else null);
|
||||
}
|
||||
|
||||
pub fn bbox(self: Outline) Error!types.BBox {
|
||||
var res = std.mem.zeroes(types.BBox);
|
||||
try intToError(c.FT_Outline_Get_BBox(self.handle, @ptrCast(*c.FT_BBox, &res)));
|
||||
return res;
|
||||
pub fn bbox(self: Outline) Error!BBox {
|
||||
var b: BBox = undefined;
|
||||
try intToError(c.FT_Outline_Get_BBox(self.handle, &b));
|
||||
return b;
|
||||
}
|
||||
|
||||
pub fn OutlineFuncs(comptime Context: type) type {
|
||||
return struct {
|
||||
move_to: fn (ctx: Context, to: types.Vector) Error!void,
|
||||
line_to: fn (ctx: Context, to: types.Vector) Error!void,
|
||||
conic_to: fn (ctx: Context, control: types.Vector, to: types.Vector) Error!void,
|
||||
cubic_to: fn (ctx: Context, control_0: types.Vector, control_1: types.Vector, to: types.Vector) Error!void,
|
||||
shift: c_int,
|
||||
delta: isize,
|
||||
move_to: fn (ctx: Context, to: Vector) Error!void,
|
||||
line_to: fn (ctx: Context, to: Vector) Error!void,
|
||||
conic_to: fn (ctx: Context, control: Vector, to: Vector) Error!void,
|
||||
cubic_to: fn (ctx: Context, control_0: Vector, control_1: Vector, to: Vector) Error!void,
|
||||
shift: i32,
|
||||
delta: i32,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -70,8 +65,8 @@ pub fn OutlineFuncsWrapper(comptime Context: type) type {
|
|||
return @ptrCast(*Self, @alignCast(@alignOf(Self), ptr));
|
||||
}
|
||||
|
||||
fn castVec(vec: [*c]const c.FT_Vector) types.Vector {
|
||||
return @intToPtr(*types.Vector, @ptrToInt(vec)).*;
|
||||
fn castVec(vec: [*c]const c.FT_Vector) Vector {
|
||||
return @intToPtr(*Vector, @ptrToInt(vec)).*;
|
||||
}
|
||||
|
||||
pub fn move_to(to: [*c]const c.FT_Vector, ctx: ?*anyopaque) callconv(.C) c_int {
|
||||
|
|
@ -130,7 +125,7 @@ pub fn decompose(self: Outline, ctx: anytype, callbacks: OutlineFuncs(@TypeOf(ct
|
|||
var wrapper = OutlineFuncsWrapper(@TypeOf(ctx)){ .ctx = ctx, .callbacks = callbacks };
|
||||
try intToError(c.FT_Outline_Decompose(
|
||||
self.handle,
|
||||
&c.FT_Outline_Funcs{
|
||||
&.{
|
||||
.move_to = @TypeOf(wrapper).move_to,
|
||||
.line_to = @TypeOf(wrapper).line_to,
|
||||
.conic_to = @TypeOf(wrapper).conic_to,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue