Support hang indentation and parshape measures

This commit is contained in:
gloamxun committed 2026-10-23 01:18:19 +08:00
1 parent 24a96d1c7c
commit 8993186005
7 files changed
+269 -88

No files matched your search

+12 -8
View File
@@ -48,16 +48,16 @@ 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`). 289 workspace tests are green and no oracle
PDF opt-in with `?engine=route-d`). 293 workspace tests are green and no oracle
fixture is ignored.
Known gaps, in dependency order:
1. paragraph breaking reproduces TeX's passes and demerits (including
`\adjdemerits`, `\doublehyphendemerits`, `\finalhyphendemerits`,
`\hyphenpenalty`, `\exhyphenpenalty` and `\hyphenation` exceptions), but
not yet `\parshape`, `\looseness`, `\hangindent`, spacefactor or
`\parfillskip`/fil glue orders;
`\hyphenpenalty`, `\exhyphenpenalty`, `\hyphenation` exceptions and
`\hangindent`/`\hangafter`/`\parshape` line geometry), but not yet
`\looseness`, spacefactor or `\parfillskip`/fil glue orders;
2. the page builder is a scrolling builder with fraction policies, not a TeX
page builder with badness and an interpreted `\output`;
3. `\insert` classes are data structures, not TeX registers and an output
@@ -179,10 +179,14 @@ and `\finalhyphendemerits` all affect the chosen solution, and
`\hyphenation` exceptions are inserted into the pattern trie (unit-tested by
counting the discretionary points they add).
Still open: `\parfillskip`/fil glue orders, `\hangindent`/`\parshape`/
`\looseness`, spacefactor/`\sfcode`, vertical-list skips
(`\baselineskip`, `\lineskip`, `\parskip`), double/final hyphen demerit
oracle fixtures, and more width fixtures.
`\hangindent`/`\hangafter` and `\parshape` now drive each line's measure
and left offset; the DP remembers a candidate's line number so the geometry can
vary per line, and a 120pt oracle fixture checks every line origin against
pdfLaTeX.
Still open: `\parfillskip`/fil glue orders, `\looseness`, spacefactor/
`\sfcode`, vertical-list skips (`\baselineskip`, `\lineskip`, `\parskip`),
double/final hyphen demerit oracle fixtures, and more width fixtures.
### P2 — Vertical list, page builder, `\output` (L2)
+15 -10
View File
@@ -71,7 +71,9 @@ the fallback here mirrors that choice by taking the longest prefix within
tolerance and otherwise the first prefix that overflows. Justification
stretches normal glue past its nominal stretch (badness simply exceeds 100)
and clamps shrink at the declared limit, so overfull lines stay overfull
exactly as in TeX. The bounds and hyphen demerits are `ParagraphStyle`
exactly as in TeX. Each line can take its measure and left offset from
`\hangindent`/`\hangafter` or an explicit `\parshape` list; the display list
honours the same offsets. The bounds and hyphen demerits are `ParagraphStyle`
fields mirroring `\pretolerance`, `\tolerance`, `\hyphenpenalty` and
`\exhyphenpenalty`, `\linepenalty`, `\adjdemerits`,
`\doublehyphendemerits`, `\finalhyphendemerits` and `\emergencystretch`,
@@ -84,7 +86,9 @@ horizontally. The narrow measures exercise hyphenated and overfull breaks,
150pt the final-pass overfull box, and 180-240pt ordinary tolerance
solutions. Two further fixtures pin register behaviour at 120pt:
`\pretolerance=10000` stops before hyphenation and `\hyphenpenalty=10000`
inhibits it, leaving the overfull first-fit lines TeX produces. `route_d_multiline_bands_track_pdftex` rasterizes the same
inhibits it, leaving the overfull first-fit lines TeX produces. A 120pt
fixture with `\hangindent=20pt \hangafter=1` checks every line origin
against pdfLaTeX as well as the word positions inside each line. `route_d_multiline_bands_track_pdftex` rasterizes the same
paragraph in both engines and compares ink bands, covering baseline placement
and justification.
@@ -116,9 +120,10 @@ and justification.
- The M1 paragraph builder parses CMR10 TFM metrics (widths, height/depth,
italic correction, kern pairs, ligatures), applies TeX Live's en-US
hyphenation patterns and runs TeX's tolerance passes with demerits. The
tolerance bounds, break penalties and flagged demerits are modelled, and
`\hyphenation` exceptions are inserted into the pattern trie. Remaining gaps
are `\looseness`, `\parshape`, `\hangindent`, spacefactor/`\sfcode`,
tolerance bounds, break penalties and flagged demerits are modelled,
`\hyphenation` exceptions are inserted into the pattern trie, and
`\hangindent`/`\hangafter`/`\parshape` change each line's measure and left
offset. Remaining gaps are `\looseness`, spacefactor/`\sfcode`,
`\parfillskip`/fil glue orders, and the vertical-list skips
(`\baselineskip`, `\lineskip`, `\parskip`).
@@ -292,7 +297,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 181 unit tests plus six route-D integration tests and five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 289 tests (181 route-D unit, 6 route-D integration, 5 oracle, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
The crate currently has 184 unit tests plus six route-D integration tests and six oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 293 tests (184 route-D unit, 6 route-D integration, 6 oracle, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
### M0 incremental demo
@@ -320,10 +325,10 @@ The staged program that closes these milestones is described in
Route D currently covers M0-M4/M6 as a working subset. The remaining milestones are
deliberately open rather than approximated:
- **M1**: `\parshape`, `\looseness`, `\hangindent`, spacefactor/`\sfcode`,
`\parfillskip`/fil glue orders and the vertical-list skips are still open;
the tolerance, penalty and demerit registers plus `\hyphenation` exceptions
are modelled.
- **M1**: `\looseness`, spacefactor/`\sfcode`, `\parfillskip`/fil glue orders
and the vertical-list skips are still open; the tolerance, penalty and demerit
registers, `\hyphenation` exceptions, and `\hangindent`/`\parshape` are
modelled.
- **M5**: `cmr10.tfm` is parsed at runtime with widths, glyph heights/depths and kern pairs. only used text faces embed Liberation Serif/Mono as Type0/Identity-H; each face is subset to the glyphs actually used (composite components included, glyph IDs retained); FontFile2 and ToUnicode streams use Flate compression; the ToUnicode CMap follows the used characters; ff/fi/fl/ffi/ffl ligatures come from TFM, and CMR10 italic corrections are applied at line ends; full NFSS family switching is not implemented.
- **M6**: `\output`, `\insert`, mark/float output policies, class-file execution and
math limit policies are only partially modeled; `OutputRoutine::wants_break` can force a page break between units, and insertion material is stacked by class from the page bottom; `\output` is still Rust code rather than interpreted tokens.