From dc832997e49a5b90b7bd1344063c560702432603 Mon Sep 17 00:00:00 2001 From: alichraghi Date: Mon, 18 Jul 2022 15:48:46 +0430 Subject: [PATCH] freetype: fix import structure --- freetype/src/freetype/GlyphSlot.zig | 2 +- freetype/src/freetype/Library.zig | 2 +- .../src/freetype/{Glyph.zig => glyph.zig} | 116 +++++++++--------- freetype/src/freetype/main.zig | 22 ++-- .../src/freetype/{Stroker.zig => stroke.zig} | 18 +-- 5 files changed, 80 insertions(+), 80 deletions(-) rename freetype/src/freetype/{Glyph.zig => glyph.zig} (50%) rename freetype/src/freetype/{Stroker.zig => stroke.zig} (53%) diff --git a/freetype/src/freetype/GlyphSlot.zig b/freetype/src/freetype/GlyphSlot.zig index 043e6f2c..4e64a8ed 100644 --- a/freetype/src/freetype/GlyphSlot.zig +++ b/freetype/src/freetype/GlyphSlot.zig @@ -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; diff --git a/freetype/src/freetype/Library.zig b/freetype/src/freetype/Library.zig index 463587d6..2ff65b0d 100644 --- a/freetype/src/freetype/Library.zig +++ b/freetype/src/freetype/Library.zig @@ -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; diff --git a/freetype/src/freetype/Glyph.zig b/freetype/src/freetype/glyph.zig similarity index 50% rename from freetype/src/freetype/Glyph.zig rename to freetype/src/freetype/glyph.zig index 9bacc92d..14b5dbb5 100644 --- a/freetype/src/freetype/Glyph.zig +++ b/freetype/src/freetype/glyph.zig @@ -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, diff --git a/freetype/src/freetype/main.zig b/freetype/src/freetype/main.zig index 3c0c8bff..46518cd4 100644 --- a/freetype/src/freetype/main.zig +++ b/freetype/src/freetype/main.zig @@ -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")); } diff --git a/freetype/src/freetype/Stroker.zig b/freetype/src/freetype/stroke.zig similarity index 53% rename from freetype/src/freetype/Stroker.zig rename to freetype/src/freetype/stroke.zig index 3c761b82..86fd8dcb 100644 --- a/freetype/src/freetype/Stroker.zig +++ b/freetype/src/freetype/stroke.zig @@ -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); + } +};