Change the finishPaintTask
/finishPaintTask
helpers into private methods
This commit is contained in:
parent
c2f1e65cc3
commit
6858dae1c3
@ -146,7 +146,7 @@ class IRenderableView {
|
||||
/**
|
||||
* @returns {Promise} Resolved on draw completion.
|
||||
*/
|
||||
draw() {}
|
||||
async draw() {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -746,7 +746,41 @@ class PDFPageView {
|
||||
return this.viewport.convertToPdfPoint(x, y);
|
||||
}
|
||||
|
||||
draw() {
|
||||
async #finishPaintTask(paintTask, error = null) {
|
||||
// The paintTask may have been replaced by a new one, so only remove
|
||||
// the reference to the paintTask if it matches the one that is
|
||||
// triggering this callback.
|
||||
if (paintTask === this.paintTask) {
|
||||
this.paintTask = null;
|
||||
}
|
||||
|
||||
if (error instanceof RenderingCancelledException) {
|
||||
this._renderError = null;
|
||||
return;
|
||||
}
|
||||
this._renderError = error;
|
||||
|
||||
this.renderingState = RenderingStates.FINISHED;
|
||||
this._resetZoomLayer(/* removeFromDOM = */ true);
|
||||
|
||||
// Ensure that the thumbnails won't become partially (or fully) blank,
|
||||
// for documents that contain interactive form elements.
|
||||
this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
|
||||
|
||||
this.eventBus.dispatch("pagerendered", {
|
||||
source: this,
|
||||
pageNumber: this.id,
|
||||
cssTransform: false,
|
||||
timestamp: performance.now(),
|
||||
error: this._renderError,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async draw() {
|
||||
if (this.renderingState !== RenderingStates.INITIAL) {
|
||||
console.error("Must be in new state before drawing");
|
||||
this.reset(); // Ensure that we reset all state to prevent issues.
|
||||
@ -755,7 +789,7 @@ class PDFPageView {
|
||||
|
||||
if (!pdfPage) {
|
||||
this.renderingState = RenderingStates.FINISHED;
|
||||
return Promise.reject(new Error("pdfPage is not loaded"));
|
||||
throw new Error("pdfPage is not loaded");
|
||||
}
|
||||
|
||||
this.renderingState = RenderingStates.RUNNING;
|
||||
@ -827,47 +861,13 @@ class PDFPageView {
|
||||
};
|
||||
}
|
||||
|
||||
const finishPaintTask = async (error = null) => {
|
||||
// The paintTask may have been replaced by a new one, so only remove
|
||||
// the reference to the paintTask if it matches the one that is
|
||||
// triggering this callback.
|
||||
if (paintTask === this.paintTask) {
|
||||
this.paintTask = null;
|
||||
}
|
||||
|
||||
if (error instanceof RenderingCancelledException) {
|
||||
this._renderError = null;
|
||||
return;
|
||||
}
|
||||
this._renderError = error;
|
||||
|
||||
this.renderingState = RenderingStates.FINISHED;
|
||||
this._resetZoomLayer(/* removeFromDOM = */ true);
|
||||
|
||||
// Ensure that the thumbnails won't become partially (or fully) blank,
|
||||
// for documents that contain interactive form elements.
|
||||
this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
|
||||
|
||||
this.eventBus.dispatch("pagerendered", {
|
||||
source: this,
|
||||
pageNumber: this.id,
|
||||
cssTransform: false,
|
||||
timestamp: performance.now(),
|
||||
error: this._renderError,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const paintTask = this.paintOnCanvas(canvasWrapper);
|
||||
paintTask.onRenderContinue = renderContinueCallback;
|
||||
this.paintTask = paintTask;
|
||||
|
||||
const resultPromise = paintTask.promise.then(
|
||||
() => {
|
||||
return finishPaintTask(null).then(async () => {
|
||||
return this.#finishPaintTask(paintTask).then(async () => {
|
||||
this.#renderTextLayer();
|
||||
|
||||
if (this.annotationLayer) {
|
||||
@ -891,8 +891,8 @@ class PDFPageView {
|
||||
this.#renderAnnotationEditorLayer();
|
||||
});
|
||||
},
|
||||
function (reason) {
|
||||
return finishPaintTask(reason);
|
||||
error => {
|
||||
return this.#finishPaintTask(paintTask, error);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -258,39 +258,39 @@ class PDFThumbnailView {
|
||||
reducedCanvas.height = 0;
|
||||
}
|
||||
|
||||
draw() {
|
||||
async #finishRenderTask(renderTask, canvas, error = null) {
|
||||
// The renderTask may have been replaced by a new one, so only remove
|
||||
// the reference to the renderTask if it matches the one that is
|
||||
// triggering this callback.
|
||||
if (renderTask === this.renderTask) {
|
||||
this.renderTask = null;
|
||||
}
|
||||
|
||||
if (error instanceof RenderingCancelledException) {
|
||||
return;
|
||||
}
|
||||
this.renderingState = RenderingStates.FINISHED;
|
||||
this._convertCanvasToImage(canvas);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async draw() {
|
||||
if (this.renderingState !== RenderingStates.INITIAL) {
|
||||
console.error("Must be in new state before drawing");
|
||||
return Promise.resolve();
|
||||
return undefined;
|
||||
}
|
||||
const { pdfPage } = this;
|
||||
|
||||
if (!pdfPage) {
|
||||
this.renderingState = RenderingStates.FINISHED;
|
||||
return Promise.reject(new Error("pdfPage is not loaded"));
|
||||
throw new Error("pdfPage is not loaded");
|
||||
}
|
||||
|
||||
this.renderingState = RenderingStates.RUNNING;
|
||||
|
||||
const finishRenderTask = async (error = null) => {
|
||||
// The renderTask may have been replaced by a new one, so only remove
|
||||
// the reference to the renderTask if it matches the one that is
|
||||
// triggering this callback.
|
||||
if (renderTask === this.renderTask) {
|
||||
this.renderTask = null;
|
||||
}
|
||||
|
||||
if (error instanceof RenderingCancelledException) {
|
||||
return;
|
||||
}
|
||||
this.renderingState = RenderingStates.FINISHED;
|
||||
this._convertCanvasToImage(canvas);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Render the thumbnail at a larger size and downsize the canvas (similar
|
||||
// to `setImage`), to improve consistency between thumbnails created by
|
||||
// the `draw` and `setImage` methods (fixes issue 8233).
|
||||
@ -324,12 +324,8 @@ class PDFThumbnailView {
|
||||
renderTask.onContinue = renderContinueCallback;
|
||||
|
||||
const resultPromise = renderTask.promise.then(
|
||||
function () {
|
||||
return finishRenderTask(null);
|
||||
},
|
||||
function (error) {
|
||||
return finishRenderTask(error);
|
||||
}
|
||||
() => this.#finishRenderTask(renderTask, canvas),
|
||||
error => this.#finishRenderTask(renderTask, canvas, error)
|
||||
);
|
||||
resultPromise.finally(() => {
|
||||
// Zeroing the width and height causes Firefox to release graphics
|
||||
|
Loading…
x
Reference in New Issue
Block a user