Commit f76f561
pdf: read interleaved font runs in visual order ("C.6." kept whole) (#157)
PDF generators that paint a line's bold runs *after* the surrounding regular
text (the XXXLutz terms document does this for every bold token) hand the
sanitizer cells in stream order, not reading order. docling's cluster join
follows the docling-parse cell index — that same stream order — so the bold
label number drifted to the line's end: "C.6. Zur Wahrung der Widerrufsfrist
…" read "C. Zur Wahrung … Mitteilung 6.", "binnen 14 Tagen ohne Angabe"
read "binnen ohne 2. 14 Tagen Angabe", and searching the output for "C.6"
found nothing.
Two changes, both in the shared text path (native + browser, flat + ML):
- region_text: restore reading order geometrically before joining — group a
region's cells into lines by vertical *overlap* (not a quantized band:
2206's inline `>` sits ~2 pt above its line's band, and a plain band-sort
drifted it into the next line, which is why the join trusted index order
until now), sort lines top to bottom and cells left to right (right to
left for Arabic-majority regions), stably — index order still breaks ties.
- dp_lines contraction: never merge two cells across a horizontal gap that
another active cell occupies — an occupied gap is not a gap, and bridging
it with a space would stitch the line wrong before any ordering could
help. Space-only cells never block; glyph-adjacent merges skip the scan.
The full corpus battery is the arbiter that this deviation from raw index
order is safe: docling-core, docling (regression suite included),
docling-asr, docling-serve and docling-pdf suites all green, plus a unit
test locking the interleaved-runs order and the off-baseline `>` grouping.
fmt/clippy clean; the no-default-features and wasm targets compile.
Refs #157
Signed-off-by: artiz <artem.kustikov@gmail.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EY5KAiquN4YpVf2PXEQkVT1 parent d2a3b63 commit f76f561
2 files changed
Lines changed: 129 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
729 | 729 | | |
730 | 730 | | |
731 | 731 | | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
736 | 769 | | |
737 | 770 | | |
738 | 771 | | |
| |||
1710 | 1743 | | |
1711 | 1744 | | |
1712 | 1745 | | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
1713 | 1790 | | |
1714 | 1791 | | |
1715 | 1792 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
173 | 215 | | |
174 | 216 | | |
175 | 217 | | |
| |||
214 | 256 | | |
215 | 257 | | |
216 | 258 | | |
217 | | - | |
| 259 | + | |
218 | 260 | | |
219 | 261 | | |
220 | 262 | | |
221 | 263 | | |
222 | 264 | | |
223 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
224 | 269 | | |
225 | 270 | | |
226 | 271 | | |
| |||
251 | 296 | | |
252 | 297 | | |
253 | 298 | | |
254 | | - | |
| 299 | + | |
255 | 300 | | |
256 | 301 | | |
257 | 302 | | |
| |||
0 commit comments