Merge pull request #9853 from Snuffleupagus/re-render-after-cancel

Fix re-rendering, using the same canvas, when rendering was previously cancelled (PR 8519 follow-up)
This commit is contained in:
Tim van der Meij 2018-06-29 23:25:43 +02:00 committed by GitHub
commit 99f8f2c275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 6 deletions

View File

@ -2380,9 +2380,10 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
InternalRenderTask.prototype = {
initializeGraphics:
function InternalRenderTask_initializeGraphics(transparency) {
initializeGraphics(transparency) {
if (this.cancelled) {
return;
}
if (this._canvas) {
if (canvasInRendering.has(this._canvas)) {
throw new Error(
@ -2393,9 +2394,6 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
canvasInRendering.set(this._canvas, this);
}
if (this.cancelled) {
return;
}
if (this._pdfBug && globalScope.StepperManager &&
globalScope.StepperManager.enabled) {
this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);

View File

@ -1253,6 +1253,37 @@ describe('api', function() {
done();
});
});
it('re-render page, using the same canvas, after cancelling rendering',
function(done) {
if (isNodeJS()) {
pending('TODO: Support Canvas testing in Node.js.');
}
let viewport = page.getViewport(1);
let canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
let renderTask = page.render({
canvasContext: canvasAndCtx.context,
viewport,
});
renderTask.cancel();
renderTask.promise.then(() => {
throw new Error('shall cancel rendering');
}, (reason) => {
expect(reason instanceof RenderingCancelledException).toEqual(true);
}).then(() => {
let reRenderTask = page.render({
canvasContext: canvasAndCtx.context,
viewport,
});
return reRenderTask.promise;
}).then(() => {
CanvasFactory.destroy(canvasAndCtx);
done();
}, done.fail);
});
it('multiple render() on the same canvas', function(done) {
if (isNodeJS()) {
pending('TODO: Support Canvas testing in Node.js.');