Skip to content

Add fonts with different font-weights #2920

@whjvenyl

Description

@whjvenyl

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');

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions