Browse Source

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

Julian Viereck 14 years ago
parent
commit
52aba8648e
  1. 36
      src/core.js

36
src/core.js

@ -70,8 +70,7 @@ var Page = (function PageClosure() { @@ -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() { @@ -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() { @@ -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();
// 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));
}
};

Loading…
Cancel
Save