Expand description
Rich-text layout engine — wraps a RichDoc to a fixed width with
per-run fonts and sizes, producing paint-ready line/fragment geometry.
The engine is deliberately catalog-agnostic: it never loads fonts itself.
The caller supplies a resolver: Fn(&InlineStyle) -> Arc<Font> that maps a
run’s style (family + bold/italic) to a concrete Font. The demo crate
provides a resolver backed by the system-font catalog (with faux-bold /
faux-italic fallback); the library and its tests stay independent of it.
§What it computes
- Word wrapping across style boundaries — a “word” is a maximal run of non-whitespace pieces even when they span several differently-styled runs, so a bold suffix never wraps away from its plain prefix.
- Per-visual-line height =
max(ascent + descent) * LINE_SPACINGacross the fragments on that line, so a large glyph grows the whole line. - Block alignment (left / center / right) within the text column.
- List markers:
•for bullets,N.for ordered items, hung in a gutter to the left of the text. Ordered numbering counts consecutiveOrderedblocks at the same indent and restarts after any break.
Geometry is expressed top-down (y grows downward from the document top); the read-only view flips it into the framework’s Y-up space at paint time.
Structs§
- Block
Layout - Layout of one block/paragraph.
- DocLayout
- Layout of a whole document.
- Line
Fragment - One piece of a run as it sits on a single visual line: the smallest unit the painter draws. A wrapped run may contribute several fragments (one per line); adjacent same-style pieces on a line are merged into one fragment.
- Line
Layout - One visual line within a block.
Constants§
- INDENT_
PX - Indent step, in logical pixels, per
Block::indentlevel. - LINE_
SPACING - Line-height multiplier applied to the tallest (ascent + descent) on a line.
- LIST_
GUTTER_ PX - Width reserved to the left of a list item’s text for its marker.
- MARKER_
GAP_ PX - Gap between a list marker’s right edge and the text column.
Functions§
- layout_
doc - Lay
docout towidthlogical pixels usingresolverfor fonts anddefault_font_sizewhere a run leaves its size inherited.
Type Aliases§
- Font
Resolver - A resolver maps a run style to the concrete font to shape/measure it with.