- Notifications
You must be signed in to change notification settings - Fork 4.8k
Open
Description
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:
Relevant code:
jsPDF/src/modules/context2d.js
Lines 556 to 567 in c10d90c
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
Labels
No labels