oxedyne/fe2o3/fe2o3_austenite/src/flow/mod.rs
3.1 KiB, 3 runs
created by r1870400018:63530, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! Contract (U0, 2026-09-23): realised elements lower straight to [`crate::ir::Node`], never through |
| 2 | //! `doc::Block`, whose book idiom is what the evaluator replaces. Every function here only dispatches to |
| 3 | //! the owning unit's file, so none of the flow units edits this one. A container element (block, box, |
| 4 | //! grid cell) lays out its body by calling [`layout_block`] or `par::layout_par`, which realise one level |
| 5 | //! at a time through `eval::realise`; styles arrive resolved per element as its `StyleChain`. |
| 6 | |
| 7 | pub mod block; |
| 8 | mod carry; |
| 9 | pub mod decorate; |
| 10 | pub mod grid; |
| 11 | pub mod inline; |
| 12 | pub mod lists; |
| 13 | pub mod math; |
| 14 | pub mod page; |
| 15 | pub mod par; |
| 16 | pub mod text; |
| 17 | pub mod visual; |
| 18 | |
| 19 | pub use page::{ |
| 20 | PageBody, |
| 21 | Paginator, |
| 22 | }; |
| 23 | |
| 24 | use crate::eval::content::Content; |
| 25 | use crate::eval::styles::StyleChain; |
| 26 | use crate::eval::value::{ |
| 27 | Paint, |
| 28 | Value, |
| 29 | }; |
| 30 | use crate::eval::Engine; |
| 31 | use crate::ir::{ |
| 32 | Dims, |
| 33 | Node, |
| 34 | Sp, |
| 35 | }; |
| 36 | use crate::page::PageGeometry; |
| 37 | |
| 38 | use oxedyne_fe2o3_core::prelude::*; |
| 39 | |
| 40 | /// The space an element is laid out into. `height` is what remains of the current column; `base` is the |
| 41 | /// size relative lengths resolve against (the container's, not the remainder). |
| 42 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 43 | pub struct Region { |
| 44 | pub width: Sp, |
| 45 | pub height: Sp, |
| 46 | pub base: (Sp, Sp), |
| 47 | pub expand_x: bool, // fill the width rather than shrink to content |
| 48 | pub expand_y: bool, |
| 49 | } |
| 50 | |
| 51 | impl Region { |
| 52 | pub fn new(width: Sp, height: Sp) -> Self { |
| 53 | Self { width, height, base: (width, height), expand_x: true, expand_y: false } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /// Which parity a `pagebreak(to: ..)` asks the next page to have. |
| 58 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 59 | pub enum Parity { |
| 60 | Odd, |
| 61 | Even, |
| 62 | } |
| 63 | |
| 64 | /// How a page's `header` or `footer` is set. `auto` leaves the slot to the page numbering; `none` clears it, |
| 65 | /// the numbering with it. |
| 66 | #[derive(Clone, Debug)] |
| 67 | pub enum Slot { |
| 68 | Auto, |
| 69 | Off, |
| 70 | On(Content), |
| 71 | } |
| 72 | |
| 73 | /// What a run of pages under one `set page(..)` shares: the geometry, and the furniture [`decorate`] |
| 74 | /// evaluates per page with `here()` there. Its pages' bodies come from the [`Paginator`] one at a time, so |
| 75 | /// no run holds them. |
| 76 | #[derive(Clone, Debug)] |
| 77 | pub struct RunSetup { |
| 78 | pub geom: PageGeometry, |
| 79 | pub columns: usize, |
| 80 | pub gutter: Sp, |
| 81 | pub fill: Option<Paint>, |
| 82 | pub numbering: Value, // `page.numbering`, none by default |
| 83 | pub header: Slot, |
| 84 | pub footer: Slot, |
| 85 | pub background: Option<Content>, |
| 86 | pub foreground: Option<Content>, |
| 87 | pub styles: StyleChain, // the chain furniture is evaluated under |
| 88 | } |
| 89 | |
| 90 | /// The document as pages, one at a time, from its content under `styles`. |
| 91 | pub fn paginate(content: &Content, styles: &StyleChain) -> Paginator { |
| 92 | Paginator::new(content, styles) |
| 93 | } |
| 94 | |
| 95 | /// Block-level content into a vertical list for a region. |
| 96 | pub fn layout_block( |
| 97 | engine: &mut Engine, |
| 98 | content: &Content, |
| 99 | styles: &StyleChain, |
| 100 | region: Region, |
| 101 | ) |
| 102 | -> Outcome<Vec<Node>> |
| 103 | { |
| 104 | block::layout_flow(engine, content, styles, region) |
| 105 | } |
| 106 | |
| 107 | /// `measure(content)`: the natural size in a region, laid out and discarded. |
| 108 | pub fn measure( |
| 109 | engine: &mut Engine, |
| 110 | content: &Content, |
| 111 | styles: &StyleChain, |
| 112 | region: Region, |
| 113 | ) |
| 114 | -> Outcome<Dims> |
| 115 | { |
| 116 | block::measure(engine, content, styles, region) |
| 117 | } |