fop 0.1.1

FOP (Formatting Objects Processor) — Apache FOP-compatible XSL-FO processor in pure Rust
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
//! XSL-FO 1.1 Conformance: Writing modes, RTL/LTR/vertical, advanced list scenarios
//!
//! Part of the XSL-FO 1.1 conformance test suite.
//! Reference: https://www.w3.org/TR/xsl11/

use super::process_fo_document;

// ---------------------------------------------------------------------------
// Section 7.27: Writing mode and direction (RTL/LTR/vertical)
// ---------------------------------------------------------------------------

#[test]
fn conformance_rtl_writing_mode() {
    // fo:block with writing-mode="rl-tb" for Arabic/Hebrew (Section 7.27.7)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block writing-mode="lr-tb">Left to right (default): Hello World</fo:block>
      <fo:block writing-mode="rl-tb" xml:lang="ar">&#x645;&#x631;&#x62D;&#x628;&#x627; &#x628;&#x627;&#x644;&#x639;&#x627;&#x644;&#x645;</fo:block>
      <fo:block writing-mode="rl-tb" xml:lang="he">&#x5E9;&#x5DC;&#x5D5;&#x5DD; &#x5E2;&#x5D5;&#x5DC;&#x5DD;</fo:block>
      <fo:block writing-mode="lr-tb">Back to LTR text.</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "RTL writing-mode should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_direction_rtl() {
    // fo:block with direction="rtl" property (Section 7.27.1)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block direction="ltr">English text direction left-to-right.</fo:block>
      <fo:block direction="rtl" text-align="right">RTL block direction applied here.</fo:block>
      <fo:block>
        Mixed: <fo:inline direction="rtl">inline RTL</fo:inline> back to LTR.
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "direction property should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_vertical_writing_mode() {
    // fo:block with writing-mode="tb-rl" for CJK vertical text (Section 7.27.7)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="297mm" page-height="210mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block writing-mode="tb-rl" xml:lang="ja">&#x7E26;&#x66F8;&#x304D;&#x306E;&#x65E5;&#x672C;&#x8A9E;&#x30C6;&#x30AD;&#x30B9;&#x30C8;</fo:block>
      <fo:block writing-mode="tb-rl" xml:lang="zh">&#x4E2D;&#x6587;&#x5782;&#x76F4;&#x6392;&#x7248;</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Vertical writing-mode should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_bidi_mixed_content() {
    // Mixed LTR/RTL content with bidi-override (Section 7.27)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block>English with embedded <fo:bidi-override direction="rtl">&#x645;&#x631;&#x62D;&#x628;&#x627;</fo:bidi-override> Arabic.</fo:block>
      <fo:block writing-mode="rl-tb" xml:lang="ar">
        &#x639;&#x631;&#x628;&#x64A; &#x645;&#x639; <fo:bidi-override direction="ltr">English</fo:bidi-override> &#x645;&#x636;&#x645;&#x646;.
      </fo:block>
      <fo:block>Normal LTR paragraph continues.</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Bidi mixed content should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_external_graphic_scaling() {
    // fo:external-graphic with scaling attributes (Section 7.13.10)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block>Scale to fit within box:</fo:block>
      <fo:block>
        <fo:external-graphic src="url(placeholder.png)"
          content-width="80mm" content-height="60mm"
          scaling="uniform"/>
      </fo:block>
      <fo:block>Non-uniform scaling:</fo:block>
      <fo:block>
        <fo:external-graphic src="url(placeholder.png)"
          content-width="60mm" content-height="80mm"
          scaling="non-uniform"/>
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "external-graphic scaling should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_external_graphic_explicit_dimensions() {
    // fo:external-graphic with explicit width and height (Section 7.13)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block>Image with explicit dimensions:</fo:block>
      <fo:block>
        <fo:external-graphic src="url(test.jpg)"
          width="100mm" height="75mm"/>
      </fo:block>
      <fo:block>Scaled down to fit:</fo:block>
      <fo:block>
        <fo:external-graphic src="url(test.jpg)"
          content-width="scale-down-to-fit"
          content-height="scale-down-to-fit"
          width="50mm" height="50mm"/>
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "external-graphic explicit dimensions should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_external_graphic_alignment() {
    // fo:external-graphic with text-align and inline placement (Section 7.13)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block text-align="center" space-after="5mm">
        <fo:external-graphic src="url(centered.png)"
          content-width="60mm" content-height="45mm"/>
      </fo:block>
      <fo:block text-align="right" space-after="5mm">
        <fo:external-graphic src="url(right.png)"
          content-width="40mm" content-height="30mm"/>
      </fo:block>
      <fo:block>Image followed by caption text.</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "external-graphic alignment should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

// ---------------------------------------------------------------------------
// Section 8.4: Advanced list scenarios
// ---------------------------------------------------------------------------

#[test]
fn conformance_list_provisional_properties() {
    // fo:list-block with provisional-distance-between-starts (Section 8.4.2)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:list-block provisional-distance-between-starts="15mm"
        provisional-label-separation="2mm"
        space-after="6pt">
        <fo:list-item>
          <fo:list-item-label end-indent="label-end()">
            <fo:block>1.</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block>First item with custom provisional spacing</fo:block>
          </fo:list-item-body>
        </fo:list-item>
        <fo:list-item>
          <fo:list-item-label end-indent="label-end()">
            <fo:block>2.</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block>Second item in the list</fo:block>
          </fo:list-item-body>
        </fo:list-item>
        <fo:list-item>
          <fo:list-item-label end-indent="label-end()">
            <fo:block>3.</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block>Third item completes the list</fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </fo:list-block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "List with provisional properties should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_list_multiline_items() {
    // fo:list-item with multi-line body content (Section 8.4)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:list-block provisional-distance-between-starts="12mm">
        <fo:list-item space-after="6pt">
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block>This is the first item with a long description that wraps to multiple lines. The label should stay aligned at the top.</fo:block>
            <fo:block space-before="4pt">A second paragraph in the same list item.</fo:block>
          </fo:list-item-body>
        </fo:list-item>
        <fo:list-item space-after="6pt">
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block>Second item is shorter.</fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </fo:list-block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Multi-line list items should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_definition_list_pattern() {
    // Definition list pattern using fo:list-block (Section 8.4)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-size="14pt" font-weight="bold" space-after="8pt">Glossary</fo:block>
      <fo:list-block provisional-distance-between-starts="40mm"
        provisional-label-separation="5mm">
        <fo:list-item space-after="8pt">
          <fo:list-item-label end-indent="label-end()">
            <fo:block font-weight="bold">XSL-FO</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block>Extensible Stylesheet Language Formatting Objects. A markup language for XML document formatting.</fo:block>
          </fo:list-item-body>
        </fo:list-item>
        <fo:list-item space-after="8pt">
          <fo:list-item-label end-indent="label-end()">
            <fo:block font-weight="bold">PDF</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block>Portable Document Format. A file format for capturing and sending electronic documents.</fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </fo:list-block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Definition list pattern should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_mixed_ordered_unordered_lists() {
    // Mixed ordered and unordered list styles (Section 8.4)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-weight="bold">Steps:</fo:block>
      <fo:list-block provisional-distance-between-starts="10mm">
        <fo:list-item>
          <fo:list-item-label end-indent="label-end()">
            <fo:block>1.</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block>First step in the process</fo:block>
            <fo:block font-weight="bold" space-before="4pt">Notes:</fo:block>
            <fo:list-block provisional-distance-between-starts="8mm">
              <fo:list-item>
                <fo:list-item-label end-indent="label-end()">
                  <fo:block>&#x2013;</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                  <fo:block>Nested note one</fo:block>
                </fo:list-item-body>
              </fo:list-item>
              <fo:list-item>
                <fo:list-item-label end-indent="label-end()">
                  <fo:block>&#x2013;</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                  <fo:block>Nested note two</fo:block>
                </fo:list-item-body>
              </fo:list-item>
            </fo:list-block>
          </fo:list-item-body>
        </fo:list-item>
        <fo:list-item>
          <fo:list-item-label end-indent="label-end()">
            <fo:block>2.</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block>Second step completes the process</fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </fo:list-block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Mixed ordered/unordered lists should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_table_complex_spanning() {
    // Table with complex colspan and rowspan combinations (Section 9.3.5)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:table table-layout="fixed" width="150mm">
        <fo:table-column column-width="50mm"/>
        <fo:table-column column-width="50mm"/>
        <fo:table-column column-width="50mm"/>
        <fo:table-body>
          <fo:table-row>
            <fo:table-cell number-columns-spanned="2" number-rows-spanned="2"
              padding="2mm" border="1pt solid black" background-color="#e0e0e0">
              <fo:block font-weight="bold">Spans 2x2</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Top right</fo:block>
            </fo:table-cell>
          </fo:table-row>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Middle right</fo:block>
            </fo:table-cell>
          </fo:table-row>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Bottom left</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Bottom mid</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Bottom right</fo:block>
            </fo:table-cell>
          </fo:table-row>
        </fo:table-body>
      </fo:table>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Complex spanning should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_table_nested_block_content() {
    // Table cells with nested blocks, lists, and inline formatting (Section 9.3)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:table table-layout="fixed" width="160mm">
        <fo:table-column column-width="60mm"/>
        <fo:table-column column-width="100mm"/>
        <fo:table-body>
          <fo:table-row>
            <fo:table-cell padding="3mm" border="1pt solid #999999">
              <fo:block font-weight="bold">Feature</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="3mm" border="1pt solid #999999">
              <fo:block font-weight="bold">Description</fo:block>
            </fo:table-cell>
          </fo:table-row>
          <fo:table-row>
            <fo:table-cell padding="3mm" border="1pt solid #999999" display-align="before">
              <fo:block>Nested Lists</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="3mm" border="1pt solid #999999">
              <fo:block>Cell with a list:</fo:block>
              <fo:list-block provisional-distance-between-starts="8mm">
                <fo:list-item>
                  <fo:list-item-label end-indent="label-end()"><fo:block>&#x2022;</fo:block></fo:list-item-label>
                  <fo:list-item-body start-indent="body-start()"><fo:block>Item one</fo:block></fo:list-item-body>
                </fo:list-item>
                <fo:list-item>
                  <fo:list-item-label end-indent="label-end()"><fo:block>&#x2022;</fo:block></fo:list-item-label>
                  <fo:list-item-body start-indent="body-start()"><fo:block>Item two</fo:block></fo:list-item-body>
                </fo:list-item>
              </fo:list-block>
            </fo:table-cell>
          </fo:table-row>
          <fo:table-row>
            <fo:table-cell padding="3mm" border="1pt solid #999999">
              <fo:block>Formatting</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="3mm" border="1pt solid #999999">
              <fo:block>
                <fo:inline font-weight="bold">Bold</fo:inline>,
                <fo:inline font-style="italic">italic</fo:inline>,
                <fo:inline text-decoration="underline">underline</fo:inline>
              </fo:block>
            </fo:table-cell>
          </fo:table-row>
        </fo:table-body>
      </fo:table>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Table with nested content should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_table_text_wrap_cells() {
    // Table cells with long text that wraps to multiple lines (Section 9.3)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:table table-layout="fixed" width="160mm">
        <fo:table-column column-width="40mm"/>
        <fo:table-column column-width="120mm"/>
        <fo:table-body>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid black" font-weight="bold">
              <fo:block>Short</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>This is a much longer piece of text that should wrap to multiple lines within the narrow column, demonstrating proper text flow within table cells.</fo:block>
            </fo:table-cell>
          </fo:table-row>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid black" font-weight="bold">
              <fo:block>Also wraps</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Another long sentence that demonstrates text wrapping. The table row height should be determined by the tallest cell content.</fo:block>
            </fo:table-cell>
          </fo:table-row>
        </fo:table-body>
      </fo:table>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Table text wrap should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_table_mixed_column_widths() {
    // Table with fixed and proportional column widths mixed (Section 9.3.2)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:table table-layout="fixed" width="160mm">
        <fo:table-column column-width="30mm"/>
        <fo:table-column column-width="proportional-column-width(2)"/>
        <fo:table-column column-width="proportional-column-width(1)"/>
        <fo:table-body>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block font-weight="bold">Fixed 30mm</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Proportional 2x takes 2/3 of remaining</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Proportional 1x</fo:block>
            </fo:table-cell>
          </fo:table-row>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Row 2</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Wide cell content here</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Narrow</fo:block>
            </fo:table-cell>
          </fo:table-row>
        </fo:table-body>
      </fo:table>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Mixed column widths should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_table_complete_structure() {
    // Complete table structure: header + body + footer with all features (Section 9.3)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:table table-layout="fixed" width="160mm" border-collapse="collapse">
        <fo:table-column column-width="20mm"/>
        <fo:table-column column-width="60mm"/>
        <fo:table-column column-width="40mm"/>
        <fo:table-column column-width="40mm"/>
        <fo:table-header>
          <fo:table-row background-color="#336699">
            <fo:table-cell padding="2mm" border="1pt solid white">
              <fo:block color="white" font-weight="bold">#</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid white">
              <fo:block color="white" font-weight="bold">Product</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid white">
              <fo:block color="white" font-weight="bold">Qty</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid white">
              <fo:block color="white" font-weight="bold">Price</fo:block>
            </fo:table-cell>
          </fo:table-row>
        </fo:table-header>
        <fo:table-body>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid #cccccc"><fo:block>1</fo:block></fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid #cccccc"><fo:block>Widget A</fo:block></fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid #cccccc"><fo:block>10</fo:block></fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid #cccccc"><fo:block>$5.00</fo:block></fo:table-cell>
          </fo:table-row>
          <fo:table-row background-color="#f5f5f5">
            <fo:table-cell padding="2mm" border="1pt solid #cccccc"><fo:block>2</fo:block></fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid #cccccc"><fo:block>Gadget B</fo:block></fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid #cccccc"><fo:block>5</fo:block></fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid #cccccc"><fo:block>$12.50</fo:block></fo:table-cell>
          </fo:table-row>
        </fo:table-body>
        <fo:table-footer>
          <fo:table-row background-color="#e8e8e8">
            <fo:table-cell number-columns-spanned="2" padding="2mm" border="1pt solid #cccccc">
              <fo:block font-weight="bold">Total</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid #cccccc"><fo:block>15</fo:block></fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid #cccccc"><fo:block>$112.50</fo:block></fo:table-cell>
          </fo:table-row>
        </fo:table-footer>
      </fo:table>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Complete table structure should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_letter_word_spacing() {
    // Letter-spacing and word-spacing properties (Section 7.15.2)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block letter-spacing="0pt" space-after="6pt">Normal letter spacing: Hello World</fo:block>
      <fo:block letter-spacing="2pt" space-after="6pt">Wide letter spacing: Hello World</fo:block>
      <fo:block letter-spacing="-1pt" space-after="6pt">Narrow letter spacing: Hello World</fo:block>
      <fo:block word-spacing="10pt" space-after="6pt">Wide word spacing: Hello World</fo:block>
      <fo:block word-spacing="-2pt">Narrow word spacing: Hello World</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Letter and word spacing should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_text_rendering_modes() {
    // Various text rendering scenarios for quality (Section 7.15)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-size="8pt" space-after="4pt">8pt: The quick brown fox jumps over the lazy dog.</fo:block>
      <fo:block font-size="10pt" space-after="4pt">10pt: The quick brown fox jumps over the lazy dog.</fo:block>
      <fo:block font-size="12pt" space-after="4pt">12pt: The quick brown fox jumps over the lazy dog.</fo:block>
      <fo:block font-size="14pt" space-after="4pt">14pt: The quick brown fox jumps.</fo:block>
      <fo:block font-size="18pt" space-after="4pt">18pt: Quick brown fox.</fo:block>
      <fo:block font-size="24pt">24pt: Big text!</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Text rendering modes should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_inline_text_mixed_sizes() {
    // Mixed font sizes in inline content on same line (Section 7.15)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block line-height="20pt" space-after="8pt">
        Normal text with
        <fo:inline font-size="8pt"> small 8pt</fo:inline>
        and
        <fo:inline font-size="16pt"> large 16pt</fo:inline>
        and back to normal size.
      </fo:block>
      <fo:block>
        Chemical formula: H
        <fo:inline baseline-shift="sub" font-size="8pt">2</fo:inline>
        O + CO
        <fo:inline baseline-shift="sub" font-size="8pt">2</fo:inline>
      </fo:block>
      <fo:block space-before="6pt">
        Math: x
        <fo:inline baseline-shift="super" font-size="8pt">2</fo:inline>
        + y
        <fo:inline baseline-shift="super" font-size="8pt">2</fo:inline>
        = z
        <fo:inline baseline-shift="super" font-size="8pt">2</fo:inline>
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Mixed inline text sizes should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_multiple_footnotes() {
    // Multiple fo:footnote elements on the same page (Section 8.5)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block>First footnote
        <fo:footnote>
          <fo:inline baseline-shift="super" font-size="8pt">1</fo:inline>
          <fo:footnote-body>
            <fo:block font-size="9pt">1. First footnote text.</fo:block>
          </fo:footnote-body>
        </fo:footnote>
        and second footnote
        <fo:footnote>
          <fo:inline baseline-shift="super" font-size="8pt">2</fo:inline>
          <fo:footnote-body>
            <fo:block font-size="9pt">2. Second footnote text.</fo:block>
          </fo:footnote-body>
        </fo:footnote>
        in the same paragraph.
      </fo:block>
      <fo:block space-before="6pt">Another paragraph with a third footnote
        <fo:footnote>
          <fo:inline baseline-shift="super" font-size="8pt">3</fo:inline>
          <fo:footnote-body>
            <fo:block font-size="9pt">3. Third footnote in a different block.</fo:block>
          </fo:footnote-body>
        </fo:footnote>
        reference.
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Multiple footnotes should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_footnote_in_table() {
    // fo:footnote inside a table cell (Section 8.5)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:table table-layout="fixed" width="160mm">
        <fo:table-column column-width="80mm"/>
        <fo:table-column column-width="80mm"/>
        <fo:table-body>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Cell with footnote
                <fo:footnote>
                  <fo:inline baseline-shift="super" font-size="8pt">*</fo:inline>
                  <fo:footnote-body>
                    <fo:block font-size="9pt">* Table cell footnote.</fo:block>
                  </fo:footnote-body>
                </fo:footnote>
              </fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Regular cell content</fo:block>
            </fo:table-cell>
          </fo:table-row>
        </fo:table-body>
      </fo:table>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Footnote in table cell should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_keep_with_next_heading() {
    // fo:block keep-with-next to prevent orphaned headings (Section 7.20.3)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-size="16pt" font-weight="bold" keep-with-next="always" space-after="6pt">
        Section 1: Introduction
      </fo:block>
      <fo:block>This paragraph follows the section heading. The heading should never appear alone at the bottom of a page without at least one following paragraph.</fo:block>
      <fo:block space-before="8pt">Another paragraph in section 1 continues here.</fo:block>
      <fo:block font-size="16pt" font-weight="bold" keep-with-next="always" space-before="12pt" space-after="6pt">
        Section 2: Details
      </fo:block>
      <fo:block>Section 2 content follows immediately after the heading.</fo:block>
      <fo:block space-before="6pt">More section 2 content here.</fo:block>
      <fo:block font-size="14pt" font-weight="bold" keep-with-next="always" space-before="8pt" space-after="4pt">
        Subsection 2.1
      </fo:block>
      <fo:block>Subsection content.</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "keep-with-next heading should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_break_before_odd_even() {
    // break-before="page" for explicit page breaks (Section 7.20.2)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block>Chapter 1 content on page 1.</fo:block>
      <fo:block break-before="page">This starts on a new page.</fo:block>
      <fo:block space-before="6pt">Continued content on page 2.</fo:block>
      <fo:block break-before="page">Chapter 3 starts on page 3.</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "break-before page should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_keep_together_table() {
    // fo:table keep-together to prevent breaking mid-table (Section 7.20.1)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block>Some introductory content before the table.</fo:block>
      <fo:table table-layout="fixed" width="160mm" keep-together="always" space-before="8pt">
        <fo:table-column column-width="80mm"/>
        <fo:table-column column-width="80mm"/>
        <fo:table-body>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block font-weight="bold">Column A</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block font-weight="bold">Column B</fo:block>
            </fo:table-cell>
          </fo:table-row>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Row 1 data</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Row 1 value</fo:block>
            </fo:table-cell>
          </fo:table-row>
          <fo:table-row>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Row 2 data</fo:block>
            </fo:table-cell>
            <fo:table-cell padding="2mm" border="1pt solid black">
              <fo:block>Row 2 value</fo:block>
            </fo:table-cell>
          </fo:table-row>
        </fo:table-body>
      </fo:table>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "keep-together table should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_widow_orphan_paragraphs() {
    // Widow/orphan control for multi-paragraph content (Section 7.19.6)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block widows="2" orphans="2">
        The first paragraph has widow and orphan control set to 2. This means at least 2 lines must appear at the top of a new page and at least 2 lines must remain at the bottom of the previous page. This prevents isolated single lines.
      </fo:block>
      <fo:block space-before="6pt" widows="3" orphans="3">
        This paragraph sets both widows and orphans to 3. That means at least 3 lines must stay together at the bottom and at least 3 lines must appear together at the top of a page. This is a more conservative setting for important text.
      </fo:block>
      <fo:block space-before="6pt">
        This paragraph uses default widow/orphan values and contains enough text to test normal text flow across page boundaries in the document layout.
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Widow/orphan paragraphs should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}

#[test]
fn conformance_complex_multisequence_document() {
    // Complex document with multiple page sequences (Section 7.8)
    let result = process_fo_document(
        r##"<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="cover"
      page-width="210mm" page-height="297mm"
      margin-top="50mm" margin-bottom="50mm"
      margin-left="30mm" margin-right="30mm">
      <fo:region-body/>
    </fo:simple-page-master>
    <fo:simple-page-master master-name="toc"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body margin-top="12mm"/>
      <fo:region-before extent="12mm"/>
    </fo:simple-page-master>
    <fo:simple-page-master master-name="body"
      page-width="210mm" page-height="297mm"
      margin-top="20mm" margin-bottom="20mm"
      margin-left="20mm" margin-right="20mm">
      <fo:region-body margin-top="12mm" margin-bottom="12mm"/>
      <fo:region-before extent="12mm"/>
      <fo:region-after extent="12mm"/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="cover">
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-size="24pt" font-weight="bold" text-align="center" space-before="30mm">
        Document Title
      </fo:block>
      <fo:block font-size="14pt" text-align="center" space-before="10mm">
        Author Name
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
  <fo:page-sequence master-reference="toc" format="i" initial-page-number="1">
    <fo:static-content flow-name="xsl-region-before">
      <fo:block text-align="center" font-size="9pt">Table of Contents</fo:block>
    </fo:static-content>
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-size="14pt" font-weight="bold" space-after="8pt">Contents</fo:block>
      <fo:block>Chapter 1 .............. 1</fo:block>
      <fo:block>Chapter 2 .............. 5</fo:block>
    </fo:flow>
  </fo:page-sequence>
  <fo:page-sequence master-reference="body" format="1" initial-page-number="1">
    <fo:static-content flow-name="xsl-region-before">
      <fo:block text-align="right" font-size="9pt">Chapter 1</fo:block>
    </fo:static-content>
    <fo:static-content flow-name="xsl-region-after">
      <fo:block text-align="center" font-size="9pt">Page <fo:page-number/></fo:block>
    </fo:static-content>
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-size="16pt" font-weight="bold" id="ch1">Chapter 1: Introduction</fo:block>
      <fo:block space-before="6pt">First chapter content begins here with body text that flows across pages.</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>"##,
    );
    assert!(
        result.is_ok(),
        "Complex multi-sequence document should work: {:?}",
        result.err()
    );
    assert!(!result.expect("test: should succeed").is_empty());
}