Merge pull request #16122 from Snuffleupagus/rm-onUnsupportedFeature

[api-minor] Remove the deprecated `onUnsupportedFeature` functionality (PR 15758 follow-up)
This commit is contained in:
Jonas Jenwald 2023-03-08 12:16:27 +01:00 committed by GitHub
commit e5427ab11b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 5 additions and 201 deletions

View File

@ -27,7 +27,6 @@ import {
stringToPDFString, stringToPDFString,
stringToUTF8String, stringToUTF8String,
unreachable, unreachable,
UNSUPPORTED_FEATURES,
Util, Util,
warn, warn,
} from "../shared/util.js"; } from "../shared/util.js";
@ -220,15 +219,8 @@ class Page {
/** /**
* @private * @private
*/ */
_onSubStreamError(handler, reason, objId) { _onSubStreamError(reason, objId) {
if (this.evaluatorOptions.ignoreErrors) { if (this.evaluatorOptions.ignoreErrors) {
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}".`); warn(`getContentStream - ignoring sub-stream (${objId}): "${reason}".`);
return; return;
} }
@ -238,7 +230,7 @@ class Page {
/** /**
* @returns {Promise<BaseStream>} * @returns {Promise<BaseStream>}
*/ */
getContentStream(handler) { getContentStream() {
return this.pdfManager.ensure(this, "content").then(content => { return this.pdfManager.ensure(this, "content").then(content => {
if (content instanceof BaseStream) { if (content instanceof BaseStream) {
return content; return content;
@ -246,7 +238,7 @@ class Page {
if (Array.isArray(content)) { if (Array.isArray(content)) {
return new StreamsSequenceStream( return new StreamsSequenceStream(
content, content,
this._onSubStreamError.bind(this, handler) this._onSubStreamError.bind(this)
); );
} }
// Replace non-existent page content with empty content. // Replace non-existent page content with empty content.
@ -378,7 +370,7 @@ class Page {
cacheKey, cacheKey,
annotationStorage = null, annotationStorage = null,
}) { }) {
const contentStreamPromise = this.getContentStream(handler); const contentStreamPromise = this.getContentStream();
const resourcesPromise = this.loadResources([ const resourcesPromise = this.loadResources([
"ColorSpace", "ColorSpace",
"ExtGState", "ExtGState",
@ -528,7 +520,7 @@ class Page {
sink, sink,
combineTextItems, combineTextItems,
}) { }) {
const contentStreamPromise = this.getContentStream(handler); const contentStreamPromise = this.getContentStream();
const resourcesPromise = this.loadResources([ const resourcesPromise = this.loadResources([
"ExtGState", "ExtGState",
"Font", "Font",

View File

@ -28,7 +28,6 @@ import {
shadow, shadow,
stringToPDFString, stringToPDFString,
TextRenderingMode, TextRenderingMode,
UNSUPPORTED_FEATURES,
Util, Util,
warn, warn,
} from "../shared/util.js"; } from "../shared/util.js";
@ -948,13 +947,6 @@ class PartialEvaluator {
return; return;
} }
if (this.options.ignoreErrors) { if (this.options.ignoreErrors) {
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}".`); warn(`handleTilingType - ignoring pattern: "${reason}".`);
return; return;
} }
@ -996,13 +988,6 @@ class PartialEvaluator {
return translated; return translated;
}) })
.catch(reason => { .catch(reason => {
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({ return new TranslatedFont({
loadedName: "g_font_error", loadedName: "g_font_error",
font: new ErrorFont(`Type3 font load error: ${reason}`), font: new ErrorFont(`Type3 font load error: ${reason}`),
@ -1052,13 +1037,6 @@ class PartialEvaluator {
); );
if (this.options.ignoreErrors) { if (this.options.ignoreErrors) {
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}".`); warn(`ensureStateFont: "${reason}".`);
return; return;
} }
@ -1216,12 +1194,6 @@ class PartialEvaluator {
warn(`${partialMsg}.`); warn(`${partialMsg}.`);
return errorFont(); return errorFont();
} }
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.`); warn(`${partialMsg} -- attempting to fallback to a default font.`);
// Falling back to a default font to avoid completely broken rendering, // Falling back to a default font to avoid completely broken rendering,
@ -1340,12 +1312,6 @@ class PartialEvaluator {
}) })
.catch(reason => { .catch(reason => {
// TODO fontCapability.reject? // TODO fontCapability.reject?
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}".`); warn(`loadFont - translateFont failed: "${reason}".`);
fontCapability.resolve( fontCapability.resolve(
@ -1451,13 +1417,6 @@ class PartialEvaluator {
return null; return null;
} }
if (this.options.ignoreErrors) { if (this.options.ignoreErrors) {
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}".`); warn(`parseColorSpace - ignoring ColorSpace: "${reason}".`);
return null; return null;
} }
@ -1479,7 +1438,6 @@ class PartialEvaluator {
shading, shading,
this.xref, this.xref,
resources, resources,
this.handler,
this._pdfFunctionFactory, this._pdfFunctionFactory,
localColorSpaceCache localColorSpaceCache
); );
@ -1842,16 +1800,6 @@ class PartialEvaluator {
return; return;
} }
if (self.options.ignoreErrors) { if (self.options.ignoreErrors) {
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}".`); warn(`getOperatorList - ignoring XObject: "${reason}".`);
return; return;
} }
@ -2166,16 +2114,6 @@ class PartialEvaluator {
return; return;
} }
if (self.options.ignoreErrors) { if (self.options.ignoreErrors) {
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}".`); warn(`getOperatorList - ignoring ExtGState: "${reason}".`);
return; return;
} }
@ -2223,14 +2161,6 @@ class PartialEvaluator {
return; return;
} }
if (self.options.ignoreErrors) { if (self.options.ignoreErrors) {
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("GENERIC")
) {
self.handler.send("UnsupportedFeature", {
featureId: UNSUPPORTED_FEATURES.errorMarkedContent,
});
}
warn( warn(
`getOperatorList - ignoring beginMarkedContentProps: "${reason}".` `getOperatorList - ignoring beginMarkedContentProps: "${reason}".`
); );
@ -2281,13 +2211,6 @@ class PartialEvaluator {
return; return;
} }
if (this.options.ignoreErrors) { if (this.options.ignoreErrors) {
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( warn(
`getOperatorList - ignoring errors during "${task.name}" ` + `getOperatorList - ignoring errors during "${task.name}" ` +
`task: "${reason}".` `task: "${reason}".`
@ -3778,13 +3701,6 @@ class PartialEvaluator {
return null; return null;
} }
if (this.options.ignoreErrors) { if (this.options.ignoreErrors) {
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}".`); warn(`readToUnicode - ignoring ToUnicode data: "${reason}".`);
return null; return null;
} }
@ -4358,13 +4274,6 @@ class PartialEvaluator {
]); ]);
} catch (reason) { } catch (reason) {
if (evaluatorOptions.ignoreErrors) { if (evaluatorOptions.ignoreErrors) {
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}".`); warn(`buildFontPaths - ignoring ${glyphName} glyph: "${reason}".`);
return; return;
} }

View File

@ -19,7 +19,6 @@ import {
info, info,
shadow, shadow,
unreachable, unreachable,
UNSUPPORTED_FEATURES,
Util, Util,
warn, warn,
} from "../shared/util.js"; } from "../shared/util.js";
@ -46,7 +45,6 @@ class Pattern {
shading, shading,
xref, xref,
res, res,
handler,
pdfFunctionFactory, pdfFunctionFactory,
localColorSpaceCache localColorSpaceCache
) { ) {
@ -82,11 +80,6 @@ class Pattern {
if (ex instanceof MissingDataException) { if (ex instanceof MissingDataException) {
throw ex; throw ex;
} }
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
handler.send("UnsupportedFeature", {
featureId: UNSUPPORTED_FEATURES.shadingPattern,
});
}
warn(ex); warn(ex);
return new DummyShading(); return new DummyShading();
} }

View File

@ -582,8 +582,6 @@ function getDataProp(val) {
class PDFDocumentLoadingTask { class PDFDocumentLoadingTask {
static #docId = 0; static #docId = 0;
#onUnsupportedFeature = null;
constructor() { constructor() {
this._capability = createPromiseCapability(); this._capability = createPromiseCapability();
this._transport = null; this._transport = null;
@ -618,28 +616,6 @@ class PDFDocumentLoadingTask {
this.onProgress = null; this.onProgress = null;
} }
/**
* @type {function | null} The current callback used with unsupported
* features.
*/
get onUnsupportedFeature() {
return this.#onUnsupportedFeature;
}
/**
* Callback for when an unsupported feature is used in the PDF document.
* The callback receives an {@link UNSUPPORTED_FEATURES} argument.
* @type {function}
*/
set onUnsupportedFeature(callback) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
deprecated(
"The PDFDocumentLoadingTask onUnsupportedFeature property will be removed in the future."
);
this.#onUnsupportedFeature = callback;
}
}
/** /**
* Promise for document loading task completion. * Promise for document loading task completion.
* @type {Promise<PDFDocumentProxy>} * @type {Promise<PDFDocumentProxy>}
@ -2361,7 +2337,6 @@ class WorkerTransport {
this.loadingTask = loadingTask; this.loadingTask = loadingTask;
this.commonObjs = new PDFObjects(); this.commonObjs = new PDFObjects();
this.fontLoader = new FontLoader({ this.fontLoader = new FontLoader({
onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
ownerDocument: params.ownerDocument, ownerDocument: params.ownerDocument,
styleElement: params.styleElement, styleElement: params.styleElement,
}); });
@ -2761,7 +2736,6 @@ class WorkerTransport {
isEvalSupported: params.isEvalSupported, isEvalSupported: params.isEvalSupported,
disableFontFace: params.disableFontFace, disableFontFace: params.disableFontFace,
ignoreErrors: params.ignoreErrors, ignoreErrors: params.ignoreErrors,
onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
fontRegistry, fontRegistry,
}); });
@ -2840,13 +2814,6 @@ class WorkerTransport {
}); });
}); });
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
messageHandler.on(
"UnsupportedFeature",
this._onUnsupportedFeature.bind(this)
);
}
messageHandler.on("FetchBuiltInCMap", data => { messageHandler.on("FetchBuiltInCMap", data => {
if (this.destroyed) { if (this.destroyed) {
return Promise.reject(new Error("Worker was destroyed.")); return Promise.reject(new Error("Worker was destroyed."));
@ -2876,15 +2843,6 @@ class WorkerTransport {
}); });
} }
_onUnsupportedFeature({ featureId }) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
}
this.loadingTask.onUnsupportedFeature?.(featureId);
}
}
getData() { getData() {
return this.messageHandler.sendWithPromise("GetData", null); return this.messageHandler.sendWithPromise("GetData", null);
} }

View File

@ -19,20 +19,15 @@ import {
FeatureTest, FeatureTest,
shadow, shadow,
string32, string32,
UNSUPPORTED_FEATURES,
warn, warn,
} from "../shared/util.js"; } from "../shared/util.js";
import { isNodeJS } from "../shared/is_node.js"; import { isNodeJS } from "../shared/is_node.js";
class FontLoader { class FontLoader {
constructor({ constructor({
onUnsupportedFeature,
ownerDocument = globalThis.document, ownerDocument = globalThis.document,
styleElement = null, // For testing only. styleElement = null, // For testing only.
}) { }) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this._onUnsupportedFeature = onUnsupportedFeature;
}
this._document = ownerDocument; this._document = ownerDocument;
this.nativeFontFaces = []; this.nativeFontFaces = [];
@ -90,11 +85,6 @@ class FontLoader {
try { try {
await nativeFontFace.loaded; await nativeFontFace.loaded;
} catch (ex) { } catch (ex) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this._onUnsupportedFeature({
featureId: UNSUPPORTED_FEATURES.errorFontLoadNative,
});
}
warn(`Failed to load font '${nativeFontFace.family}': '${ex}'.`); warn(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
// When font loading failed, fall back to the built-in font renderer. // When font loading failed, fall back to the built-in font renderer.
@ -332,7 +322,6 @@ class FontFaceObject {
isEvalSupported = true, isEvalSupported = true,
disableFontFace = false, disableFontFace = false,
ignoreErrors = false, ignoreErrors = false,
onUnsupportedFeature,
fontRegistry = null, fontRegistry = null,
} }
) { ) {
@ -344,9 +333,6 @@ class FontFaceObject {
this.isEvalSupported = isEvalSupported !== false; this.isEvalSupported = isEvalSupported !== false;
this.disableFontFace = disableFontFace === true; this.disableFontFace = disableFontFace === true;
this.ignoreErrors = ignoreErrors === true; this.ignoreErrors = ignoreErrors === true;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this._onUnsupportedFeature = onUnsupportedFeature;
}
this.fontRegistry = fontRegistry; this.fontRegistry = fontRegistry;
} }
@ -409,11 +395,6 @@ class FontFaceObject {
if (!this.ignoreErrors) { if (!this.ignoreErrors) {
throw ex; throw ex;
} }
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this._onUnsupportedFeature({
featureId: UNSUPPORTED_FEATURES.errorFontGetPath,
});
}
warn(`getPathGenerator - ignoring character: "${ex}".`); warn(`getPathGenerator - ignoring character: "${ex}".`);
return (this.compiledGlyphs[character] = function (c, size) { return (this.compiledGlyphs[character] = function (c, size) {

View File

@ -40,7 +40,6 @@ import {
PermissionFlag, PermissionFlag,
shadow, shadow,
UnexpectedResponseException, UnexpectedResponseException,
UNSUPPORTED_FEATURES,
Util, Util,
VerbosityLevel, VerbosityLevel,
} from "./shared/util.js"; } from "./shared/util.js";
@ -116,7 +115,6 @@ export {
shadow, shadow,
SVGGraphics, SVGGraphics,
UnexpectedResponseException, UnexpectedResponseException,
UNSUPPORTED_FEATURES,
updateTextLayer, updateTextLayer,
Util, Util,
VerbosityLevel, VerbosityLevel,

View File

@ -346,32 +346,6 @@ const OPS = {
constructPath: 91, constructPath: 91,
}; };
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 = { const PasswordResponses = {
NEED_PASSWORD: 1, NEED_PASSWORD: 1,
INCORRECT_PASSWORD: 2, INCORRECT_PASSWORD: 2,
@ -1105,7 +1079,6 @@ export {
UnexpectedResponseException, UnexpectedResponseException,
UnknownErrorException, UnknownErrorException,
unreachable, unreachable,
UNSUPPORTED_FEATURES,
utf8StringToString, utf8StringToString,
Util, Util,
VerbosityLevel, VerbosityLevel,