mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-31 19:37:21 +02:00
Merge pull request #21021 from Snuffleupagus/PDFThumbnailView-unconditional-OffscreenCanvas
Use `OffscreenCanvas` unconditionally in the `web/pdf_thumbnail_view.js` file
This commit is contained in:
commit
cc5e30b99c
@ -21,11 +21,7 @@
|
|||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
/** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */
|
/** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */
|
||||||
|
|
||||||
import {
|
import { OutputScale, RenderingCancelledException } from "pdfjs-lib";
|
||||||
FeatureTest,
|
|
||||||
OutputScale,
|
|
||||||
RenderingCancelledException,
|
|
||||||
} from "pdfjs-lib";
|
|
||||||
import { RenderableView, RenderingStates } from "./renderable_view.js";
|
import { RenderableView, RenderingStates } from "./renderable_view.js";
|
||||||
import { AppOptions } from "./app_options.js";
|
import { AppOptions } from "./app_options.js";
|
||||||
|
|
||||||
@ -55,26 +51,16 @@ const THUMBNAIL_WIDTH = 126; // px
|
|||||||
* mode.
|
* mode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class TempImageFactory {
|
function getTempCanvas(width, height) {
|
||||||
static getCanvas(width, height) {
|
const canvas = new OffscreenCanvas(width, height);
|
||||||
let tempCanvas;
|
// Since this is a temporary canvas, we need to fill it with a white
|
||||||
if (FeatureTest.isOffscreenCanvasSupported) {
|
// background ourselves. `#getPageDrawContext` uses CSS rules for this.
|
||||||
tempCanvas = new OffscreenCanvas(width, height);
|
const ctx = canvas.getContext("2d", { alpha: false });
|
||||||
} else {
|
ctx.save();
|
||||||
tempCanvas = document.createElement("canvas");
|
ctx.fillStyle = "rgb(255, 255, 255)";
|
||||||
tempCanvas.width = width;
|
ctx.fillRect(0, 0, width, height);
|
||||||
tempCanvas.height = height;
|
ctx.restore();
|
||||||
}
|
return [canvas, ctx];
|
||||||
|
|
||||||
// Since this is a temporary canvas, we need to fill it with a white
|
|
||||||
// background ourselves. `#getPageDrawContext` uses CSS rules for this.
|
|
||||||
const ctx = tempCanvas.getContext("2d", { alpha: false });
|
|
||||||
ctx.save();
|
|
||||||
ctx.fillStyle = "rgb(255, 255, 255)";
|
|
||||||
ctx.fillRect(0, 0, width, height);
|
|
||||||
ctx.restore();
|
|
||||||
return [tempCanvas, ctx];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PDFThumbnailView extends RenderableView {
|
class PDFThumbnailView extends RenderableView {
|
||||||
@ -364,10 +350,6 @@ class PDFThumbnailView extends RenderableView {
|
|||||||
image.setAttribute("data-l10n-id", "pdfjs-thumb-page-canvas");
|
image.setAttribute("data-l10n-id", "pdfjs-thumb-page-canvas");
|
||||||
image.setAttribute("data-l10n-args", this.#getPageL10nArgs());
|
image.setAttribute("data-l10n-args", this.#getPageL10nArgs());
|
||||||
imageContainer.classList.remove("missingThumbnailImage");
|
imageContainer.classList.remove("missingThumbnailImage");
|
||||||
if (!FeatureTest.isOffscreenCanvasSupported) {
|
|
||||||
// Clean up the canvas element since it is no longer needed.
|
|
||||||
reducedCanvas.width = reducedCanvas.height = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async draw() {
|
async draw() {
|
||||||
@ -506,7 +488,7 @@ class PDFThumbnailView extends RenderableView {
|
|||||||
}
|
}
|
||||||
// drawImage does an awful job of rescaling the image, doing it gradually.
|
// drawImage does an awful job of rescaling the image, doing it gradually.
|
||||||
let [reducedWidth, reducedHeight] = this.#getReducedImageDims(canvas);
|
let [reducedWidth, reducedHeight] = this.#getReducedImageDims(canvas);
|
||||||
const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(
|
const [reducedImage, reducedImageCtx] = getTempCanvas(
|
||||||
reducedWidth,
|
reducedWidth,
|
||||||
reducedHeight
|
reducedHeight
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user