Expose the page box height and depth to the output routine

This commit is contained in:
gloamxun committed 2026-10-23 13:24:14 +08:00
1 parent 70b360e50e
commit be23fe9686
4 files changed
+49 -4

No files matched your search

+17
View File
@@ -5905,6 +5905,23 @@ mod tests {
assert_eq!(page_prev_graf(&empty), 0);
}
#[test]
fn output_routine_reads_the_page_box_height() {
let pt = 65_536;
let mut document = Document::new(
100 * pt,
vec![
Unit::rule(1, 10 * pt, 40 * pt),
Unit::penalty(2, -10_000),
Unit::rule(3, 10 * pt, 70 * pt),
],
);
document.output_routine = Some(r"\ifdim\ht255>50pt\shipout\box255\else\relax\fi".into());
let engine = Engine::layout_paged(&document).expect("paged layout");
assert_eq!(engine.pages().len(), 1);
assert_eq!(item_height(&engine.pages()[0].items[0]), 70 * pt);
}
#[test]
fn output_register_assignments_persist_across_pages() {
let mut document = Document::new(
+27
View File
@@ -185,6 +185,10 @@ enum Register {
PageFillStretch,
PageFilllStretch,
PageShrink,
/// TeX `\ht255`: height of the page box handed to the output routine.
BoxHeight255,
/// TeX `\dp255`: depth of the page box handed to the output routine.
BoxDepth255,
Vsize,
TopSkip,
MaxDepth,
@@ -205,6 +209,8 @@ impl Dimension {
Register::PageFillStretch => context.page_fill_stretch,
Register::PageFilllStretch => context.page_filll_stretch,
Register::PageShrink => context.page_shrink,
Register::BoxHeight255 => context.page_total,
Register::BoxDepth255 => context.page_depth,
Register::Vsize => context.vsize,
Register::TopSkip => context.top_skip,
Register::MaxDepth => context.max_depth,
@@ -609,6 +615,17 @@ fn parse_integer(tokens: &[Token], index: &mut usize) -> Result<Integer, String>
Ok(integer)
}
/// Reads the box number after `\\ht`/`\\dp`; only box 255 is modelled.
fn expect_box_255(tokens: &[Token], index: &mut usize, name: &str) -> Result<(), String> {
match tokens.get(*index) {
Some(Token::Number { value, unit }) if *value == 255.0 && unit.is_none() => {
*index += 1;
Ok(())
}
_ => Err(format!("{name} only supports box 255")),
}
}
fn parse_dimension(tokens: &[Token], index: &mut usize) -> Result<Dimension, String> {
let dimension = match tokens.get(*index) {
Some(Token::Number { value, unit }) => {
@@ -635,6 +652,16 @@ fn parse_dimension(tokens: &[Token], index: &mut usize) -> Result<Dimension, Str
"pagefillstretch" => Register::PageFillStretch,
"pagefilllstretch" => Register::PageFilllStretch,
"pageshrink" => Register::PageShrink,
"ht" => {
*index += 1;
expect_box_255(tokens, index, "\\ht")?;
return Ok(Dimension::Register(Register::BoxHeight255));
}
"dp" => {
*index += 1;
expect_box_255(tokens, index, "\\dp")?;
return Ok(Dimension::Register(Register::BoxDepth255));
}
"vsize" => Register::Vsize,
"topskip" => Register::TopSkip,
"maxdepth" => Register::MaxDepth,
+3 -2
View File
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
PDF opt-in with `?engine=route-d`). 420 workspace tests are green and no oracle
PDF opt-in with `?engine=route-d`). 421 workspace tests are green and no oracle
fixture is ignored.
Known gaps, in dependency order:
@@ -77,7 +77,8 @@ Known gaps, in dependency order:
3. `\insert` classes are TeX registers addressed by number (`\count<n>`,
`\dimen<n>`, `\skip<n>`, with `\count0` aliasing `\pageno`) and the
interpreted output routine can assign `\pageno`, `\deadcycles`,
`\outputpenalty` and those insertion registers, and the assigned values carry
`\outputpenalty` and those insertion registers, `\ht255`/`\dp255` expose the page
box height and depth, and the assigned values carry
over to later pages (TeX output registers are global); an assigned `\vsize`
changes later page goals for documents without insertions or floats, but
insertion-register writes still do not feed back into page building, `\box255` content is not inspectable and the full
+2 -2
View File
@@ -116,7 +116,7 @@ and justification.
| --- | --- | --- |
| M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 |
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, TeX Live en-US hyphenation, TeX demerits and tolerance passes, `\hangindent`/`\parshape`, `\parfillskip`, sentence spacing, `\spaceskip`/`\xspaceskip`, `\raggedright` (infinite `\rightskip`), `\looseness`, `\baselineskip`/`\lineskip`/`\parskip` interline glue, pdfLaTeX oracle matrix 90-240pt plus register, geometry, `\sfcode`, `\parindent`, `\parshape`, `\leftskip`/`\rightskip`, `\hfil`/`\hfill` glue orders, `\prevgraf` in the output routine, and vertical-glue fixtures |
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; `page::PageBuilder` scores candidate breakpoints with TeX page badness, glue setting (with `\raggedbottom`/`\flushbottom` applied when pages are materialised, and TeX glue orders `\vfil`/`\vfill`/`\vfilll` honoured so only the highest order with stretch is used), `\topskip`/`\maxdepth`, and `Engine::layout_paged` uses it for documents whose units are single vertical items, placing top and bottom floats (with `\floatsep`, a `\bottomfraction` cap and the `\topnumber`/`\bottomnumber`/`\totalnumber` limits, with `\floatpagefraction` deciding when a float-heavy page ships without body) and insertion classes on that path, while in-text floats flow inline as body material; paged layouts replay edits from the edited unit's page and fall back to a full rebuild only when insertions or an interpreted `\output` are present; `\output` is interpreted for a `\shipout`/`\ifdim`/`\ifnum`/`\ifodd`/`\ifcase` subset; `\pageno`, `\outputpenalty` and `\deadcycles` are readable and assignable registers (`\pageno=...` carries into the next page, and an assigned `\vsize` retargets later pages when the document has no insertions or floats), insertion class registers `\count<n>`/`\dimen<n>`/`\skip<n>` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`) and accept assignments for the duration of the routine, `\deadcycles` accumulates pages the output routine did not ship and resets on the next shipout, `PageFragment::penalty` carries the break penalty, and `PageFragment::stretches` records glue stretch per TeX order so `\pagefilstretch`/`\pagefillstretch`/`\pagefilllstretch` are readable in the output routine |
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; `page::PageBuilder` scores candidate breakpoints with TeX page badness, glue setting (with `\raggedbottom`/`\flushbottom` applied when pages are materialised, and TeX glue orders `\vfil`/`\vfill`/`\vfilll` honoured so only the highest order with stretch is used), `\topskip`/`\maxdepth`, and `Engine::layout_paged` uses it for documents whose units are single vertical items, placing top and bottom floats (with `\floatsep`, a `\bottomfraction` cap and the `\topnumber`/`\bottomnumber`/`\totalnumber` limits, with `\floatpagefraction` deciding when a float-heavy page ships without body) and insertion classes on that path, while in-text floats flow inline as body material; paged layouts replay edits from the edited unit's page and fall back to a full rebuild only when insertions or an interpreted `\output` are present; `\output` is interpreted for a `\shipout`/`\ifdim`/`\ifnum`/`\ifodd`/`\ifcase` subset; `\pageno`, `\outputpenalty` and `\deadcycles` are readable and assignable registers (`\pageno=...` carries into the next page, and an assigned `\vsize` retargets later pages when the document has no insertions or floats), `\ht255` and `\dp255` expose the page box height and depth to the routine, insertion class registers `\count<n>`/`\dimen<n>`/`\skip<n>` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`) and accept assignments for the duration of the routine, `\deadcycles` accumulates pages the output routine did not ship and resets on the next shipout, `PageFragment::penalty` carries the break penalty, and `PageFragment::stretches` records glue stretch per TeX order so `\pagefilstretch`/`\pagefillstretch`/`\pagefilllstretch` are readable in the output routine |
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | **partial**: source parsing, natural column widths, spans, rule rows, 10pt display-list painting and row-level page splitting; no booktabs/longtable parity yet |
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | **partial**: token parser, atom boxes with CMR10 metrics, delimiter scaling, accents and a display-list painter; no CMEX size variants or TeX math spacing classes yet |
| M5 | NFSS/TFM metrics, CM/Latin Modern | same line/page breaks as reference |
@@ -346,7 +346,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`) supplies advances, kerns, ligatures, and italic correction for layout, while the display list and PDF select the matching Liberation face. `Engine::edit` preserves the face when reflowing an edited paragraph.
The crate currently has 287 unit tests plus seven route-D integration tests and twenty-four oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 420 tests (287 route-D unit, 7 route-D integration, 24 oracle, 71 v1 integration, 24 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
The crate currently has 288 unit tests plus seven route-D integration tests and twenty-four oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 421 tests (288 route-D unit, 7 route-D integration, 24 oracle, 71 v1 integration, 24 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
### M0 incremental demo