FA-79991 / Typography line breaking / Open access
Widow and orphan page breaking: widow before orphan ordering · case 01
Curing a widow can create an orphan that is left on the page.
ROOT CAUSE
The orphan check runs before the widow adjustment, so a reduced opening is never rechecked.
VERIFIED REPAIR
Resolve widows first and then re-apply the orphan rule to the reduced amount.
Unsuccessful approach: Rechecking the orphan rule against the page room instead of the kept lines misses the new orphan.
Case contract
Input [paragraph line counts, page height, min orphan lines, min widow lines]. Lines flow onto pages. When a paragraph must break on a page that already holds lines, at least min widow lines must carry to the next page (move lines forward) and, if the paragraph starts on this page, at least min orphan lines must stay (else move it all). A paragraph that exactly fits stays. Constraints are waived on an empty page. Return lines per page.
Why this case matters
Line breaking decides where paragraphs wrap on screen and in print; a wrong decision point shifts every following line.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
paras, H, orphan, widow = x
pages = []
used = 0
for p in paras:
rem = p
started = True
while rem > 0:
room = H - used
if rem <= room:
used += rem
rem = 0
continue
a = room
if used > 0:
if started and a < orphan:
a = 0
if rem - a < widow:
a = max(rem - widow, 0)
used += a
rem -= a
if a > 0:
started = False
pages.append(used)
used = 0
if used > 0:
pages.append(used)
return pages
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: widow before orphan ordering', [[2, 2, 1, 1, 4, 8], 4, 2, 3], [4, 2, 4, 4, 4]), ('regression: widow before orphan ordering', [[3, 5, 5, 1, 7, 7, 3, 1], 4, 3, 3], [3, 4, 1, 4, 2, 4, 3, 4, 3, 4]), ('regression: widow before orphan ordering', [[9, 7, 4, 1, 2], 10, 2, 3], [9, 7, 7]), ('regression: widow before orphan ordering', [[5, 2, 7, 5, 9], 6, 3, 3], [5, 6, 3, 5, 6, 3]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[7, 1, 3, 8, 6, 3], 12, 3, 2], [11, 12, 5]), ('control layout', [[4, 1, 5], 9, 3, 1], [9, 1])], [('regression: widow before orphan ordering', [[1, 2, 8, 5, 8, 6, 7, 9], 7, 3, 3], [7, 4, 5, 7, 7, 7, 7, 2]), ('regression: widow before orphan ordering', [[7, 9, 3, 9, 7, 5], 5, 3, 3], [5, 5, 5, 4, 5, 4, 5, 2, 5]), ('regression: widow before orphan ordering', [[3, 4, 1], 6, 3, 3], [3, 5]), ('regression: widow before orphan ordering', [[2, 2, 5, 5, 7, 6, 4, 2], 8, 2, 3], [6, 8, 7, 6, 6]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('orphan pushed forward', [[5, 3], 6, 2, 2], [5, 3]), ('control layout', [[6, 3, 5, 3, 1, 6, 5, 7], 10, 2, 3], [9, 9, 8, 10]), ('control layout', [[2, 5, 2], 11, 3, 1], [9])], [('regression: widow before orphan ordering', [[7, 9, 3, 9, 7, 5], 5, 3, 3], [5, 5, 5, 4, 5, 4, 5, 2, 5]), ('regression: widow before orphan ordering', [[3, 4, 1], 6, 3, 3], [3, 5]), ('regression: widow before orphan ordering', [[3, 5, 5, 1, 7, 7, 3, 1], 4, 3, 3], [3, 4, 1, 4, 2, 4, 3, 4, 3, 4]), ('regression: widow before orphan ordering', [[2, 8, 4, 5, 9, 5, 8, 2], 9, 3, 3], [7, 7, 9, 5, 9, 6]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('orphan pushed forward', [[5, 3], 6, 2, 2], [5, 3]), ('control layout', [[7, 4, 1, 1, 2, 6], 6, 3, 2], [6, 6, 6, 3]), ('control layout', [[7, 8, 5, 1], 10, 1, 3], [10, 10, 1])], [('regression: widow before orphan ordering', [[2, 2, 5, 5, 7, 6, 4, 2], 8, 2, 3], [6, 8, 7, 6, 6]), ('regression: widow before orphan ordering', [[7, 6, 7, 4], 8, 2, 3], [7, 8, 5, 4]), ('regression: widow before orphan ordering', [[8, 4, 3, 3, 3, 1, 4], 5, 2, 2], [5, 5, 5, 3, 4, 4]), ('regression: widow before orphan ordering', [[2, 2, 1, 1, 4, 8], 4, 2, 3], [4, 2, 4, 4, 4]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('control layout', [[3, 3, 8, 5, 7, 7], 5, 1, 3], [3, 5, 5, 3, 5, 5, 5, 2]), ('control layout', [[6, 9, 7, 1, 7, 9, 8], 4, 3, 2], [4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1])], [('regression: widow before orphan ordering', [[9, 7, 4, 1, 2], 10, 2, 3], [9, 7, 7]), ('regression: widow before orphan ordering', [[2, 2, 5, 5, 7, 6, 4, 2], 8, 2, 3], [6, 8, 7, 6, 6]), ('regression: widow before orphan ordering', [[2, 2, 1, 1, 4, 8], 4, 2, 3], [4, 2, 4, 4, 4]), ('regression: widow before orphan ordering', [[5, 5, 9, 6, 5], 5, 3, 3], [5, 5, 5, 4, 5, 1, 5]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('control layout', [[2, 9, 5, 6, 7, 3, 5, 6], 9, 1, 2], [9, 9, 9, 8, 8]), ('control layout', [[2, 6, 6, 3, 7, 5], 11, 2, 1], [11, 11, 7])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: widow before orphan ordering | [4, 3, 3, 4, 4] | [4, 2, 4, 4, 4] | Failed |
| regression: widow before orphan ordering | [3, 4, 3, 4, 4, 3, 4, 3, 4] | [3, 4, 1, 4, 2, 4, 3, 4, 3, 4] | Failed |
| regression: widow before orphan ordering | [9, 8, 6] | [9, 7, 7] | Failed |
| regression: widow before orphan ordering | [5, 6, 5, 6, 6] | [5, 6, 3, 5, 6, 3] | Failed |
| single widow pulled back | [5, 2] | [5, 2] | Passed |
| long paragraph continuation | [6, 6, 4] | [6, 6, 4] | Passed |
| control layout | [11, 12, 5] | [11, 12, 5] | Passed |
| control layout | [9, 1] | [9, 1] | Passed |
SHA-256 / b3734dc6595a52e8517ba3407722b19294b25eea8e01091dc548466531800212
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
paras, H, orphan, widow = x
pages = []
used = 0
for p in paras:
rem = p
started = True
while rem > 0:
room = H - used
if rem <= room:
used += rem
rem = 0
continue
a = room
if used > 0:
if rem - a < widow:
a = max(rem - widow, 0)
if started and room < orphan:
a = 0
used += a
rem -= a
if a > 0:
started = False
pages.append(used)
used = 0
if used > 0:
pages.append(used)
return pages
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: widow before orphan ordering', [[2, 2, 1, 1, 4, 8], 4, 2, 3], [4, 2, 4, 4, 4]), ('regression: widow before orphan ordering', [[3, 5, 5, 1, 7, 7, 3, 1], 4, 3, 3], [3, 4, 1, 4, 2, 4, 3, 4, 3, 4]), ('regression: widow before orphan ordering', [[9, 7, 4, 1, 2], 10, 2, 3], [9, 7, 7]), ('regression: widow before orphan ordering', [[5, 2, 7, 5, 9], 6, 3, 3], [5, 6, 3, 5, 6, 3]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[7, 1, 3, 8, 6, 3], 12, 3, 2], [11, 12, 5]), ('control layout', [[4, 1, 5], 9, 3, 1], [9, 1])], [('regression: widow before orphan ordering', [[1, 2, 8, 5, 8, 6, 7, 9], 7, 3, 3], [7, 4, 5, 7, 7, 7, 7, 2]), ('regression: widow before orphan ordering', [[7, 9, 3, 9, 7, 5], 5, 3, 3], [5, 5, 5, 4, 5, 4, 5, 2, 5]), ('regression: widow before orphan ordering', [[3, 4, 1], 6, 3, 3], [3, 5]), ('regression: widow before orphan ordering', [[2, 2, 5, 5, 7, 6, 4, 2], 8, 2, 3], [6, 8, 7, 6, 6]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('orphan pushed forward', [[5, 3], 6, 2, 2], [5, 3]), ('control layout', [[6, 3, 5, 3, 1, 6, 5, 7], 10, 2, 3], [9, 9, 8, 10]), ('control layout', [[2, 5, 2], 11, 3, 1], [9])], [('regression: widow before orphan ordering', [[7, 9, 3, 9, 7, 5], 5, 3, 3], [5, 5, 5, 4, 5, 4, 5, 2, 5]), ('regression: widow before orphan ordering', [[3, 4, 1], 6, 3, 3], [3, 5]), ('regression: widow before orphan ordering', [[3, 5, 5, 1, 7, 7, 3, 1], 4, 3, 3], [3, 4, 1, 4, 2, 4, 3, 4, 3, 4]), ('regression: widow before orphan ordering', [[2, 8, 4, 5, 9, 5, 8, 2], 9, 3, 3], [7, 7, 9, 5, 9, 6]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('orphan pushed forward', [[5, 3], 6, 2, 2], [5, 3]), ('control layout', [[7, 4, 1, 1, 2, 6], 6, 3, 2], [6, 6, 6, 3]), ('control layout', [[7, 8, 5, 1], 10, 1, 3], [10, 10, 1])], [('regression: widow before orphan ordering', [[2, 2, 5, 5, 7, 6, 4, 2], 8, 2, 3], [6, 8, 7, 6, 6]), ('regression: widow before orphan ordering', [[7, 6, 7, 4], 8, 2, 3], [7, 8, 5, 4]), ('regression: widow before orphan ordering', [[8, 4, 3, 3, 3, 1, 4], 5, 2, 2], [5, 5, 5, 3, 4, 4]), ('regression: widow before orphan ordering', [[2, 2, 1, 1, 4, 8], 4, 2, 3], [4, 2, 4, 4, 4]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('control layout', [[3, 3, 8, 5, 7, 7], 5, 1, 3], [3, 5, 5, 3, 5, 5, 5, 2]), ('control layout', [[6, 9, 7, 1, 7, 9, 8], 4, 3, 2], [4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1])], [('regression: widow before orphan ordering', [[9, 7, 4, 1, 2], 10, 2, 3], [9, 7, 7]), ('regression: widow before orphan ordering', [[2, 2, 5, 5, 7, 6, 4, 2], 8, 2, 3], [6, 8, 7, 6, 6]), ('regression: widow before orphan ordering', [[2, 2, 1, 1, 4, 8], 4, 2, 3], [4, 2, 4, 4, 4]), ('regression: widow before orphan ordering', [[5, 5, 9, 6, 5], 5, 3, 3], [5, 5, 5, 4, 5, 1, 5]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('control layout', [[2, 9, 5, 6, 7, 3, 5, 6], 9, 1, 2], [9, 9, 9, 8, 8]), ('control layout', [[2, 6, 6, 3, 7, 5], 11, 2, 1], [11, 11, 7])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: widow before orphan ordering | [4, 3, 3, 4, 4] | [4, 2, 4, 4, 4] | Failed |
| regression: widow before orphan ordering | [3, 4, 3, 4, 4, 3, 4, 3, 4] | [3, 4, 1, 4, 2, 4, 3, 4, 3, 4] | Failed |
| regression: widow before orphan ordering | [9, 8, 6] | [9, 7, 7] | Failed |
| regression: widow before orphan ordering | [5, 6, 5, 6, 6] | [5, 6, 3, 5, 6, 3] | Failed |
| single widow pulled back | [5, 2] | [5, 2] | Passed |
| long paragraph continuation | [6, 6, 4] | [6, 6, 4] | Passed |
| control layout | [11, 12, 5] | [11, 12, 5] | Passed |
| control layout | [9, 1] | [9, 1] | Passed |
SHA-256 / 1bd4a59cc737760a1a40e1a2a68c2585a5e24c0dc8980bdd2804f19146da840f
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
paras, H, orphan, widow = x
pages = []
used = 0
for p in paras:
rem = p
started = True
while rem > 0:
room = H - used
if rem <= room:
used += rem
rem = 0
continue
a = room
if used > 0:
if rem - a < widow:
a = max(rem - widow, 0)
if started and a < orphan:
a = 0
used += a
rem -= a
if a > 0:
started = False
pages.append(used)
used = 0
if used > 0:
pages.append(used)
return pages
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: widow before orphan ordering', [[2, 2, 1, 1, 4, 8], 4, 2, 3], [4, 2, 4, 4, 4]), ('regression: widow before orphan ordering', [[3, 5, 5, 1, 7, 7, 3, 1], 4, 3, 3], [3, 4, 1, 4, 2, 4, 3, 4, 3, 4]), ('regression: widow before orphan ordering', [[9, 7, 4, 1, 2], 10, 2, 3], [9, 7, 7]), ('regression: widow before orphan ordering', [[5, 2, 7, 5, 9], 6, 3, 3], [5, 6, 3, 5, 6, 3]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[7, 1, 3, 8, 6, 3], 12, 3, 2], [11, 12, 5]), ('control layout', [[4, 1, 5], 9, 3, 1], [9, 1])], [('regression: widow before orphan ordering', [[1, 2, 8, 5, 8, 6, 7, 9], 7, 3, 3], [7, 4, 5, 7, 7, 7, 7, 2]), ('regression: widow before orphan ordering', [[7, 9, 3, 9, 7, 5], 5, 3, 3], [5, 5, 5, 4, 5, 4, 5, 2, 5]), ('regression: widow before orphan ordering', [[3, 4, 1], 6, 3, 3], [3, 5]), ('regression: widow before orphan ordering', [[2, 2, 5, 5, 7, 6, 4, 2], 8, 2, 3], [6, 8, 7, 6, 6]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('orphan pushed forward', [[5, 3], 6, 2, 2], [5, 3]), ('control layout', [[6, 3, 5, 3, 1, 6, 5, 7], 10, 2, 3], [9, 9, 8, 10]), ('control layout', [[2, 5, 2], 11, 3, 1], [9])], [('regression: widow before orphan ordering', [[7, 9, 3, 9, 7, 5], 5, 3, 3], [5, 5, 5, 4, 5, 4, 5, 2, 5]), ('regression: widow before orphan ordering', [[3, 4, 1], 6, 3, 3], [3, 5]), ('regression: widow before orphan ordering', [[3, 5, 5, 1, 7, 7, 3, 1], 4, 3, 3], [3, 4, 1, 4, 2, 4, 3, 4, 3, 4]), ('regression: widow before orphan ordering', [[2, 8, 4, 5, 9, 5, 8, 2], 9, 3, 3], [7, 7, 9, 5, 9, 6]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('orphan pushed forward', [[5, 3], 6, 2, 2], [5, 3]), ('control layout', [[7, 4, 1, 1, 2, 6], 6, 3, 2], [6, 6, 6, 3]), ('control layout', [[7, 8, 5, 1], 10, 1, 3], [10, 10, 1])], [('regression: widow before orphan ordering', [[2, 2, 5, 5, 7, 6, 4, 2], 8, 2, 3], [6, 8, 7, 6, 6]), ('regression: widow before orphan ordering', [[7, 6, 7, 4], 8, 2, 3], [7, 8, 5, 4]), ('regression: widow before orphan ordering', [[8, 4, 3, 3, 3, 1, 4], 5, 2, 2], [5, 5, 5, 3, 4, 4]), ('regression: widow before orphan ordering', [[2, 2, 1, 1, 4, 8], 4, 2, 3], [4, 2, 4, 4, 4]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('control layout', [[3, 3, 8, 5, 7, 7], 5, 1, 3], [3, 5, 5, 3, 5, 5, 5, 2]), ('control layout', [[6, 9, 7, 1, 7, 9, 8], 4, 3, 2], [4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1])], [('regression: widow before orphan ordering', [[9, 7, 4, 1, 2], 10, 2, 3], [9, 7, 7]), ('regression: widow before orphan ordering', [[2, 2, 5, 5, 7, 6, 4, 2], 8, 2, 3], [6, 8, 7, 6, 6]), ('regression: widow before orphan ordering', [[2, 2, 1, 1, 4, 8], 4, 2, 3], [4, 2, 4, 4, 4]), ('regression: widow before orphan ordering', [[5, 5, 9, 6, 5], 5, 3, 3], [5, 5, 5, 4, 5, 1, 5]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('control layout', [[2, 9, 5, 6, 7, 3, 5, 6], 9, 1, 2], [9, 9, 9, 8, 8]), ('control layout', [[2, 6, 6, 3, 7, 5], 11, 2, 1], [11, 11, 7])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: widow before orphan ordering | [4, 2, 4, 4, 4] | [4, 2, 4, 4, 4] | Passed |
| regression: widow before orphan ordering | [3, 4, 1, 4, 2, 4, 3, 4, 3, 4] | [3, 4, 1, 4, 2, 4, 3, 4, 3, 4] | Passed |
| regression: widow before orphan ordering | [9, 7, 7] | [9, 7, 7] | Passed |
| regression: widow before orphan ordering | [5, 6, 3, 5, 6, 3] | [5, 6, 3, 5, 6, 3] | Passed |
| single widow pulled back | [5, 2] | [5, 2] | Passed |
| long paragraph continuation | [6, 6, 4] | [6, 6, 4] | Passed |
| control layout | [11, 12, 5] | [11, 12, 5] | Passed |
| control layout | [9, 1] | [9, 1] | Passed |
SHA-256 / c82f20e7ba00a89fa597364b8822270fa95d23699d5cffa977bd7170a9da6369
Verification & scope
A deterministic toy typesetting model with integer widths and a stipulated rule set; it does not claim conformance to any engine. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:49:49.649519+00:00.
Case digest / 441ec6448bbfef4ebe1213666ad1313dccad2883547df491985cb924a116590d