Skip to content

Commit e5a82f4

Browse files
committed
Add table auto layout documentation
DEVSIX-1252
1 parent 12fe56e commit e5a82f4

File tree

1 file changed

+38
-14
lines changed
  • layout/src/main/java/com/itextpdf/layout/element

1 file changed

+38
-14
lines changed

layout/src/main/java/com/itextpdf/layout/element/Table.java

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public class Table extends BlockElement<Table> implements ILargeElement {
100100
*
101101
* @param columnWidths preferable column widths in points. Values must be greater than or equal to zero,
102102
* otherwise it will be interpreted as undefined.
103-
* @param largeTable whether parts of the table will be written before all data is added.
103+
* @param largeTable whether parts of the table will be written before all data is added.
104+
* Note, large table do not support auto layout. Table width must be specified.
104105
* @see #setAutoLayout()
105106
* @see #setFixedLayout()
106107
*/
@@ -189,8 +190,8 @@ public Table(float[] pointColumnWidths) {
189190
}
190191

191192
/**
192-
* Constructs a {@code Table} with number of columns. Each column will get equal percent width.
193-
* 100% table width set implicitly for backward compatibility.
193+
* Constructs a {@code Table} with specified number of columns. Each column will get equal percent width,
194+
* the final column widths depend on selected table layout. 100% table width set implicitly for backward compatibility.
194195
* <br/>
195196
* Since 7.0.2 table layout algorithms were introduced. Auto layout is default, except large tables.
196197
* For large table fixed layout set implicitly.
@@ -203,6 +204,7 @@ public Table(float[] pointColumnWidths) {
203204
*
204205
* @param numColumns the number of columns, each column will have equal percent width.
205206
* @param largeTable whether parts of the table will be written before all data is added.
207+
* Note, large table do not support auto layout. Table width must be specified.
206208
* @see #setAutoLayout()
207209
* @see #setFixedLayout()
208210
* @deprecated in 7.1 each column will have undefined width.
@@ -225,8 +227,8 @@ public Table(int numColumns, boolean largeTable) {
225227
}
226228

227229
/**
228-
* Constructs a {@code Table} with number of columns. Each column will get equal percent width.
229-
* 100% table width set implicitly for backward compatibility.
230+
* Constructs a {@code Table} with specified number of columns. Each column will get equal percent width,
231+
* the final column widths depend on selected table layout. 100% table width set implicitly for backward compatibility.
230232
* <br/>
231233
* Since 7.0.2 table layout was introduced. Auto layout is default, except large tables.
232234
* For large table fixed layout set implicitly.
@@ -291,12 +293,23 @@ private static UnitValue[] normalizeColumnWidths(int numberOfColumns) {
291293
* <p/>
292294
* Algorithm description
293295
* <br/>
294-
* 1. Scan columns for width property and set it. (Columns have set in constructor, analog of {@code <colgroup>} element in HTML)<br/>
295-
* 2. Scan the very first row of table for width property and set it to undefined columns (cell width has lower priority in comparing with column).
296-
* If cell has colspan, each column will get equal width: {@code (width/colspan)}.<br/>
297-
* 3. If sum of columns is less, than table width, there are two options:<br/>
298-
* 3.1. If undefined columns still exist, they will get the rest remaining width.<br/>
299-
* 3.2. Otherwise all columns will be expanded proportionally based on its width.<br/>
296+
* 1. Scan columns for width property and set it. All the rest columns get undefined value.
297+
* Column width includes borders and paddings. Columns have set in constructor, analog of {@code <colgroup>} element in HTML.
298+
* <br/>
299+
* 2. Scan the very first row of table for width property and set it to undefined columns.
300+
* Cell width has lower priority in comparing with column. Cell width doesn't include borders and paddings.
301+
* <br/>
302+
* 2.1 If cell has colspan and all columns are undefined, each column will get equal width: {@code width/colspan}.
303+
* <br/>
304+
* 2.2 If some columns already have width, equal remain width will be added {@code remainWidth/colspan} to each column.
305+
* <br/>
306+
* 3. If sum of columns is less, than table width, there are two options:
307+
* <br/>
308+
* 3.1. If undefined columns still exist, they will get the rest remaining width.
309+
* <br/>
310+
* 3.2. Otherwise all columns will be expanded proportionally based on its width.
311+
* <br/>
312+
* 4. If sum of columns is greater, than table width, nothing to do.
300313
*
301314
* @return this element.
302315
*/
@@ -306,12 +319,23 @@ public Table setFixedLayout() {
306319
}
307320

308321
/**
309-
* Set auto layout.
322+
* Set auto layout. Analog of {@code table-layout:fixed} CSS property. <br />
323+
* Note, large table does not support auto layout.
310324
* <p/>
311-
* 1.
325+
* Algorithm principles.
326+
* <br/>
327+
* 1. Column width cannot be less, than min-width of any cell in the column (calculated by layout).
328+
* <br/>
329+
* 2. Specified table width has higher priority, than sum of column and cell widths.
330+
* <br/>
331+
* 3. Percent value of cell and column width has higher priority, than point value.
332+
* <br/>
333+
* 4. Cell width has higher priority, than column width.
334+
* <br/>
335+
* 5. If column has no width, it will try to reach max-value (calculated by layout).
336+
*
312337
* @return this element.
313338
*/
314-
315339
public Table setAutoLayout() {
316340
setProperty(Property.TABLE_LAYOUT, "auto");
317341
return this;

0 commit comments

Comments
 (0)