Honour forced vertical penalties in the M0 page builder
This commit is contained in:
1 parent
19ecb7fdc6
commit
252963f0fa
2 files changed
+54
-5
No files matched your search
@@ -164,7 +164,19 @@ impl Engine {
|
||||
current.items.push(item.clone());
|
||||
}
|
||||
}
|
||||
VerticalItem::Penalty(_) => {}
|
||||
VerticalItem::Penalty(penalty) => {
|
||||
if *penalty <= -10_000 && !current.items.is_empty() {
|
||||
pages.push(std::mem::replace(
|
||||
&mut current,
|
||||
Page {
|
||||
items: Vec::new(),
|
||||
sources: Vec::new(),
|
||||
hash: 0,
|
||||
},
|
||||
));
|
||||
used = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,7 +240,8 @@ impl Engine {
|
||||
.iter()
|
||||
.map(|item| match item {
|
||||
VerticalItem::Box(vertical_box) => vertical_box.height,
|
||||
VerticalItem::Glue(height) | VerticalItem::Penalty(height) => *height,
|
||||
VerticalItem::Glue(height) => *height,
|
||||
VerticalItem::Penalty(_) => 0,
|
||||
})
|
||||
.sum();
|
||||
if checkpoint.used + edited_height > next.page_goal && !checkpoint.page_items.is_empty() {
|
||||
@@ -277,7 +290,19 @@ impl Engine {
|
||||
current.items.push(item.clone());
|
||||
}
|
||||
}
|
||||
VerticalItem::Penalty(_) => {}
|
||||
VerticalItem::Penalty(penalty) => {
|
||||
if *penalty <= -10_000 && !current.items.is_empty() {
|
||||
pages.push(std::mem::replace(
|
||||
&mut current,
|
||||
Page {
|
||||
items: Vec::new(),
|
||||
sources: Vec::new(),
|
||||
hash: 0,
|
||||
},
|
||||
));
|
||||
used = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,6 +376,29 @@ mod tests {
|
||||
assert!(engine.recomputed_pages() >= 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vertical_penalty_can_force_a_page_break() {
|
||||
let unit = Unit {
|
||||
id: 0,
|
||||
source: "penalty".to_owned(),
|
||||
items: vec![
|
||||
VerticalItem::Box(VerticalBox {
|
||||
width: 10,
|
||||
height: 10,
|
||||
}),
|
||||
VerticalItem::Penalty(-10_000),
|
||||
VerticalItem::Box(VerticalBox {
|
||||
width: 10,
|
||||
height: 10,
|
||||
}),
|
||||
],
|
||||
};
|
||||
let engine = Engine::layout(&Document::new(100, vec![unit]));
|
||||
assert_eq!(engine.layout.pages.len(), 2);
|
||||
assert_eq!(engine.layout.pages[0].items.len(), 1);
|
||||
assert_eq!(engine.layout.pages[1].items.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checkpoint_round_trips_through_serde() {
|
||||
let engine = Engine::layout(&document());
|
||||
|
||||
+3
-2
@@ -101,8 +101,9 @@ overfull ratio 4.11, badness 6942. TeX rejects the underfull candidate under
|
||||
its tolerance but still emits the moderately overfull 5-word line. Reproducing
|
||||
this needs a two-pass tolerance algorithm with an emergency overfull pass, not
|
||||
a single cost function.
|
||||
- Page breaking only handles vertical boxes/glue; vertical penalties are recorded
|
||||
but not interpreted.
|
||||
- Page breaking handles vertical boxes/glue and forced vertical penalties
|
||||
(`penalty <= -10000`); positive penalties are recorded but not yet part of
|
||||
page badness.
|
||||
- No macro state, output routine, math, fonts or PDF output in the new core yet.
|
||||
- The v1 server and project API still use `src/rust_typeset` and are unchanged.
|
||||
|
||||
|
||||
Reference in new issue
Block a user