From af50f1afa18083eb448565aec42a5fb3dbf15535 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 18:20:32 +0800 Subject: [PATCH] Paint route-D float placeholders at page edges --- crates/texrra-tex-core/src/lib.rs | 36 ++++++++++++++++++++ crates/texrra-tex-core/src/render.rs | 49 +++++++++++++++++++++++++++- docs/TEX_CORE.md | 2 ++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 904c439..3e029f3 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -1372,6 +1372,42 @@ mod tests { ))); } + #[test] + fn float_placeholders_are_painted_at_page_edges() { + let page = Page { + items: vec![VerticalItem::Box(VerticalBox { + width: 100 * 65_536, + height: 20 * 65_536, + })], + insertions: Vec::new(), + marks: Vec::new(), + floats: vec![ + Float { + placement: FloatPlacement::Top, + width: 50 * 65_536, + height: 15 * 65_536, + }, + Float { + placement: FloatPlacement::Bottom, + width: 60 * 65_536, + height: 10 * 65_536, + }, + ], + sources: Vec::new(), + hash: 0, + }; + let list = page.display_list_with_goal(700 * 65_536); + assert!(list.items.iter().any(|item| matches!( + item, + crate::render::DisplayItem::Rule { y, width, height, .. } + if *y == 0 && *width == 50 * 65_536 && *height == 15 * 65_536 + ))); + assert!(list.items.iter().any(|item| matches!( + item, + crate::render::DisplayItem::Rule { y, width, height, .. } + if *y == 690 * 65_536 && *width == 60 * 65_536 && *height == 10 * 65_536 + ))); + } #[test] fn footnote_separator_sits_above_the_insertion_area() { let page = Page { diff --git a/crates/texrra-tex-core/src/render.rs b/crates/texrra-tex-core/src/render.rs index 128abe3..499835b 100755 --- a/crates/texrra-tex-core/src/render.rs +++ b/crates/texrra-tex-core/src/render.rs @@ -7,7 +7,7 @@ use crate::cmr10::Cmr10Metrics; use crate::math::{self, MathAtom}; -use crate::{Halign, HorizontalItem, Page, VerticalItem}; +use crate::{FloatPlacement, Halign, HorizontalItem, Page, VerticalItem}; /// One absolute drawing primitive in scaled points. #[derive(Clone, Debug, PartialEq, Eq)] @@ -238,6 +238,27 @@ impl Page { pub fn display_list_with_goal(&self, page_goal: i64) -> DisplayList { let mut list = DisplayList::default(); let mut y = 0_i64; + let top_height: i64 = self + .floats + .iter() + .filter(|float| float.placement == FloatPlacement::Top) + .map(|float| float.height) + .sum(); + let mut float_y = 0_i64; + for float in self + .floats + .iter() + .filter(|float| float.placement == FloatPlacement::Top) + { + list.push(DisplayItem::Rule { + x: 0, + y: float_y, + width: float.width, + height: float.height, + }); + float_y += float.height; + } + y = top_height; let body_width = self .items .iter() @@ -361,6 +382,32 @@ impl Page { list.images.extend(insertion_list.images); list.width = list.width.max(width); } + if page_goal > 0 { + let bottom_height: i64 = self + .floats + .iter() + .filter(|float| float.placement == FloatPlacement::Bottom) + .map(|float| float.height) + .sum(); + if bottom_height > 0 { + let mut float_y = (page_goal - bottom_height).max(y); + for float in self + .floats + .iter() + .filter(|float| float.placement == FloatPlacement::Bottom) + { + list.push(DisplayItem::Rule { + x: 0, + y: float_y, + width: float.width, + height: float.height, + }); + float_y += float.height; + list.width = list.width.max(float.width); + } + y = y.max(float_y); + } + } list.width = list.width.max( self.items .iter() diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index acc74e2..02577bd 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -263,3 +263,5 @@ M2 (partial): insertion material is expanded into the page display list at its r 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. + +M2 (partial): top and bottom float placeholders are painted at the page edges in display lists; real float material and float-page fractions remain.