Skip to content

Commit 54db748

Browse files
committed
Merge pull request mozilla#1831 from brendandahl/priority-rendering
Change to priority/pausible rendering.
2 parents 6c86b61 + ed7a10a commit 54db748

File tree

3 files changed

+229
-182
lines changed

3 files changed

+229
-182
lines changed

src/api.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
234234
* {
235235
* canvasContext(required): A 2D context of a DOM Canvas object.,
236236
* textLayer(optional): An object that has beginLayout, endLayout, and
237-
* appendText functions.
237+
* appendText functions.,
238+
* continueCallback(optional): A function that will be called each time
239+
* the rendering is paused. To continue
240+
* rendering call the function that is the
241+
* first argument to the callback.
238242
* }.
239243
* @return {Promise} A promise that is resolved when the page finishes
240244
* rendering.
@@ -270,6 +274,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
270274
else
271275
promise.resolve();
272276
};
277+
var continueCallback = params.continueCallback;
273278

274279
// Once the operatorList and fonts are loaded, do the actual rendering.
275280
this.displayReadyPromise.then(
@@ -282,7 +287,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
282287
var gfx = new CanvasGraphics(params.canvasContext,
283288
this.objs, params.textLayer);
284289
try {
285-
this.display(gfx, params.viewport, complete);
290+
this.display(gfx, params.viewport, complete, continueCallback);
286291
} catch (e) {
287292
complete(e);
288293
}
@@ -340,7 +345,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
340345
/**
341346
* For internal use only.
342347
*/
343-
display: function PDFPageProxy_display(gfx, viewport, callback) {
348+
display: function PDFPageProxy_display(gfx, viewport, callback,
349+
continueCallback) {
344350
var stats = this.stats;
345351
stats.time('Rendering');
346352

@@ -356,18 +362,24 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
356362
stepper.nextBreakPoint = stepper.getNextBreakPoint();
357363
}
358364

365+
var continueWrapper;
366+
if (continueCallback)
367+
continueWrapper = function() { continueCallback(next); }
368+
else
369+
continueWrapper = next;
370+
359371
var self = this;
360372
function next() {
361-
startIdx =
362-
gfx.executeOperatorList(operatorList, startIdx, next, stepper);
373+
startIdx = gfx.executeOperatorList(operatorList, startIdx,
374+
continueWrapper, stepper);
363375
if (startIdx == length) {
364376
gfx.endDrawing();
365377
stats.timeEnd('Rendering');
366378
stats.timeEnd('Overall');
367379
if (callback) callback();
368380
}
369381
}
370-
next();
382+
continueWrapper();
371383
},
372384
/**
373385
* @return {Promise} That is resolved with the a {string} that is the text

src/fonts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ var FontLoader = {
532532

533533
// XXX we should have a time-out here too, and maybe fire
534534
// pdfjsFontLoadFailed?
535-
var src = '<!DOCTYPE HTML><html><head>';
535+
var src = '<!DOCTYPE HTML><html><head><meta charset="utf-8">';
536536
src += '<style type="text/css">';
537537
for (var i = 0, ii = rules.length; i < ii; ++i) {
538538
src += rules[i];

0 commit comments

Comments
 (0)