Carry output-routine marks onto the following page
This commit is contained in:
1 parent
d4906a3cc5
commit
91171f2a90
4 files changed
+56
-9
No files matched your search
@@ -1524,6 +1524,7 @@ struct PagedOutput {
|
||||
skips: [i64; 256],
|
||||
initial_dimens: Vec<(u8, i64)>,
|
||||
initial_skips: Vec<(u8, i64)>,
|
||||
pending_marks: Vec<String>,
|
||||
}
|
||||
|
||||
impl PagedOutput {
|
||||
@@ -1551,6 +1552,7 @@ impl PagedOutput {
|
||||
skips,
|
||||
initial_dimens,
|
||||
initial_skips,
|
||||
pending_marks: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1588,6 +1590,7 @@ impl PagedOutput {
|
||||
insertion_counts: self.counts,
|
||||
insertion_dimens: self.dimens,
|
||||
insertion_skips: self.skips,
|
||||
output_marks: Vec::new(),
|
||||
pageno: self.pageno,
|
||||
deadcycles: self.deadcycles,
|
||||
prev_graf: page_prev_graf(page),
|
||||
@@ -1605,6 +1608,7 @@ impl PagedOutput {
|
||||
self.counts = context.insertion_counts;
|
||||
self.dimens = context.insertion_dimens;
|
||||
self.skips = context.insertion_skips;
|
||||
self.pending_marks = std::mem::take(&mut context.output_marks);
|
||||
self.goal = context.vsize.max(1);
|
||||
self.pageno = context.pageno.wrapping_add(1);
|
||||
self.deadcycles = context.deadcycles;
|
||||
@@ -2192,6 +2196,7 @@ impl Engine {
|
||||
let mut pages = Vec::new();
|
||||
let mut held: BTreeMap<u8, Vec<VerticalItem>> = BTreeMap::new();
|
||||
let mut fragments = builder.build_with_deferred_bottom_floats(&nodes);
|
||||
let mut carried_marks: Vec<String> = Vec::new();
|
||||
let mut page_index = 0;
|
||||
while page_index < fragments.len() {
|
||||
let fragment = fragments[page_index].clone();
|
||||
@@ -2271,6 +2276,14 @@ impl Engine {
|
||||
Self::set_page_glue(&mut items, fragment);
|
||||
let mut page = Page::empty();
|
||||
page.items = items;
|
||||
if !carried_marks.is_empty() {
|
||||
let mut marks_with_carry: Vec<Mark> = std::mem::take(&mut carried_marks)
|
||||
.into_iter()
|
||||
.map(|text| Mark { class: 0, text })
|
||||
.collect();
|
||||
marks_with_carry.append(&mut marks);
|
||||
marks = marks_with_carry;
|
||||
}
|
||||
page.marks = marks;
|
||||
page.floats = floats;
|
||||
let reserved: i64 = insertions.values().map(|insertion| insertion.height).sum();
|
||||
@@ -2300,6 +2313,10 @@ impl Engine {
|
||||
if shipped {
|
||||
pages.push(page);
|
||||
}
|
||||
carried_marks = routine
|
||||
.as_ref()
|
||||
.map(|active| active.pending_marks.clone())
|
||||
.unwrap_or_default();
|
||||
if let Some(active) = routine.as_ref() {
|
||||
let goal = active.goal;
|
||||
let has_bottom_float = nodes
|
||||
@@ -2559,6 +2576,7 @@ impl Engine {
|
||||
insertion_counts,
|
||||
insertion_dimens,
|
||||
insertion_skips,
|
||||
output_marks: Vec::new(),
|
||||
prev_graf: page_prev_graf(&page),
|
||||
insert_penalties: 0,
|
||||
pageno,
|
||||
@@ -3447,6 +3465,25 @@ mod tests {
|
||||
assert_eq!(counts, vec![3, 2, 2], "pages: {counts:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_marks_reach_the_following_page() {
|
||||
let mut units = Vec::new();
|
||||
for step in 0..3_u64 {
|
||||
units.push(Unit::rule(step * 2, 300, 600));
|
||||
if step < 2 {
|
||||
units.push(Unit::vskip(step * 2 + 1, 0));
|
||||
}
|
||||
}
|
||||
let mut document = Document::new(1000, units);
|
||||
document.top_skip = 0;
|
||||
document.output_routine = Some(r"\mark{carried}\shipout\box255".to_owned());
|
||||
let engine = Engine::layout_paged(&document).expect("paged");
|
||||
assert_eq!(engine.layout.pages.len(), 3);
|
||||
assert!(engine.layout.pages[0].marks.is_empty());
|
||||
assert_eq!(engine.layout.pages[1].marks[0].text, "carried");
|
||||
assert_eq!(engine.layout.pages[1].marks[0].class, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_can_advance_vsize_for_later_pages() {
|
||||
let mut units = Vec::new();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
use std::fmt;
|
||||
|
||||
/// Page registers visible to the output routine.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct OutputContext {
|
||||
/// TeX `\pagegoal`: the goal the current page was built for.
|
||||
pub page_goal: i64,
|
||||
@@ -59,6 +59,8 @@ pub struct OutputContext {
|
||||
pub insertion_dimens: [i64; 256],
|
||||
/// TeX `\skip<n>` for insertion class `n`.
|
||||
pub insertion_skips: [i64; 256],
|
||||
/// `\mark{...}` texts written by the routine; they reach later pages.
|
||||
pub output_marks: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for OutputContext {
|
||||
@@ -87,6 +89,7 @@ impl Default for OutputContext {
|
||||
insertion_counts: [1000; 256],
|
||||
insertion_dimens: [0; 256],
|
||||
insertion_skips: [0; 256],
|
||||
output_marks: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,6 +155,7 @@ enum Op {
|
||||
Shipout,
|
||||
Relax,
|
||||
Message(String),
|
||||
Mark(String),
|
||||
IfDim {
|
||||
left: Dimension,
|
||||
relation: Relation,
|
||||
@@ -516,10 +520,11 @@ fn parse_sequence(tokens: &[Token], index: &mut usize, stop: &[&str]) -> Result<
|
||||
*index += 1;
|
||||
ops.push(Op::Relax);
|
||||
}
|
||||
"message" => {
|
||||
"message" | "mark" => {
|
||||
let op_name = name.to_owned();
|
||||
*index += 1;
|
||||
if !matches!(tokens.get(*index), Some(Token::Open)) {
|
||||
return Err("\\message expects a braced argument".to_owned());
|
||||
return Err(format!("\\{op_name} expects a braced argument"));
|
||||
}
|
||||
*index += 1;
|
||||
let mut text = String::new();
|
||||
@@ -535,7 +540,11 @@ fn parse_sequence(tokens: &[Token], index: &mut usize, stop: &[&str]) -> Result<
|
||||
}
|
||||
}
|
||||
}
|
||||
ops.push(Op::Message(text));
|
||||
ops.push(if op_name == "mark" {
|
||||
Op::Mark(text)
|
||||
} else {
|
||||
Op::Message(text)
|
||||
});
|
||||
}
|
||||
"advance" | "multiply" | "divide" => {
|
||||
*index += 1;
|
||||
@@ -872,6 +881,7 @@ fn execute(ops: &[Op], context: &mut OutputContext, shipped: &mut usize) -> Resu
|
||||
match op {
|
||||
Op::Shipout => *shipped += 1,
|
||||
Op::Relax | Op::Message(_) => {}
|
||||
Op::Mark(text) => context.output_marks.push(text.clone()),
|
||||
Op::IfDim {
|
||||
left,
|
||||
relation,
|
||||
|
||||
Reference in new issue
Block a user