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)
|
||||
|
||||
Reference in new issue
Block a user