Cap page depth at Document max_depth
This commit is contained in:
1 parent
9599982b91
commit
169119a48d
5 files changed
+66
-10
No files matched your search
@@ -8,7 +8,6 @@
|
||||
//! `Engine`; wiring this module into `Document` is the next P2 step.
|
||||
|
||||
use crate::Mark;
|
||||
use std::cmp::Reverse;
|
||||
|
||||
/// Vertical glue with the stretch and shrink TeX uses to set a page.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -250,7 +249,7 @@ impl PageBuilder {
|
||||
feasible
|
||||
};
|
||||
pool.into_iter()
|
||||
.min_by_key(|candidate| (candidate.cost, Reverse(candidate.height)))
|
||||
.min_by_key(|candidate| (candidate.cost, (candidate.height - self.page_goal).abs()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,6 +346,25 @@ mod tests {
|
||||
assert_eq!(pages[0].depth, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overfull_pages_take_the_least_overfull_break() {
|
||||
let builder = PageBuilder::new(50);
|
||||
let nodes = [
|
||||
VerticalNode::Box {
|
||||
height: 60,
|
||||
depth: 0,
|
||||
},
|
||||
VerticalNode::Glue(VerticalGlue::new(0, 0, 0)),
|
||||
VerticalNode::Box {
|
||||
height: 40,
|
||||
depth: 0,
|
||||
},
|
||||
];
|
||||
let pages = builder.build(&nodes);
|
||||
assert_eq!(pages.len(), 2);
|
||||
assert_eq!(pages[0].height, 60, "the shorter overfull page wins");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_do_not_change_page_heights() {
|
||||
let builder = PageBuilder::new(100);
|
||||
|
||||
Reference in new issue
Block a user