JFLib

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 Metrics Font metrics in twips (1/20 point). Positive ascent/height and nonnegative descent.

    • ascent: i32
    • descent: i32
    • height: i32
  • trait Measure A reusable measurement interface. Widths must be nonnegative, metrics positive and bounded.

    • fn width(&mut self, text: &str, format: ResolvedFormat) -> i32 Measure a fragment at format.display_size_half_points(), without GUI zoom.
    • fn metrics(&mut self, format: ResolvedFormat) -> Metrics Return glyph metrics at format.display_size_half_points(), in twips. The layout itself accounts for the script baseline displacement.
  • struct Fragment A text fragment positioned on a page in twips, ready for the caller's renderer.

    • leader: doc_core::TabLeader -- Visual fill for a tab; text remains 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: String
    • format: ResolvedFormat
    • x: i32
    • baseline: i32
    • width: i32
  • struct Line A line with a stable paragraph target for navigation and hit testing.

    • cell: Option<Id> -- Owning table cell, or None for 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: usize
    • paragraph: 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: i32
    • height: i32
    • fragments: Vec<Fragment>
  • struct Page One 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 CellBox A 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: Id
    • cell: Id
    • row: usize
    • column: usize
    • paragraph: Id
    • row_span: usize
    • column_span: usize
    • last_row_height: u32
    • row_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: u16
    • border_color: u32
  • struct Separator A horizontal rule separating footnote content from the main page text, in twips.

    • x: i32
    • y: i32
    • width: i32
  • struct Layout Laid-out document; page coordinates do not change when the view zoom changes.

    • settings: PageSettings
    • pages: Vec<Page>
  • enum Error Invalid model/measurements or exceeded expansion, fragment or page budget.

    • Model(doc_core::Error)
    • Metrics
    • Limit

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 with Error::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 TableFit

    • Contents
    • Page
    • Equal
  • fn table_fit( d: &Document, id: Id, mode: TableFit, measure: &mut impl Measure, ) -> Result<Vec<u32>, Error> Compute fixed widths; applying TableChange::Columns records 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 CellEdge
    • side:BorderSide
    • offset:i32
    • length:i32
    • border:CellBorder

Source: docs/API.md in the JFLib repository.