1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

Handle errors gracefully, in PartialEvaluator.buildFontPaths, when glyph path building fails

The building of glyph paths, in the `FontRendererFactory`, can fail in various ways for corrupt font data. However, we're currently not attempting to handle any such errors in the evaluator, which means that a single broken glyph *can* prevent an entire page from rendering.

To address this we simply have to pass along, and check, the existing `ignoreErrors` option in `PartialEvaluator.buildFontPaths` similar to the rest of the `PartialEvaluator` code.
This commit is contained in:
Jonas Jenwald 2021-05-15 18:21:18 +02:00
parent b2ffebe978
commit 68350378c0
3 changed files with 61 additions and 27 deletions

View file

@ -734,14 +734,24 @@ class CompiledFont {
}
getPathJs(unicode) {
const cmap = lookupCmap(this.cmap, unicode);
let fn = this.compiledGlyphs[cmap.glyphId];
const { charCode, glyphId } = lookupCmap(this.cmap, unicode);
let fn = this.compiledGlyphs[glyphId];
if (!fn) {
fn = this.compileGlyph(this.glyphs[cmap.glyphId], cmap.glyphId);
this.compiledGlyphs[cmap.glyphId] = fn;
try {
fn = this.compileGlyph(this.glyphs[glyphId], glyphId);
this.compiledGlyphs[glyphId] = fn;
} catch (ex) {
// Avoid attempting to re-compile a corrupt glyph.
this.compiledGlyphs[glyphId] = NOOP;
if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
this.compiledCharCodeToGlyphId[charCode] = glyphId;
}
throw ex;
}
}
if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
this.compiledCharCodeToGlyphId[charCode] = glyphId;
}
return fn;
}
@ -781,10 +791,10 @@ class CompiledFont {
}
hasBuiltPath(unicode) {
const cmap = lookupCmap(this.cmap, unicode);
const { charCode, glyphId } = lookupCmap(this.cmap, unicode);
return (
this.compiledGlyphs[cmap.glyphId] !== undefined &&
this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined
this.compiledGlyphs[glyphId] !== undefined &&
this.compiledCharCodeToGlyphId[charCode] !== undefined
);
}
}