Merge pull request #5017 from Snuffleupagus/bug-1028735

[CIDFontType2] Map characters missing in toUnicode to the private use area (bug 1028735 and issue 4881)
This commit is contained in:
Yury Delendik 2014-07-12 07:18:07 -05:00
commit b5e5de00df
4 changed files with 28 additions and 10 deletions

View File

@ -2473,6 +2473,7 @@ var Font = (function FontClosure() {
var toUnicode = properties.toUnicode; var toUnicode = properties.toUnicode;
var isSymbolic = !!(properties.flags & FontFlags.Symbolic); var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
var isIdentityUnicode = properties.isIdentityUnicode; var isIdentityUnicode = properties.isIdentityUnicode;
var isCidFontType2 = (properties.type === 'CIDFontType2');
var newMap = Object.create(null); var newMap = Object.create(null);
var toFontChar = []; var toFontChar = [];
var usedFontCharCodes = []; var usedFontCharCodes = [];
@ -2483,11 +2484,17 @@ var Font = (function FontClosure() {
var fontCharCode = originalCharCode; var fontCharCode = originalCharCode;
// First try to map the value to a unicode position if a non identity map // First try to map the value to a unicode position if a non identity map
// was created. // was created.
if (!isIdentityUnicode && originalCharCode in toUnicode) { if (!isIdentityUnicode) {
var unicode = toUnicode[fontCharCode]; if (toUnicode[originalCharCode] !== undefined) {
// TODO: Try to map ligatures to the correct spot. var unicode = toUnicode[fontCharCode];
if (unicode.length === 1) { // TODO: Try to map ligatures to the correct spot.
fontCharCode = unicode.charCodeAt(0); if (unicode.length === 1) {
fontCharCode = unicode.charCodeAt(0);
}
} else if (isCidFontType2) {
// For CIDFontType2, move characters not present in toUnicode
// to the private use area (fixes bug 1028735 and issue 4881).
fontCharCode = nextAvailableFontCharCode;
} }
} }
// Try to move control characters, special characters and already mapped // Try to move control characters, special characters and already mapped
@ -2496,7 +2503,7 @@ var Font = (function FontClosure() {
// font was symbolic and there is only an identity unicode map since the // font was symbolic and there is only an identity unicode map since the
// characters probably aren't in the correct position (fixes an issue // characters probably aren't in the correct position (fixes an issue
// with firefox and thuluthfont). // with firefox and thuluthfont).
if ((fontCharCode in usedFontCharCodes || if ((usedFontCharCodes[fontCharCode] !== undefined ||
fontCharCode <= 0x1f || // Control chars fontCharCode <= 0x1f || // Control chars
fontCharCode === 0x7F || // Control char fontCharCode === 0x7F || // Control char
fontCharCode === 0xAD || // Soft hyphen fontCharCode === 0xAD || // Soft hyphen
@ -2514,7 +2521,7 @@ var Font = (function FontClosure() {
nextAvailableFontCharCode = fontCharCode + 1; nextAvailableFontCharCode = fontCharCode + 1;
} }
} while (fontCharCode in usedFontCharCodes && } while (usedFontCharCodes[fontCharCode] !== undefined &&
nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END); nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
} }
@ -3888,8 +3895,9 @@ var Font = (function FontClosure() {
} }
var charCodeToGlyphId = [], charCode; var charCodeToGlyphId = [], charCode;
if (properties.type == 'CIDFontType2') { if (properties.type === 'CIDFontType2') {
var cidToGidMap = properties.cidToGidMap || []; var cidToGidMap = properties.cidToGidMap || [];
var cidToGidMapLength = cidToGidMap.length;
var cMap = properties.cMap.map; var cMap = properties.cMap.map;
for (charCode in cMap) { for (charCode in cMap) {
charCode |= 0; charCode |= 0;
@ -3897,9 +3905,9 @@ var Font = (function FontClosure() {
assert(cid.length === 1, 'Max size of CID is 65,535'); assert(cid.length === 1, 'Max size of CID is 65,535');
cid = cid.charCodeAt(0); cid = cid.charCodeAt(0);
var glyphId = -1; var glyphId = -1;
if (cidToGidMap.length === 0) { if (cidToGidMapLength === 0) {
glyphId = charCode; glyphId = charCode;
} else if (cid in cidToGidMap) { } else if (cidToGidMap[cid] !== undefined) {
glyphId = cidToGidMap[cid]; glyphId = cidToGidMap[cid];
} }
if (glyphId >= 0 && glyphId < numGlyphs) { if (glyphId >= 0 && glyphId < numGlyphs) {

View File

@ -56,6 +56,7 @@
!bug903856.pdf !bug903856.pdf
!bug850854.pdf !bug850854.pdf
!bug866395.pdf !bug866395.pdf
!bug1028735.pdf
!basicapi.pdf !basicapi.pdf
!mixedfonts.pdf !mixedfonts.pdf
!shading_extend.pdf !shading_extend.pdf

BIN
test/pdfs/bug1028735.pdf Normal file

Binary file not shown.

View File

@ -176,6 +176,15 @@
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
}, },
{ "id": "bug1028735",
"file": "pdfs/bug1028735.pdf",
"md5": "5d1a2a87d176ff3b24e66af3cb2365be",
"rounds": 1,
"link": false,
"firstPage": 1,
"lastPage": 1,
"type": "eq"
},
{ "id": "issue1512", { "id": "issue1512",
"file": "pdfs/issue1512.pdf", "file": "pdfs/issue1512.pdf",
"md5": "41a19fe03d522346ee3baa732403fca4", "md5": "41a19fe03d522346ee3baa732403fca4",