mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
update to master
This commit is contained in:
commit
8006faf74e
9 changed files with 163 additions and 85 deletions
|
@ -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();
|
||||
|
@ -126,7 +144,7 @@ function nextPage(task, loadError) {
|
|||
|
||||
page.startRendering(
|
||||
ctx,
|
||||
function(e) {
|
||||
function nextPageStartRendering(e) {
|
||||
snapshotCurrentPage(task, (!failure && e) ?
|
||||
('render : ' + e) : failure);
|
||||
}
|
||||
|
@ -146,13 +164,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);
|
||||
},
|
||||
|
@ -201,7 +219,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--;
|
||||
}
|
||||
|
|
1
test/pdfs/hudsonsurvey.pdf.link
Normal file
1
test/pdfs/hudsonsurvey.pdf.link
Normal file
|
@ -0,0 +1 @@
|
|||
https://issues.apache.org/jira/secure/attachment/12421789/survey.pdf
|
|
@ -146,6 +146,12 @@
|
|||
"rounds": 1,
|
||||
"type": "load"
|
||||
},
|
||||
{ "id": "hudsonsurvey",
|
||||
"file": "pdfs/hudsonsurvey.pdf",
|
||||
"link": true,
|
||||
"rounds": 1,
|
||||
"type": "load"
|
||||
},
|
||||
{ "id": "extgstate",
|
||||
"file": "pdfs/extgstate.pdf",
|
||||
"link": false,
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<body onload="load();">
|
||||
<pre style="width:800; height:800; overflow: scroll;"id="stdout"></pre>
|
||||
<p>Inflight requests: <span id="inFlightCount"></span></p>
|
||||
<div id="content-end"><!-- cleanup() guard --></div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue