question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add fonts with different font-weights

See original GitHub issue

Cross-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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
HackbrettXXXcommented, Dec 22, 2020

Resolved in #3036.

1reaction
HackbrettXXXcommented, Dec 11, 2020

I think throwing an error is good 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple font-weights, one @font-face query - Stack Overflow
Here's an example using the same font-family name with different styles and weights associated with different fonts:
Read more >
How To Set Weights And Styles With The @font-face Declaration
Another way to set weights and styles is to use the same font-family name multiple times, setting the weights and styles in each...
Read more >
font-weight - CSS: Cascading Style Sheets - MDN Web Docs
The font-weight CSS descriptor allows authors to specify font weights for the fonts specified in the @font-face rule. The font-weight ...
Read more >
Using multiple font files the right way - HackSoft
Multiple font files for a single font can lead to a messy css if you ... for different font weights (light, bold) and...
Read more >
Add fonts with different font-weights · Issue #2920 - GitHub
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 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found