[api-minor] Add an option to set the max canvas area
This commit is contained in:
parent
e0d934ac9d
commit
e9474f1c84
@ -71,6 +71,7 @@ import { getGlyphsUnicode } from "./glyphlist.js";
|
||||
import { getLookupTableFactory } from "./core_utils.js";
|
||||
import { getMetrics } from "./metrics.js";
|
||||
import { getUnicodeForGlyph } from "./unicode.js";
|
||||
import { ImageResizer } from "./image_resizer.js";
|
||||
import { MurmurHash3_64 } from "../shared/murmurhash3.js";
|
||||
import { OperatorList } from "./operator_list.js";
|
||||
import { PDFImage } from "./image.js";
|
||||
@ -81,6 +82,7 @@ const DefaultPartialEvaluatorOptions = Object.freeze({
|
||||
ignoreErrors: false,
|
||||
isEvalSupported: true,
|
||||
isOffscreenCanvasSupported: false,
|
||||
canvasMaxAreaInBytes: -1,
|
||||
fontExtraProperties: false,
|
||||
useSystemFonts: true,
|
||||
cMapUrl: null,
|
||||
@ -229,6 +231,7 @@ class PartialEvaluator {
|
||||
this.parsingType3Font = false;
|
||||
|
||||
this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
|
||||
ImageResizer.setMaxArea(this.options.canvasMaxAreaInBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,8 +103,17 @@ class ImageResizer {
|
||||
}
|
||||
|
||||
static set MAX_AREA(area) {
|
||||
this._hasMaxArea = true;
|
||||
shadow(this, "MAX_AREA", area);
|
||||
if (area >= 0) {
|
||||
this._hasMaxArea = true;
|
||||
shadow(this, "MAX_AREA", area);
|
||||
}
|
||||
}
|
||||
|
||||
static setMaxArea(area) {
|
||||
if (!this._hasMaxArea) {
|
||||
// Divide by 4 to have the value in pixels.
|
||||
this.MAX_AREA = area >> 2;
|
||||
}
|
||||
}
|
||||
|
||||
static _areGoodDims(width, height) {
|
||||
|
@ -201,6 +201,9 @@ if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
||||
* `OffscreenCanvas` in the worker. Primarily used to improve performance of
|
||||
* image conversion/rendering.
|
||||
* The default value is `true` in web environments and `false` in Node.js.
|
||||
* @property {boolean} [canvasMaxAreaInBytes] - The integer value is used to
|
||||
* know when an image must be resized (uses `OffscreenCanvas` in the worker).
|
||||
* If it's -1 then a possibly slow algorithm is used to guess the max value.
|
||||
* @property {boolean} [disableFontFace] - By default fonts are converted to
|
||||
* OpenType fonts and loaded via the Font Loading API or `@font-face` rules.
|
||||
* If disabled, fonts will be rendered using a built-in font renderer that
|
||||
@ -306,6 +309,9 @@ function getDocument(src) {
|
||||
typeof src.isOffscreenCanvasSupported === "boolean"
|
||||
? src.isOffscreenCanvasSupported
|
||||
: !isNodeJS;
|
||||
const canvasMaxAreaInBytes = Number.isInteger(src.canvasMaxAreaInBytes)
|
||||
? src.canvasMaxAreaInBytes
|
||||
: -1;
|
||||
const disableFontFace =
|
||||
typeof src.disableFontFace === "boolean" ? src.disableFontFace : isNodeJS;
|
||||
const fontExtraProperties = src.fontExtraProperties === true;
|
||||
@ -393,6 +399,7 @@ function getDocument(src) {
|
||||
ignoreErrors,
|
||||
isEvalSupported,
|
||||
isOffscreenCanvasSupported,
|
||||
canvasMaxAreaInBytes,
|
||||
fontExtraProperties,
|
||||
useSystemFonts,
|
||||
cMapUrl: useWorkerFetch ? cMapUrl : null,
|
||||
|
10
web/app.js
10
web/app.js
@ -149,6 +149,10 @@ class DefaultExternalServices {
|
||||
static updateEditorStates(data) {
|
||||
throw new Error("Not implemented: updateEditorStates");
|
||||
}
|
||||
|
||||
static get canvasMaxAreaInBytes() {
|
||||
return shadow(this, "canvasMaxAreaInBytes", -1);
|
||||
}
|
||||
}
|
||||
|
||||
const PDFViewerApplication = {
|
||||
@ -945,7 +949,11 @@ const PDFViewerApplication = {
|
||||
}
|
||||
// Set the necessary API parameters, using all the available options.
|
||||
const apiParams = AppOptions.getAll(OptionKind.API);
|
||||
const params = { ...apiParams, ...args };
|
||||
const params = {
|
||||
canvasMaxAreaInBytes: this.externalServices.canvasMaxAreaInBytes,
|
||||
...apiParams,
|
||||
...args,
|
||||
};
|
||||
|
||||
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
||||
params.docBaseUrl ||= document.URL.split("#")[0];
|
||||
|
@ -434,6 +434,11 @@ class FirefoxExternalServices extends DefaultExternalServices {
|
||||
const isInAutomation = FirefoxCom.requestSync("isInAutomation");
|
||||
return shadow(this, "isInAutomation", isInAutomation);
|
||||
}
|
||||
|
||||
static get canvasMaxAreaInBytes() {
|
||||
const maxArea = FirefoxCom.requestSync("getCanvasMaxArea");
|
||||
return shadow(this, "canvasMaxAreaInBytes", maxArea);
|
||||
}
|
||||
}
|
||||
PDFViewerApplication.externalServices = FirefoxExternalServices;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user