freetype: fix import structure

This commit is contained in:
alichraghi 2022-07-18 15:48:46 +04:30 committed by Stephen Gutekanst
parent 4e624c5381
commit dc832997e4
5 changed files with 80 additions and 80 deletions

View file

@ -1,7 +1,7 @@
const c = @import("c");
const intToError = @import("error.zig").intToError;
const Error = @import("error.zig").Error;
const Glyph = @import("Glyph.zig");
const Glyph = @import("glyph.zig").Glyph;
const Library = @import("freetype.zig").Library;
const Face = @import("freetype.zig").Face;
const RenderMode = @import("freetype.zig").RenderMode;

View file

@ -2,7 +2,7 @@ const std = @import("std");
const c = @import("c");
const intToError = @import("error.zig").intToError;
const Error = @import("error.zig").Error;
const Stroker = @import("Stroker.zig");
const Stroker = @import("stroke.zig").Stroker;
const Face = @import("freetype.zig").Face;
const OpenArgs = @import("freetype.zig").OpenArgs;
const LcdFilter = @import("lcdfilter.zig").LcdFilter;

View file

@ -2,7 +2,7 @@ const std = @import("std");
const c = @import("c");
const intToError = @import("error.zig").intToError;
const Error = @import("error.zig").Error;
const Stroker = @import("Stroker.zig");
const Stroker = @import("stroke.zig").Stroker;
const Library = @import("freetype.zig").Library;
const RenderMode = @import("freetype.zig").RenderMode;
const SizeMetrics = @import("freetype.zig").SizeMetrics;
@ -13,8 +13,6 @@ const GlyphFormat = @import("image.zig").GlyphFormat;
const Vector = @import("image.zig").Vector;
const Bitmap = @import("image.zig").Bitmap;
const Glyph = @This();
pub const BBoxMode = enum(u2) {
// https://freetype.org/freetype2/docs/reference/ft2-glyph_management.html#ft_glyph_bbox_mode
// both `unscaled` and `subpixel` are set to 0
@ -24,76 +22,78 @@ pub const BBoxMode = enum(u2) {
pixels = c.FT_GLYPH_BBOX_PIXELS,
};
handle: c.FT_Glyph,
pub const Glyph = struct {
handle: c.FT_Glyph,
pub fn deinit(self: Glyph) void {
c.FT_Done_Glyph(self.handle);
}
pub fn deinit(self: Glyph) void {
c.FT_Done_Glyph(self.handle);
}
pub fn newGlyph(library: Library, glyph_format: GlyphFormat) Glyph {
var g: c.FT_Glyph = undefined;
return .{
.handle = c.FT_New_Glyph(library.handle, @enumToInt(glyph_format), &g),
};
}
pub fn newGlyph(library: Library, glyph_format: GlyphFormat) Glyph {
var g: c.FT_Glyph = undefined;
return .{
.handle = c.FT_New_Glyph(library.handle, @enumToInt(glyph_format), &g),
};
}
pub fn copy(self: Glyph) Error!Glyph {
var g: c.FT_Glyph = undefined;
try intToError(c.FT_Glyph_Copy(self.handle, &g));
return Glyph{ .handle = g };
}
pub fn copy(self: Glyph) Error!Glyph {
var g: c.FT_Glyph = undefined;
try intToError(c.FT_Glyph_Copy(self.handle, &g));
return Glyph{ .handle = g };
}
pub fn transform(self: Glyph, matrix: ?Matrix, delta: ?Vector) Error!void {
try intToError(c.FT_Glyph_Transform(self.handle, if (matrix) |m| &m else null, if (delta) |d| &d else null));
}
pub fn transform(self: Glyph, matrix: ?Matrix, delta: ?Vector) Error!void {
try intToError(c.FT_Glyph_Transform(self.handle, if (matrix) |m| &m else null, if (delta) |d| &d else null));
}
pub fn getCBox(self: Glyph, bbox_mode: BBoxMode) BBox {
var b: BBox = undefined;
c.FT_Glyph_Get_CBox(self.handle, @enumToInt(bbox_mode), &b);
return b;
}
pub fn getCBox(self: Glyph, bbox_mode: BBoxMode) BBox {
var b: BBox = undefined;
c.FT_Glyph_Get_CBox(self.handle, @enumToInt(bbox_mode), &b);
return b;
}
pub fn toBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph {
try intToError(c.FT_Glyph_To_Bitmap(&self.handle, @enumToInt(render_mode), if (origin) |o| &o else null, 1));
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) };
}
pub fn toBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph {
try intToError(c.FT_Glyph_To_Bitmap(&self.handle, @enumToInt(render_mode), if (origin) |o| &o else null, 1));
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) };
}
pub fn copyBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph {
try intToError(c.FT_Glyph_To_Bitmap(&self.handle, @enumToInt(render_mode), if (origin) |o| &o else null, 0));
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) };
}
pub fn copyBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph {
try intToError(c.FT_Glyph_To_Bitmap(&self.handle, @enumToInt(render_mode), if (origin) |o| &o else null, 0));
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) };
}
pub fn castBitmapGlyph(self: Glyph) Error!BitmapGlyph {
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) };
}
pub fn castBitmapGlyph(self: Glyph) Error!BitmapGlyph {
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) };
}
pub fn castOutlineGlyph(self: Glyph) Error!OutlineGlyph {
return OutlineGlyph{ .handle = @ptrCast(c.FT_OutlineGlyph, self.handle) };
}
pub fn castOutlineGlyph(self: Glyph) Error!OutlineGlyph {
return OutlineGlyph{ .handle = @ptrCast(c.FT_OutlineGlyph, self.handle) };
}
pub fn castSvgGlyph(self: Glyph) Error!SvgGlyph {
return SvgGlyph{ .handle = @ptrCast(c.FT_SvgGlyph, self.handle) };
}
pub fn castSvgGlyph(self: Glyph) Error!SvgGlyph {
return SvgGlyph{ .handle = @ptrCast(c.FT_SvgGlyph, self.handle) };
}
pub fn stroke(self: *Glyph, stroker: Stroker) Error!void {
try intToError(c.FT_Glyph_Stroke(&self.handle, stroker.handle, 0));
}
pub fn stroke(self: *Glyph, stroker: Stroker) Error!void {
try intToError(c.FT_Glyph_Stroke(&self.handle, stroker.handle, 0));
}
pub fn strokeBorder(self: *Glyph, stroker: Stroker, inside: bool) Error!void {
try intToError(c.FT_Glyph_StrokeBorder(&self.handle, stroker.handle, if (inside) 1 else 0, 0));
}
pub fn strokeBorder(self: *Glyph, stroker: Stroker, inside: bool) Error!void {
try intToError(c.FT_Glyph_StrokeBorder(&self.handle, stroker.handle, if (inside) 1 else 0, 0));
}
pub fn format(self: Glyph) GlyphFormat {
return @intToEnum(GlyphFormat, self.handle.*.format);
}
pub fn format(self: Glyph) GlyphFormat {
return @intToEnum(GlyphFormat, self.handle.*.format);
}
pub fn advanceX(self: Glyph) isize {
return self.handle.*.advance.x;
}
pub fn advanceX(self: Glyph) isize {
return self.handle.*.advance.x;
}
pub fn advanceY(self: Glyph) isize {
return self.handle.*.advance.y;
}
pub fn advanceY(self: Glyph) isize {
return self.handle.*.advance.y;
}
};
const SvgGlyph = struct {
handle: c.FT_SvgGlyph,

View file

@ -1,22 +1,22 @@
pub usingnamespace @import("freetype.zig");
pub usingnamespace @import("types.zig");
pub usingnamespace @import("image.zig");
pub usingnamespace @import("color.zig");
pub usingnamespace @import("freetype.zig");
pub usingnamespace @import("glyph.zig");
pub usingnamespace @import("image.zig");
pub usingnamespace @import("lcdfilter.zig");
pub usingnamespace @import("stroke.zig");
pub usingnamespace @import("types.zig");
pub const c = @import("c");
pub const Glyph = @import("Glyph.zig");
pub const Stroker = @import("Stroker.zig");
pub const Error = @import("error.zig").Error;
const std = @import("std");
test {
std.testing.refAllDeclsRecursive(@import("freetype.zig"));
std.testing.refAllDeclsRecursive(@import("types.zig"));
std.testing.refAllDeclsRecursive(@import("image.zig"));
std.testing.refAllDeclsRecursive(@import("color.zig"));
std.testing.refAllDeclsRecursive(@import("lcdfilter.zig"));
std.testing.refAllDeclsRecursive(@import("error.zig"));
std.testing.refAllDeclsRecursive(Glyph);
std.testing.refAllDeclsRecursive(Stroker);
std.testing.refAllDeclsRecursive(@import("freetype.zig"));
std.testing.refAllDeclsRecursive(@import("glyph.zig"));
std.testing.refAllDeclsRecursive(@import("image.zig"));
std.testing.refAllDeclsRecursive(@import("lcdfilter.zig"));
std.testing.refAllDeclsRecursive(@import("stroke.zig"));
std.testing.refAllDeclsRecursive(@import("types.zig"));
}

View file

@ -1,7 +1,5 @@
const c = @import("c");
const Stroker = @This();
pub const LineCap = enum(u2) {
butt = c.FT_STROKER_LINECAP_BUTT,
round = c.FT_STROKER_LINECAP_ROUND,
@ -15,12 +13,14 @@ pub const LineJoin = enum(u2) {
miter_fixed = c.FT_STROKER_LINEJOIN_MITER_FIXED,
};
handle: c.FT_Stroker,
pub const Stroker = struct {
handle: c.FT_Stroker,
pub fn set(self: Stroker, radius: i32, line_cap: LineCap, line_join: LineJoin, miter_limit: i32) void {
c.FT_Stroker_Set(self.handle, radius, @enumToInt(line_cap), @enumToInt(line_join), miter_limit);
}
pub fn set(self: Stroker, radius: i32, line_cap: LineCap, line_join: LineJoin, miter_limit: i32) void {
c.FT_Stroker_Set(self.handle, radius, @enumToInt(line_cap), @enumToInt(line_join), miter_limit);
}
pub fn deinit(self: Stroker) void {
c.FT_Stroker_Done(self.handle);
}
pub fn deinit(self: Stroker) void {
c.FT_Stroker_Done(self.handle);
}
};