Add fonts with different font-weights
See original GitHub issueCross-Link to original issue #199.
Request to extend the ‘addFont’ with an additional parameter for font-weights. (or even better, replace the ‘font-style’ definition):
Why: As of now, there’s a missmatch between the possibility to define font-weights and font-styles in css and what’s possible in jsPDF. Several popular font-families consist out of several individual fonts, which define their style primarly on the font-weight, not the font-style.
For example, the popular Roboto font defines for ‘bold’ either the Roboto-Medium (with 500 weight) and Roboto-Bold (with 700 weight). With the current implementation and the font-matching done purely on font-style, it is not possible to have both of those fonts defined in the same pdf-report. (since font weight maps to [‘normal’, ‘italic’, ‘bold’, … ])
font-face declaration of roboto medium:
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 500;
src: local('Roboto Medium'), local('Roboto-Medium'),
font('Roboto-Medium.woff2') format('woff2'),
font('Roboto-Medium.woff') format('woff');
font-display: swap;
}
currently possible to be render it in jspdf with:
doc.addFileToVFS('Roboto-Medium.ttf', robotoMedium);
doc.addFont('Roboto-Medium.ttf', 'Roboto', 'normal');
desired call with font-weight:
doc.addFont('Roboto-Medium.ttf', 'Roboto', 'normal', '500');
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top GitHub Comments
Resolved in #3036.
I think throwing an error is good 😃