Compare commits

...
Author SHA1 Message Date
autocraft-bot[bot] 8460bff5c7 Merge main (8d75a12b) into the pull request
Resolved both conflicts and removed every marker.

Resolved both conflicts and removed every marker.
2026-12-03 20:43:42 +00:00
autocraft-bot[bot] f670da8602 Part 1: in crates/layout/src/floats.rs, the re-placement condition is no
Part 1: in crates/layout/src/floats.rs, the re-placement condition is now `float.y < 0.0 && area.map_or(r.bottom(), |(_, b)| b) < y0 + lead - 0.5`. Floats without a wrap area (in front of or behind text) now need a negative offset and to sit above the pushed first line, like wrapping floats. A positive-offset label over a top-and-bottom picture is no longer moved down. fmt --check and clippy -D warnings are clean. In `cargo test -p wordcraft-layout`, 756 passed and 1 failed: the timing test a_megabyte_long_word_lays_out_quickly, which has no floats and failed again alone after 244 s. I think the sandbox is slow, but I didn't run it on the base commit. I didn't add a test for the label-over-picture case.
2026-12-02 20:00:12 +00:00
jayzed80 4e79e67534 Merge remote-tracking branch 'upstream/main' into HEAD
# Conflicts:
#	crates/layout/src/tests.rs
2026-11-18 21:15:56 +00:00
jayzed80 50041c808c Address review: keep a re-placed float's x, and don't move a wrap area onto the first line (#6567)
A float placed again from a pushed-down first line takes only its new
vertical position, so its drawn rect and wrap area stay together across.
A wrapping float whose moved area would reach the first line stays where
it was: that line was laid out without it in the way.
2026-11-14 01:02:27 +00:00
jayzed80 c0c42caf95 Layout: measure sibling paragraph floats from a wrapped first line (#6567) 2026-11-14 00:13:46 +00:00
2 changed files with 110 additions and 5 deletions
+44 -5
View File
@@ -483,6 +483,7 @@ fn anchor_floats_but(
ctx.fields.page_format = pb.page_format;
let (col_x, width) = (pb.col_x(), pb.col_w());
let mut rects = HashMap::new();
let mut areas = HashMap::new();
if !pb.web && place {
// (A mark from a page before may be short of the areas this page started with.)
pb.excl.truncate(excl_mark.max(pb.seeded));
@@ -519,20 +520,58 @@ fn anchor_floats_but(
// with it known from the start (#2048).
let above = area.as_ref().filter(|a| text_before && a.0.y < top - 0.5).map(|a| (page, a.clone()));
ctx.floats_above.insert((block, oi), above);
if let Some(area) = area {
match early.and_then(|v| v.iter().position(|(b, k, _)| (*b, *k) == (block, oi))).filter(|k| *k < pb.seeded) {
let slot = if let Some(area) = area {
let b = area.0.bottom();
let k = match early.and_then(|v| v.iter().position(|(b, k, _)| (*b, *k) == (block, oi))).filter(|k| *k < pb.seeded) {
Some(k) => {
if let Some(slot) = pb.excl.get_mut(k) {
*slot = area;
}
k
}
None => pb.excl.push(area),
}
}
None => {
let k = pb.excl.len();
pb.excl.push(area);
k
}
};
Some((k, b))
} else {
None
};
areas.insert(oi, slot);
}
}
let rel = rel_exclusions(&body_wraps(ctx, pb), col_x, y0, before);
let pl = ctx.para_labelled(p, width, None, &rel, before, label.clone());
let lead = pl.lines.first().map_or(0.0, |l| l.top.max(0.0));
if !pb.web && place && lead > 0.0 {
let page = pb.pages.len().saturating_sub(1);
let top = y0 - before;
let text_before = top > pb.top + 0.5 || pb.col > 0;
let frame = PageFrame { sect: pb.sect, margin_top: None, origin: (0.0, 0.0), number: pb.number, mirror: ctx.mirror };
for (oi, o) in p.objects.iter().enumerate() {
let Some((_, _, float)) = floating(o) else { continue };
let Some(&area) = areas.get(&oi) else { continue };
let Some(&r) = rects.get(&oi) else { continue };
if float.y < 0.0 && area.map_or(r.bottom(), |(_, b)| b) < y0 + lead - 0.5 {
// Only down: across it stays where it was placed (`settle_early` may have moved it).
let moved = Rect { y: float_rect(Some(frame), (col_x, width), top + lead, r.w, r.h, float).y, ..r };
// A wrap area moved onto the first line would cover text laid out without it.
if area.is_some_and(|(_, b)| b + (moved.y - r.y) > y0 + lead - 0.5) {
continue;
}
rects.insert(oi, moved);
if let Some((k, _)) = area
&& let Some(slot) = pb.excl.get_mut(k)
{
slot.0.y += moved.y - r.y;
let above = (text_before && slot.0.y < top - 0.5).then(|| (page, slot.clone()));
ctx.floats_above.insert((block, oi), above);
}
}
}
}
(rects, pl, rel)
}
+66
View File
@@ -19106,6 +19106,72 @@ fn turned_cell_float_keeps_its_along_text_offset() {
}
}
/// #6567: when a wrapping float (such as a page-tall `wrapTopAndBottom` frame) pushes its anchor
/// paragraph's first line to the bottom of the page, sibling paragraph-relative floats with
/// negative vertical offsets are measured from the displaced paragraph line rather than placed
/// above the page from the pre-wrap origin.
#[test]
fn negative_offset_floats_in_a_paragraph_pushed_down_by_a_wrapping_float_stay_on_the_page() {
use wordcraft_doc::para::{Anchor, Float, FloatAlign, Wrap};
let mut doc = Document::from_text("");
doc.last_section.page_w = 595.3;
doc.last_section.page_h = 841.9;
let mut para = Paragraph::new();
let title = Float {
wrap: Wrap::InFrontOfText,
h_rel: Anchor::Margin,
h_align: Some(FloatAlign::Center),
v_rel: Anchor::Paragraph,
y: -652.55,
..Default::default()
};
let row = Float { wrap: Wrap::InFrontOfText, h_rel: Anchor::Column, v_rel: Anchor::Paragraph, x: 36.0, y: -460.75, ..Default::default() };
let frame = Float { wrap: Wrap::TopAndBottom, h_rel: Anchor::Column, v_rel: Anchor::Paragraph, y: -43.11, ..Default::default() };
para.insert_object(para.len(), rect_shape(378.5, 105.75, title), &Default::default()).unwrap();
para.insert_object(para.len(), rect_shape(194.55, 38.45, row), &Default::default()).unwrap();
para.insert_object(para.len(), rect_shape(556.46, 802.52, frame), &Default::default()).unwrap();
doc.body = vec![wordcraft_doc::para_block(para)];
let l = lay(&doc);
assert_eq!(l.pages.len(), 1);
let placed = shapes(&l.pages[0].items);
assert_eq!(placed.len(), 3, "{placed:?}");
let frame_rect = placed.iter().find(|r| (r.h - 802.52).abs() < 0.1).unwrap();
let title_rect = placed.iter().find(|r| (r.h - 105.75).abs() < 0.1).unwrap();
let row_rect = placed.iter().find(|r| (r.h - 38.45).abs() < 0.1).unwrap();
let line_top = first_line_top(&l.pages[0].items);
assert!((frame_rect.y - (72.0 - 43.11)).abs() < 0.5, "frame stays at the top of the page: {frame_rect:?}");
assert!((title_rect.y - (line_top - 652.55)).abs() < 0.5, "title measured from displaced line {line_top}: {title_rect:?}");
assert!((row_rect.y - (line_top - 460.75)).abs() < 0.5, "row measured from displaced line {line_top}: {row_rect:?}");
assert!(title_rect.y > frame_rect.y && row_rect.bottom() < frame_rect.bottom(), "{placed:?}");
}
/// #6567 review: a wrapping float above its paragraph that would land on the first line when
/// placed from it again isn't moved there: that line was laid out without it in the way.
#[test]
fn a_wrapping_float_isnt_moved_onto_a_first_line_laid_out_without_it() {
crate::test_fonts();
use wordcraft_doc::para::{Anchor, Float, Wrap};
let mut doc = Document::from_text("Words in the first line of the paragraph.");
let frame = Float { wrap: Wrap::TopAndBottom, h_rel: Anchor::Column, v_rel: Anchor::Paragraph, ..Default::default() };
let square = Float { wrap: Wrap::Square, h_rel: Anchor::Column, v_rel: Anchor::Paragraph, y: -10.0, ..Default::default() };
doc.insert_object(&Pos::body(0, 0), rect_shape(150.0, 50.0, square), &Default::default()).unwrap();
doc.insert_object(&Pos::body(0, 0), rect_shape(200.0, 100.0, frame), &Default::default()).unwrap();
let l = lay(&doc);
let items = &l.pages[0].items;
let square = shapes(items).into_iter().find(|r| (r.h - 50.0).abs() < 0.1).unwrap();
let (x, y, height) = items
.iter()
.find_map(|i| match i {
Placed::Lines { x, y, para, story: StoryRef::Body, .. } => para.lines.first().map(|l| (*x + l.left, *y, l.height)),
_ => None,
})
.unwrap();
assert!(y > 72.0 + 99.0, "the frame pushes the first line down: {y}");
let overlaps = square.y < y + height && square.bottom() > y && square.x < x + 1.0 && square.right() > x;
assert!(!overlaps, "the float {square:?} covers the first line's text at ({x}, {y})");
}
/// A caption kept with the next paragraph (`keepNext`) before a table goes over with the table
/// when the table's repeated header row and the start of its first row don't fit under it, as in
/// Word, instead of staying alone at the foot of the page: keep with next asked a table for a