Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix: font registration to support italic styles in PDF generation

Amruth Pillai6d54ffa88baa
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);
+ }
};