1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

Change to priority rendering.

This commit is contained in:
Brendan Dahl 2012-06-18 09:48:47 -07:00
parent a32d875cc3
commit 3c874c9bb7
2 changed files with 214 additions and 167 deletions

View file

@ -234,7 +234,11 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* {
* canvasContext(required): A 2D context of a DOM Canvas object.,
* textLayer(optional): An object that has beginLayout, endLayout, and
* appendText functions.
* appendText functions.,
* continueCallback(optional): A function that will be called each time
* the rendering is paused. To continue
* rendering call the function that is the
* first argument to the callback.
* }.
* @return {Promise} A promise that is resolved when the page finishes
* rendering.
@ -270,6 +274,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
else
promise.resolve();
};
var continueCallback = params.continueCallback;
// Once the operatorList and fonts are loaded, do the actual rendering.
this.displayReadyPromise.then(
@ -282,7 +287,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
var gfx = new CanvasGraphics(params.canvasContext,
this.objs, params.textLayer);
try {
this.display(gfx, params.viewport, complete);
this.display(gfx, params.viewport, complete, continueCallback);
} catch (e) {
complete(e);
}
@ -340,7 +345,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
/**
* For internal use only.
*/
display: function PDFPageProxy_display(gfx, viewport, callback) {
display: function PDFPageProxy_display(gfx, viewport, callback,
continueCallback) {
var stats = this.stats;
stats.time('Rendering');
@ -356,10 +362,16 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
stepper.nextBreakPoint = stepper.getNextBreakPoint();
}
var continueWrapper;
if (continueCallback)
continueWrapper = function() { continueCallback(next); }
else
continueWrapper = next;
var self = this;
function next() {
startIdx =
gfx.executeOperatorList(operatorList, startIdx, next, stepper);
startIdx = gfx.executeOperatorList(operatorList, startIdx,
continueWrapper, stepper);
if (startIdx == length) {
gfx.endDrawing();
stats.timeEnd('Rendering');
@ -367,7 +379,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
if (callback) callback();
}
}
next();
continueWrapper();
},
/**
* @return {Promise} That is resolved with the a {string} that is the text