diff --git a/src/modules/context2d.js b/src/modules/context2d.js index 2086b6be0..6bd5094e9 100644 --- a/src/modules/context2d.js +++ b/src/modules/context2d.js @@ -423,11 +423,15 @@ import { console } from "../libs/console.js"; var fontSizeUnit = rxFontSize.exec(fontSize)[2]; if ("px" === fontSizeUnit) { - fontSize = Math.floor(parseFloat(fontSize) * this.pdf.internal.scaleFactor); + fontSize = Math.floor( + parseFloat(fontSize) * this.pdf.internal.scaleFactor + ); } else if ("em" === fontSizeUnit) { fontSize = Math.floor(parseFloat(fontSize) * this.pdf.getFontSize()); } else { - fontSize = Math.floor(parseFloat(fontSize) * this.pdf.internal.scaleFactor); + fontSize = Math.floor( + parseFloat(fontSize) * this.pdf.internal.scaleFactor + ); } this.pdf.setFontSize(fontSize); @@ -450,21 +454,19 @@ import { console } from "../libs/console.js"; } var jsPdfFontName = ""; - var parts = fontFamily - .toLowerCase() - .replace(/"|'/g, "") - .split(/\s*,\s*/); + var parts = fontFamily.replace(/"|'/g, "").split(/\s*,\s*/); var fallbackFonts = { arial: "Helvetica", + Arial: "Helvetica", verdana: "Helvetica", + Verdana: "Helvetica", helvetica: "Helvetica", + Helvetica: "Helvetica", "sans-serif": "Helvetica", fixed: "Courier", monospace: "Courier", terminal: "Courier", - courier: "Courier", - times: "Times", cursive: "Times", fantasy: "Times", serif: "Times" diff --git a/test/reference/context2d-custom-fonts.pdf b/test/reference/context2d-custom-fonts.pdf new file mode 100644 index 000000000..229f5adfb Binary files /dev/null and b/test/reference/context2d-custom-fonts.pdf differ diff --git a/test/specs/context2d.spec.js b/test/specs/context2d.spec.js index 3b4044916..8d7472553 100644 --- a/test/specs/context2d.spec.js +++ b/test/specs/context2d.spec.js @@ -146,6 +146,25 @@ describe("Context2D: standard tests", () => { comparePdf(doc.output(), "fonts.pdf", "context2d"); }); + it("context2d: custom fonts", () => { + var PTSans = loadBinaryResource("reference/PTSans.ttf"); + + var doc = new jsPDF({ + orientation: "p", + unit: "pt", + format: "a4", + floatPrecision: 2 + }); + doc.addFileToVFS("PTSans.ttf", PTSans); + doc.addFont("PTSans.ttf", "PTSans", "normal"); + + var ctx = doc.context2d; + ctx.font = "normal 16pt PTSans"; + ctx.fillText("А ну чики брики и в дамки!", 20, 20); + + comparePdf(doc.output(), "context2d-custom-fonts.pdf", "context2d"); + }); + it("context2d: css color names", () => { var doc = new jsPDF({ orientation: "p",