mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Fix the charCodeOf
method in IdentityToUnicodeMap
in order to prevent text selection from breaking
After PR 6590, `font.spaceWidth` is now called in more cases than before (in `PartialEvaluator_getTextContent`), which exposed an underlying issue with `IdentityToUnicodeMap_charCodeOf` throwing an error. This breaks text-selection in some PDF files found in the wild, hence this patch replaces the `error` with an actual function instead (modelled after `IdentityCMap_charCodeOf`).
This commit is contained in:
parent
e2aca385c6
commit
4810b7b8fc
4 changed files with 79 additions and 3 deletions
|
@ -15,7 +15,7 @@
|
|||
/* globals FONT_IDENTITY_MATRIX, FontType, warn, GlyphsUnicode, error, string32,
|
||||
readUint32, Stream, FontRendererFactory, shadow, stringToBytes,
|
||||
bytesToString, info, assert, IdentityCMap, Name, CMapFactory, PDFJS,
|
||||
isNum, Lexer, isArray, ISOAdobeCharset, ExpertCharset,
|
||||
isNum, Lexer, isArray, ISOAdobeCharset, ExpertCharset, isInt,
|
||||
ExpertSubsetCharset, Util, DingbatsGlyphsUnicode */
|
||||
|
||||
'use strict';
|
||||
|
@ -2256,7 +2256,7 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
|
|||
},
|
||||
|
||||
charCodeOf: function (v) {
|
||||
error('should not call .charCodeOf');
|
||||
return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -4700,7 +4700,7 @@ var Font = (function FontClosure() {
|
|||
}
|
||||
}
|
||||
// ... via toUnicode map
|
||||
if (!charcode && 'toUnicode' in this) {
|
||||
if (!charcode && this.toUnicode) {
|
||||
charcode = this.toUnicode.charCodeOf(glyphUnicode);
|
||||
}
|
||||
// setting it to unicode if negative or undefined
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue