Zero gjslint warnings mark
This commit is contained in:
parent
537eb8f47b
commit
7036bcd4c7
4
pdf.js
4
pdf.js
@ -3226,8 +3226,8 @@ var XRef = (function() {
|
||||
if (this.encrypt && !suppressEncryption) {
|
||||
try {
|
||||
e = parser.getObj(this.encrypt.createCipherTransform(num, gen));
|
||||
} catch(ex) {
|
||||
// almost all streams must to encrypted, but sometimes
|
||||
} catch (ex) {
|
||||
// almost all streams must be encrypted, but sometimes
|
||||
// they are not probably due to some broken generators
|
||||
// re-trying without encryption
|
||||
return this.fetch(ref, true);
|
||||
|
@ -49,7 +49,7 @@ function load() {
|
||||
};
|
||||
r.send(null);
|
||||
}
|
||||
window.onload = load;
|
||||
documet.addEventListener('DOMContentLoaded', load);
|
||||
|
||||
function nextTask() {
|
||||
if (currentTaskIdx == manifest.length) {
|
||||
|
101
worker/client.js
101
worker/client.js
@ -3,23 +3,26 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
if (typeof console.time == 'undefined') {
|
||||
var consoleUtils = (function() {
|
||||
var consoleTimer = {};
|
||||
console.time = function(name) {
|
||||
|
||||
var obj = {};
|
||||
obj.time = function(name) {
|
||||
consoleTimer[name] = Date.now();
|
||||
};
|
||||
|
||||
console.timeEnd = function(name) {
|
||||
obj.timeEnd = function(name) {
|
||||
var time = consoleTimer[name];
|
||||
if (time == null) {
|
||||
throw 'Unkown timer name ' + name;
|
||||
}
|
||||
this.log('Timer:', name, Date.now() - time);
|
||||
console.log('Timer:', name, Date.now() - time);
|
||||
};
|
||||
}
|
||||
|
||||
return obj;
|
||||
})();
|
||||
|
||||
function FontWorker() {
|
||||
this.worker = new Worker('worker/font.js');
|
||||
this.worker = new Worker('../worker/font.js');
|
||||
this.fontsWaiting = 0;
|
||||
this.fontsWaitingCallbacks = [];
|
||||
|
||||
@ -96,7 +99,7 @@ FontWorker.prototype = {
|
||||
this.fontsWaiting++;
|
||||
}
|
||||
|
||||
console.time('ensureFonts');
|
||||
consoleUtils.time('ensureFonts');
|
||||
// If there are fonts, that need to get loaded, tell the FontWorker to get
|
||||
// started and push the callback on the waiting-callback-stack.
|
||||
if (notLoaded.length != 0) {
|
||||
@ -124,7 +127,7 @@ function WorkerPDFDoc(canvas) {
|
||||
|
||||
this.ctx = canvas.getContext('2d');
|
||||
this.canvas = canvas;
|
||||
this.worker = new Worker('worker/pdf.js');
|
||||
this.worker = new Worker('../worker/pdf.js');
|
||||
this.fontWorker = new FontWorker();
|
||||
this.waitingForFonts = false;
|
||||
this.waitingForFontsCallback = [];
|
||||
@ -167,7 +170,8 @@ function WorkerPDFDoc(canvas) {
|
||||
},
|
||||
|
||||
'$putImageData': function(imageData, x, y) {
|
||||
var imgData = this.getImageData(0, 0, imageData.width, imageData.height);
|
||||
var imgData = this.getImageData(0, 0,
|
||||
imageData.width, imageData.height);
|
||||
|
||||
// Store the .data property to avaid property lookups.
|
||||
var imageRealData = imageData.data;
|
||||
@ -339,7 +343,7 @@ function WorkerPDFDoc(canvas) {
|
||||
|
||||
var renderData = function() {
|
||||
if (id == 0) {
|
||||
console.time('main canvas rendering');
|
||||
consoleUtils.time('main canvas rendering');
|
||||
var ctx = this.ctx;
|
||||
ctx.save();
|
||||
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||
@ -348,8 +352,8 @@ function WorkerPDFDoc(canvas) {
|
||||
}
|
||||
renderProxyCanvas(canvasList[id], cmdQueue);
|
||||
if (id == 0) {
|
||||
console.timeEnd('main canvas rendering');
|
||||
console.timeEnd('>>> total page display time:');
|
||||
consoleUtils.timeEnd('main canvas rendering');
|
||||
consoleUtils.timeEnd('>>> total page display time:');
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
@ -368,51 +372,52 @@ function WorkerPDFDoc(canvas) {
|
||||
};
|
||||
|
||||
// Listen to the WebWorker for data and call actionHandler on it.
|
||||
this.worker.onmessage = function(event) {
|
||||
this.worker.addEventListener('message', function(event) {
|
||||
var data = event.data;
|
||||
if (data.action in actionHandler) {
|
||||
actionHandler[data.action].call(this, data.data);
|
||||
} else {
|
||||
throw 'Unkown action from worker: ' + data.action;
|
||||
}
|
||||
}.bind(this);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
WorkerPDFDoc.prototype.open = function(url, callback) {
|
||||
var req = new XMLHttpRequest();
|
||||
req.open('GET', url);
|
||||
req.mozResponseType = req.responseType = 'arraybuffer';
|
||||
req.expected = (document.URL.indexOf('file:') == 0) ? 0 : 200;
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4 && req.status == req.expected) {
|
||||
var data = req.mozResponseArrayBuffer || req.mozResponse ||
|
||||
req.responseArrayBuffer || req.response;
|
||||
WorkerPDFDoc.prototype = {
|
||||
open: function(url, callback) {
|
||||
var req = new XMLHttpRequest();
|
||||
req.open('GET', url);
|
||||
req.mozResponseType = req.responseType = 'arraybuffer';
|
||||
req.expected = (document.URL.indexOf('file:') == 0) ? 0 : 200;
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4 && req.status == req.expected) {
|
||||
var data = req.mozResponseArrayBuffer || req.mozResponse ||
|
||||
req.responseArrayBuffer || req.response;
|
||||
|
||||
this.loadCallback = callback;
|
||||
this.worker.postMessage(data);
|
||||
this.showPage(this.numPage);
|
||||
this.loadCallback = callback;
|
||||
this.worker.postMessage(data);
|
||||
this.showPage(this.numPage);
|
||||
}
|
||||
}.bind(this);
|
||||
req.send(null);
|
||||
},
|
||||
|
||||
showPage: function(numPage) {
|
||||
this.numPage = parseInt(numPage, 10);
|
||||
console.log('=== start rendering page ' + numPage + ' ===');
|
||||
consoleUtils.time('>>> total page display time:');
|
||||
this.worker.postMessage(numPage);
|
||||
if (this.onChangePage) {
|
||||
this.onChangePage(numPage);
|
||||
}
|
||||
}.bind(this);
|
||||
req.send(null);
|
||||
};
|
||||
},
|
||||
|
||||
WorkerPDFDoc.prototype.showPage = function(numPage) {
|
||||
this.numPage = parseInt(numPage, 10);
|
||||
console.log('=== start rendering page ' + numPage + ' ===');
|
||||
console.time('>>> total page display time:');
|
||||
this.worker.postMessage(numPage);
|
||||
if (this.onChangePage) {
|
||||
this.onChangePage(numPage);
|
||||
nextPage: function() {
|
||||
if (this.numPage != this.numPages)
|
||||
this.showPage(++this.numPage);
|
||||
},
|
||||
|
||||
prevPage: function() {
|
||||
if (this.numPage != 1)
|
||||
this.showPage(--this.numPage);
|
||||
}
|
||||
};
|
||||
|
||||
WorkerPDFDoc.prototype.nextPage = function() {
|
||||
if (this.numPage != this.numPages)
|
||||
this.showPage(++this.numPage);
|
||||
};
|
||||
|
||||
WorkerPDFDoc.prototype.prevPage = function() {
|
||||
if (this.numPage != 1)
|
||||
this.showPage(--this.numPage);
|
||||
};
|
||||
|
||||
|
@ -56,12 +56,12 @@ var actionHandler = {
|
||||
};
|
||||
|
||||
// Listen to the MainThread for data and call actionHandler on it.
|
||||
this.onmessage = function(event) {
|
||||
addEventListener('message', function(event) {
|
||||
var data = event.data;
|
||||
if (data.action in actionHandler) {
|
||||
actionHandler[data.action].call(this, data.data);
|
||||
} else {
|
||||
throw 'Unkown action from worker: ' + data.action;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -11,8 +11,10 @@ var console = {
|
||||
action: 'log',
|
||||
data: args
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
var consoleUtils = {
|
||||
time: function(name) {
|
||||
consoleTimer[name] = Date.now();
|
||||
},
|
||||
@ -22,7 +24,7 @@ var console = {
|
||||
if (time == null) {
|
||||
throw 'Unkown timer name ' + name;
|
||||
}
|
||||
this.log('Timer:', name, Date.now() - time);
|
||||
console.log('Timer:', name, Date.now() - time);
|
||||
}
|
||||
};
|
||||
|
||||
@ -42,7 +44,7 @@ var canvas = new CanvasProxy(1224, 1584);
|
||||
|
||||
// Listen for messages from the main thread.
|
||||
var pdfDocument = null;
|
||||
onmessage = function(event) {
|
||||
addEventListener('message', function(event) {
|
||||
var data = event.data;
|
||||
// If there is no pdfDocument yet, then the sent data is the PDFDocument.
|
||||
if (!pdfDocument) {
|
||||
@ -55,7 +57,7 @@ onmessage = function(event) {
|
||||
}
|
||||
// User requested to render a certain page.
|
||||
else {
|
||||
console.time('compile');
|
||||
consoleUtils.time('compile');
|
||||
|
||||
// Let's try to render the first page...
|
||||
var page = pdfDocument.getPage(parseInt(data, 10));
|
||||
@ -77,19 +79,19 @@ onmessage = function(event) {
|
||||
var fonts = [];
|
||||
var gfx = new CanvasGraphics(canvas.getContext('2d'), CanvasProxy);
|
||||
page.compile(gfx, fonts);
|
||||
console.timeEnd('compile');
|
||||
consoleUtils.timeEnd('compile');
|
||||
|
||||
// Send fonts to the main thread.
|
||||
console.time('fonts');
|
||||
consoleUtils.time('fonts');
|
||||
postMessage({
|
||||
action: 'fonts',
|
||||
data: fonts
|
||||
});
|
||||
console.timeEnd('fonts');
|
||||
consoleUtils.timeEnd('fonts');
|
||||
|
||||
console.time('display');
|
||||
consoleUtils.time('display');
|
||||
page.display(gfx);
|
||||
canvas.flush();
|
||||
console.timeEnd('display');
|
||||
consoleUtils.timeEnd('display');
|
||||
}
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user