Add a penalty constructor for vertical breaks
This commit is contained in:
1 parent
b17e16df08
commit
51d65e6fad
2 files changed
+22
No files matched your search
@@ -300,6 +300,11 @@ impl Unit {
|
||||
Self::halign(id, rows, column_count, intercolumn)
|
||||
}
|
||||
|
||||
/// A vertical penalty item, corresponding to `\penalty`.
|
||||
pub fn penalty(id: UnitId, value: i64) -> Self {
|
||||
Self::vertical(id, vec![VerticalItem::Penalty(value)])
|
||||
}
|
||||
|
||||
/// A vertical glue item, corresponding to `\vskip`.
|
||||
pub fn vskip(id: UnitId, height: i64) -> Self {
|
||||
Self::vertical(id, vec![VerticalItem::Glue(height)])
|
||||
@@ -1222,6 +1227,21 @@ mod tests {
|
||||
assert_eq!(halign.cell_box(2, 0), Some((30, 110)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forced_penalty_between_boxes_starts_a_page() {
|
||||
let block = |id| {
|
||||
Unit::vertical(
|
||||
id,
|
||||
vec![VerticalItem::Box(VerticalBox {
|
||||
width: 100,
|
||||
height: 30,
|
||||
})],
|
||||
)
|
||||
};
|
||||
let document = Document::new(100, vec![block(1), Unit::penalty(2, -10_000), block(3)]);
|
||||
let engine = Engine::layout(&document);
|
||||
assert_eq!(engine.pages().len(), 2);
|
||||
}
|
||||
#[test]
|
||||
fn vskip_consumes_vertical_space() {
|
||||
let block = |id| {
|
||||
|
||||
@@ -210,3 +210,5 @@ for a later overlaid slash.
|
||||
`\boxed{x}` adds 3pt padding around its body in the math model.
|
||||
|
||||
`Unit::vskip(id, height)` adds a vertical glue item to the page list.
|
||||
|
||||
`Unit::penalty(id, value)` adds a vertical penalty; values <= -10000 force a page break.
|
||||
Reference in new issue
Block a user