Repository navigation
Fonts: shape long items in bounded pieces - #1702
Conversation
The shaper lets one call grow to 256 glyphs per input character, as an embedded font's substitutions decide, and every glyph was then copied out. Items longer than 1 KiB are now shaped in pieces (cut at a space where one is near, never before a combining mark or after a joiner), each with the rest of the paragraph as context and the item's script, and a piece that expands past 32 glyphs per character falls back to one glyph per character from the cmap.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
What was wrong
shape_rangehanded a whole item to HarfRust in one call. HarfRust lets a call grow its buffers to 256 glyphs per input character (minimum 65,536), and an embedded font with a default-onccmpMultipleSubst lookup decides how far each character expands. Every resulting glyph was then copied into the output vector. A long run of text in such a font could therefore allocate gigabytes during layout. HarfRust has no public way to set a lower limit.What changed
MAX_SHAPE_CHUNK) are shaped in pieces. A cut goes at a space near the end of the window, otherwise before a character that starts a cluster: never before a combining mark (bidi class NSM) and never after a joiner (BN). Each piece is shaped with the rest of the paragraph as pre- and post-context, and with the script guessed for the whole item, so pieces agree. This bounds each HarfRust call to about 262k glyphs.MAX_GLYPHS_PER_CHAR), its output is dropped in favour of one glyph per character from the cmap. This bounds what is retained.cmap_glyphsand reused for the no-shaper case.Blast radius
deckcraft-fontsshaping, used by text layout. Items up to 1 KiB, which covers almost all runs, are shaped exactly as before. Longer items may differ at cut points only where a cross-space feature such as kerning against a space would have applied.Checks run
cargo test -p deckcraft-fonts(new tests: piece boundaries, coverage and limits; long LTR and RTL items keep every cluster in visual order)cargo clippy -p deckcraft-fonts --all-targets -- -D warningscargo fmt -p deckcraft-fonts --checkcargo check -p deckcraft-text(the main caller)Checks not run
cargo xtask ciand visual text checks; craft-fonts was not present, so only bundled fonts were exercised.ccmpexpansion font fixture is in the tree.Addresses CodeRabbit security findings (CWE-409).
Summary by CodeRabbit