]> git.parisson.com Git - pdf.js.git/commitdiff
Add the 'for' keyword and support 2's complement signed integer
authorVivien Nicolas <21@vingtetun.org>
Fri, 3 Jun 2011 22:43:50 +0000 (00:43 +0200)
committerVivien Nicolas <21@vingtetun.org>
Fri, 3 Jun 2011 22:43:50 +0000 (00:43 +0200)
PDFFont.js
pdf.js

index 6a7c49b7bf40c667fda0b15c7a17a21c495bd6a3..51e8282d1ed78e0dc85707368cb3b132787ec1fb 100644 (file)
@@ -153,7 +153,11 @@ var Type1Parser = function(aAsciiStream, aBinaryStream) {
         value = -((value - 251) * 256) - parseInt(aStream.getByte()) - 108;
         count++;
       } else {
-        error("Two complement signed integers are ignored for the moment");
+        var byte = aStream.getByte();
+        var high = (byte >> 1);
+        value = (byte - high) * 16777216 + aStream.getByte() * 65536 +
+                aStream.getByte() * 256 *  + aStream.getByte();
+        count += 4;
       }
 
       charString.push(value);
@@ -372,6 +376,17 @@ var Type1Parser = function(aAsciiStream, aBinaryStream) {
           executionStack.push(bool ? procedure2 : procedure1);
           break;
 
+        case "for":
+          var procedure = operandStack.pop();
+          var limit = operandStack.pop();
+          var increment = operandStack.pop();
+          var initial = operandStack.pop();
+          for (var i = 0; i < limit; i += increment) {
+            operandStack.push(i);
+            executionStack.push(procedure.slice());
+          }
+          break;
+
         case "dup":
           dump("duplicate: " + operandStack.peek());
           operandStack.push(operandStack.peek());
@@ -459,6 +474,12 @@ var Type1Parser = function(aAsciiStream, aBinaryStream) {
         case "def":
           var value = operandStack.pop();
           var key = operandStack.pop();
+
+          if (key == "FontName" && Fonts.get(value)) {
+            // The font has already be decoded, stop!
+            return true;
+          }
+
           dump("def: " + key + " = " + value);
           dictionaryStack.peek().set(key, value);
           break;
@@ -573,26 +594,20 @@ var Type1Parser = function(aAsciiStream, aBinaryStream) {
 };
 
 
-var hack = true;
-
 var Type1Font = function(aFontName, aFontFile) {
   // All Type1 font program should begin with the comment %!
   if (aFontFile.getByte() != 0x25 || aFontFile.getByte() != 0x21)
     error("Invalid file header");
 
-  if (hack) {
-    var start = Date.now();
+  var start = Date.now();
 
-    var ASCIIStream = aFontFile.makeSubStream(0, aFontFile.dict.get("Length1"), aFontFile.dict);
-    var binaryStream = aFontFile.makeSubStream(aFontFile.dict.get("Length1"), aFontFile.dict.get("Length2"), aFontFile.dict);
+  var ASCIIStream = aFontFile.makeSubStream(0, aFontFile.dict.get("Length1"), aFontFile.dict);
+  var binaryStream = aFontFile.makeSubStream(aFontFile.dict.get("Length1"), aFontFile.dict.get("Length2"), aFontFile.dict);
 
-    this.parser = new Type1Parser(ASCIIStream, binaryStream);
-    this.parser.parse();
+  this.parser = new Type1Parser(ASCIIStream, binaryStream);
+  this.parser.parse();
 
-    var end = Date.now();
-    dump("Time to parse font is:" + (end - start));
-    
-    hack = false;
-  }
+  var end = Date.now();
+  dump("Time to parse font is:" + (end - start));
 };
 
diff --git a/pdf.js b/pdf.js
index 001882ad334e26e06d2c0f48a3618eb79b8bb149..cca5ae73073d0e5a3de1f5eeba4f9d6dedba85bc 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -2291,6 +2291,10 @@ var CanvasGraphics = (function() {
                 TODO("support Type3 font");
                 break;
 
+              case "TrueType":
+                TODO("implement TrueType support");
+                break;
+
               default:
                 error("Unsupported font type: " + subtype);
                 break;