Crate sdf_glyph_renderer[][src]

Expand description

This crate is a Rust implementation of the signed distance field generation techniques demonstrated by Valve and Mapbox. The generic interface works with any bitmap, and a high level interface enables easy operation with FreeType faces when the optional freetype feature is enabled.

The approach taken by this crate is similar to TinySDF; it works from a raster bitmap rather than directly from vector outlines. This keeps the crate simple and allows it to be used generically with any bitmap. The SDF is calculated using the same algorithm described in this paper by Felzenszwalb & Huttenlocher.

Rather than re-invent the rasterisation process for fonts, this crate relies on FreeType to generate the bitmap. This is quite fast (we’re talking µs/glyph), and the results are almost always indistinguishable from the more sophisticated vector-based approach of sdf-glyph-foundry.

This crate is used by pbf_font_tools to generate SDF glyphs from any FreeType-readable font. If you’re looking for a batch generation tool, check out build_pbf_glyphs.


A raw bitmap containing only the alpha channel.



Compresses a Vec into a Vec for efficiency.

Render a signed distance field for the given bitmap, recording distances out to radius pixels from the shape outline (the rest will be clamped). The range of the output field is [-1.0, 1.0], normalised to units of radius.