Attempt to fallback to a default font, for non-available ones, in more cases (issue 16432)

This essentially extends PR 11218 to also apply when looking up the final font-reference, via the XRef-table, fails because the font isn't available.

This patch also changes `PartialEvaluator.fallbackFontDict` to simply use "Helvetica" as the default font-name, since that seems generally reasonable given the now existing font-substitution code.
This commit is contained in:
Jonas Jenwald 2023-05-17 10:19:14 +02:00
parent 5ae353cf4d
commit bfb374dbf6
3 changed files with 29 additions and 27 deletions

View File

@ -1212,26 +1212,7 @@ class PartialEvaluator {
fontRef = fontRes.getRaw(fontName); fontRef = fontRes.getRaw(fontName);
} }
} }
if (!fontRef) { if (fontRef) {
const partialMsg = `Font "${
fontName || (font && font.toString())
}" is not available`;
if (!this.options.ignoreErrors && !this.parsingType3Font) {
warn(`${partialMsg}.`);
return errorFont();
}
warn(`${partialMsg} -- attempting to fallback to a default font.`);
// Falling back to a default font to avoid completely broken rendering,
// but note that there're no guarantees that things will look "correct".
if (fallbackFontDict) {
fontRef = fallbackFontDict;
} else {
fontRef = PartialEvaluator.fallbackFontDict;
}
}
if (this.parsingType3Font && this.type3FontRefs.has(fontRef)) { if (this.parsingType3Font && this.type3FontRefs.has(fontRef)) {
return errorFont(); return errorFont();
} }
@ -1241,9 +1222,21 @@ class PartialEvaluator {
} }
font = xref.fetchIfRef(fontRef); font = xref.fetchIfRef(fontRef);
}
if (!(font instanceof Dict)) { if (!(font instanceof Dict)) {
if (!this.options.ignoreErrors && !this.parsingType3Font) {
warn(`Font "${fontName}" is not available.`);
return errorFont(); return errorFont();
} }
warn(
`Font "${fontName}" is not available -- attempting to fallback to a default font.`
);
// Falling back to a default font to avoid completely broken rendering,
// but note that there're no guarantees that things will look "correct".
font = fallbackFontDict || PartialEvaluator.fallbackFontDict;
}
// We are holding `font.cacheKey` references only for `fontRef`s that // We are holding `font.cacheKey` references only for `fontRef`s that
// are not actually `Ref`s, but rather `Dict`s. See explanation below. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
@ -4412,7 +4405,7 @@ class PartialEvaluator {
static get fallbackFontDict() { static get fallbackFontDict() {
const dict = new Dict(); const dict = new Dict();
dict.set("BaseFont", Name.get("PDFJS-FallbackFont")); dict.set("BaseFont", Name.get("Helvetica"));
dict.set("Type", Name.get("FallbackType")); dict.set("Type", Name.get("FallbackType"));
dict.set("Subtype", Name.get("FallbackType")); dict.set("Subtype", Name.get("FallbackType"));
dict.set("Encoding", Name.get("WinAnsiEncoding")); dict.set("Encoding", Name.get("WinAnsiEncoding"));

View File

@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/11493613/inputFields-Flattened-Output.pdf

View File

@ -50,6 +50,14 @@
"lastPage": 3, "lastPage": 3,
"type": "eq" "type": "eq"
}, },
{ "id": "issue16432",
"file": "pdfs/issue16432.pdf",
"md5": "b67b0324c307d8af43d11b0edec88e3e",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq"
},
{ "id": "tracemonkey-fbf", { "id": "tracemonkey-fbf",
"file": "pdfs/tracemonkey.pdf", "file": "pdfs/tracemonkey.pdf",
"md5": "9a192d8b1a7dc652a19835f6f08098bd", "md5": "9a192d8b1a7dc652a19835f6f08098bd",