Read output penalty and page number in the output routine
This commit is contained in:
1 parent
4bec90cf8c
commit
a2a2eafab5
6 files changed
+243
-47
No files matched your search
@@ -70,6 +70,9 @@ pub struct PageFragment {
|
||||
pub end: usize,
|
||||
/// TeX's page cost for the breakpoint: badness plus penalty.
|
||||
pub cost: i64,
|
||||
/// Penalty that produced this break: a forced penalty value, the chosen
|
||||
/// candidate's penalty, or zero for the final page.
|
||||
pub penalty: i64,
|
||||
/// Badness of the page height against the page goal.
|
||||
pub badness: i64,
|
||||
/// Height of the page box after glue setting.
|
||||
@@ -89,6 +92,7 @@ struct Candidate {
|
||||
depth: i64,
|
||||
shrink: i64,
|
||||
reserved: i64,
|
||||
penalty: i64,
|
||||
end: usize,
|
||||
next: usize,
|
||||
}
|
||||
@@ -198,7 +202,8 @@ impl PageBuilder {
|
||||
height,
|
||||
depth,
|
||||
badness,
|
||||
badness + penalty,
|
||||
badness + *penalty,
|
||||
*penalty,
|
||||
self.insertion_space(nodes, start, end, held),
|
||||
);
|
||||
return Some((
|
||||
@@ -239,6 +244,7 @@ impl PageBuilder {
|
||||
best.depth,
|
||||
best.badness,
|
||||
best.cost,
|
||||
best.penalty,
|
||||
self.insertion_space(nodes, start, best.end, held),
|
||||
);
|
||||
Some((
|
||||
@@ -311,6 +317,7 @@ impl PageBuilder {
|
||||
let badness = self.badness(height, reserved, stretch, shrink);
|
||||
Candidate {
|
||||
cost: badness + penalty,
|
||||
penalty,
|
||||
badness,
|
||||
height,
|
||||
depth,
|
||||
@@ -352,12 +359,14 @@ impl PageBuilder {
|
||||
depth: i64,
|
||||
badness: i64,
|
||||
cost: i64,
|
||||
penalty: i64,
|
||||
insertions: Vec<InsertionSpace>,
|
||||
) -> PageFragment {
|
||||
PageFragment {
|
||||
start,
|
||||
end,
|
||||
cost,
|
||||
penalty,
|
||||
badness,
|
||||
height,
|
||||
depth,
|
||||
@@ -400,6 +409,16 @@ mod tests {
|
||||
VerticalNode::Glue(VerticalGlue::new(width, stretch, shrink))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forced_penalty_breaks_record_the_penalty() {
|
||||
let builder = PageBuilder::new(100);
|
||||
let nodes = vec![box_(20, 0), VerticalNode::Penalty(-10_000), box_(20, 0)];
|
||||
let pages = builder.build(&nodes);
|
||||
assert_eq!(pages.len(), 2);
|
||||
assert_eq!(pages[0].penalty, -10_000);
|
||||
assert_eq!(pages[1].penalty, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn breaks_before_the_page_overflows() {
|
||||
let builder = PageBuilder::new(100);
|
||||
|
||||
Reference in new issue
Block a user