From 52cf5ac70235ac975e733d943a1fe2911c7c9d62 Mon Sep 17 00:00:00 2001 From: Steffen Becker Date: Thu, 6 Aug 2026 19:19:06 +0000 Subject: [PATCH] fix: derive single line spacing from the font, not a fixed 1.15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Single spacing is the font's natural line height. The hardcoded 1.15 is Liberation Serif's (and Liberation Sans' and Caladea's), but Carlito needs 1.2208 and Liberation Mono 1.1333 — measured against LibreOffice at 12pt. A Calibri body ran 6% too tight, drifting a line per page. Emitted next to font-family, so an explicit line spacing still wins. --- src/lib/styles/styleSheet.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lib/styles/styleSheet.ts b/src/lib/styles/styleSheet.ts index 94494f3..067fec6 100644 --- a/src/lib/styles/styleSheet.ts +++ b/src/lib/styles/styleSheet.ts @@ -198,10 +198,25 @@ function cssFontFamily(name: string): string { return `'${name.replace(/'/g, "\\'")}', var(--font-serif)`; } +// Single spacing is the font's *natural* line height, so it differs per family. +// editor.css covers Liberation Serif's 1.15; only the bundled families that deviate +// are listed, measured against LibreOffice at 12pt. +const SINGLE_LINE_HEIGHT: Record = { + Calibri: 1.2208, + Carlito: 1.2208, + 'Courier New': 1.1333, + 'Liberation Mono': 1.1333, +}; + // The text half of a rule, shared with the table-style family (tableStyles.ts). export function textDeclarations(t: TextProps): string[] { const out: string[] = []; - if (t.fontFamily) out.push(`font-family: ${cssFontFamily(t.fontFamily)}`); + if (t.fontFamily) { + out.push(`font-family: ${cssFontFamily(t.fontFamily)}`); + const lh = SINGLE_LINE_HEIGHT[t.fontFamily]; + // An explicit line spacing is emitted after this and wins. + if (lh) out.push(`line-height: ${lh}`); + } if (t.fontSizePt != null) out.push(`font-size: ${t.fontSizePt}pt`); if (t.bold != null) out.push(`font-weight: ${t.bold ? 700 : 400}`); if (t.italic != null) out.push(`font-style: ${t.italic ? 'italic' : 'normal'}`);