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();