Add mark and float constructors

This commit is contained in:
gloamxun committed 2026-10-20 13:34:09 +08:00
1 parent 30464dd214
commit 6116bf3553
2 files changed
+46

No files matched your search

+44
View File
@@ -300,6 +300,29 @@ impl Unit {
Self::halign(id, rows, column_count, intercolumn)
}
/// A running mark item, recorded on the page where it is shipped out.
pub fn mark(id: UnitId, class: u8, text: &str) -> Self {
Self::vertical(
id,
vec![VerticalItem::Mark(Mark {
class,
text: text.to_owned(),
})],
)
}
/// A top/bottom float item.
pub fn float(id: UnitId, placement: FloatPlacement, width: i64, height: i64) -> Self {
Self::vertical(
id,
vec![VerticalItem::Float(Float {
placement,
width,
height,
})],
)
}
/// A vertical penalty item, corresponding to `\penalty`.
pub fn penalty(id: UnitId, value: i64) -> Self {
Self::vertical(id, vec![VerticalItem::Penalty(value)])
@@ -1227,6 +1250,27 @@ mod tests {
assert_eq!(halign.cell_box(2, 0), Some((30, 110)));
}
#[test]
fn mark_and_float_constructors_build_page_items() {
let document = Document::new(
100,
vec![
Unit::mark(1, 0, "Intro"),
Unit::float(2, FloatPlacement::Top, 50, 20),
Unit::vertical(
3,
vec![VerticalItem::Box(VerticalBox {
width: 100,
height: 50,
})],
),
],
);
let engine = Engine::layout(&document);
assert_eq!(engine.pages().len(), 1);
assert_eq!(engine.pages()[0].marks[0].text, "Intro");
assert_eq!(engine.pages()[0].floats.len(), 1);
}
#[test]
fn forced_penalty_between_boxes_starts_a_page() {
let block = |id| {
+2
View File
@@ -239,3 +239,5 @@ v1 remains the production renderer; the route-D core is additive and tested inde
`\mathring{x}` is the U+030A ring accent.
`\overleftrightarrow` uses U+20E1.
`Unit::mark(id, class, text)` and `Unit::float(id, placement, width, height)` are convenience constructors for M2 page items.