From b242826d2966955a73a0d754ba6d53ddfc2cf674 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Fri, 11 Apr 2014 09:55:39 -0700 Subject: [PATCH] Fix seac regression. --- src/core/fonts.js | 43 ++++++++++++++++++++++++++++++---------- test/pdfs/.gitignore | 1 + test/pdfs/issue4573.pdf | Bin 0 -> 8474 bytes test/test_manifest.json | 10 ++++++++++ 4 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 test/pdfs/issue4573.pdf diff --git a/src/core/fonts.js b/src/core/fonts.js index ee927abfc..8056dc7dc 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -2471,7 +2471,8 @@ var Font = (function FontClosure() { } return { toFontChar: toFontChar, - charCodeToGlyphId: newMap + charCodeToGlyphId: newMap, + nextAvailableFontCharCode: nextAvailableFontCharCode }; } @@ -4046,18 +4047,25 @@ var Font = (function FontClosure() { this.toFontChar = newMapping.toFontChar; var numGlyphs = font.numGlyphs; + function getCharCode(charCodeToGlyphId, glyphId, addMap) { + for (var charCode in charCodeToGlyphId) { + if (glyphId === charCodeToGlyphId[charCode]) { + return charCode | 0; + } + } + if (addMap) { + newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = + glyphId; + return newMapping.nextAvailableFontCharCode++; + } + return null; + } + var seacs = font.seacs; - var charCode; if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) { var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX; var charset = font.getCharset(); - var charCodeToGlyphId = mapping; - var toFontChar = newMapping.toFontChar; var seacMap = Object.create(null); - var glyphIdToCharCode = Object.create(null); - for (charCode in charCodeToGlyphId) { - glyphIdToCharCode[charCodeToGlyphId[charCode]] = charCode | 0; - } for (var glyphId in seacs) { glyphId |= 0; var seac = seacs[glyphId]; @@ -4072,10 +4080,23 @@ var Font = (function FontClosure() { x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4], y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5] }; - charCode = glyphIdToCharCode[glyphId]; + + var charCode = getCharCode(mapping, glyphId); + if (charCode === null) { + // There's no point in mapping it if the char code was never mapped + // to begin with. + continue; + } + // Find a fontCharCode that maps to the base and accent glyphs. If one + // doesn't exists, create it. + var charCodeToGlyphId = newMapping.charCodeToGlyphId; + var baseFontCharCode = getCharCode(charCodeToGlyphId, baseGlyphId, + true); + var accentFontCharCode = getCharCode(charCodeToGlyphId, accentGlyphId, + true); seacMap[charCode] = { - baseFontCharCode: toFontChar[glyphIdToCharCode[baseGlyphId]], - accentFontCharCode: toFontChar[glyphIdToCharCode[accentGlyphId]], + baseFontCharCode: baseFontCharCode, + accentFontCharCode: accentFontCharCode, accentOffset: accentOffset }; } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 70f8aa8e4..38d7c5a4c 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -71,3 +71,4 @@ !bug859204.pdf !issue4246.pdf !issue4461.pdf +!issue4573.pdf diff --git a/test/pdfs/issue4573.pdf b/test/pdfs/issue4573.pdf new file mode 100644 index 0000000000000000000000000000000000000000..128af35c9e18adb52450bb745fa2308cebf9fc04 GIT binary patch literal 8474 zcmdT~c|26n+pmP0QX#vz_AM@B7W+h0J%q}0H}$fUozco|6A>kkef87C1ab%(o z2@APM^<9Su5w{vLfSep;^|#AZURZI&<#**+}6e0;?f^V4u z4KROr$oN>&Cyz)=7S>Z6bl9WJ{i3r8XW zSvZvk1)yc%074$p3CSU(dz5x$Uf?5Zf7$LqOSqWYMznfUGQ4?l)Z;4#3fnUKFI4nqedwKtafc zBOy98Q*aa{56Mt{pxQuFXHE{aJu{FG+cN>pC`6~uF!iBk9xk_Sck4d_we34JJ7}m4 zmxug=RxT9W_k?fX}RA!_s{6Cl3_A2-Tc>|oME5!{00(G&F zDI^@m1EygPlc6qOz+4LgHslY~a)F7)iUH>CFl}>cDfrF#dl_vni9af-tLX1)fiUc; z?n%b~8GwOWco!EOw4SM}*A|cgz_S2o2!I3t!~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J7@08R#aImlSVZ>FT*f}j1W#pb$vcbth{>~l`!J)=;C)E}!Q^$Y~A^!$fj;!j71_wlBl z$}w95?)aJVr-YxqO{1t-eTeIx09U*Y(JzhsbKu7%`Yh*5o2*W|9t>V>|F2hU{v@0W z47&1zN&o$U?hlc&NWg^wM!l1hVfamwf!>h=TTFl_l?4BXgobW5{~^ilkl+aD;&X=t zz0musP*w&FeLX<^p(=zf=FvMeXz(9nTbK5K<)o#dJJEmTd|rbOb_*8|iK9=1MaAX6|T%2xX1WDwFY KAtCKkI{yO|+yZm} literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index 738232d81..b7971ef15 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -665,6 +665,16 @@ "rounds": 1, "type": "eq" }, + { "id": "issue4573", + "file": "pdfs/issue4573.pdf", + "md5": "34b0c4fdee19e57033275b766c5f57a3", + "rounds": 1, + "link": false, + "firstPage": 1, + "lastPage": 1, + "type": "eq", + "about": "Seac with differences array that messes up mapping." + }, { "id": "ocs", "file": "pdfs/ocs.pdf", "md5": "2ade57e954ae7632749cf328daeaa7a8",