A signed distance field generator with support for Viktor Chlumský's MSDF technique.
A simple example can be found below, with a more in-depth one in example/generate.zig.
constGenerator=@import("mist");
constfont_data=@embedFile("OpenSans-Bold.ttf");
vargen: Generator=try .create(font_data);
defergen.destroy();
varseed: u64=undefined;
io.random(std.mem.asBytes(&seed));
constgen_opts: Generator.Options= .{
.sdf_type=.mtsdf,
.px_size=64,
.px_range=8,
.coloring_rng_seed=seed,
.validate_shape=true,
.normalize_shape=true,
.orient_contours=true,
};
for ([_]u21{ 'A', 'B', 'C' }) |codepoint| {
constdata=trygen.generateSingle(allocator, codepoint, &gen_opts);
deferdata.deinit(allocator);
varimage: stbi.Image=try .createEmpty(
data.glyph_data.width,
data.glyph_data.height,
gen_opts.sdf_type.numChannels(),
.{},
);
deferimage.deinit();
@memcpy(image.data, data.pixels);
varpath_buf: [64]u8=undefined;
constpath=trystd.fmt.bufPrintZ(&path_buf, "{u}_sdf.png", .{codepoint});
tryimage.writeToFile(path, .png);
}The library exposes a similar set of functionality to Chlumský's work, but it's not intended to be its equivalent, some features will be implemented differently and some will be intentionally omitted. Issues and PRs can still compare to msdfgen, like if the library generates a less correct SDF than it, but direct ports, or the request for them will be closed.