freetype: fix import structure
This commit is contained in:
parent
4e624c5381
commit
dc832997e4
5 changed files with 80 additions and 80 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
const c = @import("c");
|
const c = @import("c");
|
||||||
const intToError = @import("error.zig").intToError;
|
const intToError = @import("error.zig").intToError;
|
||||||
const Error = @import("error.zig").Error;
|
const Error = @import("error.zig").Error;
|
||||||
const Glyph = @import("Glyph.zig");
|
const Glyph = @import("glyph.zig").Glyph;
|
||||||
const Library = @import("freetype.zig").Library;
|
const Library = @import("freetype.zig").Library;
|
||||||
const Face = @import("freetype.zig").Face;
|
const Face = @import("freetype.zig").Face;
|
||||||
const RenderMode = @import("freetype.zig").RenderMode;
|
const RenderMode = @import("freetype.zig").RenderMode;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ const std = @import("std");
|
||||||
const c = @import("c");
|
const c = @import("c");
|
||||||
const intToError = @import("error.zig").intToError;
|
const intToError = @import("error.zig").intToError;
|
||||||
const Error = @import("error.zig").Error;
|
const Error = @import("error.zig").Error;
|
||||||
const Stroker = @import("Stroker.zig");
|
const Stroker = @import("stroke.zig").Stroker;
|
||||||
const Face = @import("freetype.zig").Face;
|
const Face = @import("freetype.zig").Face;
|
||||||
const OpenArgs = @import("freetype.zig").OpenArgs;
|
const OpenArgs = @import("freetype.zig").OpenArgs;
|
||||||
const LcdFilter = @import("lcdfilter.zig").LcdFilter;
|
const LcdFilter = @import("lcdfilter.zig").LcdFilter;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ const std = @import("std");
|
||||||
const c = @import("c");
|
const c = @import("c");
|
||||||
const intToError = @import("error.zig").intToError;
|
const intToError = @import("error.zig").intToError;
|
||||||
const Error = @import("error.zig").Error;
|
const Error = @import("error.zig").Error;
|
||||||
const Stroker = @import("Stroker.zig");
|
const Stroker = @import("stroke.zig").Stroker;
|
||||||
const Library = @import("freetype.zig").Library;
|
const Library = @import("freetype.zig").Library;
|
||||||
const RenderMode = @import("freetype.zig").RenderMode;
|
const RenderMode = @import("freetype.zig").RenderMode;
|
||||||
const SizeMetrics = @import("freetype.zig").SizeMetrics;
|
const SizeMetrics = @import("freetype.zig").SizeMetrics;
|
||||||
|
|
@ -13,8 +13,6 @@ const GlyphFormat = @import("image.zig").GlyphFormat;
|
||||||
const Vector = @import("image.zig").Vector;
|
const Vector = @import("image.zig").Vector;
|
||||||
const Bitmap = @import("image.zig").Bitmap;
|
const Bitmap = @import("image.zig").Bitmap;
|
||||||
|
|
||||||
const Glyph = @This();
|
|
||||||
|
|
||||||
pub const BBoxMode = enum(u2) {
|
pub const BBoxMode = enum(u2) {
|
||||||
// https://freetype.org/freetype2/docs/reference/ft2-glyph_management.html#ft_glyph_bbox_mode
|
// https://freetype.org/freetype2/docs/reference/ft2-glyph_management.html#ft_glyph_bbox_mode
|
||||||
// both `unscaled` and `subpixel` are set to 0
|
// both `unscaled` and `subpixel` are set to 0
|
||||||
|
|
@ -24,76 +22,78 @@ pub const BBoxMode = enum(u2) {
|
||||||
pixels = c.FT_GLYPH_BBOX_PIXELS,
|
pixels = c.FT_GLYPH_BBOX_PIXELS,
|
||||||
};
|
};
|
||||||
|
|
||||||
handle: c.FT_Glyph,
|
pub const Glyph = struct {
|
||||||
|
handle: c.FT_Glyph,
|
||||||
|
|
||||||
pub fn deinit(self: Glyph) void {
|
pub fn deinit(self: Glyph) void {
|
||||||
c.FT_Done_Glyph(self.handle);
|
c.FT_Done_Glyph(self.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn newGlyph(library: Library, glyph_format: GlyphFormat) Glyph {
|
pub fn newGlyph(library: Library, glyph_format: GlyphFormat) Glyph {
|
||||||
var g: c.FT_Glyph = undefined;
|
var g: c.FT_Glyph = undefined;
|
||||||
return .{
|
return .{
|
||||||
.handle = c.FT_New_Glyph(library.handle, @enumToInt(glyph_format), &g),
|
.handle = c.FT_New_Glyph(library.handle, @enumToInt(glyph_format), &g),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy(self: Glyph) Error!Glyph {
|
pub fn copy(self: Glyph) Error!Glyph {
|
||||||
var g: c.FT_Glyph = undefined;
|
var g: c.FT_Glyph = undefined;
|
||||||
try intToError(c.FT_Glyph_Copy(self.handle, &g));
|
try intToError(c.FT_Glyph_Copy(self.handle, &g));
|
||||||
return Glyph{ .handle = g };
|
return Glyph{ .handle = g };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transform(self: Glyph, matrix: ?Matrix, delta: ?Vector) Error!void {
|
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));
|
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 {
|
pub fn getCBox(self: Glyph, bbox_mode: BBoxMode) BBox {
|
||||||
var b: BBox = undefined;
|
var b: BBox = undefined;
|
||||||
c.FT_Glyph_Get_CBox(self.handle, @enumToInt(bbox_mode), &b);
|
c.FT_Glyph_Get_CBox(self.handle, @enumToInt(bbox_mode), &b);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph {
|
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));
|
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) };
|
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copyBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph {
|
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));
|
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) };
|
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn castBitmapGlyph(self: Glyph) Error!BitmapGlyph {
|
pub fn castBitmapGlyph(self: Glyph) Error!BitmapGlyph {
|
||||||
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) };
|
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn castOutlineGlyph(self: Glyph) Error!OutlineGlyph {
|
pub fn castOutlineGlyph(self: Glyph) Error!OutlineGlyph {
|
||||||
return OutlineGlyph{ .handle = @ptrCast(c.FT_OutlineGlyph, self.handle) };
|
return OutlineGlyph{ .handle = @ptrCast(c.FT_OutlineGlyph, self.handle) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn castSvgGlyph(self: Glyph) Error!SvgGlyph {
|
pub fn castSvgGlyph(self: Glyph) Error!SvgGlyph {
|
||||||
return SvgGlyph{ .handle = @ptrCast(c.FT_SvgGlyph, self.handle) };
|
return SvgGlyph{ .handle = @ptrCast(c.FT_SvgGlyph, self.handle) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stroke(self: *Glyph, stroker: Stroker) Error!void {
|
pub fn stroke(self: *Glyph, stroker: Stroker) Error!void {
|
||||||
try intToError(c.FT_Glyph_Stroke(&self.handle, stroker.handle, 0));
|
try intToError(c.FT_Glyph_Stroke(&self.handle, stroker.handle, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn strokeBorder(self: *Glyph, stroker: Stroker, inside: bool) Error!void {
|
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));
|
try intToError(c.FT_Glyph_StrokeBorder(&self.handle, stroker.handle, if (inside) 1 else 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format(self: Glyph) GlyphFormat {
|
pub fn format(self: Glyph) GlyphFormat {
|
||||||
return @intToEnum(GlyphFormat, self.handle.*.format);
|
return @intToEnum(GlyphFormat, self.handle.*.format);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn advanceX(self: Glyph) isize {
|
pub fn advanceX(self: Glyph) isize {
|
||||||
return self.handle.*.advance.x;
|
return self.handle.*.advance.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn advanceY(self: Glyph) isize {
|
pub fn advanceY(self: Glyph) isize {
|
||||||
return self.handle.*.advance.y;
|
return self.handle.*.advance.y;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const SvgGlyph = struct {
|
const SvgGlyph = struct {
|
||||||
handle: c.FT_SvgGlyph,
|
handle: c.FT_SvgGlyph,
|
||||||
|
|
@ -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("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("lcdfilter.zig");
|
||||||
|
pub usingnamespace @import("stroke.zig");
|
||||||
|
pub usingnamespace @import("types.zig");
|
||||||
pub const c = @import("c");
|
pub const c = @import("c");
|
||||||
pub const Glyph = @import("Glyph.zig");
|
|
||||||
pub const Stroker = @import("Stroker.zig");
|
|
||||||
pub const Error = @import("error.zig").Error;
|
pub const Error = @import("error.zig").Error;
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
test {
|
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("color.zig"));
|
||||||
std.testing.refAllDeclsRecursive(@import("lcdfilter.zig"));
|
|
||||||
std.testing.refAllDeclsRecursive(@import("error.zig"));
|
std.testing.refAllDeclsRecursive(@import("error.zig"));
|
||||||
std.testing.refAllDeclsRecursive(Glyph);
|
std.testing.refAllDeclsRecursive(@import("freetype.zig"));
|
||||||
std.testing.refAllDeclsRecursive(Stroker);
|
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"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
const c = @import("c");
|
const c = @import("c");
|
||||||
|
|
||||||
const Stroker = @This();
|
|
||||||
|
|
||||||
pub const LineCap = enum(u2) {
|
pub const LineCap = enum(u2) {
|
||||||
butt = c.FT_STROKER_LINECAP_BUTT,
|
butt = c.FT_STROKER_LINECAP_BUTT,
|
||||||
round = c.FT_STROKER_LINECAP_ROUND,
|
round = c.FT_STROKER_LINECAP_ROUND,
|
||||||
|
|
@ -15,12 +13,14 @@ pub const LineJoin = enum(u2) {
|
||||||
miter_fixed = c.FT_STROKER_LINEJOIN_MITER_FIXED,
|
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 {
|
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);
|
c.FT_Stroker_Set(self.handle, radius, @enumToInt(line_cap), @enumToInt(line_join), miter_limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: Stroker) void {
|
pub fn deinit(self: Stroker) void {
|
||||||
c.FT_Stroker_Done(self.handle);
|
c.FT_Stroker_Done(self.handle);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue