Skip to main content

Crate mos_layout

Crate mos_layout 

Source
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.

Modules§

boundary 🔒
Page boundary signatures (issue #70; design note docs/incremental-dependencies.md §4.5, §6, §7).
image 🔒
list 🔒
style 🔒
support 🔒
types 🔒
word 🔒

Structs§

FontFamily
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).
ImageHandle
Decoded raster image data shared between every page that places the same source image. Held by Arc so a single PNG referenced from multiple #image(...) directives shares one buffer end-to-end.
ImagePlacement
One image placement on a page. The PDF backend emits this as a q ... cm /Im<id> Do Q block in the content stream.
LayoutEngine
The driver for MVP 0 layout.
LayoutResult
Result of laying out a [mos_core::Document]: a PageGraph plus any warnings the engine emitted. Mirrors mos_eval::LowerResult so the CLI can render diagnostics uniformly.
LayoutState 🔒
Mutable cursor + accumulator threaded through the layout.
Page
One laid-out page.
PageBoundarySignature
A compact, deterministic digest of one laid-out Page’s break-defining content (design note §4.5).
PageGraph
The paginated output graph (manifest §6 stage 7).
PageGraphSignature
The ordered per-page boundary signatures of a whole PageGraph.
PageStyle
Page geometry resolved from #set page(...). width_pt/height_pt describe the full media box; margin_pt is symmetric on all four sides for MVP 1.5 (per-side margins are deferred).
PendingMarker 🔒
ShapedGlyph
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.
TextStyle
Body text style resolved from #set text(...). leading applies to body paragraphs only; headings keep their own multiplier so a #set text(leading: 2.0) doesn’t balloon section titles.
WordSubRun
One face’s slice of a per-glyph-fallback shaping result. A word shaped through shape_with_fallback produces a Vec<WordSubRun>; each sub-run is self-contained: its text is the source UTF-8 slice covered by exactly this sub-run, its glyphscluster offsets are rebased to the sub-run’s local text (so plan_embedded can build /ToUnicode without knowing about the parent word), and its advance_pt is the sum of per-glyph advances at the requested point size.

Enums§

Base14Font
One of the 14 standard PDF fonts every conformant PDF reader ships built in (PDF 1.7 §9.6.2.2).
EmbeddedFontId
Stable identifier for each bundled embedded cut. Used as the enum payload of Font::Embedded so Font stays Copy/Hash/Eq without 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 PageStyle instead 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 font at size points.
descent
Descender depth for font at size points, 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 font at size points. For Base14 faces this is one AFM lookup; for embedded faces it shapes the single character. Used by the paragraph engine for character-wise hyphenation of oversized words.
paper_size_pt
Resolve a paper-size name ("A4", "B5", "Letter", "Legal") to (width_pt, height_pt). ISO 216 A and B sizes are computed algorithmically; non-ISO sizes are explicit constants.
shape_with_fallback
Shape text against primary with per-glyph fallback. Walks each HarfBuzz cluster in the primary’s shaped output; clusters that contain any .notdef (GID 0) glyph are re-shaped against each embedded face in fallbacks in order. The first fallback to produce a glyph stream with no .notdef wins the whole cluster (cluster- granular replacement, never partial: partial replacement would duplicate bases, drop marks, break ligatures).
text_width
Advance width of text rendered in font at size points.