@@ -44,12 +44,14 @@ This file is part of the iText (R) project.
44
44
package com .itextpdf .layout .element ;
45
45
46
46
import com .itextpdf .kernel .PdfException ;
47
+ import com .itextpdf .kernel .colors .ColorConstants ;
47
48
import com .itextpdf .kernel .pdf .tagging .StandardRoles ;
48
49
import com .itextpdf .kernel .pdf .tagutils .AccessibilityProperties ;
49
50
import com .itextpdf .kernel .pdf .tagutils .DefaultAccessibilityProperties ;
50
51
import com .itextpdf .layout .Document ;
51
52
import com .itextpdf .layout .borders .Border ;
52
53
import com .itextpdf .layout .property .BorderCollapsePropertyValue ;
54
+ import com .itextpdf .layout .property .CaptionSide ;
53
55
import com .itextpdf .layout .property .Property ;
54
56
import com .itextpdf .layout .property .UnitValue ;
55
57
import com .itextpdf .layout .renderer .IRenderer ;
@@ -87,6 +89,7 @@ public class Table extends BlockElement<Table> implements ILargeElement {
87
89
private int rowWindowStart = 0 ;
88
90
private Document document ;
89
91
private Cell [] lastAddedRow ;
92
+ private Div caption ;
90
93
91
94
/**
92
95
* Constructs a {@code Table} with the preferable column widths.
@@ -513,6 +516,54 @@ public Table setSkipLastFooter(boolean skipLastFooter) {
513
516
return this ;
514
517
}
515
518
519
+ /** Sets the table's caption.
520
+ *
521
+ * If there is no {@link Property#CAPTION_SIDE} set (note that it's an inheritable property),
522
+ * {@link CaptionSide#TOP} will be used.
523
+ * Also the {@link StandardRoles#CAPTION} will be set on the element.
524
+ *
525
+ * @param caption The element to be set as a caption.
526
+ * @return this element
527
+ */
528
+
529
+ public Table setCaption (Div caption ) {
530
+ this .caption = caption ;
531
+ if (null != caption ) {
532
+ ensureCaptionPropertiesAreSet ();
533
+ }
534
+ return this ;
535
+ }
536
+
537
+ /**
538
+ * Sets the table's caption and its caption side.
539
+ *
540
+ * Also the {@link StandardRoles#CAPTION} will be set on the element.
541
+ *
542
+ * @param caption The element to be set as a caption.
543
+ * @param side The caption side to be set on the caption.
544
+ ** @return this element
545
+ */
546
+ public Table setCaption (Div caption , CaptionSide side ) {
547
+ if (null != caption ) {
548
+ caption .setProperty (Property .CAPTION_SIDE , side );
549
+ }
550
+ setCaption (caption );
551
+ return this ;
552
+ }
553
+
554
+ private void ensureCaptionPropertiesAreSet () {
555
+ this .caption .getAccessibilityProperties ().setRole (StandardRoles .CAPTION );
556
+ }
557
+
558
+ /**
559
+ * Gets the table's caption.
560
+ *
561
+ * @return the table's caption.
562
+ */
563
+ public Div getCaption () {
564
+ return caption ;
565
+ }
566
+
516
567
/**
517
568
* Starts new row. This mean that next cell will be added at the beginning of next line.
518
569
*
@@ -798,7 +849,7 @@ public Table setBorderCollapse(BorderCollapsePropertyValue collapsePropertyValue
798
849
}
799
850
return this ;
800
851
}
801
-
852
+
802
853
public Table setHorizontalBorderSpacing (float spacing ) {
803
854
setProperty (Property .HORIZONTAL_BORDER_SPACING , spacing );
804
855
if (null != header ) {
@@ -820,7 +871,7 @@ public Table setVerticalBorderSpacing(float spacing) {
820
871
}
821
872
return this ;
822
873
}
823
-
874
+
824
875
@ Override
825
876
public AccessibilityProperties getAccessibilityProperties () {
826
877
if (tagProperties == null ) {
@@ -915,10 +966,10 @@ private void ensureHeaderIsInitialized() {
915
966
header .setBorderCollapse ((BorderCollapsePropertyValue ) this .<BorderCollapsePropertyValue >getProperty (Property .BORDER_COLLAPSE ));
916
967
}
917
968
if (hasOwnProperty (Property .HORIZONTAL_BORDER_SPACING )) {
918
- header .setHorizontalBorderSpacing ((float )this .<Float >getProperty (Property .HORIZONTAL_BORDER_SPACING ));
969
+ header .setHorizontalBorderSpacing ((float ) this .<Float >getProperty (Property .HORIZONTAL_BORDER_SPACING ));
919
970
}
920
971
if (hasOwnProperty (Property .VERTICAL_BORDER_SPACING )) {
921
- header .setVerticalBorderSpacing ((float )this .<Float >getProperty (Property .VERTICAL_BORDER_SPACING ));
972
+ header .setVerticalBorderSpacing ((float ) this .<Float >getProperty (Property .VERTICAL_BORDER_SPACING ));
922
973
}
923
974
}
924
975
}
@@ -933,10 +984,10 @@ private void ensureFooterIsInitialized() {
933
984
footer .setBorderCollapse ((BorderCollapsePropertyValue ) this .<BorderCollapsePropertyValue >getProperty (Property .BORDER_COLLAPSE ));
934
985
}
935
986
if (hasOwnProperty (Property .HORIZONTAL_BORDER_SPACING )) {
936
- footer .setHorizontalBorderSpacing ((float )this .<Float >getProperty (Property .HORIZONTAL_BORDER_SPACING ));
987
+ footer .setHorizontalBorderSpacing ((float ) this .<Float >getProperty (Property .HORIZONTAL_BORDER_SPACING ));
937
988
}
938
989
if (hasOwnProperty (Property .VERTICAL_BORDER_SPACING )) {
939
- footer .setVerticalBorderSpacing ((float )this .<Float >getProperty (Property .VERTICAL_BORDER_SPACING ));
990
+ footer .setVerticalBorderSpacing ((float ) this .<Float >getProperty (Property .VERTICAL_BORDER_SPACING ));
940
991
}
941
992
}
942
993
}
0 commit comments