Ship the page after maxdeadcycles
This commit is contained in:
1 parent
8007fd1b6c
commit
4111080422
4 files changed
+84
-8
No files matched your search
@@ -673,6 +673,10 @@ pub struct Document {
|
||||
/// Extra vertical displacement of the page origin (`\voffset`).
|
||||
#[serde(default)]
|
||||
pub v_offset: i64,
|
||||
/// TeX `\maxdeadcycles`: how many pages the output routine may decline to
|
||||
/// ship before TeX ships the page itself. Defaults to 25.
|
||||
#[serde(default = "default_max_deadcycles")]
|
||||
pub max_deadcycles: i64,
|
||||
/// TeX `\output` token list, interpreted by [`output::OutputProgram`].
|
||||
/// `None` ships every page the builder produces.
|
||||
#[serde(default)]
|
||||
@@ -731,6 +735,10 @@ fn default_total_number() -> u8 {
|
||||
12
|
||||
}
|
||||
|
||||
fn default_max_deadcycles() -> i64 {
|
||||
25
|
||||
}
|
||||
|
||||
impl Document {
|
||||
pub fn new(page_goal: i64, units: Vec<Unit>) -> Self {
|
||||
Self {
|
||||
@@ -757,6 +765,7 @@ impl Document {
|
||||
par_skip: 0,
|
||||
h_offset: 0,
|
||||
v_offset: 0,
|
||||
max_deadcycles: default_max_deadcycles(),
|
||||
output_routine: None,
|
||||
}
|
||||
}
|
||||
@@ -1972,6 +1981,7 @@ impl Engine {
|
||||
top_skip: document.top_skip,
|
||||
max_depth: document.max_depth,
|
||||
output_penalty: page_penalties.get(index).copied().unwrap_or(10_000),
|
||||
max_deadcycles: document.max_deadcycles,
|
||||
insertion_counts,
|
||||
insertion_dimens,
|
||||
insertion_skips,
|
||||
@@ -1979,7 +1989,15 @@ impl Engine {
|
||||
deadcycles,
|
||||
prev_graf: page_prev_graf(&page),
|
||||
};
|
||||
let shipped_now = program.shipout_count(&mut context).ok()?;
|
||||
let forced = deadcycles >= document.max_deadcycles.max(0);
|
||||
if forced {
|
||||
context.deadcycles = 0;
|
||||
}
|
||||
let shipped_now = if forced {
|
||||
1
|
||||
} else {
|
||||
program.shipout_count(&mut context).ok()?
|
||||
};
|
||||
insertion_counts = context.insertion_counts;
|
||||
insertion_dimens = context.insertion_dimens;
|
||||
insertion_skips = context.insertion_skips;
|
||||
@@ -2162,6 +2180,7 @@ impl Engine {
|
||||
top_skip: document.top_skip,
|
||||
max_depth: document.max_depth,
|
||||
output_penalty: fragment.penalty,
|
||||
max_deadcycles: document.max_deadcycles,
|
||||
insertion_counts,
|
||||
insertion_dimens,
|
||||
insertion_skips,
|
||||
@@ -2169,7 +2188,15 @@ impl Engine {
|
||||
pageno,
|
||||
deadcycles,
|
||||
};
|
||||
let shipped = program.shipout_count(&mut context).ok()?;
|
||||
let forced = deadcycles >= document.max_deadcycles.max(0);
|
||||
if forced {
|
||||
context.deadcycles = 0;
|
||||
}
|
||||
let shipped = if forced {
|
||||
1
|
||||
} else {
|
||||
program.shipout_count(&mut context).ok()?
|
||||
};
|
||||
insertion_counts = context.insertion_counts;
|
||||
insertion_dimens = context.insertion_dimens;
|
||||
insertion_skips = context.insertion_skips;
|
||||
@@ -6015,6 +6042,35 @@ mod tests {
|
||||
assert_eq!(item_height(&engine.pages()[0].items[0]), 70 * pt);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn max_deadcycles_forces_a_page_out() {
|
||||
let document_with = |limit: i64| {
|
||||
let mut document = Document::new(
|
||||
100,
|
||||
vec![
|
||||
Unit::rule(1, 10, 90),
|
||||
Unit::penalty(2, -10_000),
|
||||
Unit::rule(3, 10, 90),
|
||||
Unit::penalty(4, -10_000),
|
||||
Unit::rule(5, 10, 90),
|
||||
Unit::penalty(6, -10_000),
|
||||
Unit::rule(7, 10, 90),
|
||||
],
|
||||
);
|
||||
document.output_routine = Some(r"\relax".into());
|
||||
document.max_deadcycles = limit;
|
||||
document
|
||||
};
|
||||
// With the default limit no page is ever shipped.
|
||||
let idle = Engine::layout_paged(&document_with(25)).expect("paged layout");
|
||||
assert_eq!(idle.pages().len(), 0);
|
||||
// After two dead cycles TeX ships the third page itself, then the
|
||||
// fourth page starts a fresh dead cycle and is dropped too.
|
||||
let forced = Engine::layout_paged(&document_with(2)).expect("paged layout");
|
||||
assert_eq!(forced.pages().len(), 1);
|
||||
assert_eq!(item_height(&forced.pages()[0].items[0]), 90);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_register_assignments_persist_across_pages() {
|
||||
let mut document = Document::new(
|
||||
|
||||
Reference in new issue
Block a user