TiTanF
High-Performance TrueType Font Rasterizer
Pure Rust • SIMD Accelerated • Zero Dependencies • no_std Ready
Overview
TiTanF is a production-ready, zero-dependency TrueType font rasterizer written entirely in Rust. It was developed to investigate efficient vector graphics rendering techniques without relying on external libraries like FreeType.
It features a custom-built parser, a robust geometry processing pipeline, and a SIMD-optimized anti-aliased rasterizer.
Features
- ⚡ SIMD Accelerated — Hand-written SIMD intrinsics (SSE2/AVX2 for x86_64, NEON for AArch64) for the rasterization stage.
- 🦀 Zero Dependencies — No
libc, no external crates. Just pure Rust. - 📦
no_stdSupport — Designed for embedded systems and bare-metal environments (requiresalloc). - 🛡️ Safe — Minimal
unsafecode (isolated to SIMD intrinsics), leveraging the borrow checker for memory safety. - 🔧 Comprehensive Parsing — Supports
cmap(Format 4/12),glyf,head,hhea,hmtx,kern,loca, andmaxptables.
Architecture
The rendering pipeline is divided into three distinct stages:
- Parsing (
src/tables): The raw TrueType binary is parsed into zero-copy structures where possible. Complex tables likeglyfare lazily evaluated. - Geometry Processing (
src/geometry):- Points: Glyph contours are extracted and transformed (scaled/translated).
- Lines: Bezier curves are flattened into line segments using recursive subdivision for sub-pixel accuracy.
- Rasterization (
src/rasterizer):- DDA: An analytic coverage-based anti-aliasing approach (similar to FreeType's smooth rasterizer).
- Accumulation: The coverage buffer is converted to a bitmap using a parallel prefix sum algorithm optimized with SIMD.
Quick Start
use TrueTypeFont;
Performance
Benchmarks were conducted rendering 1,000 characters (mixed CJK and Latin) at various font sizes.
TiTanF demonstrates superior scaling characteristics compared to standard libraries like rusttype and ab_glyph, particularly at larger font sizes where the SIMD optimizations significantly reduce the overhead of pixel coverage calculations.
| Size (1k chars) | TiTanF | RustType | ab_glyph | Fontdue |
|---|---|---|---|---|
| 12pt | 18.4 ms | 18.6 ms | 16.9 ms | 4.8 ms |
| 72pt | 51.5 ms | 54.8 ms | 51.9 ms | 24.0 ms |
| 120pt | 86.4 ms | 99.5 ms | 98.0 ms | 51.2 ms |
| 250pt | 244.0 ms | 304.1 ms | 296.0 ms | 165.2 ms |
Comparison Analysis:
- Scaling: While
rusttypeandab_glyphdegrade linearly or worse at large sizes, TiTanF maintains better performance, running ~20% faster than the competition at 250pt. - Efficiency: The rasterizer is highly optimized for large coverage areas, making it ideal for UI rendering at high DPIs.
(Note: fontdue uses a different, highly specialized rasterization technique and remains the fastest option, but TiTanF offers a competitive pure-Rust alternative with a focus on correctness and readability.)
License
This project is licensed under the MIT License.