Fix copying on supplementary plane characters

pdf.js had a problem when copying characters on supplementary planes
(0xPPXXXX where PP is nonzero).  This is because certain methods of
PartialEvaluator use classic String.fromCharCode instead of ES6's
String.fromCodePoint.

Despite the fact that readToUnicode method *tried* to parse out-of-UCS2
code points by parsing UTF-16BE, it was inadequate because
String.fromCharCode only supports UCS-2 range of Unicode.
This commit is contained in:
Tsukasa OI 2019-02-09 06:53:16 +00:00
parent 2b6e6364ef
commit 96ba6afd47
4 changed files with 10 additions and 2 deletions

View File

@ -2045,7 +2045,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
continue; continue;
} }
} }
toUnicode[charcode] = String.fromCharCode(code); toUnicode[charcode] = String.fromCodePoint(code);
} }
continue; continue;
} }
@ -2179,7 +2179,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1); var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000); str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
} }
map[charCode] = String.fromCharCode.apply(String, str); map[charCode] = String.fromCodePoint.apply(String, str);
}); });
return new ToUnicodeMap(map); return new ToUnicodeMap(map);
}); });

View File

@ -75,6 +75,7 @@
!issue9940.pdf !issue9940.pdf
!issue10388_reduced.pdf !issue10388_reduced.pdf
!issue10438_reduced.pdf !issue10438_reduced.pdf
!issue10529.pdf
!bad-PageLabels.pdf !bad-PageLabels.pdf
!decodeACSuccessive.pdf !decodeACSuccessive.pdf
!filled-background.pdf !filled-background.pdf

BIN
test/pdfs/issue10529.pdf Normal file

Binary file not shown.

View File

@ -1451,6 +1451,13 @@
"type": "eq", "type": "eq",
"nativeImageDecoderSupport": "none" "nativeImageDecoderSupport": "none"
}, },
{ "id": "issue10529",
"file": "pdfs/issue10529.pdf",
"md5": "1a4d404a137c610ff0c747cbea3b8666",
"rounds": 1,
"link": false,
"type": "text"
},
{ "id": "issue6071", { "id": "issue6071",
"file": "pdfs/issue6071.pdf", "file": "pdfs/issue6071.pdf",
"md5": "2e08526d8e7c9ba4269fc12ef488d3eb", "md5": "2e08526d8e7c9ba4269fc12ef488d3eb",