mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-27 02:14:50 +10:00
fix: font registration to support italic styles in PDF generation
This commit is contained in:
@@ -41,22 +41,25 @@ export const registerFonts = (typography: Typography) => {
|
|||||||
const bodyRange = getFontWeightRange(typography.body.fontWeights);
|
const bodyRange = getFontWeightRange(typography.body.fontWeights);
|
||||||
const headingRange = getFontWeightRange(typography.heading.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;
|
if (isStandardPdfFontFamily(family)) return;
|
||||||
|
|
||||||
const normalizedWeight = toFontWeight(weight);
|
const normalizedWeight = toFontWeight(weight);
|
||||||
const key = `${family}:${normalizedWeight}`;
|
const fontStyle = italic ? "italic" : "normal";
|
||||||
|
const key = `${family}:${normalizedWeight}:${fontStyle}`;
|
||||||
if (registeredFontVariants.has(key)) return;
|
if (registeredFontVariants.has(key)) return;
|
||||||
|
|
||||||
const source = getWebFontSource(family, normalizedWeight);
|
const source = getWebFontSource(family, normalizedWeight, italic);
|
||||||
if (!source) return;
|
if (!source) return;
|
||||||
|
|
||||||
Font.register({ family, src: source, fontWeight: Number(normalizedWeight) });
|
Font.register({ family, src: source, fontWeight: Number(normalizedWeight), fontStyle });
|
||||||
registeredFontVariants.add(key);
|
registeredFontVariants.add(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
registerFont(bodyFontFamily, bodyRange.lowest);
|
for (const italic of [false, true]) {
|
||||||
registerFont(bodyFontFamily, bodyRange.highest);
|
registerFont(bodyFontFamily, bodyRange.lowest, italic);
|
||||||
registerFont(headingFontFamily, headingRange.lowest);
|
registerFont(bodyFontFamily, bodyRange.highest, italic);
|
||||||
registerFont(headingFontFamily, headingRange.highest);
|
registerFont(headingFontFamily, headingRange.lowest, italic);
|
||||||
|
registerFont(headingFontFamily, headingRange.highest, italic);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user