From fb22be1a49081c48debf43b9c054bfb1d0514774 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 18:37:25 +0800 Subject: [PATCH] Carry vertical content on route-D floats --- crates/texrra-tex-core/src/lib.rs | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 9ede6bd..369a866 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -189,6 +189,9 @@ pub struct Float { pub placement: FloatPlacement, pub width: i64, pub height: i64, + /// Vertical material carried by the float. Empty for a dimension-only float. + #[serde(default)] + pub content: Vec, } #[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] @@ -382,10 +385,26 @@ impl Unit { placement, width, height, + content: Vec::new(), })], ) } + /// Build a float that carries vertical material. + pub fn float_with_content( + id: UnitId, + placement: FloatPlacement, + width: i64, + height: i64, + content: Vec, + ) -> Self { + let mut unit = Self::float(id, placement, width, height); + if let Some(VerticalItem::Float(float)) = unit.items.first_mut() { + float.content = content; + } + unit + } + /// A vertical penalty item, corresponding to `\penalty`. pub fn penalty(id: UnitId, value: i64) -> Self { Self::vertical(id, vec![VerticalItem::Penalty(value)]) @@ -1266,6 +1285,7 @@ mod tests { placement: FloatPlacement::Top, width: 40, height: 20, + content: Vec::new(), }), VerticalItem::Box(VerticalBox { width: 10, @@ -1295,6 +1315,7 @@ mod tests { placement: FloatPlacement::Bottom, width: 40, height: 30, + content: Vec::new(), }), VerticalItem::Box(VerticalBox { width: 10, @@ -1461,11 +1482,13 @@ mod tests { placement: FloatPlacement::Top, width: 50 * 65_536, height: 15 * 65_536, + content: Vec::new(), }, Float { placement: FloatPlacement::Bottom, width: 60 * 65_536, height: 10 * 65_536, + content: Vec::new(), }, ], sources: Vec::new(), @@ -1780,6 +1803,27 @@ mod tests { assert!(svg.contains(">A")); assert!(svg.contains("