use std::fmt::Debug; use typst_library::diag::{bail, SourceResult}; use typst_library::engine::Engine; use typst_library::foundations::{Resolve, StyleChain}; use typst_library::layout::grid::resolve::{ Cell, CellGrid, Header, LinePosition, Repeatable, }; use typst_library::layout::resolve::Footer; use typst_library::layout::{ Abs, Axes, Dir, Fr, Fragment, Frame, FrameItem, Length, Point, Region, Regions, Rel, Size, Sizing, }; use typst_library::text::TextElem; use typst_library::visualize::Geometry; use typst_syntax::Span; use typst_utils::Numeric; use super::{ generate_line_segments, hline_stroke_at_column, layout_cell, vline_stroke_at_row, LineSegment, Rowspan, UnbreakableRowGroup, }; /// Performs grid layout. pub struct GridLayouter<'a> { /// The grid of cells. pub(super) grid: &'a CellGrid<'a>, /// The regions to layout children into. pub(super) regions: Regions<'a>, /// The inherited styles. pub(super) styles: StyleChain<'a>, /// Resolved column sizes. pub(super) rcols: Vec, /// The sum of `rcols`. pub(super) width: Abs, /// Resolved row sizes, by region. pub(super) rrows: Vec>, /// The amount of unbreakable rows remaining to be laid out in the /// current unbreakable row group. While this is positive, no region breaks /// should occur. pub(super) unbreakable_rows_left: usize, /// Rowspans not yet laid out because not all of their spanned rows were /// laid out yet. pub(super) rowspans: Vec, /// Grid layout state for the current region. pub(super) current: Current, /// Frames for finished regions. pub(super) finished: Vec, /// The amount and height of header rows on each finished region. pub(super) finished_header_rows: Vec, /// Whether this is an RTL grid. pub(super) is_rtl: bool, /// Currently repeating headers, one per level. Sorted by increasing /// levels. /// /// Note that some levels may be absent, in particular level 0, which does /// not exist (so all levels are >= 1). pub(super) repeating_headers: Vec<&'a Header>, /// Headers, repeating or not, awaiting their first successful layout. /// Sorted by increasing levels. pub(super) pending_headers: &'a [Repeatable
], /// Next headers to be processed. pub(super) upcoming_headers: &'a [Repeatable
], /// Currently repeating footers, one per level. Sorted by increasing /// levels. /// /// Note that some levels may be absent, in particular level 0, which does /// not exist (so all levels are >= 1). pub(super) repeating_footers: Vec<&'a Footer>, /// Next footers to be processed. pub(super) upcoming_footers: &'a [Repeatable