Skip to content

Commit

Permalink
Merge pull request #2834 from HackbrettXXX/context2d-custom-fonts
Browse files Browse the repository at this point in the history
fix usage of custom fonts in context2d
  • Loading branch information
HackbrettXXX authored Aug 10, 2020
2 parents 511d4f6 + 1d7221d commit eb70ab2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/modules/context2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"
Expand Down
Binary file added test/reference/context2d-custom-fonts.pdf
Binary file not shown.
19 changes: 19 additions & 0 deletions test/specs/context2d.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eb70ab2

Please sign in to comment.