23 releases (6 breaking)
|0.7.1||Sep 7, 2018|
|0.6.5||Aug 24, 2018|
|0.6.2||Jun 20, 2018|
|0.5.2||Mar 21, 2018|
|0.2.0||Mar 19, 2016|
#2 in Rendering
9,754 downloads per month
Used in 171 crates (44 directly)
RustType is a pure Rust alternative to libraries like FreeType.
The current capabilities of RustType:
- Reading TrueType formatted fonts and font collections. This includes
*.ttfas well as a subset of
- 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_cachemodule. 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:
- OpenType formatted fonts that are not just TrueType fonts (OpenType is a superset of TrueType). Notably there is no support yet for cubic Bezier curves used in glyphs.
- Font hinting.
- Ligatures of any kind
- Some less common TrueType sub-formats.
- Right-to-left and vertical text layout.
To hit the ground running with RustType, look at the
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
FontCollection, from which you can access individual fonts, then their glyphs.
The initial motivation for the project was to provide easy-to-use font rendering for games. There are numerous avenues for improving RustType. Ideas:
- Some form of hinting for improved legibility at small font sizes.
- Replacing the dependency on stb_truetype-rs (a translation of stb_truetype.h), with OpenType font loading written in idiomatic Rust.
- Add support for cubic curves in OpenType fonts.
- Extract the rasterisation code into a separate vector graphics rendering crate.
- 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.
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.
- glyph_brush - can cache vertex generation & provides more complex layouts.
- approx 0.3
- arrayvec 0.4
- ordered-float 1.0
- stb_truetype 0.2.2
- gpu_cache? crossbeam-deque 0.6
- gpu_cache? crossbeam-utils 0.6
- gpu_cache? linked-hash-map 0.5
- gpu_cache? num_cpus 1.0
- gpu_cache? rustc-hash 1.0