Repository navigation
Size tables by table-layout, <col> and <colgroup> widths, and row and table heights #606
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Part of #552 (step 28, missing support, medium priority).
Table sizing ignores four things templates set:
table-layout: column widths always come from the content.<col>and<colgroup>, whether as awidthattribute or in CSS.heightontrand ontable.- a percentage
heighton a cell.
Invoices and statements depend on fixed columns and fixed row heights.
Measured on gravitypdf at 60b82630, PHP 8.5.4, from the positions text is drawn at.
| Document | Browser | mPDF |
|---|---|---|
<table style="table-layout:fixed;width:100mm"><tr><td style="width:20mm"> 60 × x </td><td>b</td></tr></table> |
a 100 mm table: the first column 20 mm with the xs overflowing or broken, the second 80 mm |
the first column widens to 140 mm, and the table grows past 100 mm |
<table><col style="width:80mm"><col style="width:20mm"><tr><td>a</td><td>b</td></tr></table> |
columns of 80 and 20 mm | both as wide as their content |
the same with <colgroup><col width="80mm"><col width="20mm"></colgroup> |
columns of 80 and 20 mm | the same as above |
<tr style="height:30mm"> |
the row 30 mm tall | one line tall |
<table style="height:100mm"> with two one-line rows |
the rows share the 100 mm | one line each; the paragraph after the table follows at y = 34 mm |
<td style="height:50%"> in a 100 mm table |
half the table's height | ignored |
<td style="height:30mm"> |
30 mm | 30 mm (works) |
Cause.
table-layout. Never read._tableColumnWidth()(src/Mpdf.php:20547) and_tableWidth()(:21023) always size columns from their content's minimum and maximum widths.<col>and<colgroup>. There is noColorColgrouptag class, so both tags are dropped.- Heights.
Trnever readsHEIGHT.Tablereads noheightfor layout.Tdskips any value with%(src/Tag/Td.php:390-394).
Fix.
<col>and<colgroup>.- Add tag classes that record, per column index, the
width(attribute or CSS) andspan. _tableColumnWidth()treats a column's width as it treats the widestwidthamong the column's cells.- A cell's own
widthwins over its column's, as in the auto layout algorithm. - The other properties a
colcan carry (background,border,visibility: collapse) can come later.
- Add tag classes that record, per column index, the
table-layout: fixed. When the table has a width other thanauto, take the column widths from the<col>elements, and failing those from the first row's cells. Share out what is left equally, and never widen a column for its content. Content that does not fit wraps where it can, and breaks or overflows where it cannot, followingoverflow-wrap(Read thetext-decorationlonghands,text-align: startandend, andword-breakandoverflow-wrap#607). The layout no longer needs every row's content to be measured, but mPDF buffers the whole table anyway, so this is a sizing change, not a streaming one.- Heights.
heightontris a minimum row height, as on cells.heightontableis a minimum table height, shared out over the rows in proportion.- A
%height on a cell resolves against the table's height when it has one. - A row taller than a page still splits as rows do today.
Tests. Fixed and auto layout with the same content, <col> with span, <colgroup span>, <col> in a table with colspan cells, a fixed table narrower than its content, row and table heights in a table that crosses a page, and % cell heights with and without a table height.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity