textflow-rs 0.2.3

Bounded no_std Unicode text layout, bidi shaping, line breaking, and caret positioning for Rust
Documentation

TextFlow provides line breaking, bidirectional text, glyph shaping, font fallback, visual runs, and caret positioning. Caller-owned buffers make memory use explicit, while the optional alloc feature provides a reusable fixed-capacity workspace over the same algorithms.

Used by

mirui uses TextFlow for bounded Unicode analysis, shaping, line layout, and caret placement with MIRX and OpenType font sources across software, GPU, and web renderers.

Demo

use textflow::TextFlow;

let text = "A small UI can still set type well.";
let lines = TextFlow::new(text, 12)
    .map(|line| line.text())
    .collect::<Vec<_>>();

assert_eq!(lines, ["A small UI", "can still", "set type", "well."]);

Text layout and shaping

  • #![no_std] by default with a core-only runtime.
  • Caller-owned buffers with explicit capacity and unsupported-text errors.
  • Format-neutral Typeface and GlyphSource interfaces for TTF, OpenType, MIRX, flash-backed assets, and application-specific font stores.
  • Stable glyph IDs, UTF-8 cluster ranges, visual bidi runs, safe line boundaries, and caret positions.
  • Optional reusable heap workspace with admission limits and no growth during layout.

Embedded footprint

The ESP32-C3 demo runs bidirectional resolution, font selection, shaping, wrapping, visual reordering, glyph positioning, and caret generation without an allocator. All working capacity is supplied by fixed arrays.

Measured with Rust 1.97.0, esp-hal 1.1.0, size optimization, LTO, one codegen unit, and aborting panics:

ESP32-C3 release image App partition Static RAM (.data + .bss)
ESP-HAL baseline 73,536 B 808 B
Full TextFlow pipeline 83,024 B 824 B
TextFlow delta 9,488 B 16 B

The demo's main stack frame is 2,336 B, including 2,304 B of caller-owned text buffers. Heap usage is 0 B. Run examples/esp32c3/measure.sh to rebuild both images and reproduce the Flash and static RAM comparison.

Feature flags

Feature Adds
unicode Bounded grapheme, line-break, and script classification
bidi Caller-buffer bidirectional paragraph resolution
shaping Format-neutral shaping, fallback, line selection, and positioned output
complex-shaping Bounded script providers with borrowed substitution and positioning data
script-arabic Arabic joining forms, ligatures, cursive attachment, and mark positioning
script-thai Thai cluster substitution and mark positioning
alloc Reusable owning workspace for the shaping pipeline

Default features are empty. The current Unicode and shaping implementation intentionally supports a defined subset and returns capability errors for unsupported scripts, controls, clusters, and font features.

Font integration

A format adapter supplies Typeface for complete shaping or GlyphSource for scalar cmap, advance, .notdef, and pair-kerning access, together with its parser, table cache, raster lookup, storage access, and diagnostics. The complex-shaping feature adds ScriptTypeface, ScriptProvider, and ShapingData for sharing script behavior across borrowed font formats. script-arabic and script-thai expose the allocation-free scripts::ARABIC and scripts::THAI providers.

Documentation

License

MIT