Compose: a line past the breaker's estimated wrap segments is re-broken for its segment

On narrow segments beside an object, the breaker's estimate of the segments ran out; the lines
after it were set for the whole column and placed in one segment, running across the object.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
moppeeerandClaude Opus 5.5 committed 2026-10-16 09:47:56 +02:00
1 parent a97bd20a68
commit c708b08033
2 files changed
+28 -1

No files matched your search

+3 -1
View File
@@ -1268,7 +1268,9 @@ fn compose_with_db(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &C
// paragraph from here, starting with this line's segments as they are. A pass
// re-breaks at its first line only for a new line, whose segments it carries, so
// every re-break makes progress; their number is capped too.
if (k > 0 || !continues) && rebreaks < 256 && slots.get(k).is_some_and(|&(a, b)| ((b - a) - (x1 - x0)).abs() > 0.5) {
// Past the estimated slots the breaker set the line for the whole column.
let (sa, sb) = slots.get(k).copied().unwrap_or((col.x0, col.x1));
if (k > 0 || !continues) && rebreaks < 256 && ((sb - sa) - (x1 - x0)).abs() > 0.5 {
rebreaks += 1;
carry.insert(0, (x0, x1));
if !continues {
+25
View File
@@ -1155,3 +1155,28 @@ fn a_line_fits_when_its_baseline_does() {
assert!(!overset(&mut s, 78.5), "the line is set; its descenders hang below the frame");
assert!(overset(&mut s, 50.0), "a baseline below the frame still oversets the line");
}
/// Beside an object with text on both sides, every line stays within its segment, however many
/// lines the paragraph needs (the breaker's segment estimate can run out on narrow segments; a
/// line it set for the whole column ran across the object).
#[test]
fn every_line_beside_a_wrap_stays_within_its_segment() {
let mut s = Session::new();
s.execute("file.new", &json!({"facingPages": false})).unwrap();
// Placeholder text: paragraphs of a few sentences, some of them starting beside the object.
let t = s.execute("frame.create", &json!({"rect": [36, 36, 576, 756], "content": "text", "text": ""})).unwrap();
s.execute("type.fillWithPlaceholder", &json!({})).unwrap();
s.execute("selection.set", &json!({"ids": []})).unwrap();
s.execute("frame.create", &json!({"rect": [196, 160, 416, 490]})).unwrap();
s.execute("object.textWrap", &json!({"mode": "boundingBox", "offset": 6})).unwrap();
let d = &s.doc().unwrap().doc;
let c = s.cache.get(d, designcraft_doc::StoryId(t["story"].as_u64().unwrap()), None);
let mut beside = 0;
for l in c.frames.iter().flat_map(|f| &f.lines) {
let end = l.glyphs.iter().filter(|g| g.visible).map(|g| g.x + g.adv).fold(l.x0, f64::max);
assert!(end <= l.x1 + 0.5, "line at {} runs to {end}, past its segment {}..{}", l.baseline, l.x0, l.x1);
beside += usize::from(l.x1 < 400.0 || l.x0 > 400.0);
}
assert!(beside > 20, "lines on both sides of the object: {beside}");
}