Move the verbosity
option from the global PDFJS
object and into getDocument
/PDFWorker
instead
Given the purpose of this option, it doesn't seem necessary to make it available through `GlobalWorkerOptions`.
This commit is contained in:
parent
fdd2376170
commit
a97901efb6
@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
||||||
isArrayBuffer, isSameOrigin, MessageHandler, MissingPDFException,
|
isArrayBuffer, isNum, isSameOrigin, MessageHandler, MissingPDFException,
|
||||||
NativeImageDecoding, PageViewport, PasswordException, stringToBytes,
|
NativeImageDecoding, PageViewport, PasswordException, setVerbosityLevel,
|
||||||
UnexpectedResponseException, UnknownErrorException, unreachable, Util, warn
|
stringToBytes, UnexpectedResponseException, UnknownErrorException,
|
||||||
|
unreachable, Util, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting,
|
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting,
|
||||||
@ -128,6 +129,8 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
|||||||
* the loading and parsing of the PDF data.
|
* the loading and parsing of the PDF data.
|
||||||
* @property {boolean} postMessageTransfers - (optional) Enables transfer usage
|
* @property {boolean} postMessageTransfers - (optional) Enables transfer usage
|
||||||
* in postMessage for ArrayBuffers. The default value is `true`.
|
* in postMessage for ArrayBuffers. The default value is `true`.
|
||||||
|
* @property {number} verbosity - (optional) Controls the logging level; the
|
||||||
|
* constants from {VerbosityLevel} should be used.
|
||||||
* @property {string} docBaseUrl - (optional) The base URL of the document,
|
* @property {string} docBaseUrl - (optional) The base URL of the document,
|
||||||
* used when attempting to recover valid absolute URLs for annotations, and
|
* used when attempting to recover valid absolute URLs for annotations, and
|
||||||
* outline items, that (incorrectly) only specify relative URLs.
|
* outline items, that (incorrectly) only specify relative URLs.
|
||||||
@ -240,9 +243,13 @@ function getDocument(src) {
|
|||||||
params.nativeImageDecoderSupport = NativeImageDecoding.DECODE;
|
params.nativeImageDecoderSupport = NativeImageDecoding.DECODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the main-thread verbosity level.
|
||||||
|
setVerbosityLevel(params.verbosity);
|
||||||
|
|
||||||
if (!worker) {
|
if (!worker) {
|
||||||
const workerParams = {
|
const workerParams = {
|
||||||
postMessageTransfers: params.postMessageTransfers,
|
postMessageTransfers: params.postMessageTransfers,
|
||||||
|
verbosity: params.verbosity,
|
||||||
};
|
};
|
||||||
// Worker was not provided -- creating and owning our own. If message port
|
// Worker was not provided -- creating and owning our own. If message port
|
||||||
// is specified in global worker options, using it.
|
// is specified in global worker options, using it.
|
||||||
@ -1206,6 +1213,8 @@ class LoopbackPort {
|
|||||||
* @property {Object} port - (optional) The `workerPort`.
|
* @property {Object} port - (optional) The `workerPort`.
|
||||||
* @property {boolean} postMessageTransfers - (optional) Enables transfer usage
|
* @property {boolean} postMessageTransfers - (optional) Enables transfer usage
|
||||||
* in postMessage for ArrayBuffers. The default value is `true`.
|
* in postMessage for ArrayBuffers. The default value is `true`.
|
||||||
|
* @property {number} verbosity - (optional) Controls the logging level; the
|
||||||
|
* constants from {VerbosityLevel} should be used.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1300,7 +1309,7 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
* @param {PDFWorkerParameters} params - The worker initialization parameters.
|
* @param {PDFWorkerParameters} params - The worker initialization parameters.
|
||||||
*/
|
*/
|
||||||
function PDFWorker({ name = null, port = null,
|
function PDFWorker({ name = null, port = null,
|
||||||
postMessageTransfers = true, } = {}) {
|
postMessageTransfers = true, verbosity = null, } = {}) {
|
||||||
if (port && pdfWorkerPorts.has(port)) {
|
if (port && pdfWorkerPorts.has(port)) {
|
||||||
throw new Error('Cannot use more than one PDFWorker per port');
|
throw new Error('Cannot use more than one PDFWorker per port');
|
||||||
}
|
}
|
||||||
@ -1308,6 +1317,7 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.destroyed = false;
|
this.destroyed = false;
|
||||||
this.postMessageTransfers = postMessageTransfers !== false;
|
this.postMessageTransfers = postMessageTransfers !== false;
|
||||||
|
this.verbosity = (isNum(verbosity) ? verbosity : getVerbosityLevel());
|
||||||
|
|
||||||
this._readyCapability = createPromiseCapability();
|
this._readyCapability = createPromiseCapability();
|
||||||
this._port = null;
|
this._port = null;
|
||||||
@ -1408,7 +1418,7 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
this._readyCapability.resolve();
|
this._readyCapability.resolve();
|
||||||
// Send global setting, e.g. verbosity level.
|
// Send global setting, e.g. verbosity level.
|
||||||
messageHandler.send('configure', {
|
messageHandler.send('configure', {
|
||||||
verbosity: getVerbosityLevel(),
|
verbosity: this.verbosity,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this._setupFakeWorker();
|
this._setupFakeWorker();
|
||||||
|
@ -14,11 +14,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createBlob, createObjectURL, createPromiseCapability, getVerbosityLevel,
|
createBlob, createObjectURL, createPromiseCapability, InvalidPDFException,
|
||||||
InvalidPDFException, isLittleEndian, MissingPDFException, OPS, PageViewport,
|
isLittleEndian, MissingPDFException, OPS, PageViewport, PasswordException,
|
||||||
PasswordException, PasswordResponses, removeNullCharacters, setVerbosityLevel,
|
PasswordResponses, removeNullCharacters, shadow, UnexpectedResponseException,
|
||||||
shadow, UnexpectedResponseException, UnknownErrorException,
|
UnknownErrorException, UNSUPPORTED_FEATURES, Util
|
||||||
UNSUPPORTED_FEATURES, Util, VERBOSITY_LEVELS
|
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { DEFAULT_LINK_REL, getFilenameFromUrl, LinkTarget } from './dom_utils';
|
import { DEFAULT_LINK_REL, getFilenameFromUrl, LinkTarget } from './dom_utils';
|
||||||
import {
|
import {
|
||||||
@ -42,22 +41,6 @@ var PDFJS = globalScope.PDFJS;
|
|||||||
|
|
||||||
PDFJS.pdfBug = false;
|
PDFJS.pdfBug = false;
|
||||||
|
|
||||||
if (PDFJS.verbosity !== undefined) {
|
|
||||||
setVerbosityLevel(PDFJS.verbosity);
|
|
||||||
}
|
|
||||||
delete PDFJS.verbosity;
|
|
||||||
Object.defineProperty(PDFJS, 'verbosity', {
|
|
||||||
get() {
|
|
||||||
return getVerbosityLevel();
|
|
||||||
},
|
|
||||||
set(level) {
|
|
||||||
setVerbosityLevel(level);
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
PDFJS.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
|
|
||||||
PDFJS.OPS = OPS;
|
PDFJS.OPS = OPS;
|
||||||
PDFJS.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
|
PDFJS.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
|
||||||
PDFJS.shadow = shadow;
|
PDFJS.shadow = shadow;
|
||||||
|
@ -23,20 +23,10 @@
|
|||||||
* to the PDF.js.
|
* to the PDF.js.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function PDFJS() {
|
function PDFJS() { // eslint-disable-line no-unused-vars
|
||||||
// Mock class constructor. See src/display/api.js.
|
// Mock class constructor. See src/display/api.js.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls the logging level.
|
|
||||||
* The constants from PDFJS.VERBOSITY_LEVELS should be used:
|
|
||||||
* - errors
|
|
||||||
* - warnings [default]
|
|
||||||
* - infos
|
|
||||||
* @var {number}
|
|
||||||
*/
|
|
||||||
PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.warnings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the eventual result of an asynchronous operation.
|
* Represents the eventual result of an asynchronous operation.
|
||||||
* @external Promise
|
* @external Promise
|
||||||
|
@ -83,6 +83,7 @@ exports.NativeImageDecoding = pdfjsSharedUtil.NativeImageDecoding;
|
|||||||
exports.UnexpectedResponseException =
|
exports.UnexpectedResponseException =
|
||||||
pdfjsSharedUtil.UnexpectedResponseException;
|
pdfjsSharedUtil.UnexpectedResponseException;
|
||||||
exports.OPS = pdfjsSharedUtil.OPS;
|
exports.OPS = pdfjsSharedUtil.OPS;
|
||||||
|
exports.VerbosityLevel = pdfjsSharedUtil.VerbosityLevel;
|
||||||
exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
|
exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
|
||||||
exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
|
exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
|
||||||
exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
|
exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
|
||||||
|
@ -142,10 +142,10 @@ var FontType = {
|
|||||||
MMTYPE1: 10,
|
MMTYPE1: 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
var VERBOSITY_LEVELS = {
|
const VerbosityLevel = {
|
||||||
errors: 0,
|
ERRORS: 0,
|
||||||
warnings: 1,
|
WARNINGS: 1,
|
||||||
infos: 5,
|
INFOS: 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
var CMapCompressionType = {
|
var CMapCompressionType = {
|
||||||
@ -251,10 +251,12 @@ var OPS = {
|
|||||||
constructPath: 91,
|
constructPath: 91,
|
||||||
};
|
};
|
||||||
|
|
||||||
var verbosity = VERBOSITY_LEVELS.warnings;
|
let verbosity = VerbosityLevel.WARNINGS;
|
||||||
|
|
||||||
function setVerbosityLevel(level) {
|
function setVerbosityLevel(level) {
|
||||||
verbosity = level;
|
if (Number.isInteger(level)) {
|
||||||
|
verbosity = level;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVerbosityLevel() {
|
function getVerbosityLevel() {
|
||||||
@ -265,19 +267,19 @@ function getVerbosityLevel() {
|
|||||||
// as warning that Workers were disabled, which is important to devs but not
|
// as warning that Workers were disabled, which is important to devs but not
|
||||||
// end users.
|
// end users.
|
||||||
function info(msg) {
|
function info(msg) {
|
||||||
if (verbosity >= VERBOSITY_LEVELS.infos) {
|
if (verbosity >= VerbosityLevel.INFOS) {
|
||||||
console.log('Info: ' + msg);
|
console.log('Info: ' + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Non-fatal warnings.
|
// Non-fatal warnings.
|
||||||
function warn(msg) {
|
function warn(msg) {
|
||||||
if (verbosity >= VERBOSITY_LEVELS.warnings) {
|
if (verbosity >= VerbosityLevel.WARNINGS) {
|
||||||
console.log('Warning: ' + msg);
|
console.log('Warning: ' + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated API function -- display regardless of the PDFJS.verbosity setting.
|
// Deprecated API function -- display regardless of the `verbosity` setting.
|
||||||
function deprecated(details) {
|
function deprecated(details) {
|
||||||
console.log('Deprecated API usage: ' + details);
|
console.log('Deprecated API usage: ' + details);
|
||||||
}
|
}
|
||||||
@ -1573,7 +1575,7 @@ export {
|
|||||||
FONT_IDENTITY_MATRIX,
|
FONT_IDENTITY_MATRIX,
|
||||||
IDENTITY_MATRIX,
|
IDENTITY_MATRIX,
|
||||||
OPS,
|
OPS,
|
||||||
VERBOSITY_LEVELS,
|
VerbosityLevel,
|
||||||
UNSUPPORTED_FEATURES,
|
UNSUPPORTED_FEATURES,
|
||||||
AnnotationBorderStyleType,
|
AnnotationBorderStyleType,
|
||||||
AnnotationFieldFlag,
|
AnnotationFieldFlag,
|
||||||
|
@ -740,6 +740,8 @@ let PDFViewerApplication = {
|
|||||||
PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) {
|
PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) {
|
||||||
parameters.docBaseUrl = this.baseUrl;
|
parameters.docBaseUrl = this.baseUrl;
|
||||||
}
|
}
|
||||||
|
// TODO: Remove this once all options are moved from the `PDFJS` object.
|
||||||
|
parameters.verbosity = PDFJS.verbosity;
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
for (let prop in args) {
|
for (let prop in args) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user