1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-28 23:28:16 +02:00

XFA - Use fake MyriadPro as a fallback for missing fonts

- aims to fix #13597.
This commit is contained in:
Calixte Denizet 2021-07-10 16:18:45 +02:00
parent d416b23898
commit 690b5d1941
6 changed files with 62 additions and 31 deletions

View file

@ -83,8 +83,8 @@ class XFAFactory {
return null;
}
appendFonts(fonts) {
this.form[$globalData].fontFinder.add(fonts);
appendFonts(fonts, reallyMissingFonts) {
this.form[$globalData].fontFinder.add(fonts, reallyMissingFonts);
}
getPages() {

View file

@ -24,7 +24,7 @@ class FontFinder {
this.add(pdfFonts);
}
add(pdfFonts) {
add(pdfFonts, reallyMissingFonts = null) {
for (const pdfFont of pdfFonts) {
this.addPdfFont(pdfFont);
}
@ -33,6 +33,14 @@ class FontFinder {
pdfFont.regular = pdfFont.italic || pdfFont.bold || pdfFont.bolditalic;
}
}
if (!reallyMissingFonts || reallyMissingFonts.size === 0) {
return;
}
const myriad = this.fonts.get("PdfJS-Fallback-PdfJS-XFA");
for (const missing of reallyMissingFonts) {
this.fonts.set(missing, myriad);
}
}
addPdfFont(pdfFont) {
@ -47,13 +55,10 @@ class FontFinder {
}
}
let property = "";
if (cssFontInfo.italicAngle !== "0") {
if (parseFloat(cssFontInfo.fontWeight) >= 700) {
property = "bolditalic";
} else {
property = "italic";
}
} else if (parseFloat(cssFontInfo.fontWeight) >= 700) {
const fontWeight = parseFloat(cssFontInfo.fontWeight);
if (parseFloat(cssFontInfo.italicAngle) !== 0) {
property = fontWeight >= 700 ? "bolditalic" : "italic";
} else if (fontWeight >= 700) {
property = "bold";
}
@ -91,7 +96,7 @@ class FontFinder {
return font;
}
const pattern = /,|-| |bolditalic|bold|italic|regular|it/gi;
const pattern = /,|-|_| |bolditalic|bold|italic|regular|it/gi;
let name = fontName.replace(pattern, "");
font = this.fonts.get(name);
if (font) {