Files
8b73226375 Newspaper columns keep a paragraph's last lines together, as Word does (#6828)
* Layout: balanced columns keep a continued paragraph's last lines together from Word 2013's layout

When the columns of a section's last page are balanced before a continuous
break, Word (compatibility mode 15) does not leave one line of a paragraph
alone in a column: the last two or three lines of a paragraph that began on the
page before, and a two- or three-line paragraph that begins the page, stay in
the first column that can hold them. settled_end only guarded a paragraph's
start, and skipped even that at the top of a column, so the balancing tries
split such lines one per column and the section came out a line short.

In mode 15, while balancing, widow/orphan control also applies at the top of a
column, a one-line fragment of a continued paragraph with more after it moves
on whole, and lines it moved go to the next column instead of overflowing.
Mode 14 and unbalanced flow are unchanged. Part of #6821 fix, measured in Word
with synthetic documents (see layout::tests::balanced_tail).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* Layout: balanced columns also keep kept paragraphs whole, and the lines are pinned beside notes and floats (#6821)

Measured in Word for Windows (synthetic documents, exact 14 pt lines, two and
three columns, compatibility mode 15): a paragraph with keep lines together, or
keep with next and the paragraph after it, stays whole in the first balanced
column; the tails and short paragraphs behave as before beside a footnote and a
square-wrapped picture; a section that starts and ends on one page, and plain
page flow with a footnote, widow control on and off, already matched.

keep_together now also applies at the top of a column while balancing in mode 15.
The move-on after widow/orphan control is taken only when that control, not a row
beside a floating object, moved the lines back (review of the first commit).
Tests added for notes, floats, a mid-page section, keep lines/next, unbalanced
columns and mode 14.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* Layout: balanced columns fall back to the old layout when the strict rules cannot fit, and keep paragraphs ask again at a column top (#6821)

Second review: pass(full) can now fail (a page whose columns are a couple of
lines high), so balance_columns lays the page out once more without the strict
rules of Word 2013's layout (PageBuilder::relaxed, kept across the snapshot
restore) instead of leaving a spilled pass. A paragraph moved to a column top
by the lines before it asks keep lines / keep with next again there, and keeps
going on to a column that holds it. Tests: the columns' left edges come from the
first page, a page too short for the rules keeps every line, docs reworded.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* Layout tests: classify columns by the declared column edges

The balanced-tail test helper took column edges from observed caret positions, so an empty middle column could be mistaken for the last one. The edges now come from the section geometry and keep every declared column.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* Layout: release floats when balancing moves their anchors (#6821)

Use the same overflow decision for line emission and for retaining late floats. Cover the strict widow control case and qualify the balancing evidence.

---------

Co-authored-by: vangel76 <[email protected]>
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Co-authored-by: Martin Ball <[email protected]>
2026-11-21 17:00:25 +00:00
..