PaNDa2code/zig_freetype2
Minimal Zig wrapper around FreeType2
zig_freetype2 is a minimal Zig wrapper around FreeType2, designed to make integrating FreeType into Zig projects easier.
Use zig fetch
to add the module to your project:
zig fetch --save git+https://github.com/PaNDa2code/zig_freetype2
In your build.zig
file:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const freetype = b.dependency("zig_freetype2", .{});
const freetype_mod = freetype.module("zig_freetype2");
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_mod.addImport("freetype", freetype_mod);
const exe = b.addExecutable(.{
.name = "my_project",
.root_module = exe_mod,
.linkage = if (target.result.abi == .musl) .static else .dynamic,
});
b.installArtifact(exe);
}
Example:
const std = @import("std");
const freetype = @import("freetype");
pub fn main() !void {
const gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer gpa.deinit();
const library = try freetype.Library.init(allocator);
defer library.deinit();
const face = try library.face("arial.ttf");
defer face.deinit();
const glyph = try face.getGlyph('A');
defer glyph.deinit();
}
This project is currently incomplete and depends on libc.
The long-term goal is to remove the libc dependency entirely and support more platforms.