Rebuild paged documents that defer bottom floats
This commit is contained in:
1 parent
4dd28b3aa7
commit
66b2ccf380
3 files changed
+53
-5
No files matched your search
@@ -2434,6 +2434,15 @@ impl Engine {
|
||||
let Some((nodes, owners, node_items)) = document_nodes(document) else {
|
||||
return false;
|
||||
};
|
||||
if nodes
|
||||
.iter()
|
||||
.any(|node| matches!(node, VerticalNode::BottomFloat { .. }))
|
||||
{
|
||||
// A bottom float that did not fit is carried on the fragment, and a
|
||||
// suffix rebuild starting from a page boundary cannot recover that
|
||||
// queue. Rebuild the whole paged document instead of misplacing it.
|
||||
return false;
|
||||
}
|
||||
let Some(mut first_node) = owners.iter().position(|owner| *owner >= unit_index) else {
|
||||
return false;
|
||||
};
|
||||
@@ -6520,6 +6529,45 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_edit_with_bottom_floats_rebuilds_with_the_float_queue() {
|
||||
let style = ParagraphStyle {
|
||||
line_width: 100 * 65_536,
|
||||
line_height: 12 * 65_536,
|
||||
..ParagraphStyle::default()
|
||||
};
|
||||
let paragraph = |id, text: &str| {
|
||||
Unit::paragraph_with_style_and_face(id, text, style.clone(), ParagraphFont::Roman)
|
||||
};
|
||||
let mut document = Document::new(
|
||||
40 * 65_536,
|
||||
vec![
|
||||
paragraph(1, "alpha"),
|
||||
paragraph(2, "beta"),
|
||||
Unit::float(3, FloatPlacement::Bottom, 100, 20 * 65_536),
|
||||
paragraph(4, "gamma"),
|
||||
],
|
||||
);
|
||||
document.text_float_sep = 0;
|
||||
let mut engine = Engine::layout_paged(&document).expect("bottom floats are page-buildable");
|
||||
let total = engine.pages().len();
|
||||
assert_eq!(total, 2, "the float should be deferred to the second page");
|
||||
|
||||
let mut edited = document.clone();
|
||||
edited.units[3] = paragraph(4, "delta");
|
||||
engine.edit(&edited, 4, "delta");
|
||||
assert_eq!(
|
||||
engine.recomputed_pages(),
|
||||
total,
|
||||
"the queue must force a full rebuild"
|
||||
);
|
||||
|
||||
let fresh = Engine::layout_paged(&edited).expect("paged");
|
||||
let hashes: Vec<_> = engine.pages().iter().map(|page| page.hash).collect();
|
||||
let fresh_hashes: Vec<_> = fresh.pages().iter().map(|page| page.hash).collect();
|
||||
assert_eq!(hashes, fresh_hashes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_layout_places_top_floats() {
|
||||
let document = Document::new(
|
||||
|
||||
Reference in new issue
Block a user