fix: derive single line spacing from the font, not a fixed 1.15
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.
This commit is contained in:
1 parent
b1c515fd2f
commit
52cf5ac702
1 file changed
+16
-1
@@ -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<string, number> = {
|
||||
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'}`);
|
||||
|
||||
Reference in new issue
Block a user