Repository navigation
Commit 6c67f40
committed
Fix InlineFragmentation's widows/orphans merge-back to shift, not just merge
Confirmed while porting OrphansWidowsIntegrationTests.cs (Batch 2, commit
d8b2587): ApplyLineBreaking's widows correction could only fully merge two
runs into one (breaks.RemoveAt), never shift the break point earlier by a
partial number of lines, and never fell back to pushing a run whole onto a
FRESH page when an in-place merge didn't fit the current page's remaining
room. A 4-line paragraph with widows:2, naturally breaking 3-before/1-after,
needed only a 1-line shift (2-before/2-after) to satisfy widows - the old
code tried merging all 4 lines onto the current page, found they didn't fit,
and gave up, leaving the violation.
Rewrote the widows loop to try, in order: (1) shift the break earlier by the
minimum number of lines that satisfies widows without leaving the earlier
run below its own orphans minimum - always valid at a full page height,
since a shifted-but-still-separate run starts fresh at a page top regardless
of exactly where the break falls; (2) if no shift works, cascade the
existing full-merge (now against a full page height for any run but run 0,
same as before); (3) for a merge specifically into run 0, if it doesn't fit
run 0's own natural (tighter) capacity but WOULD fit a full page, apply the
same fresh-page boost firstRunMovedToFreshPage already gives orphans on the
first run. Only when none of these work does it decline gracefully, per
css-break-3 4.3.
Also fixes a related gap in firstRunMovedToFreshPage: it never checked
whether the run was already flush at a fresh page's own top before pushing
it to ANOTHER one - for an unsatisfiable orphans minimum after a forced
break, this silently walked the box one page past where the break named,
leaving that page blank. Added an alreadyAtFreshPageTop guard, applied
consistently to both the pre-loop check and phase 1's own runStart==0
back-off branch (missing it from the latter initially caused a real
regression in Orphans2_NothingAboveItInTheFragmentainer_IsLeftWhereItIs,
caught by running the full suite before committing).
Real discovery made while verifying empirically (per this project's own
established practice of testing hand-traced fixes against actual runtime
behavior): OrphansWidowsIntegrationTests.cs's <br>-joined Paragraph() helper
never exercised this code at all. This fork's <br> handling
(DomParser.CorrectLineBreaksBlocks) only folds a <br> into a real forced-
newline when it's the LAST thing in its inline run; a <br> with more content
after it is left as a literal box, and the surrounding text gets split into
SEPARATE anonymous BLOCK siblings (confirmed by direct box-tree inspection:
7 children, alternating 1-line blocks and inline <br> boxes, the <p> itself
with zero LineBoxes of its own) - so each "line" was really an independent
1-line sibling block, never touching ApplyLineBreaking's multi-line logic.
Rewrote Paragraph() to use natural word-wrapping (narrow width, space-
separated distinct words) instead, which produces a real multi-line box and
actually exercises the fix.
Un-ignores 6 tests in OrphansWidowsIntegrationTests.cs (Widows2/3/4, both
Orphans2 first-run variants, Widows2 on a second-page paragraph) and 1 in
FragmentainerCursorIntegrationTests.cs (AForcedBreak_LandsOnThePageItNames).
Full suite: HtmlRenderer.Test 2427 passed/128 skipped/0 failed (unchanged),
HtmlRenderer.IntegrationTest 330 passed/94 skipped/0 failed (was 323/101),
HtmlRenderer.PdfSharp.Test 39 passed/0 failed (unchanged).1 parent 42fff5b commit 6c67f40
3 files changed
Lines changed: 101 additions & 51 deletions
File tree
- Source
- HtmlRenderer/Core/Fragmentation
- Test/HtmlRenderer.IntegrationTest/Fragmentation
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
96 | 102 | | |
97 | 103 | | |
98 | 104 | | |
| |||
117 | 123 | | |
118 | 124 | | |
119 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
120 | 141 | | |
121 | 142 | | |
122 | 143 | | |
123 | 144 | | |
124 | 145 | | |
125 | 146 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
132 | 169 | | |
133 | 170 | | |
134 | | - | |
135 | | - | |
136 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
137 | 191 | | |
138 | 192 | | |
139 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
140 | 213 | | |
141 | 214 | | |
142 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | 77 | | |
87 | 78 | | |
88 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
139 | 154 | | |
140 | | - | |
141 | | - | |
| 155 | + | |
| 156 | + | |
142 | 157 | | |
143 | 158 | | |
144 | 159 | | |
| |||
165 | 180 | | |
166 | 181 | | |
167 | 182 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | 183 | | |
178 | 184 | | |
179 | 185 | | |
| |||
192 | 198 | | |
193 | 199 | | |
194 | 200 | | |
195 | | - | |
196 | | - | |
197 | 201 | | |
198 | 202 | | |
199 | 203 | | |
| |||
213 | 217 | | |
214 | 218 | | |
215 | 219 | | |
216 | | - | |
217 | | - | |
218 | 220 | | |
219 | 221 | | |
220 | 222 | | |
| |||
237 | 239 | | |
238 | 240 | | |
239 | 241 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | 242 | | |
249 | 243 | | |
250 | 244 | | |
| |||
309 | 303 | | |
310 | 304 | | |
311 | 305 | | |
312 | | - | |
313 | | - | |
314 | 306 | | |
315 | 307 | | |
316 | 308 | | |
| |||
408 | 400 | | |
409 | 401 | | |
410 | 402 | | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | 403 | | |
418 | 404 | | |
419 | 405 | | |
| |||
0 commit comments