From 6e1ee13d687119a6198e549133b17f66c7434e93 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 18:19:42 +0800 Subject: [PATCH] Paint a footnote separator above insertions --- crates/texrra-tex-core/src/lib.rs | 32 ++++++++++++++++++++++++++++ crates/texrra-tex-core/src/render.rs | 20 +++++++++++++++++ docs/TEX_CORE.md | 2 ++ 3 files changed, 54 insertions(+) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 14163fc..904c439 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -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 { diff --git a/crates/texrra-tex-core/src/render.rs b/crates/texrra-tex-core/src/render.rs index 1ed877f..128abe3 100755 --- a/crates/texrra-tex-core/src/render.rs +++ b/crates/texrra-tex-core/src/render.rs @@ -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 = 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); diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 86f3fd8..acc74e2 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -261,3 +261,5 @@ M7 (partial): DisplayList::special injects raw PDF content-stream operators; SVG M2 (partial): insertion material is expanded into the page display list at its reserved position, so footnote/float material is no longer dropped by the painter; page-bottom placement and rules remain to be modelled. M2 (partial): Page::display_list_with_goal places insertion material at page_goal minus its height; page builders can pass the real goal. Footnote rules and float-page policy remain. + +M2 (partial): a 0.4pt rule at 40% of the body width is painted above insertion material when a page goal is supplied.