Reserve textfloatsep between floats and body text

This commit is contained in:
gloamxun committed 2026-10-21 12:51:01 +08:00
1 parent 1014713ec0
commit 830e1f851b
4 files changed
+273 -24

No files matched your search

+26 -4
View File
@@ -312,13 +312,19 @@ impl Page {
/// Paint the page, placing insertion material at `page_goal` when it is
/// positive. A zero goal keeps insertion material in normal flow.
pub fn display_list_with_goal(&self, page_goal: i64) -> DisplayList {
self.display_list_with_layout(page_goal, 0)
}
/// Paint the page with TeX's `\textfloatsep` kept between body text and a
/// float area, matching the space the page builder reserved.
pub fn display_list_with_layout(&self, page_goal: i64, text_float_sep: i64) -> DisplayList {
let mut list = DisplayList::default();
let mut y;
let top_height: i64 = self
.floats
.iter()
.filter(|float| float.placement == FloatPlacement::Top)
.map(|float| float.height)
.map(|float| float.height + float.gap_before)
.sum();
let mut float_y = 0_i64;
for float in self
@@ -330,7 +336,22 @@ impl Page {
Self::paint_float(float, 0, float_y, &mut list);
float_y += float.height;
}
y = top_height;
let has_body = self.items.iter().any(|item| {
matches!(
item,
VerticalItem::Box(_)
| VerticalItem::Rule { .. }
| VerticalItem::Halign(_)
| VerticalItem::Paragraph(_)
| VerticalItem::Math { .. }
| VerticalItem::Glue(_)
)
});
y = if top_height > 0 && has_body {
top_height + text_float_sep.max(0)
} else {
top_height
};
let body_width = self
.items
.iter()
@@ -495,10 +516,11 @@ impl Page {
.floats
.iter()
.filter(|float| float.placement == FloatPlacement::Bottom)
.map(|float| float.height)
.map(|float| float.height + float.gap_before)
.sum();
if bottom_height > 0 {
let mut float_y = (page_goal - bottom_height).max(y);
let bottom_area = bottom_height + text_float_sep.max(0);
let mut float_y = (page_goal - bottom_area).max(y) + text_float_sep.max(0);
for float in self
.floats
.iter()