Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix usage of custom fonts in context2d #2834

Merged
merged 1 commit into from Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/modules/context2d.js
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.