mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Convert the thumbnail view(er) code to use proper private methods
This allows us to get rid of the `@private` JSDoc comments, which were used to convey intent back when proper private methods could not be used yet in JavaScript. This improves code readability/maintenance and enables better usage validation by tooling such as ESlint.
This commit is contained in:
parent
5adad89eb3
commit
862c27ee67
2 changed files with 20 additions and 41 deletions
|
@ -55,7 +55,7 @@ class TempImageFactory {
|
|||
tempCanvas.height = height;
|
||||
|
||||
// Since this is a temporary canvas, we need to fill it with a white
|
||||
// background ourselves. `_getPageDrawContext` uses CSS rules for this.
|
||||
// background ourselves. `#getPageDrawContext` uses CSS rules for this.
|
||||
const ctx = tempCanvas.getContext("2d", { alpha: false });
|
||||
ctx.save();
|
||||
ctx.fillStyle = "rgb(255, 255, 255)";
|
||||
|
@ -196,10 +196,7 @@ class PDFThumbnailView {
|
|||
this.resume = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_getPageDrawContext(upscaleFactor = 1) {
|
||||
#getPageDrawContext(upscaleFactor = 1) {
|
||||
// Keep the no-thumbnail outline visible, i.e. `data-loaded === false`,
|
||||
// until rendering/image conversion is complete, to avoid display issues.
|
||||
const canvas = document.createElement("canvas");
|
||||
|
@ -216,14 +213,11 @@ class PDFThumbnailView {
|
|||
return { ctx, canvas, transform };
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_convertCanvasToImage(canvas) {
|
||||
#convertCanvasToImage(canvas) {
|
||||
if (this.renderingState !== RenderingStates.FINISHED) {
|
||||
throw new Error("_convertCanvasToImage: Rendering has not finished.");
|
||||
throw new Error("#convertCanvasToImage: Rendering has not finished.");
|
||||
}
|
||||
const reducedCanvas = this._reduceImage(canvas);
|
||||
const reducedCanvas = this.#reduceImage(canvas);
|
||||
|
||||
const image = document.createElement("img");
|
||||
image.className = "thumbnailImage";
|
||||
|
@ -253,7 +247,7 @@ class PDFThumbnailView {
|
|||
return;
|
||||
}
|
||||
this.renderingState = RenderingStates.FINISHED;
|
||||
this._convertCanvasToImage(canvas);
|
||||
this.#convertCanvasToImage(canvas);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
|
@ -280,7 +274,7 @@ class PDFThumbnailView {
|
|||
// NOTE: To primarily avoid increasing memory usage too much, but also to
|
||||
// reduce downsizing overhead, we purposely limit the up-scaling factor.
|
||||
const { ctx, canvas, transform } =
|
||||
this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
|
||||
this.#getPageDrawContext(DRAW_UPSCALE_FACTOR);
|
||||
const drawViewport = this.viewport.clone({
|
||||
scale: DRAW_UPSCALE_FACTOR * this.scale,
|
||||
});
|
||||
|
@ -342,14 +336,11 @@ class PDFThumbnailView {
|
|||
return;
|
||||
}
|
||||
this.renderingState = RenderingStates.FINISHED;
|
||||
this._convertCanvasToImage(canvas);
|
||||
this.#convertCanvasToImage(canvas);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_reduceImage(img) {
|
||||
const { ctx, canvas } = this._getPageDrawContext();
|
||||
#reduceImage(img) {
|
||||
const { ctx, canvas } = this.#getPageDrawContext();
|
||||
|
||||
if (img.width <= 2 * canvas.width) {
|
||||
ctx.drawImage(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue