Skip to content

Commit

Permalink
Enable using OT SVG in FreeType
Browse files Browse the repository at this point in the history
  • Loading branch information
tchayen committed Sep 2, 2024
1 parent 86fc802 commit 8bd5600
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit 8bd5600

Please sign in to comment.