eagerly compile XForm objects

This commit is contained in:
Andreas Gal 2011-06-14 22:54:49 -07:00
parent e7d6b47099
commit e8ce0b361d

21
pdf.js
View File

@ -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 += "(";