TiTanF
High-Performance, Zero-Dependency TrueType Font Rasterizer
Overview
TiTanF is a production-grade TrueType font rasterizer implemented entirely in Rust without any external dependencies (libc, freetype, etc.). It was engineered to explore high-performance vector graphics rendering techniques suitable for embedded systems and OS development.
The library features a hand-written parser for the TrueType format, a robust geometry processing pipeline, and a custom anti-aliased rasterizer accelerated by SIMD instructions (SSE2 on x86_64, NEON on AArch64).
Key Features
- SIMD Accelerated: Leveraging hand-written intrinsics for
x86_64(SSE2) andaarch64(NEON) to optimize the pixel coverage accumulation stage. - Zero Dependencies: A strictly dependency-free library. No C bindings, no system libraries—just pure Rust.
- Embedded Ready: Fully
no_stdcompatible (requiresalloc), making it ideal for kernels, bootloaders, and embedded graphical interfaces. - Memory Safe: Utilizes safe Rust for 99% of the codebase, with
unsafelimited strictly to SIMD optimizations. - Robust Parsing: Zero-copy parsing of complex TrueType tables (
glyf,cmap(Format 0, 4, 6, 12),kern,hmtx, etc.).
Architecture
The rendering pipeline is architected into three distinct stages to maximize modularity and performance:
- Parsing (
src/tables): Raw binary data is parsed into strongly-typed Rust structures. Complex tables likeglyf(glyph data) are lazy-loaded to minimize initial memory footprint. - Geometry (
src/geometry):- Contour Extraction: Bezier curves (quadratic) are extracted from the glyph data.
- ** flattening:** Curves are recursively subdivided into monotonic line segments for rasterization.
- Rasterization (
src/rasterizer):- Analytic Area: Uses an analytic coverage-based anti-aliasing algorithm (DDA) to calculate exact pixel coverage.
- Accumulation: A SIMD-optimized parallel prefix sum converts edge deltas into the final alpha map.
Quick Start
Add this to your Cargo.toml:
[]
= "2.1.0"
Rendering a Character:
use TrueTypeFont;
Performance
Benchmarks performed on an AMD Ryzen 9 5900X rendering 1,000 characters (Mixed CJK & Latin).
| Font Size | TiTanF | RustType | ab_glyph | Fontdue |
|---|---|---|---|---|
| 12px | 18.4 ms | 18.6 ms | 16.9 ms | 4.8 ms |
| 72px | 51.5 ms | 54.8 ms | 51.9 ms | 24.0 ms |
| 120px | 86.4 ms | 99.5 ms | 98.0 ms | 51.2 ms |
| 250px | 244.0 ms | 304.1 ms | 296.0 ms | 165.2 ms |
License
Distributed under the MIT license.