From a6b9efc06bc7ef12806c26cbcefc1feebbb7467f Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Wed, 29 Feb 2012 22:11:32 -0600 Subject: [PATCH 1/4] Re-encode cmap based on post table or current encoding; fix GlyphsUnicode table entries --- src/fonts.js | 58 ++++++++++++++++++++++++++++++++-- src/glyphlist.js | 81 ------------------------------------------------ 2 files changed, 55 insertions(+), 84 deletions(-) diff --git a/src/fonts.js b/src/fonts.js index 9d11d81cc..d04fd1a4e 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -1870,6 +1870,9 @@ var Font = (function FontClosure() { ids[i] = i; } + var unusedUnicode = kCmapGlyphOffset; + var glyphNames = properties.glyphNames || []; + var encoding = properties.baseEncoding; if (toFontChar && toFontChar.length > 0) { // checking if cmap is just identity map var isIdentity = true; @@ -1892,7 +1895,6 @@ var Font = (function FontClosure() { glyphs[i].unicode = unicode; usedUnicodes[unicode] = true; } - var unusedUnicode = kCmapGlyphOffset; for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) { var i = unassignedUnicodeItems[j]; while (unusedUnicode in usedUnicodes) @@ -1913,14 +1915,13 @@ var Font = (function FontClosure() { // copying all characters to private use area, all mapping all known // glyphs to the unicodes. The glyphs and ids arrays will grow. var usedUnicodes = []; - var glyphNames = properties.glyphNames || []; for (var i = 0, ii = glyphs.length; i < ii; i++) { var code = glyphs[i].unicode; var gid = ids[i]; glyphs[i].unicode += kCmapGlyphOffset; toFontChar[code] = glyphs[i].unicode; - var glyphName = glyphNames[gid] || properties.baseEncoding[code]; + var glyphName = glyphNames[gid] || encoding[code]; if (glyphName in GlyphsUnicode) { var unicode = GlyphsUnicode[glyphName]; if (unicode in usedUnicodes) @@ -1936,6 +1937,57 @@ var Font = (function FontClosure() { } } this.useToFontChar = true; + } else if (!this.isSymbolicFont && + (this.hasEncoding || properties.glyphNames)) { + // Re-encode cmap encoding to unicode, based on the 'post' table data + // 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 gid = ids[i] + + var glyphName = glyphNames[gid] || encoding[code]; + 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]; + 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; + + code = glyphs[destination].unicode; + gid = ids[destination]; + glyphName = glyphNames[gid] || encoding[code]; + + unicode = GlyphsUnicode[glyphName]; + if (!unicode || reverseMap[unicode] === j) { + unicode = 0; + break; // unknown glyph name or in its own place + } + + j = destination; + destination = reverseMap[unicode]; + } + + if (!unicode) { + // Future glyph cannot be assigned to unicode, generate new one. + while (reverseMap[unusedUnicode]) + unusedUnicode++; + unicode = unusedUnicode++; + } + + glyphs[j].unicode = unicode; + reverseMap[unicode] = j; + } + } } // Moving all symbolic font glyphs into 0xF000 - 0xF0FF range. diff --git a/src/glyphlist.js b/src/glyphlist.js index 01b94442a..694134840 100644 --- a/src/glyphlist.js +++ b/src/glyphlist.js @@ -1508,27 +1508,7 @@ var GlyphsUnicode = { dalet: 0x05D3, daletdagesh: 0xFB33, daletdageshhebrew: 0xFB33, - dalethatafpatah: 0x05D305B2, - dalethatafpatahhebrew: 0x05D305B2, - dalethatafsegol: 0x05D305B1, - dalethatafsegolhebrew: 0x05D305B1, dalethebrew: 0x05D3, - dalethiriq: 0x05D305B4, - dalethiriqhebrew: 0x05D305B4, - daletholam: 0x05D305B9, - daletholamhebrew: 0x05D305B9, - daletpatah: 0x05D305B7, - daletpatahhebrew: 0x05D305B7, - daletqamats: 0x05D305B8, - daletqamatshebrew: 0x05D305B8, - daletqubuts: 0x05D305BB, - daletqubutshebrew: 0x05D305BB, - daletsegol: 0x05D305B6, - daletsegolhebrew: 0x05D305B6, - daletsheva: 0x05D305B0, - daletshevahebrew: 0x05D305B0, - dalettsere: 0x05D305B5, - dalettserehebrew: 0x05D305B5, dalfinalarabic: 0xFEAA, dammaarabic: 0x064F, dammalowarabic: 0x064F, @@ -1845,10 +1825,6 @@ var GlyphsUnicode = { finalkafdagesh: 0xFB3A, finalkafdageshhebrew: 0xFB3A, finalkafhebrew: 0x05DA, - finalkafqamats: 0x05DA05B8, - finalkafqamatshebrew: 0x05DA05B8, - finalkafsheva: 0x05DA05B0, - finalkafshevahebrew: 0x05DA05B0, finalmem: 0x05DD, finalmemhebrew: 0x05DD, finalnun: 0x05DF, @@ -2037,14 +2013,7 @@ var GlyphsUnicode = { hakatakanahalfwidth: 0xFF8A, halantgurmukhi: 0x0A4D, hamzaarabic: 0x0621, - hamzadammaarabic: 0x0621064F, - hamzadammatanarabic: 0x0621064C, - hamzafathaarabic: 0x0621064E, - hamzafathatanarabic: 0x0621064B, hamzalowarabic: 0x0621, - hamzalowkasraarabic: 0x06210650, - hamzalowkasratanarabic: 0x0621064D, - hamzasukunarabic: 0x06210652, hangulfiller: 0x3164, hardsigncyrillic: 0x044A, harpoonleftbarbup: 0x21BC, @@ -2476,10 +2445,6 @@ var GlyphsUnicode = { lameddagesh: 0xFB3C, lameddageshhebrew: 0xFB3C, lamedhebrew: 0x05DC, - lamedholam: 0x05DC05B9, - lamedholamdagesh: '05DC 05B9 05BC', - lamedholamdageshhebrew: '05DC 05B9 05BC', - lamedholamhebrew: 0x05DC05B9, lamfinalarabic: 0xFEDE, lamhahinitialarabic: 0xFCCA, laminitialarabic: 0xFEDF, @@ -2489,8 +2454,6 @@ var GlyphsUnicode = { lammedialarabic: 0xFEE0, lammeemhahinitialarabic: 0xFD88, lammeeminitialarabic: 0xFCCC, - lammeemjeeminitialarabic: 'FEDF FEE4 FEA0', - lammeemkhahinitialarabic: 'FEDF FEE4 FEA8', largecircle: 0x25EF, lbar: 0x019A, lbelt: 0x026C, @@ -2787,7 +2750,6 @@ var GlyphsUnicode = { noonfinalarabic: 0xFEE6, noonghunnaarabic: 0x06BA, noonghunnafinalarabic: 0xFB9F, - noonhehinitialarabic: 0xFEE7FEEC, nooninitialarabic: 0xFEE7, noonjeeminitialarabic: 0xFCD2, noonjeemisolatedarabic: 0xFC4B, @@ -3159,27 +3121,7 @@ var GlyphsUnicode = { qof: 0x05E7, qofdagesh: 0xFB47, qofdageshhebrew: 0xFB47, - qofhatafpatah: 0x05E705B2, - qofhatafpatahhebrew: 0x05E705B2, - qofhatafsegol: 0x05E705B1, - qofhatafsegolhebrew: 0x05E705B1, qofhebrew: 0x05E7, - qofhiriq: 0x05E705B4, - qofhiriqhebrew: 0x05E705B4, - qofholam: 0x05E705B9, - qofholamhebrew: 0x05E705B9, - qofpatah: 0x05E705B7, - qofpatahhebrew: 0x05E705B7, - qofqamats: 0x05E705B8, - qofqamatshebrew: 0x05E705B8, - qofqubuts: 0x05E705BB, - qofqubutshebrew: 0x05E705BB, - qofsegol: 0x05E705B6, - qofsegolhebrew: 0x05E705B6, - qofsheva: 0x05E705B0, - qofshevahebrew: 0x05E705B0, - qoftsere: 0x05E705B5, - qoftserehebrew: 0x05E705B5, qparen: 0x24AC, quarternote: 0x2669, qubuts: 0x05BB, @@ -3253,32 +3195,11 @@ var GlyphsUnicode = { reharmenian: 0x0580, rehfinalarabic: 0xFEAE, rehiragana: 0x308C, - rehyehaleflamarabic: '0631 FEF3 FE8E 0644', rekatakana: 0x30EC, rekatakanahalfwidth: 0xFF9A, resh: 0x05E8, reshdageshhebrew: 0xFB48, - reshhatafpatah: 0x05E805B2, - reshhatafpatahhebrew: 0x05E805B2, - reshhatafsegol: 0x05E805B1, - reshhatafsegolhebrew: 0x05E805B1, reshhebrew: 0x05E8, - reshhiriq: 0x05E805B4, - reshhiriqhebrew: 0x05E805B4, - reshholam: 0x05E805B9, - reshholamhebrew: 0x05E805B9, - reshpatah: 0x05E805B7, - reshpatahhebrew: 0x05E805B7, - reshqamats: 0x05E805B8, - reshqamatshebrew: 0x05E805B8, - reshqubuts: 0x05E805BB, - reshqubutshebrew: 0x05E805BB, - reshsegol: 0x05E805B6, - reshsegolhebrew: 0x05E805B6, - reshsheva: 0x05E805B0, - reshshevahebrew: 0x05E805B0, - reshtsere: 0x05E805B5, - reshtserehebrew: 0x05E805B5, reversedtilde: 0x223D, reviahebrew: 0x0597, reviamugrashhebrew: 0x0597, @@ -3477,7 +3398,6 @@ var GlyphsUnicode = { shaddadammaarabic: 0xFC61, shaddadammatanarabic: 0xFC5E, shaddafathaarabic: 0xFC60, - shaddafathatanarabic: 0x0651064B, shaddakasraarabic: 0xFC62, shaddakasratanarabic: 0xFC5F, shade: 0x2592, @@ -3674,7 +3594,6 @@ var GlyphsUnicode = { tchehfinalarabic: 0xFB7B, tchehinitialarabic: 0xFB7C, tchehmedialarabic: 0xFB7D, - tchehmeeminitialarabic: 0xFB7CFEE4, tcircle: 0x24E3, tcircumflexbelow: 0x1E71, tcommaaccent: 0x0163, From 8cb8de3092c90e1ceb6753372ef6ab4b0b33bd57 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Wed, 29 Feb 2012 22:57:54 -0600 Subject: [PATCH 2/4] Lint error --- src/fonts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fonts.js b/src/fonts.js index d04fd1a4e..1992c0c7d 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -1947,7 +1947,7 @@ var Font = (function FontClosure() { for (var i = 0, ii = glyphs.length; i < ii; i++) { var code = glyphs[i].unicode; - var gid = ids[i] + var gid = ids[i]; var glyphName = glyphNames[gid] || encoding[code]; if (glyphName in GlyphsUnicode) { From 38e3f32557a8a96fba2fea3851a0e2d6b0563598 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Thu, 1 Mar 2012 21:23:36 -0600 Subject: [PATCH 3/4] 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!ot{m zLH?SEfB_&QM_ZHw5{Qk*FH0pjHm8nodmu;?0@XvfLg0UEunz%Y2zR_nIZ*KGef(bj z62D#HuW}F*78m`yHUxnZ!a@R9=lE~={9ZHFCPY4F{f&7o&&1S?ve|~yQLY~vzDTFD zAsW~~?m0ee#+HuuZ@~pNEJpLo^))R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-0600 Subject: [PATCH 4/4] Optimization --- src/fonts.js | 48 ++++-------------------------------------------- 1 file changed, 4 insertions(+), 44 deletions(-) diff --git a/src/fonts.js b/src/fonts.js index 0d0e12fec..df0acbbc5 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -1966,51 +1966,11 @@ var Font = (function FontClosure() { } if (glyphName in GlyphsUnicode) { var unicode = GlyphsUnicode[glyphName]; - if (!unicode || reverseMap[unicode] === i) - continue; // unknown glyph name or in its own place + if (!unicode || (unicode in reverseMap)) + continue; // unknown glyph name or its place is taken - 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]; - if (!glyphName) { - glyphName = differences[code] || encoding[code]; - changeCode = true; - } - - unicode = GlyphsUnicode[glyphName]; - if (!unicode || reverseMap[unicode] === j) { - unicode = 0; - break; // unknown glyph name or in its own place - } - - j = destination; - destination = reverseMap[unicode]; - } - - if (!unicode) { - // Future glyph cannot be assigned to unicode, generate new one. - while (reverseMap[unusedUnicode]) - unusedUnicode++; - unicode = unusedUnicode++; - } - - glyphs[j].unicode = unicode; - reverseMap[unicode] = j; + glyphs[i].unicode = unicode; + reverseMap[unicode] = i; if (changeCode) toFontChar[code] = unicode; }