Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable using OT SVG in FreeType #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const use_system_zlib = b.option(bool, "use_system_zlib", "Use system zlib") orelse false;
const enable_brotli = b.option(bool, "enable_brotli", "Build brotli") orelse true;
const enable_ot_svg = b.option(bool, "enable_ot_svg", "enable OpenType SVG") orelse false;

const build_options = b.addOptions();
build_options.addOption(bool, "enable_ot_svg", enable_ot_svg);

const freetype_module = b.addModule("mach-freetype", .{
.root_source_file = b.path("src/freetype.zig"),
Expand All @@ -13,6 +17,7 @@ pub fn build(b: *std.Build) !void {
.root_source_file = b.path("src/harfbuzz.zig"),
.imports = &.{.{ .name = "freetype", .module = freetype_module }},
});
freetype_module.addImport("build-options", build_options.createModule());

const freetype_tests = b.addTest(.{
.name = "freetype-tests",
Expand Down
12 changes: 12 additions & 0 deletions src/freetype.zig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const build_options = @import("build-options");

pub const c = @cImport({
@cInclude("freetype/ftadvanc.h");
@cInclude("freetype/ftbbox.h");
Expand All @@ -8,6 +10,10 @@ pub const c = @cImport({
@cInclude("freetype/ftstroke.h");
@cInclude("freetype/fttrigon.h");
@cInclude("freetype/ftsynth.h");
@cInclude("freetype/ftmodapi.h");
if (build_options.enable_ot_svg) {
@cInclude("freetype/otsvg.h");
}
});

pub const Affine23 = c.FT_Affine23;
Expand Down Expand Up @@ -1044,6 +1050,10 @@ pub const Library = struct {
pub fn setLcdFilter(self: Library, lcd_filter: LcdFilter) Error!void {
return intToError(c.FT_Library_SetLcdFilter(self.handle, @intFromEnum(lcd_filter)));
}

pub fn setProperty(self: Library, module_name: [*c]const u8, property_name: [*c]const u8, value: *const anyopaque) Error!void {
return intToError(c.FT_Property_Set(self.handle, module_name, property_name, value));
}
};

pub const OpenArgs = struct {
Expand Down Expand Up @@ -1567,6 +1577,7 @@ pub const Error = error{
BbxTooBig,
CorruptedFontHeader,
CorruptedFontGlyphs,
MissingSVGHooks,
};

pub fn intToError(err: c_int) Error!void {
Expand Down Expand Up @@ -1661,6 +1672,7 @@ pub fn intToError(err: c_int) Error!void {
c.FT_Err_Bbx_Too_Big => Error.BbxTooBig,
c.FT_Err_Corrupted_Font_Header => Error.CorruptedFontHeader,
c.FT_Err_Corrupted_Font_Glyphs => Error.CorruptedFontGlyphs,
c.FT_Err_Missing_SVG_Hooks => Error.MissingSVGHooks,
else => unreachable,
};
}
Expand Down