From db53320da81499c643783250af059f18e923f3f0 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 30 Jan 2025 11:46:38 +0100 Subject: [PATCH] Initialize the image-options, on the worker-thread, once per document Currently we're initializing the image-options for every page, which seems unnecessary since it should suffice to do that once per document. Also, changes the `BasePdfManager` constructor to improve readability/documentation a little bit. --- src/core/evaluator.js | 10 ---------- src/core/pdf_manager.js | 35 +++++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 07253e647..d8a88c656 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -75,9 +75,6 @@ import { getFontSubstitution } from "./font_substitutions.js"; import { getGlyphsUnicode } from "./glyphlist.js"; import { getMetrics } from "./metrics.js"; import { getUnicodeForGlyph } from "./unicode.js"; -import { ImageResizer } from "./image_resizer.js"; -import { JpegStream } from "./jpeg_stream.js"; -import { JpxImage } from "./jpx.js"; import { MurmurHash3_64 } from "../shared/murmurhash3.js"; import { OperatorList } from "./operator_list.js"; import { PDFImage } from "./image.js"; @@ -240,13 +237,6 @@ class PartialEvaluator { this._regionalImageCache = new RegionalImageCache(); this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this); - - ImageResizer.setOptions(this.options); - JpegStream.setOptions(this.options); - JpxImage.setOptions({ - wasmUrl: this.options.wasmUrl, - handler, - }); } /** diff --git a/src/core/pdf_manager.js b/src/core/pdf_manager.js index 94285f47e..3b277ea85 100644 --- a/src/core/pdf_manager.js +++ b/src/core/pdf_manager.js @@ -20,6 +20,9 @@ import { warn, } from "../shared/util.js"; import { ChunkedStreamManager } from "./chunked_stream.js"; +import { ImageResizer } from "./image_resizer.js"; +import { JpegStream } from "./jpeg_stream.js"; +import { JpxImage } from "./jpx.js"; import { MissingDataException } from "./core_utils.js"; import { PDFDocument } from "./document.js"; import { Stream } from "./stream.js"; @@ -36,25 +39,41 @@ function parseDocBaseUrl(url) { } class BasePdfManager { - constructor(args) { + constructor({ + // source, + // disableAutoFetch, + docBaseUrl, + docId, + enableXfa, + evaluatorOptions, + handler, + // length, + password, + // rangeChunkSize, + }) { if ( (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) && this.constructor === BasePdfManager ) { unreachable("Cannot initialize BasePdfManager."); } - this._docBaseUrl = parseDocBaseUrl(args.docBaseUrl); - this._docId = args.docId; - this._password = args.password; - this.enableXfa = args.enableXfa; + this._docBaseUrl = parseDocBaseUrl(docBaseUrl); + this._docId = docId; + this._password = password; + this.enableXfa = enableXfa; // Check `OffscreenCanvas` and `ImageDecoder` support once, // rather than repeatedly throughout the worker-thread code. - args.evaluatorOptions.isOffscreenCanvasSupported &&= + evaluatorOptions.isOffscreenCanvasSupported &&= FeatureTest.isOffscreenCanvasSupported; - args.evaluatorOptions.isImageDecoderSupported &&= + evaluatorOptions.isImageDecoderSupported &&= FeatureTest.isImageDecoderSupported; - this.evaluatorOptions = Object.freeze(args.evaluatorOptions); + this.evaluatorOptions = Object.freeze(evaluatorOptions); + + // Initially image-options once per document. + ImageResizer.setOptions(evaluatorOptions); + JpegStream.setOptions(evaluatorOptions); + JpxImage.setOptions({ ...evaluatorOptions, handler }); } get docId() {