Expand description
Layout engine for Mosaic.
MVP 0 implements the smallest end-to-end slice that gets ink on a
page: greedy line-breaking against fixed A4 metrics, walking a
lowered Document into a PageGraph. Real shaping
(HarfBuzz/rustybuzz), Knuth-Plass, hyphenation, and font
embedding are deferred per the manifest’s MVP roadmap (§30,
§22.1, §22.2). Boundary-state reuse for incremental builds
(§22.3, §33) is also out of scope here.
Structs§
- Font
Family - A four-cut family: Regular, Bold, Italic,
BoldItalic. The layout engine picks one slot per styled run (*emphasis*→ italic,**strong**→ bold, raw → fixed-width family, body → regular). - Image
Handle - Decoded raster image data shared between every page that places
the same source image. Held by
Arcso a single PNG referenced from multiple#image(...)directives shares one buffer end-to-end. - Image
Placement - One image placement on a page. The PDF backend emits this as a
q ... cm /Im<id> Do Qblock in the content stream. - Layout
Engine - The driver for MVP 0 layout.
- Layout
Result - Result of laying out a
mos_core::Document: aPageGraphplus any warnings the engine emitted. Mirrorsmos_eval::LowerResultso the CLI can render diagnostics uniformly. - Layout
State 🔒 - Mutable cursor + accumulator threaded through the layout.
- Outline
Entry - One PDF bookmark/outline entry captured during layout. Ordered in
document order; nesting is reconstructed from
levelat emit time. - Page
- One laid-out page.
- Page
Boundary Signature - A compact, deterministic digest of one laid-out
Page’s break-defining content (design note §4.5). - Page
Graph - The paginated output graph (manifest §6 stage 7).
- Page
Graph Signature - The ordered per-page boundary signatures of a whole
PageGraph. - Page
Style - Page geometry resolved from
#set page(...).width/heightdescribe the full media box;marginis symmetric on all four sides for MVP 1.5 (per-side margins are deferred). - Pending
Marker 🔒 - Pending
Outline 🔒 - Pending
Space 🔒 - Shaped
Glyph - One glyph in a shaped run. Cluster values are byte offsets into the source UTF-8 string.
- TextRun
- A single horizontal run of text on a page. The MVP 0 emitter produces one run per word; coalescing same-font neighbours is an MVP 2 optimisation.
- Text
Style - Body text style resolved from
#set text(...).leadingapplies to body paragraphs only; headings keep their own multiplier so a#set text(leading: 2.0)doesn’t balloon section titles. - Word
SubRun - One face’s slice of a per-glyph-fallback shaping result.
Enums§
- Base14
Font - One of the 14 standard PDF fonts every conformant PDF reader ships built in (PDF 1.7 §9.6.2.2).
- Embedded
Font Id - Stable identifier for each bundled embedded cut. Used as the enum
payload of
Font::EmbeddedsoFontstaysCopy/Hash/Eqwithout resorting to pointer identity. - Font
- A renderable font – either one of the Adobe Core 14 (no data embedded; outlines from the PDF reader) or a bundled TrueType cut (data embedded, subset per-document).
Constants§
- A4_
HEIGHT_ PT - A4 page height in PDF points.
- A4_
WIDTH_ PT - A4 page width in PDF points (1pt = 1/72 inch). Kept as a public
constant so external callers can still read the default; the layout
engine now consults
PageStyleinstead of these directly. - HEADING_
SIZES_ 🔒PT - Heading sizes by level (1-indexed). Anything beyond level 3 falls back to body size: counters and section numbering land in MVP 1.
- HEADING_
SPACE_ 🔒AFTER_ PT - Space below each heading level.
- HEADING_
SPACE_ 🔒BEFORE_ PT - Space above each heading level (skipped for the first block on a page).
- LIST_
MARKER_ 🔒GUTTER_ PT - Horizontal gutter reserved for the list marker (
•for unordered,1.for ordered) on each nesting level. Doubles as the per-level indent step: nested items shift right by this many points before their own gutter is added. Sized to comfortably hold a one- or two-digit ordered marker at the default body size; lists with three- digit numbering will overflow the gutter visually until per-list gutter tuning lands. - MARGIN_
PT - Default page margin in points (24mm × 72/25.4).
- PARA_
SPACE_ 🔒AFTER_ PT - Vertical gap between consecutive paragraphs.
- RAW_
BLOCK_ 🔒TAB_ WIDTH - Number of columns represented by one tab in raw code/pre blocks.
Functions§
- ascent
- Ascender height for
fontatsizepoints. - descent
- Descender depth for
fontatsizepoints, as a positive number (the AFM/TTF storage convention is negative; both backends normalise on the way out). - glyph_
width - Width of a single glyph in
fontatsizepoints. - paper_
size_ pt - Resolve a paper-size name (
"A4","B5","Letter","Legal") to(width_pt, height_pt). ISO 216AandBsizes are computed algorithmically; non-ISO sizes are explicit constants. - shape_
with_ fallback - Shape
textagainstprimarywith per-glyph fallback. - starts_
with_ 🔒closing_ punctuation - text_
width - Advance width of
textrendered infontatsizepoints.