Reject overfull lines outside the emergency pass

This commit is contained in:
gloamxun committed 2026-10-23 03:17:25 +08:00
1 parent 47ef33c536
commit c8805af755
3 files changed
+34 -6

No files matched your search

+27
View File
@@ -557,6 +557,13 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
} else {
badness
};
// A line that cannot fit even after shrinking its glue is
// overfull. TeX only admits such lines in the emergency
// pass, no matter how large \tolerance is.
let overfull = natural > target && natural - target > shrink;
if overfull && pass != 2 {
continue;
}
if badness > limit {
continue;
}
@@ -1356,6 +1363,26 @@ mod tests {
assert!(paragraph.lines.len() > 1);
}
#[test]
fn tolerance_does_not_admit_overfull_lines() {
let font = crate::cmr10::Cmr10Metrics::default();
let style = ParagraphStyle {
line_width: 75 * 65_536,
par_indent: 0,
tolerance: 10_000,
..ParagraphStyle::default()
};
let paragraph = layout_paragraph_with_font(
"hyphenation hyphenation hyphenation hyphenation hyphenation",
&style,
&font,
);
assert!(
paragraph.lines.len() > 1,
"an overfull single line must not satisfy \\tolerance"
);
}
#[test]
fn double_hyphen_becomes_one_en_dash_box() {
let font = crate::cmr10::Cmr10Metrics::new();
+6 -5
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`). 352 workspace tests are green and no oracle
PDF opt-in with `?engine=route-d`). 353 workspace tests are green and no oracle
fixture is ignored.
Known gaps, in dependency order:
@@ -224,10 +224,11 @@ top of a page (see `Paragraph::split_at`).
Still open: generic `fil`/`fill` glue orders, `\prevgraf`, explicit
`\vskip` classes (`\smallskip` and friends),
double/final hyphen demerit oracle fixtures. Default-register probes show no
sensitivity to `\finalhyphendemerits`; forcing `\tolerance=10000` makes
pdfLaTeX hyphenate where our DP keeps one overfull line, so the demerit
fixtures need that divergence explained first.
double/final hyphen demerit oracle fixtures. The breaker now rejects overfull
lines outside the emergency pass, exactly like TeX, so `\tolerance` cannot
smuggle in a single overfull line any more; at `\tolerance=10000` the line
count matches pdfLaTeX but the first line boundary still differs, so the
demerit fixtures stay open until that trade-off is understood.
### P2 — Vertical list, page builder, `\output` (L2)
+1 -1
View File
@@ -332,7 +332,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 234 unit tests plus seven route-D integration tests and thirteen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 352 tests (234 route-D unit, 7 route-D integration, 13 oracle, 71 v1 integration, 20 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
The crate currently has 235 unit tests plus seven route-D integration tests and thirteen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 353 tests (235 route-D unit, 7 route-D integration, 13 oracle, 71 v1 integration, 20 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
### M0 incremental demo