Merge branch 'master' of https://github.com/andreasgal/pdf.js.git into invalidpdf-1

Conflicts:
	test/test_manifest.json
This commit is contained in:
notmasteryet 2011-09-24 09:57:59 -05:00
commit 39ba5324a7
7 changed files with 260 additions and 58 deletions

View file

@ -39,7 +39,7 @@ function load() {
var r = new XMLHttpRequest();
r.open('GET', manifestFile, false);
r.onreadystatechange = function(e) {
r.onreadystatechange = function loadOnreadystatechange(e) {
if (r.readyState == 4) {
log('done\n');
manifest = JSON.parse(r.responseText);
@ -50,7 +50,21 @@ function load() {
r.send(null);
}
function cleanup() {
var styleSheet = document.styleSheets[0];
if (styleSheet) {
while (styleSheet.cssRules.length > 0)
styleSheet.deleteRule(0);
}
var guard = document.getElementById('content-end');
var body = document.body;
while (body.lastChild !== guard)
body.removeChild(body.lastChild);
}
function nextTask() {
cleanup();
if (currentTaskIdx == manifest.length) {
return done();
}
@ -62,7 +76,7 @@ function nextTask() {
var r = new XMLHttpRequest();
r.open('GET', task.file);
r.mozResponseType = r.responseType = 'arraybuffer';
r.onreadystatechange = function() {
r.onreadystatechange = function nextTaskOnreadystatechange() {
var failure;
if (r.readyState == 4) {
var data = r.mozResponseArrayBuffer || r.mozResponse ||
@ -85,11 +99,15 @@ function isLastPage(task) {
return (task.pageNum > task.pdfDoc.numPages);
}
function canvasToDataURL() {
return canvas.toDataURL('image/png');
}
function nextPage(task, loadError) {
var failure = loadError || '';
if (!task.pdfDoc) {
sendTaskResult(canvas.toDataURL('image/png'), task, failure);
sendTaskResult(canvasToDataURL(), task, failure);
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
++currentTaskIdx;
nextTask();
@ -133,7 +151,7 @@ function nextPage(task, loadError) {
page.startRendering(
ctx,
function(e) {
function nextPageStartRendering(e) {
snapshotCurrentPage(task, (!failure && e) ?
('render : ' + e) : failure);
}
@ -153,13 +171,13 @@ function nextPage(task, loadError) {
function snapshotCurrentPage(task, failure) {
log('done, snapshotting... ');
sendTaskResult(canvas.toDataURL('image/png'), task, failure);
sendTaskResult(canvasToDataURL(), task, failure);
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
// Set up the next request
var backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0;
setTimeout(
function() {
function snapshotCurrentPageSetTimeout() {
++task.pageNum;
nextPage(task);
},
@ -208,7 +226,7 @@ function sendTaskResult(snapshot, task, failure) {
// (The POST URI is ignored atm.)
r.open('POST', '/submit_task_results', true);
r.setRequestHeader('Content-Type', 'application/json');
r.onreadystatechange = function(e) {
r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
if (r.readyState == 4) {
inFlightRequests--;
}