Refactor how the default viewer handles the worker options, by making use of AppOptions
instead of the global PDFJS
object
This commit is contained in:
parent
57165afb08
commit
b0956a5d91
22
web/app.js
22
web/app.js
@ -51,13 +51,8 @@ const DEFAULT_SCALE_DELTA = 1.1;
|
|||||||
const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
|
const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
|
||||||
|
|
||||||
function configure(PDFJS) {
|
function configure(PDFJS) {
|
||||||
if (typeof PDFJSDev !== 'undefined' &&
|
|
||||||
PDFJSDev.test('FIREFOX || MOZCENTRAL || GENERIC || CHROME')) {
|
|
||||||
GlobalWorkerOptions.workerSrc = '../build/pdf.worker.js';
|
|
||||||
}
|
|
||||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||||
PDFJS.cMapUrl = '../external/bcmaps/';
|
PDFJS.cMapUrl = '../external/bcmaps/';
|
||||||
GlobalWorkerOptions.workerSrc = '../src/worker_loader.js';
|
|
||||||
} else {
|
} else {
|
||||||
PDFJS.cMapUrl = '../web/cmaps/';
|
PDFJS.cMapUrl = '../web/cmaps/';
|
||||||
}
|
}
|
||||||
@ -299,7 +294,7 @@ let PDFViewerApplication = {
|
|||||||
hashParams['useonlycsszoom'] === 'true');
|
hashParams['useonlycsszoom'] === 'true');
|
||||||
}
|
}
|
||||||
if ('verbosity' in hashParams) {
|
if ('verbosity' in hashParams) {
|
||||||
PDFJS.verbosity = hashParams['verbosity'] | 0;
|
AppOptions.set('verbosity', hashParams['verbosity'] | 0);
|
||||||
}
|
}
|
||||||
if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) &&
|
if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) &&
|
||||||
hashParams['disablebcmaps'] === 'true') {
|
hashParams['disablebcmaps'] === 'true') {
|
||||||
@ -711,6 +706,11 @@ let PDFViewerApplication = {
|
|||||||
return this.open(file, args);
|
return this.open(file, args);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Set the necessary global worker parameters, using the available options.
|
||||||
|
const workerParameters = AppOptions.getAll('worker');
|
||||||
|
for (let key in workerParameters) {
|
||||||
|
GlobalWorkerOptions[key] = workerParameters[key];
|
||||||
|
}
|
||||||
|
|
||||||
let parameters = Object.create(null);
|
let parameters = Object.create(null);
|
||||||
if (typeof file === 'string') { // URL
|
if (typeof file === 'string') { // URL
|
||||||
@ -728,8 +728,11 @@ 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.
|
// Set the necessary API parameters, using the available options.
|
||||||
parameters.verbosity = PDFJS.verbosity;
|
const apiParameters = AppOptions.getAll('api');
|
||||||
|
for (let key in apiParameters) {
|
||||||
|
parameters[key] = apiParameters[key];
|
||||||
|
}
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
for (let prop in args) {
|
for (let prop in args) {
|
||||||
@ -1515,6 +1518,9 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
|||||||
|
|
||||||
function loadFakeWorker() {
|
function loadFakeWorker() {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
if (!GlobalWorkerOptions.workerSrc) {
|
||||||
|
GlobalWorkerOptions.workerSrc = AppOptions.get('workerSrc');
|
||||||
|
}
|
||||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||||
if (typeof SystemJS === 'object') {
|
if (typeof SystemJS === 'object') {
|
||||||
SystemJS.import('pdfjs/core/worker').then((worker) => {
|
SystemJS.import('pdfjs/core/worker').then((worker) => {
|
||||||
|
@ -127,6 +127,29 @@ const defaultOptions = {
|
|||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
postMessageTransfers: {
|
||||||
|
/** @type {boolean} */
|
||||||
|
value: true,
|
||||||
|
kind: OptionKind.API,
|
||||||
|
},
|
||||||
|
verbosity: {
|
||||||
|
/** @type {number} */
|
||||||
|
value: 1,
|
||||||
|
kind: OptionKind.API,
|
||||||
|
},
|
||||||
|
|
||||||
|
workerPort: {
|
||||||
|
/** @type {Object} */
|
||||||
|
value: null,
|
||||||
|
kind: OptionKind.WORKER,
|
||||||
|
},
|
||||||
|
workerSrc: {
|
||||||
|
/** @type {string} */
|
||||||
|
value: (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION') ?
|
||||||
|
'../src/worker_loader.js' : '../build/pdf.worker.js'),
|
||||||
|
kind: OptionKind.WORKER,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const userOptions = Object.create(null);
|
const userOptions = Object.create(null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user