From ed73cf6d502f02e0acebac67384000b597cab96b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 18 Sep 2021 00:01:24 +0200 Subject: [PATCH] Support cmaps with only CID characters, when building the ToUnicode-map (issue 9367) In this particular case the `CMap`-data that we create contains only numbers, but no strings, which causes `PartialEvaluator.readToUnicode` to create a ToUnicode-map with only empty strings. *Please note:* This is yet another case where I don't know if it's necessarily the best and most correct solution, but it does fix the referenced issue. --- src/core/evaluator.js | 5 +++++ test/pdfs/issue9367.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 14 insertions(+) create mode 100644 test/pdfs/issue9367.pdf.link diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 48a170016..0cf84ac7b 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -3455,6 +3455,11 @@ class PartialEvaluator { // NOTE: cmap can be a sparse array, so use forEach instead of // `for(;;)` to iterate over all keys. cmap.forEach(function (charCode, token) { + // Some cmaps contain *only* CID characters (fixes issue9367.pdf). + if (typeof token === "number") { + map[charCode] = String.fromCodePoint(token); + return; + } const str = []; for (let k = 0; k < token.length; k += 2) { const w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1); diff --git a/test/pdfs/issue9367.pdf.link b/test/pdfs/issue9367.pdf.link new file mode 100644 index 000000000..8c4599be5 --- /dev/null +++ b/test/pdfs/issue9367.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/1634833/E-WG18_105147.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index c45fb9210..320cb303e 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -2358,6 +2358,14 @@ "lastPage": 2, "type": "eq" }, + { "id": "issue9367", + "file": "pdfs/issue9367.pdf", + "md5": "81a2c6f1fe5d1bb00ff0479aa6547155", + "rounds": 1, + "link": true, + "lastPage": 1, + "type": "eq" + }, { "id": "issue10529", "file": "pdfs/issue10529.pdf", "md5": "1a4d404a137c610ff0c747cbea3b8666",