Native Text Engine
Native text engine for SDF glyph generation and text layout.
This engine uses Rust for high-performance text shaping (via rustybuzz) and SDF generation. It maintains a glyph atlas with LRU cache eviction.
Usage
val engine = NativeTextEngine()
engine.init(2048, 2048) // Initialize with atlas size
engine.loadFont(fontBytes) // Load primary font
// Process text and get layout
val layoutJson = engine.processText("Hello", 48f, 400f)
// Upload pending glyphs to atlas
if (engine.hasPendingUploads()) {
val uploads = parsePendingUploads(engine.getPendingUploads())
atlasManager.updateAtlas(uploads)
}SDF Processing
Glyph data is pre-processed in Rust with alpha values:
A channel: normal text alpha (smoothstep at threshold 0.7)
G channel: shadow alpha (smoothstep falloff for glow effect)
Functions
Clears all loaded fallback fonts.
Gets the current atlas size.
Gets pending glyph uploads as JSON. Each upload contains position, size, and RGBA pixel data (pre-processed SDF).
Checks if there are pending glyph uploads.
Loads a fallback font for missing glyphs. Fallback fonts are tried in order when the primary font doesn't contain a glyph.
Loads a fallback font from Android assets using zero-copy file descriptor. More memory efficient than loading entire font into ByteArray.
Loads a fallback font from a file path using zero-copy file descriptor.
Processes text and returns layout information as JSON. This also generates SDF glyphs for any new characters.