From 6d54ffa88baa7c44712fe7ea3cbca27c484f36b9 Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Fri, 8 May 2026 00:29:10 +0200 Subject: [PATCH] fix: font registration to support italic styles in PDF generation --- packages/pdf/src/hooks/use-register-fonts.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/pdf/src/hooks/use-register-fonts.ts b/packages/pdf/src/hooks/use-register-fonts.ts index 1f2e725c0..a42401334 100644 --- a/packages/pdf/src/hooks/use-register-fonts.ts +++ b/packages/pdf/src/hooks/use-register-fonts.ts @@ -41,22 +41,25 @@ export const registerFonts = (typography: Typography) => { const bodyRange = getFontWeightRange(typography.body.fontWeights); const headingRange = getFontWeightRange(typography.heading.fontWeights); - const registerFont = (family: string, weight: number) => { + const registerFont = (family: string, weight: number, italic = false) => { if (isStandardPdfFontFamily(family)) return; const normalizedWeight = toFontWeight(weight); - const key = `${family}:${normalizedWeight}`; + const fontStyle = italic ? "italic" : "normal"; + const key = `${family}:${normalizedWeight}:${fontStyle}`; if (registeredFontVariants.has(key)) return; - const source = getWebFontSource(family, normalizedWeight); + const source = getWebFontSource(family, normalizedWeight, italic); if (!source) return; - Font.register({ family, src: source, fontWeight: Number(normalizedWeight) }); + Font.register({ family, src: source, fontWeight: Number(normalizedWeight), fontStyle }); registeredFontVariants.add(key); }; - registerFont(bodyFontFamily, bodyRange.lowest); - registerFont(bodyFontFamily, bodyRange.highest); - registerFont(headingFontFamily, headingRange.lowest); - registerFont(headingFontFamily, headingRange.highest); + for (const italic of [false, true]) { + registerFont(bodyFontFamily, bodyRange.lowest, italic); + registerFont(bodyFontFamily, bodyRange.highest, italic); + registerFont(headingFontFamily, headingRange.lowest, italic); + registerFont(headingFontFamily, headingRange.highest, italic); + } };