rhwp 0.9.0

HWP/HWPX document engine for Rust applications, WebAssembly, and CLI automation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
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
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
//! 페이지 분할 표 레이아웃 (layout_partial_table)

mod row_band;
mod tail_alignment;

use super::super::composer::{compose_paragraph, ComposedParagraph};
use super::super::float_placement::{
    native_hwp5_stored_reset_fragment_paint_geometry, topbottom_flow_vertical_offset_hu,
};
use super::super::height_measurer::{
    stored_nested_table_empty_wrap_spacer, stored_nested_table_wrap_successor,
    stored_square_picture_empty_anchor_advance, stored_square_picture_has_adjacent_text,
    stored_square_picture_wrap_anchor_for_para, MeasuredTable,
};
use super::super::page_layout::LayoutRect;
use super::super::render_tree::*;
use super::super::style_resolver::ResolvedStyleSet;
use super::super::{hwpunit_to_px, px_to_hwpunit};
use super::border_rendering::{
    apply_table_border_overrides, build_row_col_x, collect_cell_borders,
    mark_cell_span_interior_covered, render_cell_diagonal, render_edge_borders,
    render_spaced_cell_borders, render_transparent_borders,
};
use super::nested_table_origin::NestedTableOrigin;
use super::table_layout::{
    border_style_has_diagonal, calc_nested_split_rows, effective_margin_left_line,
    expand_page_fragment_clip_to_own_text_lines, extend_completed_nested_table_border_clips,
    native_terminal_child_host_line_spacing, translate_render_subtree_y, unwrapped_table_cell_ctx,
    NestedTableSplit, StoredNestedHostFlow, INLINE_WRAP_WIDTH_EPSILON_PX,
};
use super::text_measurement::{estimate_text_width, resolved_to_text_style};
use super::{
    repeats_native_empty_host_rowbreak_fragment_margin, CellContext, CellPathEntry, LayoutEngine,
};
use crate::model::bin_data::BinDataContent;
use crate::model::control::Control;
use crate::model::paragraph::Paragraph;
use crate::model::shape::{CaptionDirection, CommonObjAttr, HorzRelTo};
use crate::model::style::{Alignment, BorderLine};
use crate::model::table::{Cell, Table};
use crate::renderer::float_placement::native_multirow_internal_reset_rowbreak_anchor_advance_hu;

/// 반복 머리행은 잘린 이어받기 조각이 아니라 온전한 셀 인스턴스다.
/// 표의 이어받기 플래그나 내용 클립 대신 원본 행을 얼마나 포함하는지 확인한다.
fn partial_cell_has_complete_rows(cell: &Cell, render_rows: &[usize]) -> bool {
    let row = cell.row as usize;
    let span = cell.row_span as usize;
    span > 0
        && render_rows
            .iter()
            .position(|&r| r == row)
            .is_some_and(|start| {
                render_rows.get(start..start + span).is_some_and(|rows| {
                    rows.iter()
                        .enumerate()
                        .all(|(offset, &r)| r == row + offset)
                })
            })
}

/// #7028에서는 조각 단위의 셀 구역 지오메트리를 추가하지 않는다.
/// 활성 셀 구역이 걸친 셀만 기존 출력을 유지하고, 관련 없는 셀은 계속 처리 대상으로 둔다.
fn partial_cell_intersects_diagonal_zone(
    cell: &Cell,
    table: &Table,
    styles: &ResolvedStyleSet,
) -> bool {
    table.zones.iter().any(|zone| {
        let sr = zone.start_row as usize;
        let er = (zone.end_row as usize + 1).min(table.row_count as usize);
        let sc = zone.start_col as usize;
        let ec = (zone.end_col as usize + 1).min(table.col_count as usize);
        sr < er
            && sc < ec
            && (cell.row as usize) < er
            && sr < cell.row as usize + cell.row_span as usize
            && (cell.col as usize) < ec
            && sc < cell.col as usize + cell.col_span as usize
            && zone.border_fill_id.checked_sub(1).is_some_and(|idx| {
                styles
                    .border_styles
                    .get(idx as usize)
                    .is_some_and(border_style_has_diagonal)
            })
    })
}

/// 인라인으로 재분류된 부동 그림이 유지해야 할 문단 기준 가로 오프셋(px).
///
/// `[#2004]` 정규화(`reclassify_cell_floating_stacks`)는 같은 자리에 겹친 전면급
/// 부동 그림 더미를 **그림 1장짜리 인라인 문단 N개**로 쪼갠다. 한글이 이런 더미를
/// 쪽당 1장씩 놓는 것을 재현하려면 필요한 변환이다(끄면 그림이 아예 안 그려진다).
/// 다만 그 변환은 `treat_as_char` 만 바꾸고 개체의 `horzOffset` 은 그대로 두는데,
/// 인라인 배치는 그 값을 보지 않아 쪼갠 그림이 전부 셀 왼끝에 겹친다
/// (issue2004 5~8쪽: 한글 대비 −19~−28px).
///
/// 저장 글자처럼 원문 inline 그림에는 위치값을 일반 적용하지 않는다. 문단 기준
/// offset은 `reclassify_cell_floating_stacks`가 만든 합성 줄에서만 복원한다.
pub(super) fn inline_para_horizontal_offset_px(
    common: &CommonObjAttr,
    synthetic_reclassified_stack: bool,
    dpi: f64,
) -> f64 {
    if !synthetic_reclassified_stack || !matches!(common.horz_rel_to, HorzRelTo::Para) {
        return 0.0;
    }
    hwpunit_to_px(common.horizontal_offset as i32, dpi)
}

/// `layout_partial_table_resolved`가 표 자체와 분리해 사용하는 host 문맥.
///
/// 일반 페이지 item은 원본 문단/control에서 이 값을 만들고, 재귀 child cursor는
/// 임시 `Table::clone()` 없이 원본 중첩 표와 synthetic-equivalent 기본값을 넘긴다.
#[derive(Clone, Copy)]
struct PartialTableHostContext<'a> {
    paragraphs: &'a [Paragraph],
    para_index: usize,
    control_index: usize,
    repeat_fragment_outer_margin: bool,
    pre_emitted_host_height: f64,
    /// [#7418] 같은 host 글의 내용 높이(마지막 줄간격 제외). 없으면 `pre_emitted_host_height`.
    pre_emitted_host_content_height: f64,
    host_line_spacing: f64,
    resolved_table_top: Option<f64>,
    resolved_table_left: Option<f64>,
    predecessor_flow_bottom: Option<f64>,
    end_row_owns_stored_frame: bool,
    /// 현재 호스트의 확정된 줄·표 계획에서 온 물리 조각 상자다.
    computed_fragment_frame: bool,
}

/// 투명하고 비어 있는 1×1 감싸기 표 안의 내용 표를 반환한다.
///
/// HWPX는 중첩 표를 담기 위한 바깥 표만 남길 수 있다. 이 표의 빈 문단 하나에는
/// 독립적으로 보이는 내용이 없으므로 행 지오메트리는 중첩 표의 지오메트리와 같다.
/// 이 해제 조건은 좁게 유지한다. 텍스트, 추가 문단 또는 1×1이 아닌 격자가 있으면
/// 바깥 표 자체의 의미가 있으므로 감싸기 해제를 중단한다.
fn transparent_nested_table<'a>(
    table: &'a crate::model::table::Table,
    styles: &ResolvedStyleSet,
) -> &'a crate::model::table::Table {
    crate::renderer::height_measurer::transparent_table_wrapper_child(table, styles)
        .map(|child| transparent_nested_table(child, styles))
        .unwrap_or(table)
}

/// 분할 셀 조각에서 실제로 보이는 첫 줄의 저장 vpos를 찾는다.
///
/// `cell_line_ranges_from_cut`은 문단 중간 줄에서 시작할 수 있다. 문단 첫 줄을
/// 쓰면 이미 앞 조각에서 소비한 줄 높이를 다시 더해 다음 문단 스냅이 밀린다.
fn fragment_vpos_origin(
    cell: &crate::model::table::Cell,
    line_ranges: Option<&[(usize, usize)]>,
) -> i32 {
    line_ranges
        .and_then(|ranges| {
            ranges
                .iter()
                .position(|&(start, end)| start < end)
                .and_then(|para_idx| {
                    let (start_line, _) = ranges[para_idx];
                    cell.paragraphs.get(para_idx).and_then(|para| {
                        para.line_segs
                            .get(start_line)
                            // recompose된 문단처럼 저장 LINE_SEG가 줄 수보다 적으면
                            // 기존의 보수적 첫 세그먼트 폴백을 유지한다.
                            .or_else(|| para.line_segs.first())
                            .map(|seg| seg.vertical_pos)
                    })
                })
        })
        .unwrap_or(0)
        .max(0)
}

/// 셀의 실제 텍스트 하단 경계.
///
/// `text_y_start`에는 세로 정렬 offset이 포함되므로 여기에 전체 `cell_h`를 더하면
/// Center/Bottom 셀에서 물리 셀 하단을 넘는다.
fn cell_content_bottom(cell_y: f64, cell_h: f64, pad_bottom: f64) -> f64 {
    cell_y + cell_h - pad_bottom
}

/// [#4159] 종료 분할 셀의 clip이 재귀 중첩 표 전체 stroke를 포섭하도록 확장한다.
///
/// 재귀 표는 셀의 `inner_y`(top padding 뒤)에서 시작하지만 바깥 셀과 같은 fragment
/// 높이를 사용할 수 있다. 이때 중첩 표의 마지막 border만 padding만큼 셀 bbox 밖으로
/// 내려간다. 이어질 유닛이 없는 terminal 조각에서는 그 stroke도 현재 쪽 소속이므로
/// clip에 포함한다. 비종료 조각은 다음 쪽 콘텐츠 노출을 막기 위해 절대 확장하지 않는다.
fn expand_terminal_cell_clip_to_nested_table_descendants(
    cell_node: &mut RenderNode,
    terminal: bool,
) {
    if !terminal || !matches!(&cell_node.node_type, RenderNodeType::TableCell(cell) if cell.clip) {
        return;
    }

    fn subtree_bottom(node: &RenderNode) -> f64 {
        node.children
            .iter()
            .fold(node.bbox.y + node.bbox.height, |bottom, child| {
                bottom.max(subtree_bottom(child))
            })
    }

    fn nested_table_bottom(node: &RenderNode) -> Option<f64> {
        node.children.iter().fold(None, |bottom, child| {
            let candidate = if matches!(child.node_type, RenderNodeType::Table(_)) {
                Some(subtree_bottom(child))
            } else {
                nested_table_bottom(child)
            };
            match (bottom, candidate) {
                (Some(a), Some(b)) => Some(a.max(b)),
                (Some(a), None) => Some(a),
                (None, Some(b)) => Some(b),
                (None, None) => None,
            }
        })
    }

    let Some(content_bottom) = nested_table_bottom(cell_node) else {
        return;
    };
    let grown_height = content_bottom - cell_node.bbox.y;
    if grown_height > cell_node.bbox.height {
        cell_node.bbox.height = grown_height;
    }
}

/// 명시적 recursive RowCut으로 source-bounded 렌더를 끝낸 직계 child만 현재
/// clipped cell viewport에 포섭한다.
///
/// 일반 nonterminal cell을 확장하면 다음 쪽 scalar tail이 노출된다. 반면
/// `recursive_cut` 경로는 현재 쪽의 source start/end를 이미 제한하므로, 해당 호출이
/// 새로 추가한 table root bbox는 안전하게 현재 조각 소유로 볼 수 있다. child 내부를
/// 다시 순회하지 않는 이유는 그 안의 별도 clipped scalar tail을 섞지 않기 위해서다.
fn expand_cell_clip_to_new_source_bounded_children(
    cell_node: &mut RenderNode,
    first_new_child: usize,
) {
    if !matches!(&cell_node.node_type, RenderNodeType::TableCell(cell) if cell.clip) {
        return;
    }

    let current_bottom = cell_node.bbox.y + cell_node.bbox.height;
    let content_bottom = cell_node.children[first_new_child.min(cell_node.children.len())..]
        .iter()
        .filter(|child| child.visible)
        .map(|child| child.bbox.y + child.bbox.height)
        .fold(current_bottom, f64::max);
    let grown_height = content_bottom - cell_node.bbox.y;
    if grown_height > cell_node.bbox.height {
        cell_node.bbox.height = grown_height;
    }
}

// 표 수평 정렬 보조 타입은 table_layout.rs에 통합됨

/// [#4149] 셀 커서 fast path 프로브 — 부분 표 조각 레이아웃을 대상 셀 하나로 제한한다.
///
/// 계약: 방출되는 노드의 좌표는 전량 레이아웃과 완전 동일해야 한다 — 프로브는
/// "생략"만 하고 "변형"은 하지 않는다 (셀 방출 루프는 셀-간 캐리가 없음이 근거).
pub(crate) struct PartialTableCellProbe {
    /// 대상 셀 인덱스 — 이 셀만 방출한다.
    pub(crate) cell_idx: usize,
    /// 이 문단까지 방출 후 중단한다 (캐럿 문단 — 이후 문단은 캐럿 탐색에 불필요하고
    /// 앞 문단의 y 에도 영향이 없다).
    pub(crate) stop_after_para: usize,
    /// true 면 컷 창 문단(`window_paras`)만 순회·compose 한다. 사전 게이트가
    /// (a) 컷 존재, (b) shrink 조기탈출(다중줄 문단 존재), (c) effective Top 정렬을
    /// 증명한 경우에만 true 가 된다.
    pub(crate) windowed: bool,
    /// `windowed` 일 때 컷 창에 유닛이 있는 문단 범위 [lo, hi] (inclusive).
    /// 범위 밖 문단은 컷 창에 유닛이 없어 전량 레이아웃에서도 skip 됨이 증명된다.
    pub(crate) window_paras: (usize, usize),
}

/// 셀 문단 compose 저장소 — 실제로 잘리는 가로쓰기 셀은 가시 창만 lazy 구성한다.
///
/// Lazy 슬롯의 compose 결과는 Eager 경로와 동일한 변환 순서
/// (compose → recompose_cell_lines_in_frame → recompose_stored_single_line_if_overflowing)를
/// 문단 단위로 적용한다. windowed 프로브 게이트가 shrink 를 조기탈출로 증명하므로
/// Lazy 에서 inner_width 는 Eager 와 동일하다.
enum CellComposedStore {
    Eager(Vec<ComposedParagraph>),
    Lazy(Vec<Option<ComposedParagraph>>),
}

/// [#6923] 저장 줄이 여러 개인 문단의 TAC 중첩 표가 **자기 줄**에 앉도록 하는 세로 델타.
///
/// 한/글이 저장한 사다리는 표를 소유한 줄을 따로 적는다(`148738070` p69:
/// ls[0] 49113HU 글줄 · ls[1] 51229HU 표 밴드). 종전 렌더는 문단 첫 줄 좌표에 표를 앉혀
/// 앞 글줄 위로 28.2px 올라왔다 — 정본은 그 둘을 34.8px 띄운다.
///
/// 조각/프레임 원점을 모르는 자리이므로 **이 조각의 첫 렌더 줄 기준 델타**만 돌려준다.
/// 합성 lineseg(재조판 산출)나 단일 줄 문단, 소유 줄이 기준 줄보다 앞서는 경우는 `None`.
fn stored_nested_table_line_offset_px(
    para: &crate::model::paragraph::Paragraph,
    control_index: usize,
    start_line: usize,
    dpi: f64,
) -> Option<f64> {
    use crate::model::paragraph::LineSeg;
    if para.line_segs.len() < 2 {
        return None;
    }
    if para
        .line_segs
        .iter()
        .any(|seg| seg.tag & LineSeg::TAG_IMPLEMENTATION_PROPERTY != 0)
    {
        return None;
    }
    let owner = crate::renderer::layout::control_line_seg_index(para, control_index)?;
    let base = start_line.min(para.line_segs.len() - 1);
    if owner <= base {
        return None;
    }
    let delta = i64::from(para.line_segs.get(owner)?.vertical_pos)
        - i64::from(para.line_segs.get(base)?.vertical_pos);
    (delta > 0).then(|| crate::renderer::hwpunit_to_px(delta as i32, dpi))
}

/// 변경되지 않은 원본 줄에서 컨트롤을 현재 글줄 창이 소유하는지 판정한다.
/// 배치와 정렬 경계가 같은 원본 소유 관계를 사용한다.
pub(super) fn stored_control_owned_by_line_window(
    para: &crate::model::paragraph::Paragraph,
    control_index: usize,
    start_line: usize,
    end_line: usize,
) -> Option<bool> {
    if para.line_segs.len() < 2
        || para.stored_text_partition_is_dirty()
        || para.line_segs.iter().any(|line| {
            line.tag & crate::model::paragraph::LineSeg::TAG_IMPLEMENTATION_PROPERTY != 0
        })
    {
        return None;
    }
    crate::renderer::layout::control_line_seg_index(para, control_index)
        .map(|owner| start_line <= owner && owner < end_line)
}

impl CellComposedStore {
    fn get(
        &mut self,
        cpi: usize,
        cell: &Cell,
        inner_width: f64,
        styles: &ResolvedStyleSet,
        engine: &LayoutEngine,
    ) -> &ComposedParagraph {
        match self {
            CellComposedStore::Eager(v) => &v[cpi],
            CellComposedStore::Lazy(slots) => slots[cpi].get_or_insert_with(|| {
                engine.compose_cell_unit_paragraph(
                    &cell.paragraphs[cpi],
                    cell.text_direction,
                    inner_width,
                    styles,
                )
            }),
        }
    }

    /// 전량 슬라이스가 필요한 경로도 셀 컷·지연 배치와 같은 조판기를 사용한다.
    fn materialize(
        &mut self,
        cell: &Cell,
        inner_width: f64,
        styles: &ResolvedStyleSet,
        engine: &LayoutEngine,
    ) {
        if matches!(self, CellComposedStore::Lazy(_)) {
            let v = (0..cell.paragraphs.len())
                .map(|cpi| self.get(cpi, cell, inner_width, styles, engine).clone())
                .collect();
            *self = CellComposedStore::Eager(v);
        }
    }

    /// Eager 전제 슬라이스 접근 — windowed 프로브 게이트 밖에서만 호출된다.
    fn eager_slice(&self) -> &[ComposedParagraph] {
        match self {
            CellComposedStore::Eager(v) => v,
            CellComposedStore::Lazy(_) => {
                unreachable!("windowed 프로브에서 전량 compose 접근 금지")
            }
        }
    }
}

/// [#4149] 프로브 사전 계획 결과.
pub(crate) enum ProbeCutPlan {
    /// 프로브로 다룰 수 없는 조합 (rowspan 셀, 빈 창 등) — legacy 폴백.
    Unsupported,
    /// 이 조각에서 셀이 컷되지 않음 (전체 가시). 소형 셀 한정 전량 프로브 가능.
    Uncut,
    /// 컷 존재. `window_paras` = 창에 유닛이 있는 문단 범위 [lo, hi] (inclusive).
    Cut {
        window_paras: (usize, usize),
        /// 전량 레이아웃의 `cell_was_split` 이 true 임이 증명됨 (s>0 문단 존재
        /// 또는 창 밖 미가시 문단의 compose 줄 수 ≥ 1).
        split_proven: bool,
        /// 대상 문단이 창 안에 있는가 — 밖이면 이 페이지에 대상 문단 run 이 없다.
        target_in_window: bool,
    },
}

/// [Task #1025] `row` 를 포함하는 rowspan 블록 범위 `[b_start, b_end)`.
/// rs>1 셀이 겹치는 행을 전이적으로 확장한다(겹침 없으면 `[row, row+1)`).
/// 페이지네이터 `mt.row_block_for` / `advance_row_block_cut` 와 동일한 블록 정의.
pub(super) fn rowspan_block_range(
    table: &crate::model::table::Table,
    row: usize,
) -> (usize, usize) {
    let mut b_start = row;
    let mut b_end = row + 1;
    loop {
        let mut changed = false;
        for c in &table.cells {
            if c.row_span <= 1 {
                continue;
            }
            let cs = c.row as usize;
            let ce = cs + c.row_span as usize;
            if cs < b_end && ce > b_start {
                if cs < b_start {
                    b_start = cs;
                    changed = true;
                }
                if ce > b_end {
                    b_end = ce;
                    changed = true;
                }
            }
        }
        if !changed {
            break;
        }
    }
    (b_start, b_end)
}

/// [Task #1025] 블록 `[b_start, b_end)` 컷 벡터에서 `cell` 의 인덱스.
/// `advance_row_block_cut` 과 동일한 `(row, col)` 안정 순서. 없으면 None.
fn block_cut_index(
    table: &crate::model::table::Table,
    b_start: usize,
    b_end: usize,
    cell: &crate::model::table::Cell,
) -> Option<usize> {
    let mut cells: Vec<&crate::model::table::Cell> = table
        .cells
        .iter()
        .filter(|c| {
            let cr = c.row as usize;
            let ce = cr + (c.row_span as usize).max(1);
            cr < b_end && ce > b_start
        })
        .collect();
    cells.sort_by_key(|c| (c.row, c.col));
    cells
        .iter()
        .position(|c| c.row == cell.row && c.col == cell.col)
}

/// [#7226] 이어받는 조각이 **같은 행 안에서** 재개하는 걸침 칸인가.
///
/// `RowCut`(= `start_cut`/`end_cut`)은 그 행의 `row_span == 1` 칸을 col 순서로만
/// 색인한다(`single_row_cut_index`). 그래서 칸이 전부 걸침 칸인 행은 앞 조각이
/// 그 행의 물리 밴드를 얼마나 소비했든 컷에 적을 자리가 없어 `start_cut` 이 빈
/// 채로 다음 조각에 온다. 그 조각은 같은 칸을 **첫 유닛부터 다시 칠해** 두 조각이
/// 같은 행을 소유하고 글자가 포개진다(1342000 edu 33쪽, `#6981` 잔여 축).
///
/// 앞 조각이 남긴 정확한 잔여 밴드(`start_row_height_override`)는 그 행에서
/// 시작하는 걸침 칸에도 같은 뜻이다 — 소비 높이 = 선언 행 높이 − 잔여 밴드.
/// 일반 행 컷의 슬롯은 단일행 칸만 소유한다. 같은 시작행의 병합 칸도 잔여
/// 물리 밴드와 실제 소비된 행 컷의 점유를 공통 높이 계산으로 이어받는다.
/// 블록 컷은 병합 칸의 명시적인 슬롯을 계속 소유한다.
pub(crate) fn resumes_inside_own_start_row(
    table: &crate::model::table::Table,
    cell: &crate::model::table::Cell,
    start_row: usize,
    start_cut: &[usize],
    start_cut_is_block: bool,
    start_row_height_override: Option<f64>,
    straddle_page_bands: &[crate::renderer::pagination::StraddleCellCarry],
) -> bool {
    let accepted_source_start = table
        .cells
        .iter()
        .position(|owner| std::ptr::eq(owner, cell))
        .and_then(|index| {
            straddle_page_bands
                .iter()
                .find(|carry| carry.cell_index == index)
        })
        .and_then(|carry| carry.next_unit)
        .is_some_and(|unit| unit > 0);
    cell.row_span > 1
        && cell.row as usize == start_row
        && (accepted_source_start
            || (!start_cut_is_block && !start_cut.is_empty())
            || (start_row_height_override.is_some()
                && start_cut.is_empty()
                && !table
                    .cells
                    .iter()
                    .any(|c| c.row as usize == start_row && c.row_span == 1)))
}

/// [#6935] 이 조각의 **시작 컷**이 `cell` 을 실제로 가리키는가.
///
/// 시작 컷의 인덱스 공간에 따라 판정이 다르다.
///
/// - 블록 공간(`start_cut_is_block`): 컷이 블록-셀 `(row,col)` 서수라 블록에 걸친 칸도
///   자기 자리를 갖는다 — 블록 범위와 겹치면 컷이 소관한다.
/// - 행 공간: 컷이 시작 행의 `row_span == 1` 칸만 담는다. 그 행에서 시작하지 않는 걸친
///   칸이나 같은 행에서 시작한 병합 칸은 **적을 자리가 없으므로** 컷이 소관하지 않는다. 그런 칸은 `#1748` 의 높이 기반
///   구제(`rowbreak_straddle_cut_units`)가 앞 조각 소비분을 이어 준다.
///
/// 종전에는 `is_block_split` 하나가 시작·끝 두 공간을 OR 로 합쳐, 시작이 행 공간인데 끝이
/// 블록 공간인 조각에서 이 판정이 **참**이 됐다. 그러면 걸친 칸이 컷 소관으로 잡혀 높이
/// 기반 구제가 막히고, 정작 컷에는 자리가 없어 `su = 0` 으로 떨어져 앞 조각이 그린 내용을
/// 처음부터 다시 그렸다 (18179365 2쪽: 글자 +434, 글자 겹침 47건).
fn start_cut_covers_cell(
    cell_row: usize,
    cell_end_row: usize,
    start_row: usize,
    start_cut: &[usize],
    start_cut_is_block: bool,
    split_start_block: Option<(usize, usize)>,
) -> bool {
    if start_cut_is_block {
        split_start_block.is_some_and(|(s, e)| cell_row < e && cell_end_row > s)
    } else {
        !start_cut.is_empty() && cell_row == start_row && cell_end_row == cell_row + 1
    }
}

/// 끝 행을 내용 컷으로 나누면 그 행에서 끝나는 셀도 조각 경계를 지난다.
/// 내용 선택과 실제 행 상자 수용이 동일한 끝 경계를 사용한다.
pub(crate) fn cell_crosses_fragment_end(cell: &Cell, end_row: usize, end_cut: &[usize]) -> bool {
    let first = usize::from(cell.row);
    let end = first + usize::from(cell.row_span);
    first < end_row && (end > end_row || (end == end_row && !end_cut.is_empty()))
}

/// [#4128 추출] 행내 `row_span==1` 셀의 col 오름차순 컷 벡터 서수.
/// `advance_row_cut` 부기와 동일한 순서 (기존 인라인 식의 명명).
fn single_row_cut_index(
    table: &crate::model::table::Table,
    cell: &crate::model::table::Cell,
) -> usize {
    table
        .cells
        .iter()
        .filter(|c| c.row_span == 1 && c.row == cell.row && c.col < cell.col)
        .count()
}

/// [#4128 추출] 이 페이지 조각에서 `cell` 의 가시 유닛 창 `[su, eu)`.
/// `apply_start`/`apply_end` 는 셀이 분할 시작/끝 행(블록)에 걸렸는지 여부
/// (`is_split_start_row`/`is_split_end_row` 판정 결과). `units_len` 이 있으면
/// 그 범위로 클램프하고, 없으면 `usize::MAX` 센티널을 유지한다.
#[allow(clippy::too_many_arguments)]
fn cell_cut_window(
    table: &crate::model::table::Table,
    cell: &crate::model::table::Cell,
    // [#6935] 시작 컷과 끝 컷은 서로 다른 인덱스 공간에서 올 수 있다.
    start_cut_is_block: bool,
    end_cut_is_block: bool,
    apply_start: bool,
    start_block: Option<(usize, usize)>,
    apply_end: bool,
    end_block: Option<(usize, usize)>,
    start_cut: &[usize],
    end_cut: &[usize],
    units_len: Option<usize>,
    // [#6756] 컷 부기가 담긴 행(시작/끝) — 행-지역 서수 판정용.
    start_row_for_cut: usize,
    end_row_for_cut: usize,
) -> (usize, usize) {
    // [#6756] 블록 서수가 **컷 벡터 범위를 벗어나면** 행-지역 서수로 되찾는다. `start_cut`/`end_cut` 부기는 `advance_row_cut` 이 **컷 행의 `row_span==1`
    // 셀만** 담기 때문이다(`single_row_cut_index` 와 같은 순서). 그런데 종전에는
    // 블록 분할이면 무조건 `block_cut_index` 로 찾아, 컷 행이 **큰 rowspan 블록 안에**
    // 있으면 두 서수 공간이 어긋난다.
    //
    // 17253153: 셀 (11,0) 이 `row_span=17` 이라 블록이 `(11, 28)` 로 잡히고, 컷 행 14
    // 의 셀 (14,1) 은 블록 서수 **7** 이 된다. `end_cut` 은 항목이 **2개**뿐이라
    // `get(7) == None` → `eu = usize::MAX` → **컷이 사라져 그 행 전체가 그려진다.**
    // 그 행은 다음 조각이 `start_cut` 대로 다시 그려 **중복**이 된다(2쪽 끝 두 줄이
    // 3쪽 머리에 다시 나오고, 본문 하한을 48.2px·용지를 10.6px 넘는다).
    //
    // `#1748` 이 남긴 "컷 부기는 컷 행의 row_span==1 셀만 담는다"는 관찰 그대로다 —
    // 거기서는 **걸친 rowspan 셀**만 높이 기반 경로로 구제했고, 블록 안의 보통 셀은
    // 그대로 남아 있었다.
    let row_local_cut_index = |cut_row: usize| -> Option<usize> {
        (cell.row_span == 1 && cell.row as usize == cut_row)
            .then(|| single_row_cut_index(table, cell))
    };
    let su = if start_cut_is_block {
        match (apply_start, start_block) {
            (true, Some((bs, be))) => block_cut_index(table, bs, be, cell)
                .filter(|i| *i < start_cut.len())
                .or_else(|| row_local_cut_index(start_row_for_cut))
                .and_then(|i| start_cut.get(i).copied())
                .unwrap_or(0),
            _ => 0,
        }
    } else if apply_start && cell.row_span == 1 {
        start_cut
            .get(single_row_cut_index(table, cell))
            .copied()
            .unwrap_or(0)
    } else {
        0
    };
    let eu = if end_cut_is_block {
        match (apply_end, end_block) {
            (true, Some((bs, be))) => block_cut_index(table, bs, be, cell)
                .filter(|i| *i < end_cut.len())
                .or_else(|| row_local_cut_index(end_row_for_cut))
                .and_then(|i| end_cut.get(i).copied())
                .unwrap_or(usize::MAX),
            _ => usize::MAX,
        }
    } else if apply_end && cell.row_span == 1 {
        end_cut
            .get(single_row_cut_index(table, cell))
            .copied()
            .unwrap_or(usize::MAX)
    } else {
        usize::MAX
    };
    match units_len {
        Some(len) => {
            let su = su.min(len);
            (su, eu.clamp(su, len))
        }
        None => (su, eu),
    }
}

/// [#6924] 쪽 조각이 **소유한** clip 하단 글줄을 담도록 그 셀 clip 을 미리 넓힌다.
///
/// `suppress_bottom_clipped_text_residue`(#2007)는 clip 바닥에 6px 미만으로 걸친 글줄을
/// "다음 조각이 온전히 그릴 것" 이라 보고 지운다. 그 전제는 확인되지 않은 채였고, 소유자가
/// 없는 줄까지 지워 **문서에서 통째로 사라졌다** — 렌더 트리에는 정상 좌표로 남는데 SVG 에
/// 한 자도 나가지 않는다(148751598 1쪽 31자 · 148738070 1쪽 38자 · 156060125 6쪽 ·
/// 1490000 vietnam 114쪽 · 1342000 edu 377쪽. 한컴 2024 정답지가 다섯 곳 모두 그 줄을 그린다).
///
/// 소속은 컷 부기가 이미 안다(`partial_table_page_contains_cell_position`). 소유한 줄이면
/// 여기서 clip 을 그 줄 아랫변까지 넓혀 둔다 — 그러면 줄이 더는 바닥에 "걸치지" 않아
/// 억제 조건 자체가 성립하지 않는다. 억제 로직은 건드리지 않는다.
///
/// **형제 셀과 부딪치면 넓히지 않는다.** 소유한 줄이라도 이웃 셀 내용 위로 나가면 두 글자
/// 모두 못 읽는다(edu 82쪽 Cell3↔Cell10 · 152쪽 Cell13↔Cell24 실측: 겹침 94→97). 그런 줄은
/// 종전대로 억제에 맡긴다 — 행 높이 축의 별개 결함이라 여기서 풀 문제가 아니다.
type FragmentCellFlowBottoms = std::collections::HashMap<crate::renderer::render_tree::NodeId, f64>;

fn expand_fragment_cell_clip_for_owned_bottom_lines(
    table_node: &mut RenderNode,
    owns_line: &dyn Fn(
        &crate::renderer::render_tree::TableCellNode,
        &crate::renderer::render_tree::TextLineNode,
    ) -> bool,
) -> FragmentCellFlowBottoms {
    use crate::renderer::render_tree::RenderNodeType;
    let mut flow_bottoms = FragmentCellFlowBottoms::new();
    let cell_boxes: Vec<(usize, crate::renderer::render_tree::BoundingBox)> = table_node
        .children
        .iter()
        .enumerate()
        .filter(|(_, c)| matches!(c.node_type, RenderNodeType::TableCell(_)))
        .map(|(i, c)| (i, c.bbox))
        .collect();
    for (idx, cell) in table_node.children.iter_mut().enumerate() {
        let RenderNodeType::TableCell(meta) = &cell.node_type else {
            continue;
        };
        if !meta.clip || !meta.page_fragment {
            continue;
        }
        let meta = meta.clone();
        let clip_bottom = cell.bbox.y + cell.bbox.height;
        let mut wanted_bottom = clip_bottom;
        for line in &cell.children {
            if !line.visible {
                continue;
            }
            let RenderNodeType::TextLine(tl) = &line.node_type else {
                continue;
            };
            let line_bottom = line.bbox.y + line.bbox.height;
            // clip 바닥을 걸치는 줄만 대상 — 완전히 안이거나 완전히 밖인 줄은 다른 축이다.
            if line.bbox.y >= clip_bottom || line_bottom <= clip_bottom {
                continue;
            }
            if !owns_line(&meta, tl) {
                continue;
            }
            wanted_bottom = wanted_bottom.max(line_bottom);
        }
        if wanted_bottom <= clip_bottom {
            continue;
        }
        // 형제 셀 충돌 검사 — 넓힌 상자가 다른 셀과 겹치면 포기한다.
        let grown = crate::renderer::render_tree::BoundingBox::new(
            cell.bbox.x,
            cell.bbox.y,
            cell.bbox.width,
            wanted_bottom - cell.bbox.y,
        );
        let collides = cell_boxes.iter().any(|(other_idx, other)| {
            *other_idx != idx
                && grown.x < other.x + other.width
                && other.x < grown.x + grown.width
                && grown.y < other.y + other.height
                && other.y < grown.y + grown.height
        });
        if collides {
            continue;
        }
        // 이 증가는 글줄의 표시용 클립이다. 부모 표의 흐름 높이는 기존 하단을 쓴다.
        flow_bottoms.insert(cell.id, clip_bottom);
        cell.bbox.height = wanted_bottom - cell.bbox.y;
    }
    flow_bottoms
}

impl LayoutEngine {
    /// 부모 내용 컷이 새 자식 행의 물리 경계를 가리키는 열을 반환한다.
    fn nested_row_cut_frame_columns(
        &self,
        table: &crate::model::table::Table,
        row: usize,
        cut: &[usize],
        block_cut: bool,
        styles: &ResolvedStyleSet,
    ) -> Vec<bool> {
        let columns = usize::from(table.col_count);
        let mut result = vec![false; columns];
        if block_cut {
            return result;
        }
        for (slot, index) in self
            .indexed_row_cut_cell_order(table, row)
            .into_iter()
            .enumerate()
        {
            let cell = &table.cells[index];
            let units = self.cell_units(cell, table, styles);
            if units
                .get(cut.get(slot).copied().unwrap_or(0))
                .is_some_and(|unit| unit.starts_nested_row())
            {
                let start = usize::from(cell.col).min(columns);
                let end = (start + usize::from(cell.col_span)).min(columns);
                result[start..end].fill(true);
            }
        }
        result
    }

    /// [#4128] 이 PartialTable 페이지 조각에 `cell` 의 대상 위치가 실제로 렌더되는가.
    /// pagination 메타데이터(행 범위 + 유닛 컷)와 memoize 된 `cell_units` 만 사용하며
    /// render tree 를 짓지 않는다. 분할 게이트 판정은 `layout_partial_table_cells`
    /// 의 셀 방출 판정과 동일 산식 — 드리프트 금지.
    ///
    /// `target`: `(cell_para_idx, target_line, at_line_start)`. `None` 은 셀 전체 질의
    /// (행/블록 겹침만 판정). 컷 경계(`ord == eu`)는 대상 offset 이 정확히 줄 시작일
    /// 때만 포함한다 — legacy 오름차순 스캔의 inclusive run 매치
    /// (`offset <= char_start + count`)가 이전 조각을 먼저 돌려주는 동작과 결과
    /// 페이지가 일치해야 하기 때문.
    #[allow(clippy::too_many_arguments)]
    pub(crate) fn partial_table_page_contains_cell_position(
        &self,
        table: &crate::model::table::Table,
        cell: &crate::model::table::Cell,
        start_row: usize,
        end_row: usize,
        start_cut: &[usize],
        end_cut: &[usize],
        is_block_split: bool,
        // [#6935] 시작 컷의 인덱스 공간 — 끝 컷과 다를 수 있다.
        start_cut_is_block: bool,
        target: Option<(usize, usize, bool)>,
        styles: &ResolvedStyleSet,
    ) -> bool {
        let cell_row = cell.row as usize;
        let cell_end_row = cell_row + (cell.row_span as usize).max(1);
        // 행/블록 겹침 없음 → 이 조각에 셀 없음. 반복 헤더 사본은 원본 행 페이지가
        // legacy 첫-히트와 같으므로 후보에 넣지 않는다.
        if cell_row >= end_row || cell_end_row <= start_row {
            return false;
        }
        let Some((cell_para_idx, target_line, at_line_start)) = target else {
            return true;
        };
        // 분할 게이트 — layout_partial_table_cells 와 동일 판정
        let split_start_block = if start_cut_is_block && !start_cut.is_empty() {
            Some(rowspan_block_range(table, start_row))
        } else {
            None
        };
        let split_end_block = if is_block_split && !end_cut.is_empty() {
            Some(rowspan_block_range(table, end_row.saturating_sub(1)))
        } else {
            None
        };
        let is_split_start_row = start_cut_covers_cell(
            cell_row,
            cell_end_row,
            start_row,
            start_cut,
            start_cut_is_block,
            split_start_block,
        );
        let is_split_end_row = if is_block_split {
            split_end_block.is_some_and(|(s, e)| cell_row < e && cell_end_row > s)
        } else {
            !end_cut.is_empty() && cell.row_span == 1 && cell_row == end_row.saturating_sub(1)
        };
        if !(is_split_start_row || is_split_end_row) {
            return true; // 이 조각에서 셀이 컷되지 않음 → 전체 가시
        }
        // 비블록 컷 모델은 row_span==1 셀만 부기 — rowspan 걸침 셀은 보수적 포함
        // (straddle 높이 컷 경로는 페이지 후보를 좁힐 권위가 아니다).
        if !start_cut_is_block && !is_block_split && cell.row_span > 1 {
            return true;
        }
        let Some(ord) = self.cell_unit_ordinal_for(cell, table, styles, cell_para_idx, target_line)
        else {
            return true; // 유닛 매핑 실패(빈 셀 등) → 보수적 포함
        };
        let units_len = self.cell_units(cell, table, styles).len();
        let (su, eu) = cell_cut_window(
            table,
            cell,
            start_cut_is_block,
            is_block_split,
            is_split_start_row,
            split_start_block,
            is_split_end_row,
            split_end_block,
            start_cut,
            end_cut,
            Some(units_len),
            start_row,
            end_row.saturating_sub(1),
        );
        ord >= su && (ord < eu || (ord == eu && at_line_start))
    }

    /// [#4149] 커서 fast path 의 프로브 사전 계획 — 이 PartialTable 조각에서 `cell` 의
    /// 컷 창과 창 문단 범위를 계산한다. 분할 게이트 판정은
    /// `layout_partial_table_cells` 의 셀 방출 판정과 동일 산식 — 드리프트 금지.
    /// memoize 된 `cell_units` 만 사용하며 render tree 를 짓지 않는다.
    #[allow(clippy::too_many_arguments)]
    pub(crate) fn partial_table_cell_probe_plan(
        &self,
        table: &crate::model::table::Table,
        cell: &crate::model::table::Cell,
        start_row: usize,
        end_row: usize,
        start_cut: &[usize],
        end_cut: &[usize],
        is_block_split: bool,
        // [#6935] 시작 컷의 인덱스 공간 — 끝 컷과 다를 수 있다.
        start_cut_is_block: bool,
        styles: &ResolvedStyleSet,
        target_para: usize,
    ) -> ProbeCutPlan {
        // rowspan 셀은 straddle 높이-컷 경로(is_rowbreak_straddle)가 얽혀 보수적 폴백.
        if cell.row_span > 1 {
            return ProbeCutPlan::Unsupported;
        }
        // 프로브도 배치용 원점을 재추측하지 않고 renderer의 물리 시작 컷을 쓴다.
        let physical_start_cut = if start_cut_is_block {
            start_cut.to_vec()
        } else {
            self.skip_leading_free_spacers_in_row_cut(table, start_row, start_cut, styles)
        };
        let start_cut = physical_start_cut.as_slice();
        let cell_row = cell.row as usize;
        let cell_end_row = cell_row + (cell.row_span as usize).max(1);
        // 분할 게이트 — layout_partial_table_cells 와 동일 판정
        let split_start_block = if start_cut_is_block && !start_cut.is_empty() {
            Some(rowspan_block_range(table, start_row))
        } else {
            None
        };
        let split_end_block = if is_block_split && !end_cut.is_empty() {
            Some(rowspan_block_range(table, end_row.saturating_sub(1)))
        } else {
            None
        };
        let is_split_start_row = start_cut_covers_cell(
            cell_row,
            cell_end_row,
            start_row,
            start_cut,
            start_cut_is_block,
            split_start_block,
        );
        let is_split_end_row = if is_block_split {
            split_end_block.is_some_and(|(s, e)| cell_row < e && cell_end_row > s)
        } else {
            !end_cut.is_empty() && cell.row_span == 1 && cell_row == end_row.saturating_sub(1)
        };
        if !(is_split_start_row || is_split_end_row) {
            // row_span==1 이므로 is_rowbreak_straddle(rowspan>1 전제) 도달 불가 — 전체 가시.
            return ProbeCutPlan::Uncut;
        }
        let (su, eu) = cell_cut_window(
            table,
            cell,
            start_cut_is_block,
            is_block_split,
            is_split_start_row,
            split_start_block,
            is_split_end_row,
            split_end_block,
            start_cut,
            end_cut,
            None,
            start_row,
            end_row.saturating_sub(1),
        );
        let units = self.cell_units(cell, table, styles);
        let lo = su.min(units.len());
        let hi = eu.min(units.len()).max(lo);
        if lo >= hi {
            return ProbeCutPlan::Unsupported;
        }
        let mut pmin = usize::MAX;
        let mut pmax = 0usize;
        for u in &units[lo..hi] {
            pmin = pmin.min(u.para_idx);
            pmax = pmax.max(u.para_idx);
        }
        if pmin == usize::MAX || pmax >= cell.paragraphs.len() {
            return ProbeCutPlan::Unsupported;
        }
        // cell_was_split 증명 — 전량 레이아웃의 `s != 0 || e != total` 판정과 동치인
        // 충분조건만 취한다:
        //   (a) 어떤 문단의 가시 시작줄 s > 0, 또는
        //   (b) 창 밖 미가시 문단((0,0))의 compose 줄 수 ≥ 1 (recompose 는 줄을
        //       늘리기만 하므로 pre-recompose ≥ 1 ⇒ post ≥ 1 > 0 = e).
        let ranges = self.cell_line_ranges_from_cut(cell, table, styles, su, eu);
        let mut split_proven = ranges.iter().any(|&(s, _)| s > 0);
        if !split_proven {
            for (i, &(s, e)) in ranges.iter().enumerate() {
                if s == 0 && e == 0 && (i < pmin || i > pmax) {
                    if crate::renderer::composer::compose_paragraph_in_context(
                        &cell.paragraphs[i],
                        styles,
                    )
                    .lines
                    .is_empty()
                    {
                        continue;
                    }
                    split_proven = true;
                    break;
                }
            }
        }
        ProbeCutPlan::Cut {
            window_paras: (pmin, pmax),
            split_proven,
            target_in_window: (pmin..=pmax).contains(&target_para),
        }
    }

    /// [#4149] 표 서브트리(호스트 표 + 중첩 표/글상자/캡션)가 프로브를 차단하는
    /// 상태 의존 요소를 갖는지 — 표 포인터 키 메모.
    ///
    /// 차단 근거: (a) 개요/번호 문단은 auto counter 를 소비하는데 프로브는 이전
    /// 페이지 replay 없이 셀 하나만 레이아웃하므로 번호가 어긋난다.
    /// (b) AutoNumber/NewNumber 컨트롤·캡션 자동번호도 동일. (c) 묶음 개체는 내부
    /// 글상자 유무를 싸게 판정할 수 없어 보수적으로 차단.
    pub(crate) fn table_subtree_blocks_cursor_probe(
        &self,
        table: &crate::model::table::Table,
        styles: &ResolvedStyleSet,
    ) -> bool {
        fn paras_block(paras: &[Paragraph], styles: &ResolvedStyleSet) -> bool {
            use crate::model::style::HeadType;
            for p in paras {
                let head = styles
                    .para_styles
                    .get(p.para_shape_id as usize)
                    .map(|s| s.head_type)
                    .unwrap_or(HeadType::None);
                if matches!(head, HeadType::Outline | HeadType::Number) {
                    return true;
                }
                for c in &p.controls {
                    match c {
                        Control::AutoNumber(_) | Control::NewNumber(_) => return true,
                        Control::Table(t) => {
                            // 캡션은 존재 자체가 아니라 auto counter 소비 요소
                            // (개요/번호 헤드·AutoNumber)를 가질 때만 차단한다 —
                            // layout_caption 은 자동 번호 투영으로만
                            // counter 를 만진다.
                            if let Some(cap) = t.caption.as_ref() {
                                if paras_block(&cap.paragraphs, styles) {
                                    return true;
                                }
                            }
                            for cell in &t.cells {
                                if paras_block(&cell.paragraphs, styles) {
                                    return true;
                                }
                            }
                        }
                        Control::Shape(s) => {
                            use crate::model::shape::ShapeObject;
                            let drawing = match &**s {
                                ShapeObject::Rectangle(sh) => Some(&sh.drawing),
                                ShapeObject::Ellipse(sh) => Some(&sh.drawing),
                                ShapeObject::Polygon(sh) => Some(&sh.drawing),
                                ShapeObject::Curve(sh) => Some(&sh.drawing),
                                ShapeObject::Line(_) | ShapeObject::Arc(_) => None,
                                // Group/Chart/Ole 등은 내부 글상자·캡션을 싸게 확인할 수
                                // 없어 보수적으로 차단한다.
                                _ => return true,
                            };
                            if let Some(d) = drawing {
                                if let Some(cap) = d.caption.as_ref() {
                                    if paras_block(&cap.paragraphs, styles) {
                                        return true;
                                    }
                                }
                                if let Some(tb) = d.text_box.as_ref() {
                                    if paras_block(&tb.paragraphs, styles) {
                                        return true;
                                    }
                                }
                            }
                        }
                        Control::Picture(pic) => {
                            if let Some(cap) = pic.caption.as_ref() {
                                if paras_block(&cap.paragraphs, styles) {
                                    return true;
                                }
                            }
                        }
                        _ => {}
                    }
                }
            }
            false
        }
        let key = table as *const crate::model::table::Table as usize;
        if let Some(&cached) = self.cursor_probe_block_cache.borrow().get(&key) {
            return cached;
        }
        let blocked = table
            .cells
            .iter()
            .any(|c| paras_block(&c.paragraphs, styles));
        self.cursor_probe_block_cache
            .borrow_mut()
            .insert(key, blocked);
        blocked
    }

    /// [#2029 추출] 부분 표의 셀 방출 루프 — 셀 geometry/배경/반복 헤더와 셀
    /// 문단 배치를 `table_node.children` 에 방출한다. 셀-간 캐리 없음(실측 muts 0,
    /// 외부 sink = table_node 단일) — 원본 무변경 이동.
    #[allow(clippy::too_many_arguments)]
    fn layout_partial_table_cells(
        &self,
        tree: &mut PageLayoutContext,
        table_node: &mut RenderNode,
        table: &crate::model::table::Table,
        para_index: usize,
        control_index: usize,
        section_index: usize,
        styles: &ResolvedStyleSet,
        outline_numbering_id: u16,
        bin_data_content: &[BinDataContent],
        start_row: usize,
        end_row: usize,
        end_row_height_override: Option<f64>,
        start_row_height_override: Option<f64>,
        is_continuation: bool,
        start_cut: &[usize],
        end_cut: &[usize],
        is_block_split: bool,
        // [#6935] 시작 컷의 인덱스 공간 — 끝 컷과 다를 수 있다.
        start_cut_is_block: bool,
        cell_spacing: f64,
        col_count: usize,
        row_count: usize,
        table_x: f64,
        table_y: f64,
        row_heights: &[f64],
        resolved_row_heights: &[f64],
        straddle_page_bands: &[crate::renderer::pagination::StraddleCellCarry],
        // [#7063 레인②] 첫 행을 쪽 상자로 고정한 조각에서 **내용이 쓸 높이**(예산이 자른 값).
        // 테두리 상자는 `row_heights` 를 쓰고, 내용은 이 값을 쓴다.
        budget_row_height_0: Option<f64>,
        row_col_x: &super::border_rendering::RowColumnGeometry,
        header_rows: &[usize],
        render_rows: &[usize],
        render_row_y: &[f64],
        h_edges: &mut Vec<Vec<Option<super::border_rendering::BorderEdge>>>,
        v_edges: &mut Vec<Vec<Option<super::border_rendering::BorderEdge>>>,
        h_span_covered: &mut [Vec<bool>],
        v_span_covered: &mut [Vec<bool>],
        measured_table: Option<&MeasuredTable>,
        enclosing_cell_ctx: Option<&CellContext>,
        clamp_header_negative_para_offset: bool,
        probe: Option<&PartialTableCellProbe>,
        // [#7095] 쪽이 상자를 정한 비끝 1×1 조각 — 칸 `valign` 을 조각 내용으로 적용한다.
        center_pinned_single_cell: bool,
        center_saved_spanning_cell: Option<usize>,
        align_saved_opening_frame: bool,
        end_row_owns_stored_frame: bool,
        computed_fragment_frame: bool,
        external_frame: Option<super::table_layout::ReflowExternalCutFrame>,
        // 원본 쪽 재시작과 전달된 물리 높이를 함께 확인한 시작/끝 행.
        original_restart_alignment_rows: [Option<usize>; 2],
        // [#6976] 접기 대상 행(모델 행 인덱스)과 그 행이 남긴 여분의 최솟값 수집기.
        fold_last_row: Option<usize>,
        fold_slack: &mut f64,
    ) {
        let parent_owned = external_frame.is_none_or(|frame| frame.parent_owned);
        for (cell_idx, cell) in table.cells.iter().enumerate() {
            // [#4149] 프로브: 대상 셀만 방출. 셀 방출 루프는 셀-간 캐리가 없어
            // (실측 muts 0, 외부 sink = table_node 단일) 생략이 대상 셀 좌표를 바꾸지 않는다.
            if probe.is_some_and(|p| p.cell_idx != cell_idx) {
                continue;
            }
            let cell_row = cell.row as usize;
            let cell_col = cell.col as usize;
            if cell_col >= col_count || cell_row >= row_count {
                continue;
            }

            // 이 셀이 렌더링 범위에 포함되는지 확인
            let cell_end_row = cell_row + cell.row_span as usize;
            let render_range_start = if !header_rows.is_empty() {
                *header_rows.first().unwrap()
            } else {
                start_row
            };
            let render_range_end = end_row.min(row_count);

            // 제목행 반복으로 렌더링되는 셀인지 판별
            let is_repeated_header_cell = !header_rows.is_empty()
                && header_rows.contains(&cell_row)
                && cell_end_row <= start_row;

            // 셀이 렌더링 범위와 겹치는지 확인
            if cell_row >= render_range_end || cell_end_row <= render_range_start {
                if !is_repeated_header_cell {
                    continue;
                }
            }

            // render_rows에서 이 셀의 시작 행 위치 찾기
            // row_span이 페이지 경계를 넘는 셀: cell_row가 render_rows에 없을 수 있음
            // 이 경우 셀 span 범위 내에서 render_rows에 포함된 첫 번째 행을 찾음
            let render_idx = render_rows.iter().position(|&r| r == cell_row).or_else(|| {
                render_rows
                    .iter()
                    .position(|&r| r > cell_row && r < cell_end_row)
            });
            let render_y_offset = match render_idx {
                Some(idx) => render_row_y[idx],
                None => continue, // 렌더링 범위에 없음
            };

            let rcx = &row_col_x[cell_row.min(row_count - 1)];
            let cell_x = table_x + rcx[cell_col];
            let cell_y = table_y + render_y_offset;

            // 병합 셀 크기
            let end_col = (cell_col + cell.col_span as usize).min(col_count);
            let cell_w =
                row_col_x.cell_width(cell_row.min(row_count - 1), cell_col, end_col, cell_spacing);
            let frame_cell_w = self
                .paragraph_frame_width_override(cell, table)
                .unwrap_or(cell_w);

            // 행 높이: 병합 셀의 경우 렌더링 범위 내의 행만 합산
            let mut cell_h = 0.0;
            let mut span_count = 0;
            for rs in 0..cell.row_span as usize {
                let target_r = cell_row + rs;
                if let Some(ri) = render_rows.iter().position(|&r| r == target_r) {
                    cell_h += row_heights[target_r];
                    if span_count > 0 {
                        cell_h += cell_spacing;
                    }
                    span_count += 1;
                    let _ = ri;
                }
            }
            if cell_h <= 0.0 {
                continue;
            }

            // 이 셀이 분할 행에 속하는지 판별 (clip 플래그에 사용)
            // [Task #1025] page-larger 블록 분할이면 컷이 블록-셀 인덱스 → 블록 범위
            // (rowspan-확장)와 셀 교차로 판정. 그 외는 기존 per-row 판정.
            let split_start_block = if start_cut_is_block && !start_cut.is_empty() {
                Some(rowspan_block_range(table, start_row))
            } else {
                None
            };
            let split_end_block = if is_block_split && !end_cut.is_empty() {
                Some(rowspan_block_range(table, end_row.saturating_sub(1)))
            } else {
                None
            };
            let is_split_start_row = start_cut_covers_cell(
                cell_row,
                cell_end_row,
                start_row,
                start_cut,
                start_cut_is_block,
                split_start_block,
            );
            let is_split_end_row = if is_block_split {
                split_end_block.is_some_and(|(s, e)| cell_row < e && cell_end_row > s)
            } else {
                !end_cut.is_empty() && cell.row_span == 1 && cell_row == end_row.saturating_sub(1)
            };
            let is_in_split_row = is_split_start_row || is_split_end_row;
            // [#5946] 쪽 분할이 행 높이 override 로만 이어질 때(컷 부기 없음)
            // 중첩 표·긴 셀 내용이 조각 높이를 무시하고 다음 행 위로 포개진다.
            // 행정업무운영편람 141쪽: '3. 쪽' 예시 서식이 '4. 항목란' 과 겹침.
            let height_override_clip = (start_row_height_override.is_some()
                && cell_row == start_row)
                || (end_row_height_override.is_some()
                    && end_row
                        .checked_sub(1)
                        .is_some_and(|last| cell_row <= last && cell_end_row > last));

            // [Task #1748] RowBreak 표에서 페이지 경계가 rowspan 블록 내부를 per-row
            // 분할할 때(#1022 경로), 컷 부기(start_cut/end_cut)는 컷 행의 row_span==1
            // 셀만 담아 경계에 걸친 rowspan 셀은 컷 없이 전체 렌더된다 — 컷 페이지에선
            // 셀 박스 아래로 흘러넘치고(+13px 잉크), 연속 페이지에선 처음부터
            // 재렌더(중복)된다. 높이 기반 유닛 컷으로 가시 줄 범위를 제한한다.
            let straddles_fragment_start = cell_row < start_row && cell_end_row > start_row;
            let straddles_fragment_end = cell_crosses_fragment_end(cell, render_range_end, end_cut)
                || (cell_row < render_range_end
                    && cell_row + usize::from(cell.row_span) == render_range_end
                    && end_row_height_override.is_some()
                    && self.cell_uses_plain_reflow_units(cell, table));
            // [#6024] block-split 조각이라도 **컷이 비어 있는 쪽 경계**(행 경계
            // 컷)의 straddle rowspan 셀은 split-block 범위(is_in_split_row)에
            // 잡히지 않는다 — 그대로 두면 연속 조각이 병합 셀 내용을 처음부터
            // 재렌더한다(10857 p9: 밴드 라벨 '10·사무분장 조정' 중복, 한글은 빈
            // 칸). 컷이 있는 쪽 경계는 종전대로 cell_cut_window 가 소관한다.
            let straddle_start_uncovered = (straddles_fragment_start
                && (!start_cut_is_block || start_cut.is_empty()))
                // [#7226] 컷에 적을 자리가 없어 빈 `start_cut` 으로 재개한 걸침 전용
                // 행 — 앞 조각이 소비한 밴드만큼 유닛 컷을 이어 중복 렌더를 막는다.
                || resumes_inside_own_start_row(
                    table,
                    cell,
                    start_row,
                    start_cut,
                    start_cut_is_block,
                    start_row_height_override,
                    straddle_page_bands,
                );
            let straddle_end_uncovered =
                straddles_fragment_end && (!is_block_split || end_cut.is_empty());
            // CellBreak 표의 경계 straddle rowspan 셀도 같은 기전으로 중복된다
            // (10857 p67 '조사관 교육훈련', pb=CellBreak 실측) — 높이-유닛 컷은
            // 분할 모드와 무관한 산술이라 함께 적용한다.
            let is_rowbreak_straddle = (!is_in_split_row
                || (straddle_start_uncovered && !start_cut_is_block))
                && cell.row_span > 1
                && !is_repeated_header_cell
                && matches!(
                    table.layout_page_break(),
                    crate::model::table::TablePageBreak::RowBreak
                        | crate::model::table::TablePageBreak::CellBreak
                )
                && (straddle_start_uncovered || straddle_end_uncovered);
            let cell_id = tree.next_id();
            let mut cell_node = RenderNode::new(
                cell_id,
                if parent_owned {
                    RenderNodeType::TableCell(TableCellNode {
                        col: cell.col,
                        row: cell.row,
                        col_span: cell.col_span,
                        row_span: cell.row_span,
                        border_fill_id: cell.border_fill_id,
                        text_direction: cell.text_direction,
                        // 온전한 행도 일반 표와 같은 셀 소유 경계로 그린다.
                        // 쪽 조각 여부는 아래 별도 필드가 소유한다. 저장 줄이
                        // 인증한 중첩 표 노출은 공통 clip 확장 경로가 처리한다.
                        clip: true,
                        closed_reflow_frame: false,
                        page_fragment: is_in_split_row
                            || is_rowbreak_straddle
                            || height_override_clip,
                        model_cell_index: Some(cell_idx as u32),
                        model_para_range: None,
                    })
                } else {
                    RenderNodeType::Group(GroupNode {
                        paint_transform: None,
                        section_index: None,
                        para_index: None,
                        control_index: None,
                    })
                },
                BoundingBox::new(cell_x, cell_y, cell_w, cell_h),
            );

            // 셀 BorderFill 조회
            let border_style = if parent_owned && cell.border_fill_id > 0 {
                let idx = (cell.border_fill_id as usize).saturating_sub(1);
                styles.border_styles.get(idx)
            } else {
                None
            };

            // #7028: 가로쓰기와 세로쓰기 경로가 갈라지기 전에 한 번 판정한다.
            // 나중에 확장될 수 있는 내용 클립 대신 격자 상자를 사용한다.
            // 실제 컷이나 높이 덮어쓰기가 적용된 셀은 기존 대각선 처리를 유지한다.
            let cell_diagonals = border_style
                .filter(|bs| border_style_has_diagonal(bs))
                .filter(|_| {
                    !is_in_split_row
                        && !height_override_clip
                        && partial_cell_has_complete_rows(cell, render_rows)
                        && !partial_cell_intersects_diagonal_zone(cell, table, styles)
                })
                .map(|bs| render_cell_diagonal(tree, bs, cell_x, cell_y, cell_w, cell_h))
                .unwrap_or_default();

            // 셀 배경
            self.render_cell_background(
                tree,
                &mut cell_node,
                border_style,
                cell_x,
                cell_y,
                cell_w,
                cell_h,
                bin_data_content,
            );

            let (mut pad_left, mut pad_right, pad_top, pad_bottom) =
                self.resolve_stored_nested_cell_padding(cell, table, styles);

            // 실제 cut이 있는 셀은 cursor probe와 전체 렌더링이 같은 문단 창을
            // 소비한다. 다중줄은 padding shrink의 조기 반환, split_proven은 Top
            // 정렬을 보장하므로 창 밖의 compose/높이 합산은 결과에 쓰이지 않는다.
            // rowspan·세로쓰기·실제로 잘리지 않는 셀은 기존 전량 경로를 유지한다.
            // 유한한 저장 프레임은 가운데·아래 정렬도 보존할 수 있다.
            // 위 정렬 전용 탐색 최적화로 선택한 앞 조각의 높이를 생략하지 않는다.
            let straddle_cut_units = is_rowbreak_straddle.then(|| {
                self.rowbreak_straddle_cut_units(
                    table,
                    cell,
                    start_row,
                    render_range_end,
                    start_cut,
                    start_cut_is_block,
                    start_row_height_override,
                    end_cut,
                    is_block_split,
                    end_row_height_override,
                    cell_h,
                    resolved_row_heights,
                    straddle_page_bands,
                    styles,
                )
            });
            let opening_cell_cut = (!is_continuation
                && is_split_end_row
                && !is_block_split
                && !start_cut_is_block
                && cell.row_span == 1)
                .then(|| {
                    cell_cut_window(
                        table,
                        cell,
                        start_cut_is_block,
                        is_block_split,
                        is_split_start_row,
                        split_start_block,
                        is_split_end_row,
                        split_end_block,
                        start_cut,
                        end_cut,
                        None,
                        start_row,
                        end_row.saturating_sub(1),
                    )
                });
            let stored_mixed_opening_frame = opening_cell_cut.and_then(|(start, end)| {
                self.stored_mixed_opening_cell_frame(
                    cell,
                    table,
                    styles,
                    start,
                    end,
                    resolved_row_heights,
                )
            });
            // 저장 텍스트 병합 셀의 마지막 조각은 남은 소유 유닛을 최종 물리 셀 상자 안에서 정렬한다.
            // 연속된 원본 줄 위치도 포함하며, 선택한 컷을 아래 줄 구성과 실제 그리기에 재사용한다.
            let stored_restart_span_frame_owns_alignment = !is_in_split_row
                && cell_end_row <= render_range_end
                && straddle_cut_units.is_some_and(|(start, end)| {
                    let units = self.cell_units(cell, table, styles);
                    start > 0
                        && end >= units.len()
                        && self.stored_plain_text_span_frame(table, cell)
                });
            let original_restart_span_owns_alignment = original_restart_alignment_rows[1]
                .is_some_and(|row| cell_row <= row && row < cell_end_row)
                && straddle_cut_units.is_some_and(|(_, end)| {
                    self.original_restart_span_cut_owns_alignment(table, cell, end, styles)
                });
            let end_row_source_frame_candidate = end_row_height_override.is_some()
                && cell_row + 1 == end_row
                && !end_cut.is_empty()
                && !is_block_split;
            // 원본 전체 행과 중첩 단일 셀은 물리 프레임을 인증하는 출처가 다르다.
            // 정렬 소유는 둘 다 보존하되, 선택 줄 높이의 소비 근거를 합치지 않는다.
            let full_width_row_frame_owns_alignment = end_row_source_frame_candidate
                && self
                    .stored_full_width_row_declared_height(
                        table,
                        cell_row,
                        styles,
                        self.current_body_area.get().3,
                    )
                    .is_some();
            let nested_single_cell_frame_owns_alignment = end_row_source_frame_candidate
                && self
                    .saved_nested_single_cell_frame_height(table, start_cut, end_cut, styles)
                    .is_some();
            // 재귀 자식의 셀 상자는 명시적 override가 없어도 선택 컷 높이를 쓴다.
            // 원본 재시작에서 끝난 조각은 그 실제 상자 안에 선택 줄만 정렬한다.
            let plain_cut_frame_owns_alignment = is_split_end_row
                && !is_block_split
                && !start_cut_is_block
                && (cell_row != start_row || start_cut.iter().all(|cut| *cut == 0))
                && (self
                    .row_plain_restart_capacity_cut(table, cell_row, styles)
                    .is_some_and(|cut| cut == end_cut)
                    // 문단 경계의 저장 쪽 재시작(다음 문단 첫 줄 vpos 0)도 같은 원본 조각이다.
                    // 1342000 31쪽 행 24 경남 칸(valign Center): 한/글 2020 PDF 는 이 조각 안
                    // 6줄을 가운데 정렬해 첫 줄을 조각 위 9.8px 에 둔다(위 정렬이면 3.8px).
                    // 칸 하나뿐인 표는 칸이 곧 표 조각이라 한/글이 위에서부터 흘린다
                    // (rowbreak-problem-pages 13쪽·1382000 20쪽 1×1 Center 칸: 첫 줄이 위 정렬 자리).
                    || table.cells.len() > 1
                        && self.row_cut_ends_at_stored_page_reset(
                        table,
                        cell_row,
                        &[],
                        end_cut,
                        styles,
                    ));
            let cut_frame_owns_alignment = is_continuation
                && start_row_height_override.is_some()
                && cell_row == start_row
                && cell.row_span == 1
                && ((start_cut_is_block
                    && end_cut.is_empty()
                    && self
                        .saved_block_reset_opening_frame_height(table, start_row, start_cut, styles)
                        .is_some())
                    || (!start_cut_is_block
                        && start_cut
                            .get(single_row_cut_index(table, cell))
                            .is_some_and(|&start| {
                                let units = self.cell_units(cell, table, styles);
                                let (_, end) = cell_cut_window(
                                    table,
                                    cell,
                                    start_cut_is_block,
                                    is_block_split,
                                    is_split_start_row,
                                    split_start_block,
                                    is_split_end_row,
                                    split_end_block,
                                    start_cut,
                                    end_cut,
                                    None,
                                    start_row,
                                    end_row.saturating_sub(1),
                                );
                                // 종료 컷 목록이 비어 있지 않아도 모든 내용 유닛을 이미 소유하고 선언된 물리 행만 이어질 수 있다.
                                // 이 프레임에서는 남은 내용 전체를 정렬한다. 실제 내용 컷이 있으면 위쪽 원점을 유지해야 한다.
                                // 저장 행 잔여 프레임도 완전한 남은 내용의 정렬 공간을 소유한다.
                                end >= units.len()
                                    && (self.stored_row_frame_owns_complete_tail(table, cell)
                                        || self.row_uses_reflow_physical_frame(table, cell_row)
                                        || (self.profile.get().hwp5_stored_pagination_layout()
                                            && (!self.profile.get().session_edited()
                                                || self
                                                    .stored_full_width_row_declared_height(
                                                        table,
                                                        cell_row,
                                                        styles,
                                                        self.current_body_area.get().3,
                                                    )
                                                    .is_some())
                                            && self.cell_unit_opens_stored_page_frame(
                                                cell, table, styles, start,
                                            ))
                                        || (self.profile.get().hwpx_stored_layout()
                                            && self
                                                .stored_full_width_row_declared_height(
                                                    table,
                                                    cell_row,
                                                    styles,
                                                    self.current_body_area.get().3,
                                                )
                                                .is_some()
                                            && self.cell_unit_opens_stored_page_frame(
                                                cell, table, styles, start,
                                            ))
                                        || self
                                            .stored_first_frame_row_remainder(
                                                table,
                                                start_row,
                                                start_cut,
                                                resolved_row_heights,
                                                styles,
                                            )
                                            .is_some_and(|height| {
                                                start_row_height_override == Some(height)
                                            })
                                        || self.stored_paragraph_allows_orphan_split(
                                            table, cell, &units, start, styles,
                                        ))
                            })));
            // 유효한 저장 앞 프레임과 이어받기 프레임은 원본 정렬을 소유한다.
            // 줄 구성 창과 최종 배치 원점에서 같은 소유 결과를 사용한다.
            let ordinary_source_frame_owns_alignment = cell.row_span == 1
                && !is_block_split
                && !start_cut_is_block
                && (original_restart_alignment_rows.contains(&Some(cell_row))
                    || (end_row_height_override.is_some()
                        && cell_row + 1 == end_row
                        && self.stored_ordinary_row_frame_owns_alignment(
                            table, cell_row, end_cut, styles,
                        ))
                    || (is_continuation
                        && start_row_height_override.is_some()
                        && cell_row == start_row
                        && self.stored_ordinary_row_frame_owns_alignment(
                            table, cell_row, start_cut, styles,
                        )));
            let heading_frame_owns_alignment = end_row_height_override.is_some()
                && cell_row + 1 == end_row
                && self.stored_heading_before_inline_frame_cut(
                    table,
                    cell_row,
                    if cell_row == start_row {
                        start_cut
                    } else {
                        &[]
                    },
                    end_cut,
                    styles,
                );
            // 저장 재시작 컷의 내용 밖 빈 띠도 수용한 마지막 행 상자에 속한다.
            // 그 물리 상자를 읽을 때에는 같은 선택 줄을 원본 정렬로 배치한다.
            // 임의 예산 컷·병합/개체 셀에는 이 소유를 추정하지 않는다.
            let closing_source_frame_owns_alignment = end_row_owns_stored_frame
                && cell.row_span == 1
                && cell_row + 1 == end_row
                && end_row_height_override.is_some();
            let accepted_block_frame_owns_alignment = measured_table.is_some_and(|measured| {
                measured.fragment_block_frames.iter().any(|&(first, end)| {
                    first <= cell_row && cell_row + usize::from(cell.row_span) <= end
                })
            });
            // 스캔과 행 배치가 인증한 일반 행의 독립 최소를 그대로 소비한다.
            // 앞 조각에서 소비한 0 높이 행은 새 정렬 공간이 아니며, 실제 내용 컷이
            // 끝나지 않았거나 뒤의 선 접기가 상자를 바꾸는 경우에는 인증하지 않는다.
            let completed_block_frame_owns_alignment = split_start_block.is_some_and(|block| {
                if !self.stored_plain_text_span_frame(table, cell)
                    || fold_last_row.is_some_and(|row| cell_row <= row && row < cell_end_row)
                {
                    return false;
                }
                let units = self.cell_units(cell, table, styles);
                let (start, end) = cell_cut_window(
                    table,
                    cell,
                    start_cut_is_block,
                    is_block_split,
                    is_split_start_row,
                    split_start_block,
                    is_split_end_row,
                    split_end_block,
                    start_cut,
                    end_cut,
                    Some(units.len()),
                    start_row,
                    end_row.saturating_sub(1),
                );
                let end_units = if split_end_block == Some(block) {
                    end_cut
                } else {
                    &[]
                };
                let mut rows = (cell_row.max(start_row)..cell_end_row.min(end_row))
                    .filter(|&row| row_heights[row] > 0.0)
                    .peekable();
                start > 0
                    && end >= units.len()
                    && rows.peek().is_some()
                    && rows.all(|row| {
                        self.stored_complete_block_row_minimum(
                            table, block, row, start_cut, end_units, styles,
                        )
                        .is_some_and(|minimum| row_heights[row] >= minimum)
                    })
            });
            let computed_frame_owns_alignment = computed_fragment_frame
                && cell.row_span == 1
                && cell_row + 1 == end_row
                && !is_block_split
                && !start_cut_is_block
                && end_row_height_override.is_some();
            let stored_span_frame_owns_alignment = accepted_block_frame_owns_alignment
                || completed_block_frame_owns_alignment
                || stored_restart_span_frame_owns_alignment
                || is_rowbreak_straddle
                    && cell.row_span > 1
                    && cell.vertical_align != crate::model::table::VerticalAlign::Top
                    && straddle_cut_units.is_some_and(|(start, end)| {
                        self.stored_span_cut_owns_alignment(cell, table, styles, start, end)
                            || (start < end
                                && self.current_program_span_owns_alignment(table, cell))
                            || self.stored_plain_spanning_frame_owns_alignment(
                                cell, table, start, end, end_row, styles,
                            )
                            || (start > 0
                                && end >= self.cell_units(cell, table, styles).len()
                                && straddle_page_bands.iter().any(|carry| {
                                    carry.cell_index == cell_idx
                                        && (carry.owns_blank_band || carry.physical_height > 0.0)
                                }))
                    });
            // 하위 원본 행은 끝부분의 빈 띠를 소유한다. 상위 커서는
            // 전체 하위 표를 상위 표의 세로 정렬 띠로 옮기지 않고
            // 그 물리 공간을 전달한다.
            let descendant_owns_closing_band = cell.row_span == 1
                && cell_row + 1 == end_row
                && self
                    .stored_nested_plain_cut_frame_extra(
                        table,
                        cell_row,
                        if cell_row == start_row {
                            start_cut
                        } else {
                            &[]
                        },
                        end_cut,
                        styles,
                    )
                    .is_some();
            let complete_suffix_frame = is_continuation
                && start_row_height_override.is_none()
                && is_split_start_row
                && cell.row_span == 1
                && cell.text_direction == 0
                && {
                    // 남은 내용 전체의 정렬 소유는 컷의 표현 형식과 무관하다.
                    // 실제 줄 선택과 같은 Query로 행/블록 서수를 함께 해석한다.
                    // 이미 소비한 개체나 완결된 현재 개체가 있다는 이유로
                    // 현재 꼬리까지 Top으로 바꾸지 않는다. 부분 유닛 컷과
                    // 하위 행의 닫는 띠 소유는 각각의 기존 계약이 처리한다.
                    let units = self.cell_units(cell, table, styles);
                    let (start, end) = cell_cut_window(
                        table,
                        cell,
                        start_cut_is_block,
                        is_block_split,
                        is_split_start_row,
                        split_start_block,
                        is_split_end_row,
                        split_end_block,
                        start_cut,
                        end_cut,
                        Some(units.len()),
                        start_row,
                        end_row.saturating_sub(1),
                    );
                    start > 0 && end >= units.len()
                };
            let frame_owns_alignment = !descendant_owns_closing_band
                && (ordinary_source_frame_owns_alignment
                    || stored_mixed_opening_frame.is_some()
                    || closing_source_frame_owns_alignment
                    || computed_frame_owns_alignment
                    || complete_suffix_frame
                    || heading_frame_owns_alignment
                    || self
                        .stored_nested_text_frame_for_cut(
                            table,
                            start_cut,
                            end_cut,
                            start_cut_is_block,
                            is_block_split,
                        )
                        .is_some()
                    || full_width_row_frame_owns_alignment
                    || plain_cut_frame_owns_alignment
                    || nested_single_cell_frame_owns_alignment
                    || cut_frame_owns_alignment
                    || stored_span_frame_owns_alignment
                    || original_restart_span_owns_alignment);
            // 분할 행: [Task #993/#1025] start_cut/end_cut(유닛 컷)으로 표시할 줄 범위 계산.
            // 블록 분할이면 블록-셀 (row,col) 인덱스, 그 외는 행내 row_span==1 col 인덱스.
            let cut_units: Option<(usize, usize)> = if let Some(cut) = straddle_page_bands
                .iter()
                .find(|carry| carry.cell_index == cell_idx)
                .and_then(|carry| carry.fragment_cut)
            {
                Some(cut)
            } else if is_in_split_row {
                let (mut su, mut eu) = cell_cut_window(
                    table,
                    cell,
                    start_cut_is_block,
                    is_block_split,
                    is_split_start_row,
                    split_start_block,
                    is_split_end_row,
                    split_end_block,
                    start_cut,
                    end_cut,
                    None,
                    start_row,
                    end_row.saturating_sub(1),
                );
                // 조각의 종료 BlockCut이 이 병합 셀을 소유하더라도 시작 RowCut은 소유하지 않는다.
                // 종료 슬롯을 보존하고, 예약과 동일한 물리 시작 앞부분을 소비한다.
                if straddle_start_uncovered && !start_cut_is_block {
                    if let Some((physical_start, _)) = straddle_cut_units {
                        su = su.max(physical_start);
                    }
                }
                // 시작 행의 걸침 셀도 수용 단계와 같은 상자·원본 유닛 컷을 쓴다.
                // 옆 셀의 RowCut 높이로 끝을 다시 추정하면 병합 내용이 누락·반복된다.
                if eu == usize::MAX && cell.row_span > 1 && cell_end_row > render_range_end {
                    let (_, accepted_end) = self.rowbreak_straddle_cut_units(
                        table,
                        cell,
                        start_row,
                        render_range_end,
                        start_cut,
                        start_cut_is_block,
                        start_row_height_override,
                        end_cut,
                        is_block_split,
                        end_row_height_override,
                        cell_h,
                        resolved_row_heights,
                        straddle_page_bands,
                        styles,
                    );
                    eu = accepted_end.max(su);
                }
                Some((su, eu))
            } else if is_rowbreak_straddle {
                straddle_cut_units
            } else {
                None
            };
            let saved_frame_needs_alignment =
                (align_saved_opening_frame && cell_row + 1 == end_row || frame_owns_alignment)
                    && cell.vertical_align != crate::model::table::VerticalAlign::Top;
            let mixed_opening_frame = cut_units
                .and_then(|(start, end)| {
                    self.stored_mixed_opening_frame(table, cell, styles, start, end)
                })
                .filter(|frame| frame.physical_height == cell_h);
            let declared_opening_content_height = (!is_continuation)
                .then(|| self.declared_nested_opening_cut_height(table, start_cut, end_cut, styles))
                .flatten()
                .map(|frame| frame - pad_top - pad_bottom);
            // 선언된 첫 쪽과 현재 수용 상자가 같은 프레임이면 내용 높이와
            // 원본 정렬도 그 결과가 소유한다. Top 전용 창으로 다시 판정하지 않는다.
            let declared_opening_frame_owns_alignment = declared_opening_content_height
                .is_some_and(|height| {
                    (height + pad_top + pad_bottom - cell_h).abs() <= hwpunit_to_px(2, self.dpi)
                });
            // 실제 그림 앵커 컷을 예약한 첫 행 상자만 선택한 앞 내용의 정렬을 소유한다.
            // 뒤 그림까지 포함한 전체 셀 높이 또는 Top 강제로 다시 해석하지 않는다.
            let atomic_opening_alignment_height = (!is_block_split
                && !start_cut_is_block
                && !(is_continuation && cell_row == start_row)
                && cell_row + 1 == end_row
                && cut_units.is_some_and(|(start, end)| start == 0 && end > 0)
                && end_row_height_override.is_some())
            .then(|| {
                self.row_declared_first_frame(
                    table,
                    cell_row,
                    resolved_row_heights[cell_row],
                    end_cut,
                    styles,
                )
                .filter(|frame| cell_h <= frame.height + 0.5)
                .and_then(|frame| frame.cell_alignment_height(cell_idx))
            })
            .flatten();
            let atomic_opening_frame_owns_alignment = atomic_opening_alignment_height.is_some();
            let composition_window = if saved_frame_needs_alignment
                || mixed_opening_frame.is_some()
                || declared_opening_frame_owns_alignment
                || atomic_opening_frame_owns_alignment
            {
                None
            } else if let Some(p) = probe.filter(|p| p.windowed) {
                Some(p.window_paras)
            } else if probe.is_none()
                && cell.text_direction == 0
                && cell.paragraphs.iter().any(|p| p.line_segs.len() >= 2)
            {
                match self.partial_table_cell_probe_plan(
                    table,
                    cell,
                    start_row,
                    end_row,
                    start_cut,
                    end_cut,
                    is_block_split,
                    start_cut_is_block,
                    styles,
                    0,
                ) {
                    ProbeCutPlan::Cut {
                        window_paras,
                        split_proven: true,
                        ..
                    } => Some(window_paras),
                    _ => None,
                }
            } else {
                None
            };
            let windowed_composition = composition_window.is_some();
            let mut composed_store: CellComposedStore;
            if windowed_composition {
                // shrink 생략 근거: 프로브 사전 게이트가 line_segs>=2 문단 존재를
                // 증명했고, shrunk_cell_horizontal_padding 은 그 경우 composed 를
                // 읽지 않고 패딩을 그대로 반환한다 (조기 탈출과 동일 결과).
                composed_store = CellComposedStore::Lazy(vec![None; cell.paragraphs.len()]);
            } else {
                // 셀 내 문단 구성
                let mut composed_paras: Vec<_> = cell
                    .paragraphs
                    .iter()
                    .map(|p| crate::renderer::composer::compose_paragraph_in_context(p, styles))
                    .collect();

                // [#7080] **쪽 경계에 걸친 칸은 여백을 보존한다.**
                //
                // 이 경로의 `cell_h` 는 칸 전체 높이가 아니라 **이 조각의 높이**다. 그래서
                // #7413 의 높이 판정("줄바꿈한 결과가 칸 높이를 넘는가")에 조각 높이가
                // 들어가면, 쪽을 넘는 긴 칸은 어느 조각에서도 줄바꿈 결과가 그 조각 높이를
                // 넘으므로 **늘 "넘친다"** 로 판정돼 여백이 1px 까지 깎인다(80168 75쪽:
                // 23734 → 23866). 반면 컷을 정하는 측정(`cell_units_uncached`)은 원 패딩으로
                // 재므로 측정과 배치가 서로 다른 폭을 쓴다(AGENTS.md "측정과 배치의 공통 결과").
                //
                // 조각 높이로는 이 판정을 할 수 없으니 여기서는 깎지 않는다. 칸 전체 높이를
                // 아는 경로(`table_layout.rs`·`table_cell_content.rs`)의 판정은 그대로다.
                let fragment_cell =
                    is_in_split_row || straddles_fragment_start || straddles_fragment_end;

                // 텍스트 오버플로우 시 좌우 패딩 축소
                let (new_pl, new_pr) = self.shrink_cell_padding_for_overflow(
                    pad_left,
                    pad_right,
                    cell_w,
                    (cell_h - pad_top - pad_bottom).max(0.0),
                    &composed_paras,
                    &cell.paragraphs,
                    styles,
                    cell.apply_inner_margin || fragment_cell,
                    cell.line_wrap == crate::model::table::CELL_LINE_WRAP_SQUEEZE,
                );
                pad_left = new_pl;
                pad_right = new_pr;

                let inner_width_for_recompose = crate::renderer::composer::cell_inner_text_width(
                    frame_cell_w,
                    pad_left,
                    pad_right,
                    self.dpi,
                );
                // [Task #671] line_segs 비어 있는 셀 paragraph 의 단일 ComposedLine 압축
                // 결과를 셀 가용 너비 (inner_width) 에 맞춰 다중 ComposedLine 으로 재분할.
                for (cpi, para) in cell.paragraphs.iter().enumerate() {
                    if let Some(comp) = composed_paras.get_mut(cpi) {
                        *comp = self.compose_cell_unit_paragraph(
                            para,
                            cell.text_direction,
                            inner_width_for_recompose,
                            styles,
                        );
                    }
                }
                composed_store = CellComposedStore::Eager(composed_paras);
            }

            let inner_x = cell_x + pad_left;
            let inner_width = crate::renderer::composer::cell_inner_text_width(
                frame_cell_w,
                pad_left,
                pad_right,
                self.dpi,
            );
            // [#7063 레인②] 테두리 상자는 `cell_h`(쪽이 정한 높이)를 쓰지만, 내용이 쓸 높이는
            // 예산이 자른 값이다. 첫 행을 쪽 상자로 고정한 조각에서만 둘이 갈린다.
            let content_cell_h = match budget_row_height_0 {
                Some(budget) if cell_row == 0 && cell.row_span == 1 => budget,
                _ => cell_h,
            };
            let inner_height = (content_cell_h - pad_top - pad_bottom).max(0.0);

            let reflow_content_height = cut_units.and_then(|(start, end)| {
                self.reflow_partial_cell_content_height(cell, table, start, end, styles)
            });
            let atomic_suffix_content_height = complete_suffix_frame
                .then(|| {
                    cut_units.and_then(|(start, end)| {
                        self.stored_atomic_picture_suffix_content_height(
                            cell, table, styles, start, end,
                        )
                    })
                })
                .flatten();
            if reflow_content_height.is_some() {
                if let RenderNodeType::TableCell(meta) = &mut cell_node.node_type {
                    // 자식의 가시 폭은 부모의 물리 괘선 폭을 늘리지 않는다.
                    // 자식 선언 폭은 유지하되 부모가 소유한 셀 경계에서 표시를 제한한다.
                    meta.closed_reflow_frame = true;
                    meta.clip = true;
                }
            }
            let line_ranges: Option<Vec<(usize, usize)>> = cut_units
                .map(|(su, eu)| self.cell_line_ranges_from_cut(cell, table, styles, su, eu));
            let authenticated_hwpx_frame =
                self.direct_hwpx_cell_preserves_stored_frame(cell, table);
            // 빈 저장 줄의 높이를 배치에서 재추측하지 않는다. 현재 컷이 소유한
            // 같은 CellUnit의 물리 전진량을 소비하며, 다른 조각의 빈 줄은 제외한다.
            let stored_empty_line_advances = if authenticated_hwpx_frame {
                self.stored_empty_line_advances_for_cut(cell, table, styles, cut_units)
            } else {
                vec![None; cell.paragraphs.len()]
            };
            // #7032: 빈 문자열의 줄 구성은 의도적으로 줄을 생성하지 않는다.
            // 기존 빈 문단 적용 조건과 유닛 원장을 유지하며, 이 경로에서
            // 컷 정책이나 공통 줄 구성기를 변경하지 않는다.
            let empty_paragraphs: Vec<bool> = cell
                .paragraphs
                .iter()
                .enumerate()
                .map(|(index, para)| {
                    cell.text_direction == 0
                        && !self.profile.get().hwp3_layout()
                        && para.text.is_empty()
                        && (stored_empty_line_advances[index].is_some()
                            || super::paragraph_layout::empty_no_lineseg_paragraph_metrics(
                                para,
                                styles,
                                styles.para_styles.get(para.para_shape_id as usize),
                                false,
                                self.dpi,
                            )
                            .is_some())
                })
                .collect();
            let empty_owners = cut_units
                .filter(|_| empty_paragraphs.iter().any(|&empty| empty))
                .map(|(su, eu)| self.cell_cut_empty_paragraph_owners(cell, table, styles, su, eu));
            // 글자 없이 비글자처럼 취급 개체만 든 빈 문단은 빈 줄을 소유하지 않아도 이
            // 조각에 그 개체 유닛이 있으면 이 조각이 문단을 소유한다. 빈 줄 소유만 보면
            // 개체가 어느 조각에서도 그려지지 않고(행이 쪽을 넘어 나뉘거나 여러 행을
            // 차지하는 칸), 소유하지 않은 채 그리면 칸 내용 높이·정렬에서 빠진다.
            let control_owned_empty_paragraph = |pi: usize| {
                empty_paragraphs[pi]
                    && !empty_owners.as_ref().is_none_or(|owners| owners[pi])
                    && cut_units.is_some_and(|(su, eu)| {
                        self.cell_cut_contains_non_inline_control_units(
                            cell, table, styles, su, eu, pi,
                        )
                    })
            };
            let owns_empty_paragraph = |pi: usize| {
                empty_paragraphs[pi]
                    && (empty_owners.as_ref().is_none_or(|owners| owners[pi])
                        || control_owned_empty_paragraph(pi))
            };
            // 개체로 소유한 빈 문단의 정렬 높이는 빈 줄과 개체 띠 중 큰 쪽이다.
            // 개체는 문단 원점에 오프셋으로 놓이고 빈 줄과 같은 띠를 차지한다.
            let control_owned_empty_paragraph_height = |pi: usize, lines_h: f64| {
                if control_owned_empty_paragraph(pi) {
                    lines_h.max(self.calc_cell_wrap_objects_bottom_height(
                        std::slice::from_ref(&cell.paragraphs[pi]),
                        styles,
                    ))
                } else {
                    lines_h
                }
            };
            // 셀 내 텍스트 높이 (분할 행이면 줄 범위 내만 계산)
            // spacing_before: 셀 첫 문단 제외, spacing_after: 셀 마지막 문단 제외
            let split_para_count = cell.paragraphs.len();
            // 정렬할 내용의 끝은 원본 셀의 끝이 아니라 현재 조각의 마지막 가시 줄이다.
            // 뒤 조각으로 넘어가는 줄간격은 물리 높이에는 남아도 가시 내용 높이가 아니다.
            let last_visible_line = line_ranges.as_ref().and_then(|ranges| {
                ranges
                    .iter()
                    .enumerate()
                    .rev()
                    .find_map(|(pi, &(start, end))| {
                        (start < end).then_some((pi, end.saturating_sub(1)))
                    })
            });
            let stored_picture_cut_frame = self
                .stored_picture_cut_frame(cell, table, styles, cut_units)
                .filter(|frame| {
                    let partial = cut_units.is_some_and(|(start, end)| {
                        start > 0 || end < self.cell_units(cell, table, styles).len()
                    });
                    let block = split_end_block.or(split_start_block);
                    let owns_physical_rows = measured_table.is_some()
                        && block.is_some_and(|block| {
                            let start = if split_start_block == Some(block) {
                                start_cut
                            } else {
                                &[]
                            };
                            let end = if split_end_block == Some(block) {
                                end_cut
                            } else {
                                &[]
                            };
                            let first_row = cell_row.max(start_row);
                            let last_row = (cell_row + usize::from(cell.row_span)).min(end_row);
                            // 이어받은 블록은 이미 소비한 앞 행을 0 높이로 남긴다.
                            // 그 행에는 이번 조각의 공간 소유를 다시 요구하지 않는다.
                            let mut physical_rows = (first_row..last_row)
                                .filter(|&row| row_heights[row] > 0.0)
                                .peekable();
                            physical_rows.peek().is_some()
                                && physical_rows.all(|row| {
                                    self.row_block_cut_uses_measured_height(
                                        table, block, row, start, end, styles,
                                    )
                                })
                        });
                    // 새 수용 장부의 완전 블록 표시와 구분한다. 부분 그림 컷은
                    // 예약·행 배치에 쓴 같은 물리 행 질의가 증명하는 띠만 소유한다.
                    !partial
                        || (frame.content_height <= inner_height + self.dpi / 7200.0
                            && owns_physical_rows)
                });
            // [#4149] windowed 프로브: 아래에서 effective_align 이 Top 으로 확정되므로
            // (cell_was_split=true 사전 증명) total_content_height 는 미사용 — 0 고정.
            let total_content_height = if windowed_composition {
                0.0
            } else if let Some(frame) = &stored_picture_cut_frame {
                frame.content_height
            } else if let Some(height) = atomic_suffix_content_height {
                height
            } else if let Some(ref ranges) = line_ranges {
                let mut total = 0.0;
                for (pi, ((comp, para), &(start, end))) in composed_store
                    .eager_slice()
                    .iter()
                    .zip(cell.paragraphs.iter())
                    .zip(ranges.iter())
                    .enumerate()
                {
                    let para_style = styles.para_styles.get(para.para_shape_id as usize);
                    let is_last_para = last_visible_line.is_some_and(|(last_pi, _)| pi == last_pi);
                    if empty_paragraphs[pi] {
                        if owns_empty_paragraph(pi) {
                            total += control_owned_empty_paragraph_height(
                                pi,
                                self.calc_para_lines_height(
                                    &comp.lines,
                                    para,
                                    false,
                                    false,
                                    pi,
                                    split_para_count,
                                    para_style,
                                    styles,
                                ),
                            );
                        }
                        continue;
                    }
                    // 첫 저장 문단의 물리 앞 띠도 같은 선택 줄의 점유에 포함한다.
                    if start == 0 && end > 0 {
                        let spacing_before = para_style.map(|s| s.spacing_before).unwrap_or(0.0);
                        total += crate::renderer::cell_paragraph_spacing::paragraph_before(
                            para,
                            pi,
                            spacing_before,
                            self.dpi,
                        )
                        .occupied_before();
                    }
                    let line_count = comp.lines.len();
                    for li in start..end {
                        // CellUnit은 좌우 조각의 마지막 seg에서만 한 물리 줄을
                        // 전진한다. 정렬 높이도 같은 저장 줄 소속을 소비한다.
                        if line_count == para.line_segs.len()
                            && li + 1 < end
                            && crate::renderer::height_measurer::stored_seg_is_row_fragment(
                                para,
                                li + 1,
                            )
                        {
                            continue;
                        }
                        if li < line_count {
                            let line = &comp.lines[li];
                            let h = hwpunit_to_px(line.line_height, self.dpi);
                            let is_cell_last_line = last_visible_line == Some((pi, li));
                            if !is_cell_last_line {
                                total += h + hwpunit_to_px(line.line_spacing, self.dpi);
                            } else {
                                total += h;
                            }
                        }
                    }
                    // spacing_after: 셀 마지막 문단 제외
                    if end == comp.lines.len() && end > start && !is_last_para {
                        let spacing_after = para_style.map(|s| s.spacing_after).unwrap_or(0.0);
                        total += spacing_after;
                    }
                    if start < end {
                        total +=
                            self.paragraph_cell_non_inline_controls_flow_height(&para.controls);
                    }
                }
                // 문단 줄 범위는 mixed 자식 표의 유닛을 표현하지 않는다.
                // 예약한 같은 컷의 내용 높이를 세로 정렬에서도 소비해야 온전한
                // 중첩 셀이 텍스트 줄 높이만으로 가운데/아래로 밀리지 않는다.
                let nested_cut_height = cut_units
                    .map(|(start, end)| {
                        self.nested_cell_cut_content_height(cell, table, styles, start, end)
                    })
                    .unwrap_or(0.0);
                total.max(nested_cut_height)
            } else {
                // 글자처럼 취급 개체 중 가장 큰 것. 글자 없는 문단은 담을 줄이 없어 composed
                // 높이가 placeholder 뿐이라 이 값이 그 문단의 실제 줄 높이다 — 빼면
                // `valign=Center` 가 개체 **상단**을 칸 중앙에 놓아 아래 칸을 침범한다(#7182).
                // 글자가 있는 문단은 줄 높이가 개체를 이미 담으므로 max 로 얹어도 변하지
                // 않는다. 일반 표 경로(`table_layout`)의 `max_inline_height` 와 같은 계약.
                let max_inline_h = cell
                    .paragraphs
                    .iter()
                    .flat_map(|p| p.controls.iter())
                    .filter_map(|c| match c {
                        Control::Picture(p) if p.common.treat_as_char => Some(p.common.height),
                        Control::Shape(s) if s.common().treat_as_char => Some(s.common().height),
                        _ => None,
                    })
                    .map(|h| hwpunit_to_px(h as i32, self.dpi))
                    .fold(0.0f64, f64::max);
                // 중첩 표가 있는 셀: LINE_SEG.line_height에 중첩 표 높이가 미포함되므로
                // vpos 기반으로 전체 콘텐츠 높이를 계산
                let has_nested = cell
                    .paragraphs
                    .iter()
                    .any(|p| p.controls.iter().any(|c| matches!(c, Control::Table(_))));
                if has_nested {
                    let unit_content_h = self.cell_units_content_height(cell, table, styles);
                    let last_seg_end: i32 = cell
                        .paragraphs
                        .iter()
                        .flat_map(|p| p.line_segs.last())
                        .map(|s| s.vertical_pos + s.line_height)
                        .max()
                        .unwrap_or(0);
                    let vpos_h = hwpunit_to_px(last_seg_end, self.dpi);
                    let line_h = self.calc_composed_paras_content_height(
                        composed_store.eager_slice(),
                        &cell.paragraphs,
                        styles,
                    );
                    let nested_bottom = self.calc_nested_controls_bottom_height(
                        composed_store.eager_slice(),
                        &cell.paragraphs,
                        styles,
                    );
                    vpos_h
                        .max(line_h)
                        .max(nested_bottom)
                        .max(unit_content_h)
                        .max(max_inline_h)
                        .max(self.calc_non_inline_controls_flow_height(&cell.paragraphs))
                        .max(self.calc_cell_wrap_objects_bottom_height(&cell.paragraphs, styles))
                } else {
                    self.calc_composed_paras_content_height(
                        composed_store.eager_slice(),
                        &cell.paragraphs,
                        styles,
                    )
                    .max(max_inline_h)
                    .max(self.calc_non_inline_controls_flow_height(&cell.paragraphs))
                    .max(self.calc_cell_wrap_objects_bottom_height(&cell.paragraphs, styles))
                }
            };

            // 수직 정렬
            use crate::model::table::VerticalAlign;
            // [Task #697 후속] 분할 행이라도 이 셀의 line_ranges 가 셀의 모든 paragraph line 을
            // 그대로 visible 처리한다면 (= 실제 split 적용 안 받은 cell, 예: inner-table-01.hwp
            // cell[10] '사업개요' 라벨) 원본 cell.vertical_align 을 사용한다. split 적용으로
            // line 일부가 잘린 cell 만 Top 강제.
            let cell_was_split = if windowed_composition {
                // [#4149] windowed 프로브 사전 게이트가 증명한 값 (s>0 문단 존재 또는
                // 창 밖 미가시 문단의 compose 줄 수 ≥ 1) — 전량 판정과 동치.
                true
            } else {
                cut_units.is_some_and(|(start_unit, end_unit)| {
                    let unit_len = self.cell_units(cell, table, styles).len();
                    start_unit > 0 || end_unit < unit_len
                }) || line_ranges.as_ref().is_some_and(|ranges| {
                    ranges.iter().enumerate().any(|(i, &(s, e))| {
                        if empty_paragraphs[i] {
                            return !owns_empty_paragraph(i);
                        }
                        let total = composed_store
                            .eager_slice()
                            .get(i)
                            .map(|c| c.lines.len())
                            .unwrap_or(0);
                        s != 0 || e != total
                    })
                })
            };
            // [#4042] 쪽 경계로 실제 잘리는 셀은 세로 가운데/아래 정렬이 성립하지 않는다.
            // 한컴 조판 규칙: 용지 시작 y 에서 아래로 흐르며 쪽 경계에 닿으면 자른다 —
            // 가시 슬라이스(inner_height)보다 콘텐츠가 큰 셀은 위에서부터 흘러야 하며,
            // 가운데 정렬은 다음 쪽으로 넘어갈 콘텐츠까지 세어 가시 조각을 셀 중앙으로
            // 밀어버린다. `cell_was_split`(문단 줄 컷)은 문단 줄은 온전하되 중첩 표 유닛이
            // 슬라이스를 넘어 잘리는 셀(42065 Row2: 셀 안 두 표가 쪽을 넘김)을 놓친다.
            // 그래서 전체 콘텐츠 높이(중첩 표 포함, cell_units 캐시 재사용 → O(1))가
            // 가시 슬라이스를 넘는지 직접 본다. 넘으면 이 조각은 컷 대상이므로 Top 앵커.
            // 넘지 않는 셀(예: #697 세로 병합 라벨)은 종전대로 valign 을 존중한다.
            // 다중열(col_count>1) 중첩 표를 담은 셀만 대상. 단일 1×1 중첩 표는 그
            // fragment 를 셀 중앙에 두는 것이 한컴 정답(#2195/#4058 76076, issue_2308 핀)
            // 이고, cell_units_content_height 는 1×1 표의 full 높이를 세어 슬라이스를
            // 넘는 것처럼 오판(false positive)하므로 제외한다. 42065 Row2 처럼 여러
            // 다중열 표가 쪽을 넘겨 흐르는 셀만 Top 앵커가 필요하다.
            let has_multicol_nested = cell.paragraphs.iter().any(|p| {
                p.controls
                    .iter()
                    .any(|c| matches!(c, Control::Table(t) if t.col_count > 1))
            });
            let cell_content_cut_by_slice = has_multicol_nested
                && self.cell_units_content_height(cell, table, styles) > inner_height + 0.5;
            let effective_align = if descendant_owns_closing_band {
                VerticalAlign::Top
            } else if stored_picture_cut_frame.is_some() {
                // 수용한 물리 띠 안에서 이번 컷의 그림과 소유 줄만 정렬한다.
                cell.vertical_align
            } else if frame_owns_alignment
                || mixed_opening_frame.is_some()
                || declared_opening_frame_owns_alignment
                || atomic_opening_frame_owns_alignment
            {
                // 앞 조각의 빈 공간을 보존한 물리 상자는 이 조각 내용으로 정렬한다.
                cell.vertical_align
            } else if center_saved_spanning_cell == Some(cell_idx) {
                VerticalAlign::Center
            } else if align_saved_opening_frame
                && cell_row + 1 == end_row
                && !cell_content_cut_by_slice
            {
                // 이 유한한 저장 프레임은 선택한 앞 조각만 소유한다.
                // 원래 정렬은 남은 꼬리가 아니라 line_ranges를 사용한다.
                cell.vertical_align
            } else if (is_in_split_row || is_rowbreak_straddle)
                && (cell_was_split || cell_content_cut_by_slice)
            {
                VerticalAlign::Top
            } else {
                cell.vertical_align
            };
            // 온전한 셀은 그림 띠와 빈 마지막 줄의 닫힌 원본 프레임을 함께 소비한다.
            // 실제 내용 컷은 그 조각의 기존 유닛 소유를 유지한다.
            let stored_empty_picture_frame = (!cell_was_split
                && !is_rowbreak_straddle
                && stored_picture_cut_frame.is_none())
            .then(|| self.stored_empty_picture_cell_frame(cell, table))
            .flatten()
            .filter(|frame| hwpunit_to_px(frame.content_height_hu, self.dpi) <= inner_height + 0.5);
            let total_content_height = declared_opening_content_height
                .filter(|_| declared_opening_frame_owns_alignment)
                .or_else(|| {
                    stored_empty_picture_frame
                        .map(|frame| hwpunit_to_px(frame.content_height_hu, self.dpi))
                })
                .or(reflow_content_height)
                .unwrap_or(total_content_height);
            // [#3820 Stage 78] RowBreak 마지막 physical tail은 paginator가 정한
            // 정확한 높이(override)를 사용한다. 저장 LINE_SEG가 glyph em보다 작은
            // 경우, 그 raw 줄높이만으로 Center를 계산하면 한 줄짜리 텍스트가 tail의
            // 지나치게 아래로 내려간다. 실제 paint glyph가 차지하는 em은 Center
            // 정렬의 최소 콘텐츠 높이여야 한다. 이 보정은 end-tail을 실제로 소유한
            // 셀에만 적용해 일반 저장 줄높이/행 높이 해석에는 영향을 주지 않는다.
            // 첫 저장 띠의 소유를 예약에 사용한 문단 메트릭에서 그대로 읽는다.
            let first_source_lead = cell.paragraphs.first().map_or(0.0, |para| {
                let owns_first_line = line_ranges.as_ref().is_none_or(|ranges| {
                    ranges
                        .first()
                        .is_some_and(|&(start, end)| start == 0 && end > 0)
                });
                if !owns_first_line
                    || !cut_units.is_none_or(|(start, _)| start == 0)
                    || !crate::renderer::cell_paragraph_has_only_text_metadata(para)
                    || para.stored_text_partition_is_dirty()
                    || self
                        .render_normalization
                        .borrow()
                        .cell_frame_reflowed(table, cell)
                    || !para.line_segs.first().is_some_and(|line| {
                        line.tag & crate::model::paragraph::LineSeg::TAG_IMPLEMENTATION_PROPERTY
                            == 0
                    })
                {
                    return 0.0;
                }
                crate::renderer::cell_paragraph_spacing::paragraph_before(
                    para,
                    0,
                    styles
                        .para_styles
                        .get(para.para_shape_id as usize)
                        .map_or(0.0, |style| style.spacing_before),
                    self.dpi,
                )
                .stored_lead
            });
            let owns_end_tail = end_row_height_override.is_some()
                && end_row.checked_sub(1).is_some_and(|last_row| {
                    cell_row <= last_row && last_row < cell_row + cell.row_span as usize
                });
            let selected_frame_owns_alignment = closing_source_frame_owns_alignment
                || computed_frame_owns_alignment
                || full_width_row_frame_owns_alignment;
            let declared_opening_content_height = (!is_continuation)
                .then(|| self.declared_nested_opening_cut_height(table, start_cut, end_cut, styles))
                .flatten()
                .map(|frame| frame - pad_top - pad_bottom);
            let stored_page_content_height = cut_units.and_then(|(start, end)| {
                self.stored_cell_cut_alignment_height(cell, table, styles, start, end)
            });
            let centered_content_height = if let Some(height) = atomic_opening_alignment_height {
                height
            } else if let Some(frame) = &stored_picture_cut_frame {
                frame.content_height
            } else if let Some(height) = atomic_suffix_content_height {
                height
            } else if let Some(frame) = mixed_opening_frame {
                // 예약한 상자와 같은 source host/child의 닫힌 점유 끝을 정렬한다.
                frame.content_height
            } else if let Some(height) = reflow_content_height {
                height
            } else if let Some(frame) = &stored_mixed_opening_frame {
                frame.content_height
            } else if let Some(height) = declared_opening_content_height {
                // 인증한 프레임은 원본 잉크 경계에서 끝난다. 첫 빈 띠와 문단 사이 빈 띠도
                // 내용에 속하며, 보이는 줄 전진량만 합산할 때 빠져도 소유를 보존한다.
                height
            } else if let Some(height) = stored_page_content_height {
                // 같은 컷의 예약이 보존한 원본 쪽 프레임을 정렬에도 사용한다.
                height
            } else if selected_frame_owns_alignment {
                // 수용한 종료 프레임은 선택한 가시 줄을 정렬한다. 다음 쪽으로
                // 전진하는 마지막 줄간격·문단 뒤 간격을 정렬 높이로 다시 얹지 않는다.
                total_content_height
            } else if ordinary_source_frame_owns_alignment {
                cut_units
                    .and_then(|(start, end)| {
                        self.stored_ordinary_cell_cut_content_height(
                            table, cell, start, end, styles,
                        )
                    })
                    .unwrap_or(total_content_height)
            } else if heading_frame_owns_alignment {
                // 앞 제목의 줄 구성은 다음 개체를 포함하지 않는다. 셀 컷의
                // 패딩·다음 줄 전진까지 잉크 높이로 다시 가운데 정렬하지 않는다.
                total_content_height
            } else if original_restart_span_owns_alignment {
                cut_units
                    .map(|(start, end)| {
                        self.cell_cut_visible_height(cell, table, styles, start, end)
                    })
                    .unwrap_or(total_content_height)
            } else if center_saved_spanning_cell == Some(cell_idx) || cut_frame_owns_alignment {
                // 그림 띠를 포함한 컷 유닛 높이를 예약과 정렬에서 함께 소비한다.
                let units = self.cell_units(cell, table, styles);
                cut_units
                    .map(|(start, end)| {
                        let (start, end) = (start.min(units.len()), end.min(units.len()));
                        units[start..end]
                            .iter()
                            .map(|unit| unit.height)
                            .sum::<f64>()
                            // 예약과 자식 배치가 여는 이어받기 위 띠도 정렬 내용이다.
                            // 빠뜨리면 같은 물리 여백의 절반만큼 내용이 아래로 밀린다.
                            + self.nested_continuation_header_height(cell, &units, start, styles)
                            - self.continued_cut_nested_atom_tail(cell, &units, start, end, styles)
                    })
                    .unwrap_or(total_content_height)
            } else if effective_align == VerticalAlign::Center && owns_end_tail {
                let visual_height = line_ranges.as_ref().map(|ranges| {
                    let mut total = 0.0;
                    let para_count = cell.paragraphs.len();
                    for (pi, ((comp, para), &(start, end))) in composed_store
                        .eager_slice()
                        .iter()
                        .zip(cell.paragraphs.iter())
                        .zip(ranges.iter())
                        .enumerate()
                    {
                        let para_style = styles.para_styles.get(para.para_shape_id as usize);
                        let is_last_para =
                            last_visible_line.is_some_and(|(last_pi, _)| pi == last_pi);
                        if empty_paragraphs[pi] {
                            if owns_empty_paragraph(pi) {
                                total += control_owned_empty_paragraph_height(
                                    pi,
                                    self.calc_para_lines_height(
                                        &comp.lines,
                                        para,
                                        false,
                                        false,
                                        pi,
                                        para_count,
                                        para_style,
                                        styles,
                                    ),
                                );
                            }
                            continue;
                        }
                        if start == 0 && end > 0 {
                            total += crate::renderer::cell_paragraph_spacing_before(
                                para,
                                pi,
                                para_style.map_or(0.0, |style| style.spacing_before),
                            );
                        }
                        for li in start..end.min(comp.lines.len()) {
                            if comp.lines.len() == para.line_segs.len()
                                && li + 1 < end
                                && crate::renderer::height_measurer::stored_seg_is_row_fragment(
                                    para,
                                    li + 1,
                                )
                            {
                                continue;
                            }
                            let line = &comp.lines[li];
                            let raw_height = hwpunit_to_px(line.line_height, self.dpi);
                            let glyph_em = line
                                .runs
                                .iter()
                                .filter_map(|run| {
                                    styles
                                        .char_styles
                                        .get(run.char_style_id as usize)
                                        .map(|style| style.font_size)
                                })
                                .fold(0.0f64, f64::max);
                            let line_height = raw_height.max(glyph_em);
                            let is_cell_last_line = last_visible_line == Some((pi, li));
                            total += line_height;
                            if !is_cell_last_line {
                                total += hwpunit_to_px(line.line_spacing, self.dpi);
                            }
                        }
                        if end == comp.lines.len() && end > start && !is_last_para {
                            total += para_style.map(|s| s.spacing_after).unwrap_or(0.0);
                        }
                    }
                    total
                });
                visual_height
                    .map(|height| total_content_height.max(height))
                    .unwrap_or(total_content_height)
            } else {
                total_content_height
            };
            // [#7063 레인②] 세로 정렬의 기준은 **테두리 상자**의 안높이다. 내용 높이
            // (`inner_height`)는 예산이 자른 값이라, 쪽 상자로 고정한 조각에서 둘이 갈린다.
            // 정본은 늘어난 상자 안에서 그 조각을 정렬한다(hwpx_sample2 19쪽: 상자
            // 89.91..1081.39 안에서 칸 내용이 95.06 — 상자 위에서 5.15px).
            let align_inner_height = (cell_h - pad_top - pad_bottom).max(0.0);
            let first_source_band_owns_position = first_source_lead > 0.0
                && matches!(effective_align, VerticalAlign::Top)
                && !matches!(cell.vertical_align, VerticalAlign::Top);
            let text_y_start = match effective_align {
                VerticalAlign::Top => cell_y + pad_top,
                VerticalAlign::Center => {
                    cell_y + pad_top + (align_inner_height - centered_content_height).max(0.0) / 2.0
                }
                VerticalAlign::Bottom => {
                    cell_y + pad_top + (align_inner_height - total_content_height).max(0.0)
                }
            };
            let text_y_start = stored_empty_picture_frame
                .map(|frame| {
                    cell_y
                        + pad_top
                        + frame.paragraph_origin_offset_px(inner_height, effective_align, self.dpi)
                })
                .unwrap_or(text_y_start);

            super::table_layout::unit_diagnostics::trace_alignment(
                cell,
                (cell_y, text_y_start),
                (
                    cell_h,
                    pad_top + pad_bottom,
                    total_content_height,
                    centered_content_height,
                ),
                effective_align,
                &[
                    ("mixed_declared", mixed_opening_frame.is_some()),
                    ("declared_opening", declared_opening_frame_owns_alignment),
                    ("atomic_opening", atomic_opening_frame_owns_alignment),
                    ("atomic_suffix", atomic_suffix_content_height.is_some()),
                    ("frame", frame_owns_alignment),
                    ("ordinary", ordinary_source_frame_owns_alignment),
                    ("opening", align_saved_opening_frame),
                    ("closing", closing_source_frame_owns_alignment),
                    ("full_width", full_width_row_frame_owns_alignment),
                    ("restart_span", original_restart_span_owns_alignment),
                    ("complete_suffix", complete_suffix_frame),
                    ("reflow_content", reflow_content_height.is_some()),
                    ("stored_page_content", stored_page_content_height.is_some()),
                    ("stored_mixed", stored_mixed_opening_frame.is_some()),
                    ("cut_frame", cut_frame_owns_alignment),
                ],
                cut_units,
            );

            // 세로쓰기 셀: 별도 레이아웃 경로 (가로 레이아웃 루프 대신)
            if cell.text_direction != 0 {
                // [#4149] 프로브가 세로쓰기 셀을 대상으로 삼는 일은 게이트로 막지만,
                // 방어적으로 전량 구성 후 동일 경로를 태운다 (좌표 동일).
                composed_store.materialize(cell, inner_width, styles, self);
                let vert_inner_area = LayoutRect {
                    x: inner_x,
                    y: cell_y + pad_top,
                    width: inner_width,
                    height: inner_height,
                };
                self.layout_vertical_cell_text(
                    tree,
                    &mut cell_node,
                    composed_store.eager_slice(),
                    &cell.paragraphs,
                    styles,
                    &vert_inner_area,
                    cell.vertical_align,
                    cell.text_direction,
                    section_index,
                    Some((para_index, control_index)),
                    cell_idx,
                    table.cells.len(),
                    enclosing_cell_ctx.cloned(),
                );
                // 세로쓰기 셀도 테두리를 엣지 그리드에 수집
                {
                    let cell_end_row_idx = cell_row + cell.row_span as usize;
                    let first_ri = render_rows.iter().position(|&r| r == cell_row).or_else(|| {
                        render_rows
                            .iter()
                            .position(|&r| r > cell_row && r < cell_end_row_idx)
                    });
                    let last_ri = render_rows
                        .iter()
                        .rposition(|&r| r >= cell_row && r < cell_end_row_idx);
                    if let (Some(fri), Some(lri)) = (first_ri, last_ri) {
                        if let Some(bs) = border_style {
                            collect_cell_borders(
                                &mut *h_edges,
                                &mut *v_edges,
                                cell_col,
                                fri,
                                cell.col_span as usize,
                                lri + 1 - fri,
                                &bs.borders,
                            );
                        }
                        mark_cell_span_interior_covered(
                            &mut *h_span_covered,
                            &mut *v_span_covered,
                            cell_col,
                            fri,
                            cell.col_span as usize,
                            lri + 1 - fri,
                        );
                    }
                }
                table_node.children.push(cell_node);
                table_node.children.extend(cell_diagonals);
                continue;
            }

            let inner_area = LayoutRect {
                x: inner_x,
                y: text_y_start,
                width: inner_width,
                height: inner_height,
            };

            // 셀 내 문단 + 컨트롤 통합 레이아웃
            // 분할 셀에서 실제 렌더링되는 마지막 문단 인덱스 계산
            // (뒤쪽 문단이 line_ranges=(0,0)으로 스킵되면 composed_paras.len()-1이 아님)
            let last_rendered_para_idx = if let Some(ref ranges) = line_ranges {
                let mut last_idx = 0usize;
                for (i, &(s, e)) in ranges.iter().enumerate() {
                    // block table 문단은 cut에 선택돼도 visible text line이 없으면
                    // `(n,n)`으로 남는다. `(0,0)`은 미선택 문단과 구분할 수 없지만
                    // `n>0`은 cell unit 원장이 이 control 문단을 현재 조각에 넣었다는
                    // 증거다. 이를 무시하면 바로 앞 텍스트 문단을 셀의 마지막 문단으로
                    // 오판해 trailing line_spacing을 버린다(issue2007 p14: 780HU).
                    let selected_zero_width_table_fragment = s == e
                        && s > 0
                        && cell.paragraphs.get(i).is_some_and(|para| {
                            // treat-as-char 표도 빈 host paragraph에서는 CellUnit의
                            // mixed nested fragment로 페이지를 나눠 실제 block처럼
                            // 배치된다(issue2007 p12/p15). source cut이 선택한 `(n,n)`
                            // table owner라는 계약이 중요하며 TAC 속성은 제외 근거가 아니다.
                            para.controls
                                .iter()
                                .any(|control| matches!(control, Control::Table(_)))
                        });
                    if owns_empty_paragraph(i)
                        || (!empty_paragraphs[i] && (s < e || selected_zero_width_table_fragment))
                    {
                        last_idx = i;
                    }
                }
                last_idx
            } else {
                cell.paragraphs.len().saturating_sub(1)
            };

            let collapse_stored_wrap_spacers = self.profile.get().hwp5_stored_pagination_layout()
                && !table.common.treat_as_char
                && matches!(
                    table.layout_page_break(),
                    crate::model::table::TablePageBreak::RowBreak
                )
                && cell.paragraphs.iter().enumerate().any(|(pi, p)| {
                    p.controls
                        .iter()
                        .enumerate()
                        .any(|(ci, _)| stored_square_picture_has_adjacent_text(cell, pi, ci))
                });
            let single_column_flow = self.stored_single_column_cell_flow(&cell.paragraphs);
            // 같은 저장 밴드 원점을 전체 셀과 현재 컷이 소유한 줄에 사용한다.
            // 첫 조각은 원래 leading band를 보존하고, 이어받기는 첫 소유 줄을
            // 현재 정렬 상자의 원점으로 삼는다. 이전 조각의 밴드를 재소비하지 않는다.
            let single_column_frame_origin_hu = single_column_flow.as_ref().map_or(0, |flow| {
                if !cut_units.is_some_and(|(start, _)| start > 0) {
                    return 0;
                }
                line_ranges
                    .as_deref()
                    .and_then(|ranges| {
                        ranges.iter().enumerate().find_map(|(pi, &(start, end))| {
                            (start < end)
                                .then(|| flow.line_origins_hu.get(pi)?.get(start).copied())
                                .flatten()
                        })
                    })
                    .unwrap_or(0)
            });
            let mut para_y = text_y_start;
            let mut has_preceding_text = false;
            // [#3637] 이 조각에서 **실제로 그려지는 첫 문단**의 vpos. 아래 중첩 표
            // 문단 스냅이 쓰는 조각 원점이다. `line_segs.first()` 를 그대로 쓰면 셀
            // 전체 좌표라 연속 조각에서 원점만큼 통째로 밀린다.
            let mut frag_vpos_origin = fragment_vpos_origin(cell, line_ranges.as_deref());
            // [#5880] 조각이 **중첩 표 호스트 문단의 중간 유닛**에서 시작하면(앞 쪽이
            // 표의 앞 행들을 이미 그렸으면) 그 문단의 소비된 유닛 높이만큼 원점을
            // 내린다. 호스트 문단은 표 전체가 저장 lineseg 한 줄이라 line_ranges 가
            // 소비분을 표현하지 못하고, 원점이 문단 머리(vpos)에 남아 후속 문단
            // 스냅이 소비분(2737927 p5: 행0·1 = 81px)만큼 아래로 밀렸다 — 밀린
            // 조각 끝의 표·각주가 조각 상자를 넘어 clip 소실(-187자, 12줄).
            // 텍스트 문단의 연속 조각은 line_ranges 의 start_line seg 가 이미 조각
            // 상대 원점이므로(기존 #3637 계약) start_line==0 인 경우만 보정한다.
            if let Some((su, _)) = cut_units {
                if su > 0 {
                    let units = self.cell_units(cell, table, styles);
                    if let Some(first_unit) = units.get(su) {
                        let first_para = first_unit.para_idx;
                        let starts_at_line0 = line_ranges
                            .as_deref()
                            .and_then(|ranges| ranges.get(first_para))
                            .is_none_or(|&(start, _)| start == 0);
                        if starts_at_line0 {
                            let consumed_px: f64 = units[..su]
                                .iter()
                                .filter(|unit| unit.para_idx == first_para)
                                .map(|unit| unit.height)
                                .sum();
                            if consumed_px > 0.5 {
                                frag_vpos_origin = frag_vpos_origin
                                    .saturating_add(px_to_hwpunit(consumed_px, self.dpi));
                            }
                        }
                    }
                }
            }
            let linear_single_cell = matches!(
                table.layout_page_break(),
                crate::model::table::TablePageBreak::RowBreak
            ) && !table.common.treat_as_char
                && table.row_count == 1
                && table.col_count == 1;
            let certified_before_origin_resumption = cut_units.is_some_and(|(su, _)| {
                su > 0
                    && !table.common.treat_as_char
                    && table.layout_page_break() == crate::model::table::TablePageBreak::RowBreak
                    && self.stored_cut_has_zero_before_origin(cell, table, styles, su)
            });
            let certified_body_frame_resumption = cut_units
                .is_some_and(|(su, _)| self.stored_cut_closes_body(cell, table, styles, su));
            // 수용한 저장 프레임의 재시작 경계에서 시작하는 이어받기는 그 프레임의 첫 빈 문단도 소유한다.
            // 보이는 줄 범위가 나중에 시작할 수 있으므로 원본 유닛 자체에서 원점을 구한다.
            let resumed_stored_frame_origin = cut_units.and_then(|(su, _)| {
                if certified_before_origin_resumption || certified_body_frame_resumption {
                    return self.stored_frame_origin_for_cut(cell, table, styles, su);
                }
                if su == 0
                    || !linear_single_cell
                    || !(self.profile.get().hwp5_stored_pagination_layout()
                        || authenticated_hwpx_frame)
                    || cell
                        .paragraphs
                        .iter()
                        .any(|para| para.stored_text_partition_is_dirty())
                {
                    return None;
                }
                self.stored_frame_origin_for_cut(cell, table, styles, su)
            });
            // 저장 첫 빈 줄과 다음 줄이 연결된 원본 HWPX는 셀 내부 원점을
            // 보존한다. 표 바깥의 문단 상대 앵커 오프셋은 셀 내부 줄 좌표를
            // 바꾸지 않는다. 명시적 원점이 없는 다른 첫 조각은 종전 범위를 쓴다.
            let preserve_linear_single_cell_vpos = certified_before_origin_resumption
                || certified_body_frame_resumption
                || declared_opening_content_height.is_some()
                || linear_single_cell
                    && ((cut_units.is_some_and(|(su, _)| su == 0)
                        && ((table.common.vertical_offset as i32).unsigned_abs() <= 141
                            || (self.profile.get().hwpx_stored_layout()
                                && !self.profile.get().session_edited()
                                && cell.paragraphs.first().is_some_and(|first| {
                                    first.text.is_empty()
                                        && first.controls.is_empty()
                                        && !first.stored_text_partition_is_dirty()
                                        && first.line_segs.len() == 1
                                        && first.line_segs[0].vertical_pos == 0
                                        && cell.paragraphs.get(1).is_some_and(|next| {
                                            !next.stored_text_partition_is_dirty()
                                                && next.line_segs.first().is_some_and(|line| {
                                                    line.vertical_pos
                                                        == first.line_segs[0].line_height
                                                            + first.line_segs[0].line_spacing
                                                })
                                        })
                                }))))
                        || resumed_stored_frame_origin.is_some());
            let vpos_origin = if preserve_linear_single_cell_vpos {
                resumed_stored_frame_origin
                    .unwrap_or_else(|| self.stored_cell_initial_frame_origin_hu(cell, styles))
            } else {
                0
            };
            if preserve_linear_single_cell_vpos && resumed_stored_frame_origin.is_some() {
                frag_vpos_origin = vpos_origin;
            }
            // 선형 저장 좌표 스냅은 앞 간격도 이미 배치한다. 그 경로를 타지 않는
            // 조각의 첫 원본 TAC 호스트만, 수용 유닛에 예약된 앞 간격을 따로 소비한다.
            let first_stored_inline_owner_lead = if preserve_linear_single_cell_vpos {
                None
            } else {
                cut_units.and_then(|(start, _)| {
                    self.stored_inline_owner_lead_for_cut(table, cell, styles, start)
                })
            };
            // [#4149] windowed 프로브: 컷 창에 유닛이 없는 문단은 아래 skip 판정의
            // 네 조건(line_ranges·mixed·nested·non-inline)이 모두 창 유닛에서만
            // 유도되므로 전량 레이아웃에서도 반드시 skip 된다 — 순회 자체를 생략한다.
            // stop_after_para 이후 문단은 캐럿 문단의 좌표에 영향이 없어 중단한다.
            // [#7095] 단, 아래에서 조각 내용 높이로 가운데 정렬하는 칸은 뒤 문단이 앞
            // 문단의 y 를 정하므로 끝까지 순회해야 캐럿이 그려진 줄과 같은 자리에 선다.
            //
            // 근거는 조각 경계가 칸 자신의 문단 사이(또는 글줄 사이)에 놓이는 형상뿐이다. 경계가
            // **중첩 표를 가로지르는** 조각(42065: 바깥 1×1 칸의 유일한 문단이 본문 전체를 담은
            // 중첩 표)은 한/글이 가운데로 옮기지 않는다 — 열면 5~7·11·16쪽이 12~36px 올라간다.
            let centers_pinned_fragment = center_pinned_single_cell
                && matches!(cell.vertical_align, VerticalAlign::Center)
                && cut_units.is_some_and(|(start_unit, end_unit)| {
                    let units = self.cell_units(cell, table, styles);
                    let hosts_table = |unit: &super::table_layout::CellUnit| {
                        cell.paragraphs
                            .get(unit.para_idx)
                            .is_some_and(|para| unit.owns_table_in_paragraph(para))
                    };
                    let cuts_through_table =
                        |before: usize, after: usize| match (units.get(before), units.get(after)) {
                            (Some(a), Some(b)) => {
                                a.para_idx == b.para_idx && hosts_table(a) && hosts_table(b)
                            }
                            _ => false,
                        };
                    // 가운데 정렬의 기준인 조각 내용은 한/글 자신의 쪽 프레임이어야 한다 — 컷이
                    // 저장 프레임 되감김에서 끝나지 않으면 rhwp 조각이 한/글 쪽과 다른 내용을
                    // 담아(1382000 22쪽) 여유를 잘못 잰다.
                    // 끝 조각은 칸 끝에서 끝나므로 그 자체가 한/글의 마지막 프레임이다.
                    (end_unit >= units.len()
                        || self.cell_unit_opens_stored_page_frame(cell, table, styles, end_unit))
                        && (start_unit == 0 || !cuts_through_table(start_unit - 1, start_unit))
                        && !cuts_through_table(end_unit - 1, end_unit)
                });
            let probe_stop = probe.filter(|_| !centers_pinned_fragment);
            let (loop_start, loop_end_excl) = match (composition_window, probe_stop) {
                (Some((lo, hi)), p) => {
                    let end = hi.saturating_add(1).min(cell.paragraphs.len()).min(
                        p.map_or(cell.paragraphs.len(), |p| {
                            p.stop_after_para.saturating_add(1)
                        }),
                    );
                    (lo.min(end), end)
                }
                (None, Some(p)) => (
                    0,
                    cell.paragraphs
                        .len()
                        .min(p.stop_after_para.saturating_add(1)),
                ),
                (None, None) => (0, cell.paragraphs.len()),
            };
            let reflow_block_flow = self.reflow_block_cell_flow_in_cell(cell, table, styles);
            for cp_idx in loop_start..loop_end_excl {
                let para = &cell.paragraphs[cp_idx];
                let no_overlap_square_stack =
                    crate::renderer::float_placement::cell_paragraph_no_overlap_square_stack(
                        &cell.paragraphs,
                        cp_idx,
                        self.dpi,
                    );
                let mut no_overlap_placer =
                    crate::renderer::float_placement::NoOverlapSquarePlacer::default();
                if empty_paragraphs[cp_idx] && !owns_empty_paragraph(cp_idx) {
                    continue;
                }
                // 개체로 소유한 빈 문단의 그림은 조각 흐름 커서 대신 문단 원점과 제
                // 오프셋에 놓는다 — 흐름 커서는 가로 자리가 다른 그림도 차례로 아래에 쌓는다.
                let control_owned_empty = control_owned_empty_paragraph(cp_idx);
                if collapse_stored_wrap_spacers
                    && stored_nested_table_empty_wrap_spacer(cell, cp_idx)
                {
                    continue;
                }
                // 분할 행이면 해당 문단의 줄 범위 적용
                let (start_line, end_line) = if let Some(ref ranges) = line_ranges {
                    if cp_idx < ranges.len() {
                        ranges[cp_idx]
                    } else {
                        (0, 0) // 범위 밖 문단은 렌더링하지 않음
                    }
                } else {
                    (
                        0,
                        composed_store
                            .get(cp_idx, cell, inner_width, styles, self)
                            .lines
                            .len(),
                    )
                };
                let mixed_nested_split = cut_units.and_then(|(su, eu)| {
                    self.mixed_nested_split_from_cut(cell, table, styles, su, eu, cp_idx)
                });
                let nested_cursor_split = cut_units.and_then(|(su, eu)| {
                    self.nested_table_split_from_cut_units(cell, table, styles, su, eu, cp_idx)
                });
                // [Task #1073] 이 문단이 per-중첩행 유닛으로 분해됐으면(가시 텍스트 없음 +
                // 단일 중첩 표 2행+) 컷에 들어온 유닛의 `nested_row` 에서 중첩 행 범위를
                // 얻어 NestedTableSplit 으로 넘긴다.
                //
                // 종전에는 "컷 유닛 인덱스 == 중첩행 번호" 라고 가정해 **셀**이 문단 1개일
                // 때만 이 경로를 썼다. 분해 조건은 문단 단위(cell_units)인데 게이트는 셀
                // 단위여서, 문단이 여럿인 셀은 아래 `available_h` 휴리스틱으로 폴백했고 그
                // 분기는 오프셋을 0.0 으로 고정하므로 연속 페이지가 행 0 부터 다시 그리고
                // 뒤 행이 어느 페이지에도 나오지 않았다.
                let nested_cut_rows: Option<(usize, usize)> = if nested_cursor_split.is_some() {
                    None
                } else {
                    cut_units.and_then(|(su, eu)| {
                        self.nested_row_range_from_cut_units(cell, table, styles, su, eu, cp_idx)
                    })
                };
                let visible_non_inline_controls = cut_units.is_some_and(|(su, eu)| {
                    self.cell_cut_contains_non_inline_control_units(
                        cell, table, styles, su, eu, cp_idx,
                    )
                });
                let has_table_ctrl = para.controls.iter().any(|c| matches!(c, Control::Table(_)));
                // 같은 형상이 **그림**으로도 온다. 셀 문단이 글자 없이 그림만 들고
                // 저장 `LINE_SEG` 가 없으면 합성 줄 수가 0 이라 아래 컷 판정이
                // "이 쪽 소속 아님"으로 읽는다 — 표 컨트롤만 구제하면 그림은 **어느
                // 조각에서도** 배치되지 않아 문서에서 통째로 사라진다(실문서: 14행
                // 표 안 그림 11장 전부 미노출). 글자처럼 취급 그림도 같다 — 빈 문단
                // 이라 실릴 글줄이 없을 뿐 한/글은 제 줄에 그린다. 셀의 행 범위
                // 판정(위 `render_range` 가드)이 이미 소속 조각을 가렸으므로, 여기
                // 서는 컨트롤을 소유한 문단을 흘리지 않으면 된다. 중복 방출은 아래
                // 컨트롤 루프의 `will_render_inline` 가드가 막는다.
                let has_picture_ctrl = para
                    .controls
                    .iter()
                    .any(|c| matches!(c, Control::Picture(_)));
                // [#3820 Stage 77] HWP5에는 내부 표 control만 있고 LINE_SEG가 전혀
                // 없는 셀 문단이 있다(76076 p35 row 6). 이 표가 들어 있는 outer
                // fragment가 아직 source cut을 쓰지 않는다면, `(0, 0)`은 비가시
                // 판정이 아니라 control-only 문단의 합성 결과다. normal-table path와
                // 같이 control을 배치해야 한다. cut fragment에서는 단위 소유권을
                // 유지해 다음 쪽 표를 앞쪽에 중복 방출하지 않는다.
                // 글자처럼 취급 도형(직선 화살표 등)만 든 문단도 같다. 저장 줄이
                // 없으면 줄 수 0 으로 건너뛰어 도형 노드가 아예 생기지 않았다 —
                // 일반 표 경로는 같은 문단을 제 줄에 그린다.
                let has_unstored_tac_shape_ctrl = para.line_segs.is_empty()
                    && para.controls.iter().any(|c| match c {
                        Control::Shape(shape) => shape.common().treat_as_char,
                        _ => false,
                    });
                let uncut_control_only_nested_table = cut_units.is_none()
                    && (has_table_ctrl || has_picture_ctrl || has_unstored_tac_shape_ctrl)
                    && para
                        .text
                        .chars()
                        .all(|ch| ch.is_whitespace() || ch == '\r' || ch == '\n');

                // [Task #993] 컷 범위 밖 문단은 이전/다음 페이지 소속 — 이 페이지에서
                // 스킵한다. cut이 없는 빈 문단은 합성 줄 수로 비가시를 판정하지 않는다.
                // content_y_accum 은 가시 콘텐츠만 추적하므로 스킵 시 전진하지 않는다.
                if start_line >= end_line
                    && mixed_nested_split.is_none()
                    && nested_cursor_split.is_none()
                    && !visible_non_inline_controls
                    && !uncut_control_only_nested_table
                    && !owns_empty_paragraph(cp_idx)
                {
                    continue;
                }

                // [#4149] 가시 문단만 여기 도달 — lazy 슬롯은 이 시점에 compose 된다.
                let composed = composed_store.get(cp_idx, cell, inner_width, styles, self);

                // 재조판 좌표 뷰의 임시 복사본을 원본 주소 기반 캐시에 넘기지 않는다.
                let source_controls = &para.controls;
                let frame_paragraph = composed.paragraph_with_frame_geometry(para);
                let para = frame_paragraph.as_ref();

                let stored_host_flow =
                    self.stored_nested_host_physical_flow(cell, table, styles, cp_idx, cut_units);
                let mut table_host_has_stored_origin = false;
                let mut single_column_snap_spacing_before = false;
                let mut stored_linear_spacing_before = None;
                if stored_host_flow.is_some() {
                    // 종료 줄의 저장 원점은 표의 시작점이 아니다. 앞 유닛에서
                    // 이어지는 현재 흐름 원점을 보존하고 같은 소유 구간을 소비한다.
                } else if let Some(origin) = single_column_flow
                    .as_ref()
                    .and_then(|flow| flow.line_origins_hu.get(cp_idx))
                    .and_then(|lines| lines.get(start_line))
                {
                    let spacing_before = if start_line == 0 {
                        styles
                            .para_styles
                            .get(para.para_shape_id as usize)
                            .map_or(0.0, |style| style.spacing_before)
                    } else {
                        0.0
                    };
                    para_y = text_y_start
                        + hwpunit_to_px(*origin - single_column_frame_origin_hu, self.dpi)
                        - spacing_before;
                    // 공통 저장 프레임의 줄 원점을 실제로 소비했다. 앞 간격이 0이어도
                    // 표 호스트 원점의 소유는 같으며, 단순 누적 흐름 커서와 구분한다.
                    table_host_has_stored_origin = has_table_ctrl;
                    single_column_snap_spacing_before = spacing_before > 0.0;
                } else if preserve_linear_single_cell_vpos {
                    let target_seg = para
                        .line_segs
                        .get(start_line)
                        .or_else(|| para.line_segs.first());
                    if let Some(seg) = target_seg {
                        // [#5995] 저장 vpos 는 spacing_before 를 이미 포함한 줄
                        // 상단이다. 이후 layout_composed_paragraph 가 spacing_before
                        // 를 다시 더하므로, 여기서 빼고 스냅해야 이중 가산이 없다
                        // (table_layout.rs 의 `anchored_y - spacing_before` 와 같은
                        // 규약. 30269: 미보정 시 +1.8mm 씩 두 번 밀려 조각 마지막
                        // 줄이 다음 쪽으로 넘어간다).
                        // 표 호스트 문단은 layout_composed_paragraph 의 spacing_before
                        // 재가산 경로를 타지 않으므로 빼면 표가 그만큼 떠오른다 —
                        // 텍스트 문단에만 적용한다.
                        let snap_spacing_before = if start_line == 0 && !has_table_ctrl {
                            let spacing = styles
                                .para_styles
                                .get(para.para_shape_id as usize)
                                .map(|s| s.spacing_before)
                                .unwrap_or(0.0);
                            // 원본 Center/Bottom이 컷 때문에 Top이 되면 첫 저장 띠와
                            // 문단 앞 간격을 별도로 보존한다. 정렬을 유지한 셀은
                            // 기존 저장 스냅과 compose가 간격을 한 번 소비한다.
                            let keep_source_band = cp_idx == 0 && first_source_band_owns_position;
                            if cp_idx > 0
                                || (!keep_source_band
                                    && spacing > 0.0
                                    && hwpunit_to_px(seg.vertical_pos - vpos_origin, self.dpi)
                                        >= spacing)
                            {
                                spacing
                            } else {
                                0.0
                            }
                        } else {
                            0.0
                        };
                        let target_top =
                            hwpunit_to_px((seg.vertical_pos - vpos_origin).max(0), self.dpi)
                                - snap_spacing_before;
                        let current_top = (para_y - text_y_start).max(0.0);
                        // [#6095] 중첩 표 호스트 문단의 저장 vpos 는 표 **아래**의
                        // host 줄 좌표일 수 있다(3090867 앵커 vpos=33720 = 직전 흐름
                        // + 중첩 표 높이). 그 좌표로 전방 스냅하면 표 페인트까지
                        // 함께 내려가 표 위에 표 높이만큼 빈공간이 생긴다(+303px,
                        // 본문이 2쪽으로 밀림). 점프가 중첩 표 선언 높이 규모면
                        // post-table host 줄로 보고 스냅을 건너뛴다 — 표는 자연
                        // 흐름에 그려지고, 후속 문단은 자기 저장 vpos 로 정렬된다.
                        let nested_tables_px: f64 = source_controls
                            .iter()
                            .filter_map(|control| match control {
                                Control::Table(nested) => Some(hwpunit_to_px(
                                    nested.common.height.min(i32::MAX as u32) as i32,
                                    self.dpi,
                                )),
                                _ => None,
                            })
                            .sum();
                        let post_table_host_line = has_table_ctrl
                            && nested_tables_px > 0.0
                            && target_top - current_top >= nested_tables_px - 24.0;
                        table_host_has_stored_origin = has_table_ctrl && !post_table_host_line;
                        // 인증된 이어받기 프레임의 첫 원본 문단도 선차감한 앞 간격을
                        // 소유한다. 셀 전체의 문단 0과 현재 프레임의 첫 문단을 혼동하면
                        // 저장 스냅이 뺀 간격을 column-top trim에서 다시 잃는다.
                        let owns_resumed_stored_entry =
                            resumed_stored_frame_origin.is_some() && !has_preceding_text;
                        if (cp_idx == 0 || owns_resumed_stored_entry)
                            && start_line == 0
                            && !has_table_ctrl
                            && target_top >= current_top
                        {
                            // 저장 원점이 이미 앞 띠를 품는다. compose는 이 위치가
                            // column-top인지 다시 추측하지 않고 선차감한 몫만 돌려놓는다.
                            stored_linear_spacing_before =
                                Some(if first_source_band_owns_position {
                                    styles
                                        .para_styles
                                        .get(para.para_shape_id as usize)
                                        .map_or(0.0, |style| style.spacing_before)
                                } else {
                                    snap_spacing_before
                                });
                        }
                        if target_top > current_top && !post_table_host_line {
                            para_y += target_top - current_top;
                        }
                    }
                }

                let stored_host_flow_entry = para_y;
                // [#3637 진단] 조각 셀에서 실제로 배치되는 문단과 그 y. 컷 범위 밖
                // 문단이 예외 경로(중첩 표 보유 등)로 새는지 직접 본다. 동작 불변.
                if std::env::var("RHWP_DIAG_CELLPARA").is_ok() {
                    eprintln!(
                        "DIAG_CELLPARA pi={} cell=({},{}) cp={} lines={}..{} cut={:?} nested={:?} mixed={} nonline={} para_y={:.1} cell_bot={:.1} owned_before={:?}",
                        para_index,
                        cell.row,
                        cell.col,
                        cp_idx,
                        start_line,
                        end_line,
                        cut_units,
                        nested_cut_rows,
                        mixed_nested_split.is_some(),
                        visible_non_inline_controls,
                        para_y,
                        cell_content_bottom(cell_y, cell_h, pad_bottom),
                        stored_linear_spacing_before,
                    );
                }
                let cell_context = if let Some(context) = enclosing_cell_ctx {
                    let mut context = context.clone();
                    if let Some(last) = context.path.last_mut() {
                        last.cell_index = cell_idx;
                        last.cell_para_index = cp_idx;
                        last.text_direction = cell.text_direction;
                    }
                    context
                } else {
                    CellContext {
                        in_textbox: false,
                        parent_para_index: para_index,
                        path: vec![CellPathEntry {
                            control_index,
                            cell_index: cell_idx,
                            cell_para_index: cp_idx,
                            text_direction: cell.text_direction,
                        }],
                    }
                };
                let cell_context_opt = Some(cell_context.clone());

                // 인라인 이미지가 있는 문단: compose 전 위치를 저장
                let paragraph_has_preceding_content = has_preceding_text;
                if start_line < end_line {
                    if let Some(frame) = &stored_picture_cut_frame {
                        if let Some(line) = para.line_segs.get(start_line) {
                            para_y =
                                text_y_start + frame.line_y(cp_idx, line.vertical_pos, self.dpi);
                        }
                    }
                }
                let para_y_before_compose = para_y;
                let paragraph_picture_band =
                    crate::renderer::float_placement::paragraph_picture_band(para, self.dpi)
                        .filter(|_| stored_empty_picture_frame.is_none());
                // 이 조각에서 문단이 시작하면 그 첫 줄 상단이 문단 기준 개체의 원점이다.
                // 저장 줄 사다리·문단 앞 간격으로 생긴 틈은 compose 안에서 더해지므로
                // compose 전 커서(`para_y_before_compose`)와 다를 수 있다.
                let mut para_first_line_top: Option<f64> = None;

                // 인라인(treat_as_char) 컨트롤의 총 폭을 미리 계산
                let total_inline_width: f64 = source_controls
                    .iter()
                    .map(|ctrl| match ctrl {
                        Control::Picture(pic) if pic.common.treat_as_char => {
                            hwpunit_to_px(pic.common.width as i32, self.dpi)
                        }
                        Control::Shape(shape) if shape.common().treat_as_char => {
                            hwpunit_to_px(shape.common().width as i32, self.dpi)
                        }
                        Control::Equation(eq) => hwpunit_to_px(
                            crate::renderer::equation::inline_box::horizontal_metrics(eq)
                                .occupied_width_hwp(),
                            self.dpi,
                        ),
                        _ => 0.0,
                    })
                    .sum();
                // `layout_table`의 empty-TAC 경로와 같은 줄별 폭 계약을 partial
                // RowBreak fragment에도 쓴다. 빈 paragraph의 image controls는 source
                // char position이 같아도 HWP LINE_SEG가 각각의 flow slot을 보존한다.
                let control_lines = composed.control_line_indices(para);
                let tac_line_widths: Vec<f64> = {
                    let mut line_widths = vec![0.0f64; composed.lines.len().max(1)];
                    for (index, ctrl) in source_controls.iter().enumerate() {
                        let (is_tac, width) = match ctrl {
                            Control::Picture(pic) if pic.common.treat_as_char => {
                                (true, hwpunit_to_px(pic.common.width as i32, self.dpi))
                            }
                            Control::Shape(shape) if shape.common().treat_as_char => {
                                (true, hwpunit_to_px(shape.common().width as i32, self.dpi))
                            }
                            Control::Equation(eq) => (
                                true,
                                hwpunit_to_px(
                                    crate::renderer::equation::inline_box::horizontal_metrics(eq)
                                        .occupied_width_hwp(),
                                    self.dpi,
                                ),
                            ),
                            Control::Table(table) if table.common.treat_as_char => (
                                true,
                                hwpunit_to_px(
                                    table.common.width as i32
                                        + table.outer_margin_left as i32
                                        + table.outer_margin_right as i32,
                                    self.dpi,
                                ),
                            ),
                            _ => (false, 0.0),
                        };
                        if !is_tac {
                            continue;
                        }
                        if let Some(owner) =
                            control_lines.as_ref().and_then(|lines| lines.get(index))
                        {
                            if let Some(line_width) = line_widths.get_mut(*owner) {
                                *line_width += width;
                            }
                            continue;
                        }
                        if composed.lines.len() <= 1 {
                            line_widths[0] += width;
                            continue;
                        }
                        if let Some(line_width) = line_widths.iter_mut().find(|line_width| {
                            **line_width == 0.0 || **line_width + width <= inner_width + 0.5
                        }) {
                            *line_width += width;
                        } else if let Some(last) = line_widths.last_mut() {
                            *last += width;
                        }
                    }
                    line_widths
                };

                // [#6653] 중첩 표를 품은 줄은 저장 사다리에 그 표 높이로 적혀 있다
                // (hwpx_sample2 p[21] `ls[1] vpos=0 lh=12080` = 161.07px, 표 157.3px).
                // 글자와 표를 함께 가진 문단은 아래 텍스트 갈래를 타는데, 그 갈래가 표
                // 전용 줄까지 지나 `para_y` 를 밀고 나서 표를 그린다 — 같은 높이를 두 번
                // 쓴다. 8쪽에는 글자 줄이 있어 드러나지 않지만, 표 줄만 넘어온 9쪽 조각은
                // 표가 161px 아래로 내려가 위에 빈 띠가 남는다(한/글 52.1 vs rhwp 210.6).
                // 이 조각이 그리는 줄에 보이는 글자가 없으면 표 전용 줄이므로, 표는 그
                // 줄이 시작한 자리에 놓는다.
                let table_host_line_only_fragment = has_table_ctrl
                    && composed
                        .lines
                        .iter()
                        .skip(start_line)
                        .take(end_line.saturating_sub(start_line))
                        .all(|line| line.runs.iter().all(|run| run.text.trim().is_empty()));
                let owns_paragraph_entry = cut_units.is_none_or(|(start, end)| {
                    let units = self.cell_units(cell, table, styles);
                    Self::reflow_host_cut_ownership(&units, cp_idx, start, end)
                        .is_some_and(|ownership| ownership.owns_start)
                });
                if table_host_line_only_fragment
                    && start_line == 0
                    && !table_host_has_stored_origin
                    && owns_paragraph_entry
                    && !matches!(
                        stored_host_flow,
                        Some(StoredNestedHostFlow::BeforeLine { .. })
                    )
                {
                    // 이 경로는 layout_composed_paragraph를 거치지 않는다.
                    // 셀 측정과 같은 문단 앞 간격을 첫 개체 줄 앞에서 한 번
                    // 소비한다. 저장 줄 원점에는 이 간격이 이미 포함돼 있다.
                    para_y += crate::renderer::cell_paragraph_spacing_before(
                        para,
                        cp_idx,
                        styles
                            .para_styles
                            .get(para.para_shape_id as usize)
                            .map_or(0.0, |style| style.spacing_before),
                    );
                }
                let para_y_before_lines = para_y;
                // 표 컨트롤이 없는 문단: 텍스트 먼저, 컨트롤 나중 (기존 동작)
                // 표 컨트롤이 있는 문단: 문단 앞 간격 적용 → 표 먼저 배치 → 텍스트(엔터 등) 나중
                if let Some(advance) = stored_empty_line_advances[cp_idx] {
                    para_y += advance;
                } else if !has_table_ctrl
                    || composed
                        .lines
                        .iter()
                        .any(|line| line.runs.iter().any(|run| !run.text.trim().is_empty()))
                {
                    let is_last_para = cp_idx == last_rendered_para_idx;
                    let numbered_comp = if start_line == 0 {
                        self.apply_paragraph_numbering(
                            Some(composed),
                            para,
                            styles,
                            outline_numbering_id,
                        )
                    } else {
                        None
                    };
                    let composed_for_layout = numbered_comp.as_ref().unwrap_or(composed);
                    // [Task #1728 v2] 셀-내 continuation 조각(cut su>0)의 첫 가시 문단
                    // (아직 텍스트 없음 + 문단 첫 줄부터 시작)은 셀-상단이라 layout_composed_paragraph
                    // 의 column-top 트림에 걸려 앞 간격이 사라진다. 한컴은 유지하므로 토글 on.
                    // 1×1 linear 셀(page-spanning 컨테이너, preserve_linear_single_cell_vpos
                    // 계열)의 continuation 은 자연 흐름으로 이미 정합하며 textbox/shape 를 품을 수
                    // 있어 spacing 추가 시 프레임 밖으로 밀린다(#issue_rowbreak_chart_overlap p17).
                    // 저장 프레임 경로의 기존 다행/다열 판정은 유지한다. 재조판 경로는
                    // 표 차원이 아니라 같은 컷의 첫 source unit이 앞 간격을 소유하는지 읽는다.
                    let keep_spacing = cut_units.is_some_and(|(su, eu)| {
                        // A complete unit window is the same cell flow as the
                        // uncut path. Only an actual fragment preserves spacing
                        // that column-top trimming would otherwise discard.
                        let is_fragment = su > 0 || eu < self.cell_units(cell, table, styles).len();
                        (is_fragment
                            && self.cell_cut_owns_reflow_paragraph_start(
                                cell, table, styles, su, cp_idx,
                            ))
                            || (su > 0
                                && !has_preceding_text
                                && start_line == 0
                                && !(table.row_count == 1 && table.col_count == 1))
                    });
                    let previous_keep_spacing =
                        self.keep_continuation_column_top_spacing_before.get();
                    self.keep_continuation_column_top_spacing_before
                        .set(keep_spacing);
                    if single_column_snap_spacing_before {
                        self.reapply_snap_anchored_spacing_before.set(true);
                    }
                    let wrap_anchor = stored_square_picture_wrap_anchor_for_para(cell, cp_idx);
                    // 측정과 같은 첫 저장 띠를 column-top 경로에서 한 번 소비한다.
                    // 단 설정·책갈피처럼 배치 상자가 없는 메타데이터는 그 소비를 막지 않는다.
                    // 각주·미주는 별도 흐름을 소유하며 본문에는 표지만 남긴다.
                    // 표지가 있다는 이유로 셀 본문의 저장 앞 띠를 버리지 않는다.
                    // 별도 저장 원점이 이미 띠를 품는 스냅·선형 셀은 기존 경로를 쓴다.
                    let allow_first_stored_lead = cp_idx == 0
                        && start_line == 0
                        && source_controls.iter().all(|control| {
                            matches!(control, Control::Footnote(_) | Control::Endnote(_))
                                || crate::renderer::composer::control_is_width_neutral_marker(
                                    control,
                                )
                        })
                        && single_column_flow.is_none()
                        && !preserve_linear_single_cell_vpos
                        && crate::renderer::cell_paragraph_spacing::paragraph_before(
                            para,
                            cp_idx,
                            styles
                                .para_styles
                                .get(para.para_shape_id as usize)
                                .map_or(0.0, |style| style.spacing_before),
                            self.dpi,
                        )
                        .stored_lead
                            > 0.0;
                    let picture_closing_line = self
                        .stored_partitioned_picture_closing_line(cell, table, styles, cut_units);
                    let lines_before = cell_node.children.len();
                    para_y = self.layout_composed_paragraph_in_frame(
                        tree,
                        &mut cell_node,
                        composed_for_layout,
                        styles,
                        &inner_area,
                        picture_closing_line
                            .map_or(para_y, |(origin, _)| cell_y + pad_top + origin),
                        start_line,
                        end_line,
                        section_index,
                        cp_idx,
                        Some(cell_context.clone()),
                        !matches!(effective_align, VerticalAlign::Top) && !allow_first_stored_lead,
                        is_last_para,
                        0.0,
                        None,
                        Some(para),
                        Some(bin_data_content),
                        wrap_anchor.as_ref(),
                        false,
                        false,
                        picture_closing_line
                            .map(|_| super::ParagraphVerticalSpacing {
                                before: 0.0,
                                after: 0.0,
                            })
                            .or_else(|| {
                                stored_linear_spacing_before.map(|before| {
                                    super::ParagraphVerticalSpacing {
                                        before,
                                        after: if end_line == composed_for_layout.lines.len() {
                                            styles
                                                .para_styles
                                                .get(para.para_shape_id as usize)
                                                .map_or(0.0, |style| style.spacing_after.max(0.0))
                                        } else {
                                            0.0
                                        },
                                    }
                                })
                            }),
                        picture_closing_line.map(|(origin, _)| {
                            cell_y + pad_top + origin
                                - hwpunit_to_px(para.line_segs[0].vertical_pos, self.dpi)
                        }),
                    );
                    if start_line == 0 && end_line > start_line {
                        para_first_line_top = cell_node.children[lines_before..]
                            .iter()
                            .find(|node| {
                                matches!(
                                    node.node_type,
                                    crate::renderer::render_tree::RenderNodeType::TextLine(_)
                                )
                            })
                            .map(|node| node.bbox.y);
                    }
                    if collapse_stored_wrap_spacers && start_line == 0 && end_line > start_line {
                        if let Some(step) = stored_square_picture_empty_anchor_advance(
                            cell, cp_idx, styles, self.dpi,
                        ) {
                            para_y += hwpunit_to_px(step, self.dpi);
                        }
                    }
                    self.keep_continuation_column_top_spacing_before
                        .set(previous_keep_spacing);

                    let has_visible_text = composed
                        .lines
                        .iter()
                        .any(|line| line.runs.iter().any(|run| !run.text.trim().is_empty()));
                    if has_visible_text {
                        has_preceding_text = true;
                    }
                } else {
                    // has_table_ctrl: 표가 포함된 문단
                    // LINE_SEG vpos가 문단 위치를 정확히 지정하므로,
                    // 추가 spacing 없이 para_y를 그대로 사용.
                }

                // 이 문단의 컨트롤(이미지/도형/중첩테이블) 배치
                // 제목행 반복 셀에서는 컨트롤을 건너뜀 (이미지/도형 중복 방지)
                if !is_repeated_header_cell {
                    let para_alignment = styles
                        .para_styles
                        .get(para.para_shape_id as usize)
                        .map(|s| s.alignment)
                        .unwrap_or(Alignment::Left);

                    // 인라인 컨트롤의 시작 X 위치 (정렬 기반)
                    //
                    // [#6122] 개체 폭 합이 칸 내폭을 넘으면 아래 배치 루프가 저장
                    // lineseg 에 맞춰 줄을 나눈다 — 그때 첫 줄의 폭은 합이 아니라 첫
                    // 개체의 폭이다. 합으로 잡으면 `.max(0.0)` 이 0 이 되어 가운데
                    // 정렬 그림이 칸 왼쪽 끝에 붙었다.
                    let first_inline_width = source_controls
                        .iter()
                        .find_map(|ctrl| match ctrl {
                            Control::Picture(pic) if pic.common.treat_as_char => {
                                Some(hwpunit_to_px(pic.common.width as i32, self.dpi))
                            }
                            Control::Shape(shape) if shape.common().treat_as_char => {
                                Some(hwpunit_to_px(shape.common().width as i32, self.dpi))
                            }
                            Control::Equation(eq) => Some(hwpunit_to_px(
                                crate::renderer::equation::inline_box::horizontal_metrics(eq)
                                    .occupied_width_hwp(),
                                self.dpi,
                            )),
                            _ => None,
                        })
                        .map(|width| width.min(inner_area.width))
                        .unwrap_or(total_inline_width);
                    let inline_align_width = if total_inline_width
                        > inner_area.width + INLINE_WRAP_WIDTH_EPSILON_PX
                        && para.line_segs.len() > 1
                    {
                        first_inline_width
                    } else {
                        total_inline_width
                    };
                    let mut inline_x = match para_alignment {
                        Alignment::Center | Alignment::Distribute => {
                            inner_area.x + (inner_area.width - inline_align_width).max(0.0) / 2.0
                        }
                        Alignment::Right => {
                            inner_area.x + (inner_area.width - inline_align_width).max(0.0)
                        }
                        _ => inner_area.x,
                    };
                    // 이 지점에서 일반 표와 부분 표의 배치가 달랐다. 일반 경로는 그림만 있는 글자처럼 취급 개체를
                    // 저장 LINE_SEG 슬롯에 대응시키지만, 이 대체 경로는 모든 그림을 첫 슬롯에 누적했다.
                    // 이 상태는 빈 텍스트 런의 대체 경로 안에서만 유지한다.
                    // 텍스트가 있거나 같은 줄에 있는 글자처럼 취급 개체는 기존 경로로 처리한다.
                    let all_runs_empty = composed.lines.iter().all(|line| line.runs.is_empty());
                    let para_margin_left = styles
                        .para_styles
                        .get(para.para_shape_id as usize)
                        .map(|style| style.margin_left)
                        .unwrap_or(0.0);
                    let para_margin_right = styles
                        .para_styles
                        .get(para.para_shape_id as usize)
                        .map(|style| style.margin_right)
                        .unwrap_or(0.0);
                    let para_indent = styles
                        .para_styles
                        .get(para.para_shape_id as usize)
                        .map(|style| style.indent)
                        .unwrap_or(0.0);
                    let mut empty_tac_seq_index = 0usize;
                    let mut empty_tac_current_line = 0usize;
                    let first_tac_width = tac_line_widths
                        .first()
                        .copied()
                        .unwrap_or(total_inline_width);
                    let mut empty_tac_x = match para_alignment {
                        Alignment::Center | Alignment::Distribute => {
                            inner_area.x + (inner_area.width - first_tac_width).max(0.0) / 2.0
                        }
                        Alignment::Right => {
                            inner_area.x + (inner_area.width - first_tac_width).max(0.0)
                        }
                        _ => {
                            inner_area.x
                                + effective_margin_left_line(para_margin_left, para_indent, 0)
                        }
                    };
                    let picture_paragraph_origin =
                        super::table_inline_picture_origin::rendered_picture_paragraph_origin(
                            &cell_node,
                            para,
                            section_index,
                            cp_idx,
                        )
                        .unwrap_or(para_y_before_compose);
                    let mut empty_tac_y = picture_paragraph_origin;
                    // [#6122] 텍스트를 가진 문단의 인라인 TAC 개체 폴백은 저장 lineseg 를
                    // 보지 않고 x 만 누적해 왔다 — 폭 초과 개행을 위해 현재 줄과 그 줄의
                    // 흐름 y 를 함께 들고 간다.
                    let mut inline_tac_line = 0usize;
                    let mut inline_tac_y = picture_paragraph_origin;
                    // 폭 초과로 줄을 내린 개체의 하단(#6122). 쪽 분할 칸의 단독 TAC
                    // 그림(#6114)도 같은 값으로 흐름을 민다 — 일반 칸까지 밀면
                    // 칸 상자 밖 글이 아래 본문과 겹친다.
                    let split_cell_tac_flow = cut_units.is_some();
                    let mut wrapped_tac_flow_bottom: Option<f64> = None;
                    let mut rendered_top_and_bottom_non_inline = false;
                    // [#7418] 이 조각이 중첩 표를 **끝까지** 그렸나 — host 줄간격은 표 뒤에만 선다.
                    let nested_row_count = source_controls.iter().find_map(|c| match c {
                        Control::Table(t) => Some(t.row_count as usize),
                        _ => None,
                    });
                    let mut nested_table_continues = nested_cursor_split
                        .as_ref()
                        .zip(nested_row_count)
                        .is_some_and(|(split, rows)| !split.terminal || split.end_row < rows)
                        || nested_cut_rows
                            .zip(nested_row_count)
                            .is_some_and(|((_, end), rows)| end < rows);

                    for (ctrl_idx, ctrl) in source_controls.iter().enumerate() {
                        match ctrl {
                            Control::Picture(pic) => {
                                // 보완 paint도 원본 줄 창의 그림 소유를 소비한다.
                                // 앞 공백 줄만 선택된 조각은 뒤 줄의 TAC 그림을 그리지 않는다.
                                if pic.common.treat_as_char
                                    && stored_control_owned_by_line_window(
                                        para, ctrl_idx, start_line, end_line,
                                    )
                                    .is_some_and(|owned| !owned)
                                {
                                    continue;
                                }
                                let visible_non_inline_control =
                                    cut_units.map_or(true, |(su, eu)| {
                                        self.cell_cut_starts_non_inline_control(
                                            cell, table, styles, su, eu, cp_idx, ctrl_idx,
                                        )
                                    });
                                let fragment_owned_square_flow =
                                    self.profile.get().hwp5_stored_pagination_layout()
                                        && !control_owned_empty
                                        && cut_units.is_some()
                                        && visible_non_inline_control
                                        && pic.common.flow_with_text
                                        && matches!(
                                            pic.common.text_wrap,
                                            crate::model::shape::TextWrap::Square
                                        );
                                if !pic.common.treat_as_char
                                    && cut_units.is_some()
                                    && !visible_non_inline_control
                                {
                                    continue;
                                }
                                if pic.common.treat_as_char {
                                    let pic_w = hwpunit_to_px(pic.common.width as i32, self.dpi);
                                    // 줄 끝 그림도 inline 경로에서 그릴 수 있다. 일반 셀과
                                    // 같이 실제 배치 기록을 확인해 보완 경로의 중복을 막는다.
                                    let will_render_inline = tree
                                        .get_inline_shape_position(
                                            section_index,
                                            cp_idx,
                                            ctrl_idx,
                                            Some(&cell_context),
                                        )
                                        .is_some();
                                    if !will_render_inline {
                                        // 저장 글줄은 공백과 개체를 함께 소유한다.
                                        // 인라인 표와 같은 순서의 펜 위치를 사용하며, 앞 텍스트와
                                        // 분리해 그림만 독립적으로 가운데 정렬하지 않는다.
                                        let stored_picture_left = self
                                            .stored_inline_control_pen(
                                                para,
                                                &composed,
                                                ctrl_idx,
                                                styles,
                                                &inner_area,
                                            )
                                            .map(|pen| {
                                                pen + hwpunit_to_px(
                                                    pic.common.margin.left as i32,
                                                    self.dpi,
                                                )
                                            });
                                        if all_runs_empty && para.line_segs.len() > 1 {
                                            let target_line =
                                                empty_tac_seq_index.min(para.line_segs.len() - 1);
                                            empty_tac_seq_index += 1;
                                            if target_line > empty_tac_current_line {
                                                empty_tac_current_line = target_line;
                                                let line_width = tac_line_widths
                                                    .get(target_line)
                                                    .copied()
                                                    .unwrap_or(0.0);
                                                let line_margin = effective_margin_left_line(
                                                    para_margin_left,
                                                    para_indent,
                                                    target_line,
                                                );
                                                empty_tac_x = match para_alignment {
                                                    Alignment::Center | Alignment::Distribute => {
                                                        inner_area.x
                                                            + (inner_area.width - line_width)
                                                                .max(0.0)
                                                                / 2.0
                                                    }
                                                    Alignment::Right => {
                                                        inner_area.x
                                                            + (inner_area.width - line_width)
                                                                .max(0.0)
                                                    }
                                                    _ => inner_area.x + line_margin,
                                                };
                                                let first_vpos = para
                                                    .line_segs
                                                    .first()
                                                    .map(|line| line.vertical_pos)
                                                    .unwrap_or(0);
                                                if let Some(segment) =
                                                    para.line_segs.get(target_line)
                                                {
                                                    empty_tac_y = picture_paragraph_origin
                                                        + hwpunit_to_px(
                                                            segment.vertical_pos - first_vpos,
                                                            self.dpi,
                                                        );
                                                }
                                            }
                                            let pic_h =
                                                hwpunit_to_px(pic.common.height as i32, self.dpi);
                                            let clamped_w = pic_w.min(inner_area.width);
                                            let clamped_h = if pic_w > 0.0 {
                                                pic_h * (clamped_w / pic_w)
                                            } else {
                                                pic_h
                                            };
                                            let pic_area = LayoutRect {
                                                x: stored_picture_left.unwrap_or(empty_tac_x),
                                                y: empty_tac_y,
                                                width: clamped_w,
                                                height: clamped_h,
                                            };
                                            self.layout_picture(
                                                tree,
                                                &mut cell_node,
                                                pic,
                                                &pic_area,
                                                bin_data_content,
                                                Alignment::Left,
                                                Some(section_index),
                                                Some(cell_context.parent_para_index),
                                                Some(ctrl_idx),
                                                Some(&cell_context),
                                                styles,
                                            );
                                            if split_cell_tac_flow {
                                                wrapped_tac_flow_bottom = Some(
                                                    wrapped_tac_flow_bottom
                                                        .unwrap_or(f64::MIN)
                                                        .max(empty_tac_y + clamped_h),
                                                );
                                            }
                                            empty_tac_x += clamped_w;
                                            continue;
                                        }
                                        // 단독 이미지(텍스트 없는 문단): 직접 렌더링
                                        let pic_h =
                                            hwpunit_to_px(pic.common.height as i32, self.dpi);
                                        // [Task #477] 셀 폭 초과 시 비율 유지 클램프
                                        let clamped_w = pic_w.min(inner_area.width);
                                        let clamped_h = if pic_w > 0.0 {
                                            pic_h * (clamped_w / pic_w)
                                        } else {
                                            pic_h
                                        };
                                        // [#6122] 이미 이 줄에 개체가 있고 폭 합이 칸 내폭을
                                        // 넘으면 한글은 다음 줄로 내린다 — 저장 lineseg 가
                                        // 그 증거다(2181727 6쪽 [그림 7]: 줄 2개의 높이가
                                        // 각 그림 높이와 정확히 같다). 이 폴백은 저장 줄을
                                        // 보지 않고 x 만 누적해 둘째 그림이 칸·용지 밖으로
                                        // 나갔다(#4370·#6101 과 같은 인라인 개체 폭 초과
                                        // 미개행 계열).
                                        let wrapped_to_next_line = inline_x
                                            > inner_area.x + INLINE_WRAP_WIDTH_EPSILON_PX
                                            && inline_x + clamped_w
                                                > inner_area.x
                                                    + inner_area.width
                                                    + INLINE_WRAP_WIDTH_EPSILON_PX
                                            && inline_tac_line + 1 < para.line_segs.len();
                                        if wrapped_to_next_line {
                                            inline_tac_line += 1;
                                            let line_margin = effective_margin_left_line(
                                                para_margin_left,
                                                para_indent,
                                                inline_tac_line,
                                            );
                                            inline_x = match para_alignment {
                                                Alignment::Center | Alignment::Distribute => {
                                                    inner_area.x
                                                        + (inner_area.width - clamped_w).max(0.0)
                                                            / 2.0
                                                }
                                                Alignment::Right => {
                                                    inner_area.x
                                                        + (inner_area.width - clamped_w).max(0.0)
                                                }
                                                _ => inner_area.x + line_margin,
                                            };
                                            let first_vpos = para
                                                .line_segs
                                                .first()
                                                .map(|line| line.vertical_pos)
                                                .unwrap_or(0);
                                            if let Some(segment) =
                                                para.line_segs.get(inline_tac_line)
                                            {
                                                inline_tac_y = picture_paragraph_origin
                                                    + hwpunit_to_px(
                                                        segment.vertical_pos - first_vpos,
                                                        self.dpi,
                                                    );
                                            }
                                        }
                                        // [#4068] `#2004` 정규화가 부동 그림 스택을 인라인으로
                                        // 재분류하며 버린 `horzOffset` 을 되살린다.
                                        let pic_area = LayoutRect {
                                            x: stored_picture_left.unwrap_or(inline_x)
                                                + inline_para_horizontal_offset_px(
                                                    &pic.common,
                                                    para.line_segs
                                                        .get(inline_tac_line)
                                                        .is_some_and(|segment| {
                                                            segment.tag
                                                                & crate::model::paragraph::LineSeg::TAG_IMPLEMENTATION_PROPERTY
                                                                != 0
                                                        }),
                                                    self.dpi,
                                                ),
                                            y: inline_tac_y,
                                            width: clamped_w,
                                            height: clamped_h,
                                        };
                                        // [Task #1151 v4] 셀 안 inline picture (partial 표 path).
                                        self.layout_picture(
                                            tree,
                                            &mut cell_node,
                                            pic,
                                            &pic_area,
                                            bin_data_content,
                                            Alignment::Left,
                                            Some(section_index),
                                            Some(cell_context.parent_para_index),
                                            Some(ctrl_idx),
                                            Some(&cell_context),
                                            styles,
                                        );
                                        if split_cell_tac_flow || wrapped_to_next_line {
                                            wrapped_tac_flow_bottom = Some(
                                                wrapped_tac_flow_bottom
                                                    .unwrap_or(f64::MIN)
                                                    .max(inline_tac_y + clamped_h),
                                            );
                                        }
                                        inline_x += clamped_w;
                                        continue;
                                    }
                                    inline_x += pic_w;
                                } else {
                                    // 비인라인 이미지: TopAndBottom+Para 는 row height 증가와
                                    // 무관하게 LINE_SEG 기준 anchor 를 유지한다.
                                    let top_and_bottom_para = matches!(
                                        pic.common.text_wrap,
                                        crate::model::shape::TextWrap::TopAndBottom
                                    ) && matches!(
                                        pic.common.vert_rel_to,
                                        crate::model::shape::VertRelTo::Para
                                    );
                                    // #1921 p8: 빈 top-anchored 문단 안에 Square 부동 그림과
                                    // TAC 그림이 함께 있으면 compose가 TAC 높이만큼 para_y를
                                    // advance한다. Square 그림의 Para 기준은 advance 후 위치가
                                    // 아니라 그 문단이 시작한 physical cell content top이다.
                                    // vpos>0으로 실제로 밀린 빈 줄(#2226)과 일반 Square 셀은
                                    // 이 조건에 포함하지 않는다.
                                    let empty_top_anchored_square_with_inline_sibling = para
                                        .text
                                        .trim()
                                        .is_empty()
                                        && para
                                            .line_segs
                                            .first()
                                            .is_some_and(|seg| seg.vertical_pos == 0)
                                        && pic.common.flow_with_text
                                        && matches!(
                                            pic.common.text_wrap,
                                            crate::model::shape::TextWrap::Square
                                        )
                                        && source_controls.iter().any(|ctrl| {
                                            matches!(
                                                ctrl,
                                                Control::Picture(sibling) if sibling.common.treat_as_char
                                            )
                                        });
                                    let parallel_picture_owner = fragment_owned_square_flow
                                        && crate::renderer::float_placement::parallel_cell_picture_band_height(
                                            para, self.dpi,
                                        ).is_some();
                                    let anchor_y = if parallel_picture_owner
                                        || empty_top_anchored_square_with_inline_sibling
                                    {
                                        if parallel_picture_owner {
                                            para_y_before_compose
                                        } else {
                                            cell_y + pad_top
                                        }
                                    } else if stored_square_picture_has_adjacent_text(
                                        cell, cp_idx, ctrl_idx,
                                    ) {
                                        para_y_before_compose
                                    } else if top_and_bottom_para {
                                        if cut_units.is_some() && visible_non_inline_controls {
                                            // continuation 조각에 개체 flow 유닛이 실제 포함된 경우
                                            // 원본 line_seg vertical_pos 는 전체 셀 내부 좌표다. 그대로
                                            // 쓰면 다음 쪽 상단에 와야 할 그림이 조각 하단으로 밀린다.
                                            para_y_before_compose
                                        } else {
                                            para.line_segs
                                                .first()
                                                .filter(|seg| seg.vertical_pos >= 0)
                                                .map(|seg| {
                                                    cell_y
                                                        + pad_top
                                                        + hwpunit_to_px(seg.vertical_pos, self.dpi)
                                                })
                                                .unwrap_or(para_y_before_compose)
                                        }
                                    } else if control_owned_empty {
                                        para_y_before_compose
                                    } else if let Some(top) = para_first_line_top.filter(|_| {
                                        // 원본 HWP5 조각 소유 Square 흐름은 아래에서 오프셋 없이
                                        // 흐름 커서를 쓰는 별도 계약이라 그대로 둔다.
                                        !fragment_owned_square_flow
                                            && matches!(
                                                pic.common.vert_rel_to,
                                                crate::model::shape::VertRelTo::Para
                                            )
                                    }) {
                                        // 문단 기준 개체의 원점은 그 문단의 위(첫 줄 상단)다.
                                        // 문단 줄을 모두 구성한 뒤의 `para_y` 는 문단 끝이라
                                        // 그림을 줄 높이만큼 끌어내렸다 — 한/글 2024 PDF
                                        // 36308670 2쪽 빈 문단 1100HU=14.67px.
                                        top
                                    } else if start_line == 0
                                        && end_line == 0
                                        && uncut_control_only_nested_table
                                        && para.line_segs.is_empty()
                                        && matches!(
                                            pic.common.vert_rel_to,
                                            crate::model::shape::VertRelTo::Para
                                        )
                                        && !cell.paragraphs[cp_idx + 1..].iter().any(|next| {
                                            next.text.chars().any(|ch| !ch.is_whitespace())
                                        })
                                    {
                                        // 저장 줄 없는 개체 전용 문단은 줄 수가 0 이라 첫 줄
                                        // 상단이 기록되지 않는다. 구성 뒤 `para_y` 는 빈 문단
                                        // 줄 하나를 지난 자리라, 문단 위를 원점으로 쓴다.
                                        //
                                        // 같은 칸에서 뒤에 글 문단이 오면 그 글은 한/글에서
                                        // 그림 아래로 밀리지만, 이 경로는 저장 줄 사다리가
                                        // 없는 뒤 문단을 그림 아래로 밀지 못한다. 그림만
                                        // 문단 위로 올리면 뒤 글을 덮으므로 그 경우는 종전
                                        // 원점을 둔다.
                                        para_y_before_compose
                                    } else {
                                        para_y
                                    };
                                    let anchor_y =
                                        super::table_inline_picture_origin::rendered_overlay_picture_origin(
                                            &cell_node, para, ctrl_idx, section_index, cp_idx, anchor_y,
                                        ).unwrap_or(anchor_y);
                                    // 칸 문단 기준 어울림 개체의 음수 오프셋은 측정 프레임 위
                                    // 공간을 만들지 않는다 — 일반 표 경로와 같은 계약
                                    // (`cell_wrap_vertical_offset_hu`).
                                    let flow_offset =
                                        crate::renderer::float_placement::cell_wrap_vertical_offset_hu(
                                            &pic.common,
                                        );
                                    let square_flow_common = (flow_offset
                                        != crate::renderer::float_placement::signed_hwpunit(
                                            pic.common.vertical_offset,
                                        ))
                                    .then(|| {
                                        let mut c = pic.common.clone();
                                        c.vertical_offset = flow_offset as u32;
                                        c
                                    });
                                    let pic_w = hwpunit_to_px(pic.common.width as i32, self.dpi);
                                    let pic_h = hwpunit_to_px(pic.common.height as i32, self.dpi);
                                    let unrestricted_take_place_cell_float =
                                        crate::renderer::float_placement::unrestricted_cell_float(
                                            &pic.common,
                                        );
                                    let picture_anchor_y = if unrestricted_take_place_cell_float {
                                        anchor_y
                                            - pic_h
                                            - hwpunit_to_px(
                                                pic.common.vertical_offset as i32,
                                                self.dpi,
                                            )
                                    } else {
                                        anchor_y
                                    };
                                    let cell_area = LayoutRect {
                                        y: picture_anchor_y,
                                        height: (inner_area.height
                                            - (picture_anchor_y - inner_area.y))
                                            .max(0.0),
                                        ..inner_area
                                    };
                                    let picture_box = paragraph_picture_band
                                        .as_ref()
                                        .and_then(|band| band.boxes.get(ctrl_idx));
                                    let paragraph_owned_picture = picture_box.is_some()
                                        && owns_paragraph_entry
                                        && start_line == 0
                                        && end_line > start_line
                                        && crate::renderer::float_placement::signed_hwpunit(
                                            pic.common.vertical_offset,
                                        ) >= 0
                                        && crate::renderer::float_placement::picture_host_follows_cell_content(
                                            &cell.paragraphs, cp_idx,
                                        );
                                    let (pic_x, pic_y) = self.compute_object_position(
                                        square_flow_common.as_ref().unwrap_or(&pic.common),
                                        picture_box.map_or(pic_w, |frame| frame.width),
                                        picture_box.map_or(pic_h, |frame| frame.height),
                                        &cell_area,
                                        &inner_area,
                                        &inner_area,
                                        &inner_area,
                                        picture_anchor_y,
                                        para_alignment,
                                    );
                                    // [Issue #2071] 셀 vertical_align 존중 (table_layout.rs 동일 수정).
                                    // 한컴은 셀 앵커 자리차지 그림을 **셀 valign 으로만** 배치하고
                                    // 그림 자체 pos vert_align 은 무시한다. compute_object_position
                                    // 은 그림 pos vert_align 을 따르므로 콘텐츠 box·그림 높이 기준
                                    // 셀 valign 위치를 강제한다.
                                    let pic_y = if fragment_owned_square_flow {
                                        // 조각의 원점에도 측정이 사용한 양수 흐름 앞 공간을
                                        // 보존한다. 이전 쪽의 음수 offset만 공통 판정으로
                                        // 제거하며 원본의 양수 변위를 함께 버리지 않는다.
                                        picture_anchor_y
                                            + hwpunit_to_px(
                                                crate::renderer::float_placement::cell_wrap_vertical_offset_hu(&pic.common),
                                                self.dpi,
                                            )
                                    } else if paragraph_owned_picture {
                                        // 현재 조각이 소유한 호스트 줄의 실제 원점이다.
                                        // 저장 전체 셀 vpos나 셀 상단으로 덮어쓰지 않는다.
                                        para_first_line_top.unwrap_or(para_y_before_compose)
                                            + hwpunit_to_px(
                                                pic.common.vertical_offset as i32,
                                                self.dpi,
                                            )
                                    } else if top_and_bottom_para
                                        && pic.common.flow_with_text
                                        && !unrestricted_take_place_cell_float
                                        && !paragraph_owned_picture
                                    {
                                        let v_off = hwpunit_to_px(
                                            pic.common.vertical_offset as i32,
                                            self.dpi,
                                        );
                                        let content_top = cell_y + pad_top;
                                        // [#5734] 셀-valign 강제(#2071)는 그림이 셀의 첫
                                        // 콘텐츠일 때의 계약이다. 다문단 셀에서 한글은 앵커
                                        // 문단의 저장 lineseg vpos 로 흐름 배치한다 —
                                        // 156684746 9쪽 왼쪽 칸: 그림 셋이 전부 셀 상단
                                        // 616~640px 에 포개졌고, 한글은 655.6→854.4 로
                                        // 차곡차곡 쌓는다. continuation 조각(su>0) 소유
                                        // 그림은 저장 vpos 가 전체 셀 좌표라 제외하고,
                                        // 첫 조각(su==0)은 셀 상단=조각 상단이라 유효하다.
                                        let stored_flow_vpos = ((self
                                            .profile
                                            .get()
                                            .hwp5_stored_pagination_layout()
                                            || self.profile.get().hwpx_stored_layout())
                                            && !(cut_units.is_some_and(|(su, _)| su > 0)
                                                && visible_non_inline_controls))
                                            .then(|| para.line_segs.first())
                                            .flatten()
                                            .filter(|seg| seg.vertical_pos > 0)
                                            .map(|seg| hwpunit_to_px(seg.vertical_pos, self.dpi));
                                        if let Some(vpos_px) = stored_flow_vpos {
                                            content_top + vpos_px + v_off
                                        } else {
                                            // [#6782] **음수** 세로 오프셋이 그림을 칸 내용
                                            // 영역 **위로 통째로** 밀어내면 한/글은 그 오프셋을
                                            // 쓰지 않는다.
                                            //
                                            // 한/글 2020 오라클 실측
                                            // (`samples/issue6782/…-chemical-labeling-standards.hwp`
                                            // 77쪽 = idx 76, 표 `pi=118 ci=0` 의 `row=4 col=3` 칸,
                                            // 그림 `w=81.1 h=65.8`):
                                            //
                                            //   한/글 y = 235.9
                                            //   rhwp 종전 y = −233.4   ← 용지 위쪽 밖, 인쇄에서 소실
                                            //   이 가드   y = 238.7    (한/글과 2.8px)
                                            //
                                            //   voff −70,819HU = −944.25px, valign=Center 이므로
                                            //   232.1 + (79.05 − 65.8 − 944.25)/2 = −233.4.
                                            //
                                            // ⚠ **음수라고 무조건 버리면 안 된다.** `#5734`
                                            // (156684746 9쪽 왼쪽 칸)의 첫 그림도 저장 vpos 가
                                            // 0이라 이 갈래로 오는데 −1,079HU(14.4px)는
                                            // 적용되는 것이 정답이다(그 핀이 잠그고 있다).
                                            //
                                            //   #6782  y+h = −167.6 ≤ content_top 232.1  → 무시
                                            //   #5734  y+h =  701.1 >  content_top 631.0  → 적용
                                            //
                                            // ⚠ 이것은 "칸과 겹치는가"라는 일반 계약이 **아니다.**
                                            // Top/Center 의 아래쪽 이탈, Bottom 정렬에서 양수
                                            // 오프셋이 만드는 위쪽 이탈, 모든 정렬의 아래쪽 완전
                                            // 이탈은 이 갈래가 다루지 않는다. 오라클이 증명하는
                                            // 것이 음수 오프셋의 위쪽 이탈 하나뿐이라 이름·주석·
                                            // 시험을 그 범위로 맞췄다.
                                            //
                                            // 기준선이 실제 칸 상단(230.2)이 아니라 padding 뒤
                                            // `content_top`(232.1)인 것도 의도한 것이다 — 좌표를
                                            // 만드는 `place()` 가 `content_top` 을 기준점으로
                                            // 쓰므로 같은 기준으로 판정해야 부호가 뒤집히지 않는다.
                                            let aligned_visual_h =
                                                picture_box.map_or(pic_h, |frame| frame.height);
                                            let place = |off: f64| match effective_align {
                                                VerticalAlign::Top => content_top + off,
                                                VerticalAlign::Center => {
                                                    // 이어받는 셀도 측정에 쓰인 흐름 앞 공간으로
                                                    // 가운데를 정한다. 음수 저장값을 별도 이동으로
                                                    // 적용한 뒤 화면 이탈 여부로 되돌리지 않는다.
                                                    let flow_offset = hwpunit_to_px(
                                                        topbottom_flow_vertical_offset_hu(
                                                            &pic.common,
                                                        ),
                                                        self.dpi,
                                                    );
                                                    content_top
                                                        + (inner_height - aligned_visual_h
                                                            + flow_offset)
                                                            / 2.0
                                                }
                                                VerticalAlign::Bottom => {
                                                    content_top + inner_height
                                                        - aligned_visual_h
                                                        - off
                                                }
                                            };
                                            let with_offset = place(v_off);
                                            // 가운데 정렬은 위 공통 흐름 프레임에서 확정한다.
                                            // Top은 #5734처럼 작은 음수 오프셋이 실제 배치에
                                            // 쓰이므로 기존 완전 이탈 규칙을 유지한다.
                                            let escapes_above_cell_content = v_off < 0.0
                                                && !matches!(
                                                    effective_align,
                                                    VerticalAlign::Center
                                                )
                                                && with_offset + pic_h <= content_top;
                                            if escapes_above_cell_content {
                                                place(0.0)
                                            } else {
                                                with_offset
                                            }
                                        }
                                    } else {
                                        pic_y
                                    };
                                    // 같은 그림 띠의 공통 원점과 각 개체 오프셋을 소비한다.
                                    // 각 그림 높이로 하단을 역산하거나 화면 이탈 뒤에 되돌리지 않는다.
                                    let pic_y = stored_empty_picture_frame
                                        .map(|frame| {
                                            text_y_start
                                                - hwpunit_to_px(frame.line_offset_hu, self.dpi)
                                                + hwpunit_to_px(
                                                    frame.picture_band_origin_hu,
                                                    self.dpi,
                                                )
                                                + hwpunit_to_px(
                                                    pic.common.vertical_offset as i32,
                                                    self.dpi,
                                                )
                                        })
                                        .unwrap_or(pic_y);
                                    let deferred_band = self.cell_cut_owns_deferred_picture_band(
                                        cell, table, styles, cut_units, cp_idx,
                                    );
                                    let pic_x =
                                        pic_x + picture_box.map_or(0.0, |frame| frame.margin_left);
                                    let pic_y = if deferred_band {
                                        para_y_before_compose
                                            + hwpunit_to_px(
                                                i32::from(pic.common.margin.top),
                                                self.dpi,
                                            )
                                    } else {
                                        pic_y + picture_box.map_or(0.0, |frame| frame.margin_top)
                                    };
                                    let pic_y = self
                                        .stored_partitioned_picture_origin(
                                            cell, table, styles, cut_units, ctrl_idx,
                                        )
                                        .map(|origin| cell_y + pad_top + origin)
                                        .unwrap_or(pic_y);
                                    let pic_y = stored_picture_cut_frame
                                        .as_ref()
                                        .map(|frame| {
                                            text_y_start
                                                + frame.picture_y(cp_idx, ctrl_idx, self.dpi)
                                        })
                                        .unwrap_or(pic_y);
                                    // 겹침 허용 안 함인 어울림 그림은 이 조각에 먼저 놓인 같은 문단
                                    // 그림과 겹치면 그 아래로 내린다. 이 경로는 문단 흐름으로 그림을
                                    // 이미 내려 놓기도 하므로 오프셋 이동량 대신 실제 자리로 판정한다.
                                    let pic_y = no_overlap_placer.place(
                                        no_overlap_square_stack.as_ref(),
                                        ctrl_idx,
                                        &pic.common,
                                        pic_x,
                                        pic_y,
                                        self.dpi,
                                    );
                                    let pic_area = LayoutRect {
                                        x: pic_x,
                                        y: pic_y,
                                        width: pic_w,
                                        height: pic_h,
                                    };
                                    let mut pic_for_layout = pic.clone();
                                    pic_for_layout.common.horizontal_offset = 0;
                                    pic_for_layout.common.vertical_offset = 0;
                                    pic_for_layout.common.horz_align =
                                        crate::model::shape::HorzAlign::Left;
                                    pic_for_layout.common.vert_align =
                                        crate::model::shape::VertAlign::Top;
                                    // [Task #1151 v4] 셀 안 non-inline picture (partial 표 path).
                                    if unrestricted_take_place_cell_float {
                                        self.layout_picture(
                                            tree,
                                            &mut *table_node,
                                            &pic_for_layout,
                                            &pic_area,
                                            bin_data_content,
                                            Alignment::Left,
                                            Some(section_index),
                                            Some(cell_context.parent_para_index),
                                            Some(ctrl_idx),
                                            Some(&cell_context),
                                            styles,
                                        );
                                    } else {
                                        self.layout_picture(
                                            tree,
                                            &mut cell_node,
                                            &pic_for_layout,
                                            &pic_area,
                                            bin_data_content,
                                            Alignment::Left,
                                            Some(section_index),
                                            Some(cell_context.parent_para_index),
                                            Some(ctrl_idx),
                                            Some(&cell_context),
                                            styles,
                                        );
                                    }
                                    if matches!(
                                        pic.common.text_wrap,
                                        crate::model::shape::TextWrap::TopAndBottom
                                    ) {
                                        rendered_top_and_bottom_non_inline = true;
                                    } else if stored_square_picture_has_adjacent_text(
                                        cell, cp_idx, ctrl_idx,
                                    ) {
                                        // 인접한 저장 텍스트가 이 Square 그림의 세로 띠를 이미 소유한다.
                                        // 분할된 쪽에서도 같은 소유 관계를 적용한다.
                                    } else if fragment_owned_square_flow {
                                        para_y +=
                                            self.cell_non_inline_control_flow_height(&pic.common);
                                    } else {
                                        para_y += self.non_inline_control_flow_height(&pic.common);
                                    }
                                }
                                has_preceding_text = true;
                            }
                            Control::Shape(shape) => {
                                // TextBox를 포함한 Shape는 한 control이 여러 physical
                                // fragment에 걸쳐 내부 문단을 이어 그릴 수 있다. Picture의
                                // entry-only owner 규칙을 Shape에 적용하면 뒤 fragment의
                                // 잔여 TextBox가 통째로 사라진다(rowbreak p17).
                                let owns_overlay_anchor = start_line == 0
                                    && end_line > start_line
                                    && matches!(
                                        shape.common().text_wrap,
                                        crate::model::shape::TextWrap::InFrontOfText
                                            | crate::model::shape::TextWrap::BehindText
                                    );
                                // 흐름을 전진시키지 않는 겹침 개체는 첫 원본 줄에 속한다.
                                // 존재하지 않는 높이 예약에 속한 것으로 처리하지 않는다.
                                if !shape.common().treat_as_char
                                    && cut_units.is_some()
                                    && !visible_non_inline_controls
                                    && !owns_overlay_anchor
                                {
                                    continue;
                                }
                                if shape.common().treat_as_char {
                                    // 글줄이 예약한 위치에는 앞 텍스트, 문단 여백과
                                    // 실제 소유 줄의 기준선이 포함된다. 온전한 셀과
                                    // 같이 그 결과를 소비하고, 등록 없는 경로만
                                    // 기존 순차 배치를 사용한다.
                                    let shape_w =
                                        hwpunit_to_px(shape.common().width as i32, self.dpi);
                                    let (shape_x, shape_y) = tree
                                        .get_inline_shape_position(
                                            section_index,
                                            cp_idx,
                                            ctrl_idx,
                                            Some(&cell_context),
                                        )
                                        .unwrap_or((inline_x, para_y_before_compose));
                                    let shape_area = LayoutRect {
                                        x: shape_x,
                                        y: shape_y,
                                        width: shape_w,
                                        height: inner_area.height,
                                    };
                                    // [Task #1138] 분할 표 셀 컨텍스트
                                    let table_cell_ctx = Some((
                                        section_index,
                                        para_index,
                                        control_index,
                                        cell_idx,
                                        cp_idx,
                                        ctrl_idx,
                                    ));
                                    self.layout_cell_shape(
                                        tree,
                                        &mut cell_node,
                                        shape,
                                        &shape_area,
                                        shape_y,
                                        Alignment::Left,
                                        para.para_shape_id,
                                        styles,
                                        bin_data_content,
                                        clamp_header_negative_para_offset,
                                        table_cell_ctx,
                                    );
                                    inline_x = shape_x + shape_w;
                                } else {
                                    // 비인라인 도형: 기존 동작
                                    let shape_anchor_y = if matches!(
                                        shape.common().vert_rel_to,
                                        crate::model::shape::VertRelTo::Para
                                    ) {
                                        para_y_before_compose
                                    } else {
                                        para_y
                                    };
                                    // [Task #1138] 분할 표 셀 컨텍스트
                                    let table_cell_ctx = Some((
                                        section_index,
                                        para_index,
                                        control_index,
                                        cell_idx,
                                        cp_idx,
                                        ctrl_idx,
                                    ));
                                    let mut shape_for_layout = shape.clone();
                                    if cut_units.is_some() && visible_non_inline_controls {
                                        shape_for_layout.common_mut().horizontal_offset = 0;
                                        shape_for_layout.common_mut().horz_align =
                                            crate::model::shape::HorzAlign::Center;
                                        if start_line >= end_line
                                            && matches!(
                                                shape.common().text_wrap,
                                                crate::model::shape::TextWrap::Square
                                                    | crate::model::shape::TextWrap::Tight
                                                    | crate::model::shape::TextWrap::Through
                                            )
                                            && matches!(
                                                shape.common().vert_rel_to,
                                                crate::model::shape::VertRelTo::Para
                                            )
                                            && (shape.common().vertical_offset as i32) > 0
                                        {
                                            shape_for_layout.common_mut().vertical_offset = 0;
                                        }
                                    }
                                    self.layout_cell_shape(
                                        tree,
                                        &mut cell_node,
                                        &shape_for_layout,
                                        &inner_area,
                                        shape_anchor_y,
                                        para_alignment,
                                        para.para_shape_id,
                                        styles,
                                        bin_data_content,
                                        clamp_header_negative_para_offset,
                                        table_cell_ctx,
                                    );
                                    let is_top_and_bottom_shape = matches!(
                                        shape.common().text_wrap,
                                        crate::model::shape::TextWrap::TopAndBottom
                                    );
                                    let mut shape_flow_h =
                                        self.cell_non_inline_control_flow_height(shape.common());
                                    if is_top_and_bottom_shape {
                                        rendered_top_and_bottom_non_inline = true;
                                        shape_flow_h = 0.0;
                                    }
                                    if !is_top_and_bottom_shape && shape_flow_h <= 0.0 {
                                        shape_flow_h =
                                            if cut_units.is_some() && visible_non_inline_controls {
                                                hwpunit_to_px(
                                                    shape.common().height as i32,
                                                    self.dpi,
                                                ) + hwpunit_to_px(
                                                    (shape.common().vertical_offset as i32).max(0),
                                                    self.dpi,
                                                ) + hwpunit_to_px(
                                                    shape.common().margin.top as i32,
                                                    self.dpi,
                                                ) + hwpunit_to_px(
                                                    shape.common().margin.bottom as i32,
                                                    self.dpi,
                                                )
                                            } else {
                                                0.0
                                            };
                                    }
                                    para_y += shape_flow_h;
                                }
                            }
                            Control::Equation(eq) => {
                                // 분할 표 내 수식: 항상 글자처럼 인라인 배치
                                let eq_w = hwpunit_to_px(
                                    crate::renderer::equation::inline_box::horizontal_metrics(eq)
                                        .occupied_width_hwp(),
                                    self.dpi,
                                );
                                let eq_h = hwpunit_to_px(
                                    crate::renderer::equation::flow_height_hwp(eq) as i32,
                                    self.dpi,
                                );

                                // 빈 runs 셀 + TAC 수식: paragraph_layout(Task #287 경로)이
                                // layout_composed_paragraph 안에서 이미 렌더 후
                                // set_inline_shape_position 호출. 중복 emit 방지
                                // (Issue #301 의 분할 표 경로 보강 — Task #318).
                                let already_rendered_inline = tree
                                    .get_inline_shape_position(
                                        section_index,
                                        cp_idx,
                                        ctrl_idx,
                                        cell_context_opt.as_ref(),
                                    )
                                    .is_some();
                                if already_rendered_inline {
                                    inline_x += eq_w;
                                    continue;
                                }

                                let (eq_x, eq_y) = {
                                    let x = inline_x;
                                    inline_x += eq_w;
                                    (x, para_y_before_compose)
                                };

                                let font_size_px = hwpunit_to_px(eq.font_size as i32, self.dpi);
                                let super::super::equation::PaintParts {
                                    layout_box,
                                    color_str,
                                    svg_content,
                                } = super::super::equation::paint_parts(eq, self.dpi);

                                let eq_node = RenderNode::new(
                                    tree.next_id(),
                                    RenderNodeType::Equation(EquationNode {
                                        svg_content,
                                        layout_box,
                                        color_str,
                                        color: eq.color,
                                        font_size: font_size_px,
                                        script: eq.script.clone(),
                                        section_index: Some(section_index),
                                        para_index: Some(para_index),
                                        control_index: Some(ctrl_idx),
                                        cell_index: Some(cell_idx),
                                        cell_para_index: Some(cp_idx),
                                        note_ref: None,
                                    }),
                                    BoundingBox::new(
                    crate::renderer::equation::inline_box::horizontal_metrics(eq).content_origin_x(eq_x, self.dpi),
                    eq_y,
                    hwpunit_to_px(crate::renderer::equation::inline_box::horizontal_metrics(eq).content_width_hwp, self.dpi),
                    eq_h,
                ),
                                );
                                cell_node.children.push(eq_node);
                            }
                            Control::Table(nested_table) => {
                                let frame_owner = composed
                                    .frame_owns_inline_table(ctrl_idx)
                                    .then(|| {
                                        crate::renderer::composer::control_slot_line_index(
                                            para, ctrl_idx,
                                        )
                                    })
                                    .flatten();
                                // 텍스트 줄만 선택된 조각은 같은 문단의 다른 저장 줄에
                                // 실린 TAC 표를 소유하지 않는다. 실제 중첩 행·재귀 컷이
                                // 선택된 경우에는 그 컷이 원본 줄 대신 소유권을 정한다.
                                if nested_table.common.treat_as_char
                                    && cut_units.is_some()
                                    && nested_cut_rows.is_none()
                                    && nested_cursor_split.is_none()
                                    && mixed_nested_split.is_none()
                                    && stored_control_owned_by_line_window(
                                        para, ctrl_idx, start_line, end_line,
                                    )
                                    .or_else(|| {
                                        frame_owner
                                            .map(|owner| start_line <= owner && owner < end_line)
                                    })
                                    .is_some_and(|owned| !owned)
                                {
                                    continue;
                                }
                                let nested_h = self.calc_nested_table_height(nested_table, styles);

                                // [Task #993] 컷 모델: 중첩 표는 atomic 유닛이라
                                // line_ranges 가 가시 여부를 이미 결정했다. 가시
                                // 중첩 표는 전체 렌더하되 셀 가용 공간을 초과하면
                                // calc_nested_split_rows 로 행 범위를 필터한다.
                                {
                                    // 중첩 표가 셀 가용 공간을 초과하면 행 범위 필터 적용
                                    let stored_square_offset = (collapse_stored_wrap_spacers && start_line == 0)
                                        .then(|| super::super::height_measurer::stored_square_table_anchor_offset(cell, cp_idx))
                                        .flatten();
                                    let stored_float_frame = stored_mixed_opening_frame.as_ref()
                                        .and_then(|frame| frame.placement_for_host(cp_idx, ctrl_idx, text_y_start))
                                        .or_else(|| (start_line == 0)
                                        .then(|| {
                                            // 저장 위치에 맞춘 빈 호스트는 문단 앞 간격
                                            // 뒤의 저장 줄에서 시작한다. 블록 프레임은
                                            // 전체 셀 배치와 같이 그 간격 앞 원점을 쓴다.
                                            let origin = if table_host_line_only_fragment
                                                && (table_host_has_stored_origin
                                                    || single_column_snap_spacing_before)
                                            {
                                                para_y_before_lines
                                                    - styles
                                                        .para_styles
                                                        .get(para.para_shape_id as usize)
                                                        .map_or(0.0, |style| style.spacing_before)
                                            } else {
                                                para_y_before_lines
                                            };
                                            self.stored_nested_float_placement(
                                                table,
                                                cell,
                                                cp_idx,
                                                nested_table,
                                                ctrl_idx,
                                                origin,
                                                styles,
                                            ).filter(|frame| {
                                                // 표 앞 공간을 역산하는 프레임의 원점은
                                                // 저장 호스트 줄이다. 누적 흐름 커서는
                                                // 아직 자식 표를 소비하지 않았으므로 그
                                                // 커서에서 표 높이를 다시 빼면 앞 행에 겹친다.
                                                !matches!(frame.flow, crate::renderer::float_placement::ParagraphFloatFlow::NextLine)
                                                    || (table_host_has_stored_origin
                                                        && (cut_units.is_none()
                                                            || frame.stored_host_origin.is_some()))
                                            })
                                        })
                                        .flatten())
                                        .map(|frame| {
                                            frame.with_cell_column_anchor(
                                                nested_table,
                                                &inner_area,
                                                hwpunit_to_px(
                                                    nested_table.common.width as i32,
                                                    self.dpi,
                                                ) * self.render_table_width_scale(nested_table),
                                                self.dpi,
                                            )
                                        });
                                    // 문단 앞/뒤 개체는 글자 뒤 커서가 아닌 문단 앵커를 쓴다.
                                    // 전체 셀과 같은 query를 소비한다. 부분 컷은 이 문단의
                                    // 첫 원본 유닛을 소유할 때만 앵커를 새로 연다.
                                    let overlay_frame = (owns_paragraph_entry && start_line == 0)
                                        .then(|| crate::renderer::float_placement::nested_overlay_outer_frame(
                                            nested_table, para_y_before_lines, nested_h, self.dpi,
                                        ))
                                        .flatten();
                                    let nested_origin = if let Some(owner) = frame_owner {
                                        let base = para
                                            .line_segs
                                            .get(start_line)
                                            .map_or(0, |line| line.vertical_pos);
                                        let origin = para.line_segs[owner].vertical_pos;
                                        NestedTableOrigin::Paragraph(
                                            para_y_before_lines
                                                + hwpunit_to_px(origin - base, self.dpi),
                                        )
                                    } else if matches!(
                                        stored_host_flow,
                                        Some(StoredNestedHostFlow::BeforeLine { .. })
                                    ) {
                                        // 앞 간격은 종료 줄을 소유한다. 본체는 앞 유닛이
                                        // 끝난 곳에서 시작하고 바깥 여백은 표 배치가 소비한다.
                                        NestedTableOrigin::Paragraph(stored_host_flow_entry)
                                    } else if let Some(frame) = stored_float_frame {
                                        NestedTableOrigin::Table(frame.table_top)
                                    } else if let Some(frame) = &overlay_frame {
                                        NestedTableOrigin::Table(frame.start)
                                    } else if let Some(offset) = stored_square_offset {
                                        NestedTableOrigin::Table(
                                            para_y_before_lines + hwpunit_to_px(offset, self.dpi),
                                        )
                                    } else if let Some((_, lead)) = first_stored_inline_owner_lead
                                        .filter(|(owner, _)| {
                                            *owner == cp_idx
                                                && !has_preceding_text
                                                && table_host_line_only_fragment
                                        })
                                    {
                                        // 첫 표의 앞 간격은 내용 유닛에 이미 포함되어 있다.
                                        // 뒤 문단은 자신의 저장 좌표 스냅을 계속 소비한다.
                                        NestedTableOrigin::Paragraph(para_y_before_lines + lead)
                                    } else if nested_table.common.treat_as_char
                                        && table_host_line_only_fragment
                                    {
                                        // 앞쪽 원본 줄이 비어 있어도 자신의 슬롯을 소유한다.
                                        // 그린 텍스트가 없다는 이유로 저장 개체 줄의 원점을 셀 상단으로 대체하지 않는다.
                                        NestedTableOrigin::Paragraph(
                                            para_y_before_lines
                                                + stored_nested_table_line_offset_px(
                                                    para, ctrl_idx, start_line, self.dpi,
                                                )
                                                .unwrap_or(0.0),
                                        )
                                    } else if has_preceding_text {
                                        NestedTableOrigin::Paragraph(
                                            if table_host_line_only_fragment {
                                                // [#6653] 은 "표는 그 줄이 시작한 자리에 놓는다" 인데
                                                // `para_y_before_lines` 는 **문단**의 시작이다.
                                                // [#6923] 저장 사다리가 표를 별도 줄에 적어 둔 문단
                                                // (148738070 p69: ls[0] 글줄 49113HU · ls[1] 표
                                                // 51229HU)에서는 그 둘이 28.2px 다르고, 문단 시작에
                                                // 앉히면 표가 앞 글줄 위로 올라온다(4쪽: 줄
                                                // 735.0..753.7 위에 표 740.0 — 겹침 13건).
                                                // 저장이 말하는 **그 줄**까지의 델타를 더한다.
                                                para_y_before_lines
                                                    + stored_nested_table_line_offset_px(
                                                        para, ctrl_idx, start_line, self.dpi,
                                                    )
                                                    .unwrap_or(0.0)
                                            } else {
                                                para_y
                                            },
                                        )
                                    } else {
                                        NestedTableOrigin::Paragraph(inner_area.y)
                                    };
                                    let owns_nested_start = owns_paragraph_entry;
                                    let nested_y = nested_origin.resolve(
                                        nested_table,
                                        self.dpi,
                                        owns_nested_start,
                                    );
                                    let available_h =
                                        (inner_area.height - (nested_y - inner_area.y)).max(0.0);
                                    // TAC(글자처럼 취급) 표: 앞 텍스트 너비만큼 x 오프셋 적용.
                                    // 분할 표 내부에서는 composed 텍스트가 이전 줄까지 포함할 수
                                    // 있으므로, 표가 남은 폭에 들어가지 않으면 셀 좌측 기준으로
                                    // 배치해 페이지 오른쪽 밖으로 밀려나는 것을 막는다.
                                    // 이어받은 저장 프레임은 소유 줄의 가로 원점도 유지한다.
                                    // 같은 줄에서 이 개체 앞의 텍스트만 기여하며, 뒤따르는 런은 앞부분에 포함하지 않는다.
                                    let stored_owner_offset = if resumed_stored_frame_origin
                                        .is_some()
                                        && nested_table.common.treat_as_char
                                        && matches!(
                                            para_alignment,
                                            Alignment::Left | Alignment::Justify
                                        ) {
                                        crate::renderer::layout::control_line_seg_index(
                                            para, ctrl_idx,
                                        )
                                        .and_then(
                                            |owner| {
                                                let line = composed.lines.get(owner)?;
                                                let position =
                                                    *para.control_text_positions().get(ctrl_idx)?;
                                                let mut remaining =
                                                    position.saturating_sub(line.char_start);
                                                let mut prefix_width = 0.0;
                                                for run in &line.runs {
                                                    let prefix: String =
                                                        run.text.chars().take(remaining).collect();
                                                    remaining = remaining
                                                        .saturating_sub(prefix.chars().count());
                                                    prefix_width += estimate_text_width(
                                                        &prefix,
                                                        &run.text_style(styles),
                                                    );
                                                }
                                                Some(
                                                    effective_margin_left_line(
                                                        para_margin_left,
                                                        para_indent,
                                                        owner,
                                                    ) + prefix_width,
                                                )
                                            },
                                        )
                                    } else {
                                        None
                                    };
                                    let tac_text_offset = if let Some(offset) = stored_owner_offset
                                    {
                                        offset
                                    } else if nested_table.common.treat_as_char {
                                        let mut text_w = 0.0;
                                        for line in &composed.lines {
                                            for run in &line.runs {
                                                if !run.text.is_empty() {
                                                    let ts = run.text_style(styles);
                                                    text_w += estimate_text_width(&run.text, &ts);
                                                }
                                            }
                                        }
                                        text_w
                                    } else {
                                        0.0
                                    };
                                    let nested_w = if nested_table.common.width > 0 {
                                        hwpunit_to_px(nested_table.common.width as i32, self.dpi)
                                            * self.render_table_width_scale(nested_table)
                                    } else {
                                        inner_area.width
                                    };
                                    let tac_x_offset = if nested_table.common.treat_as_char
                                        && tac_text_offset > 0.0
                                        && tac_text_offset + nested_w > inner_area.width + 0.5
                                    {
                                        0.0
                                    } else {
                                        tac_text_offset.min(inner_area.width)
                                    };
                                    let empty_inline_table = nested_table.common.treat_as_char
                                        && table_host_line_only_fragment
                                        && all_runs_empty;
                                    let stored_inline_left = nested_table
                                        .common
                                        .treat_as_char
                                        .then(|| {
                                            self.stored_inline_control_pen(
                                                para,
                                                &composed,
                                                ctrl_idx,
                                                styles,
                                                &inner_area,
                                            )
                                        })
                                        .flatten()
                                        .map(|pen| {
                                            pen + hwpunit_to_px(
                                                nested_table.outer_margin_left as i32,
                                                self.dpi,
                                            )
                                        });
                                    if empty_inline_table {
                                        let owner = super::control_line_seg_index(para, ctrl_idx)
                                            .unwrap_or(empty_tac_current_line);
                                        if owner != empty_tac_current_line {
                                            empty_tac_current_line = owner;
                                            let line_width =
                                                tac_line_widths.get(owner).copied().unwrap_or(0.0);
                                            empty_tac_x = match para_alignment {
                                                Alignment::Center | Alignment::Distribute => {
                                                    inner_area.x
                                                        + (inner_area.width - line_width).max(0.0)
                                                            / 2.0
                                                }
                                                Alignment::Right => {
                                                    inner_area.x
                                                        + (inner_area.width - line_width).max(0.0)
                                                }
                                                _ => {
                                                    inner_area.x
                                                        + effective_margin_left_line(
                                                            para_margin_left,
                                                            para_indent,
                                                            owner,
                                                        )
                                                }
                                            };
                                        }
                                    }
                                    // 재귀 컷도 전체 표 경로가 사용하는 인라인 줄 원점을 받는다.
                                    // 자식 부분 표의 기본 Left 정렬로 이 원점을 다시 잃지 않는다.
                                    let mut ctrl_area = LayoutRect {
                                        x: inner_area.x + tac_x_offset,
                                        y: nested_y,
                                        width: (inner_area.width - tac_x_offset).max(0.0),
                                        height: available_h,
                                    };

                                    // 중첩 표가 가용 공간을 초과하면 NestedTableSplit 적용
                                    let split_info = if let Some(split) =
                                        mixed_nested_split.as_ref()
                                    {
                                        Some(NestedTableSplit {
                                            start_row: split.start_row,
                                            end_row: split.end_row,
                                            visible_height: split.visible_height,
                                            flow_height: split.flow_height,
                                            offset_within_start: split.offset_within_start,
                                            content_offset: split.content_offset,
                                            force_source_start_cut: split.force_source_start_cut,
                                            replay_terminal_boundary_unit: split
                                                .replay_terminal_boundary_unit,
                                            terminal: split.terminal,
                                            recursive_cut: split.recursive_cut.clone(),
                                        })
                                    } else if let Some(split) = nested_cursor_split.as_ref() {
                                        Some(NestedTableSplit {
                                            start_row: split.start_row,
                                            end_row: split.end_row,
                                            visible_height: split.visible_height,
                                            flow_height: split.flow_height,
                                            offset_within_start: split.offset_within_start,
                                            content_offset: split.content_offset,
                                            force_source_start_cut: split.force_source_start_cut,
                                            replay_terminal_boundary_unit: split
                                                .replay_terminal_boundary_unit,
                                            terminal: split.terminal,
                                            recursive_cut: split.recursive_cut.clone(),
                                        })
                                    } else if let Some((row_lo, row_hi)) = nested_cut_rows {
                                        // [Task #1073] 페이지네이션 컷의 중첩행 범위로 직접
                                        // NestedTableSplit 구성 — 연속 페이지가 start_row 부터
                                        // 렌더(available_h 휴리스틱의 row0 재렌더 결함 정정).
                                        let ncol = nested_table.col_count as usize;
                                        let nrow = nested_table.row_count as usize;
                                        let nrow_heights = self.resolve_row_heights(
                                            nested_table,
                                            ncol,
                                            nrow,
                                            None,
                                            styles,
                                            true,
                                        );
                                        let ncs = hwpunit_to_px(
                                            nested_table.cell_spacing as i32,
                                            self.dpi,
                                        );
                                        let start_row = row_lo.min(nrow);
                                        let end_row = row_hi.min(nrow).max(start_row);
                                        let mut vis_h = 0.0;
                                        for r in start_row..end_row {
                                            vis_h += nrow_heights[r];
                                            if r + 1 < end_row {
                                                vis_h += ncs;
                                            }
                                        }
                                        Some(NestedTableSplit {
                                            start_row,
                                            end_row,
                                            visible_height: vis_h,
                                            flow_height: vis_h,
                                            content_offset: 0.0,
                                            force_source_start_cut: false,
                                            replay_terminal_boundary_unit: false,
                                            // 행 컷은 자식의 마지막 행을 소유하면 종료다.
                                            // 부모 셀의 end_unit 센티널과 구분한다.
                                            terminal: end_row == nrow,
                                            offset_within_start: 0.0,
                                            recursive_cut: None,
                                        })
                                    } else if nested_h > available_h + 0.5 {
                                        let ncol = nested_table.col_count as usize;
                                        let nrow = nested_table.row_count as usize;
                                        let nrow_heights = self.resolve_row_heights(
                                            nested_table,
                                            ncol,
                                            nrow,
                                            None,
                                            styles,
                                            true,
                                        );
                                        let ncell_spacing = hwpunit_to_px(
                                            nested_table.cell_spacing as i32,
                                            self.dpi,
                                        );
                                        Some(calc_nested_split_rows(
                                            &nrow_heights,
                                            ncell_spacing,
                                            0.0,
                                            available_h,
                                        ))
                                    } else {
                                        None
                                    };
                                    let split_info = split_info.map(|split| {
                                        self.with_nested_header_reservation(
                                            nested_table,
                                            split,
                                            styles,
                                        )
                                    });
                                    let split_ref = split_info.as_ref().filter(|s| {
                                        s.start_row > 0
                                            || s.end_row < nested_table.row_count as usize
                                            || s.offset_within_start > 0.5
                                            || s.visible_height + 0.5 < nested_h
                                    });
                                    if empty_inline_table
                                        && split_info
                                            .as_ref()
                                            .is_some_and(|split| split.recursive_cut.is_some())
                                    {
                                        ctrl_area.x = empty_tac_x
                                            + hwpunit_to_px(
                                                nested_table.outer_margin_left as i32,
                                                self.dpi,
                                            );
                                    }
                                    if split_ref.is_some_and(|s| {
                                        s.end_row < nested_table.row_count as usize
                                            || (nested_cursor_split.is_none()
                                                && nested_cut_rows.is_none()
                                                && s.visible_height + 0.5 < nested_h)
                                    }) {
                                        nested_table_continues = true;
                                    }

                                    let nested_ctx = cell_context_opt.as_ref().map(|ctx| {
                                        let mut new_ctx = ctx.clone();
                                        new_ctx.path.push(CellPathEntry {
                                            control_index: ctrl_idx,
                                            cell_index: 0,
                                            cell_para_index: 0,
                                            text_direction: 0,
                                        });
                                        new_ctx
                                    });
                                    // [#4334] 이 재귀 중첩 표는 `table_meta: None` 이라
                                    // TableNode.para_index/control_index 가 항상 비었다 —
                                    // 방금 확장한 `nested_ctx` 에서 이 중첩 표 자신의
                                    // 좌표를 읽는다. `section_index` 는 이미 항상 채워지는데
                                    // para/control 만 비는 게 #4334 stage3 가 실측한 42개 중
                                    // 다수의 원인이었다.
                                    let derived_table_meta = nested_ctx
                                        .as_ref()
                                        .and_then(CellContext::nested_table_meta);
                                    // 전체 셀 흐름을 만들 수 없는 혼합 호스트도 같은 컷
                                    // 소유를 사용한다. fallback 원점에서 여백을 다시 열지 않는다.
                                    let owns_reflow_host_anchor = owns_nested_start
                                        && external_frame.is_none_or(|frame| frame.parent_owned);
                                    let opens_reflow_outer_frame = owns_reflow_host_anchor
                                        || cut_units.is_some_and(|(start, end)| {
                                            let units = self.cell_units(cell, table, styles);
                                            let start = start.min(units.len());
                                            let end = end.clamp(start, units.len());
                                            Self::reflow_units_open_outer_frame(
                                                &units[start..end],
                                                split_info
                                                    .as_ref()
                                                    .and_then(|split| split.recursive_cut.as_ref()),
                                            )
                                        });
                                    let reflow_block_origin =
                                        reflow_block_flow.as_ref().and_then(|flow| {
                                            self.reflow_block_fragment_table_origin(
                                                flow,
                                                cp_idx,
                                                ctrl_idx,
                                                nested_table,
                                                ctrl_area.x,
                                                nested_y,
                                                owns_reflow_host_anchor,
                                                opens_reflow_outer_frame,
                                            )
                                        });
                                    let unrestricted_reflow_block = reflow_block_origin.is_some()
                                        && crate::renderer::float_placement::unrestricted_cell_float(
                                            &nested_table.common,
                                        );
                                    let ctrl_area = reflow_block_origin
                                        .filter(|_| unrestricted_reflow_block)
                                        .map_or(ctrl_area, |origin| {
                                            self.unrestricted_cell_float_area(&ctrl_area, origin)
                                        });
                                    let first_new_child = cell_node.children.len();
                                    let nested_parent = if unrestricted_reflow_block {
                                        &mut *table_node
                                    } else {
                                        &mut cell_node
                                    };
                                    let table_h_rendered = if let Some(recursive_cut) = split_info
                                        .as_ref()
                                        .and_then(|split| split.recursive_cut.as_ref())
                                    {
                                        // [#4069] 측정이 자식 표의 행·CellUnit 범위를
                                        // 재귀 투영한 경우 렌더도 같은 범위를 부분 표 경로에
                                        // 넘긴다. scalar y clip으로 표 전체를 매 쪽 재방출하면
                                        // vpos 리셋 프레임의 앞·뒤 문단이 서로 겹치므로, 동일
                                        // cursor가 선택한 문단/줄/자식 표만 방출해야 한다.
                                        // 이 cursor가 측정한 표는 문서 모델 안의 원본
                                        // `nested_table`이다. 매 페이지 clone을 만들면
                                        // `cell_units_cache`의 raw cell pointer가 allocator
                                        // 재사용으로 다른 clone을 가리킬 수 있다. 일반 wrapper가
                                        // 끝낸 table 해석 뒤의 구현을 원본 참조로 직접 호출한다.
                                        let source_frame_height = (recursive_cut.start_row == 0
                                            && recursive_cut.end_row == 1
                                            && !recursive_cut.is_block_split
                                            && !recursive_cut.start_cut_is_block)
                                            .then(|| {
                                                self.saved_nested_single_cell_frame_height(
                                                    nested_table,
                                                    &recursive_cut.start_cut,
                                                    &recursive_cut.end_cut,
                                                    styles,
                                                )
                                            })
                                            .flatten();
                                        let joint_opening_height = (recursive_cut.start_row == 0
                                            && !recursive_cut.is_block_split
                                            && !recursive_cut.start_cut_is_block)
                                            .then(|| {
                                                let rows = self.resolve_row_heights(
                                                    nested_table,
                                                    nested_table.col_count as usize,
                                                    nested_table.row_count as usize,
                                                    None,
                                                    styles,
                                                    true,
                                                );
                                                self.stored_joint_row_opening_height(
                                                    nested_table,
                                                    recursive_cut.end_row.checked_sub(1)?,
                                                    &rows,
                                                    &recursive_cut.start_cut,
                                                    &recursive_cut.end_cut,
                                                    styles,
                                                )
                                                .or_else(|| {
                                                    self.stored_nested_opening_cut_frame(
                                                        nested_table,
                                                        recursive_cut,
                                                        styles,
                                                    )
                                                    .map(|frame| frame.last_row_height)
                                                })
                                            })
                                            .flatten();
                                        // 물리 여유와 실제 paint가 같은 최종 원점을 소비한다.
                                        // 저장/재조판 경로의 위쪽 바깥 띠를 뒤에서 다시 더하지 않는다.
                                        let resolved_nested_table_top = reflow_block_origin
                                                    .map(|origin| origin.1)
                                                    .or_else(|| source_frame_height
                                                    .map(|_| {
                                                        nested_y
                                                            + hwpunit_to_px(
                                                                nested_table.outer_margin_top
                                                                    as i32,
                                                                self.dpi,
                                                            )
                                                    })
                                                    .or_else(|| {
                                                        stored_float_frame
                                                            .map(|f| f.table_top)
                                                            .or_else(|| overlay_frame.as_ref().map(|frame| {
                                                                frame.start + hwpunit_to_px(nested_table.outer_margin_top as i32, self.dpi)
                                                            }))
                                                            .or_else(|| {
                                                                self.stored_hwpx_cut_owns_outer_frame(para, nested_table).then(|| nested_y + hwpunit_to_px(nested_table.outer_margin_top as i32, self.dpi))
                                                            })
                                                            .or_else(|| {
                                                                self.reflow_nested_table_origin(
                                                                    para,
                                                                    styles,
                                                                    nested_table,
                                                                    &ctrl_area,
                                                                    nested_w,
                                                                    nested_y,
                                                                    opens_reflow_outer_frame,
                                                                )
                                                                .map(|(_, y)| y)
                                                            })
                                                            .or_else(|| {
                                                                self.stored_wrapper_opening_frame(
                                                                    table, start_cut, end_cut, styles,
                                                                )
                                                                .map(|frame| cell_y + frame.child_top)
                                                            })
                                                    })
                                                    .or_else(|| {
                                                        // 투영된 첫 행 유닛은 이 위쪽 바깥 띠를
                                                        // 이미 예약한다. 이어받는 하위 표의 커서는
                                                        // 그 띠를 다시 예약하지 않는다.
                                                        (recursive_cut.start_row == 0
                                                            && recursive_cut.start_cut.iter().all(|cut| *cut == 0))
                                                        .then(|| nested_y + hwpunit_to_px(
                                                            nested_table.outer_margin_top as i32, self.dpi))
                                                        .or_else(|| self.nested_row_continuation_outer_top(
                                                            nested_table, recursive_cut,
                                                        ).map(|top| nested_y + top))
                                                    }));
                                        let plain_source_height = recursive_cut
                                            .end_row
                                            .checked_sub(1)
                                            .and_then(|last_row| {
                                                let row_start =
                                                    if recursive_cut.start_row == last_row {
                                                        recursive_cut.start_cut.as_slice()
                                                    } else {
                                                        &[]
                                                    };
                                                let extra = self.stored_child_cut_frame_extra(
                                                    nested_table,
                                                    recursive_cut,
                                                    styles,
                                                )?;
                                                let content = self.row_cut_content_height(
                                                    nested_table,
                                                    last_row,
                                                    row_start,
                                                    &recursive_cut.end_cut,
                                                    styles,
                                                );
                                                let spare = (cell_y + cell_h
                                                    - pad_bottom
                                                    - resolved_nested_table_top
                                                        .unwrap_or(nested_y)
                                                    - hwpunit_to_px(
                                                        i32::from(nested_table.outer_margin_bottom),
                                                        self.dpi,
                                                    )
                                                    - self.nested_cut_physical_height(
                                                        nested_table,
                                                        recursive_cut,
                                                        styles,
                                                    ))
                                                .max(0.0);
                                                Some(content + extra.min(spare))
                                            });
                                        let reflow_closing_band = (!is_block_split
                                            && !start_cut_is_block)
                                            .then(|| {
                                                self.reflow_nested_band_at_height(
                                                    table,
                                                    usize::from(cell.row),
                                                    if usize::from(cell.row) == start_row {
                                                        start_cut
                                                    } else {
                                                        &[]
                                                    },
                                                    if usize::from(cell.row) + 1 == end_row {
                                                        end_cut
                                                    } else {
                                                        &[]
                                                    },
                                                    cell_h,
                                                    styles,
                                                )
                                            })
                                            .flatten();
                                        let rendered_bottom = self.layout_partial_table_resolved(
                                            tree,
                                            nested_parent,
                                            nested_table.as_ref(),
                                            PartialTableHostContext {
                                                paragraphs: &[],
                                                para_index: 0,
                                                control_index: 0,
                                                repeat_fragment_outer_margin: false,
                                                pre_emitted_host_height: 0.0,
                                                pre_emitted_host_content_height: 0.0,
                                                host_line_spacing: 0.0,
                                                predecessor_flow_bottom: None,
                                                resolved_table_left: reflow_block_origin
                                                    .and_then(|origin| origin.0)
                                                    .or(stored_inline_left)
                                                    .or_else(|| {
                                                        stored_float_frame
                                                            .and_then(|f| f.table_left)
                                                    }),
                                                end_row_owns_stored_frame: false,
                                                computed_fragment_frame: false,
                                                // 같은 원본 프레임의 바깥여백은 부모 흐름에 예약했다.
                                                // 실제 표 원점에서는 위 여백만 한 번 소비한다.
                                                resolved_table_top: resolved_nested_table_top,
                                            },
                                            section_index,
                                            styles,
                                            outline_numbering_id,
                                            &ctrl_area,
                                            nested_y,
                                            bin_data_content,
                                            recursive_cut.start_row,
                                            recursive_cut.end_row,
                                            recursive_cut.start_row > 0
                                                || !recursive_cut.start_cut.is_empty(),
                                            &recursive_cut.start_cut,
                                            &recursive_cut.end_cut,
                                            recursive_cut.is_block_split,
                                            recursive_cut.start_cut_is_block,
                                            // recursive_cut의 행 cursor는 이미 이 호출의
                                            // `nested_table` 자신의 행 기준(#4069 재귀
                                            // 투영)이다. 투명 래퍼 벗기기는 별개 좌표계
                                            // 판정(#4326)이라 여기서는 항상 false.
                                            false,
                                            source_frame_height
                                                .filter(|_| !recursive_cut.end_cut.is_empty())
                                                .or(joint_opening_height)
                                                .or(plain_source_height)
                                                .or_else(|| {
                                                    reflow_closing_band
                                                        .as_ref()
                                                        .map(|band| band.last_row_height)
                                                }),
                                            source_frame_height
                                                .filter(|_| !recursive_cut.start_cut.is_empty()),
                                            &[],
                                            &[],
                                            para_margin_left,
                                            para_margin_right,
                                            None,
                                            nested_ctx.as_ref(),
                                            clamp_header_negative_para_offset,
                                            // [#4149] 프로브는 최외곽 표에만 적용한다.
                                            None,
                                        );
                                        // [#3820/issue2007 p14] recursive cut은 현재 호출의
                                        // source 범위를 제한하지만 parent flow_height는 기존
                                        // 조각 높이를 유지한다. 새 child root만 clip에 포섭해
                                        // 현재 쪽 마지막 두 줄이 조상 clip에서 소실되지 않게
                                        // 하고 pagination cursor에는 영향을 주지 않는다.
                                        expand_cell_clip_to_new_source_bounded_children(
                                            &mut cell_node,
                                            first_new_child,
                                        );
                                        rendered_bottom - nested_y
                                    } else {
                                        let rendered_height = self.layout_table(
                                            tree,
                                            nested_parent,
                                            nested_table,
                                            section_index,
                                            styles,
                                            outline_numbering_id,
                                            &ctrl_area,
                                            nested_y,
                                            bin_data_content,
                                            None,
                                            1,
                                            derived_table_meta,
                                            para_alignment,
                                            nested_ctx,
                                            para_margin_left,
                                            para_margin_right,
                                            stored_inline_left.or_else(|| {
                                                empty_inline_table.then(|| {
                                                    empty_tac_x
                                                        + hwpunit_to_px(
                                                            nested_table.outer_margin_left as i32,
                                                            self.dpi,
                                                        )
                                                })
                                            }),
                                            split_ref,
                                            None,
                                            None,
                                            false,
                                            clamp_header_negative_para_offset,
                                            0.0,
                                            reflow_block_origin
                                                .or_else(|| {
                                                    stored_inline_left.map(|left| {
                                                        (
                                                            Some(left),
                                                            self.compute_table_y_position(
                                                                nested_table,
                                                                nested_h,
                                                                nested_y,
                                                                &ctrl_area,
                                                                1,
                                                                0.0,
                                                                0.0,
                                                                None,
                                                                None,
                                                                false,
                                                                false,
                                                            ),
                                                        )
                                                    })
                                                })
                                                .or_else(|| {
                                                    empty_inline_table.then(|| {
                                                        (
                                                            Some(
                                                                empty_tac_x
                                                                    + hwpunit_to_px(
                                                                        nested_table
                                                                            .outer_margin_left
                                                                            as i32,
                                                                        self.dpi,
                                                                    ),
                                                            ),
                                                            // x만 재사용해도 기존 세로 바깥여백은
                                                            // 전체 표와 같은 원점 계산으로 보존한다.
                                                            self.compute_table_y_position(
                                                                nested_table,
                                                                nested_h,
                                                                nested_y,
                                                                &ctrl_area,
                                                                1,
                                                                0.0,
                                                                0.0,
                                                                None,
                                                                None,
                                                                false,
                                                                false,
                                                            ),
                                                        )
                                                    })
                                                })
                                                .or_else(|| {
                                                    stored_float_frame
                                                        .map(|f| (f.table_left, f.table_top))
                                                })
                                                .or_else(|| {
                                                    overlay_frame.as_ref().map(|frame| {
                                                        (
                                                            None,
                                                            frame.start
                                                                + hwpunit_to_px(
                                                                    nested_table.outer_margin_top
                                                                        as i32,
                                                                    self.dpi,
                                                                ),
                                                        )
                                                    })
                                                })
                                                .or_else(|| {
                                                    self.reflow_nested_table_origin(
                                                        para,
                                                        styles,
                                                        nested_table,
                                                        &ctrl_area,
                                                        nested_w,
                                                        nested_y,
                                                        owns_nested_start,
                                                    )
                                                    .map(|(x, y)| (Some(x), y))
                                                }),
                                            Self::standalone_table_char_border_fill(
                                                Some(para),
                                                nested_table,
                                                styles,
                                            ),
                                        );
                                        if owns_nested_start {
                                            if let Some(frame) = stored_float_frame.filter(|frame| {
                                                matches!(frame.flow, crate::renderer::float_placement::ParagraphFloatFlow::Exclusion)
                                                    && split_ref.is_none_or(|split| {
                                                        split.start_row == 0
                                                            && split.end_row == usize::from(nested_table.row_count)
                                                            && split.offset_within_start == 0.0
                                                            && split.content_offset == 0.0
                                                            && split.recursive_cut.is_none()
                                                            && frame.table_top + split.visible_height
                                                                + hwpunit_to_px(i32::from(nested_table.outer_margin_bottom), self.dpi)
                                                                >= frame.occupied_bottom
                                                    })
                                            }) {
                                                // 온전한 source child의 Exclusion 상자 끝까지
                                                // clip을 연다. 일부 행/내용 컷의 미소유 꼬리는
                                                // 이 원본 상자를 소유하지 않으므로 열지 않는다.
                                                if matches!(&cell_node.node_type, RenderNodeType::TableCell(cell) if cell.clip) {
                                                    cell_node.bbox.height = cell_node.bbox.height
                                                        .max(frame.occupied_bottom - cell_node.bbox.y);
                                                }
                                            }
                                        }
                                        rendered_height
                                    };
                                    let visible_table_h = split_info
                                        .as_ref()
                                        .filter(|_| {
                                            mixed_nested_split.is_some()
                                                || nested_cursor_split.is_some()
                                        })
                                        .map(|split| split.flow_height)
                                        .unwrap_or(table_h_rendered);
                                    if std::env::var_os("RHWP_DIAG_SCAN").is_some() {
                                        eprintln!("DIAG_SCAN INLINE_SLOT parent_pi={} cp={cp_idx} ctrl={ctrl_idx} tac={} table_only={table_host_line_only_fragment} empty_runs={all_runs_empty} alignment={para_alignment:?} recursive={} line={} line_widths={tac_line_widths:?} prepared_x={empty_tac_x:.3} area_x={:.3} area_w={:.3} nested_w={nested_w:.3} painted={:?}", cell_context.parent_para_index, nested_table.common.treat_as_char, split_info.as_ref().is_some_and(|split| split.recursive_cut.is_some()), empty_tac_current_line, ctrl_area.x, ctrl_area.width, cell_node.children.get(first_new_child).map(|child| child.bbox));
                                    }
                                    if empty_inline_table {
                                        empty_tac_x += nested_w
                                            + hwpunit_to_px(
                                                nested_table.outer_margin_left as i32
                                                    + nested_table.outer_margin_right as i32,
                                                self.dpi,
                                            );
                                    }
                                    // 컷 없는 저장 떠 있는 개체는 물리 본문과 여백을
                                    // 이미 확정했다. 배치가 반환한 전체 띠의 여백을
                                    // table_top에서 다시 더하지 않는다.
                                    para_y = stored_float_frame
                                        .filter(|_| {
                                            split_info.as_ref().is_none_or(|split| {
                                                split.start_row == 0
                                                    && split.end_row
                                                        == usize::from(nested_table.row_count)
                                                    && split.offset_within_start == 0.0
                                                    && split.content_offset == 0.0
                                                    && split.recursive_cut.as_ref().is_none_or(
                                                        |cut| {
                                                            cut.start_cut.iter().all(|n| *n == 0)
                                                                && cut.end_cut.is_empty()
                                                        },
                                                    )
                                            })
                                        })
                                        .map_or_else(|| {
                                            // 투영한 유닛의 흐름은 종료 호스트와 여백을 이미 소유한다.
                                            // 본체 높이만 받은 경로에서만 같은 원본 종료 슬롯을 더한다.
                                            let trailing_host = (mixed_nested_split.is_none() && nested_cursor_split.is_none()
                                                && split_info.as_ref().is_none_or(|split| {
                                                    split.end_row == usize::from(nested_table.row_count)
                                                        && split.terminal
                                                }))
                                            .then(|| crate::renderer::float_placement::block_table_trailing_whitespace_line_hu(para, nested_table, ctrl_idx))
                                            .flatten();
                                            // 반환된 표 높이는 바깥여백까지 소유한다.
                                            // 호스트 글줄만 더하고 아래 여백을 다시 소비하지 않는다.
                                            nested_y + visible_table_h + trailing_host.map_or(0.0, |h| {
                                                hwpunit_to_px(h, self.dpi)
                                            })
                                        }, |frame| {
                                            if matches!(frame.flow, crate::renderer::float_placement::ParagraphFloatFlow::NextLine) {
                                                frame.paragraph_end(para_y, 0.0)
                                            } else {
                                                // 프레임 끝은 다음 글줄 원점이다. 문단 시작으로
                                                // 환산해 다음 문단이 앞 간격을 한 번만 적용한다.
                                                let successor_before = (self.render_normalization.borrow().cell_frame_reflowed(table, cell)
                                                    && frame.stored_successor_line_origin.is_some())
                                                    .then(|| cell.paragraphs.get(cp_idx + 1))
                                                    .flatten()
                                                    .and_then(|next| styles.para_styles.get(next.para_shape_id as usize))
                                                    .map_or(0.0, |style| style.spacing_before);
                                                frame.occupied_bottom - successor_before
                                            }
                                        });
                                    has_preceding_text = true;
                                }
                            }
                            _ => {}
                        }
                    }
                    if let Some(height) = self
                        .stored_partitioned_picture_fragment_height(cell, table, styles, cut_units)
                    {
                        para_y = cell_y + pad_top + height;
                    } else if rendered_top_and_bottom_non_inline {
                        if self.cell_cut_owns_deferred_picture_band(
                            cell, table, styles, cut_units, cp_idx,
                        ) {
                            if let Some(height) =
                                crate::renderer::float_placement::deferred_picture_band_height(
                                    para, self.dpi,
                                )
                            {
                                para_y = para_y_before_compose + height;
                            }
                        } else if let Some(advance) = self
                            .cell_picture_host_flow_advance(cell, table, styles, cut_units, cp_idx)
                        {
                            para_y = para_y_before_compose + advance;
                        } else {
                            para_y += self
                                .paragraph_top_and_bottom_non_inline_flow_height(&source_controls);
                        }
                    }
                    // [#7418] 저장 줄 없는 빈 host 의 TAC 표 줄 뒤에는 그 줄의 줄간격이 붙는다 —
                    // 측정(`no_ls_tac_table_host_trailing_spacing_px`)이 행 높이에 넣은 몫이다.
                    // 중첩 표가 이 조각에서 끝나지 않으면(쪽을 넘어 이어짐) 그 뒤 줄간격은
                    // 이 조각에 없다 — tac_object_host_line_height 2쪽: 3×3 표가 쪽 바닥까지
                    // 이어지는데 줄간격을 더해 칸 가운데 정렬이 6px 어긋났다.
                    // 줄간격은 **뒤에 이을 줄**이 이 조각에 있을 때만 공간을 쓴다 — 칸의
                    // 마지막 문단이거나 다음 문단이 다음 조각으로 가면 조각 끝의 말미다.
                    let next_para_in_fragment = match line_ranges.as_ref() {
                        Some(ranges) => ranges
                            .get(cp_idx + 1)
                            .is_some_and(|&(start, end)| start < end),
                        None => cp_idx + 1 < cell.paragraphs.len(),
                    };
                    if next_para_in_fragment && !nested_table_continues {
                        // 저장 successor 전진량은 호스트 전체 줄의 슬롯이다.
                        // 앞 조각이 입구를 소비했다면 현재 자식 컷의 전진 끝을
                        // 보존하고, 전체 높이로 이미 소비한 앞부분을 다시 싣지 않는다.
                        if !self.profile.get().session_edited()
                            && owns_paragraph_entry
                            && !self
                                .render_normalization
                                .borrow()
                                .cell_frame_reflowed(table, cell)
                        {
                            if let Some(advance) = cell.paragraphs.get(cp_idx + 1).and_then(|next| {
                                crate::renderer::float_placement::stored_inline_table_successor_advance(
                                    para, next, styles, self.dpi,
                                )
                            }) {
                                para_y = para_y_before_lines + advance;
                            }
                        }
                        // 재귀·혼합 컷은 CellUnit의 종료 간격을 flow_height에
                        // 이미 담는다. scalar 행 컷의 본체 높이에만 호스트의
                        // 줄 뒤·문단 뒤 간격을 한 번 더한다.
                        if let Some(spacing) =
                            crate::renderer::height_measurer::no_ls_tac_table_host_trailing_spacing_px(
                                para, styles, self.dpi,
                            )
                            .filter(|_| nested_cursor_split.is_none() && mixed_nested_split.is_none())
                        {
                            para_y += spacing
                                + styles
                                    .para_styles
                                    .get(para.para_shape_id as usize)
                                    .map_or(0.0, |style| style.spacing_after);
                        }
                    }
                    if !nested_table_continues
                        && nested_cursor_split.is_none()
                        && mixed_nested_split.is_none()
                        && !matches!(
                            stored_host_flow,
                            Some(StoredNestedHostFlow::BeforeLine { .. })
                        )
                    {
                        para_y += self.block_following_host_line_for_cut(
                            cell, table, styles, cp_idx, cut_units,
                        );
                    }
                    // [#6122] 폭 초과로 내린 개체는 composed 줄 높이에 없다 — 그 아래로
                    // 흐름을 밀지 않으면 다음 문단(캡션)이 그림 위에 겹쳐 그려진다.
                    if let Some(bottom) = wrapped_tac_flow_bottom {
                        let stored_advance = (!self.profile.get().session_edited()
                            && !self.render_normalization.borrow().cell_frame_reflowed(table, cell)
                            && next_para_in_fragment)
                            .then(|| cell.paragraphs.get(cp_idx + 1).and_then(|next|
                                crate::renderer::float_placement::stored_inline_picture_successor_advance(
                                    para, next, styles, self.dpi,
                                )))
                            .flatten();
                        para_y = stored_advance.map_or_else(
                            || para_y.max(bottom),
                            |advance| para_y_before_compose + advance,
                        );
                    }
                }

                let stored_empty_advance = (!self.profile.get().session_edited()
                    && !cell.dirty_flag
                    && !self
                        .render_normalization
                        .borrow()
                        .cell_frame_reflowed(table, cell))
                .then(|| {
                    crate::renderer::float_placement::stored_empty_successor_advance(
                        &cell.paragraphs,
                        cp_idx,
                        styles,
                        self.dpi,
                    )
                })
                .flatten();
                if let Some(advance) = stored_empty_advance {
                    let next_owned = line_ranges.as_ref().is_none_or(|ranges| {
                        ranges
                            .get(cp_idx + 1)
                            .is_some_and(|(start, end)| start < end)
                    });
                    if next_owned {
                        para_y = para_y_before_compose + advance;
                    }
                }
                let wrap_successor = collapse_stored_wrap_spacers
                    .then(|| stored_nested_table_wrap_successor(cell, cp_idx))
                    .flatten()
                    .filter(|&idx| {
                        line_ranges.as_ref().is_none_or(|ranges| {
                            ranges.get(idx).is_some_and(|&(start, end)| start < end)
                        })
                    });
                if has_table_ctrl
                    && (mixed_nested_split.is_none() || wrap_successor.is_some())
                    && !self
                        .render_normalization
                        .borrow()
                        .cell_frame_reflowed(table, cell)
                {
                    // LINE_SEG vpos 기반으로 para_y 보정.
                    let is_last_para = cp_idx + 1 == cell.paragraphs.len();
                    if !is_last_para {
                        if let Some(next_para) =
                            cell.paragraphs.get(wrap_successor.unwrap_or(cp_idx + 1))
                        {
                            if let Some(next_seg) = next_para.line_segs.first() {
                                // [#3637] `vertical_pos` 는 **셀 전체** 좌표라 조각 시작
                                // 유닛만큼의 원점이 빠져 있지 않다. 조각 후반부(start_cut 이
                                // 큰 연속 조각)에서 이 스냅은 문단을 셀 상자 밖으로 밀어내고,
                                // 그 글자는 어느 렌더 경로에도 보이지 않는다 — 텍스트 추출에만
                                // 남는다(156083443 보도자료 10쪽: cp=164 다음이 vpos=72846
                                // → y=1018.5, 셀 바닥 1005.1).
                                //
                                // 원점을 빼는 교정은 #3654 에서 실패했다. para_y 를 낮추면 그
                                // 값이 다시 컷 판정으로 되먹임되어 다른 문서에 새 넘침을
                                // 만든다. 이 스냅은 **밀어내기 전용**(`max`)이므로 셀 바닥으로
                                // 상한만 두면 밀림을 막으면서 기존 위치는 보존한다 — 스냅이
                                // 필요했던 쪽 안 문단은 상자 안이라 상한에 걸리지 않는다.
                                //
                                // 그래서 두 가지를 함께 건다.
                                //   ① 조각 원점(frag_vpos_origin)을 빼 조각-상대 좌표로
                                //   ② 그래도 남는 셀 내부 도약(#3654 가 걸린 자리, 소방방재
                                //      45,290 HU)에 대비해 셀 바닥으로 상한
                                // ①만으로는 #3654 처럼 도약 문서에서 여전히 밀려나고,
                                // ②만으로는 상한에서 멈춘 뒤 뒤 문단이 그 아래로 쌓인다.
                                // [#5995] 저장 vpos 는 다음 문단의 spacing_before 를
                                // 이미 포함한다. vpos 사다리를 신뢰하는 1×1 선형
                                // 셀에서는 layout_composed_paragraph 의 재가산 몫을
                                // 빼고 밀어야 이중 가산이 없다(위 preserve 스냅과
                                // 같은 규약). 그 외 형상은 기존 밀어내기 보존.
                                let next_spacing_before = if preserve_linear_single_cell_vpos
                                    || wrap_successor.is_some()
                                    || (!self.profile.get().session_edited()
                                        && !self.render_normalization.borrow().cell_frame_reflowed(table, cell)
                                        && crate::renderer::float_placement::stored_column_top_spacing_before(
                                            &cell.paragraphs,
                                            wrap_successor.unwrap_or(cp_idx + 1),
                                            styles.para_styles.get(next_para.para_shape_id as usize)
                                                .map_or(0.0, |style| style.spacing_before),
                                            styles, self.dpi,
                                        ).is_some())
                                {
                                    styles
                                        .para_styles
                                        .get(next_para.para_shape_id as usize)
                                        .map(|s| s.spacing_before)
                                        .unwrap_or(0.0)
                                } else {
                                    0.0
                                };
                                let next_vpos_y = text_y_start
                                    + hwpunit_to_px(
                                        (next_seg.vertical_pos - frag_vpos_origin).max(0),
                                        self.dpi,
                                    )
                                    - next_spacing_before;
                                let cell_content_bottom =
                                    cell_content_bottom(cell_y, cell_h, pad_bottom);
                                para_y = para_y.max(next_vpos_y.min(cell_content_bottom));
                            }
                        }
                    }
                }
                if let Some(StoredNestedHostFlow::BeforeLine { height }) = stored_host_flow {
                    // 행 컷이 수용한 같은 문단 유닛의 끝을 다음 흐름으로 전달한다.
                    // 자식의 반환 높이는 부모 종료 줄이나 예약 간격을 소유하지 않는다.
                    para_y = stored_host_flow_entry + height;
                    if std::env::var_os("RHWP_DIAG_SCAN").is_some() {
                        eprintln!("DIAG_STORED_NESTED_HOST_FLOW cp={cp_idx} entry={stored_host_flow_entry:.6} height={height:.6} end={para_y:.6}");
                    }
                }
            }

            // [#7095] 쪽이 정한 비끝 조각 상자 안에서 칸 `valign=Center` 를 적용한다.
            //
            // 한/글 2020 정본(156060125, `pdf/tac_object_host_line_height-2020.pdf`)의
            // 3~9쪽 조각은 줄마다 `칸 내용 위 + 저장 vpos` 에 쪽별 상수 하나를 더한 자리에
            // 놓이고(쪽 안 편차 0.6px 이하), 그 상수는 `(상자 안 높이 − 조각 내용 높이) / 2`
            // 와 0.55~0.93px 안에서 맞는다. #4042 가 막은 것은 **칸 전체** 내용으로 잰
            // 가운데 정렬이고, 이 조각의 내용만 재면 한/글과 같은 가운데 정렬이 된다.
            // 같은 형상의 `valign=Top` 칸(148738070)은 정본이 상자 위에 붙으므로 건드리지 않는다.
            //
            // 조각 내용 높이는 실제 배치 커서(`para_y`)에 **이 조각이 소유했지만 그리지
            // 않은 꼬리 빈 문단**의 저장 줄 상자를 더한다. 글자가 없어도 줄 상자는 공간을
            // 차지한다 — 정본 4·5·6쪽은 그 빈 줄(p67·p96·p121) 바닥까지를 내용으로 센다.
            let mut placed_dy = 0.0_f64;
            if centers_pinned_fragment
                && matches!(effective_align, VerticalAlign::Top)
                // 이미 첫 원본 띠가 소유한 위치를 남은 여유로 다시 가운데로 옮기지 않는다.
                && !first_source_band_owns_position
            {
                let trailing_empty_extent = cut_units
                    .and_then(|(_, end_unit)| {
                        let units = self.cell_units(cell, table, styles);
                        let last_owned = units.get(end_unit.checked_sub(1)?)?.para_idx;
                        if last_owned <= last_rendered_para_idx
                            || !cell.paragraphs[last_rendered_para_idx + 1..=last_owned]
                                .iter()
                                .all(|para| para.text.is_empty() && para.controls.is_empty())
                        {
                            return None;
                        }
                        let rendered_end = line_ranges.as_ref()?.get(last_rendered_para_idx)?.1;
                        let rendered_seg = cell.paragraphs[last_rendered_para_idx]
                            .line_segs
                            .get(rendered_end.checked_sub(1)?)?;
                        let tail_seg = cell.paragraphs[last_owned].line_segs.last()?;
                        let delta = (tail_seg.vertical_pos + tail_seg.line_height)
                            - (rendered_seg.vertical_pos + rendered_seg.line_height);
                        (delta > 0).then(|| hwpunit_to_px(delta, self.dpi))
                    })
                    .unwrap_or(0.0);
                let content_height = (para_y - text_y_start) + trailing_empty_extent;
                // [#7063 레인②] 가운데정렬의 기준은 테두리 상자의 안높이다 —
                // `inner_height` 는 예산이 자른 내용 높이라 쪽 상자로 고정한 조각에서 갈린다.
                let dy = ((cell_h - pad_top - pad_bottom).max(0.0) - content_height) / 2.0;
                if dy > 0.0 {
                    placed_dy = dy;
                    let box_top = cell_node.bbox.y;
                    for child in &mut cell_node.children {
                        // 앞 조각이 소유한 줄은 상자 위 clip 밖에 남는다 — 내리면 보이게 된다.
                        if child.bbox.y + 0.5 >= box_top {
                            translate_render_subtree_y(child, dy);
                        }
                    }
                }
            }
            // 각주 참조 번호
            for para in &cell.paragraphs {
                self.add_footnote_superscripts(tree, &mut cell_node, para, styles);
            }

            // [#4159] `end_cut=[]`인 종료 유닛 창은 이후 continuation이 없다. 재귀
            // 중첩 표의 bottom stroke가 top padding만큼 셀 clip을 넘는 경우에만
            // 현재 셀 bbox를 포섭 확장한다. `eu < usize::MAX` 비종료 조각은 보존한다.
            let terminal_cell_fragment =
                cut_units.is_some_and(|(_, end_unit)| end_unit == usize::MAX);
            expand_terminal_cell_clip_to_nested_table_descendants(
                &mut cell_node,
                terminal_cell_fragment,
            );
            if terminal_cell_fragment && cell_end_row == row_count {
                // 뒤 조각은 경계를 넘는 마지막 줄을 소유할 수 없다.
                // 잔여 조각을 억제하기 전에 그 줄을 복구하되, 다른 행이나 꼬리말에는 넘기지 않는다.
                let (_, body_y, _, body_h) = self.current_body_area.get();
                let paint_bottom = if body_h > 0.0 {
                    (body_y + body_h).min(tree.page_size().1)
                } else {
                    tree.page_size().1
                };
                let previous_bottom = cell_node.bbox.y + cell_node.bbox.height;
                expand_page_fragment_clip_to_own_text_lines(&mut cell_node, paint_bottom, true);
                let recovered_bottom = cell_node.bbox.y + cell_node.bbox.height;
                if collapse_stored_wrap_spacers && recovered_bottom > previous_bottom + 0.01 {
                    cell_node.bbox.height = (recovered_bottom + pad_bottom.max(0.0))
                        .min(paint_bottom)
                        - cell_node.bbox.y;
                }
            }

            // 셀 테두리를 엣지 그리드에 수집 (인접 셀 중복 제거)
            {
                let cell_end_row_idx = cell_row + cell.row_span as usize;
                let first_ri = render_rows.iter().position(|&r| r == cell_row).or_else(|| {
                    render_rows
                        .iter()
                        .position(|&r| r > cell_row && r < cell_end_row_idx)
                });
                let last_ri = render_rows
                    .iter()
                    .rposition(|&r| r >= cell_row && r < cell_end_row_idx);
                if let (Some(fri), Some(lri)) = (first_ri, last_ri) {
                    if let Some(bs) = border_style {
                        collect_cell_borders(
                            &mut *h_edges,
                            &mut *v_edges,
                            cell_col,
                            fri,
                            cell.col_span as usize,
                            lri + 1 - fri,
                            &bs.borders,
                        );
                    }
                    mark_cell_span_interior_covered(
                        &mut *h_span_covered,
                        &mut *v_span_covered,
                        cell_col,
                        fri,
                        cell.col_span as usize,
                        lri + 1 - fri,
                    );
                }
            }

            // [#6976] 배치 뒤 행 단위 상자 접기 — 이 조각의 마지막 그린 행에서 바닥을
            // 공유하는 칸들이 실제로 남긴 여분의 **최솟값**을 모은다. 상자를 접어도 어느 칸의
            // 내용·아래여백도 잘리지 않는 상한이다.
            if let Some(fold_row) = fold_last_row {
                if row_band::owns_fragment_bottom(cell_row, cell.row_span as usize, fold_row)
                    && !is_repeated_header_cell
                {
                    // 배치 커서(`para_y`)는 줄 상자 바닥과 다를 수 있다 — 상자 **안에 있던**
                    // 가시 자손의 바닥도 함께 본다. 상자 밖으로 나간 자손은 이 조각이 이미
                    // 잘라 낸 것이므로 세지 않는다(세면 접기가 영영 멈춘다).
                    let box_top = cell_node.bbox.y;
                    let box_bottom = cell_y + cell_h;
                    fn in_box_bottom(node: &RenderNode, top: f64, bottom: f64) -> f64 {
                        let mut b: f64 = f64::NEG_INFINITY;
                        if node.visible {
                            let nb = node.bbox.y + node.bbox.height;
                            if node.bbox.y + 0.5 >= top && nb <= bottom + 0.5 {
                                b = nb;
                            }
                        }
                        for child in &node.children {
                            b = b.max(in_box_bottom(child, top, bottom));
                        }
                        b
                    }
                    let mut content_bottom = para_y + placed_dy;
                    for child in &cell_node.children {
                        content_bottom =
                            content_bottom.max(in_box_bottom(child, box_top, box_bottom));
                    }
                    *fold_slack =
                        fold_slack.min(box_bottom - (content_bottom + pad_bottom.max(0.0)));
                }
            }

            table_node.children.push(cell_node);
            table_node.children.extend(cell_diagonals);
        }
    }

    /// [#7095] 본문을 통째로 담은 1×1 `RowBreak` 표의 쪽 조각인가.
    ///
    /// 이 형상에서 한컴은 조각 상자 상단을 본문 상단 + 표 `outer_margin_top` 에 둔다
    /// (정본 156060125 engine 2020: 2·3·10쪽 모두 47.15px = 45.35 + 141HU).
    /// 다중 행·열 분할 표는 이 근거가 없으므로 종전 계약을 유지한다.
    ///
    /// 마지막이 아닌 조각의 상자를 쪽이 정하는 축은 같은 술어로 아래에서 닫는다.
    /// 칸 내용을 그 상자 안에서 `valign` 으로 배치하는 축은 아직 열려 있다 — `#7095`.
    /// 쪽 경계로 잘리는 칸은 `effective_align` 이 `Top` 이라(이 파일 위쪽 #4042),
    /// 고정한 상자 아래에 빈 밴드가 남는다(7062 2쪽 1025.8..1043.9).
    fn single_cell_rowbreak_page_fragment(&self, table: &crate::model::table::Table) -> bool {
        // [#7063 레인①] `#7095` 의 조각 상자 계약에는 **계보 구분이 없다.** 그 이슈가
        // `hwp5_stored_pagination_layout` 을 요구한 것은 근거 문서가 native HWP5 저장본
        // (156060125 · 30269)뿐이었기 때문이고, 원본 HWPX 정본을 뜨면 같은 값이 나온다.
        //
        // 정본 실측(쪽 척도 제거 후, 조각 윗변 = 흐름 + `outMargin.top`):
        //
        // ```text
        //   pdf/hwpx_sample2-hwpx-2020.pdf        141HU  37.80 → 39.70   정본 39.64  (6쪽)
        //                                           0HU  37.80   불변    정본 37.72  ← 0 대조군
        //   pdf/rowbreak-problem-pages-hwpx-2020.pdf
        //                                         283HU  94.50 → 98.30   정본 98.29  (3쪽)
        //                                           0HU  94.50   불변    정본 94.46  ← 0 대조군
        //   pdf/issue2004_cell_image_stack-hwpx-2020.pdf
        //                                         283HU 123.90 → 127.70  정본 127.70 (4쪽)
        //                                         283HU  83.10 →  86.90  정본  86.95 (5~8쪽)
        // ```
        //
        // 잔차는 선언값 두 종에서 ≤0.06px 이고 `omT=0` 표는 이미 맞는다 — 상수 보정이 아니라
        // **선언 여백 그 자체**다. `issue2004` 는 같은 문서의 HWP 쌍둥이가 `#7095` 로 이미
        // 정본과 맞고 HWPX 만 여백만큼 위였던 자리라, 두 계보가 같은 정본으로 모인다.
        //
        // 형상 조건(1×1 · 비-TAC · RowBreak)은 `#7095` 그대로 둔다. 행·열을 열면 samples
        // 전수 overflow 가 2561 → 2614, text-overlap 3537 → 3551 로 34문서가 어긋난다(실측).
        //
        // **예산(`typeset` 조각 예산)은 종전 계보 게이트를 유지한다.** 이 술어가 paint 에서
        // 여는 상자는 종전보다 **크기만** 하므로(쪽이 정한 아래끝까지) 예산이 이미 정한 컷이
        // 상자 밖으로 나가지 않는다. 예산까지 함께 열면 `issue3236_split_table` 의 쪽수
        // 정답지(2쪽)가 3쪽으로 깨진다 — 2쪽 끝 한 줄이 밀린다(실측).
        //
        // `#7098` 이 기록한 `rowbreak-problem-pages.hwpx` 15쪽 text_overlap 1 → 2 는 남는다.
        // 그 쪽은 칸 안 글상자가 꼬리말을 파고드는 **선행** 결함 자리이고(정본 본문 마지막
        // 글자 1008.80 · 그 글상자는 정본에 없다), 겹침 **면적**은 325.6 → 312.9 로,
        // 최대 겹침 높이는 7.08 → 5.23 으로 줄어든다. 근거는 `text_overlap_baseline.tsv` 머리말.
        crate::renderer::float_placement::native_single_cell_rowbreak_page_fragment(true, table)
    }

    /// 표의 일부 행만 레이아웃한다 (페이지 분할).
    ///
    /// `start_row..end_row` 범위의 행만 렌더링한다.
    /// `is_continuation`이 true이고 repeat_header인 표면 행0(제목행)을 먼저 렌더링한다.
    #[allow(clippy::too_many_arguments)]
    pub(crate) fn layout_partial_table(
        &self,
        tree: &mut PageLayoutContext,
        col_node: &mut RenderNode,
        paragraphs: &[Paragraph],
        para_index: usize,
        control_index: usize,
        section_index: usize,
        styles: &ResolvedStyleSet,
        outline_numbering_id: u16,
        col_area: &LayoutRect,
        y_start: f64,
        bin_data_content: &[BinDataContent],
        start_row: usize,
        end_row: usize,
        is_continuation: bool,
        start_cut: &[usize],
        end_cut: &[usize],
        is_block_split: bool,
        // [#6935] 시작 컷의 인덱스 공간 — 끝 컷과 다를 수 있다.
        start_cut_is_block: bool,
        row_cursor_is_nested: bool,
        end_row_owns_stored_frame: bool,
        computed_fragment_frame: bool,
        end_row_height_override: Option<f64>,
        start_row_height_override: Option<f64>,
        straddle_row_relief: &[(usize, f64)],
        straddle_page_bands: &[crate::renderer::pagination::StraddleCellCarry],
        host_margin_left: f64,
        host_margin_right: f64,
        measured_table: Option<&MeasuredTable>,
        enclosing_cell_ctx: Option<&CellContext>,
        clamp_header_negative_para_offset: bool,
        probe: Option<&PartialTableCellProbe>,
        resolved_table_top: Option<f64>,
        predecessor_flow_bottom: Option<f64>,
    ) -> f64 {
        let para = match paragraphs.get(para_index) {
            Some(p) => p,
            None => return y_start,
        };
        let outer_table = match para.controls.get(control_index) {
            Some(Control::Table(t)) => t,
            _ => return y_start,
        };
        let repeat_fragment_outer_margin = computed_fragment_frame || repeats_native_empty_host_rowbreak_fragment_margin(
            self.profile.get().hwp5_stored_pagination_layout(),
            paragraphs,
            para_index,
            control_index,
        ) || crate::renderer::float_placement::stored_empty_offset_rowbreak_fragment_repeats_outer_margin(
            self.profile.get().hwp5_stored_pagination_layout() || self.profile.get().hwpx_stored_layout(),
            para, outer_table,
        ) || crate::renderer::float_placement::stored_repeated_header_rowbreak_outer_frame(
                self.profile.get(), para, outer_table,
        ) || crate::renderer::float_placement::computed_rowbreak_owns_outer_frame(
                para, outer_table, start_cut,
        ) || crate::renderer::float_placement::stored_rowbreak_owns_fragment_outer_frame(
                para, outer_table,
        ) || matches!(
            outer_table.layout_page_break(),
            crate::model::table::TablePageBreak::CellBreak
        )
            && crate::renderer::float_placement::empty_host_cellbreak_fragment_repeats_outer_margin(
                self.profile.get().hwp5_stored_pagination_layout()
                    || self.profile.get().hwpx_stored_layout(),
                para,
                outer_table,
            );
        let pre_emitted_host_height = self
            .pre_emitted_host_heights
            .borrow()
            .get(&para_index)
            .copied()
            .unwrap_or(0.0);
        let pre_emitted_host_content_height = self
            .pre_emitted_host_content_heights
            .borrow()
            .get(&para_index)
            .copied()
            .unwrap_or(pre_emitted_host_height);
        let host_line_spacing =
            crate::renderer::float_placement::block_table_caption_host_spacing_px(
                para,
                outer_table,
                self.dpi,
            );

        self.layout_partial_table_resolved(
            tree,
            col_node,
            outer_table.as_ref(),
            PartialTableHostContext {
                paragraphs,
                para_index,
                control_index,
                repeat_fragment_outer_margin,
                pre_emitted_host_height,
                pre_emitted_host_content_height,
                host_line_spacing,
                resolved_table_top,
                resolved_table_left: None,
                predecessor_flow_bottom,
                end_row_owns_stored_frame,
                computed_fragment_frame,
            },
            section_index,
            styles,
            outline_numbering_id,
            col_area,
            y_start,
            bin_data_content,
            start_row,
            end_row,
            is_continuation,
            start_cut,
            end_cut,
            is_block_split,
            start_cut_is_block,
            row_cursor_is_nested,
            end_row_height_override,
            start_row_height_override,
            straddle_row_relief,
            straddle_page_bands,
            host_margin_left,
            host_margin_right,
            measured_table,
            enclosing_cell_ctx,
            clamp_header_negative_para_offset,
            probe,
        )
    }

    /// 이미 원본 표와 host 문맥이 해석된 부분 표 렌더 구현.
    ///
    /// 재귀 child cursor는 이 경로를 직접 호출해 문서 소유 `&Table`의 안정 주소를
    /// 유지한다. 그러면 `cell_units_cache`와 `table_nested_text_flag_cache`가 페이지마다
    /// 생성·폐기되는 clone의 재사용 주소를 잘못 적중하지 않는다.
    #[allow(clippy::too_many_arguments)]
    fn layout_partial_table_resolved(
        &self,
        tree: &mut PageLayoutContext,
        col_node: &mut RenderNode,
        outer_table: &crate::model::table::Table,
        host: PartialTableHostContext<'_>,
        section_index: usize,
        styles: &ResolvedStyleSet,
        outline_numbering_id: u16,
        col_area: &LayoutRect,
        y_start: f64,
        bin_data_content: &[BinDataContent],
        start_row: usize,
        end_row: usize,
        is_continuation: bool,
        start_cut: &[usize],
        end_cut: &[usize],
        is_block_split: bool,
        // [#6935] 시작 컷의 인덱스 공간 — 끝 컷과 다를 수 있다.
        start_cut_is_block: bool,
        row_cursor_is_nested: bool,
        end_row_height_override: Option<f64>,
        start_row_height_override: Option<f64>,
        straddle_row_relief: &[(usize, f64)],
        straddle_page_bands: &[crate::renderer::pagination::StraddleCellCarry],
        host_margin_left: f64,
        host_margin_right: f64,
        measured_table: Option<&MeasuredTable>,
        enclosing_cell_ctx: Option<&CellContext>,
        clamp_header_negative_para_offset: bool,
        probe: Option<&PartialTableCellProbe>,
    ) -> f64 {
        let PartialTableHostContext {
            paragraphs,
            para_index,
            control_index,
            repeat_fragment_outer_margin,
            pre_emitted_host_height,
            pre_emitted_host_content_height,
            host_line_spacing,
            resolved_table_top,
            resolved_table_left,
            predecessor_flow_bottom,
            end_row_owns_stored_frame,
            computed_fragment_frame,
        } = host;
        let _host_scope = self.reflow_block_host_scope(
            enclosing_cell_ctx.is_none(),
            col_area.x + host_margin_left,
            y_start,
        );

        // [Issue #4326] 쪽 나누기는 투명한 1×1 감싸기 표 안의 중첩 표 행을 의도적으로 사용할 수 있다.
        // 측정 경로는 감싸기 해제 규칙 도입 때부터 이 유효 표를 사용했지만, `PartialTable`은
        // 바깥 개체만으로 원본을 식별했다. `start_row`/`end_row`가 바깥 표의 행인지
        // 해제된 중첩 표의 행인지 여기서 `end_row <= outer_table.row_count`로 다시 추정했다.
        // 이 추정은 중첩 표의 실제 단일 행 조각(`end_row == 1`)을 바깥 감싸기 표의 행 0과 구분하지 못했다.
        // #4326의 `margin_bottom` 스윕에서는 40개 중 24개 값에서 표 조각이 중복 출력되고 본문을 넘쳤다.
        // 이제 `row_cursor_is_nested`가 쪽 나누기의 좌표계 판정을 데이터로 전달하므로
        // 두 번째 추정 없이 해당 경로로 직접 보낸다.
        //
        // Native HWP5의 RowBreak 감싸기 표는 부분 커서가 자신의 바깥 행을 가리킬 때만
        // 물리 클립과 프레임을 소유한다(#1921 16쪽, #3637, HWP 2020 7쪽).
        // `row_cursor_is_nested == false`일 때 이 경로를 그대로 유지한다.
        let table = if row_cursor_is_nested {
            transparent_nested_table(outer_table, styles)
        } else {
            outer_table
        };
        let _rows = self.table_rows_scope(table);

        let external_frame = (!row_cursor_is_nested && !is_block_split && !start_cut_is_block)
            .then(|| self.reflow_unrestricted_fragment_frame(table, start_cut, end_cut, styles))
            .flatten();
        let parent_owned = external_frame.is_none_or(|frame| frame.parent_owned);
        let repeat_fragment_outer_margin = repeat_fragment_outer_margin && parent_owned;

        // 컷과 원본 물리 상자를 같은 확인 결과로 소비한다. 첫 조각의 남은 빈 띠와
        // 뒤 조각의 글줄 끝·패딩을 서로 다른 높이 추측으로 바꾸지 않는다.
        let stored_nested_text_frame = self.stored_nested_text_frame_for_cut(
            table,
            start_cut,
            end_cut,
            start_cut_is_block,
            is_block_split,
        );
        let end_row_height_override = stored_nested_text_frame
            .filter(|_| !is_continuation)
            .map(|frame| hwpunit_to_px(frame.body_height_hu, self.dpi))
            .or(end_row_height_override);
        let start_row_height_override = stored_nested_text_frame
            .filter(|_| is_continuation)
            .map(|frame| hwpunit_to_px(frame.body_height_hu, self.dpi))
            .or(start_row_height_override);
        let resolved_table_top = resolved_table_top.or_else(|| {
            stored_nested_text_frame
                .map(|_| y_start + hwpunit_to_px(i32::from(table.outer_margin_top), self.dpi))
        });

        if table.cells.is_empty() {
            return y_start;
        }

        // PageItem에는 내용 소유를 나타내는 연속 소스 컷을 보존한다. 예약 경로와
        // 동일한 물리 시작점을 사용해 앞 저장 프레임의 빈 꼬리를 다시 그리지 않는다.
        // 블록 컷은 행 컷과 슬롯 공간이 다르므로 이 행별 변환의 대상이 아니다.
        let physical_start_cut = if start_cut_is_block {
            start_cut.to_vec()
        } else {
            self.skip_leading_free_spacers_in_row_cut(table, start_row, start_cut, styles)
        };
        let start_cut = physical_start_cut.as_slice();

        // [#3820 단계120] 원본 HWP5의 빈 호스트 1×1 RowBreak 표는 common.height에
        // 첫 조각의 물리 높이를 저장하고, 다음 쪽의 셀 LINE_SEG 사다리를 0에서
        // 재시작할 수 있다. 이 배치 근거를 쪽 나누기와 구분한다. 내용 소유는
        // PageItem 컷과 논리 소비 높이를 기준으로 유지한다.
        let stored_reset_paint_geometry =
            if enclosing_cell_ctx.is_none() && std::ptr::eq(table, outer_table) {
                paragraphs.get(para_index).and_then(|host_para| {
                    native_hwp5_stored_reset_fragment_paint_geometry(
                        self.profile.get().hwp5_stored_pagination_layout(),
                        host_para,
                        table,
                        is_continuation,
                        start_cut,
                        end_cut,
                    )
                })
            } else {
                None
            };

        // 분할 표 첫 부분: 문단 기준 양수 vert_offset 적용.
        // [Task #712] HwpUnit=u32 이라 `vertical_offset > 0` 는 음수 비트표현
        // (예: -1796 HU = 0xFFFFF8FC = 4294965500u32) 도 양수로 통과시켜
        // 후속 `as i32` 캐스트에서 음수가 적용 → 표가 위로 점프, 직전 인라인
        // 표 영역 침범. 비-Partial 경로(`table_layout.rs:1069+`)는 동일 분기에
        // `raw_y.max(y_start)` 클램프가 있어 음수 무력화. Partial 경로에는
        // 클램프가 없으므로 게이트를 signed 비교로 정정해 동등 효과.
        let vert_off_signed = table.common.vertical_offset as i32;
        // [#6143] 문단 기준 오프셋이 쪽 경계에서 이미 소진된 조각.
        //
        // 오프셋의 기준점은 **앵커 문단이 놓인 자리**다. 앵커가 이 쪽에 아무것도
        // 내지 않았는데(형제 노드 0 · host 선방출 0) 표 조각이 본문 최상단에서
        // 시작한다면, 그 기준점은 이 쪽에 없다 — 앵커는 앞 쪽에 있고 오프셋은
        // 거기서 이미 쓰였다. 그대로 다시 더하면 쪽 상단에 오프셋만큼 빈 띠가
        // 생기고, 그만큼 조각이 짧아져 표가 한 쪽 더 갈라진다(156555538 9쪽:
        // 저장 사다리는 앵커 vpos=32514 + off=41592 = 74106HU(988.1px)로 표
        // 상단을 앞 쪽 바닥에 두는데, 한 행도 안 들어가 표는 다음 쪽으로 넘어간다.
        // 한글은 그 쪽 상단에 붙여 그리고 17쪽으로 끝내는데 rhwp 는 630.1px 에서
        // 시작해 18쪽이 된다).
        //
        // 게이트는 좁다 — 코퍼스 140문서 34개 조각 중 발화 0건이고, 첫 조각 &
        // 양수 오프셋 5건은 모두 형제가 있고(쪽 중간) 오프셋도 1.7~17.6px 인
        // 통상적인 미세 이동이라 그대로 남는다.
        let para_offset_consumed_by_page_break = col_node.children.is_empty()
            && start_cut.is_empty()
            && pre_emitted_host_height <= 0.0
            && (y_start - col_area.y).abs() <= 0.5
            && host.paragraphs.get(host.para_index).is_some_and(|anchor| {
                crate::renderer::float_placement::para_offset_consumed_by_page_break(
                    anchor,
                    table,
                    col_area.height,
                    self.dpi,
                )
            });
        let effective_vertical_offset = if !is_continuation
            && !para_offset_consumed_by_page_break
            && !table.common.treat_as_char
            && matches!(
                table.common.vert_rel_to,
                crate::model::shape::VertRelTo::Para
            )
            && vert_off_signed > 0
        {
            // [#2015] host 텍스트가 pre-emit 된 경우, 진입 y_start 는 이미
            // para_start+host_h(host 텍스트 끝) 흐름 위치다. vert_offset 은 para_start 기준
            // 오프셋이므로 그대로 더하면 host_h 만큼 이중계상되어 표가 아래로 밀린다
            // (부동 RowBreak 표 91.2px 오버플로우). 표의 참 상단 = para_start+vert_off =
            // y_start+(vert_off−host_h). typeset 예산도 동일 감액을 적용한다.
            // host pre-emit 이 아니면 host_h=0 → 종전과 동일(회귀 없음).
            //
            // [#7418] 바닥은 host 글의 **내용** 끝이다 — 표는 host 마지막 줄의 줄간격 띠 안까지
            // 올라온다(표 위끝 = 문단 상단 + max(오프셋, host 내용 높이)). 70833 pi=83: host 줄
            // 20 + 줄간격 12, 오프셋 23.8 → 표는 host 끝(32)이 아니라 23.8 에 선다(한/글 정본).
            hwpunit_to_px(vert_off_signed, self.dpi)
                .max(pre_emitted_host_content_height.min(pre_emitted_host_height))
                - pre_emitted_host_height
        } else {
            0.0
        };
        // [#2287 후속/1.hwpx p28] 같은 단의 직전 흐름 표와의 미세 겹침 방지
        // 안전망: 자리차지 표의 v_off/outer 흐름 미가산(#2097 반증 기록 축 —
        // 전면 가산은 82802 악화)으로 후속 TopAndBottom 표 조각의 typeset
        // 좌표가 직전 표 렌더 끝보다 소폭(6.4px) 이르게 잡히면 괘선이 겹쳐
        // 렌더된다. 흐름 표(vert=문단·비 TAC) 한정으로 직전 표 렌더 하단
        // 아래로 push-down — 겹침이 없으면 no-op.
        let is_para_flow_table = !table.common.treat_as_char
            && matches!(
                table.common.text_wrap,
                crate::model::shape::TextWrap::TopAndBottom
            )
            && matches!(
                table.common.vert_rel_to,
                crate::model::shape::VertRelTo::Para
            );
        let reclaim_previous_host_margin = if !is_continuation && start_cut.is_empty() {
            paragraphs.get(para_index).and_then(|host| {
                native_multirow_internal_reset_rowbreak_anchor_advance_hu(
                    self.profile.get().hwp5_stored_pagination_layout(),
                    host,
                    table,
                    paragraphs.get(para_index + 1),
                )
                .map(|advance| hwpunit_to_px(advance, self.dpi))
            })
        } else {
            None
        };
        // 표 조각의 바깥 상자는 현재 행의 저장/재조판 여부와 독립적으로
        // 문단을 따라가는 overlay의 물리 프레임에 속한다. 예산과 같은 계약이다.
        let recursive_overlay_frame =
            crate::renderer::float_placement::paragraph_following_overlay_rowbreak_frame(table);
        // [#8105] 쪽 위에서 시작하는 첫 조각이 문단 기준 양수 오프셋을 그대로 쓰면, 표 위끝은 문단
        // 윗변 + 오프셋 + 바깥 위 여백이다. 예산은 첫 조각 host_before 로 그 여백을 이미 예약한다
        // (`host_spacing.rs` 자리차지 표 before = outer_top). 표 여럿을 담은 빈 앵커(1342000 48쪽
        // 문단 1.3 ci=0: 정본 146 = 본문 위 132.3 + 752HU + 283HU, 1480000-201900698 11쪽)는 아래
        // 형상 규칙들이 열지 않는다. 칸 단위로 나누는(CellBreak) 표는 이 원점에 여백을 넣지 않는다
        // (1480000-201900698 156쪽 정본 표 위 135.5 = 여백 없는 원점).
        let page_top_offset_first_fragment_outer_top = !is_continuation
            && start_cut.is_empty()
            && is_para_flow_table
            && matches!(
                table.layout_page_break(),
                crate::model::table::TablePageBreak::RowBreak
            )
            && effective_vertical_offset > 0.0
            && pre_emitted_host_height <= 0.0
            && resolved_table_top.is_none()
            && enclosing_cell_ctx.is_none()
            && col_node.children.is_empty()
            && (y_start - col_area.y).abs() <= 0.5
            && paragraphs
                .get(para_index)
                .is_some_and(|host| !super::para_has_visible_text(host));

        // 아래 흐름 갈래가 이 조각의 바깥 위 여백을 이미 열었는가. 같은 여백을 다시 여는
        // 조각 형상 규칙(single_cell_page_fragment 등)이 한 번 더 더하지 않게 한다.
        let mut flow_branch_opened_outer_top = false;
        let y_start = if let Some(top) = resolved_table_top {
            top
        } else if recursive_overlay_frame {
            y_start
                + effective_vertical_offset
                + hwpunit_to_px(table.outer_margin_top as i32, self.dpi)
        } else if is_para_flow_table {
            let prev_table_end = col_node
                .children
                .iter()
                .filter_map(|child| {
                    let RenderNodeType::Table(meta) = &child.node_type else {
                        return None;
                    };
                    let repeated_previous_bottom = if repeat_fragment_outer_margin {
                        meta.para_index
                            .zip(meta.control_index)
                            .and_then(|(pi, ci)| paragraphs.get(pi)?.controls.get(ci))
                            .and_then(|control| match control {
                                Control::Table(previous) => Some(hwpunit_to_px(
                                    previous.outer_margin_bottom as i32,
                                    self.dpi,
                                )),
                                _ => None,
                            })
                            .unwrap_or(0.0)
                    } else {
                        0.0
                    };
                    Some(child.bbox.y + child.bbox.height + repeated_previous_bottom)
                })
                .fold(f64::NEG_INFINITY, f64::max)
                .max(predecessor_flow_bottom.unwrap_or(f64::NEG_INFINITY));
            let reclaims_previous_host_margin = reclaim_previous_host_margin.is_some_and(|max| {
                prev_table_end.is_finite()
                    && y_start > prev_table_end
                    && y_start - prev_table_end <= max + 0.5
            });
            if reclaims_previous_host_margin {
                prev_table_end
            } else if repeat_fragment_outer_margin {
                flow_branch_opened_outer_top = true;
                // 엄격한 Native HWP 조건에 해당하는 형상은 그린 앞 조각과 그 하단 여백을 흐름 기준으로 삼고,
                // 현재 조각의 상단 여백을 연다. 양수 개체 오프셋은 첫 조각에만 적용한다.
                // 이 순서로 2쪽의 965HU 간격(앞 하단 283 + 현재 상단 283 + 오프셋 399)을 복원하고,
                // 3쪽 이어받기 상단에는 283HU만 반복한다.
                let flow_base = if prev_table_end.is_finite() {
                    y_start.max(prev_table_end)
                } else {
                    y_start
                };
                flow_base
                    + hwpunit_to_px(table.outer_margin_top as i32, self.dpi)
                    + effective_vertical_offset
            } else if prev_table_end.is_finite()
                && y_start + effective_vertical_offset < prev_table_end - 0.5
            {
                prev_table_end
            } else {
                y_start + effective_vertical_offset
            }
        } else {
            y_start + effective_vertical_offset
        };
        // [#7095] 본문을 통째로 담은 1×1 RowBreak 표의 조각은 상단 바깥여백을 연다.
        //
        // 한컴 engine 2020 정본(156060125, `pdf/tac_object_host_line_height-2020.pdf`)의
        // 바깥 표 괘선은 2·3·10쪽 모두 **47.15px** 이고, 이는 본문 상단 45.35 +
        // `outer_margin_top` 141HU(1.88px)다. rhwp 는 본문 상단(45.35)에 그대로 그려
        // 조각 전체가 1.9px 위에 있었다. 비분할 경로는 이 여백을
        // `physical_outer_box_paint_inset`(단일 단 + 측정高==선언高) 에서만 열지만,
        // 분할 조각은 그 게이트가 성립하지 않으므로 이 형상에서 따로 연다.
        // 빈 host 저장 되감김 조각은 #3820 Stage 120(`stored_reset_paint_geometry`)이 이미
        // 칠하는 쪽에서 같은 여백을 연다 — 여기서 또 열면 표가 여백만큼 한 번 더 내려간다
        // (정책연구 보고서 168쪽 90.71 vs 정본 86.93).
        // 근거 문서(7062·30269·정책연구 보고서·KTX·hwpctl·issue2004)는 모두 본문 최상위 조각이다.
        // 칸 안에서 다시 조각을 그리는 중첩 1×1 표까지 열면 층마다 여백이 겹친다 — 42065
        // 11·15쪽 점선 위 테두리가 118.27 → 122.03 으로 두 번 내려갔다(정본 120.2). 한 층만
        // 여는 규칙은 근거가 없어 최상위 조각으로 좁히고, 중첩 조각은 종전 좌표를 유지한다.
        let single_cell_page_fragment =
            self.single_cell_rowbreak_page_fragment(table) && enclosing_cell_ctx.is_none();
        let empty_opening_continuation = enclosing_cell_ctx.is_none()
            && is_continuation
            && start_row == 0
            && start_cut.iter().copied().eq([0])
            && paragraphs
                .get(para_index + 1)
                .and_then(|next| {
                    self.saved_picture_row_empty_opening_frame(
                        &paragraphs[para_index],
                        next,
                        table,
                        styles,
                    )
                })
                .is_some_and(|frame| start_row_height_override == Some(frame.continuation_height));
        let empty_opening_first_fragment = enclosing_cell_ctx.is_none()
            && !is_continuation
            && start_row == 0
            && start_cut.is_empty()
            && end_row == 1
            && end_cut.iter().copied().eq([0])
            && paragraphs
                .get(para_index + 1)
                .and_then(|next| {
                    self.saved_picture_row_empty_opening_frame(
                        &paragraphs[para_index],
                        next,
                        table,
                        styles,
                    )
                })
                .is_some_and(|frame| end_row_height_override == Some(frame.opening_height));
        // 빈 호스트와 그림 띠는 서로 다른 조각 소유자다.
        // 그림 띠를 소유한 쪽에서 바깥 프레임을 다시 열고 셀의 기존 안 여백을 적용한다.
        // 예산도 같은 소유자의 컷을 소비한다.
        let parallel_picture_opening_continuation = enclosing_cell_ctx.is_none()
            && is_continuation
            && !start_cut_is_block
            && col_node.children.is_empty()
            && (y_start - col_area.y).abs() <= 0.5
            && start_row_height_override.is_some()
            && self
                .parallel_picture_row_opening_height(table, start_row, &[], start_cut, styles)
                .is_some();
        // 처음과 이어받기 조각은 예산이 이미 예약한 같은 바깥 위 여백을 연다.
        let multirow_reopens_outer_top = enclosing_cell_ctx.is_none()
            && crate::renderer::float_placement::native_multirow_rowbreak_reopens_outer_top(
                self.profile.get().hwp5_stored_pagination_layout(),
                table,
                is_continuation,
                start_cut,
            );
        // 저장된 자리차지 RowBreak 표는 저장 앵커(첫 조각) 또는
        // 다음 쪽 본문 상단(이어지는 조각) 뒤에 상단 바깥여백을 연다.
        // 중첩 표와 쪽 중간에서 이어지는 조각은 별도 흐름 좌표를 쓴다.
        let source_cut_reopens_outer_top = is_continuation
            && enclosing_cell_ctx.is_none()
            && col_node.children.is_empty()
            && (y_start - col_area.y).abs() <= 0.5
            && self.intra_paragraph_rowbreak_reopens_outer_top(
                &paragraphs[para_index],
                table,
                start_row,
                start_cut,
                styles,
            );
        let rowbreak_reopens_outer_top = !repeat_fragment_outer_margin
            && enclosing_cell_ctx.is_none()
            && crate::renderer::float_placement::stored_rowbreak_fragment_opens_outer_top(
                self.profile.get(),
                (self.profile.get().hwpx_stored_layout()
                    || self.profile.get().hwp5_stored_pagination_layout())
                .then(|| paragraphs.get(para_index))
                .flatten(),
                table,
                is_continuation,
                start_row,
                start_cut,
                col_node.children.is_empty() && (y_start - col_area.y).abs() <= 0.5,
            );
        let body_filling_source_frame = enclosing_cell_ctx.is_none()
            && crate::renderer::float_placement::stored_body_filling_rowbreak_frame(
                &paragraphs[para_index],
                table,
                col_area.height,
                self.dpi,
                self.profile.get().hwpx_stored_layout()
                    || self.profile.get().hwp5_stored_pagination_layout(),
                self.profile.get().session_edited(),
            );
        let stored_body_frame_opens_outer_top = (body_filling_source_frame
            || (enclosing_cell_ctx.is_none()
                && paragraphs
                    .get(para_index)
                    .is_some_and(|host| self.stored_hwpx_cut_owns_outer_frame(host, table)))
            || (is_continuation
                && enclosing_cell_ctx.is_none()
                && paragraphs.get(para_index).is_some_and(|host| {
                    self.original_body_closed_table_frame(host, table, col_area.height)
                })))
            && col_node.children.is_empty()
            && (y_start - col_area.y).abs() <= 0.5;
        // 저장 HWP5의 반복 제목행을 가진 다행 RowBreak 표도 첫 저장 앵커와
        // 다음 쪽에서 반복 제목행을 여는 조각마다 바깥 위 여백을 다시 둔다.
        // 제목행 없는 이어지는 표(76076 34쪽)는 본문 상단에 붙는 별도 계약이다.
        let native_repeated_header_reopens_outer_top = self.profile.get().hwp5_stored_pagination_layout()
                && !table.common.treat_as_char
                && matches!(
                    table.layout_page_break(),
                    crate::model::table::TablePageBreak::RowBreak
                )
                && table.row_count > 1
                && table.repeat_header
                // 이 보정은 반복 제목행 바로 뒤에서 표 끝까지 걸친 가운데
                // 정렬 셀의 저장 물리 높이를 두 조각에 나누는 경우에만 필요하다.
                // 일반 83행 교육 표까지 열면 다른 조각이 본문 아래로 밀린다.
                // 제목행 수는 셀마다 다시 세지 않고 한 번만 센다.
                && {
                    let header_rows = table.leading_header_rows().len();
                    header_rows > 0
                        && table.cells.iter().any(|cell| {
                            cell.row as usize == header_rows
                                && cell.row_span > 1
                                && cell.row as usize + cell.row_span as usize
                                    == table.row_count as usize
                                && matches!(
                                    cell.vertical_align,
                                    crate::model::table::VerticalAlign::Center
                                )
                        })
                }
                && table.outer_margin_top > 0
                && enclosing_cell_ctx.is_none()
                && !repeat_fragment_outer_margin
                && ((!is_continuation && start_row == 0 && start_cut.is_empty())
                    || (is_continuation
                        && col_node.children.is_empty()
                        && (y_start - col_area.y).abs() <= 0.5));
        // [#7685] 이어지는 RowBreak 조각은 단 위에서 바깥 위 여백을 다시 연다(조판 예산과
        // 같은 규칙 — `fragment/budget.rs`). 1342000 124쪽 정본 77.44 = 본문 위 75.6 +
        // 141HU, 종전 rhwp 75.6. 아래의 좁은 형상들은 이 규칙의 부분집합이다.
        let generic_continuation_outer_top = is_continuation
            && start_cut.iter().all(|&unit| unit == 0)
            && !table.common.treat_as_char
            && matches!(
                table.layout_page_break(),
                crate::model::table::TablePageBreak::RowBreak
            )
            && enclosing_cell_ctx.is_none()
            && col_node.children.is_empty()
            && (y_start - col_area.y).abs() <= 0.5;
        // [#8105] 문단 기준 오프셋을 앞 쪽에서 소진한 첫 조각도 이 쪽에서 바깥 위 여백을 연다 —
        // 예산(`budget.rs` 첫 조각 host_before)과 같은 원점이다. 한/글 2024 `hwpx_sample2` 6쪽 표
        // 위 괘선 = 본문 위 + 283HU, 156555538 9쪽 = 본문 위 + 140HU(다른 규칙이 이미 여는 형상).
        let consumed_offset_first_fragment_outer_top = !is_continuation
            && para_offset_consumed_by_page_break
            && col_node.children.is_empty()
            && (y_start - col_area.y).abs() <= 0.5;
        let y_start = if (single_cell_page_fragment
            || page_top_offset_first_fragment_outer_top
            || generic_continuation_outer_top
            || consumed_offset_first_fragment_outer_top
            || multirow_reopens_outer_top
            || rowbreak_reopens_outer_top
            || stored_body_frame_opens_outer_top
            || source_cut_reopens_outer_top
            || native_repeated_header_reopens_outer_top
            || empty_opening_continuation
            || parallel_picture_opening_continuation
            || empty_opening_first_fragment)
            && stored_reset_paint_geometry.is_none()
            && resolved_table_top.is_none()
            && !recursive_overlay_frame
            // [#7840] 빈 host 반복 여백 갈래가 이미 연 위 여백을 조각 형상 규칙이 다시 열면
            // 이어받는 조각이 여백만큼 한 번 더 내려간다(148738070 2~5쪽 102.04 vs 정본 98.26).
            && !flow_branch_opened_outer_top
        {
            y_start + hwpunit_to_px(table.outer_margin_top as i32, self.dpi)
        } else {
            y_start
        };

        let col_count = table.col_count as usize;
        let row_count = table.row_count as usize;
        let cell_spacing = hwpunit_to_px(table.cell_spacing as i32, self.dpi);

        // ── 1. 열 폭 계산 + 2. 행 높이 계산 (table_layout 공유 메서드) ──
        let col_widths = self.resolve_column_widths(table, col_count);
        let mut row_heights = self.resolve_row_heights_trusting_declared(
            table,
            col_count,
            row_count,
            measured_table,
            styles,
            table.common.treat_as_char,
            false,
        );
        let owns_block_row = |row: usize| {
            measured_table.is_some_and(|measured| {
                measured
                    .fragment_block_frames
                    .iter()
                    .any(|&(first, end)| first <= row && row < end)
            })
        };
        if let Some(measured) = measured_table {
            for (row, height) in row_heights.iter_mut().enumerate() {
                if owns_block_row(row) {
                    *height = measured.row_heights[row];
                }
            }
        }
        // [Task #1748] 컷 걸침 rowspan 셀의 이전 프래그먼트 소비 높이 재계산용 —
        // 2b 컷 오버라이드 이전의 원본 행 높이 (프래그먼트 무관 값).
        let resolved_row_heights = row_heights.clone();

        // ── 2b. 행 높이 오버라이드 (Task #993: 컷 기반) ──
        // 렌더 대상 모든 행의 높이를 페이지네이터와 동일한 컷 측정
        // (row_cut_content_height)으로 정정한다. 페이지네이터(typeset)와 렌더러가
        // 단일 측정 공간(advance_row_cut/cell_units)을 공유해야 분할 표가
        // 페이지를 넘지 않는다. 분할 행은 start_cut/end_cut 범위, 그 외 행은
        // 전체 콘텐츠. rowspan 연속 행(컷 0)은 resolve_row_heights 결과 유지.
        {
            let split_last_row = end_row.saturating_sub(1);
            let mut rows_to_set: std::collections::BTreeSet<usize> = (start_row..end_row).collect();
            // 연속분 머리행 반복 — start_row 이전의 반복 제목행도 렌더된다.
            // [Task #1716] 반복 대상은 표 상단의 연속 제목행 블록만(흩어진 하위 is_header 제외).
            // 페이지네이터(typeset.rs header_overhead)와 동일 leading_header_rows 사용 → 정합.
            if is_continuation && table.repeat_header && start_row > 0 {
                for r in table.leading_header_rows() {
                    if r < start_row {
                        rows_to_set.insert(r);
                    }
                }
            }
            // [Task #1025] page-larger 블록 분할(is_block_split)이면 컷이 rowspan
            // 블록-셀 인덱스 → 블록 범위(rowspan-확장)로 per-row 컷 매핑. 그 외(일반
            // 분할)는 기존 per-row(row_span==1) 경로 유지(rowspan 행은 atomic).
            let start_block = if start_cut_is_block && !start_cut.is_empty() {
                Some(rowspan_block_range(table, start_row))
            } else {
                None
            };
            let end_block = if is_block_split && !end_cut.is_empty() {
                Some(rowspan_block_range(table, split_last_row))
            } else {
                None
            };
            for r in rows_to_set {
                if r >= row_count || owns_block_row(r) {
                    continue;
                }
                let rowspan_touched = table.cells.iter().any(|c| {
                    c.row_span > 1
                        && (c.row as usize) <= r
                        && r < c.row as usize + c.row_span as usize
                });
                if start_cut_is_block || is_block_split {
                    // 시작/끝 컷은 독립적인 공간이다. 행 공간 컷을 블록 전체의
                    // 높이로 해석하면 이미 소비한 rowspan 내용을 다시 예약한다.
                    let in_start = if start_cut_is_block {
                        start_block.is_some_and(|(s, e)| s <= r && r < e)
                    } else {
                        !start_cut.is_empty() && r == start_row
                    };
                    let in_end = if is_block_split {
                        end_block.is_some_and(|(s, e)| s <= r && r < e)
                    } else {
                        !end_cut.is_empty() && r == split_last_row
                    };
                    if !in_start
                        && !in_end
                        && measured_table.is_some()
                        && self.stored_whole_row_padding_frame(
                            table,
                            r,
                            self.row_cut_content_height(table, r, &[], &[], styles),
                            resolved_row_heights[r],
                        )
                    {
                        continue;
                    }
                    // 분할 블록 밖 rowspan 행은 컷 모델 밖 — resolve_row_heights 유지.
                    if rowspan_touched && !in_start && !in_end {
                        continue;
                    }
                    let physical_block = end_block
                        .filter(|(bs, be)| *bs <= r && r < *be)
                        .or_else(|| start_block.filter(|(bs, be)| *bs <= r && r < *be));
                    if let Some(block) = physical_block {
                        let su = if start_block == Some(block) {
                            start_cut
                        } else {
                            &[]
                        };
                        let eu = if end_block == Some(block) {
                            end_cut
                        } else {
                            &[]
                        };
                        if let Some(height) = measured_table.and_then(|_| {
                            self.row_block_cut_physical_height(
                                table,
                                block,
                                (r, resolved_row_heights[r]),
                                su,
                                eu,
                                styles,
                            )
                        }) {
                            row_heights[r] = height;
                            continue;
                        }
                    }
                    // 행 r 의 row_span==1 셀(col 순)별 블록 컷 → per-row 컷 매핑.
                    let mut rcells: Vec<&crate::model::table::Cell> = table
                        .cells
                        .iter()
                        .filter(|c| c.row as usize == r && c.row_span == 1)
                        .collect();
                    rcells.sort_by_key(|c| c.col);
                    // [#2287/PR #2290 P1] 컷 블록 안의 rs=1 셀 없는 걸침-전용 행은
                    // 원본(resolve) 높이가 그대로 남아 rowspan 셀 bbox 가 컷과
                    // 무관하게 원본 크기(교육부 47×9 r3=2107px → 셀 2354.6px)로
                    // 유지됐다 — valign 이 콘텐츠를 셀 중앙(페이지 밖 y≈1259)으로
                    // 밀어 tail overflow 로 관측(리뷰 p26/p30). 컷 블록의 행높이는
                    // 아래 블록-합 보정이 권위이므로 여기서는 0 으로 둔다.
                    if rcells.is_empty() {
                        row_heights[r] = 0.0;
                        continue;
                    }
                    let mut per_start: Vec<usize> = Vec::with_capacity(rcells.len());
                    let mut per_end: Vec<usize> = Vec::with_capacity(rcells.len());
                    let mut has_visible_range = false;
                    let mut has_row_cut = false;
                    for c in &rcells {
                        let units = self.cell_units(c, table, styles);
                        let (su, eu) = cell_cut_window(
                            table,
                            c,
                            start_cut_is_block,
                            is_block_split,
                            in_start,
                            start_block,
                            in_end,
                            end_block,
                            start_cut,
                            end_cut,
                            Some(units.len()),
                            start_row,
                            end_row.saturating_sub(1),
                        );
                        if eu > su {
                            has_visible_range = true;
                        }
                        if su > 0 || eu < units.len() {
                            has_row_cut = true;
                        }
                        per_start.push(su);
                        per_end.push(eu);
                    }
                    // [#2287/PR #2290 P1] 컷 블록(in_start/in_end) 안 행은 rs=1
                    // 셀 컷이 "전체 소비"(su=0, eu=len)여도 whole-row 경로의 선언
                    // 셀높이 max 를 타면 안 된다 — 블록 분할 중 행높이는 콘텐츠
                    // 기반이어야 하고, rowspan 가시분은 아래 블록-합 보정이 채운다
                    // (교육부 r3: rs=1 셀 2개 전체 소비 17.1px 인데 선언 max 로
                    // 2107.1 유지 → 셀 bbox 2354.6 → valign 이 페이지 밖으로).
                    let h = if !has_visible_range {
                        0.0
                    } else if has_row_cut || in_start || in_end {
                        self.row_cut_content_height(table, r, &per_start, &per_end, styles)
                    } else {
                        self.row_cut_content_height(table, r, &[], &[], styles)
                    };
                    if h > 0.0 {
                        row_heights[r] = h;
                    } else if has_row_cut {
                        // 컷 범위가 이 행에서 비가시(전부 다른 조각 소속)면 0.
                        row_heights[r] = 0.0;
                    }
                }
            }
            // [#2287/PR #2290 P1] 블록-합 보정: 컷 블록에 걸친 rowspan 셀의 컷
            // 가시 높이(su..eu 유닛 합 + pad)가 rs=1 기반 행높이 합보다 크면
            // 블록 마지막 행에 차액을 가산한다 — rowspan 셀 bbox 가 컷 가시
            // 높이와 정합해야 클립/valign 이 컷 의미대로 동작한다 (typeset 의
            // consumed_height 와 동일 좌표계).
            if start_cut_is_block || is_block_split {
                let mut blocks: Vec<(usize, usize)> = Vec::new();
                for b in [start_block, end_block].into_iter().flatten() {
                    if !blocks.contains(&b) {
                        blocks.push(b);
                    }
                }
                for (bs, be) in blocks {
                    if measured_table
                        .is_some_and(|measured| measured.fragment_block_frames.contains(&(bs, be)))
                    {
                        continue;
                    }
                    let mut target = 0.0f64;
                    for c in table.cells.iter().filter(|c| {
                        c.row_span > 1 && (c.row as usize) >= bs && (c.row as usize) < be
                    }) {
                        let su = if start_block == Some((bs, be)) {
                            block_cut_index(table, bs, be, c)
                                .and_then(|i| start_cut.get(i).copied())
                                .unwrap_or(0)
                        } else {
                            0
                        };
                        let eu = if end_block == Some((bs, be)) {
                            block_cut_index(table, bs, be, c)
                                .and_then(|i| end_cut.get(i).copied())
                                .unwrap_or(usize::MAX)
                        } else {
                            usize::MAX
                        };
                        target = target.max(self.cell_cut_visible_height(c, table, styles, su, eu));
                    }
                    if target <= 0.0 {
                        continue;
                    }
                    // [#7336] 차액은 **이 조각이 실제로 그리는** 마지막 행에 싣는다.
                    //
                    // 조각이 rowspan 블록 안쪽에서 끝나면(`end_row < be`) 블록의 마지막
                    // 행은 이 조각의 `render_rows` 에 없다. 거기에 차액을 더하면 조각
                    // 상자 높이(`partial_table_height`)에도, 걸침 셀 bbox 에도 반영되지
                    // 않아 컷이 소비한 내용이 통째로 clip 된다.
                    //
                    // `samples/issue7336/nested_table_fragment_cut.hwp` 4쪽 실측: 예산
                    // `consumed=603.6`(컷 인덱스 17 = 걸침 셀의 10×2 중첩 표까지)인데
                    // 그린 상자는 `tbl_h=81.8` 이고, 중첩 표가 칸 하단(486.2) 밖 y=535.3
                    // 에 놓여 clip 으로 전멸했다. 5쪽 이어짐 조각은 컷 17 **다음**부터
                    // 재개하므로 그 사이 9행이 어느 쪽에도 남지 않았다.
                    //
                    // 비교 기준(`cur`)도 같은 범위로 맞춘다 — 그리지 않는 행의 선언
                    // 높이가 섞이면 차액이 과소 계산된다.
                    let be_painted = be.min(row_count).min(end_row.max(bs + 1));
                    let cur: f64 = (bs..be_painted)
                        .map(|r| row_heights.get(r).copied().unwrap_or(0.0))
                        .sum();
                    if target > cur + 0.5 {
                        // 컷 범위 끝에 미수용 일반 행이 남을 수 있다. 그 0높이
                        // 행에 부족분을 싣으면 원문 내용 없는 빈 행이 새로 그려진다.
                        // 실제 물리 행이 있으면 그 마지막 행이 병합 슬롯을 소유한다.
                        let last = (bs..be_painted)
                            .rfind(|&row| row_heights[row] > 0.0)
                            .or_else(|| (bs..be_painted).next_back());
                        if let Some(last) = last {
                            row_heights[last] += target - cur;
                        }
                    }
                }
            }

            if start_cut_is_block || is_block_split {
                // [#7531] 쪽을 넘어온 걸침 칸의 끝 행은 앞 쪽 빈 띠만큼 덜어 낸다. 값은
                // 조판 scan 이 같은 helper(`straddle_page_band_relief`)로 쟀던 그대로다.
                // 끝 컷으로 잘린 행은 컷 높이가 이미 이 조각의 물리 높이다. 덜기는 온전한 행에만 쓴다
                // (scan 도 잘린 행은 컷 내용 높이로 잰다).
                for &(row, amount) in straddle_row_relief {
                    let cut_end_row = !end_cut.is_empty() && row + 1 == end_row;
                    let cut_start_row = !start_cut.is_empty() && row == start_row;
                    if (start_row..end_row).contains(&row)
                        && !cut_end_row
                        && !cut_start_row
                        && !owns_block_row(row)
                    {
                        if let Some(height) = row_heights.get_mut(row) {
                            *height = (*height - amount).max(0.0);
                        }
                    }
                }

                // 빈 꼬리 밴드도 이 조각의 실제 행 높이다. 걸침 셀 요구와 비교하기
                // 전에 적용해 typeset의 누적 예약과 같은 높이 공간을 사용한다.
                if let Some(limit) = start_row_height_override {
                    if start_row < row_count && !owns_block_row(start_row) {
                        // 이어받은 물리 높이는 남은 행의 최소 점유다. 스캐너의
                        // RowScanQuery::whole_row_height와 같이 현재 컷의 내용과
                        // 유효 여백을 보존한다. 이 조각을 다시 자른 경우에는 아래
                        // end_row_height_override가 수용한 컷의 정확한 높이를 소유한다.
                        row_heights[start_row] = row_heights[start_row].max(limit.max(0.0));
                    }
                }

                // [#6981] per-row 경로의 **이어받는 걸침 셀** 보정.
                //
                // 위 블록-합 보정은 `is_block_split` 조각만 돈다. 행별 경로에서 조각 경계가
                // rowspan 블록 안쪽에 떨어지면, 이어받는 조각의 걸친 셀은 `#1748` 의
                // 높이-컷으로 **남은 유닛 전부**를 받는데 그 셀이 덮는 행들의 높이는 같은
                // 행의 `row_span==1` 셀만 보고 정해진다. 어긋난 만큼 clip 이 글자를 지운다.
                //
                // 실측(`samples/task2287/1342000_edu_curriculum_map.hwp` 377쪽): 셀
                // `(62,8) row_span=2` 는 선언 51.76px 에 문단 3개(저장 사다리 vpos
                // 0·1300·2600 HU → 내용 바닥 48.00px, 여백 1.88×2 를 더하면 51.76 — 온전하면
                // 딱 맞는다). 그리드 행 62(30.65px)/63(21.11px) 사이에 쪽이 갈리면 앞 조각이
                // 문단 1개를, 이어받는 조각이 문단 2개(32.55px)를 21.11px 행에 받아
                // `선언문 작성` 이 11.4px 밖으로 나가 사라졌다.
                //
                // 요구 높이는 조판과 **같은 출처**(`straddle_continuation_demand`)에서 낸다.
                if !start_cut_is_block && !is_block_split {
                    for r in start_row..end_row.min(row_count) {
                        let Some(need) = self.straddle_continuation_demand(
                            table,
                            r,
                            start_row,
                            start_cut,
                            start_cut_is_block,
                            start_row_height_override,
                            &resolved_row_heights,
                            straddle_page_bands,
                            styles,
                            (end_row, end_cut.is_empty()),
                        ) else {
                            continue;
                        };
                        let need = need.required();
                        let have: f64 = (start_row..=r)
                            .map(|rr| row_heights.get(rr).copied().unwrap_or(0.0))
                            .sum::<f64>()
                            + cell_spacing * (r - start_row) as f64;
                        if std::env::var("RHWP_DIAG_6981").is_ok() {
                            eprintln!(
                            "D6981R r={r} start_row={start_row} end_row={end_row} need={need:.1} have={have:.1}"
                        );
                        }
                        if need > have + 0.5 {
                            row_heights[r] += need - have;
                        }
                    }
                }
            } else {
                row_heights = self.ordinary_rowbreak_fragment_heights(
                    table,
                    &resolved_row_heights,
                    start_row,
                    end_row,
                    start_cut,
                    end_cut,
                    is_continuation,
                    start_row_height_override,
                    end_row_height_override,
                    straddle_row_relief,
                    straddle_page_bands,
                    measured_table.is_some(),
                    styles,
                );
            }
        }

        // [#3820 Stage 76] RowBreak 표의 rowspan-연속 밴드에서 실제 셀 내용은
        // 현재 쪽에 모두 들어가지만, 원본 선언 행 높이만 남은 공간보다 큰 경우가
        // 있다. 페이지네이터는 다음 조각을 다음 행부터 재개하고 이 조각의 마지막
        // 행만 남은 물리 높이에 맞춰 소비한다. 렌더러도 같은 마지막 행의 **정확한
        // 물리 높이**를 적용해야 p35의 `주요내용`을 보인 뒤 p36을 다음 행에서
        // 시작한다. auto layout이 내용 한 줄(23px)만으로 행을 축소한 경우에는
        // `min`이 남은 75px band를 다시 버리므로, 여기서 limit은 상한이 아니라
        // fragment-local row height다.
        if let Some(limit) = end_row_height_override {
            if let Some(last) = end_row
                .checked_sub(1)
                .filter(|r| *r < row_count && !owns_block_row(*r))
            {
                row_heights[last] = limit.max(0.0);
            }
        }
        // 반복 제목행 바로 뒤의 가운데 정렬 rowspan 셀이 두 물리 쪽을 소유하면
        // 컷 유닛 높이의 합보다 저장 셀 높이가 클 수 있다. 첫 조각 상자는 쪽
        // 하단까지, 마지막 조각은 선언 셀 높이의 잔여분까지 연다. 그래야 두
        // 조각에서 valign 중심과 테두리가 같은 저장 좌표계를 사용한다.
        let mut center_saved_spanning_cell = None;
        let header_count = table.leading_header_rows().len();
        let centered_span = (self.profile.get().hwp5_stored_pagination_layout()
            && !table.common.treat_as_char
            && table.repeat_header
            && header_count > 0
            && matches!(
                table.layout_page_break(),
                crate::model::table::TablePageBreak::RowBreak
            )
            && matches!(
                table.common.text_wrap,
                crate::model::shape::TextWrap::TopAndBottom
            )
            && enclosing_cell_ctx.is_none())
        .then(|| {
            table.cells.iter().enumerate().find(|(_, cell)| {
                cell.row as usize == header_count
                    && cell.row_span > 1
                    && cell.row as usize + cell.row_span as usize == row_count
                    && matches!(
                        cell.vertical_align,
                        crate::model::table::VerticalAlign::Center
                    )
            })
        })
        .flatten();
        if let (Some((cell_idx, cell)), Some(saved_anchor)) = (
            centered_span,
            paragraphs
                .get(para_index)
                .and_then(|para| para.line_segs.first())
                .filter(|seg| seg.vertical_pos > 0),
        ) {
            let two_fragment_span = (!is_continuation
                && start_row == 0
                && end_row > header_count
                && end_row < row_count
                && is_block_split
                && rowspan_block_range(table, end_row - 1) == (header_count, row_count)
                && !end_cut.is_empty())
                || (is_continuation
                    && start_row == header_count
                    && end_row == row_count
                    && start_cut_is_block
                    && rowspan_block_range(table, start_row) == (header_count, row_count)
                    && !start_cut.is_empty()
                    && end_cut.is_empty());
            if two_fragment_span {
                let units = self.cell_units(cell, table, styles);
                let (_, _, pad_top, pad_bottom) = self.resolve_cell_padding(cell, table);
                let declared = hwpunit_to_px(cell.height.min(i32::MAX as u32) as i32, self.dpi);
                let content =
                    units.iter().map(|unit| unit.height).sum::<f64>() + pad_top + pad_bottom;
                let first_table_y = col_area.y
                    + hwpunit_to_px(saved_anchor.vertical_pos, self.dpi)
                    + hwpunit_to_px(table.outer_margin_top as i32, self.dpi);
                let header_height = resolved_row_heights[..header_count].iter().sum::<f64>();
                let first_cell_y = first_table_y + header_height;
                let first_bottom =
                    crate::renderer::float_placement::single_cell_page_fragment_bottom(
                        table,
                        col_area.y + col_area.height,
                        self.dpi,
                    );
                let first_height = first_bottom - first_cell_y;
                let final_height = declared - first_height;
                let current = row_heights[header_count..end_row].iter().sum::<f64>();
                let target = if is_continuation {
                    final_height
                } else {
                    first_height
                };
                let extra = target - current;
                if declared > content + 8.0
                    && first_height > 0.0
                    && final_height > 0.0
                    && extra > 0.5
                    && extra <= declared - content + 1.0
                    && (is_continuation || (first_table_y - y_start).abs() < 1.0)
                {
                    row_heights[end_row - 1] += extra;
                    center_saved_spanning_cell = Some(cell_idx);
                }
            }
        }
        // 저장 셀 높이가 쪽 조각 상자를 포함하면 시작 위치와 관계없이 프레임이 상자를 소유한다.
        // 저장 높이가 작은 가운데 정렬 셀은 내용 높이를 유지해 정렬 위치가 바뀌지 않게 한다.
        // [#7095] 끝 조각 상자는 페이지네이터가 `max(내용, 저장 칸 높이 − 앞 조각 상자 합)` 으로
        // 정해 `end_row_height_override` 로 넘긴다(7062 10쪽: 정본 상자 874.04). 그 상자도 칸
        // `valign` 을 조각 내용으로 적용한다 — 정본 10쪽 첫 줄은 상자 위에서 9.8px 아래다.
        // [#7063 레인②] 상자를 쪽이 정할 때 **내용이 쓸 높이**(예산이 자른 값)를 따로 든다.
        let mut budget_row_height_0: Option<f64> = None;
        let source_single_cell_row_frames = paragraphs
            .get(para_index)
            .zip(paragraphs.get(para_index + 1))
            .and_then(|(host, next)| {
                self.native_single_cell_source_row_frames(host, next, table, styles)
            });
        let source_single_cell_closing_frame = is_continuation
            && end_cut.is_empty()
            && source_single_cell_row_frames.is_some_and(|frame| {
                start_cut == [frame.opening_end]
                    && end_row_height_override == Some(frame.closing_height)
            });
        // 종료 원점으로 입증된 마지막 저장 행은 컷 이후 내용의 정렬 프레임이다.
        // 페이지네이터가 예약한 같은 물리 높이일 때만 가운데 정렬을 재사용한다.
        let stored_terminal_frame = enclosing_cell_ctx.is_none()
            && is_continuation
            && start_row + 1 == end_row
            && end_row == row_count
            && end_cut.is_empty()
            && start_cut.iter().any(|&cut| cut > 0)
            && !self.profile.get().session_edited()
            && self.profile.get().hwpx_stored_layout()
            && paragraphs
                .get(para_index + 1)
                .and_then(|next| {
                    crate::renderer::float_placement::stored_rowbreak_closing_frame_height(
                        &paragraphs[para_index],
                        next,
                        table,
                        self.dpi,
                    )
                })
                .is_some_and(|height| {
                    end_row_height_override.is_some_and(|limit| (limit - height).abs() < 0.01)
                });
        let mut center_pinned_single_cell = stored_terminal_frame
            || source_single_cell_closing_frame
            || (single_cell_page_fragment
                && row_count == 1
                && is_continuation
                && end_cut.is_empty()
                && end_row_height_override.is_some());
        let owns_declared_opening_frame = end_row_height_override
            == Some(hwpunit_to_px(table.common.height as i32, self.dpi))
            && row_count == 1
            && !is_continuation
            && start_cut.is_empty()
            && end_cut.len() == 1
            && paragraphs.get(para_index + 1).is_some_and(|next| {
                crate::renderer::float_placement::stored_two_frame_successor_origin_hu(table, next)
                    .is_some()
            })
            && table.cells.first().is_some_and(|cell| {
                self.stored_cut_closes_declared_opening_frame(cell, table, styles, end_cut[0])
                    || (paragraphs.get(para_index + 1).is_some_and(|next| {
                        crate::renderer::float_placement::stored_single_cell_closing_frame_height(
                            &paragraphs[para_index],
                            next,
                            table,
                            self.dpi,
                        )
                        .is_some()
                    }) && self
                        .cell_unit_opens_stored_page_frame(cell, table, styles, end_cut[0]))
            });
        // 스캔이 수용한 원본 첫 상자는 같은 컷의 정렬·클립·테두리를 소유한다.
        // 그 뒤 일반 쪽 하단 고정으로 상자를 늘리면 각주 영역까지 다시 침범한다.
        center_pinned_single_cell |= owns_declared_opening_frame;
        if single_cell_page_fragment
            && row_count == 1
            && !owns_declared_opening_frame
            && !(end_row_owns_stored_frame && end_row_height_override.is_some())
            && end_cut.iter().any(|&unit| unit > 0)
        {
            let box_bottom = crate::renderer::float_placement::single_cell_page_fragment_bottom(
                table,
                col_area.y + col_area.height,
                self.dpi,
            );
            let pinned_height = (box_bottom - y_start).max(0.0);
            // 호환성 투영은 떠 있는 그림의 세로 묶음을 독립적인 인라인 개체로 바꿀 수 있다.
            // 그 합성 줄 지오메트리는 저장된 전쪽 프레임이 아니다(issue2004 5쪽: PDF 끝은 1023px이 아닌 약 931px).
            // 1×1 표 모양만으로 프레임 소유를 추정하지 않고 같은 컷의 줄 출처를 소비한다.
            let projected_content = table.cells.first().is_some_and(|cell| {
                self.cell_cut_has_projected_lines(
                    cell,
                    table,
                    styles,
                    start_cut.first().copied().unwrap_or(0),
                    end_cut.first().copied().unwrap_or(0),
                )
            });
            // [#6923] 쪽 **중간**에서 시작하는 비끝 조각도, 칸 내용이 상자 상단에 붙는
            // (`valign=Top`) 형상이면 상자를 쪽이 정한다 — 늘려도 내용이 움직이지 않는다.
            // 148738070 1쪽(감싼 1×1 표, 표 상단 338.4)은 정본 상자 하단이 1021.9 인데
            // rhwp 는 내용 끝(1003.5)에서 끊어 18.4px 짧았다. 위 156645214 반례는
            // `Center` 칸이라 늘리면 내용이 8px 내려가므로 그 갈래는 종전대로 둔다.
            let content_is_top_anchored = table.cells.first().is_some_and(|cell| {
                matches!(cell.vertical_align, crate::model::table::VerticalAlign::Top)
            });
            // [#7095] 한/글은 분할된 칸의 저장 높이를 **조각 상자 높이의 합**으로 적는다
            // (1382000 `pi=95`: 칸 h 325144HU = 4335px ↔ 정본 상자 855+891×3+810 = 4338px,
            // 7062: 700976HU = 9346px ↔ 정본 합 9337px, 차는 PDF 쪽 척도). 저장 높이가 쪽 상자
            // 하나보다도 작은 칸(1382000 `pi=90`: h 282HU)은 상자를 쪽에 고정할 수 없고, 정본도
            // 네 조각 모두 내용에 맞춘다(16~19쪽 상자 아래 977·980·970·897). 그런 칸은 쪽 상자로
            // 늘리지 않는다 — 늘린 상자 안에서 칸 `valign` 을 적용하면 내용이 14~18px 내려간다.
            // `valign=Top` 칸은 저장 높이가 작아도 정본이 상자를 쪽에 둔다(synam-001 `pi=163`
            // h 282HU: 20쪽 내용 끝 1032 ↔ 상자 1054) — 위 #6923 갈래는 그대로 둔다.
            let stored_cell_spans_page_box = table.cells.first().is_some_and(|cell| {
                // 일반 재조판 줄에는 저장된 전쪽 상자가 없다. 위 정렬만으로
                // 스캔의 내용 컷을 쪽 하단까지 다시 늘리지 않는다.
                (content_is_top_anchored && !self.cell_uses_plain_reflow_units(cell, table))
                    || hwpunit_to_px(cell.height.min(i32::MAX as u32) as i32, self.dpi) + 0.5
                        >= pinned_height
            });
            if stored_cell_spans_page_box && !projected_content {
                // 내용 행 높이에는 조각 마지막 줄 뒤 줄간격이 들어 있어 상자보다 클 수 있다
                // (30269 10쪽: 줄 바닥 1010.2 + 줄간격 → 1032.1, 정본 상자 1022.9). 한/글은 그
                // 줄간격을 그리지 않으므로 상자는 줄이는 쪽으로도 쪽이 정한다. 예산이 같은 상자로
                // 잘랐으므로 보이는 줄은 상자 안에 있다.
                // [#7063 레인②] 상자(테두리)만 쪽이 정하고, **내용 높이는 예산이 정한 그대로**
                // 둔다. 둘을 함께 늘리면 칸 안 중첩 표가 더 큰 `inner_height` 를 보고 다시
                // 쪼개져 이미 다음 쪽에 배치된 행을 이 쪽에도 그린다(hwpx_sample2.hwp 8쪽:
                // 9쪽 첫 행 `구 분`·`조회방법` 이 8쪽 1086~1124px 에도 나온다).
                budget_row_height_0 = Some(row_heights[0]);
                row_heights[0] = pinned_height;
                center_pinned_single_cell = true;
            } else if stored_reset_paint_geometry.is_none() {
                // 쪽 중간에서 시작하는 비끝 조각은 늘리지는 않되(위 156645214 반례), 같은 이유로
                // 쪽 상자 아래를 넘기지도 않는다. KTX 25쪽 `pi406` 은 위 바깥 여백을 연 뒤 내용
                // 행 높이(뒤 줄간격 포함)로 끝나 본문 아래를 2.6px 넘었다 — 정본은 그 자리에
                // 괘선을 그리지 않고, 줄 위치는 정본과 같은 쪽 경계에 있다.
                row_heights[0] = row_heights[0].min(pinned_height);
            }
        }

        // 저장 위치 재시작의 첫 조각에서 구성한 컷에는 재시작 직전 줄의 끝 줄간격이 포함된다.
        // 이 값은 논리 흐름 소비량으로 유지하지만, 물리 행·셀 클립과 테두리는 독립적으로 저장된 첫 높이에서 끝난다.
        // 단일 행 조건이므로 함수 반환값에서 차이를 정확하게 복원할 수 있다.
        let mut stored_reset_logical_height_delta = 0.0;
        if let Some(stored_height_hu) =
            stored_reset_paint_geometry.and_then(|geometry| geometry.first_fragment_height_hu)
        {
            if let Some(row_height) = row_heights.first_mut() {
                let stored_height = hwpunit_to_px(stored_height_hu, self.dpi);
                let paint_height = (*row_height).min(stored_height);
                stored_reset_logical_height_delta = (*row_height - paint_height).max(0.0);
                *row_height = paint_height;
            }
        }

        if std::env::var_os("RHWP_DIAG_NESTED_FRAME").is_some() {
            eprintln!("NESTED_FRAME rows={} cols={} range={:?} start={:?} end={:?} block={} start_block={} measured={} resolved={:?} actual={:?} start_override={:?} end_override={:?}", table.row_count, table.col_count, start_row..end_row, start_cut, end_cut, is_block_split, start_cut_is_block, measured_table.is_some(), resolved_row_heights, row_heights, start_row_height_override, end_row_height_override);
        }
        // ── 3. 누적 위치 계산 ──
        let mut col_x = vec![cell_spacing; col_count + 1];
        for i in 0..col_count {
            col_x[i + 1] = col_x[i] + col_widths[i] + cell_spacing;
        }

        // 행별 열 위치 계산 (셀별 독립 너비 지원)
        let row_col_x = match build_row_col_x(
            table,
            &col_widths,
            col_count,
            row_count,
            cell_spacing,
            self.dpi,
            self.render_table_width_scale(table),
        ) {
            Ok(grid) => grid,
            Err(_) => return y_start,
        };

        let declared_table_width = if table.common.width > 0 {
            hwpunit_to_px(table.common.width as i32, self.dpi)
                * self.render_table_width_scale(table)
        } else {
            0.0
        };
        let table_width = super::table_grid_width::resolved_table_width(
            &row_col_x,
            col_x.last().copied().unwrap_or(0.0),
            declared_table_width,
        );

        // ── 표 수평 위치 (table_layout 공유 메서드) ──
        let pw = self.current_paper_width.get();
        let paper_w = if pw > 0.0 { Some(pw) } else { None };
        let table_x = resolved_table_left.unwrap_or_else(|| {
            self.compute_table_x_position(
                table,
                table_width,
                col_area,
                0,
                Alignment::Left,
                host_margin_left,
                host_margin_right,
                None,
                false,
                paper_w,
            )
        });

        // 예약은 source 컷이, 부모의 실제 격자는 parent frame owner가 소유한다.
        // 부모가 없는 이어받기는 가상 행을 유지해 자식 컷만 배치한다.
        let external_reserved_height = external_frame.map(|frame| frame.occupied_height);
        if let Some(frame) = external_frame.filter(|frame| frame.parent_owned) {
            row_heights[0] = frame.parent_height - cell_spacing * 2.0;
        }

        // ── 4. 렌더링할 행 목록 구성 ──
        // is_continuation && repeat_header → start_row 이전의 반복 제목행만 반복.
        // [Task #1716] 반복 대상은 표 상단의 연속 제목행 블록만(흩어진 하위 is_header 제외).
        // 페이지네이터(typeset.rs header_overhead)와 동일 leading_header_rows 사용 → 정합.
        let mut header_rows: Vec<usize> = Vec::new();
        if is_continuation && table.repeat_header && start_row > 0 {
            for r in table.leading_header_rows() {
                if r < start_row && r < row_count {
                    header_rows.push(r);
                }
            }
            header_rows.sort_unstable();
        }
        let mut render_rows: Vec<usize> = Vec::new();
        render_rows.extend_from_slice(&header_rows);
        for r in start_row..end_row.min(row_count) {
            // 블록 컷 스캔은 현재 조각에 남긴 행 사이의 간격만 합산한다.
            // 내용 전부가 앞 조각에 속한 행은 여기서 물리 상자를 갖지 않는다.
            // 예약한 빈 띠는 위의 명시적 높이 보정을 포함해 양수 행 높이를 유지한다.
            if row_heights[r] > 0.0 {
                render_rows.push(r);
            }
        }

        // 렌더링 영역의 행별 y 위치 계산 (0부터 시작)
        let mut render_row_y: Vec<f64> = Vec::new(); // 각 render_rows 항목의 시작 y
        let mut y_accum = cell_spacing;
        for &r in &render_rows {
            render_row_y.push(y_accum);
            y_accum += row_heights[r] + cell_spacing;
        }
        let partial_table_height = y_accum;

        // 엣지 기반 테두리 수집을 위한 그리드 (렌더링 행 기준)
        let render_row_count = render_rows.len();
        let mut h_edges: Vec<Vec<Option<super::border_rendering::BorderEdge>>> =
            vec![vec![None; col_count]; render_row_count + 1];
        let mut v_edges: Vec<Vec<Option<super::border_rendering::BorderEdge>>> =
            vec![vec![None; render_row_count]; col_count + 1];
        // 병합 등으로 편집되어 h_edges/v_edges에 기록되지 않는 span 내부 위치를
        // 투명선 가이드에서 제외하기 위한 커버리지 그리드 (§투명선/셀 편집 정합성).
        let mut h_span_covered: Vec<Vec<bool>> = vec![vec![false; col_count]; render_row_count + 1];
        let mut v_span_covered: Vec<Vec<bool>> = vec![vec![false; render_row_count]; col_count + 1];
        let mut grid_row_y = render_row_y.clone();
        grid_row_y.push(partial_table_height);

        // ── 4b. 캡션 처리 (첫 번째 파트에서만 렌더링) ──
        let is_first_part = start_row == 0 && !is_continuation && start_cut.is_empty();
        let is_last_part = end_row >= row_count && end_cut.is_empty();
        let (caption_height, caption_spacing) = if is_first_part || is_last_part {
            let ch = self.calculate_caption_height(&table.caption, styles);
            let cs = table
                .caption
                .as_ref()
                .map(|c| hwpunit_to_px(c.spacing as i32, self.dpi))
                .unwrap_or(0.0);
            (ch, cs)
        } else {
            (0.0, 0.0)
        };

        let cap_dir = table.caption.as_ref().map(|c| c.direction);
        let is_left_cap = cap_dir == Some(CaptionDirection::Left);
        let is_right_cap = cap_dir == Some(CaptionDirection::Right);
        let is_lr_cap = is_left_cap || is_right_cap;
        let render_top_caption = is_first_part && cap_dir == Some(CaptionDirection::Top);
        let render_bottom_caption = is_last_part && cap_dir == Some(CaptionDirection::Bottom);
        // Left/Right 캡션은 모든 파트에서 렌더링 (표 옆에 배치)
        let render_lr_caption = is_lr_cap;

        // Left 캡션: 표를 오른쪽으로 이동
        let cap_width_px = table
            .caption
            .as_ref()
            .map(|c| hwpunit_to_px(c.width as i32, self.dpi))
            .unwrap_or(0.0);
        let table_x = if is_left_cap {
            table_x + cap_width_px + caption_spacing
        } else {
            table_x
        };

        // 바깥 여백은 조각의 논리 예약량에 이미 포함되어 있다.
        // 첫 조각과 뒤 조각 모두 표·셀·프레임의 그리기 하위 트리에서만 이 여백을 복원한다.
        //
        // [#7063] 가로는 여기서 복원하지 않는다 — 위 `compute_table_x_position` 이
        // `topbottom_float_outer_margin_left_hu` 로 이미 싣는다. `#3820 Stage 120` 의 술어
        // (자리차지 T&B · `HorzRelTo::Column` · `HorzAlign::Left` · 오프셋 0 ·
        // `outer_margin_left > 0`)는 그 일반 규칙의 **부분집합**이라 둘 다 실으면 두 번 든다
        // (p167 pi=1775 좌단이 본문 94.49 에서 98.27 이 아니라 102.04 로 갔다).
        // 세로는 저장 사다리가 세로 outer box 만 증명하므로 그대로 복원한다.

        let table_y = if render_top_caption {
            y_start + caption_height + caption_spacing
        } else {
            y_start
        } + stored_reset_paint_geometry
            .map(|geometry| hwpunit_to_px(geometry.outer_top_hu, self.dpi))
            .unwrap_or(0.0);

        // ── 5. 표 노드 생성 ──
        // 재귀 부분 표는 합성 `(para=0, control=0)`으로 table 데이터를 조회하지만,
        // RenderNode provenance에는 원본 부모 셀 문단과 현재 표 control을 기록한다.
        // TextRun이 없는 빈 셀 hit-test는 Table/TableCell traversal context만 사용하므로
        // 이 metadata까지 실제 IR 경로여야 한다 (#4252).
        let (node_para_index, node_control_index) = enclosing_cell_ctx
            .and_then(|context| {
                let table_entry = context.path.last()?;
                let parent_entry = context.path.get(context.path.len().checked_sub(2)?)?;
                Some((parent_entry.cell_para_index, table_entry.control_index))
            })
            .unwrap_or((para_index, control_index));
        let table_id = tree.next_id();
        let mut table_node = RenderNode::new(
            table_id,
            if parent_owned {
                RenderNodeType::Table(TableNode {
                    row_count: table.row_count,
                    col_count: table.col_count,
                    border_fill_id: table.border_fill_id,
                    section_index: Some(section_index),
                    para_index: Some(node_para_index),
                    control_index: Some(node_control_index),
                    // [#4334] 표 분할 조각(partial table)도 원본 부모 셀 경로를 그대로
                    // 옮겨 담는다 — provenance para/control 과 같은 근거(#4252).
                    cell_context: enclosing_cell_ctx.cloned(),
                })
            } else {
                RenderNodeType::Group(GroupNode {
                    paint_transform: None,
                    section_index: None,
                    para_index: None,
                    control_index: None,
                })
            },
            BoundingBox::new(table_x, table_y, table_width, partial_table_height),
        );

        Self::publish_table_paint_layer(table, &mut table_node);

        // ── 5-1. 표 배경 렌더링 (표 > 배경 > 색 > 면색) ──
        if parent_owned && table.border_fill_id > 0 {
            let tbl_idx = (table.border_fill_id as usize).saturating_sub(1);
            if let Some(tbl_bs) = styles.border_styles.get(tbl_idx) {
                self.render_cell_background(
                    tree,
                    &mut table_node,
                    Some(tbl_bs),
                    table_x,
                    table_y,
                    table_width,
                    partial_table_height,
                    bin_data_content,
                );
            }
        }

        let source_first_row_frame =
            self.saved_first_row_opening_frame(table, styles, self.current_body_area.get().3);
        let saved_opening_alignment_height = self
            .saved_single_cell_full_prefix_frame_height(table, start_cut, end_cut, styles)
            .or_else(|| {
                (start_row == 0 && end_row == 1 && start_cut.is_empty())
                    .then_some(source_first_row_frame.as_ref())
                    .flatten()
                    .filter(|(cut, opening, _)| {
                        cut.as_slice() == end_cut && end_row_height_override == Some(*opening)
                    })
                    .map(|(_, opening, _)| *opening)
            })
            .or_else(|| {
                source_single_cell_row_frames
                    .filter(|frame| {
                        end_cut == [frame.opening_end]
                            && end_row_height_override == Some(frame.opening_height)
                    })
                    .map(|frame| frame.opening_height)
            })
            .or_else(|| {
                end_row_height_override.and_then(|_| {
                    self.saved_multirow_opening_frame_height(
                        table, start_row, end_row, start_cut, end_cut, styles,
                    )
                })
            });
        let block_opening_height = (start_row == 0
            && start_cut.is_empty()
            && is_block_split
            && end_row_height_override.is_some()
            && resolved_table_top.is_some())
        .then(|| {
            paragraphs.get(para_index).and_then(|host| {
                self.stored_block_opening_frame_height(table, host, end_row, end_cut, styles)
            })
        })
        .flatten();
        // 완결 행 또는 저장 쪽 재시작에서 끝난 블록 컷은 선언된 첫 상자도 소유한다.
        // 예약과 같은 원본 프레임 소유자를 소비한다. 사용하지 않은 띠는 정렬 공간이며,
        // 그린 뒤 접어야 할 끝 줄간격이 아니다.
        let align_saved_opening_frame = !is_continuation
            && enclosing_cell_ctx.is_none()
            && block_opening_height
                .or(saved_opening_alignment_height.filter(|_| !is_block_split))
                .is_some_and(|frame_height| (partial_table_height - frame_height).abs() <= 0.5);

        // ── 6. 셀 렌더링 (render_rows 범위 내 셀만) ──
        // [#6976] 쪽을 끝내는 조각의 마지막 행 상자를 **배치 뒤에** 접는다.
        //
        // 행 높이에는 조각 마지막 줄 **뒤의 줄간격**이 들어 있는데 한/글은 그 띠를 그리지
        // 않는다. 그 여분은 행 높이를 정하는 단계에서는 알 수 없다 — 실제로 얼마가 남는지는
        // 칸 내용을 배치해 봐야 나오고, 배치는 행 높이가 정해진 **뒤**에 일어난다. 그래서
        // 행 높이(흐름·예약)는 그대로 두고 **그리는 상자만** 배치 뒤에 접는다.
        //
        // 조각이 쪽을 끝내므로(뒤 내용은 다음 쪽 소유) 이 축소는 뒤 내용을 밀지 않는다.
        // 쪽이 상자를 정한 조각(`budget_row_height_0`)은 제외한다 — 그 높이는 내용이 아니라
        // 쪽이 정한 값이고 정본도 그 자리를 채운다(hwpx_sample2 19쪽 pi=182 · 22~25쪽 pi=201).
        //
        // 접는 양은 그 행 **모든 칸**이 내놓는 여분의 최솟값이다. 셀 하나만 방출하는
        // `probe`(#4149 캐럿 fast path)는 그 행을 통째로 보지 못하므로, 대상 셀이 그 행의
        // 유일한 칸일 때만 접는다. 그 밖의 형상은 호출자가 legacy 로 폴백한다.
        // 줄간격 축소는 실제 이어받는 조각만 소유하지만, 완료 조각도 쪽 상한을 넘을 수 있다.
        let page_cap = crate::renderer::float_placement::rowbreak_fragment_frame_bottom(
            table,
            col_area.y + col_area.height,
            self.dpi,
            body_filling_source_frame,
        );
        let page_cap_fold = (table_y + partial_table_height - page_cap).max(0.0);
        let accepted_nested_opening_frame = (!is_continuation
            && start_row == 0
            && start_cut.is_empty()
            && !is_block_split
            && !start_cut_is_block)
            .then(|| {
                let frame = self.stored_nested_parent_opening_frame(
                    table,
                    end_row.checked_sub(1)?,
                    end_cut,
                    &resolved_row_heights,
                    styles,
                )?;
                let height = end_row_height_override?;
                ((height - frame.last_row_height).abs() <= hwpunit_to_px(2, self.dpi))
                    .then_some(frame)
            })
            .flatten();
        let owns_accepted_row_frame = end_row_height_override.is_some()
            && end_row.checked_sub(1).is_some_and(|row| {
                self.native_stored_row_has_text_frame_boundary(table, row, styles)
                    // 같은 첫 물리 상자를 다시 접지 않는다. 셀 정렬 소유와는 별도다.
                    || accepted_nested_opening_frame.is_some()
                    // 독립 최소를 가진 칸이 수용한 빈 띠만 보존한다.
                    // scan과 같은 소유 판정으로 일반 내용 행의 여백을 늘리지 않는다.
                    || ((self.row_has_continuing_reflow_minimum(table, row, styles)
                        || self.reflow_row_physical_minimum(table, row, resolved_row_heights[row], Some(end_cut), styles).is_some_and(
                            |minimum| end_row_height_override.is_some_and(|height| height <= minimum + 0.5),
                        ))
                        && self.row_has_plain_reflow_line_units(table, row, styles))
                    // [#7870] scan 이 재조판 행 첫 조각에 예약한 선언 행 높이도 같은 소유다.
                    || (!(is_continuation && row == start_row)
                        && self.row_declared_first_frame(table, row, resolved_row_heights[row], end_cut, styles).is_some_and(
                            |declared| end_row_height_override.is_some_and(|height| height <= declared.height + 0.5),
                        ))
                    || (self.profile.get().hwpx_stored_layout()
                        && self
                            .stored_full_width_row_declared_height(
                                table,
                                row,
                                styles,
                                self.current_body_area.get().3,
                            )
                            .is_some())
            });
        // 예약한 원본 본문 프레임은 빈 띠도 소유한다. 공통 컷이 닫는 물리 행 높이를
        // paint에서 다시 접으면 예약과 외곽선의 높이가 갈라진다.
        let accepted_body_closed_frame = is_continuation
            && !is_block_split
            && end_row_height_override.is_some()
            && paragraphs.get(para_index).is_some_and(|host| {
                self.original_body_closed_table_frame(host, table, col_area.height)
            })
            && end_row.checked_sub(1).is_some_and(|row| {
                self.row_cut_closes_shared_original_frame(table, row, end_cut, styles)
                    || self.row_cut_closes_original_restart_frame(
                        table,
                        row,
                        end_cut,
                        &resolved_row_heights,
                        styles,
                    )
            });
        // 같은 원본 프레임 소유를 줄 구성과 최종 셀 정렬에 넘긴다.
        // 컷으로 고른 내용만 전달된 물리 상자 안에서 정렬하며 전체 셀 내용은
        // 다음 조각의 유닛까지 이 조각에 포함하지 않는다.
        let original_restart_alignment_rows = if is_continuation
            && enclosing_cell_ctx.is_none()
            && !is_block_split
            && !start_cut_is_block
            && paragraphs.get(para_index).is_some_and(|host| {
                self.original_body_closed_table_frame(host, table, col_area.height)
            }) {
            [
                start_row_height_override
                    .filter(|_| {
                        self.row_cut_closes_original_restart_frame(
                            table,
                            start_row,
                            start_cut,
                            &resolved_row_heights,
                            styles,
                        )
                    })
                    .map(|_| start_row),
                end_row_height_override.and_then(|_| {
                    let row = end_row.checked_sub(1)?;
                    self.row_cut_closes_original_restart_frame(
                        table,
                        row,
                        end_cut,
                        &resolved_row_heights,
                        styles,
                    )
                    .then_some(row)
                }),
            ]
        } else {
            [None, None]
        };
        let fold_last_row = render_rows.last().copied().filter(|&fold_row| {
            (end_row < table.row_count as usize
                || end_cut.iter().any(|&unit| unit > 0)
                || page_cap_fold > 0.5)
                && enclosing_cell_ctx.is_none()
                && !align_saved_opening_frame
                && !end_row_owns_stored_frame
                && !(computed_fragment_frame && end_row_height_override.is_some())
                && !(end_row_height_override.is_some()
                    && !is_block_split && !start_cut_is_block
                    && self.reflow_nested_band_at_height(table, fold_row,
                        if fold_row == start_row { start_cut } else { &[] },
                        if fold_row + 1 == end_row { end_cut } else { &[] },
                        row_heights[fold_row], styles).is_some())
                && !(!is_block_split && !start_cut_is_block
                    && self.reflow_partial_row_frame_height(
                        table, fold_row,
                        if fold_row == start_row { start_cut } else { &[] },
                        if fold_row + 1 == end_row { end_cut } else { &[] }, styles,
                    ).is_some_and(|height| (height - row_heights[fold_row]).abs() <= 0.5))
                // 저장 걸침 칸의 두 조각에 이미 배분한 물리 높이는 옆 칸의
                // 후행 줄간격이 아니다. 다시 접으면 앞 조각의 공간만 유실된다.
                && center_saved_spanning_cell.is_none()
                && !owns_block_row(fold_row)
                // 이어받은 원본 행은 수용한 빈 띠도 소유한다.
                && !(fold_row == 0 && start_row == 0 && is_continuation
                    && source_first_row_frame.as_ref().is_some_and(|(cut, _, remaining)| {
                        cut.as_slice() == start_cut && start_row_height_override == Some(*remaining)
                    }))
                && !owns_accepted_row_frame
                && !accepted_body_closed_frame
                // 셀 저장 줄의 새 원점 재시작에서 자른 끝 행은 scan 이 공통 상자
                // (`stored_restart_end_row_box`)를 예약했다. 같은 컷·같은 상자면 끝 줄간격 접기로
                // 다시 줄이지 않는다(myeonjeok 1쪽 행 29).
                && !(!is_block_split
                    && end_row == fold_row + 1
                    && end_row_height_override.is_some_and(|height| {
                        self.row_plain_restart_capacity_cut(table, fold_row, styles)
                            .is_some_and(|cut| {
                                cut.as_slice() == end_cut
                                    && (self.stored_restart_end_row_box(
                                        table, fold_row, &cut, styles,
                                    ) - height)
                                        .abs()
                                        < 0.01
                            })
                    }))
                && !(end_row_height_override.is_some()
                    && !is_block_split
                    && self
                        .stored_ordinary_row_frame_owns_alignment(table, fold_row, end_cut, styles))
                && budget_row_height_0.is_none()
                // 내용을 모두 담고 자기 선언 높이 안에 있는 끝 행 상자는 선언이 만든 물리
                // 상자다. 한/글은 그 상자를 닫는 선까지 그리고 남은 선언을 다음 쪽 띠로 넘긴다
                // (1342000 58쪽 행 9 98.88px, #8105 합성 사다리 181.5px). 끝 줄간격으로 접지 않는다.
                && !(!is_block_split
                    && end_row == fold_row + 1
                    && end_row_height_override.is_some_and(|height| {
                        table.get_raw_row_heights().get(fold_row).is_some_and(|&declared| {
                            declared <= i32::MAX as u32
                                && height <= hwpunit_to_px(declared as i32, self.dpi) + 0.5
                        }) && self.row_cut_consumes_all_ordinary_units(
                            table, fold_row, end_cut, styles,
                        )
                    }))
                && probe.is_none_or(|p| {
                    table.cells.iter().enumerate().all(|(idx, cell)| {
                        cell.row as usize + cell.row_span as usize != fold_row + 1
                            || idx == p.cell_idx
                    })
                })
        });
        let mut fold_slack = f64::INFINITY;
        // 펼친 투명 래퍼도 셀 내용 주소의 한 단계다. 배치 분기는 계속 래퍼 문맥을 쓴다.
        let unwrapped_cell_ctx = if std::ptr::eq(table, outer_table) {
            None
        } else {
            unwrapped_table_cell_ctx(
                enclosing_cell_ctx,
                Some((para_index, control_index)),
                outer_table,
                table,
            )
        };
        self.layout_partial_table_cells(
            tree,
            &mut table_node,
            table,
            para_index,
            control_index,
            section_index,
            styles,
            outline_numbering_id,
            bin_data_content,
            start_row,
            end_row,
            end_row_height_override,
            start_row_height_override,
            is_continuation,
            start_cut,
            end_cut,
            is_block_split,
            start_cut_is_block,
            cell_spacing,
            col_count,
            row_count,
            table_x,
            table_y,
            &row_heights,
            &resolved_row_heights,
            straddle_page_bands,
            budget_row_height_0,
            &row_col_x,
            &header_rows,
            &render_rows,
            &render_row_y,
            &mut h_edges,
            &mut v_edges,
            &mut h_span_covered,
            &mut v_span_covered,
            measured_table,
            unwrapped_cell_ctx.as_ref().or(enclosing_cell_ctx),
            clamp_header_negative_para_offset,
            probe,
            center_pinned_single_cell,
            center_saved_spanning_cell,
            align_saved_opening_frame,
            end_row_owns_stored_frame,
            computed_fragment_frame,
            external_frame,
            original_restart_alignment_rows,
            fold_last_row,
            &mut fold_slack,
        );

        // [#6976] 접기 적용 — 자르는 양은 두 상한의 작은 쪽이다.
        //
        //   ① «마지막 줄의 저장 줄간격» — 한/글이 그리지 않는 띠. 선언 행 높이가 내용보다
        //      훨씬 큰 행이 내용 바닥까지 통째로 내려앉는 것을 막는다.
        //   ② «실제로 남은 여분» — 배치가 확정한 값(`fold_slack`). 행의 모든 칸이 내용과
        //      아래 여백을 지킨 채 내놓을 수 있는 최댓값이라 과다 절삭을 막는다.
        //
        // ①만 빼면 `table_giant_cell_overfill` 처럼 행 높이에 줄간격의 **일부만** 들어 있는
        // 조각에서 상자가 내용 아래로 내려간다. ②만 빼면 내용이 적은 선언 높이 행이 무너진다.
        if let Some(fold_row) = fold_last_row {
            let mut trail: f64 = 0.0;
            // 수용과 물리 높이가 함께 소유한 원본 병합 슬롯은 줄 뒤 여분이
            // 아니다. 마지막 paint 접기에서도 같은 컷의 소유 판정을 소비한다.
            // 실제 쪽 상한 초과분(cap_fold)은 아래에서 별도로 처리한다.
            let owns_closing_slot = is_block_split && {
                let (first, end) = rowspan_block_range(table, fold_row);
                table.cells.iter().any(|cell| {
                    let first_row = usize::from(cell.row);
                    first_row <= fold_row
                        && fold_row < first_row + usize::from(cell.row_span)
                        && block_cut_index(table, first, end, cell)
                            .and_then(|index| end_cut.get(index))
                            .is_some_and(|&end| {
                                let units = self.cell_units(cell, table, styles);
                                self.stored_reset_span_owns_closing_slot(table, cell, &units, end)
                            })
                })
            };
            let (su, eu) = (
                start_cut.first().copied().unwrap_or(0),
                end_cut.first().copied().unwrap_or(0),
            );
            if eu > 0 && !owns_closing_slot {
                for cell in table.cells.iter().filter(|c| c.row as usize == fold_row) {
                    let ranges = self.cell_line_ranges_from_cut(cell, table, styles, su, eu);
                    let Some(pi2) = ranges
                        .iter()
                        .enumerate()
                        .filter(|(_, &(a, b))| b > a)
                        .map(|(i, _)| i)
                        .next_back()
                    else {
                        continue;
                    };
                    let end = ranges[pi2].1;
                    if let Some(seg) = cell
                        .paragraphs
                        .get(pi2)
                        .and_then(|p| p.line_segs.get(end.checked_sub(1).unwrap_or(0)))
                    {
                        trail = trail.max(hwpunit_to_px(seg.line_spacing.max(0), self.dpi));
                    }
                }
            }
            // [#7095 확장] 쪽 상한 초과분. 정본은 `본문아래 − outMargin.bottom − 100HU` 에서
            // 조각 상자를 끊는다 — 그 형상 조건은 1×1 이 아니다. 정본 세 문서 10조각에서
            // 확인했다(양쪽 모두 괘선 병합으로 잰 값, 잔차 0.09~1.25px).
            //
            // ```text
            //   문서                          행×열   omB(HU)  본문아래  정본아래   잔차
            //   issue7336 p2·p5               16×1      283   1028.01  1022.99   1.25
            //   rowbreak-problem-pages p3·p4  25×7      141   1028.00  1026.03   0.09
            //   issue1853 … 6쪽                2×2      141   1020.48  1018.51   0.09
            // ```
            //
            // 내용이 상한보다 먼저 끝나는 조각(issue7336 p3·p4)은 이 값이 0 이라 접지 않는다.
            let cap_fold = page_cap_fold;
            // 두 사유(줄간격 · 쪽 상한) 중 **큰 쪽**만큼 접되, 실제로 남은 여분을 넘지 않는다.
            let fold = trail.max(cap_fold).min(fold_slack).max(0.0);
            if fold > 0.5 && partial_table_height > fold + 1.0 {
                for child in &mut table_node.children {
                    if let RenderNodeType::TableCell(meta) = &child.node_type {
                        if row_band::owns_fragment_bottom(
                            usize::from(meta.row),
                            usize::from(meta.row_span),
                            fold_row,
                        ) && child.bbox.height > fold + 1.0
                        {
                            child.bbox.height -= fold;
                        }
                    }
                }
                if let Some(last_edge) = grid_row_y.last_mut() {
                    *last_edge -= fold;
                }
                table_node.bbox.height -= fold;
                // [#6976 진단] 접은 조각과 두 상한. 동작 불변.
                if std::env::var("RHWP_DIAG_FOLD").is_ok() {
                    eprintln!(
                        "DIAG_FOLD pi={} rows={}..{} trail={:.2} slack={:.2} fold={:.2}",
                        para_index, start_row, end_row, trail, fold_slack, fold
                    );
                }
            }
        }

        if parent_owned {
            // cellzone·표 외곽 테두리 덮어쓰기를 비분할 표와 같게 적용한다. 아래의 조각 경계
            // 지우기보다 먼저 해야 열린 윗변·아랫변이 되살아나지 않는다. 그리드는 조각-지역
            // 행(`render_rows` 순서)이므로 칸·zone 행 주소를 그 공간으로 옮긴다.
            {
                // 원본 행 [row, end) 중 이 조각에 그려지는 첫·끝 조각-지역 행
                let local_rows = |row: usize, end: usize| {
                    let first = render_rows.iter().position(|&r| r >= row && r < end)?;
                    let last = render_rows.iter().rposition(|&r| r >= row && r < end)?;
                    Some((first, last))
                };
                let fragment_cells: Vec<Cell> = table
                    .cells
                    .iter()
                    .filter_map(|cell| {
                        let row = cell.row as usize;
                        let (first, last) = local_rows(row, row + (cell.row_span as usize).max(1))?;
                        Some(Cell {
                            row: first as u16,
                            row_span: (last + 1 - first) as u16,
                            col: cell.col,
                            col_span: cell.col_span,
                            border_fill_id: cell.border_fill_id,
                            ..Default::default()
                        })
                    })
                    .collect();
                let fragment_zones: Vec<_> = table
                    .zones
                    .iter()
                    .filter_map(|zone| {
                        // 끝 주소는 칸 주소라 병합 span 끝까지가 zone 이다 (#6619).
                        let end_cell = table
                            .cells
                            .iter()
                            .find(|c| c.row == zone.end_row && c.col == zone.end_col);
                        let (end_row, end_col) = end_cell.map_or(
                            (zone.end_row as usize + 1, zone.end_col as usize + 1),
                            |c| {
                                (
                                    c.row as usize + (c.row_span as usize).max(1),
                                    c.col as usize + (c.col_span as usize).max(1),
                                )
                            },
                        );
                        let (first, last) = local_rows(zone.start_row as usize, end_row)?;
                        let mut zone = zone.clone();
                        zone.start_row = first as u16;
                        zone.end_row = last as u16;
                        zone.end_col = end_col.saturating_sub(1) as u16;
                        Some(zone)
                    })
                    .collect();
                apply_table_border_overrides(
                    &mut h_edges,
                    &mut v_edges,
                    table.border_fill_id,
                    &fragment_zones,
                    &fragment_cells,
                    styles,
                );
            }

            // 어울림 표가 행 안에서 다음 쪽으로 이어지면 새 물리 조각의 맨 위는
            // 원본 셀의 윗변이 아니다. 반복 제목행이 없는 경우 그 컷 경계에
            // 수집된 가로선을 그리지 않는다. 2020 PDF의 #6756·#6549는 열린
            // 윗변을, 자리차지 #5885는 닫힌 윗변을 각각 보여 준다.
            if is_continuation
                && !start_cut.is_empty()
                && header_rows.is_empty()
                && matches!(
                    table.common.text_wrap,
                    crate::model::shape::TextWrap::Square
                )
            {
                if let Some(first_edge) = h_edges.first_mut() {
                    // 부모의 내용 컷이 자식의 온전한 행 경계를 선택한 경우에는
                    // 새 물리 프레임의 윗변을 보존한다. 측정이 만든 같은
                    // CellUnit/자식 컷으로 글줄 안의 컷과 구분한다.
                    let nested_row_boundary = self.nested_row_cut_frame_columns(
                        table,
                        start_row,
                        start_cut,
                        start_cut_is_block,
                        styles,
                    );
                    for (edge, keep) in first_edge.iter_mut().zip(nested_row_boundary) {
                        if !keep {
                            *edge = None;
                        }
                    }
                }
                // 블록 커서에서 이미 소비한 행의 물리 높이는 0이다.
                // 내부 격자 경계도 조각 원점과 겹칠 수 있다. 새로 시작하는 원본 셀은 실제 경계를 유지하지만,
                // 유닛을 이미 소비한 셀에 새 상단 경계를 부여하지 않는다.
                if start_cut_is_block {
                    let (bs, be) = rowspan_block_range(table, start_row);
                    for (index, edge) in h_edges.iter_mut().enumerate().skip(1) {
                        if grid_row_y[index] != 0.0 {
                            break;
                        }
                        let Some(&row) = render_rows.get(index) else {
                            break;
                        };
                        let has_new_owner = table.cells.iter().any(|cell| {
                            cell.row as usize == row
                                && block_cut_index(table, bs, be, cell)
                                    .and_then(|ordinal| start_cut.get(ordinal))
                                    .is_none_or(|&cut| cut == 0)
                        });
                        if !has_new_owner {
                            edge.fill(None);
                        }
                    }
                }
            }

            // Square 흐름의 내부 컷은 쪽 조각을 소유하며 셀 하단 테두리는 소유하지 않는다.
            // 다음 조각이 원래의 닫는 경계를 유지한다.
            if !is_last_part
                && !end_cut.is_empty()
                && table.layout_page_break() == crate::model::table::TablePageBreak::RowBreak
                && table.common.text_wrap == crate::model::shape::TextWrap::Square
            {
                if let Some(last_edge) = h_edges.last_mut() {
                    let nested_row_boundary = self.nested_row_cut_frame_columns(
                        table,
                        end_row.saturating_sub(1),
                        end_cut,
                        is_block_split,
                        styles,
                    );
                    for (edge, keep) in last_edge.iter_mut().zip(nested_row_boundary) {
                        if !keep {
                            *edge = None;
                        }
                    }
                }
            }

            // 복구한 Square 흐름의 마지막 줄은 최종 프레임 경계도 소유한다.
            // 쪽 나누기가 소비한 높이는 이 그리기 전용 확장과 구분한다.
            if self.profile.get().hwp5_stored_pagination_layout()
                && enclosing_cell_ctx.is_none()
                && is_continuation
                && end_cut.is_empty()
                && end_row >= row_count
                && !table.common.treat_as_char
                && matches!(
                    table.layout_page_break(),
                    crate::model::table::TablePageBreak::RowBreak
                )
            {
                // 끝 띠는 위에서 이미 접혔을 수 있으므로 수용한 현재 물리 상자에서 시작한다.
                // 접기 전 높이를 사용하면 복구한 줄이 없어도 버린 띠를 다시 되살린다.
                let mut frame_height = table_node.bbox.height;
                for child in &table_node.children {
                    let RenderNodeType::TableCell(meta) = &child.node_type else {
                        continue;
                    };
                    if !meta.clip
                        || !meta.page_fragment
                        || usize::from(meta.row) + usize::from(meta.row_span) != row_count
                    {
                        continue;
                    }
                    let Some(cell) = meta
                        .model_cell_index
                        .and_then(|idx| table.cells.get(idx as usize))
                    else {
                        continue;
                    };
                    let has_stored_wrap = cell.paragraphs.iter().enumerate().any(|(pi, para)| {
                        para.controls
                            .iter()
                            .enumerate()
                            .any(|(ci, _)| stored_square_picture_has_adjacent_text(cell, pi, ci))
                    });
                    if has_stored_wrap {
                        let body_bottom = col_area.y + col_area.height;
                        let recovered_bottom = (child.bbox.y + child.bbox.height).min(body_bottom);
                        frame_height = frame_height.max(recovered_bottom - table_y);
                    }
                }
                if let Some(last_edge) = grid_row_y.last_mut() {
                    *last_edge = frame_height;
                }
                table_node.bbox.height = frame_height;
            }

            // [#5877] `h_edges`/`v_edges`/`grid_row_y` 는 **조각-지역 행 인덱스**
            // (`render_rows` 순서)인데 `row_col_x` 는 **원본 행 전체**다. 테두리
            // 렌더러는 그 인덱스로 `row_col_x` 를 직접 참조하므로, 조각이 원본 행 18
            // 부터 시작해도 조각-지역 0·1 이 원본 행 0·1(전폭 단일 셀 제목 행 —
            // 행별 열 구획이 균등 보간된다)의 격자를 집는다. 그 결과 쪽을 넘어온
            // 조각 상단에만 표폭/열수 균등 간격의 유령 세로 괘선이 그려졌다
            // (2961515 150행×32열: 21.13px 간격, 셀 좌표는 정상).
            // 렌더 순서에 맞춰 조각용 격자를 만들어 넘긴다.
            let fragment_row_col_x: Vec<Vec<f64>> = render_rows
                .iter()
                .map(|&r| {
                    row_col_x
                        .get(r)
                        .or_else(|| row_col_x.last())
                        .cloned()
                        .unwrap_or_else(|| col_x.clone())
                })
                .collect();
            let fragment_row_col_x = if fragment_row_col_x.is_empty() {
                row_col_x.to_vec()
            } else {
                fragment_row_col_x
            };

            // 엣지 기반 테두리 렌더링
            let body_top_clip = (enclosing_cell_ctx.is_none()
                && self.is_body_flow_col_area(col_area)
                && (table_y - col_area.y).abs() <= 0.5)
                .then_some(col_area.y);
            if table.cell_spacing > 0 {
                let open_top_row = (is_continuation
                    && !start_cut.is_empty()
                    && header_rows.is_empty()
                    && matches!(
                        table.common.text_wrap,
                        crate::model::shape::TextWrap::Square
                    ))
                .then_some(start_row as u16);
                let borders = render_spaced_cell_borders(
                    tree,
                    table,
                    styles,
                    &table_node.children,
                    open_top_row,
                    self.show_transparent_borders.get(),
                );
                table_node.children.extend(borders);
                table_node
                    .children
                    .extend(super::table_layout::render_spaced_table_outer_frame(
                        tree,
                        table,
                        styles,
                        table_node.bbox,
                        open_top_row.is_some(),
                    ));
            } else {
                table_node.children.extend(render_edge_borders(
                    tree,
                    &h_edges,
                    &v_edges,
                    &fragment_row_col_x,
                    &grid_row_y,
                    table_x,
                    table_y,
                    body_top_clip,
                ));
                if self.show_transparent_borders.get() {
                    table_node.children.extend(render_transparent_borders(
                        tree,
                        &h_edges,
                        &v_edges,
                        &h_span_covered,
                        &v_span_covered,
                        &fragment_row_col_x,
                        &grid_row_y,
                        table_x,
                        table_y,
                    ));
                }
            }
        }

        // 부분 표의 셀은 조각 셀 반복이 끝난 뒤에 중첩 표 경계 노드를 받는다.
        // RowBreak 이어받기 뷰포트의 폭은 늘리지 않고 가로 클립 안에서 직계 중첩 표의 바깥 세로 테두리를
        // 보존한다(issue2007 2~3쪽).
        // [#6924] 이 조각이 어떤 글줄을 **소유**하는지는 컷 부기가 이미 안다
        // (`partial_table_page_contains_cell_position`). 그 판정을 clip 보정까지 날라
        // 소유하지 않는 줄만 지우게 한다 — 소유한 줄을 지우면 다시 그릴 조각이 없어
        // 문서에서 사라진다(148751598 1쪽 31자 · 148738070 1쪽 38자 · 156060125 6쪽).
        let owns_line = |cell_meta: &crate::renderer::render_tree::TableCellNode,
                         line: &crate::renderer::render_tree::TextLineNode|
         -> bool {
            let (Some(cell_idx), Some(para_index), Some(line_index)) =
                (cell_meta.model_cell_index, line.para_index, line.line_index)
            else {
                // 좌표를 모르면 판정하지 않는다 — 종전 계약(억제) 그대로 둔다.
                return false;
            };
            let Some(cell) = table.cells.get(cell_idx as usize) else {
                return false;
            };
            self.partial_table_page_contains_cell_position(
                table,
                cell,
                start_row,
                end_row,
                start_cut,
                end_cut,
                is_block_split,
                start_cut_is_block,
                Some((para_index, line_index as usize, true)),
                styles,
            )
        };
        // 아래 정리 단계가 글줄을 숨기기 전에 표시용 클립을 확보해야 한다.
        // 이미 visible=false가 된 줄을 나중에 클립만 넓혀 복구할 수는 없다.
        let owned_line_flow_bottoms =
            expand_fragment_cell_clip_for_owned_bottom_lines(&mut table_node, &owns_line);
        extend_completed_nested_table_border_clips(
            tree,
            &mut table_node,
            self.profile.get().hwp5_stored_pagination_layout()
                || self.profile.get().hwp5_origin_hwpx(),
            self.profile.get().hwpx_container(),
            &super::table_layout::tables_with_ladder_reserved_nested_overflow(table),
            // 상한은 **용지**다 — 한글은 본문 밖·용지 안에 그린다(3194097: 본문 우단
            // 720.0, 그림 749.4, 용지 793.7). 본문으로 잡으면 이 축이 통째로 닫힌다.
            self.current_paper_width.get(),
        );

        // [Task #1860/#3820] 노드-자식 포섭 불변: 분할 표 조각의 셀 내 절대위치 shape
        // (as-char 텍스트박스/그림 등)가 유닛 기반 셀 높이를 초과해 그려지면 표 노드
        // bbox 가 자식을 clip 한다(page17 pi=28 텍스트박스 하단 잘림). 렌더 완료 후 모든
        // **가시** 자손의 최하단을 구해 표 노드 높이를 그만큼 확장한다(확장만, 축소 없음).
        //
        // 단, RowBreak 조각의 `TableCell { clip: true }` 아래 일반 흐름 자손은 그 물리
        // cell viewport 밖에서 다음/이전 쪽의 흐름을 보유할 수 있다. 그 invisible tail까지
        // Table bbox에 포함하면 body clip도 수천 px로 확대되어 Canvas/WASM replay가
        // 현재 쪽 밖의 내용을 paint 후보로 보게 된다(42065 p8 이후). 반면 직접 배치된
        // 도형은 clip cell의 현재 쪽 표시물일 수 있으므로, **현재 column body 안에서 끝나는
        // 경우에만** 그 도형 subtree를 계속 포함한다. 이 경계는 p17의 textbox-backed
        // rectangle은 보존하면서, 다른 문서의 다음 쪽 밖 도형을 table/body clip으로
        // 역류시키지 않는다.
        if external_frame.is_none() || !parent_owned {
            let physical_page_bottom = col_area.y + col_area.height;
            let logical_table_bottom = table_node.bbox.y + table_node.bbox.height;
            let terminal_long_child_clip_only = is_continuation
                && end_row >= table.row_count as usize
                && end_cut.is_empty()
                && native_terminal_child_host_line_spacing(
                    self.profile.get().hwp5_stored_pagination_layout(),
                    self.render_normalization
                        .borrow()
                        .table_text_reflowed(table),
                    table,
                    self.dpi,
                ) > 0.5;
            fn descendant_bottom(
                node: &RenderNode,
                physical_page_bottom: f64,
                logical_table_bottom: f64,
                terminal_long_child_clip_only: bool,
                owned_line_flow_bottoms: &FragmentCellFlowBottoms,
            ) -> f64 {
                let clipped_cell = matches!(
                    node.node_type,
                    RenderNodeType::TableCell(TableCellNode { clip: true, .. })
                );
                // 마지막 셀은 자식 표의 하단 획을 보존하려고 그리기 클립을 넓힐 수 있다.
                // 이 클립은 부모 행의 새 흐름이 아니다. 잘린 셀은 논리 RowBreak 하단에서 시작하고,
                // 이 쪽에서 끝나는 것으로 확인된 직계 그리기 개체만 바깥 표 상자를 확장할 수 있다.
                let flow_bottom = owned_line_flow_bottoms
                    .get(&node.id)
                    .copied()
                    .unwrap_or(node.bbox.y + node.bbox.height);
                let mut b = if clipped_cell && terminal_long_child_clip_only {
                    flow_bottom.min(logical_table_bottom)
                } else {
                    flow_bottom
                };
                if clipped_cell {
                    for child in &node.children {
                        let is_direct_drawing = matches!(
                            child.node_type,
                            RenderNodeType::Rectangle(_)
                                | RenderNodeType::Ellipse(_)
                                | RenderNodeType::Path(_)
                                | RenderNodeType::Image(_)
                                | RenderNodeType::Group(_)
                                | RenderNodeType::TextBox
                                | RenderNodeType::Equation(_)
                                | RenderNodeType::FormObject(_)
                                | RenderNodeType::Placeholder(_)
                                | RenderNodeType::RawSvg(_)
                        );
                        if is_direct_drawing {
                            let drawing_bottom = descendant_bottom(
                                child,
                                physical_page_bottom,
                                logical_table_bottom,
                                terminal_long_child_clip_only,
                                owned_line_flow_bottoms,
                            );
                            if drawing_bottom <= physical_page_bottom + 0.5 {
                                b = b.max(drawing_bottom);
                            }
                        }
                    }
                    return b;
                }
                for c in &node.children {
                    b = b.max(descendant_bottom(
                        c,
                        physical_page_bottom,
                        logical_table_bottom,
                        terminal_long_child_clip_only,
                        owned_line_flow_bottoms,
                    ));
                }
                b
            }
            // 완결된 중첩 표는 전체 배치와 같은 논리 프레임을 사용한다.
            // 실제 분할 조각과 루트 표의 paint 상자는 바깥 반 획도 보존한다.
            let complete_nested_frame = enclosing_cell_ctx.is_some()
                && start_row == 0
                && end_row == usize::from(table.row_count)
                && start_cut.iter().all(|&unit| unit == 0)
                && end_cut.is_empty()
                && !is_block_split
                && !start_cut_is_block;
            let content_bottom = table_node
                .children
                .iter()
                .map(|child| {
                    if complete_nested_frame {
                        if let RenderNodeType::Line(line) = &child.node_type {
                            return line.y1.max(line.y2);
                        }
                    }
                    descendant_bottom(
                        child,
                        physical_page_bottom,
                        logical_table_bottom,
                        terminal_long_child_clip_only,
                        &owned_line_flow_bottoms,
                    )
                })
                .fold(table_node.bbox.y + table_node.bbox.height, f64::max);
            let grown = content_bottom - table_node.bbox.y;
            if grown > table_node.bbox.height {
                table_node.bbox.height = grown;
            }
        }

        col_node.children.push(table_node);

        // ── 캡션 렌더링 ──
        // cell_index = 65534: 캡션 식별 센티널 (셀 0과 구분)
        let cap_cell_ctx = Some(if let Some(context) = enclosing_cell_ctx {
            let mut context = context.clone();
            if let Some(last) = context.path.last_mut() {
                last.cell_index = 65534;
                last.cell_para_index = 0;
                last.text_direction = 0;
            }
            context
        } else {
            CellContext {
                in_textbox: false,
                parent_para_index: para_index,
                path: vec![CellPathEntry {
                    control_index,
                    cell_index: 65534,
                    cell_para_index: 0,
                    text_direction: 0,
                }],
            }
        });
        if render_top_caption {
            if let Some(ref caption) = table.caption {
                self.layout_caption(
                    tree,
                    col_node,
                    caption,
                    styles,
                    col_area,
                    table_x,
                    table_width,
                    y_start,
                    &mut self.auto_counter.borrow_mut(),
                    bin_data_content,
                    cap_cell_ctx.clone(),
                    CaptionOwner::new(
                        Some(section_index),
                        Some(node_para_index),
                        Some(node_control_index),
                        CaptionControlKind::Table,
                    ),
                );
            }
        }
        if render_bottom_caption {
            if let Some(ref caption) = table.caption {
                // 아래 캡션은 통째 표와 같이 표 아래 + 캡션 간격에 놓는다. 호스트 줄간격은 캡션
                // 뒤 흐름 끝(`caption_total`)에만 속한다(1613000 128쪽 [표 12]: 한/글 2020 은 표
                // 아래 349 → 캡션 줄 위 12px, 통째 표 120·121쪽과 같은 간격).
                let caption_y = table_y + partial_table_height + caption_spacing;
                self.layout_caption(
                    tree,
                    col_node,
                    caption,
                    styles,
                    col_area,
                    table_x,
                    table_width,
                    caption_y,
                    &mut self.auto_counter.borrow_mut(),
                    bin_data_content,
                    cap_cell_ctx.clone(),
                    CaptionOwner::new(
                        Some(section_index),
                        Some(node_para_index),
                        Some(node_control_index),
                        CaptionControlKind::Table,
                    ),
                );
            }
        }
        if render_lr_caption {
            if let Some(ref caption) = table.caption {
                use crate::model::shape::CaptionVertAlign;
                let cap_x = if is_left_cap {
                    table_x - cap_width_px - caption_spacing
                } else {
                    table_x + table_width + caption_spacing
                };
                let cap_y = match caption.vert_align {
                    CaptionVertAlign::Top => table_y,
                    CaptionVertAlign::Center => {
                        table_y + (partial_table_height - caption_height).max(0.0) / 2.0
                    }
                    CaptionVertAlign::Bottom => {
                        table_y + (partial_table_height - caption_height).max(0.0)
                    }
                };
                self.layout_caption(
                    tree,
                    col_node,
                    caption,
                    styles,
                    col_area,
                    cap_x,
                    cap_width_px,
                    cap_y,
                    &mut self.auto_counter.borrow_mut(),
                    bin_data_content,
                    cap_cell_ctx.clone(),
                    CaptionOwner::new(
                        Some(section_index),
                        Some(node_para_index),
                        Some(node_control_index),
                        CaptionControlKind::Table,
                    ),
                );
            }
        }

        let caption_total = if render_top_caption {
            caption_height
                + if caption_height > 0.0 {
                    caption_spacing
                } else {
                    0.0
                }
        } else if render_bottom_caption {
            caption_height
                + host_line_spacing
                + if caption_height > 0.0 {
                    caption_spacing
                } else {
                    0.0
                }
        } else {
            // Left/Right 캡션은 표 높이에 영향 없음
            0.0
        };
        // [#3637 진단] 조각 렌더 높이 vs 페이지네이터 컷 예산. 동작 불변.
        // TABLE_SPLIT_RESULT 의 consumed 와 짝지어 보면 두 공간의 발산이 보인다.
        if std::env::var("RHWP_DIAG_FRAG").is_ok() {
            eprintln!(
                "DIAG_FRAG pi={} ci={} rows={}..{} cont={} blk={} start_cut={:?} end_cut={:?} y_start={:.1} tbl_h={:.1} logical_delta={:.1} cap={:.1}",
                para_index,
                control_index,
                start_row,
                end_row,
                is_continuation,
                is_block_split,
                start_cut,
                end_cut,
                y_start,
                partial_table_height,
                stored_reset_logical_height_delta,
                caption_total,
            );
        }
        // 후속 흐름을 이동하거나 PageItem 소유를 바꾸지 않는다. Stage 120은 그리는 프레임과 클립만 바꾼다.
        // 쪽 나누기는 원래 구성한 컷 높이를 소비했다.
        let caption_outer_bottom =
            if empty_opening_continuation && end_row >= row_count && end_cut.is_empty() {
                hwpunit_to_px(table.outer_margin_bottom as i32, self.dpi)
            } else if rowbreak_reopens_outer_top && end_row >= row_count && end_cut.is_empty() {
                crate::renderer::float_placement::column_rowbreak_caption_outer_spacing_px(
                    rowbreak_reopens_outer_top,
                    &paragraphs[para_index],
                    outer_table,
                    self.dpi,
                )
            } else {
                0.0
            };
        y_start
            + external_reserved_height.unwrap_or(partial_table_height)
            + stored_reset_logical_height_delta
            + caption_total
            + caption_outer_bottom
            + crate::renderer::float_placement::column_rowbreak_grid_bottom_margin_px(
                rowbreak_reopens_outer_top,
                outer_table,
                is_continuation,
                end_cut.is_empty() || is_block_split || start_cut_is_block,
                end_row < row_count || !end_cut.is_empty(),
                self.dpi,
            )
    }
}

#[cfg(test)]
mod tests {
    use super::{
        cell_content_bottom, expand_cell_clip_to_new_source_bounded_children,
        expand_terminal_cell_clip_to_nested_table_descendants, fragment_vpos_origin,
    };
    use crate::model::paragraph::{LineSeg, Paragraph};
    use crate::model::table::Cell;
    use crate::renderer::render_tree::{
        BoundingBox, LineNode, RenderNode, RenderNodeType, TableCellNode, TableNode,
    };

    fn paragraph_with_vpos(vposes: &[i32]) -> Paragraph {
        Paragraph {
            line_segs: vposes
                .iter()
                .map(|&vertical_pos| LineSeg {
                    vertical_pos,
                    ..Default::default()
                })
                .collect(),
            ..Default::default()
        }
    }

    #[test]
    fn split_cell_fragment_origin_uses_first_visible_line_not_paragraph_start() {
        let cell = Cell {
            paragraphs: vec![paragraph_with_vpos(&[4_000, 5_000, 6_000])],
            ..Default::default()
        };

        assert_eq!(
            fragment_vpos_origin(&cell, Some(&[(1, 3)])),
            5_000,
            "문단 중간에서 시작한 조각은 첫 줄 vpos를 다시 쓰면 안 된다"
        );
    }

    #[test]
    fn split_cell_snap_cap_uses_physical_content_bottom_not_valign_start() {
        // Center/Bottom valign의 text_y_start에는 이미 offset이 들어 있다. 물리 셀
        // 하단은 어떤 valign이든 cell_y + cell_h - pad_bottom으로 고정된다.
        assert_eq!(cell_content_bottom(100.0, 80.0, 7.0), 173.0);
    }

    fn clipped_cell_with_overflowing_nested_table() -> RenderNode {
        let mut cell = RenderNode::new(
            1,
            RenderNodeType::TableCell(TableCellNode {
                col: 0,
                row: 0,
                col_span: 1,
                row_span: 1,
                border_fill_id: 0,
                text_direction: 0,
                clip: true,
                closed_reflow_frame: false,
                page_fragment: false,
                model_cell_index: Some(0),
                model_para_range: None,
            }),
            BoundingBox::new(10.0, 20.0, 100.0, 80.0),
        );
        let mut table = RenderNode::new(
            2,
            RenderNodeType::Table(TableNode {
                row_count: 1,
                col_count: 1,
                border_fill_id: 0,
                section_index: None,
                para_index: None,
                control_index: None,
                cell_context: None,
            }),
            BoundingBox::new(15.0, 25.0, 90.0, 80.0),
        );
        table.children.push(RenderNode::new(
            3,
            RenderNodeType::Line(LineNode::new(15.0, 104.0, 105.0, 104.0, Default::default())),
            BoundingBox::new(15.0, 104.0, 90.0, 2.0),
        ));
        cell.children.push(table);
        cell
    }

    #[test]
    fn issue_4159_terminal_cell_clip_contains_nested_table_stroke() {
        let mut cell = clipped_cell_with_overflowing_nested_table();
        expand_terminal_cell_clip_to_nested_table_descendants(&mut cell, true);
        assert_eq!(cell.bbox.height, 86.0);
    }

    #[test]
    fn issue_4159_nonterminal_cell_clip_does_not_expose_nested_tail() {
        let mut cell = clipped_cell_with_overflowing_nested_table();
        expand_terminal_cell_clip_to_nested_table_descendants(&mut cell, false);
        assert_eq!(cell.bbox.height, 80.0);
    }

    #[test]
    fn issue_2007_recursive_cut_clip_only_contains_new_source_bounded_child() {
        let mut cell = clipped_cell_with_overflowing_nested_table();
        let first_new_child = cell.children.len();
        cell.children.push(RenderNode::new(
            4,
            RenderNodeType::Table(TableNode {
                row_count: 1,
                col_count: 1,
                border_fill_id: 0,
                section_index: None,
                para_index: None,
                control_index: None,
                cell_context: None,
            }),
            BoundingBox::new(15.0, 25.0, 90.0, 78.0),
        ));

        expand_cell_clip_to_new_source_bounded_children(&mut cell, first_new_child);

        assert_eq!(cell.bbox.height, 83.0);
    }
}