Route route-D page breaking through the paged builder

This commit is contained in:
gloamxun committed 2026-10-23 15:02:52 +08:00
1 parent 08a312be82
commit 6b3145fd09
6 files changed
+113 -26

No files matched your search

+8 -6
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`). 449 workspace tests are green and no oracle
PDF opt-in with `?engine=route-d`). 450 workspace tests are green and no oracle
fixture is ignored.
Known gaps, in dependency order:
@@ -67,11 +67,13 @@ source-level `\hyphenation{...}` exceptions and `\parshape` measures,
`\raggedright` (infinite `\rightskip` fil), explicit
`\hfil`/`\hfill` glue orders, and `\prevgraf` visibility in the output
routine;
2. the default builder is still the scrolling builder with fraction
policies, now with line-level paragraph splits; `page::PageBuilder`
implements the candidate-breakpoint cost model (badness + penalty, glue
setting, `\topskip`, `\maxdepth`) and `Engine::layout_paged` runs it for
documents made of box/glue/penalty/mark units, insertion classes
2. the scrolling builder remains the non-paged fallback with fraction float
policies; `page::PageBuilder` implements the candidate-breakpoint cost
model (badness + penalty, glue setting, `\topskip`, `\maxdepth`) and
`Engine::layout_paged` runs it for documents made of
box/glue/penalty/mark/float/insertion units, with paragraphs expanded to
one node per line so pages break inside them; route-D previews and PDFs
use the paged builder when the document is expressible, insertion classes
(per-class limits with held-over material) and top and bottom floats
(`\textfloatsep` above the body, `\floatsep` between stacked bottom
floats, `\bottomfraction` cap); in-text floats flow inline, so every
+11 -7
View File
@@ -156,10 +156,13 @@ and justification.
Interline glue follows TeX: each baseline advances by `\baselineskip` when
the resulting gap clears `\lineskiplimit`, otherwise by `\lineskip`;
`\parskip` is appended between paragraph units in the vertical list. When a
paragraph does not fit on the page, the scrolling builder splits it at line
boundaries (`Paragraph::split_at`): the fragment keeps its baseline grid on
the next page, `\parskip` is not charged inside the paragraph, and only a
single unsplittable line is allowed to overflow at the top of a page.
paragraph does not fit on the page it is split at line boundaries
(`Paragraph::split_at`): the fragment keeps its baseline grid on the next
page, `\parskip` is not charged inside the paragraph, and only a single
unsplittable line is allowed to overflow at the top of a page. The scrolling
builder splits paragraphs directly; for the paged builder each paragraph
becomes one node per line joined by zero-width interline glue, so its page
breaks also land between lines with the same overflowing-line rule.
Remaining gaps are generic `fil`/`fill` glue orders outside
`\parfillskip` and `\prevgraf`.
@@ -358,7 +361,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 297 unit tests plus seven route-D integration tests and thirty oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 449 tests (297 route-D unit, 7 route-D integration, 30 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 12 binary units), with none ignored. v1 remains the live server path.
The crate currently has 298 unit tests plus seven route-D integration tests and thirty oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 450 tests (298 route-D unit, 7 route-D integration, 30 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 13 binary units), with none ignored. v1 remains the live server path.
### M0 incremental demo
@@ -393,8 +396,9 @@ deliberately open rather than approximated:
interline glue, the default `\sfcode`/`\frenchspacing` sentence spacing,
explicit `\spaceskip`/`\xspaceskip`, stretch and shrink on the
inter-paragraph `\parskip` glue, and `\raggedright` (infinite `\rightskip` fil) are modelled.
- **M2**: the scrolling builder still drives `Document`; `page::PageBuilder`
implements TeX's candidate-breakpoint cost (badness + penalty, glue
- **M2**: `Engine::layout` keeps the scrolling builder as the non-paged
fallback, while route-D previews and PDFs run `Engine::layout_paged`;
`page::PageBuilder` implements TeX's candidate-breakpoint cost (badness + penalty, glue
stretch/shrink, `\topskip`, `\maxdepth`); a break at glue is only legal
when it follows a non-discardable item, so glue after glue is not a
breakpoint and the glue at a break is discarded and `Engine::layout_paged` runs it