mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
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:
parent
5ae353cf4d
commit
bfb374dbf6
3 changed files with 29 additions and 27 deletions
|
@ -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"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue