diff --git a/src/core/document.js b/src/core/document.js index e733d881c..a3214f3e6 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -222,11 +222,13 @@ class Page { */ _onSubStreamError(handler, reason, objId) { if (this.evaluatorOptions.ignoreErrors) { - // Error(s) when reading one of the /Contents sub-streams -- sending - // unsupported feature notification and allow parsing to continue. - handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorContentSubStream, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + // Error(s) when reading one of the /Contents sub-streams -- sending + // unsupported feature notification and allow parsing to continue. + handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorContentSubStream, + }); + } warn(`getContentStream - ignoring sub-stream (${objId}): "${reason}".`); return; } diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 4c3aad6d1..0054576ff 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -929,11 +929,13 @@ class PartialEvaluator { return; } if (this.options.ignoreErrors) { - // Error(s) in the TilingPattern -- sending unsupported feature - // notification and allow rendering to continue. - this.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorTilingPattern, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + // Error(s) in the TilingPattern -- sending unsupported feature + // notification and allow rendering to continue. + this.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorTilingPattern, + }); + } warn(`handleTilingType - ignoring pattern: "${reason}".`); return; } @@ -975,11 +977,13 @@ class PartialEvaluator { return translated; }) .catch(reason => { - // Error in the font data -- sending unsupported feature - // notification. - this.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorFontLoadType3, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + // Error in the font data -- sending unsupported feature + // notification. + this.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorFontLoadType3, + }); + } return new TranslatedFont({ loadedName: "g_font_error", font: new ErrorFont(`Type3 font load error: ${reason}`), @@ -1029,11 +1033,13 @@ class PartialEvaluator { ); if (this.options.ignoreErrors) { - // Missing setFont operator before text rendering operator -- sending - // unsupported feature notification and allow rendering to continue. - this.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorFontState, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + // Missing setFont operator before text rendering operator -- sending + // unsupported feature notification and allow rendering to continue. + this.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorFontState, + }); + } warn(`ensureStateFont: "${reason}".`); return; } @@ -1191,10 +1197,12 @@ class PartialEvaluator { warn(`${partialMsg}.`); return errorFont(); } - // Font not found -- sending unsupported feature notification. - this.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorFontMissing, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + // Font not found -- sending unsupported feature notification. + this.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorFontMissing, + }); + } warn(`${partialMsg} -- attempting to fallback to a default font.`); // Falling back to a default font to avoid completely broken rendering, @@ -1313,10 +1321,12 @@ class PartialEvaluator { }) .catch(reason => { // TODO fontCapability.reject? - // Error in the font data -- sending unsupported feature notification. - this.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorFontTranslate, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + // Error in the font data -- sending unsupported feature notification. + this.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorFontTranslate, + }); + } warn(`loadFont - translateFont failed: "${reason}".`); fontCapability.resolve( @@ -1422,11 +1432,13 @@ class PartialEvaluator { return null; } if (this.options.ignoreErrors) { - // Error(s) in the ColorSpace -- sending unsupported feature - // notification and allow rendering to continue. - this.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorColorSpace, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + // Error(s) in the ColorSpace -- sending unsupported feature + // notification and allow rendering to continue. + this.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorColorSpace, + }); + } warn(`parseColorSpace - ignoring ColorSpace: "${reason}".`); return null; } @@ -1811,11 +1823,16 @@ class PartialEvaluator { return; } if (self.options.ignoreErrors) { - // Error(s) in the XObject -- sending unsupported feature - // notification and allow rendering to continue. - self.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorXObject, - }); + if ( + typeof PDFJSDev === "undefined" || + PDFJSDev.test("GENERIC") + ) { + // Error(s) in the XObject -- sending unsupported feature + // notification and allow rendering to continue. + self.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorXObject, + }); + } warn(`getOperatorList - ignoring XObject: "${reason}".`); return; } @@ -2130,11 +2147,16 @@ class PartialEvaluator { return; } if (self.options.ignoreErrors) { - // Error(s) in the ExtGState -- sending unsupported feature - // notification and allow parsing/rendering to continue. - self.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorExtGState, - }); + if ( + typeof PDFJSDev === "undefined" || + PDFJSDev.test("GENERIC") + ) { + // Error(s) in the ExtGState -- sending unsupported feature + // notification and allow parsing/rendering to continue. + self.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorExtGState, + }); + } warn(`getOperatorList - ignoring ExtGState: "${reason}".`); return; } @@ -2182,9 +2204,14 @@ class PartialEvaluator { return; } if (self.options.ignoreErrors) { - self.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorMarkedContent, - }); + if ( + typeof PDFJSDev === "undefined" || + PDFJSDev.test("GENERIC") + ) { + self.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorMarkedContent, + }); + } warn( `getOperatorList - ignoring beginMarkedContentProps: "${reason}".` ); @@ -2235,11 +2262,13 @@ class PartialEvaluator { return; } if (this.options.ignoreErrors) { - // Error(s) in the OperatorList -- sending unsupported feature - // notification and allow rendering to continue. - this.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorOperatorList, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + // Error(s) in the OperatorList -- sending unsupported feature + // notification and allow rendering to continue. + this.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorOperatorList, + }); + } warn( `getOperatorList - ignoring errors during "${task.name}" ` + `task: "${reason}".` @@ -3734,11 +3763,13 @@ class PartialEvaluator { return null; } if (this.options.ignoreErrors) { - // Error in the ToUnicode data -- sending unsupported feature - // notification and allow font parsing to continue. - this.handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorFontToUnicode, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + // Error in the ToUnicode data -- sending unsupported feature + // notification and allow font parsing to continue. + this.handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorFontToUnicode, + }); + } warn(`readToUnicode - ignoring ToUnicode data: "${reason}".`); return null; } @@ -4312,11 +4343,13 @@ class PartialEvaluator { ]); } catch (reason) { if (evaluatorOptions.ignoreErrors) { - // Error in the font data -- sending unsupported feature notification - // and allow glyph path building to continue. - handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.errorFontBuildPath, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + // Error in the font data -- sending unsupported feature + // notification and allow glyph path building to continue. + handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.errorFontBuildPath, + }); + } warn(`buildFontPaths - ignoring ${glyphName} glyph: "${reason}".`); return; } diff --git a/src/core/pattern.js b/src/core/pattern.js index 050e4e6a4..87705a305 100644 --- a/src/core/pattern.js +++ b/src/core/pattern.js @@ -82,9 +82,11 @@ class Pattern { if (ex instanceof MissingDataException) { throw ex; } - handler.send("UnsupportedFeature", { - featureId: UNSUPPORTED_FEATURES.shadingPattern, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + handler.send("UnsupportedFeature", { + featureId: UNSUPPORTED_FEATURES.shadingPattern, + }); + } warn(ex); return new DummyShading(); } diff --git a/src/display/api.js b/src/display/api.js index de9ed3f5c..bd01cd122 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -609,10 +609,12 @@ class PDFDocumentLoadingTask { * @type {function} */ set onUnsupportedFeature(callback) { - deprecated( - "The PDFDocumentLoadingTask onUnsupportedFeature property will be removed in the future." - ); - this.#onUnsupportedFeature = callback; + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + deprecated( + "The PDFDocumentLoadingTask onUnsupportedFeature property will be removed in the future." + ); + this.#onUnsupportedFeature = callback; + } } /** @@ -2748,10 +2750,12 @@ class WorkerTransport { }); }); - messageHandler.on( - "UnsupportedFeature", - this._onUnsupportedFeature.bind(this) - ); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + messageHandler.on( + "UnsupportedFeature", + this._onUnsupportedFeature.bind(this) + ); + } messageHandler.on("FetchBuiltInCMap", data => { if (this.destroyed) { @@ -2783,10 +2787,12 @@ class WorkerTransport { } _onUnsupportedFeature({ featureId }) { - if (this.destroyed) { - return; // Ignore any pending requests if the worker was terminated. + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + if (this.destroyed) { + return; // Ignore any pending requests if the worker was terminated. + } + this.loadingTask.onUnsupportedFeature?.(featureId); } - this.loadingTask.onUnsupportedFeature?.(featureId); } getData() { diff --git a/src/display/font_loader.js b/src/display/font_loader.js index 244ce9ca9..49a3c453d 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -30,7 +30,9 @@ class FontLoader { ownerDocument = globalThis.document, styleElement = null, // For testing only. }) { - this._onUnsupportedFeature = onUnsupportedFeature; + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + this._onUnsupportedFeature = onUnsupportedFeature; + } this._document = ownerDocument; this.nativeFontFaces = []; @@ -88,9 +90,11 @@ class FontLoader { try { await nativeFontFace.loaded; } catch (ex) { - this._onUnsupportedFeature({ - featureId: UNSUPPORTED_FEATURES.errorFontLoadNative, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + this._onUnsupportedFeature({ + featureId: UNSUPPORTED_FEATURES.errorFontLoadNative, + }); + } warn(`Failed to load font '${nativeFontFace.family}': '${ex}'.`); // When font loading failed, fall back to the built-in font renderer. @@ -340,7 +344,9 @@ class FontFaceObject { this.isEvalSupported = isEvalSupported !== false; this.disableFontFace = disableFontFace === true; this.ignoreErrors = ignoreErrors === true; - this._onUnsupportedFeature = onUnsupportedFeature; + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + this._onUnsupportedFeature = onUnsupportedFeature; + } this.fontRegistry = fontRegistry; } @@ -403,9 +409,11 @@ class FontFaceObject { if (!this.ignoreErrors) { throw ex; } - this._onUnsupportedFeature({ - featureId: UNSUPPORTED_FEATURES.errorFontGetPath, - }); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + this._onUnsupportedFeature({ + featureId: UNSUPPORTED_FEATURES.errorFontGetPath, + }); + } warn(`getPathGenerator - ignoring character: "${ex}".`); return (this.compiledGlyphs[character] = function (c, size) { diff --git a/src/shared/util.js b/src/shared/util.js index d898582db..c3d49636f 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -346,28 +346,31 @@ const OPS = { constructPath: 91, }; -const UNSUPPORTED_FEATURES = { - forms: "forms", - javaScript: "javaScript", - signatures: "signatures", - smask: "smask", - shadingPattern: "shadingPattern", - errorTilingPattern: "errorTilingPattern", - errorExtGState: "errorExtGState", - errorXObject: "errorXObject", - errorFontLoadType3: "errorFontLoadType3", - errorFontState: "errorFontState", - errorFontMissing: "errorFontMissing", - errorFontTranslate: "errorFontTranslate", - errorColorSpace: "errorColorSpace", - errorOperatorList: "errorOperatorList", - errorFontToUnicode: "errorFontToUnicode", - errorFontLoadNative: "errorFontLoadNative", - errorFontBuildPath: "errorFontBuildPath", - errorFontGetPath: "errorFontGetPath", - errorMarkedContent: "errorMarkedContent", - errorContentSubStream: "errorContentSubStream", -}; +const UNSUPPORTED_FEATURES = + typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC") + ? { + forms: "forms", + javaScript: "javaScript", + signatures: "signatures", + smask: "smask", + shadingPattern: "shadingPattern", + errorTilingPattern: "errorTilingPattern", + errorExtGState: "errorExtGState", + errorXObject: "errorXObject", + errorFontLoadType3: "errorFontLoadType3", + errorFontState: "errorFontState", + errorFontMissing: "errorFontMissing", + errorFontTranslate: "errorFontTranslate", + errorColorSpace: "errorColorSpace", + errorOperatorList: "errorOperatorList", + errorFontToUnicode: "errorFontToUnicode", + errorFontLoadNative: "errorFontLoadNative", + errorFontBuildPath: "errorFontBuildPath", + errorFontGetPath: "errorFontGetPath", + errorMarkedContent: "errorMarkedContent", + errorContentSubStream: "errorContentSubStream", + } + : null; const PasswordResponses = { NEED_PASSWORD: 1,