29 lines
1.3 KiB
JavaScript
29 lines
1.3 KiB
JavaScript
// Page geometry shared by the PDF header (render-sdlc.mjs) and the Word header
|
|
// band (render-ci-band.mjs), so both draw the same letterhead for a page.
|
|
//
|
|
// Portrait is the audited reference layout. Landscape pages are 87mm wider: the
|
|
// grey ribbon stretches and the blue banner keeps its distance from the right
|
|
// edge, while the logo and company block stay where they are.
|
|
export const PAGE_MM = { portrait: 210, landscape: 297 };
|
|
const EXTRA_MM = PAGE_MM.landscape - PAGE_MM.portrait;
|
|
|
|
export function headerValues(title, landscape) {
|
|
const extra = landscape ? EXTRA_MM : 0;
|
|
return {
|
|
documentTitle: title,
|
|
// The banner holds about 22 characters at 13.5pt; longer titles shrink to fit.
|
|
titleSize: `${Math.min(13.5, (13.5 * 22) / title.length).toFixed(1)}pt`,
|
|
pageWidth: `${landscape ? PAGE_MM.landscape : PAGE_MM.portrait}mm`,
|
|
ribbonWidth: `${64.7 + extra}mm`,
|
|
bannerLeft: `${127.2 + extra}mm`
|
|
};
|
|
}
|
|
|
|
/** Orientation of a rendered PDF, read from its first /MediaBox. */
|
|
export function isLandscapePdf(bytes) {
|
|
const box = bytes.toString('latin1').match(/\/MediaBox\s*\[\s*([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s*\]/);
|
|
if (!box) throw new Error('PDF has no /MediaBox');
|
|
const [x0, y0, x1, y1] = box.slice(1).map(Number);
|
|
return x1 - x0 > y1 - y0;
|
|
}
|