import { describe, it, expect } from 'vitest';
import { zipSync, strToU8 } from 'fflate';
import { importOdt } from '../../src/lib/import/odt';
// table:align="margins" is a table stretched between the text margins. Its style:width
// is the width the producing page had, so deriving a margin from it against ours leaves
// the table narrow — measured 12.4cm on a 14.7cm text width.
const NS =
'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ' +
'xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" ' +
'xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" ' +
'xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ' +
'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"';
function odtWithTable(tableProps: string): Uint8Array {
const styles = `
`;
const content = `
a
`;
return zipSync({ 'content.xml': strToU8(content), 'styles.xml': strToU8(styles) });
}
const attrsOf = (tableProps: string) =>
(importOdt(odtWithTable(tableProps)).content.content?.[0] as { attrs?: Record }).attrs ?? {};
describe('a table aligned to the margins', () => {
it('keeps the full text width whatever width the producer wrote', () => {
const attrs = attrsOf('style:width="14.7cm" table:align="margins"');
expect(attrs.marginLeft).toBeUndefined();
expect(attrs.marginRight).toBeUndefined();
});
it('still honours the margins the file declares itself', () => {
const attrs = attrsOf('style:width="12cm" table:align="margins" fo:margin-left="1.5cm"');
expect(attrs.marginLeft).toBe(1.5);
expect(attrs.marginRight).toBeUndefined();
});
it('leaves a centred table centred', () => {
const attrs = attrsOf('style:width="10.7cm" table:align="center"');
expect(attrs.marginLeft).toBe(2);
expect(attrs.marginRight).toBe(2);
});
});