]> git.parisson.com Git - pdf.js.git/commitdiff
more robust fontMatrix parsing, error checking
authorArtur Adib <arturadib@gmail.com>
Fri, 20 Jan 2012 19:55:52 +0000 (14:55 -0500)
committerArtur Adib <arturadib@gmail.com>
Fri, 20 Jan 2012 19:55:52 +0000 (14:55 -0500)
src/canvas.js
src/fonts.js

index 5ef9008610a2b0b12c3978a0b9d516e97476bd05..6ec8076cf0e786c728ce899b484366172d7cd75e 100644 (file)
@@ -551,6 +551,16 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
         throw 'Can\'t find font for ' + fontRefName;
       }
 
+      // If any of the diagonal elements of a transformation matrix are null
+      // ctx.restore() will fail in FF. See bugzilla bug #719844.
+      if (fontObj.fontMatrix[0] === 0 ||
+          fontObj.fontMatrix[3] === 0 ) {
+        warn('Invalid font matrix for font ' + fontRefName);
+
+        // Fallback
+        fontObj.fontMatrix = IDENTITY_MATRIX;
+      }
+
       var name = fontObj.loadedName || 'sans-serif';
 
       this.current.font = fontObj;
index f96c15458518c28f2d2af84a438781f4743d2458..96a11d1fad7a011f5bae6b719f75d3364525041b 100644 (file)
@@ -2594,7 +2594,15 @@ var Type1Parser = function type1Parser() {
     while (str[index++] != ']')
       count++;
 
-    var array = str.substr(start, count).split(' ');
+    str = str.substr(start, count);
+
+    // Trim
+    str = str.replace(/^\s+/, '');
+    str = str.replace(/\s+$/, '');
+    // Remove adjacent spaces
+    str = str.replace(/\s+/g, ' ');
+
+    var array = str.split(' ');
     for (var i = 0, ii = array.length; i < ii; i++)
       array[i] = parseFloat(array[i] || 0);
     return array;