Skip to content

Commit 7de83db

Browse files
authored
Fill the table grid from the cell widths (#45)
Word lays a table out from w:tblGrid, and the grid was always written as an even split. Cell widths were emitted faithfully onto every tcW and then had no effect: the columns rendered equal however wide the cells said they were. The widths being present and correct in the XML is what made it hard to see, since reading the output suggested nothing was wrong. Column widths now come from col/colgroup where it is present, and otherwise from the first row that maps one cell to one column. A row carrying a colspan or rowspan is skipped, since the mapping is ambiguous, and so is one where only some cells give a width, since half a row cannot lay out a table. Percentages still cannot fill the grid - w:gridCol has no percentage unit, the same reason col percentages are ignored - so they continue to apply to the cells alone. Sharing an absolute table width across the columns now happens only when the cells give no widths of their own. That combination was the worst case: a table with an explicit width and sized cells took the even share, so the widths were not merely inert but overwritten. The five updated snapshots all move the same way, from a bare gridCol to a sized one plus the fixed layout that makes Word honour it. Closes #44
1 parent fac4561 commit 7de83db

15 files changed

Lines changed: 122 additions & 9 deletions

readme.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,19 @@ Reporting is opt-in and costs nothing while `OnDiagnostic` is null. The callback
476476
`width` accepts the same units as the attribute above
477477
* Table CSS: `width`, `background-color`, `padding` (default cell padding) (Word). An absolute
478478
table `width` is shared across the columns and switches the table to fixed layout, since Word's
479-
default autofit treats the width as a preference and resizes columns to their content
479+
default autofit treats the width as a preference and resizes columns to their content. The share
480+
only applies when the cells give no widths of their own
480481
* Row CSS: `height` or HTML `height` attribute on `<tr>` (Word)
481482
* `col` / `colgroup` widths must be absolute — Word's `w:gridCol` has no percentage unit, so a
482483
percentage there is ignored
483484

485+
Word lays a table out from `w:tblGrid`, not from the cells, so column widths have to reach the grid
486+
to have any effect. They are taken from `col`/`colgroup` where it is present, and otherwise from the
487+
first row that maps one cell to one column — a row carrying a `colspan` or `rowspan` is skipped as
488+
ambiguous, and so is one where only some cells give a width, since half a row cannot lay out a
489+
table. Percentage cell widths still apply to the cells themselves but cannot fill the grid, for the
490+
same reason `col` percentages are ignored.
491+
484492

485493
### Inline / Other
486494

Binary file not shown.
260 Bytes
Loading
Binary file not shown.
Binary file not shown.
957 Bytes
Loading
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:tblPr><w:tblW w:w="0" w:type="auto" /><w:tblBorders><w:top w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:left w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:bottom w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:right w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideH w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideV w:val="single" w:color="auto" w:sz="4" w:space="0" /></w:tblBorders></w:tblPr><w:tblGrid><w:gridCol /></w:tblGrid><w:tr><w:tc><w:tcPr><w:tcW w:w="525" w:type="dxa" /></w:tcPr><w:p><w:r><w:t xml:space="preserve">A</w:t></w:r></w:p></w:tc></w:tr></w:tbl>
1+
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:tblPr><w:tblW w:w="0" w:type="auto" /><w:tblBorders><w:top w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:left w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:bottom w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:right w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideH w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideV w:val="single" w:color="auto" w:sz="4" w:space="0" /></w:tblBorders><w:tblLayout w:type="fixed" /></w:tblPr><w:tblGrid><w:gridCol w:w="525" /></w:tblGrid><w:tr><w:tc><w:tcPr><w:tcW w:w="525" w:type="dxa" /></w:tcPr><w:p><w:r><w:t xml:space="preserve">A</w:t></w:r></w:p></w:tc></w:tr></w:tbl>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:tblPr><w:tblW w:w="0" w:type="auto" /><w:tblBorders><w:top w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:left w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:bottom w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:right w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideH w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideV w:val="single" w:color="auto" w:sz="4" w:space="0" /></w:tblBorders></w:tblPr><w:tblGrid><w:gridCol /></w:tblGrid><w:tr><w:tc><w:tcPr><w:tcW w:w="525" w:type="dxa" /></w:tcPr><w:p><w:r><w:t xml:space="preserve">A</w:t></w:r></w:p></w:tc></w:tr></w:tbl>
1+
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:tblPr><w:tblW w:w="0" w:type="auto" /><w:tblBorders><w:top w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:left w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:bottom w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:right w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideH w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideV w:val="single" w:color="auto" w:sz="4" w:space="0" /></w:tblBorders><w:tblLayout w:type="fixed" /></w:tblPr><w:tblGrid><w:gridCol w:w="525" /></w:tblGrid><w:tr><w:tc><w:tcPr><w:tcW w:w="525" w:type="dxa" /></w:tcPr><w:p><w:r><w:t xml:space="preserve">A</w:t></w:r></w:p></w:tc></w:tr></w:tbl>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:tblPr><w:tblW w:w="0" w:type="auto" /><w:tblBorders><w:top w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:left w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:bottom w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:right w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideH w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideV w:val="single" w:color="auto" w:sz="4" w:space="0" /></w:tblBorders></w:tblPr><w:tblGrid><w:gridCol /></w:tblGrid><w:tr><w:tc><w:tcPr><w:tcW w:w="3750" w:type="dxa" /></w:tcPr><w:p><w:r><w:t xml:space="preserve">A</w:t></w:r></w:p></w:tc></w:tr></w:tbl>
1+
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:tblPr><w:tblW w:w="0" w:type="auto" /><w:tblBorders><w:top w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:left w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:bottom w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:right w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideH w:val="single" w:color="auto" w:sz="4" w:space="0" /><w:insideV w:val="single" w:color="auto" w:sz="4" w:space="0" /></w:tblBorders><w:tblLayout w:type="fixed" /></w:tblPr><w:tblGrid><w:gridCol w:w="3750" /></w:tblGrid><w:tr><w:tc><w:tcPr><w:tcW w:w="3750" w:type="dxa" /></w:tcPr><w:p><w:r><w:t xml:space="preserve">A</w:t></w:r></w:p></w:tc></w:tr></w:tbl>

0 commit comments

Comments
 (0)