Ship float-heavy pages without body material
This commit is contained in:
1 parent
594a57e414
commit
66dfb10b60
4 files changed
+82
-4
No files matched your search
@@ -159,6 +159,9 @@ pub struct PageBuilder {
|
||||
pub bottom_number: usize,
|
||||
/// TeX `\totalnumber`: maximum floats, of any placement, on one page.
|
||||
pub total_number: usize,
|
||||
/// TeX `\floatpagefraction`: percent of the page floats must occupy
|
||||
/// before the body is pushed to the next page.
|
||||
pub float_page_fraction_percent: u8,
|
||||
/// TeX `\raggedbottom` (default) versus `\flushbottom`.
|
||||
pub ragged_bottom: bool,
|
||||
}
|
||||
@@ -176,6 +179,7 @@ impl PageBuilder {
|
||||
top_number: 2,
|
||||
bottom_number: 1,
|
||||
total_number: 12,
|
||||
float_page_fraction_percent: 50,
|
||||
ragged_bottom: true,
|
||||
}
|
||||
}
|
||||
@@ -263,6 +267,37 @@ impl PageBuilder {
|
||||
height: box_height,
|
||||
depth: box_depth,
|
||||
} => {
|
||||
// TeX ships a page that is mostly floats on its own; the
|
||||
// body starts on the next page instead of sharing it.
|
||||
if has_float
|
||||
&& !has_body
|
||||
&& height * 100
|
||||
>= i64::from(self.float_page_fraction_percent) * self.page_goal
|
||||
{
|
||||
let end = index.max(start);
|
||||
let badness =
|
||||
self.badness(height, reserved + bottom, stretch, shrink, stretch_order);
|
||||
let fragment = self.fragment(
|
||||
start,
|
||||
end,
|
||||
height,
|
||||
depth,
|
||||
stretch,
|
||||
shrink,
|
||||
stretch_order,
|
||||
badness,
|
||||
badness,
|
||||
0,
|
||||
bottom,
|
||||
order_stretches(&nodes[start..end]),
|
||||
self.insertion_space(nodes, start, end, held),
|
||||
);
|
||||
return Some((
|
||||
fragment,
|
||||
index,
|
||||
self.insertion_overflow(nodes, start, end, held),
|
||||
));
|
||||
}
|
||||
let contribution = if first_box {
|
||||
(*box_height).max(self.top_skip)
|
||||
+ if has_float {
|
||||
@@ -1035,6 +1070,26 @@ mod tests {
|
||||
assert_eq!(pages[1].bottom, 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_page_fraction_pushes_the_body_to_the_next_page() {
|
||||
let nodes = vec![
|
||||
VerticalNode::Float { height: 60 },
|
||||
VerticalNode::Box {
|
||||
height: 10,
|
||||
depth: 0,
|
||||
},
|
||||
];
|
||||
let mut builder = PageBuilder::new(100);
|
||||
builder.float_page_fraction_percent = 50;
|
||||
let pages = builder.build(&nodes);
|
||||
assert_eq!(pages.len(), 2);
|
||||
assert_eq!((pages[0].start, pages[0].end), (0, 1));
|
||||
assert_eq!(pages[1].start, 1);
|
||||
|
||||
builder.float_page_fraction_percent = 90;
|
||||
assert_eq!(builder.build(&nodes).len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bottom_fraction_caps_bottom_float_space() {
|
||||
let builder = PageBuilder {
|
||||
|
||||
Reference in new issue
Block a user