Skip to content

"Font Awesome 6 Free Solid" not working in 2D context #3904

@Opineppes

Description

@Opineppes

Description:

When I try to set the font "Font Awesome 6 Free Solid" on the 2D context in jsPDF, nothing is displayed. After checking, it seems the regular expression used to validate font names does not allow numbers in the font name. I modified the regex to allow numbers.

Proposed fix:

I updated the regex in context2d.js to accept digits in font names.
Here’s the corrected regex:

🔗 Corrected regex

Relevant code:

rx = /^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-_,\"\'\sa-z]+?)\s*$/i;
matches = rx.exec(value);
if (matches !== null) {
var fontStyle = matches[1];
var fontVariant = matches[2];
var fontWeight = matches[3];
var fontSize = matches[4];
var lineHeight = matches[5];
var fontFamily = matches[6];
} else {
return;
}

This modification allows numbers in font names and should fix the display issue.

Expected behavior:

After this change, the font "Font Awesome 6 Free Solid" should render correctly in the 2D context of jsPDF.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions