Merge pull request #16434 from Snuffleupagus/issue-16432

Attempt to fallback to a default font, for non-available ones, in more cases (issue 16432)
This commit is contained in:
Jonas Jenwald 2023-05-17 12:30:08 +02:00 committed by GitHub
commit 46bbabbd5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 27 deletions

View File

@ -1212,37 +1212,30 @@ class PartialEvaluator {
fontRef = fontRes.getRaw(fontName);
}
}
if (!fontRef) {
const partialMsg = `Font "${
fontName || (font && font.toString())
}" is not available`;
if (!this.options.ignoreErrors && !this.parsingType3Font) {
warn(`${partialMsg}.`);
if (fontRef) {
if (this.parsingType3Font && this.type3FontRefs.has(fontRef)) {
return errorFont();
}
warn(`${partialMsg} -- attempting to fallback to a default font.`);
if (this.fontCache.has(fontRef)) {
return this.fontCache.get(fontRef);
}
font = xref.fetchIfRef(fontRef);
}
if (!(font instanceof Dict)) {
if (!this.options.ignoreErrors && !this.parsingType3Font) {
warn(`Font "${fontName}" is not available.`);
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".
if (fallbackFontDict) {
fontRef = fallbackFontDict;
} else {
fontRef = PartialEvaluator.fallbackFontDict;
}
}
if (this.parsingType3Font && this.type3FontRefs.has(fontRef)) {
return errorFont();
}
if (this.fontCache.has(fontRef)) {
return this.fontCache.get(fontRef);
}
font = xref.fetchIfRef(fontRef);
if (!(font instanceof Dict)) {
return errorFont();
font = fallbackFontDict || PartialEvaluator.fallbackFontDict;
}
// We are holding `font.cacheKey` references only for `fontRef`s that
@ -4412,7 +4405,7 @@ class PartialEvaluator {
static get fallbackFontDict() {
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("Subtype", Name.get("FallbackType"));
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,
"type": "eq"
},
{ "id": "issue16432",
"file": "pdfs/issue16432.pdf",
"md5": "b67b0324c307d8af43d11b0edec88e3e",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq"
},
{ "id": "tracemonkey-fbf",
"file": "pdfs/tracemonkey.pdf",
"md5": "9a192d8b1a7dc652a19835f6f08098bd",