Skip to content

Commit e7dc622

Browse files
Opineppesquentin.legrandHackbrettXXX
authored
Fix: Context2d font regex too restrictive ( #3904 ) (#3906)
--------- Co-authored-by: quentin.legrand <[email protected]> Co-authored-by: Lukas Holländer <[email protected]>
1 parent e080935 commit e7dc622

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/modules/context2d.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ import {
553553

554554
//source: https://stackoverflow.com/a/10136041
555555
// eslint-disable-next-line no-useless-escape
556-
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;
556+
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-z0-9]+?)\s*$/i;
557557
matches = rx.exec(value);
558558
if (matches !== null) {
559559
var fontStyle = matches[1];

test/reference/fa-solid-900.ttf

391 KB
Binary file not shown.

test/specs/context2d.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,24 @@ describe("Context2D: standard tests", () => {
164164
comparePdf(doc.output(), "context2d-custom-fonts.pdf", "context2d");
165165
});
166166

167+
it("context2d: custom fonts name regex", () => {
168+
const FaSolid = loadBinaryResource("reference/fa-solid-900.ttf");
169+
170+
const doc = new jsPDF({
171+
orientation: "p",
172+
unit: "pt",
173+
format: "a4",
174+
floatPrecision: 2
175+
});
176+
doc.addFileToVFS("fa-solid-900.ttf", FaSolid);
177+
doc.addFont("fa-solid-900.ttf", "Font Awesome 6 Free Solid", "normal");
178+
179+
const ctx = doc.context2d;
180+
ctx.font = "normal 16pt \"Font Awesome 6 Free Solid\"";
181+
182+
expect(doc.getFont().fontName).toBe("Font Awesome 6 Free Solid");
183+
});
184+
167185
it("context2d: css color names", () => {
168186
var doc = new jsPDF({
169187
orientation: "p",

0 commit comments

Comments
 (0)