Merge pull request #969 from arturadib/fix-worker-loader
Fix worker_loader.js for examples/. Simpler code
This commit is contained in:
commit
93bb2cf0d3
@ -629,8 +629,7 @@ var PDFDoc = (function PDFDocClosure() {
|
|||||||
var worker = new Worker(workerSrc);
|
var worker = new Worker(workerSrc);
|
||||||
|
|
||||||
var messageHandler = new MessageHandler('main', worker);
|
var messageHandler = new MessageHandler('main', worker);
|
||||||
// Tell the worker the file it was created from.
|
|
||||||
messageHandler.send('workerSrc', workerSrc);
|
|
||||||
messageHandler.on('test', function pdfDocTest(supportTypedArray) {
|
messageHandler.on('test', function pdfDocTest(supportTypedArray) {
|
||||||
if (supportTypedArray) {
|
if (supportTypedArray) {
|
||||||
this.worker = worker;
|
this.worker = worker;
|
||||||
|
@ -85,13 +85,6 @@ var WorkerMessageHandler = {
|
|||||||
handler.send('test', data instanceof Uint8Array);
|
handler.send('test', data instanceof Uint8Array);
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on('workerSrc', function wphSetupWorkerSrc(data) {
|
|
||||||
// In development, the `workerSrc` message is handled in the
|
|
||||||
// `worker_loader.js` file. In production the workerProcessHandler is
|
|
||||||
// called for this. This servers as a dummy to prevent calling an
|
|
||||||
// undefined action `workerSrc`.
|
|
||||||
});
|
|
||||||
|
|
||||||
handler.on('doc', function wphSetupDoc(data) {
|
handler.on('doc', function wphSetupDoc(data) {
|
||||||
// Create only the model of the PDFDoc, which is enough for
|
// Create only the model of the PDFDoc, which is enough for
|
||||||
// processing the content of the pdf.
|
// processing the content of the pdf.
|
||||||
|
@ -3,51 +3,30 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function onMessageLoader(evt) {
|
// List of files to include;
|
||||||
// Reset the `onmessage` function as it was only set to call
|
var files = [
|
||||||
// this function the first time a message is passed to the worker
|
'core.js',
|
||||||
// but shouldn't get called anytime afterwards.
|
'util.js',
|
||||||
this.onmessage = null;
|
'canvas.js',
|
||||||
|
'obj.js',
|
||||||
|
'function.js',
|
||||||
|
'charsets.js',
|
||||||
|
'cidmaps.js',
|
||||||
|
'colorspace.js',
|
||||||
|
'crypto.js',
|
||||||
|
'evaluator.js',
|
||||||
|
'fonts.js',
|
||||||
|
'glyphlist.js',
|
||||||
|
'image.js',
|
||||||
|
'metrics.js',
|
||||||
|
'parser.js',
|
||||||
|
'pattern.js',
|
||||||
|
'stream.js',
|
||||||
|
'worker.js',
|
||||||
|
'../external/jpgjs/jpg.js'
|
||||||
|
];
|
||||||
|
|
||||||
if (evt.data.action !== 'workerSrc') {
|
// Load all the files.
|
||||||
throw 'Worker expects first message to be `workerSrc`';
|
for (var i = 0; i < files.length; i++) {
|
||||||
}
|
importScripts(files[i]);
|
||||||
|
|
||||||
// Content of `PDFJS.workerSrc` as defined on the main thread.
|
|
||||||
var workerSrc = evt.data.data;
|
|
||||||
|
|
||||||
// Extract the directory that contains the source files to load.
|
|
||||||
// Assuming the source files have the same relative possition as the
|
|
||||||
// `workerSrc` file.
|
|
||||||
var dir = workerSrc.substring(0, workerSrc.lastIndexOf('/') + 1);
|
|
||||||
|
|
||||||
// List of files to include;
|
|
||||||
var files = [
|
|
||||||
'core.js',
|
|
||||||
'util.js',
|
|
||||||
'canvas.js',
|
|
||||||
'obj.js',
|
|
||||||
'function.js',
|
|
||||||
'charsets.js',
|
|
||||||
'cidmaps.js',
|
|
||||||
'colorspace.js',
|
|
||||||
'crypto.js',
|
|
||||||
'evaluator.js',
|
|
||||||
'fonts.js',
|
|
||||||
'glyphlist.js',
|
|
||||||
'image.js',
|
|
||||||
'metrics.js',
|
|
||||||
'parser.js',
|
|
||||||
'pattern.js',
|
|
||||||
'stream.js',
|
|
||||||
'worker.js',
|
|
||||||
'../external/jpgjs/jpg.js'
|
|
||||||
];
|
|
||||||
|
|
||||||
// Load all the files.
|
|
||||||
for (var i = 0; i < files.length; i++) {
|
|
||||||
importScripts(dir + files[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onmessage = onMessageLoader;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user