feat: a cell keeps its own margins where they differ from the table's
w:tcMar and an ODF cell style's own fo:padding were both dropped: the table's value (in ODF the first cell's) stood for every cell. cellPadding is now an attr on tableCell/tableHeader too, measured against the table's rather than the editor default, so only a real disagreement carries one. --cell-pad inherits, so the cell's own declaration wins for its own td and the CSS is unchanged. Checked against LibreOffice: a 1.2cm cell in a 0.3cm table puts its text at 332.2pt where the grid column starts at 297.6.
This commit is contained in:
1 parent
aad4e7a3e4
commit
ca3767f3d4
8 files changed
+81
-36
No files matched your search
@@ -120,9 +120,6 @@ LibreOffice's 48, with 62 line-level differences, most of them the justification
|
||||
where Word moves the text to the next list tab — reading `w:lvl/w:pPr/w:ind w:hanging`
|
||||
would settle it. Deliberate for now: in flow, a wide marker pushed the text and cost
|
||||
the thesis fixture a page.
|
||||
- **A cell's own margins are not read**, only the table's (`w:tcMar`; ODF puts padding on
|
||||
every cell style, and we take the first cell's for the whole table). No producer in
|
||||
the corpus writes per-cell margins.
|
||||
- Lines whose natural width lands within ~0.2mm of the right margin may take one word
|
||||
more or fewer than LibreOffice. Sub-0.1mm engine rounding, not a layout rule.
|
||||
|
||||
|
||||
@@ -46,6 +46,31 @@ describe('table cell padding', () => {
|
||||
// Word's 108 twips and LibreOffice's 0.191cm are both our 0.19cm default.
|
||||
expect(cellPaddingAttr([0, 0.1905, 0, 0.191])).toBeNull();
|
||||
expect(cellPaddingAttr([0.026, 0.026, 0.026, 0.026])).toEqual([0.026, 0.026, 0.026, 0.026]);
|
||||
// A cell measures against its table's, so the editor default is an override there
|
||||
// and its own table's value is not.
|
||||
expect(cellPaddingAttr([0, 0.19, 0, 0.19], [0.3, 0.3, 0.3, 0.3])).toEqual([0, 0.19, 0, 0.19]);
|
||||
expect(cellPaddingAttr([0.3, 0.3, 0.3, 0.3], [0.3, 0.3, 0.3, 0.3])).toBeNull();
|
||||
// An undeclared side falls back to the table's, not the editor default.
|
||||
expect(cellPaddingAttr([0.1, null, null, null], [0.3, 0.3, 0.3, 0.3])).toEqual([0.1, 0.3, 0.3, 0.3]);
|
||||
});
|
||||
|
||||
it('round-trips one cell’s own margins against the table’s', async () => {
|
||||
const mixed: N = structuredClone(doc);
|
||||
mixed.content[1].attrs = { cellPadding: [0.3, 0.3, 0.3, 0.3] };
|
||||
mixed.content[1].content[0].content[1].attrs.cellPadding = [0.02, 0.6, 0.02, 0.6];
|
||||
const margins = { top: 2, bottom: 2, left: 2, right: 2 };
|
||||
const cellOf = (d: N, row: number, col: number) =>
|
||||
(d.content!.find((n: N) => n.type === 'table') as N).content[row].content[col];
|
||||
|
||||
const odt = await importOdt(await buildOdt(mixed, margins, 'portrait'));
|
||||
expect(cellOf(odt.content, 0, 0).attrs?.cellPadding ?? null).toBeNull();
|
||||
expect(cellOf(odt.content, 0, 1).attrs?.cellPadding).toEqual([0.02, 0.6, 0.02, 0.6]);
|
||||
|
||||
const docx = importDocx(await buildDocx(mixed, margins, 'portrait'));
|
||||
expect(cellOf(docx.content, 0, 0).attrs?.cellPadding ?? null).toBeNull();
|
||||
for (const [i, cm] of [0.02, 0.6, 0.02, 0.6].entries()) {
|
||||
expect(cellOf(docx.content, 0, 1).attrs?.cellPadding[i]).toBeCloseTo(cm, 2);
|
||||
}
|
||||
});
|
||||
|
||||
it('round-trips a table’s own cell margins', async () => {
|
||||
|
||||
Reference in new issue
Block a user