doc_layout#
typographic paragraph flow and page layout -- crate root lib/doc_layout/lib.rs
Bounded paragraph flow and pagination in twips. New native functionality; no legacy counterpart.
Font measurement is supplied by the caller, so pagination is independent of zoom and GUI DPI.
doc_layout crate root#
struct MetricsFont metrics in twips (1/20 point). Positive ascent/height and nonnegative descent.ascent: i32descent: i32height: i32
trait MeasureA reusable measurement interface. Widths must be nonnegative, metrics positive and bounded.fn width(&mut self, text: &str, format: ResolvedFormat) -> i32Measure a fragment atformat.display_size_half_points(), without GUI zoom.fn metrics(&mut self, format: ResolvedFormat) -> MetricsReturn glyph metrics atformat.display_size_half_points(), in twips. The layout itself accounts for the script baseline displacement.
struct FragmentA text fragment positioned on a page in twips, ready for the caller's renderer.leader: doc_core::TabLeader-- Visual fill for a tab;textremains empty and its source is the original tab.source: Option<(usize, usize)>-- UTF-8 range in Document::text_projection; None for generated note-number prefixes.text: Stringformat: ResolvedFormatx: i32baseline: i32width: i32
struct LineA line with a stable paragraph target for navigation and hit testing.cell: Option<Id>-- Owning table cell, orNonefor body and note text.bar_tabs: Vec<i32>-- Absolute page x positions of bar tab rules, in twips.start: usize-- Start/end in the paragraph's displayed UTF-8 text, excluding an explicit line break.end: usizeparagraph: Id-- Document paragraph ID, or zero for a generated non-editable heading.x: i32-- Aligned start in twips, including an empty line's insertion point.top: i32height: i32fragments: Vec<Fragment>
struct PageOne page; an empty document still produces one page.cells: Vec<CellBox>lines: Vec<Line>separators: Vec<Separator>-- Page-bottom rules above footnotes; empty on pages without footnotes.
struct CellBoxA table cell rectangle in page twips, shared by paint, hit testing and resizing.edges: Vec<CellEdge>-- Shared edges resolved per adjacent grid segment; offsets are relative to this box.repeated: bool-- Display instance of an existing header cell; never a second document cell.table: Idcell: Idrow: usizecolumn: usizeparagraph: Idrow_span: usizecolumn_span: usizelast_row_height: u32row_end: bool-- False for a cell fragment ending at a page break instead of its grid row boundary.rect: [i32;4]fill: Option<u32>border_width: u16border_color: u32
struct SeparatorA horizontal rule separating footnote content from the main page text, in twips.x: i32y: i32width: i32
struct LayoutLaid-out document; page coordinates do not change when the view zoom changes.settings: PageSettingspages: Vec<Page>
enum ErrorInvalid model/measurements or exceeded expansion, fragment or page budget.Model(doc_core::Error)MetricsLimit
impl Layout
fn paragraph_at(&self, page: usize, y: i32) -> Option<Id>Hit-test the vertical extent of a line on a page, in page-relative twips.fn paginate(d: &Document, measure: &mut impl Measure) -> Result<Layout, Error>Paginate a validated document. Handles formatting runs, whitespace, tabs, line/page breaks, paragraph spacing/indents, alignment and heading keep-with-next when it fits on one page. Footnotes reserve page-bottom space with continuations; endnotes follow the main text. An anchor line and the first line of every note it references must fit on the same page. A same-line group that cannot meet that requirement without reordering note bodies fails withError::Limit; notes are never silently omitted. Rectangular tables flow by rows. No shaping, bidirectional algorithm or Word-identical pagination is claimed.
doc_layout/table_fit.rs#
Source: lib/doc_layout/table_fit.rs
enum TableFitContentsPageEqual
fn table_fit( d: &Document, id: Id, mode: TableFit, measure: &mut impl Measure, ) -> Result<Vec<u32>, Error>Compute fixed widths; applyingTableChange::Columnsrecords the fit as one undo step. Contents measures explicit lines and tabs. It wraps text when natural widths exceed the page.
doc_layout/table_borders.rs#
Source: lib/doc_layout/table_borders.rs
struct CellEdgeside:BorderSideoffset:i32length:i32border:CellBorder