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