Add displayReadyPromise to the Page object to not request the IRQueue all the time and simplify some stuff

This commit is contained in:
Julian Viereck 2011-12-22 19:04:53 +01:00
parent 0c22e5d653
commit 52aba8648e

View File

@ -70,8 +70,7 @@ var Page = (function PageClosure() {
this.xref = xref;
this.ref = ref;
this.ctx = null;
this.callback = null;
this.displayReadyPromise = null;
}
Page.prototype = {
@ -167,20 +166,12 @@ var Page = (function PageClosure() {
IRQueue, fonts) {
var self = this;
this.IRQueue = IRQueue;
var gfx = new CanvasGraphics(this.ctx, this.objs, this.textLayer);
var displayContinuation = function pageDisplayContinuation() {
// Always defer call to display() to work around bug in
// Firefox error reporting from XHR callbacks.
setTimeout(function pageSetTimeout() {
try {
self.display(gfx, self.callback);
} catch (e) {
if (self.callback)
self.callback(e);
else
throw e;
}
self.displayReadyPromise.resolve();
});
};
@ -397,12 +388,27 @@ var Page = (function PageClosure() {
return items;
},
startRendering: function pageStartRendering(ctx, callback, textLayer) {
this.ctx = ctx;
this.callback = callback;
this.textLayer = textLayer;
this.startRenderingTime = Date.now();
this.pdf.startRendering(this);
// If there is no displayReadyPromise yet, then the IRQueue was never
// requested before. Make the request and create the promise.
if (!this.displayReadyPromise) {
this.pdf.startRendering(this);
this.displayReadyPromise = new Promise();
}
// Once the IRQueue and fonts are loaded, perform the actual rendering.
this.displayReadyPromise.then(function pageDisplayReadyPromise() {
var gfx = new CanvasGraphics(ctx, this.objs, textLayer);
try {
this.display(gfx, callback);
} catch (e) {
if (self.callback)
self.callback(e);
else
throw e;
}
}.bind(this));
}
};