Files
edentext/tests/unit/hf-zone-margins.test.ts
T
Steffen Becker 86cacc40b1 fix: the space below a zone's last paragraph is no part of its band
Probed: a header of one 10pt line with a 12mm bottom margin puts the body at the
band's min-height, not 12mm lower, and a footer's trailing margin is dropped the
same way — while a margin between two of the zone's paragraphs counts in full
(two lines 12mm apart give a 20.16mm band). The collapsed zone paragraph carries
only the margins between its source paragraphs now. One 16-page fixture went
183 reports → 5, its body having sat 10.3mm low on every page.
2026-09-04 19:30:09 +02:00

38 lines
1.7 KiB
TypeScript

// A header/footer zone's own vertical margins: LibreOffice keeps them on the Header /
// Footer paragraph style. A footer's space above grows the band; the space *below* the
// zone's last paragraph does not — LibreOffice drops it, so neither zone carries it back.
import { describe, it, expect } from 'vitest';
import { unzipSync, strFromU8 } from 'fflate';
import { buildOdt } from '../../src/lib/export/odt';
import { importOdt } from '../../src/lib/import/odt';
type N = any;
const doc: N = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Body' }] }] };
const zone = (attrs: N, text: string): N => ({
type: 'doc',
content: [{ type: 'paragraph', attrs, content: [{ type: 'text', text }] }],
});
const hf = {
header: zone({ spaceAfter: 34 }, 'Kopf'),
footer: zone({ spaceBefore: 24 }, 'Fuss'),
headerFirst: null, footerFirst: null, differentFirstPage: false,
headerEven: null, footerEven: null, differentOddEven: false,
pageCount: 1,
};
describe('header/footer zone margins', () => {
it('ride the ODF zone styles and come back', async () => {
const bytes = await buildOdt(doc, undefined, 'portrait', hf);
const styles = strFromU8(unzipSync(bytes)['styles.xml']);
expect(styles).toContain('fo:margin-bottom="34pt"');
expect(styles).toContain('fo:margin-top="24pt"');
const back = await importOdt(bytes);
expect(back.footer?.content?.[0]?.attrs?.spaceBefore).toBeCloseTo(24, 1);
// Probed: a header of one 10pt line with a 12mm bottom margin puts the body at the
// band's min-height, not 12mm lower — the trailing margin is no part of the band.
expect(back.header?.content?.[0]?.attrs?.spaceAfter ?? 0).toBe(0);
});
});