]> git.parisson.com Git - pdf.js.git/commitdiff
eagerly compile XForm objects
authorAndreas Gal <andreas.gal@gmail.com>
Wed, 15 Jun 2011 05:54:49 +0000 (22:54 -0700)
committerAndreas Gal <andreas.gal@gmail.com>
Wed, 15 Jun 2011 05:54:49 +0000 (22:54 -0700)
pdf.js

diff --git a/pdf.js b/pdf.js
index 20299909e28c270e5d74c13246f5165b06b2f3c6..48e20c455bbe0af63a97bd3bd0d2a12fa6c37932 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -1689,8 +1689,7 @@ var CanvasGraphics = (function() {
             var savedXref = this.xref, savedRes = this.res, savedXobjs = this.xobjs;
             this.xref = xref;
             this.res = resources || new Dict();
-            this.xobjs = this.res.get("XObject") || new Dict();
-            this.xobjs = this.xref.fetchIfRef(this.xobjs);
+            this.xobjs = xref.fetchIfRef(this.res.get("XObject")) || new Dict();
 
             stream.execute(this);
 
@@ -1700,6 +1699,8 @@ var CanvasGraphics = (function() {
         },
 
         compile: function(stream, xref, resources) {
+            var xobjs = xref.fetchIfRef(resources.get("XObject")) || new Dict();
+
             var parser = new Parser(new Lexer(stream), false);
             var objpool = [];
 
@@ -1724,6 +1725,22 @@ var CanvasGraphics = (function() {
                     assertWellFormed(fn, "Unknown command '" + cmd + "'");
                     // TODO figure out how to type-check vararg functions
 
+                    if (cmd == "Do") { // eagerly compile XForm objects
+                        var name = args[0].name;
+                        var xobj = xobjs.get(name);
+                        if (xobj) {
+                            xobj = xref.fetchIfRef(xobj);
+                            assertWellFormed(IsStream(xobj), "XObject should be a stream");
+
+                            var type = xobj.dict.get("Subtype");
+                            assertWellFormed(IsName(type), "XObject should have a Name subtype");
+
+                            if ("Form" == type.name) {
+                                this.compile(xobj, xref, xobj.dict.get("Resources"));
+                            }
+                        }
+                    }
+
                     src += "this.";
                     src += fn;
                     src += "(";