Paint a footnote separator above insertions

This commit is contained in:
gloamxun committed 2026-10-20 18:19:42 +08:00
1 parent 493180125a
commit 6e1ee13d68
3 files changed
+54

No files matched your search

+32
View File
@@ -1372,6 +1372,38 @@ mod tests {
)));
}
#[test]
fn footnote_separator_sits_above_the_insertion_area() {
let page = Page {
items: vec![
VerticalItem::Box(VerticalBox {
width: 100 * 65_536,
height: 100 * 65_536,
}),
VerticalItem::Insertion(Insertion {
class: 0,
height: 20 * 65_536,
items: vec![VerticalItem::Rule {
width: 100 * 65_536,
height: 2 * 65_536,
}],
}),
],
insertions: Vec::new(),
marks: Vec::new(),
floats: Vec::new(),
sources: Vec::new(),
hash: 0,
};
let list = page.display_list_with_goal(700 * 65_536);
let separator = list.items.iter().find_map(|item| match item {
crate::render::DisplayItem::Rule { y, width, .. } if *width == 40 * 65_536 => Some(*y),
_ => None,
});
let y = separator.expect("separator rule");
assert!(y > 690 * 65_536);
assert!(y < 700 * 65_536);
}
#[test]
fn insertion_material_sits_at_the_page_bottom() {
let page = Page {
+20
View File
@@ -238,6 +238,17 @@ impl Page {
pub fn display_list_with_goal(&self, page_goal: i64) -> DisplayList {
let mut list = DisplayList::default();
let mut y = 0_i64;
let body_width = self
.items
.iter()
.map(|item| match item {
VerticalItem::Halign(halign) => halign.width,
VerticalItem::Rule { width, .. } => *width,
VerticalItem::Box(box_) => box_.width,
_ => 0,
})
.max()
.unwrap_or(0);
let items: Vec<VerticalItem> = self
.items
.iter()
@@ -336,6 +347,15 @@ impl Page {
};
insertion_list.place(0, top);
let width = insertion_list.width.max(list.width);
if page_goal > 0 && top > y + 26_214 {
let separator_width = (body_width * 2 / 5).max(65_536);
list.push(DisplayItem::Rule {
x: 0,
y: top - 26_214,
width: separator_width,
height: 26_214,
});
}
y = top + insertion_list.height;
list.items.extend(insertion_list.items);
list.images.extend(insertion_list.images);