diff options
Diffstat (limited to 'toolkit/components/pdfjs/content/build')
-rw-r--r-- | toolkit/components/pdfjs/content/build/pdf.mjs | 219 | ||||
-rw-r--r-- | toolkit/components/pdfjs/content/build/pdf.scripting.mjs | 4 | ||||
-rw-r--r-- | toolkit/components/pdfjs/content/build/pdf.worker.mjs | 274 |
3 files changed, 276 insertions, 221 deletions
diff --git a/toolkit/components/pdfjs/content/build/pdf.mjs b/toolkit/components/pdfjs/content/build/pdf.mjs index 4e51efdb78..dbba618862 100644 --- a/toolkit/components/pdfjs/content/build/pdf.mjs +++ b/toolkit/components/pdfjs/content/build/pdf.mjs @@ -70,7 +70,6 @@ __webpack_require__.d(__webpack_exports__, { PasswordResponses: () => (/* reexport */ PasswordResponses), PermissionFlag: () => (/* reexport */ PermissionFlag), PixelsPerInch: () => (/* reexport */ PixelsPerInch), - PromiseCapability: () => (/* reexport */ PromiseCapability), RenderingCancelledException: () => (/* reexport */ RenderingCancelledException), UnexpectedResponseException: () => (/* reexport */ UnexpectedResponseException), Util: () => (/* reexport */ Util), @@ -789,24 +788,6 @@ function getModificationDate(date = new Date()) { const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")]; return buffer.join(""); } -class PromiseCapability { - #settled = false; - constructor() { - this.promise = new Promise((resolve, reject) => { - this.resolve = data => { - this.#settled = true; - resolve(data); - }; - this.reject = reason => { - this.#settled = true; - reject(reason); - }; - }); - } - get settled() { - return this.#settled; - } -} let NormalizeRegex = null; let NormalizationMap = null; function normalizeUnicode(str) { @@ -820,6 +801,17 @@ function getUuid() { return crypto.randomUUID(); } const AnnotationPrefix = "pdfjs_internal_id_"; +const FontRenderOps = { + BEZIER_CURVE_TO: 0, + MOVE_TO: 1, + LINE_TO: 2, + QUADRATIC_CURVE_TO: 3, + RESTORE: 4, + SAVE: 5, + SCALE: 6, + TRANSFORM: 7, + TRANSLATE: 8 +}; ;// CONCATENATED MODULE: ./src/display/base_factory.js @@ -1742,11 +1734,11 @@ class HighlightToolbar { const button = document.createElement("button"); button.className = "highlightButton"; button.tabIndex = 0; - button.setAttribute("data-l10n-id", `pdfjs-highlight-floating-button`); + button.setAttribute("data-l10n-id", `pdfjs-highlight-floating-button1`); const span = document.createElement("span"); button.append(span); span.className = "visuallyHidden"; - span.setAttribute("data-l10n-id", "pdfjs-editor-highlight-button-label"); + span.setAttribute("data-l10n-id", "pdfjs-highlight-floating-button-label"); button.addEventListener("contextmenu", noContextMenu); button.addEventListener("click", () => { this.#uiManager.highlightSelection("floating_button"); @@ -3431,6 +3423,7 @@ class AnnotationEditor { #editToolbar = null; #focusedResizerName = ""; #hasBeenClicked = false; + #initialPosition = null; #isEditing = false; #isInEditMode = false; #isResizerEnabledForKeyboard = false; @@ -3656,12 +3649,14 @@ class AnnotationEditor { this.#translate(this.parentDimensions, x, y); } translateInPage(x, y) { + this.#initialPosition ||= [this.x, this.y]; this.#translate(this.pageDimensions, x, y); this.div.scrollIntoView({ block: "nearest" }); } drag(tx, ty) { + this.#initialPosition ||= [this.x, this.y]; const [parentWidth, parentHeight] = this.parentDimensions; this.x += tx / parentWidth; this.y += ty / parentHeight; @@ -3688,6 +3683,9 @@ class AnnotationEditor { block: "nearest" }); } + get _hasBeenMoved() { + return !!this.#initialPosition && (this.#initialPosition[0] !== this.x || this.#initialPosition[1] !== this.y); + } getBaseTranslation() { const [parentWidth, parentHeight] = this.parentDimensions; const { @@ -4911,7 +4909,6 @@ class FontLoader { } class FontFaceObject { constructor(translatedData, { - isEvalSupported = true, disableFontFace = false, ignoreErrors = false, inspectFont = null @@ -4920,7 +4917,6 @@ class FontFaceObject { for (const i in translatedData) { this[i] = translatedData[i]; } - this.isEvalSupported = isEvalSupported !== false; this.disableFontFace = disableFontFace === true; this.ignoreErrors = ignoreErrors === true; this._inspectFont = inspectFont; @@ -4975,22 +4971,72 @@ class FontFaceObject { throw ex; } warn(`getPathGenerator - ignoring character: "${ex}".`); + } + if (!Array.isArray(cmds) || cmds.length === 0) { return this.compiledGlyphs[character] = function (c, size) {}; } - if (this.isEvalSupported && util_FeatureTest.isEvalSupported) { - const jsBuf = []; - for (const current of cmds) { - const args = current.args !== undefined ? current.args.join(",") : ""; - jsBuf.push("c.", current.cmd, "(", args, ");\n"); + const commands = []; + for (let i = 0, ii = cmds.length; i < ii;) { + switch (cmds[i++]) { + case FontRenderOps.BEZIER_CURVE_TO: + { + const [a, b, c, d, e, f] = cmds.slice(i, i + 6); + commands.push(ctx => ctx.bezierCurveTo(a, b, c, d, e, f)); + i += 6; + } + break; + case FontRenderOps.MOVE_TO: + { + const [a, b] = cmds.slice(i, i + 2); + commands.push(ctx => ctx.moveTo(a, b)); + i += 2; + } + break; + case FontRenderOps.LINE_TO: + { + const [a, b] = cmds.slice(i, i + 2); + commands.push(ctx => ctx.lineTo(a, b)); + i += 2; + } + break; + case FontRenderOps.QUADRATIC_CURVE_TO: + { + const [a, b, c, d] = cmds.slice(i, i + 4); + commands.push(ctx => ctx.quadraticCurveTo(a, b, c, d)); + i += 4; + } + break; + case FontRenderOps.RESTORE: + commands.push(ctx => ctx.restore()); + break; + case FontRenderOps.SAVE: + commands.push(ctx => ctx.save()); + break; + case FontRenderOps.SCALE: + assert(commands.length === 2, "Scale command is only valid at the third position."); + break; + case FontRenderOps.TRANSFORM: + { + const [a, b, c, d, e, f] = cmds.slice(i, i + 6); + commands.push(ctx => ctx.transform(a, b, c, d, e, f)); + i += 6; + } + break; + case FontRenderOps.TRANSLATE: + { + const [a, b] = cmds.slice(i, i + 2); + commands.push(ctx => ctx.translate(a, b)); + i += 2; + } + break; } - return this.compiledGlyphs[character] = new Function("c", "size", jsBuf.join("")); } - return this.compiledGlyphs[character] = function (c, size) { - for (const current of cmds) { - if (current.cmd === "scale") { - current.args = [size, -size]; - } - c[current.cmd].apply(c, current.args); + return this.compiledGlyphs[character] = function glyphDrawer(ctx, size) { + commands[0](ctx); + commands[1](ctx); + ctx.scale(size, -size); + for (let i = 2, ii = commands.length; i < ii; i++) { + commands[i](ctx); } }; } @@ -7951,7 +7997,7 @@ class TextLayerRenderTask { this._reader = null; this._textDivProperties = textDivProperties || new WeakMap(); this._canceled = false; - this._capability = new PromiseCapability(); + this._capability = Promise.withResolvers(); this._layoutTextParams = { prevFontSize: null, prevFontFamily: null, @@ -8019,7 +8065,11 @@ class TextLayerRenderTask { } } _render() { - const capability = new PromiseCapability(); + const { + promise, + resolve, + reject + } = Promise.withResolvers(); let styleCache = Object.create(null); if (this._isReadableStream) { const pump = () => { @@ -8028,13 +8078,13 @@ class TextLayerRenderTask { done }) => { if (done) { - capability.resolve(); + resolve(); return; } Object.assign(styleCache, value.styles); this._processItems(value.items, styleCache); pump(); - }, capability.reject); + }, reject); }; this._reader = this._textContentSource.getReader(); pump(); @@ -8044,11 +8094,11 @@ class TextLayerRenderTask { styles } = this._textContentSource; this._processItems(items, styles); - capability.resolve(); + resolve(); } else { throw new Error('No "textContentSource" parameter specified.'); } - capability.promise.then(() => { + promise.then(() => { styleCache = null; render(this); }, this._capability.reject); @@ -8241,7 +8291,7 @@ class MessageHandler { } sendWithPromise(actionName, data, transfers) { const callbackId = this.callbackId++; - const capability = new PromiseCapability(); + const capability = Promise.withResolvers(); this.callbackCapabilities[callbackId] = capability; try { this.comObj.postMessage({ @@ -8263,7 +8313,7 @@ class MessageHandler { comObj = this.comObj; return new ReadableStream({ start: controller => { - const startCapability = new PromiseCapability(); + const startCapability = Promise.withResolvers(); this.streamControllers[streamId] = { controller, startCall: startCapability, @@ -8282,7 +8332,7 @@ class MessageHandler { return startCapability.promise; }, pull: controller => { - const pullCapability = new PromiseCapability(); + const pullCapability = Promise.withResolvers(); this.streamControllers[streamId].pullCall = pullCapability; comObj.postMessage({ sourceName, @@ -8295,7 +8345,7 @@ class MessageHandler { }, cancel: reason => { assert(reason instanceof Error, "cancel must have a valid reason"); - const cancelCapability = new PromiseCapability(); + const cancelCapability = Promise.withResolvers(); this.streamControllers[streamId].cancelCall = cancelCapability; this.streamControllers[streamId].isClosed = true; comObj.postMessage({ @@ -8324,7 +8374,7 @@ class MessageHandler { const lastDesiredSize = this.desiredSize; this.desiredSize -= size; if (lastDesiredSize > 0 && this.desiredSize <= 0) { - this.sinkCapability = new PromiseCapability(); + this.sinkCapability = Promise.withResolvers(); this.ready = this.sinkCapability.promise; } comObj.postMessage({ @@ -8362,7 +8412,7 @@ class MessageHandler { reason: wrapReason(reason) }); }, - sinkCapability: new PromiseCapability(), + sinkCapability: Promise.withResolvers(), onPull: null, onCancel: null, isCancelled: false, @@ -8975,7 +9025,7 @@ class PDFDataTransportStreamReader { done: true }; } - const requestCapability = new PromiseCapability(); + const requestCapability = Promise.withResolvers(); this._requests.push(requestCapability); return requestCapability.promise; } @@ -9047,7 +9097,7 @@ class PDFDataTransportStreamRangeReader { done: true }; } - const requestCapability = new PromiseCapability(); + const requestCapability = Promise.withResolvers(); this._requests.push(requestCapability); return requestCapability.promise; } @@ -9205,7 +9255,7 @@ function getDocument(src) { } const fetchDocParams = { docId, - apiVersion: "4.1.342", + apiVersion: "4.1.379", data, password, disableAutoFetch, @@ -9228,7 +9278,6 @@ function getDocument(src) { }; const transportParams = { ignoreErrors, - isEvalSupported, disableFontFace, fontExtraProperties, enableXfa, @@ -9294,7 +9343,7 @@ function getDataProp(val) { class PDFDocumentLoadingTask { static #docId = 0; constructor() { - this._capability = new PromiseCapability(); + this._capability = Promise.withResolvers(); this._transport = null; this._worker = null; this.docId = `d${PDFDocumentLoadingTask.#docId++}`; @@ -9335,7 +9384,7 @@ class PDFDataRangeTransport { this._progressListeners = []; this._progressiveReadListeners = []; this._progressiveDoneListeners = []; - this._readyCapability = new PromiseCapability(); + this._readyCapability = Promise.withResolvers(); } addRangeListener(listener) { this._rangeListeners.push(listener); @@ -9588,7 +9637,7 @@ class PDFPageProxy { } const intentPrint = !!(renderingIntent & RenderingIntentFlag.PRINT); if (!intentState.displayReadyCapability) { - intentState.displayReadyCapability = new PromiseCapability(); + intentState.displayReadyCapability = Promise.withResolvers(); intentState.operatorList = { fnArray: [], argsArray: [], @@ -9934,7 +9983,7 @@ class PDFWorker { this.name = name; this.destroyed = false; this.verbosity = verbosity; - this._readyCapability = new PromiseCapability(); + this._readyCapability = Promise.withResolvers(); this._port = null; this._webWorker = null; this._messageHandler = null; @@ -10110,7 +10159,7 @@ class WorkerTransport { this._networkStream = networkStream; this._fullReader = null; this._lastProgress = null; - this.downloadInfoCapability = new PromiseCapability(); + this.downloadInfoCapability = Promise.withResolvers(); this.setupMessageHandler(); } #cacheSimpleMethod(name, data = null) { @@ -10171,7 +10220,7 @@ class WorkerTransport { return this.destroyCapability.promise; } this.destroyed = true; - this.destroyCapability = new PromiseCapability(); + this.destroyCapability = Promise.withResolvers(); this.#passwordCapability?.reject(new Error("Worker was destroyed during onPassword callback")); const waitOn = []; for (const page of this.#pageCache.values()) { @@ -10239,7 +10288,7 @@ class WorkerTransport { }; }); messageHandler.on("ReaderHeadersReady", data => { - const headersCapability = new PromiseCapability(); + const headersCapability = Promise.withResolvers(); const fullReader = this._fullReader; fullReader.headersReady.then(() => { if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) { @@ -10325,7 +10374,7 @@ class WorkerTransport { loadingTask._capability.reject(reason); }); messageHandler.on("PasswordRequest", exception => { - this.#passwordCapability = new PromiseCapability(); + this.#passwordCapability = Promise.withResolvers(); if (loadingTask.onPassword) { const updatePassword = password => { if (password instanceof Error) { @@ -10378,7 +10427,6 @@ class WorkerTransport { } const inspectFont = params.pdfBug && globalThis.FontInspector?.enabled ? (font, url) => globalThis.FontInspector.fontAdded(font, url) : null; const font = new FontFaceObject(exportedData, { - isEvalSupported: params.isEvalSupported, disableFontFace: params.disableFontFace, ignoreErrors: params.ignoreErrors, inspectFont @@ -10639,34 +10687,35 @@ class WorkerTransport { }); } } +const INITIAL_DATA = Symbol("INITIAL_DATA"); class PDFObjects { #objs = Object.create(null); #ensureObj(objId) { return this.#objs[objId] ||= { - capability: new PromiseCapability(), - data: null + ...Promise.withResolvers(), + data: INITIAL_DATA }; } get(objId, callback = null) { if (callback) { const obj = this.#ensureObj(objId); - obj.capability.promise.then(() => callback(obj.data)); + obj.promise.then(() => callback(obj.data)); return null; } const obj = this.#objs[objId]; - if (!obj?.capability.settled) { + if (!obj || obj.data === INITIAL_DATA) { throw new Error(`Requesting object that isn't resolved yet ${objId}.`); } return obj.data; } has(objId) { const obj = this.#objs[objId]; - return obj?.capability.settled ?? false; + return !!obj && obj.data !== INITIAL_DATA; } resolve(objId, data = null) { const obj = this.#ensureObj(objId); obj.data = data; - obj.capability.resolve(); + obj.resolve(); } clear() { for (const objId in this.#objs) { @@ -10680,10 +10729,9 @@ class PDFObjects { *[Symbol.iterator]() { for (const objId in this.#objs) { const { - capability, data } = this.#objs[objId]; - if (!capability.settled) { + if (data === INITIAL_DATA) { continue; } yield [objId, data]; @@ -10748,7 +10796,7 @@ class InternalRenderTask { this.graphicsReady = false; this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined"; this.cancelled = false; - this.capability = new PromiseCapability(); + this.capability = Promise.withResolvers(); this.task = new RenderTask(this); this._cancelBound = this.cancel.bind(this); this._continueBound = this._continue.bind(this); @@ -10849,8 +10897,8 @@ class InternalRenderTask { } } } -const version = "4.1.342"; -const build = "e384df6f1"; +const version = "4.1.379"; +const build = "017e49244"; ;// CONCATENATED MODULE: ./src/shared/scripting_utils.js function makeColorComp(n) { @@ -13708,7 +13756,6 @@ class FreeTextEditor extends AnnotationEditor { } onceAdded() { if (this.width) { - this.#cheatInitialRect(); return; } this.enableEditMode(); @@ -14085,22 +14132,9 @@ class FreeTextEditor extends AnnotationEditor { value, fontSize, color, - rect, pageIndex } = this.#initialData; - return serialized.value !== value || serialized.fontSize !== fontSize || serialized.rect.some((x, i) => Math.abs(x - rect[i]) >= 1) || serialized.color.some((c, i) => c !== color[i]) || serialized.pageIndex !== pageIndex; - } - #cheatInitialRect(delayed = false) { - if (!this.annotationElementId) { - return; - } - this.#setEditorDimensions(); - if (!delayed && (this.width === 0 || this.height === 0)) { - setTimeout(() => this.#cheatInitialRect(true), 0); - return; - } - const padding = FreeTextEditor._internalPadding * this.parentScale; - this.#initialData.rect = this.getRect(padding, padding); + return this._hasBeenMoved || serialized.value !== value || serialized.fontSize !== fontSize || serialized.color.some((c, i) => c !== color[i]) || serialized.pageIndex !== pageIndex; } } @@ -15315,10 +15349,8 @@ class HighlightEditor extends AnnotationEditor { } const div = super.render(); if (this.#text) { - const mark = document.createElement("mark"); - div.append(mark); - mark.append(document.createTextNode(this.#text)); - mark.className = "visuallyHidden"; + div.setAttribute("aria-label", this.#text); + div.setAttribute("role", "mark"); } if (this.#isFreeHighlight) { div.classList.add("free"); @@ -17534,8 +17566,8 @@ class DrawLayer { -const pdfjsVersion = "4.1.342"; -const pdfjsBuild = "e384df6f1"; +const pdfjsVersion = "4.1.379"; +const pdfjsBuild = "017e49244"; var __webpack_exports__AbortException = __webpack_exports__.AbortException; var __webpack_exports__AnnotationEditorLayer = __webpack_exports__.AnnotationEditorLayer; @@ -17561,7 +17593,6 @@ var __webpack_exports__PDFWorker = __webpack_exports__.PDFWorker; var __webpack_exports__PasswordResponses = __webpack_exports__.PasswordResponses; var __webpack_exports__PermissionFlag = __webpack_exports__.PermissionFlag; var __webpack_exports__PixelsPerInch = __webpack_exports__.PixelsPerInch; -var __webpack_exports__PromiseCapability = __webpack_exports__.PromiseCapability; var __webpack_exports__RenderingCancelledException = __webpack_exports__.RenderingCancelledException; var __webpack_exports__UnexpectedResponseException = __webpack_exports__.UnexpectedResponseException; var __webpack_exports__Util = __webpack_exports__.Util; @@ -17583,4 +17614,4 @@ var __webpack_exports__setLayerDimensions = __webpack_exports__.setLayerDimensio var __webpack_exports__shadow = __webpack_exports__.shadow; var __webpack_exports__updateTextLayer = __webpack_exports__.updateTextLayer; var __webpack_exports__version = __webpack_exports__.version; -export { __webpack_exports__AbortException as AbortException, __webpack_exports__AnnotationEditorLayer as AnnotationEditorLayer, __webpack_exports__AnnotationEditorParamsType as AnnotationEditorParamsType, __webpack_exports__AnnotationEditorType as AnnotationEditorType, __webpack_exports__AnnotationEditorUIManager as AnnotationEditorUIManager, __webpack_exports__AnnotationLayer as AnnotationLayer, __webpack_exports__AnnotationMode as AnnotationMode, __webpack_exports__CMapCompressionType as CMapCompressionType, __webpack_exports__ColorPicker as ColorPicker, __webpack_exports__DOMSVGFactory as DOMSVGFactory, __webpack_exports__DrawLayer as DrawLayer, __webpack_exports__FeatureTest as FeatureTest, __webpack_exports__GlobalWorkerOptions as GlobalWorkerOptions, __webpack_exports__ImageKind as ImageKind, __webpack_exports__InvalidPDFException as InvalidPDFException, __webpack_exports__MissingPDFException as MissingPDFException, __webpack_exports__OPS as OPS, __webpack_exports__Outliner as Outliner, __webpack_exports__PDFDataRangeTransport as PDFDataRangeTransport, __webpack_exports__PDFDateString as PDFDateString, __webpack_exports__PDFWorker as PDFWorker, __webpack_exports__PasswordResponses as PasswordResponses, __webpack_exports__PermissionFlag as PermissionFlag, __webpack_exports__PixelsPerInch as PixelsPerInch, __webpack_exports__PromiseCapability as PromiseCapability, __webpack_exports__RenderingCancelledException as RenderingCancelledException, __webpack_exports__UnexpectedResponseException as UnexpectedResponseException, __webpack_exports__Util as Util, __webpack_exports__VerbosityLevel as VerbosityLevel, __webpack_exports__XfaLayer as XfaLayer, __webpack_exports__build as build, __webpack_exports__createValidAbsoluteUrl as createValidAbsoluteUrl, __webpack_exports__fetchData as fetchData, __webpack_exports__getDocument as getDocument, __webpack_exports__getFilenameFromUrl as getFilenameFromUrl, __webpack_exports__getPdfFilenameFromUrl as getPdfFilenameFromUrl, __webpack_exports__getXfaPageViewport as getXfaPageViewport, __webpack_exports__isDataScheme as isDataScheme, __webpack_exports__isPdfFile as isPdfFile, __webpack_exports__noContextMenu as noContextMenu, __webpack_exports__normalizeUnicode as normalizeUnicode, __webpack_exports__renderTextLayer as renderTextLayer, __webpack_exports__setLayerDimensions as setLayerDimensions, __webpack_exports__shadow as shadow, __webpack_exports__updateTextLayer as updateTextLayer, __webpack_exports__version as version }; +export { __webpack_exports__AbortException as AbortException, __webpack_exports__AnnotationEditorLayer as AnnotationEditorLayer, __webpack_exports__AnnotationEditorParamsType as AnnotationEditorParamsType, __webpack_exports__AnnotationEditorType as AnnotationEditorType, __webpack_exports__AnnotationEditorUIManager as AnnotationEditorUIManager, __webpack_exports__AnnotationLayer as AnnotationLayer, __webpack_exports__AnnotationMode as AnnotationMode, __webpack_exports__CMapCompressionType as CMapCompressionType, __webpack_exports__ColorPicker as ColorPicker, __webpack_exports__DOMSVGFactory as DOMSVGFactory, __webpack_exports__DrawLayer as DrawLayer, __webpack_exports__FeatureTest as FeatureTest, __webpack_exports__GlobalWorkerOptions as GlobalWorkerOptions, __webpack_exports__ImageKind as ImageKind, __webpack_exports__InvalidPDFException as InvalidPDFException, __webpack_exports__MissingPDFException as MissingPDFException, __webpack_exports__OPS as OPS, __webpack_exports__Outliner as Outliner, __webpack_exports__PDFDataRangeTransport as PDFDataRangeTransport, __webpack_exports__PDFDateString as PDFDateString, __webpack_exports__PDFWorker as PDFWorker, __webpack_exports__PasswordResponses as PasswordResponses, __webpack_exports__PermissionFlag as PermissionFlag, __webpack_exports__PixelsPerInch as PixelsPerInch, __webpack_exports__RenderingCancelledException as RenderingCancelledException, __webpack_exports__UnexpectedResponseException as UnexpectedResponseException, __webpack_exports__Util as Util, __webpack_exports__VerbosityLevel as VerbosityLevel, __webpack_exports__XfaLayer as XfaLayer, __webpack_exports__build as build, __webpack_exports__createValidAbsoluteUrl as createValidAbsoluteUrl, __webpack_exports__fetchData as fetchData, __webpack_exports__getDocument as getDocument, __webpack_exports__getFilenameFromUrl as getFilenameFromUrl, __webpack_exports__getPdfFilenameFromUrl as getPdfFilenameFromUrl, __webpack_exports__getXfaPageViewport as getXfaPageViewport, __webpack_exports__isDataScheme as isDataScheme, __webpack_exports__isPdfFile as isPdfFile, __webpack_exports__noContextMenu as noContextMenu, __webpack_exports__normalizeUnicode as normalizeUnicode, __webpack_exports__renderTextLayer as renderTextLayer, __webpack_exports__setLayerDimensions as setLayerDimensions, __webpack_exports__shadow as shadow, __webpack_exports__updateTextLayer as updateTextLayer, __webpack_exports__version as version }; diff --git a/toolkit/components/pdfjs/content/build/pdf.scripting.mjs b/toolkit/components/pdfjs/content/build/pdf.scripting.mjs index f590e83af3..8f4c2a7762 100644 --- a/toolkit/components/pdfjs/content/build/pdf.scripting.mjs +++ b/toolkit/components/pdfjs/content/build/pdf.scripting.mjs @@ -3957,8 +3957,8 @@ function initSandbox(params) { ;// CONCATENATED MODULE: ./src/pdf.scripting.js -const pdfjsVersion = "4.1.342"; -const pdfjsBuild = "e384df6f1"; +const pdfjsVersion = "4.1.379"; +const pdfjsBuild = "017e49244"; globalThis.pdfjsScripting = { initSandbox: initSandbox }; diff --git a/toolkit/components/pdfjs/content/build/pdf.worker.mjs b/toolkit/components/pdfjs/content/build/pdf.worker.mjs index e2cd54cf56..76770f6556 100644 --- a/toolkit/components/pdfjs/content/build/pdf.worker.mjs +++ b/toolkit/components/pdfjs/content/build/pdf.worker.mjs @@ -744,24 +744,6 @@ function getModificationDate(date = new Date()) { const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")]; return buffer.join(""); } -class PromiseCapability { - #settled = false; - constructor() { - this.promise = new Promise((resolve, reject) => { - this.resolve = data => { - this.#settled = true; - resolve(data); - }; - this.reject = reason => { - this.#settled = true; - reject(reason); - }; - }); - } - get settled() { - return this.#settled; - } -} let NormalizeRegex = null; let NormalizationMap = null; function normalizeUnicode(str) { @@ -775,6 +757,17 @@ function getUuid() { return crypto.randomUUID(); } const AnnotationPrefix = "pdfjs_internal_id_"; +const FontRenderOps = { + BEZIER_CURVE_TO: 0, + MOVE_TO: 1, + LINE_TO: 2, + QUADRATIC_CURVE_TO: 3, + RESTORE: 4, + SAVE: 5, + SCALE: 6, + TRANSFORM: 7, + TRANSLATE: 8 +}; ;// CONCATENATED MODULE: ./src/core/primitives.js @@ -1789,7 +1782,7 @@ class ChunkedStreamManager { this._promisesByRequest = new Map(); this.progressiveDataLength = 0; this.aborted = false; - this._loadedStreamCapability = new PromiseCapability(); + this._loadedStreamCapability = Promise.withResolvers(); } sendRequest(begin, end) { const rangeReader = this.pdfNetworkStream.getRangeReader(begin, end); @@ -1852,7 +1845,7 @@ class ChunkedStreamManager { if (chunksNeeded.size === 0) { return Promise.resolve(); } - const capability = new PromiseCapability(); + const capability = Promise.withResolvers(); this._promisesByRequest.set(requestId, capability); const chunksToRequest = []; for (const chunk of chunksNeeded) { @@ -5075,6 +5068,18 @@ function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, symbolHeight += rdh; symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext); } + let increment = 0; + if (!transposed) { + if (referenceCorner > 1) { + currentS += symbolWidth - 1; + } else { + increment = symbolWidth - 1; + } + } else if (!(referenceCorner & 1)) { + currentS += symbolHeight - 1; + } else { + increment = symbolHeight - 1; + } const offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1); const offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0); let s2, t2, symbolRow; @@ -5101,7 +5106,6 @@ function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, throw new Jbig2Error(`operator ${combinationOperator} is not supported`); } } - currentS += symbolHeight - 1; } else { for (t2 = 0; t2 < symbolHeight; t2++) { row = bitmap[offsetT + t2]; @@ -5124,14 +5128,13 @@ function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, throw new Jbig2Error(`operator ${combinationOperator} is not supported`); } } - currentS += symbolWidth - 1; } i++; const deltaS = huffman ? huffmanTables.tableDeltaS.decode(huffmanInput) : decodeInteger(contextCache, "IADS", decoder); if (deltaS === null) { break; } - currentS += deltaS + dsOffset; + currentS += increment + deltaS + dsOffset; } while (true); } return bitmap; @@ -18702,22 +18705,13 @@ function lookupCmap(ranges, unicode) { } function compileGlyf(code, cmds, font) { function moveTo(x, y) { - cmds.push({ - cmd: "moveTo", - args: [x, y] - }); + cmds.add(FontRenderOps.MOVE_TO, [x, y]); } function lineTo(x, y) { - cmds.push({ - cmd: "lineTo", - args: [x, y] - }); + cmds.add(FontRenderOps.LINE_TO, [x, y]); } function quadraticCurveTo(xa, ya, x, y) { - cmds.push({ - cmd: "quadraticCurveTo", - args: [xa, ya, x, y] - }); + cmds.add(FontRenderOps.QUADRATIC_CURVE_TO, [xa, ya, x, y]); } let i = 0; const numberOfContours = getInt16(code, i); @@ -18774,17 +18768,11 @@ function compileGlyf(code, cmds, font) { } const subglyph = font.glyphs[glyphIndex]; if (subglyph) { - cmds.push({ - cmd: "save" - }, { - cmd: "transform", - args: [scaleX, scale01, scale10, scaleY, x, y] - }); + cmds.add(FontRenderOps.SAVE); + cmds.add(FontRenderOps.TRANSFORM, [scaleX, scale01, scale10, scaleY, x, y]); if (!(flags & 0x02)) {} compileGlyf(subglyph, cmds, font); - cmds.push({ - cmd: "restore" - }); + cmds.add(FontRenderOps.RESTORE); } } while (flags & 0x20); } else { @@ -18874,22 +18862,13 @@ function compileGlyf(code, cmds, font) { } function compileCharString(charStringCode, cmds, font, glyphId) { function moveTo(x, y) { - cmds.push({ - cmd: "moveTo", - args: [x, y] - }); + cmds.add(FontRenderOps.MOVE_TO, [x, y]); } function lineTo(x, y) { - cmds.push({ - cmd: "lineTo", - args: [x, y] - }); + cmds.add(FontRenderOps.LINE_TO, [x, y]); } function bezierCurveTo(x1, y1, x2, y2, x, y) { - cmds.push({ - cmd: "bezierCurveTo", - args: [x1, y1, x2, y2, x, y] - }); + cmds.add(FontRenderOps.BEZIER_CURVE_TO, [x1, y1, x2, y2, x, y]); } const stack = []; let x = 0, @@ -19059,17 +19038,11 @@ function compileCharString(charStringCode, cmds, font, glyphId) { const bchar = stack.pop(); y = stack.pop(); x = stack.pop(); - cmds.push({ - cmd: "save" - }, { - cmd: "translate", - args: [x, y] - }); + cmds.add(FontRenderOps.SAVE); + cmds.add(FontRenderOps.TRANSLATE, [x, y]); let cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]])); compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId); - cmds.push({ - cmd: "restore" - }); + cmds.add(FontRenderOps.RESTORE); cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]])); compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId); } @@ -19236,6 +19209,22 @@ function compileCharString(charStringCode, cmds, font, glyphId) { parse(charStringCode); } const NOOP = []; +class Commands { + cmds = []; + add(cmd, args) { + if (args) { + if (args.some(arg => typeof arg !== "number")) { + warn(`Commands.add - "${cmd}" has at least one non-number arg: "${args}".`); + const newArgs = args.map(arg => typeof arg === "number" ? arg : 0); + this.cmds.push(cmd, ...newArgs); + } else { + this.cmds.push(cmd, ...args); + } + } else { + this.cmds.push(cmd); + } + } +} class CompiledFont { constructor(fontMatrix) { if (this.constructor === CompiledFont) { @@ -19253,8 +19242,7 @@ class CompiledFont { let fn = this.compiledGlyphs[glyphId]; if (!fn) { try { - fn = this.compileGlyph(this.glyphs[glyphId], glyphId); - this.compiledGlyphs[glyphId] = fn; + fn = this.compiledGlyphs[glyphId] = this.compileGlyph(this.glyphs[glyphId], glyphId); } catch (ex) { this.compiledGlyphs[glyphId] = NOOP; if (this.compiledCharCodeToGlyphId[charCode] === undefined) { @@ -19282,20 +19270,13 @@ class CompiledFont { warn("Invalid fd index for glyph index."); } } - const cmds = [{ - cmd: "save" - }, { - cmd: "transform", - args: fontMatrix.slice() - }, { - cmd: "scale", - args: ["size", "-size"] - }]; + const cmds = new Commands(); + cmds.add(FontRenderOps.SAVE); + cmds.add(FontRenderOps.TRANSFORM, fontMatrix.slice()); + cmds.add(FontRenderOps.SCALE); this.compileGlyphImpl(code, cmds, glyphId); - cmds.push({ - cmd: "restore" - }); - return cmds; + cmds.add(FontRenderOps.RESTORE); + return cmds.cmds; } compileGlyphImpl() { unreachable("Children classes should implement this."); @@ -25941,14 +25922,18 @@ class Font { charCodeToGlyphId[mapping.charCode] = mapping.glyphId; } forcePostTable = true; - } else { + } else if (cmapPlatformId === 3 && cmapEncodingId === 0) { for (const mapping of cmapMappings) { let charCode = mapping.charCode; - if (cmapPlatformId === 3 && charCode >= 0xf000 && charCode <= 0xf0ff) { + if (charCode >= 0xf000 && charCode <= 0xf0ff) { charCode &= 0xff; } charCodeToGlyphId[charCode] = mapping.glyphId; } + } else { + for (const mapping of cmapMappings) { + charCodeToGlyphId[mapping.charCode] = mapping.glyphId; + } } if (properties.glyphNames && (baseEncoding.length || this.differences.length)) { for (let i = 0; i < 256; ++i) { @@ -27080,7 +27065,13 @@ class MeshShading extends BaseShading { } } getIR() { - return ["Mesh", this.shadingType, this.coords, this.colors, this.figures, this.bounds, this.bbox, this.background]; + const { + bounds + } = this; + if (bounds[2] - bounds[0] === 0 || bounds[3] - bounds[1] === 0) { + throw new FormatError(`Invalid MeshShading bounds: [${bounds}].`); + } + return ["Mesh", this.shadingType, this.coords, this.colors, this.figures, bounds, this.bbox, this.background]; } } class DummyShading extends BaseShading { @@ -31794,7 +31785,10 @@ class PartialEvaluator { if (font.cacheKey && this.fontCache.has(font.cacheKey)) { return this.fontCache.get(font.cacheKey); } - const fontCapability = new PromiseCapability(); + const { + promise, + resolve + } = Promise.withResolvers(); let preEvaluatedFont; try { preEvaluatedFont = this.preEvaluateFont(font); @@ -31831,14 +31825,14 @@ class PartialEvaluator { } assert(fontID?.startsWith("f"), 'The "fontID" must be (correctly) defined.'); if (fontRefIsRef) { - this.fontCache.put(fontRef, fontCapability.promise); + this.fontCache.put(fontRef, promise); } else { font.cacheKey = `cacheKey_${fontID}`; - this.fontCache.put(font.cacheKey, fontCapability.promise); + this.fontCache.put(font.cacheKey, promise); } font.loadedName = `${this.idFactory.getDocId()}_${fontID}`; this.translateFont(preEvaluatedFont).then(translatedFont => { - fontCapability.resolve(new TranslatedFont({ + resolve(new TranslatedFont({ loadedName: font.loadedName, font: translatedFont, dict: font, @@ -31846,14 +31840,14 @@ class PartialEvaluator { })); }).catch(reason => { warn(`loadFont - translateFont failed: "${reason}".`); - fontCapability.resolve(new TranslatedFont({ + resolve(new TranslatedFont({ loadedName: font.loadedName, font: new ErrorFont(reason instanceof Error ? reason.message : reason), dict: font, evaluatorOptions: this.options })); }); - return fontCapability.promise; + return promise; } buildPath(operatorList, fn, args, parsingText = false) { const lastIndex = operatorList.length - 1; @@ -31937,19 +31931,33 @@ class PartialEvaluator { localShadingPatternCache }) { let id = localShadingPatternCache.get(shading); - if (!id) { - var shadingFill = Pattern.parseShading(shading, this.xref, resources, this._pdfFunctionFactory, localColorSpaceCache); - const patternIR = shadingFill.getIR(); - id = `pattern_${this.idFactory.createObjId()}`; - if (this.parsingType3Font) { - id = `${this.idFactory.getDocId()}_type3_${id}`; + if (id) { + return id; + } + let patternIR; + try { + const shadingFill = Pattern.parseShading(shading, this.xref, resources, this._pdfFunctionFactory, localColorSpaceCache); + patternIR = shadingFill.getIR(); + } catch (reason) { + if (reason instanceof AbortException) { + return null; } - localShadingPatternCache.set(shading, id); - if (this.parsingType3Font) { - this.handler.send("commonobj", [id, "Pattern", patternIR]); - } else { - this.handler.send("obj", [id, this.pageIndex, "Pattern", patternIR]); + if (this.options.ignoreErrors) { + warn(`parseShading - ignoring shading: "${reason}".`); + localShadingPatternCache.set(shading, null); + return null; } + throw reason; + } + id = `pattern_${this.idFactory.createObjId()}`; + if (this.parsingType3Font) { + id = `${this.idFactory.getDocId()}_type3_${id}`; + } + localShadingPatternCache.set(shading, id); + if (this.parsingType3Font) { + this.handler.send("commonobj", [id, "Pattern", patternIR]); + } else { + this.handler.send("obj", [id, this.pageIndex, "Pattern", patternIR]); } return id; } @@ -31975,14 +31983,16 @@ class PartialEvaluator { return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task, localTilingPatternCache); } else if (typeNum === PatternType.SHADING) { const shading = dict.get("Shading"); - const matrix = dict.getArray("Matrix"); const objId = this.parseShading({ shading, resources, localColorSpaceCache, localShadingPatternCache }); - operatorList.addOp(fn, ["Shading", objId, matrix]); + if (objId) { + const matrix = dict.getArray("Matrix"); + operatorList.addOp(fn, ["Shading", objId, matrix]); + } return undefined; } throw new FormatError(`Unknown PatternType: ${typeNum}`); @@ -32393,6 +32403,9 @@ class PartialEvaluator { localColorSpaceCache, localShadingPatternCache }); + if (!patternId) { + continue; + } args = [patternId]; fn = OPS.shadingFill; break; @@ -33998,6 +34011,10 @@ class PartialEvaluator { systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName); } } + let fontMatrix = dict.getArray("FontMatrix"); + if (!Array.isArray(fontMatrix) || fontMatrix.length !== 6 || fontMatrix.some(x => typeof x !== "number")) { + fontMatrix = FONT_IDENTITY_MATRIX; + } const properties = { type, name: fontName.name, @@ -34010,7 +34027,7 @@ class PartialEvaluator { loadedName: baseDict.loadedName, composite, fixedPitch: false, - fontMatrix: dict.getArray("FontMatrix") || FONT_IDENTITY_MATRIX, + fontMatrix, firstChar, lastChar, toUnicode, @@ -35327,7 +35344,8 @@ function pickPlatformItem(dict) { return null; } class FileSpec { - constructor(root, xref) { + #contentAvailable = false; + constructor(root, xref, skipContent = false) { if (!(root instanceof Dict)) { return; } @@ -35340,10 +35358,12 @@ class FileSpec { if (root.has("RF")) { warn("Related file specifications are not supported"); } - this.contentAvailable = true; - if (!root.has("EF")) { - this.contentAvailable = false; - warn("Non-embedded file specifications are not supported"); + if (!skipContent) { + if (root.has("EF")) { + this.#contentAvailable = true; + } else { + warn("Non-embedded file specifications are not supported"); + } } } get filename() { @@ -35354,7 +35374,7 @@ class FileSpec { return this._filename; } get content() { - if (!this.contentAvailable) { + if (!this.#contentAvailable) { return null; } if (!this.contentRef && this.root) { @@ -38563,7 +38583,7 @@ class Catalog { continue; } if (!outlineDict.has("Title")) { - throw new FormatError("Invalid outline item encountered."); + warn("Invalid outline item encountered."); } const data = { url: null, @@ -38592,7 +38612,7 @@ class Catalog { unsafeUrl: data.unsafeUrl, newWindow: data.newWindow, setOCGState: data.setOCGState, - title: stringToPDFString(title), + title: typeof title === "string" ? stringToPDFString(title) : "", color: rgbColor, count: Number.isInteger(count) ? count : undefined, bold: !!(flags & 2), @@ -39598,7 +39618,11 @@ class Catalog { case "GoToR": const urlDict = action.get("F"); if (urlDict instanceof Dict) { - url = urlDict.get("F") || null; + const fs = new FileSpec(urlDict, null, true); + const { + filename + } = fs.serializable; + url = filename; } else if (typeof urlDict === "string") { url = urlDict; } @@ -51360,7 +51384,7 @@ class AnnotationBorderStyle { } } setDashArray(dashArray, forceStyle = false) { - if (Array.isArray(dashArray) && dashArray.length > 0) { + if (Array.isArray(dashArray)) { let isValid = true; let allZeros = true; for (const element of dashArray) { @@ -51372,7 +51396,7 @@ class AnnotationBorderStyle { allZeros = false; } } - if (isValid && !allZeros) { + if (dashArray.length === 0 || isValid && !allZeros) { this.dashArray = dashArray; if (forceStyle) { this.setStyle(Name.get("D")); @@ -56282,7 +56306,7 @@ class MessageHandler { } sendWithPromise(actionName, data, transfers) { const callbackId = this.callbackId++; - const capability = new PromiseCapability(); + const capability = Promise.withResolvers(); this.callbackCapabilities[callbackId] = capability; try { this.comObj.postMessage({ @@ -56304,7 +56328,7 @@ class MessageHandler { comObj = this.comObj; return new ReadableStream({ start: controller => { - const startCapability = new PromiseCapability(); + const startCapability = Promise.withResolvers(); this.streamControllers[streamId] = { controller, startCall: startCapability, @@ -56323,7 +56347,7 @@ class MessageHandler { return startCapability.promise; }, pull: controller => { - const pullCapability = new PromiseCapability(); + const pullCapability = Promise.withResolvers(); this.streamControllers[streamId].pullCall = pullCapability; comObj.postMessage({ sourceName, @@ -56336,7 +56360,7 @@ class MessageHandler { }, cancel: reason => { assert(reason instanceof Error, "cancel must have a valid reason"); - const cancelCapability = new PromiseCapability(); + const cancelCapability = Promise.withResolvers(); this.streamControllers[streamId].cancelCall = cancelCapability; this.streamControllers[streamId].isClosed = true; comObj.postMessage({ @@ -56365,7 +56389,7 @@ class MessageHandler { const lastDesiredSize = this.desiredSize; this.desiredSize -= size; if (lastDesiredSize > 0 && this.desiredSize <= 0) { - this.sinkCapability = new PromiseCapability(); + this.sinkCapability = Promise.withResolvers(); this.ready = this.sinkCapability.promise; } comObj.postMessage({ @@ -56403,7 +56427,7 @@ class MessageHandler { reason: wrapReason(reason) }); }, - sinkCapability: new PromiseCapability(), + sinkCapability: Promise.withResolvers(), onPull: null, onCancel: null, isCancelled: false, @@ -56681,7 +56705,7 @@ class WorkerTask { constructor(name) { this.name = name; this.terminated = false; - this._capability = new PromiseCapability(); + this._capability = Promise.withResolvers(); } get finished() { return this._capability.promise; @@ -56725,7 +56749,7 @@ class WorkerMessageHandler { docId, apiVersion } = docParams; - const workerVersion = "4.1.342"; + const workerVersion = "4.1.379"; if (apiVersion !== workerVersion) { throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`); } @@ -56785,7 +56809,7 @@ class WorkerMessageHandler { password, rangeChunkSize }; - const pdfManagerCapability = new PromiseCapability(); + const pdfManagerCapability = Promise.withResolvers(); let newPdfManager; if (data) { try { @@ -57287,8 +57311,8 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" && ;// CONCATENATED MODULE: ./src/pdf.worker.js -const pdfjsVersion = "4.1.342"; -const pdfjsBuild = "e384df6f1"; +const pdfjsVersion = "4.1.379"; +const pdfjsBuild = "017e49244"; var __webpack_exports__WorkerMessageHandler = __webpack_exports__.WorkerMessageHandler; export { __webpack_exports__WorkerMessageHandler as WorkerMessageHandler }; |