fontdue 0.1.1

A simple no_std font parser and rasterizer.


Documentation Documentation License

Fontdue is a simple, no_std, pure Rust, truetype font parser and rasterizer. It aims to support all valid (unicode encoded) TrueType fonts correctly, and strives to make interacting with fonts as fast as possible. This includes: layout and rasterization.

A non-goal of this library is to be allocation free and have a fast, "zero cost" initial load. This library does make allocations and depends on the alloc crate. Fonts are fully parsed on creation and relevant information is stored in a more convenient to access format. Unlike other font libraries, the font structures have no lifetime dependencies since it allocates its own space.

Ideally, font loading should be faster in the future, but making the loading process correct and readable was the initial priority.

Important Notices


Please bear with me on new features or quirks that you find. I will definitely get to issues you open (also thank you for opening them), but I don't have as much time as I would like to work on fontdue so please be paitent, this is a mostly solo project <3.

Reusing Fontdue code

Please don't reuse Fontdue's raster code directly in your project. Fontdue uses unsafe code in the rasterizer, and the rasterizer itself is very not safe to use on its own with un-sanitized input.

If you're looking to reuse that code in your project (with the appropriate licensing and attribution), please be aware of the effort that went into making it safe. Fontdue itself does not expose the raw raster in its API because it performs the necessary sanitization to use it safely for you, and has been fuzzed for bugs in the process.

TrueType Table Support

  • cmap Character to glyph mapping (Unicode only)
    • Supported formats: 0, 4, 6, 10, 12, 13
    • Unsupported formats: 2, 8, 14
  • glyf Glyph outlining
    • Unsupported features: Compound glyph matched points, compound glyph scaled offset
  • head General font information
  • hhea General horizontal layout (Optional)
  • hmtx Glyph horizontal layout (Optional)
  • vhea General vertical layout (Optional)
  • vmtx Glyph vertical layout (Optional)
  • loca Glyph outline offsets and lengths
  • maxp Maximum values used for the font
  • kern Kerning pair layout (Optional)
    • Supported formats: 0
    • Unsupported formats: 1, 2, 3


// Read the font data.
let font = include_bytes!("../resources/Roboto-Regular.ttf") as &[u8];
// Parse it into the font type.
let mut font = fontdue::Font::from_bytes(font).unwrap();
// Rasterize and get the layout metrics for the letter 'g' at 17px.
let (metrics, bitmap) = font.rasterize('g', 17.0);


Strives to be the fastest.


Here are some benchmarks. They generate the layout metrics and bitmap for the letter 'g' are different sizes. This is going straight from the character 'g' to the metrics and bitmap, which is how the majority of people will interact with a font library and is the expected real world performance.

Fontdue: Metrics + Rasterize 'g'/20  time:   [993.07 ns 995.05 ns 997.21 ns]
Fontdue: Metrics + Rasterize 'g'/40  time:   [1.4955 us 1.4969 us 1.4987 us]
Fontdue: Metrics + Rasterize 'g'/60  time:   [2.1639 us 2.1653 us 2.1672 us]
Fontdue: Metrics + Rasterize 'g'/80  time:   [3.0232 us 3.0256 us 3.0284 us]


Other popular font library.

RustType: Metrics + Rasterize 'g'/20 time:   [11.701 us 11.719 us 11.738 us]
RustType: Metrics + Rasterize 'g'/40 time:   [18.993 us 19.036 us 19.081 us]
RustType: Metrics + Rasterize 'g'/60 time:   [27.106 us 27.188 us 27.276 us]
RustType: Metrics + Rasterize 'g'/80 time:   [37.033 us 37.177 us 37.335 us]


Fontdue started as a slightly more production ready wrapper around font-rs because of how fast it made rasterization look (link), and how simple the wonderful rusttype crate made font parsing look (link). Since then, I've done a few rewrites on the raster and it no longer shares any code or methodology to font-rs, but I feel like it still deservers some attribution. Instead of attempting to find the converage of a pixel, fontdue performs pseudo ray tracing collision detection on the geometry of the glyph with the pixel grid and estimates the shading.