Paint route-D float placeholders at page edges

This commit is contained in:
gloamxun committed 2026-10-20 18:20:32 +08:00
1 parent 6e1ee13d68
commit af50f1afa1
3 files changed
+86 -1

No files matched your search

+36
View File
@@ -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 {
+48 -1
View File
@@ -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()
+2
View File
@@ -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.