XFA - Use fake MyriadPro as a fallback for missing fonts
- aims to fix #13597.
This commit is contained in:
parent
d416b23898
commit
690b5d1941
@ -993,7 +993,22 @@ class PDFDocument {
|
|||||||
promises.length = 0;
|
promises.length = 0;
|
||||||
pdfFonts.length = 0;
|
pdfFonts.length = 0;
|
||||||
|
|
||||||
|
const reallyMissingFonts = new Set();
|
||||||
for (const missing of missingFonts) {
|
for (const missing of missingFonts) {
|
||||||
|
if (!getXfaFontWidths(`${missing}-Regular`)) {
|
||||||
|
// No substitution available: we'll fallback on Myriad.
|
||||||
|
reallyMissingFonts.add(missing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reallyMissingFonts.size) {
|
||||||
|
missingFonts.push("PdfJS-Fallback");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const missing of missingFonts) {
|
||||||
|
if (reallyMissingFonts.has(missing)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (const fontInfo of [
|
for (const fontInfo of [
|
||||||
{ name: "Regular", fontWeight: 400, italicAngle: 0 },
|
{ name: "Regular", fontWeight: 400, italicAngle: 0 },
|
||||||
{ name: "Bold", fontWeight: 700, italicAngle: 0 },
|
{ name: "Bold", fontWeight: 700, italicAngle: 0 },
|
||||||
@ -1002,10 +1017,6 @@ class PDFDocument {
|
|||||||
]) {
|
]) {
|
||||||
const name = `${missing}-${fontInfo.name}`;
|
const name = `${missing}-${fontInfo.name}`;
|
||||||
const widths = getXfaFontWidths(name);
|
const widths = getXfaFontWidths(name);
|
||||||
if (!widths) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dict = new Dict(null);
|
const dict = new Dict(null);
|
||||||
dict.set("BaseFont", Name.get(name));
|
dict.set("BaseFont", Name.get(name));
|
||||||
dict.set("Type", Name.get("Font"));
|
dict.set("Type", Name.get("Font"));
|
||||||
@ -1040,7 +1051,7 @@ class PDFDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
this.xfaFactory.appendFonts(pdfFonts);
|
this.xfaFactory.appendFonts(pdfFonts, reallyMissingFonts);
|
||||||
}
|
}
|
||||||
|
|
||||||
async serializeXfaData(annotationStorage) {
|
async serializeXfaData(annotationStorage) {
|
||||||
|
@ -83,8 +83,8 @@ class XFAFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
appendFonts(fonts) {
|
appendFonts(fonts, reallyMissingFonts) {
|
||||||
this.form[$globalData].fontFinder.add(fonts);
|
this.form[$globalData].fontFinder.add(fonts, reallyMissingFonts);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPages() {
|
getPages() {
|
||||||
|
@ -24,7 +24,7 @@ class FontFinder {
|
|||||||
this.add(pdfFonts);
|
this.add(pdfFonts);
|
||||||
}
|
}
|
||||||
|
|
||||||
add(pdfFonts) {
|
add(pdfFonts, reallyMissingFonts = null) {
|
||||||
for (const pdfFont of pdfFonts) {
|
for (const pdfFont of pdfFonts) {
|
||||||
this.addPdfFont(pdfFont);
|
this.addPdfFont(pdfFont);
|
||||||
}
|
}
|
||||||
@ -33,6 +33,14 @@ class FontFinder {
|
|||||||
pdfFont.regular = pdfFont.italic || pdfFont.bold || pdfFont.bolditalic;
|
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) {
|
addPdfFont(pdfFont) {
|
||||||
@ -47,13 +55,10 @@ class FontFinder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let property = "";
|
let property = "";
|
||||||
if (cssFontInfo.italicAngle !== "0") {
|
const fontWeight = parseFloat(cssFontInfo.fontWeight);
|
||||||
if (parseFloat(cssFontInfo.fontWeight) >= 700) {
|
if (parseFloat(cssFontInfo.italicAngle) !== 0) {
|
||||||
property = "bolditalic";
|
property = fontWeight >= 700 ? "bolditalic" : "italic";
|
||||||
} else {
|
} else if (fontWeight >= 700) {
|
||||||
property = "italic";
|
|
||||||
}
|
|
||||||
} else if (parseFloat(cssFontInfo.fontWeight) >= 700) {
|
|
||||||
property = "bold";
|
property = "bold";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +96,7 @@ class FontFinder {
|
|||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pattern = /,|-| |bolditalic|bold|italic|regular|it/gi;
|
const pattern = /,|-|_| |bolditalic|bold|italic|regular|it/gi;
|
||||||
let name = fontName.replace(pattern, "");
|
let name = fontName.replace(pattern, "");
|
||||||
font = this.fonts.get(name);
|
font = this.fonts.get(name);
|
||||||
if (font) {
|
if (font) {
|
||||||
|
@ -63,25 +63,31 @@ import { getLookupTableFactory } from "./core_utils.js";
|
|||||||
import { normalizeFontName } from "./fonts_utils.js";
|
import { normalizeFontName } from "./fonts_utils.js";
|
||||||
|
|
||||||
const getXFAFontMap = getLookupTableFactory(function (t) {
|
const getXFAFontMap = getLookupTableFactory(function (t) {
|
||||||
t["MyriadPro-Regular"] = {
|
t["MyriadPro-Regular"] = t["PdfJS-Fallback-Regular"] = {
|
||||||
name: "LiberationSans-Regular",
|
name: "LiberationSans-Regular",
|
||||||
factors: MyriadProRegularFactors,
|
factors: MyriadProRegularFactors,
|
||||||
baseWidths: LiberationSansRegularWidths,
|
baseWidths: LiberationSansRegularWidths,
|
||||||
lineHeight: MyriadProRegularLineHeight,
|
lineHeight: MyriadProRegularLineHeight,
|
||||||
};
|
};
|
||||||
t["MyriadPro-Bold"] = {
|
t["MyriadPro-Bold"] = t["PdfJS-Fallback-Bold"] = {
|
||||||
name: "LiberationSans-Bold",
|
name: "LiberationSans-Bold",
|
||||||
factors: MyriadProBoldFactors,
|
factors: MyriadProBoldFactors,
|
||||||
baseWidths: LiberationSansBoldWidths,
|
baseWidths: LiberationSansBoldWidths,
|
||||||
lineHeight: MyriadProBoldLineHeight,
|
lineHeight: MyriadProBoldLineHeight,
|
||||||
};
|
};
|
||||||
t["MyriadPro-It"] = {
|
t["MyriadPro-It"] =
|
||||||
|
t["MyriadPro-Italic"] =
|
||||||
|
t["PdfJS-Fallback-Italic"] =
|
||||||
|
{
|
||||||
name: "LiberationSans-Italic",
|
name: "LiberationSans-Italic",
|
||||||
factors: MyriadProItalicFactors,
|
factors: MyriadProItalicFactors,
|
||||||
baseWidths: LiberationSansItalicWidths,
|
baseWidths: LiberationSansItalicWidths,
|
||||||
lineHeight: MyriadProItalicLineHeight,
|
lineHeight: MyriadProItalicLineHeight,
|
||||||
};
|
};
|
||||||
t["MyriadPro-BoldIt"] = {
|
t["MyriadPro-BoldIt"] =
|
||||||
|
t["MyriadPro-BoldItalic"] =
|
||||||
|
t["PdfJS-Fallback-BoldItalic"] =
|
||||||
|
{
|
||||||
name: "LiberationSans-BoldItalic",
|
name: "LiberationSans-BoldItalic",
|
||||||
factors: MyriadProBoldItalicFactors,
|
factors: MyriadProBoldItalicFactors,
|
||||||
baseWidths: LiberationSansBoldItalicWidths,
|
baseWidths: LiberationSansBoldItalicWidths,
|
||||||
@ -154,7 +160,7 @@ const getXFAFontMap = getLookupTableFactory(function (t) {
|
|||||||
baseWidths: LiberationSansBoldItalicWidths,
|
baseWidths: LiberationSansBoldItalicWidths,
|
||||||
lineHeight: SegoeuiBoldItalicLineHeight,
|
lineHeight: SegoeuiBoldItalicLineHeight,
|
||||||
};
|
};
|
||||||
t["Helvetica-Regular"] = {
|
t["Helvetica-Regular"] = t.Helvetica = {
|
||||||
name: "LiberationSans-Regular",
|
name: "LiberationSans-Regular",
|
||||||
factors: HelveticaRegularFactors,
|
factors: HelveticaRegularFactors,
|
||||||
baseWidths: LiberationSansRegularWidths,
|
baseWidths: LiberationSansRegularWidths,
|
||||||
|
1
test/pdfs/xfa_issue13597.pdf.link
Normal file
1
test/pdfs/xfa_issue13597.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://web.archive.org/web/20210710141547/https://help.adobe.com/en_US/livecycle/11.0/SampleForms/941/Form.pdf
|
@ -1184,6 +1184,14 @@
|
|||||||
"enableXfa": true,
|
"enableXfa": true,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "xfa_issue13597",
|
||||||
|
"file": "pdfs/xfa_issue13597.pdf",
|
||||||
|
"md5": "1ed9338f7e797789c0b41182f51b9002",
|
||||||
|
"link": true,
|
||||||
|
"rounds": 1,
|
||||||
|
"enableXfa": true,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "xfa_issue13633",
|
{ "id": "xfa_issue13633",
|
||||||
"file": "pdfs/xfa_issue13633.pdf",
|
"file": "pdfs/xfa_issue13633.pdf",
|
||||||
"md5": "e5b0d09285ca6a140eba08d740be0ea0",
|
"md5": "e5b0d09285ca6a140eba08d740be0ea0",
|
||||||
|
Loading…
Reference in New Issue
Block a user