mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 23:28:06 +02:00
Merge pull request #1831 from brendandahl/priority-rendering
Change to priority/pausible rendering.
This commit is contained in:
commit
54db7489bd
3 changed files with 227 additions and 180 deletions
24
src/api.js
24
src/api.js
|
@ -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
|
||||
|
|
|
@ -532,7 +532,7 @@ var FontLoader = {
|
|||
|
||||
// XXX we should have a time-out here too, and maybe fire
|
||||
// pdfjsFontLoadFailed?
|
||||
var src = '<!DOCTYPE HTML><html><head>';
|
||||
var src = '<!DOCTYPE HTML><html><head><meta charset="utf-8">';
|
||||
src += '<style type="text/css">';
|
||||
for (var i = 0, ii = rules.length; i < ii; ++i) {
|
||||
src += rules[i];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue