1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

[api-minor] Make isOffscreenCanvasSupported configurable via the API (issue 14952)

This patch first of all makes `isOffscreenCanvasSupported` configurable, defaulting to `true` in browsers and `false` in Node.js environments, with a new `getDocument` parameter. While you normally want to use this, in order to improve performance, it should still be possible for users to control it (similar to e.g. `isEvalSupported`).

The specific problem, as reported in issue 14952, is that the SVG back-end doesn't support the new ImageMask data-format that's introduced in PR 14754. In particular:
 - When the SVG back-end is used in Node.js environments, this patch will "just work" without the user needing to make any code changes.
 - If the SVG back-end is used in browsers, this patch will require that `isOffscreenCanvasSupported: false` is added to the `getDocument`-call.
This commit is contained in:
Jonas Jenwald 2022-10-06 22:05:32 +02:00
parent 7d5f7a517c
commit 1ea4c4b519
6 changed files with 37 additions and 5 deletions

View file

@ -84,6 +84,7 @@ const DefaultPartialEvaluatorOptions = Object.freeze({
disableFontFace: false,
ignoreErrors: false,
isEvalSupported: true,
isOffscreenCanvasSupported: true,
fontExtraProperties: false,
useSystemFonts: true,
cMapUrl: null,
@ -652,6 +653,7 @@ class PartialEvaluator {
imageIsFromDecodeStream: image instanceof DecodeStream,
inverseDecode: !!decode && decode[0] > 0,
interpolate,
isOffscreenCanvasSupported: this.options.isOffscreenCanvasSupported,
});
if (imgData.isSingleOpaquePixel) {

View file

@ -356,6 +356,7 @@ class PDFImage {
imageIsFromDecodeStream,
inverseDecode,
interpolate,
isOffscreenCanvasSupported = true,
}) {
const isSingleOpaquePixel =
width === 1 &&
@ -366,7 +367,7 @@ class PDFImage {
return { isSingleOpaquePixel };
}
if (FeatureTest.isOffscreenCanvasSupported) {
if (isOffscreenCanvasSupported && FeatureTest.isOffscreenCanvasSupported) {
const canvas = new OffscreenCanvas(width, height);
const ctx = canvas.getContext("2d");
const imgData = ctx.createImageData(width, height);

View file

@ -410,6 +410,7 @@ class WorkerMessageHandler {
disableFontFace: data.disableFontFace,
ignoreErrors: data.ignoreErrors,
isEvalSupported: data.isEvalSupported,
isOffscreenCanvasSupported: data.isOffscreenCanvasSupported,
fontExtraProperties: data.fontExtraProperties,
useSystemFonts: data.useSystemFonts,
cMapUrl: data.cMapUrl,