From 38e3f32557a8a96fba2fea3851a0e2d6b0563598 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Thu, 1 Mar 2012 21:23:36 -0600 Subject: [PATCH] Add and fix pdfkit_compressed.pdf --- src/fonts.js | 30 +++++++++++++++++++++++++----- test/pdfs/.gitignore | 1 + test/pdfs/pdfkit_compressed.pdf | Bin 0 -> 8286 bytes test/test_manifest.json | 6 ++++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test/pdfs/pdfkit_compressed.pdf diff --git a/src/fonts.js b/src/fonts.js index 261a907f2..0d0e12fec 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -1881,6 +1881,7 @@ var Font = (function FontClosure() { var unusedUnicode = kCmapGlyphOffset; var glyphNames = properties.glyphNames || []; var encoding = properties.baseEncoding; + var differences = properties.differences; if (toFontChar && toFontChar.length > 0) { // checking if cmap is just identity map var isIdentity = true; @@ -1945,35 +1946,51 @@ var Font = (function FontClosure() { } } this.useToFontChar = true; - } else if (!this.isSymbolicFont && - (this.hasEncoding || properties.glyphNames)) { + } else if (!this.isSymbolicFont && (this.hasEncoding || + properties.glyphNames || differences.length > 0)) { // Re-encode cmap encoding to unicode, based on the 'post' table data - // or base encoding + // diffrence array or base encoding var reverseMap = []; for (var i = 0, ii = glyphs.length; i < ii; i++) reverseMap[glyphs[i].unicode] = i; for (var i = 0, ii = glyphs.length; i < ii; i++) { var code = glyphs[i].unicode; + var changeCode = false; var gid = ids[i]; - var glyphName = glyphNames[gid] || encoding[code]; + var glyphName = glyphNames[gid]; + if (!glyphName) { + glyphName = differences[code] || encoding[code]; + changeCode = true; + } if (glyphName in GlyphsUnicode) { var unicode = GlyphsUnicode[glyphName]; if (!unicode || reverseMap[unicode] === i) continue; // unknown glyph name or in its own place var destination = reverseMap[unicode]; + if (typeof destination === 'number' && destination > i) + continue; + var j = i; // Flipping unicodes while next destination unicode has assigned // glyph and future glyph can be assigned to unicode. while (typeof destination === 'number') { glyphs[j].unicode = unicode; reverseMap[unicode] = j; + if (changeCode) { + toFontChar[code] = unicode; + changeCode = false; + } code = glyphs[destination].unicode; gid = ids[destination]; - glyphName = glyphNames[gid] || encoding[code]; + glyphName = glyphNames[gid]; + if (!glyphName) { + glyphName = differences[code] || encoding[code]; + changeCode = true; + } unicode = GlyphsUnicode[glyphName]; if (!unicode || reverseMap[unicode] === j) { @@ -1994,7 +2011,10 @@ var Font = (function FontClosure() { glyphs[j].unicode = unicode; reverseMap[unicode] = j; + if (changeCode) + toFontChar[code] = unicode; } + this.useToFontChar = true; } } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 81b63290d..f14236860 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -19,6 +19,7 @@ !issue840.pdf !scan-bad.pdf !freeculture.pdf +!pdfkit_compressed.pdf !issue918.pdf !issue1249.pdf !smaskdim.pdf diff --git a/test/pdfs/pdfkit_compressed.pdf b/test/pdfs/pdfkit_compressed.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f3e25216d231f4b18c14e33b00bfc7877650c30c GIT binary patch literal 8286 zcmZ{qcU;p+(D0Qip$P~GD2Cn%od8m#9layHgb+FjkkEVYh9XGsMUbvYlMaG(REi*= z2m%TLrS~UzchC9WJ@0-#ncbb=?CkE$>|fuo=_o4m3GxdA*eBC%91(Cu2nq(|RFo7F5EK%?3PCXeu&|&h*KfW> zfAg*E=z_v}1}VE>*D1oF2wNBcqydB5qa1)>iK|6O6m~CHfKLwf@B&eY014iwLycsj z7ws2ZG2~%dN%$`s$uY7aMmSbv{1O_kkXiBh%qga+$6=4&!@>z~cHv~wWYt-(c4RUd z(ECoV57V)uf(%zac{OTlonGfAr(wAY_+NYc75b}?{x|ejiSmG94KDfmhem1Az2kNQ9>c6q{o4Uy6THd^P`jA8d@F`Y;sG z41|p_5M%)J!6r)86l;J>~8MTx8pyH?avbUC)*yL zu&WQhSH**0jYkK9&4eQy!6%P!vHf!=MHmw5;pldiZ^5g(VlSoa=z&BjI6ypr!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