martensite-text
HarfBuzz text shaping, Unicode BiDi, two-tier caching, and velocity-damped IME candidate positioning.
Overview
martensite-text provides the internationalized text layout and typography engine for the Martensite GUI framework. Built on top of cosmic-text and HarfBuzz, it solves complex text shaping, multi-script font fallback, Unicode bidirectional text (UAX #9), and line breaking.
To sustain 120 FPS interactive window resizing across thousands of text nodes, martensite-text implements a two-tier caching architecture alongside a kinetic IME positioner that prevents Input Method candidate popups from flickering or lagging during active container scrolling.
The entire crate is built under #![forbid(unsafe_code)].
Key Features
- Complex Text Shaping & BiDi: Seamlessly shapes Arabic, Hebrew, Devanagari, CJK, and Latin scripts with automatic bidirectional reordering and font fallback.
- Two-Tier Text Caching:
- Tier 1 (Inline): Stored in each node's
ColdNodeto absorb repeated min/max constraint probes during two-pass flexbox layout without global lock contention. - Tier 2 (Global LRU): Bounded 16 MB memory budget (
TextShapeCache) caching fully shaped glyph runs across identical text strings and style attributes.
- Tier 1 (Inline): Stored in each node's
- Velocity-Damped IME Positioning (
ImePositioner): Projects caret positions and dampens velocity during rapid mousewheel scrolling, ensuring CJK/IME candidate windows dock smoothly without visual detachment. - Font Management (
FontManager): System font discovery viafontdb, system font collection querying, and zero-copy custom font asset loading. - 100% Safe Rust:
#![forbid(unsafe_code)]enforced across all text buffers and shaping routines.
Quick Start
Add martensite-text to your Cargo.toml:
[]
= "0.7.0"
Measuring and shaping text:
use ;
Two-Tier Cache Architecture
Measure Request (Text, FontSize, MaxWidth)
|
v
+----------------------+
| Tier 1: Inline Cache | -----> [Hit: Return Instant Bounds]
+----------------------+
| (Miss)
v
+----------------------+
| Tier 2: 16MB LRU | -----> [Hit: Return Cached ShapeRun]
+----------------------+
| (Miss)
v
+----------------------+
| Full HarfBuzz Shape | -----> [Compute, Populate Tiers, Return]
+----------------------+
Part of Martensite
This crate provides typography and text layout for the Martensite GUI framework. For high-level widgets and application tools, see martensite.
License
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.