#true-type #opentype #font-rendering #otf #font #text-rendering

unmaintained no-std rusttype

A pure Rust alternative to libraries like FreeType. RustType provides an API for loading, querying and rasterising TrueType fonts. It also provides an implementation of a dynamic GPU glyph cache for hardware font rendering

38 releases

0.9.3 Nov 2, 2022
0.9.2 May 23, 2020
0.9.1 Apr 25, 2020
0.8.2 Nov 23, 2019
0.2.0 Mar 19, 2016

#715 in Graphics APIs

Download history 26405/week @ 2024-07-21 22746/week @ 2024-07-28 22484/week @ 2024-08-04 43728/week @ 2024-08-11 32722/week @ 2024-08-18 45915/week @ 2024-08-25 31697/week @ 2024-09-01 34546/week @ 2024-09-08 29805/week @ 2024-09-15 36200/week @ 2024-09-22 48623/week @ 2024-09-29 15946/week @ 2024-10-06 41941/week @ 2024-10-13 30002/week @ 2024-10-20 40681/week @ 2024-10-27 18515/week @ 2024-11-03

131,623 downloads per month
Used in 701 crates (181 directly)

MIT/Apache

92KB
1.5K SLoC

RustType

crates.io docs.rs

RustType is a pure Rust alternative to libraries like FreeType.

The current capabilities of RustType:

  • Reading OpenType formatted fonts and font collections. This includes *.ttf as well as *.otf font files.
  • Retrieving glyph shapes and commonly used properties for a font and its glyphs.
  • Laying out glyphs horizontally using horizontal and vertical metrics, and glyph-pair-specific kerning.
  • Rasterising glyphs with sub-pixel positioning using an accurate analytical algorithm (not based on sampling).
  • Managing a font cache on the GPU with the gpu_cache module. This keeps recently used glyph renderings in a dynamic cache in GPU memory to minimise texture uploads per-frame. It also allows you keep the draw call count for text very low, as all glyphs are kept in one GPU texture.

Notable things that RustType does not support yet:

  • Font hinting.
  • Ligatures of any kind.
  • Some less common TrueType sub-formats.
  • Right-to-left and vertical text layout.

Testing & examples

Heavier examples, tests & benchmarks are in the ./dev directory. This avoids dev-dependency feature bleed.

Run all tests with cargo test --all --all-features.

Run examples with cargo run --example <NAME> -p dev

Getting Started

To hit the ground running with RustType, look at dev/examples/ascii.rs supplied with the crate. It demonstrates loading a font file, rasterising an arbitrary string, and displaying the result as ASCII art. If you prefer to just look at the documentation, the entry point for loading fonts is Font, from which you can access individual fonts, then their glyphs.

Future Plans

The initial motivation for the project was to provide easy-to-use font rendering for games. There are numerous avenues for improving RustType. Ideas:

  • Support for some common forms of ligatures.
  • And, eventually, support for embedded right-to-left Unicode text.

If you think you could help with achieving any of these goals, feel free to open a tracking issue for discussing them.

Minimum supported rust compiler

This crate is maintained with latest stable rust.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

See Also

  • glyph_brush - can cache vertex generation & provides more complex layouts.

Dependencies

~1MB
~23K SLoC