Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modules/context2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ import {

//source: https://stackoverflow.com/a/10136041
// eslint-disable-next-line no-useless-escape
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;
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;
matches = rx.exec(value);
if (matches !== null) {
var fontStyle = matches[1];
Expand Down
Binary file added test/reference/fa-solid-900.ttf
Binary file not shown.
18 changes: 18 additions & 0 deletions test/specs/context2d.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ describe("Context2D: standard tests", () => {
comparePdf(doc.output(), "context2d-custom-fonts.pdf", "context2d");
});

it("context2d: custom fonts name regex", () => {
const FaSolid = loadBinaryResource("reference/fa-solid-900.ttf");

const doc = new jsPDF({
orientation: "p",
unit: "pt",
format: "a4",
floatPrecision: 2
});
doc.addFileToVFS("fa-solid-900.ttf", FaSolid);
doc.addFont("fa-solid-900.ttf", "Font Awesome 6 Free Solid", "normal");

const ctx = doc.context2d;
ctx.font = "normal 16pt \"Font Awesome 6 Free Solid\"";

expect(doc.getFont().fontName).toBe("Font Awesome 6 Free Solid");
});

it("context2d: css color names", () => {
var doc = new jsPDF({
orientation: "p",
Expand Down