[Pkg-javascript-commits] [pdf.js] 97/141: Fix seac regression.

David Prévot taffit at moszumanska.debian.org
Sat Apr 19 22:40:34 UTC 2014


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

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

commit b242826d2966955a73a0d754ba6d53ddfc2cf674
Author: Brendan Dahl <brendan.dahl at gmail.com>
Date:   Fri Apr 11 09:55:39 2014 -0700

    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(-)

diff --git a/src/core/fonts.js b/src/core/fonts.js
index ee927ab..8056dc7 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 70f8aa8..38d7c5a 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 0000000..128af35
Binary files /dev/null and b/test/pdfs/issue4573.pdf differ
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 738232d..b7971ef 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",

-- 
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