Break pages only at legal glue points
This commit is contained in:
1 parent
247cbf2b9e
commit
2b2ccd511c
4 files changed
+71
-9
No files matched your search
@@ -404,7 +404,13 @@ impl PageBuilder {
|
||||
float_total += 1;
|
||||
}
|
||||
VerticalNode::Glue(glue) => {
|
||||
if index > start {
|
||||
// TeX only allows a break at glue that follows a
|
||||
// non-discardable item: glue after glue is not a legal
|
||||
// breakpoint, and the glue at a break is discarded rather
|
||||
// than counted towards the page height.
|
||||
let legal_break =
|
||||
index > start && !matches!(nodes[index - 1], VerticalNode::Glue(_));
|
||||
if legal_break {
|
||||
candidates.push(self.candidate(
|
||||
height,
|
||||
depth,
|
||||
|
||||
@@ -764,6 +764,60 @@ fn pages_break_like_pdftex_with_paragraph_spacing() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pages_respect_stretchy_vertical_glue_like_pdftex() {
|
||||
let paragraphs: Vec<String> = (0..100)
|
||||
.map(|index| format!("p{index} alpha beta gamma"))
|
||||
.collect();
|
||||
let body: String = paragraphs
|
||||
.iter()
|
||||
.map(|paragraph| format!("{paragraph}\\par\\vskip 20pt plus 40pt minus 5pt\n"))
|
||||
.collect();
|
||||
let source = format!(
|
||||
"\\documentclass[10pt]{{article}}\n\
|
||||
\\pdfpagewidth=612bp \\pdfpageheight=792bp\n\
|
||||
\\pagestyle{{empty}}\n\
|
||||
\\begin{{document}}\n\
|
||||
\\hsize=345pt \\parindent=15pt \\parskip=0pt \\topskip=12pt \\vsize=550pt\n\
|
||||
{body}\\end{{document}}\n"
|
||||
);
|
||||
let Some(reference) = pdftex_pages(&source) else {
|
||||
eprintln!("skipping: pdflatex/pdftotext are not installed");
|
||||
return;
|
||||
};
|
||||
let mut units = Vec::new();
|
||||
for text in ¶graphs {
|
||||
let style = ParagraphStyle {
|
||||
line_width: 345 * PT,
|
||||
par_indent: 15 * PT,
|
||||
line_height: 12 * PT,
|
||||
..ParagraphStyle::default()
|
||||
};
|
||||
let mut unit = Unit::paragraph_with_style(units.len() as u64 + 1, text, style);
|
||||
if !units.is_empty() {
|
||||
unit.space_before = 20 * PT;
|
||||
unit.space_stretch = 40 * PT;
|
||||
unit.space_shrink = 5 * PT;
|
||||
}
|
||||
units.push(unit);
|
||||
}
|
||||
let mut document = Document::new(550 * PT, units);
|
||||
document.top_skip = 12 * PT;
|
||||
document.text_float_sep = 0;
|
||||
let engine = Engine::layout_paged(&document).expect("paged layout");
|
||||
let ours: Vec<String> = engine.pages().iter().map(page_alnum_text).collect();
|
||||
assert_eq!(
|
||||
ours.len(),
|
||||
reference.len(),
|
||||
"route-D produced {} pages, pdfLaTeX {}",
|
||||
ours.len(),
|
||||
reference.len()
|
||||
);
|
||||
for (index, (ours, reference)) in ours.iter().zip(&reference).enumerate() {
|
||||
assert_eq!(ours, reference, "text on page {}", index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pages_break_like_pdftex_on_a_shorter_page() {
|
||||
let paragraphs: Vec<String> = (0..80)
|
||||
|
||||
@@ -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`). 445 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 446 workspace tests are green and no oracle
|
||||
fixture is ignored.
|
||||
|
||||
Known gaps, in dependency order:
|
||||
@@ -301,9 +301,9 @@ interpreter past the shipout/ifdim/ifnum/ifodd/ifcase subset.
|
||||
|
||||
Acceptance: 10 page fixtures (article text, footnotes, floats, forced breaks);
|
||||
page counts identical and first/last baselines within 1pt of pdfLaTeX.
|
||||
Progress: four page fixtures are wired (single-line paragraphs, `\parskip=6pt`
|
||||
spacing, multi-line paragraphs split across pages, and `\newpage` forced
|
||||
breaks); each asserts the same
|
||||
Progress: five page fixtures are wired (single-line paragraphs, `\parskip=6pt`
|
||||
spacing, multi-line paragraphs split across pages, `\newpage` forced breaks,
|
||||
and stretchy `\vskip` glue between paragraphs); each asserts the same
|
||||
page count and the same per-page text as pdfLaTeX.
|
||||
|
||||
### P3 — `\halign` / `\valign` (L2)
|
||||
|
||||
+6
-4
@@ -355,7 +355,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 296 unit tests plus seven route-D integration tests and twenty-eight oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 445 tests (296 route-D unit, 7 route-D integration, 28 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 296 unit tests plus seven route-D integration tests and twenty-nine oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 446 tests (296 route-D unit, 7 route-D integration, 29 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 12 binary units), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
@@ -383,15 +383,17 @@ 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**: generic `fil`/`fill` glue orders and
|
||||
`\prevgraf` are still open; the tolerance, penalty and demerit registers,
|
||||
- **M1**: the paragraph model covers generic `fil`/`fill` glue orders and
|
||||
`\prevgraf`, plus the tolerance, penalty and demerit registers,
|
||||
`\hyphenation` exceptions, `\hangindent`/`\parshape`, `\parfillskip` with
|
||||
or without `fil`, `\looseness`, `\baselineskip`/`\lineskip`/`\parskip`
|
||||
interline glue, the default `\sfcode`/`\frenchspacing` sentence spacing,
|
||||
explicit `\spaceskip`/`\xspaceskip`, 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
|
||||
stretch/shrink, `\topskip`, `\maxdepth`) and `Engine::layout_paged` runs it
|
||||
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
|
||||
for simple documents; `PageBuilder::ragged_bottom` selects `\raggedbottom`
|
||||
(the default) or `\flushbottom`, which stretches `VerticalItem::StretchGlue`
|
||||
in proportion to its stretch so the page body reaches the goal (only shrink
|
||||
|
||||
Reference in new issue
Block a user