[Pkg-javascript-commits] [pdf.js] 98/116: Don't skip mapping of glyphs for CIDFontType2 fonts with a CIDToGIDMap

David Prévot taffit at moszumanska.debian.org
Fri Mar 6 16:20:05 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 8174da61fb9e6d86831b6ba71c1a8eed55328a8f
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Fri Jan 2 14:21:56 2015 +0100

    Don't skip mapping of glyphs for CIDFontType2 fonts with a CIDToGIDMap
    
    Also don't skip mapping of glyphs which are empty, if the corresponding charCode is included in toUnicode.
---
 src/core/fonts.js       |  26 ++++++++++++++++++--------
 test/pdfs/.gitignore    |   2 ++
 test/pdfs/issue4061.pdf | Bin 0 -> 115240 bytes
 test/pdfs/issue5202.pdf | Bin 0 -> 5241 bytes
 test/test_manifest.json |  14 ++++++++++++++
 5 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/src/core/fonts.js b/src/core/fonts.js
index 872a5b0..8a191e1 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -2203,6 +2203,10 @@ var ToUnicodeMap = (function ToUnicodeMapClosure() {
       }
     },
 
+    has: function(i) {
+      return this._map[i] !== undefined;
+    },
+
     get: function(i) {
       return this._map[i];
     },
@@ -2232,6 +2236,10 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
       }
     },
 
+    has: function (i) {
+      return this.firstChar <= i && i <= this.lastChar;
+    },
+
     get: function (i) {
       if (this.firstChar <= i && i <= this.lastChar) {
         return String.fromCharCode(i);
@@ -2664,7 +2672,6 @@ var Font = (function FontClosure() {
     var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
     var isIdentityUnicode =
       properties.toUnicode instanceof IdentityToUnicodeMap;
-    var isCidFontType2 = (properties.type === 'CIDFontType2');
     var newMap = Object.create(null);
     var toFontChar = [];
     var usedFontCharCodes = [];
@@ -2675,8 +2682,7 @@ var Font = (function FontClosure() {
       var fontCharCode = originalCharCode;
       // First try to map the value to a unicode position if a non identity map
       // was created.
-      // console.log(fontCharCode);
-      if (!isIdentityUnicode && toUnicode.get(originalCharCode) !== undefined) {
+      if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
         var unicode = toUnicode.get(fontCharCode);
         // TODO: Try to map ligatures to the correct spot.
         if (unicode.length === 1) {
@@ -4040,8 +4046,9 @@ var Font = (function FontClosure() {
       if (isTrueType) {
         var isGlyphLocationsLong = int16(tables.head.data[50],
                                          tables.head.data[51]);
-        missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
-                               isGlyphLocationsLong, hintsValid, dupFirstEntry);
+        missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
+                                               numGlyphs, isGlyphLocationsLong,
+                                               hintsValid, dupFirstEntry);
       }
 
       if (!tables.hhea) {
@@ -4066,17 +4073,20 @@ var Font = (function FontClosure() {
       var charCodeToGlyphId = [], charCode;
       if (properties.type === 'CIDFontType2') {
         var cidToGidMap = properties.cidToGidMap || [];
-        var cidToGidMapLength = cidToGidMap.length;
+        var isCidToGidMapEmpty = cidToGidMap.length === 0;
+        var toUnicode = properties.toUnicode;
+
         properties.cMap.forEach(function(charCode, cid) {
           assert(cid <= 0xffff, 'Max size of CID is 65,535');
           var glyphId = -1;
-          if (cidToGidMapLength === 0) {
+          if (isCidToGidMapEmpty) {
             glyphId = charCode;
           } else if (cidToGidMap[cid] !== undefined) {
             glyphId = cidToGidMap[cid];
           }
 
-          if (glyphId >= 0 && glyphId < numGlyphs && !missingGlyphs[charCode]) {
+          if (glyphId >= 0 && glyphId < numGlyphs &&
+              (!missingGlyphs[glyphId] || toUnicode.has(charCode))) {
             charCodeToGlyphId[charCode] = glyphId;
           }
         });
diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore
index e612c39..8108d7c 100644
--- a/test/pdfs/.gitignore
+++ b/test/pdfs/.gitignore
@@ -18,6 +18,7 @@
 !sizes.pdf
 !close-path-bug.pdf
 !issue4630.pdf
+!issue5202.pdf
 !issue5280.pdf
 !alphatrans.pdf
 !devicen.pdf
@@ -62,6 +63,7 @@
 !issue1002.pdf
 !issue925.pdf
 !issue2840.pdf
+!issue4061.pdf
 !issue4668.pdf
 !issue5039.pdf
 !issue5070.pdf
diff --git a/test/pdfs/issue4061.pdf b/test/pdfs/issue4061.pdf
new file mode 100644
index 0000000..ace045d
Binary files /dev/null and b/test/pdfs/issue4061.pdf differ
diff --git a/test/pdfs/issue5202.pdf b/test/pdfs/issue5202.pdf
new file mode 100644
index 0000000..7196c55
Binary files /dev/null and b/test/pdfs/issue5202.pdf differ
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 1e05ff5..797ddd8 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -485,6 +485,20 @@
        "lastPage": 1,
        "type": "eq"
     },
+    {  "id": "issue4061",
+       "file": "pdfs/issue4061.pdf",
+       "md5": "236aaa8840a47c3c061f8e3034549764",
+       "rounds": 1,
+       "link": false,
+       "type": "eq"
+    },
+    {  "id": "issue5202",
+       "file": "pdfs/issue5202.pdf",
+       "md5": "bb9cc69211112e66aab40828086a4e5a",
+       "rounds": 1,
+       "link": false,
+       "type": "eq"
+    },
     {  "id": "issue5238",
        "file": "pdfs/issue5238.pdf",
        "md5": "6ddecda00893be1793de20a70c83a3c2",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list