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,11 +1,16 @@
|
|||
const std = @import("std");
|
||||
const c = @import("c.zig");
|
||||
const types = @import("types.zig");
|
||||
const Glyph = @import("Glyph.zig");
|
||||
const Outline = @import("Outline.zig");
|
||||
const Bitmap = @import("Bitmap.zig");
|
||||
const Error = @import("error.zig").Error;
|
||||
const intToError = @import("error.zig").intToError;
|
||||
const Error = @import("error.zig").Error;
|
||||
const Glyph = @import("Glyph.zig");
|
||||
const Library = @import("freetype.zig").Library;
|
||||
const Face = @import("freetype.zig").Face;
|
||||
const RenderMode = @import("freetype.zig").RenderMode;
|
||||
const Matrix = @import("types.zig").Matrix;
|
||||
const Outline = @import("image.zig").Outline;
|
||||
const GlyphFormat = @import("image.zig").GlyphFormat;
|
||||
const Vector = @import("image.zig").Vector;
|
||||
const GlyphMetrics = @import("image.zig").GlyphMetrics;
|
||||
const Bitmap = @import("image.zig").Bitmap;
|
||||
|
||||
const GlyphSlot = @This();
|
||||
|
||||
|
|
@ -14,40 +19,49 @@ pub const SubGlyphInfo = struct {
|
|||
flags: u32,
|
||||
arg1: i32,
|
||||
arg2: i32,
|
||||
transform: types.Matrix,
|
||||
transform: Matrix,
|
||||
};
|
||||
|
||||
handle: c.FT_GlyphSlot,
|
||||
|
||||
pub fn init(handle: c.FT_GlyphSlot) GlyphSlot {
|
||||
return GlyphSlot{ .handle = handle };
|
||||
pub fn library(self: GlyphSlot) Library {
|
||||
return .{ .handle = self.handle.*.library };
|
||||
}
|
||||
|
||||
pub fn render(self: GlyphSlot, render_mode: types.RenderMode) Error!void {
|
||||
return intToError(c.FT_Render_Glyph(self.handle, @enumToInt(render_mode)));
|
||||
pub fn face(self: GlyphSlot) Face {
|
||||
return .{ .handle = self.handle.*.face };
|
||||
}
|
||||
|
||||
pub fn subGlyphInfo(self: GlyphSlot, sub_index: u32) Error!SubGlyphInfo {
|
||||
var info = std.mem.zeroes(SubGlyphInfo);
|
||||
try intToError(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;
|
||||
pub fn next(self: GlyphSlot) GlyphSlot {
|
||||
return .{ .handle = self.handle.*.next };
|
||||
}
|
||||
|
||||
pub fn glyph(self: GlyphSlot) Error!Glyph {
|
||||
var out = std.mem.zeroes(c.FT_Glyph);
|
||||
try intToError(c.FT_Get_Glyph(self.handle, &out));
|
||||
return Glyph.init(out);
|
||||
pub fn glyphIndex(self: GlyphSlot) u32 {
|
||||
return self.handle.*.glyph_index;
|
||||
}
|
||||
|
||||
pub fn outline(self: GlyphSlot) ?Outline {
|
||||
return if (self.format() == .outline)
|
||||
Outline.init(&self.handle.*.outline)
|
||||
else
|
||||
null;
|
||||
pub fn metrics(self: GlyphSlot) GlyphMetrics {
|
||||
return self.handle.*.metrics;
|
||||
}
|
||||
|
||||
pub fn linearHoriAdvance(self: GlyphSlot) i32 {
|
||||
return @intCast(i32, self.handle.*.linearHoriAdvance);
|
||||
}
|
||||
|
||||
pub fn linearVertAdvance(self: GlyphSlot) i32 {
|
||||
return @intCast(i32, self.handle.*.linearVertAdvance);
|
||||
}
|
||||
|
||||
pub fn advance(self: GlyphSlot) Vector {
|
||||
return self.handle.*.advance;
|
||||
}
|
||||
|
||||
pub fn format(self: GlyphSlot) GlyphFormat {
|
||||
return @intToEnum(GlyphFormat, self.handle.*.format);
|
||||
}
|
||||
|
||||
pub fn bitmap(self: GlyphSlot) Bitmap {
|
||||
return Bitmap.init(self.handle.*.bitmap);
|
||||
return .{ .handle = self.handle.*.bitmap };
|
||||
}
|
||||
|
||||
pub fn bitmapLeft(self: GlyphSlot) i32 {
|
||||
|
|
@ -58,22 +72,30 @@ pub fn bitmapTop(self: GlyphSlot) i32 {
|
|||
return self.handle.*.bitmap_top;
|
||||
}
|
||||
|
||||
pub fn linearHoriAdvance(self: GlyphSlot) i64 {
|
||||
return self.handle.*.linearHoriAdvance;
|
||||
pub fn outline(self: GlyphSlot) ?Outline {
|
||||
return if (self.format() == .outline) .{ .handle = &self.handle.*.outline } else null;
|
||||
}
|
||||
|
||||
pub fn linearVertAdvance(self: GlyphSlot) i64 {
|
||||
return self.handle.*.linearVertAdvance;
|
||||
pub fn lsbDelta(self: GlyphSlot) i32 {
|
||||
return @intCast(i32, self.handle.*.lsb_delta);
|
||||
}
|
||||
|
||||
pub fn advance(self: GlyphSlot) types.Vector {
|
||||
return @ptrCast(*types.Vector, &self.handle.*.advance).*;
|
||||
pub fn rsbDelta(self: GlyphSlot) i32 {
|
||||
return @intCast(i32, self.handle.*.rsb_delta);
|
||||
}
|
||||
|
||||
pub fn format(self: GlyphSlot) Glyph.GlyphFormat {
|
||||
return @intToEnum(Glyph.GlyphFormat, self.handle.*.format);
|
||||
pub fn render(self: GlyphSlot, render_mode: RenderMode) Error!void {
|
||||
return intToError(c.FT_Render_Glyph(self.handle, @enumToInt(render_mode)));
|
||||
}
|
||||
|
||||
pub fn metrics(self: GlyphSlot) Glyph.GlyphMetrics {
|
||||
return self.handle.*.metrics;
|
||||
pub fn subGlyphInfo(self: GlyphSlot, sub_index: u32) Error!SubGlyphInfo {
|
||||
var info: SubGlyphInfo = undefined;
|
||||
try intToError(c.FT_Get_SubGlyph_Info(self.handle, sub_index, &info.index, &info.flags, &info.arg1, &info.arg2, &info.transform));
|
||||
return info;
|
||||
}
|
||||
|
||||
pub fn getGlyph(self: GlyphSlot) Error!Glyph {
|
||||
var res: c.FT_Glyph = undefined;
|
||||
try intToError(c.FT_Get_Glyph(self.handle, &res));
|
||||
return Glyph{ .handle = res };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue