Reduce page goal by reserved insertion space
This commit is contained in:
1 parent
a4388942f0
commit
c54a56ad36
3 files changed
+52
-8
No files matched your search
@@ -1731,6 +1731,7 @@ impl Engine {
|
||||
let mut page_fill_stretches = Vec::new();
|
||||
let mut page_filll_stretches = Vec::new();
|
||||
let mut page_shrinks = Vec::new();
|
||||
let mut page_goals: Vec<i64> = Vec::new();
|
||||
let mut held: BTreeMap<u8, Vec<VerticalItem>> = BTreeMap::new();
|
||||
let fragments = builder.build(&nodes);
|
||||
for fragment in &fragments {
|
||||
@@ -1794,6 +1795,8 @@ impl Engine {
|
||||
page.items = items;
|
||||
page.marks = marks;
|
||||
page.floats = floats;
|
||||
let reserved: i64 = insertions.values().map(|insertion| insertion.height).sum();
|
||||
page_goals.push((document.page_goal - reserved).max(0));
|
||||
page.insertions = insertions.into_values().collect();
|
||||
page.sources = sources;
|
||||
page.seal_in_place();
|
||||
@@ -1824,6 +1827,8 @@ impl Engine {
|
||||
}
|
||||
}
|
||||
let mut page = Page::empty();
|
||||
let reserved: i64 = insertions.values().map(|insertion| insertion.height).sum();
|
||||
page_goals.push((document.page_goal - reserved).max(0));
|
||||
page.insertions = insertions.into_values().collect();
|
||||
page.seal_in_place();
|
||||
pages.push(page);
|
||||
@@ -1841,7 +1846,7 @@ impl Engine {
|
||||
for (index, page) in pages.into_iter().enumerate() {
|
||||
let page_total: i64 = page.items.iter().map(item_height).sum();
|
||||
let context = output::OutputContext {
|
||||
page_goal: document.page_goal,
|
||||
page_goal: page_goals.get(index).copied().unwrap_or(document.page_goal),
|
||||
page_total,
|
||||
page_depth: page_depths.get(index).copied().unwrap_or(0),
|
||||
page_stretch: page_stretches.get(index).copied().unwrap_or(0),
|
||||
@@ -2651,6 +2656,43 @@ mod tests {
|
||||
assert_eq!(result.layout.pages[1].insertions.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_sees_page_goal_after_insertion_reservation() {
|
||||
let scale = 65_536;
|
||||
let mut document = Document::new(
|
||||
200 * scale,
|
||||
vec![
|
||||
Unit::rule(1, 0, 40 * scale),
|
||||
Unit::insertion(
|
||||
2,
|
||||
0,
|
||||
40 * scale,
|
||||
vec![VerticalItem::Rule {
|
||||
width: 0,
|
||||
height: 40 * scale,
|
||||
}],
|
||||
),
|
||||
Unit::rule(3, 0, 40 * scale),
|
||||
],
|
||||
);
|
||||
document.insertion_classes = vec![InsertionClass {
|
||||
number: 0,
|
||||
fraction_percent: 100,
|
||||
max_height: None,
|
||||
skip: None,
|
||||
multiplier: 1000,
|
||||
}];
|
||||
document.output_routine =
|
||||
Some(r"\ifdim\pagegoal<195pt\ifdim\pagetotal>79pt\shipout\box255\fi\fi".to_owned());
|
||||
let engine = Engine::layout_paged(&document).expect("paged");
|
||||
assert_eq!(engine.pages().len(), 1);
|
||||
|
||||
document.units.remove(1);
|
||||
document.output_routine = Some(r"\ifdim\pagegoal<195pt\shipout\box255\fi".to_owned());
|
||||
let engine = Engine::layout_paged(&document).expect("paged");
|
||||
assert!(engine.pages().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_can_force_an_early_page_break() {
|
||||
struct BreakAfterTwo {
|
||||
|
||||
Reference in new issue
Block a user