diff --git a/src/core/cmap.js b/src/core/cmap.js index 3dd5f95fb..b43906537 100644 --- a/src/core/cmap.js +++ b/src/core/cmap.js @@ -996,7 +996,7 @@ var CMapFactory = (function CMapFactoryClosure() { } return { - create(params) { + async create(params) { var encoding = params.encoding; var fetchBuiltInCMap = params.fetchBuiltInCMap; var useCMap = params.useCMap; @@ -1015,7 +1015,7 @@ var CMapFactory = (function CMapFactoryClosure() { return parsedCMap; }); } - return Promise.reject(new Error("Encoding required.")); + throw new Error("Encoding required."); }, }; })(); diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 2f8a88126..344540143 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -2612,31 +2612,48 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { encoding: cmapObj, fetchBuiltInCMap: this.fetchBuiltInCMap, useCMap: null, - }).then(function(cmap) { - if (cmap instanceof IdentityCMap) { - return new IdentityToUnicodeMap(0, 0xffff); - } - var map = new Array(cmap.length); - // Convert UTF-16BE - // NOTE: cmap can be a sparse array, so use forEach instead of for(;;) - // to iterate over all keys. - cmap.forEach(function(charCode, token) { - var str = []; - for (var k = 0; k < token.length; k += 2) { - var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1); - if ((w1 & 0xf800) !== 0xd800) { - // w1 < 0xD800 || w1 > 0xDFFF - str.push(w1); - continue; - } - k += 2; - var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1); - str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000); + }).then( + function(cmap) { + if (cmap instanceof IdentityCMap) { + return new IdentityToUnicodeMap(0, 0xffff); } - map[charCode] = String.fromCodePoint.apply(String, str); - }); - return new ToUnicodeMap(map); - }); + var map = new Array(cmap.length); + // Convert UTF-16BE + // NOTE: cmap can be a sparse array, so use forEach instead of + // `for(;;)` to iterate over all keys. + cmap.forEach(function(charCode, token) { + var str = []; + for (var k = 0; k < token.length; k += 2) { + var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1); + if ((w1 & 0xf800) !== 0xd800) { + // w1 < 0xD800 || w1 > 0xDFFF + str.push(w1); + continue; + } + k += 2; + var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1); + str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000); + } + map[charCode] = String.fromCodePoint.apply(String, str); + }); + return new ToUnicodeMap(map); + }, + reason => { + if (reason instanceof AbortException) { + return null; + } + if (this.options.ignoreErrors) { + // Error in the ToUnicode data -- sending unsupported feature + // notification and allow font parsing to continue. + this.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.font, + }); + warn(`readToUnicode - ignoring ToUnicode data: "${reason}".`); + return null; + } + throw reason; + } + ); } return Promise.resolve(null); }, diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index d55596365..c2392001c 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -352,6 +352,7 @@ !issue7878.pdf !font_ascent_descent.pdf !issue11442_reduced.pdf +!issue11549_reduced.pdf !issue8097_reduced.pdf !transparent.pdf !xobject-image.pdf diff --git a/test/pdfs/issue11549_reduced.pdf b/test/pdfs/issue11549_reduced.pdf new file mode 100644 index 000000000..e9e8ee66f Binary files /dev/null and b/test/pdfs/issue11549_reduced.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 014981764..b737f2a1d 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -60,6 +60,13 @@ "link": false, "type": "eq" }, + { "id": "issue11549", + "file": "pdfs/issue11549_reduced.pdf", + "md5": "a1ea636f413e02e10dbdf379ab4a99ae", + "rounds": 1, + "link": false, + "type": "eq" + }, { "id": "issue1293", "file": "pdfs/issue1293r.pdf", "md5": "4a098f5051f34fab036f5bbe88f8deef",