Skip to main content

Module layout

Module layout 

Source
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_SPACING across 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 consecutive Ordered blocks 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§

BlockLayout
Layout of one block/paragraph.
DocLayout
Layout of a whole document.
LineFragment
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.
LineLayout
One visual line within a block.

Constants§

INDENT_PX
Indent step, in logical pixels, per Block::indent level.
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 doc out to width logical pixels using resolver for fonts and default_font_size where a run leaves its size inherited.

Type Aliases§

FontResolver
A resolver maps a run style to the concrete font to shape/measure it with.