1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge worker_pull with master

This commit is contained in:
Julian Viereck 2011-10-08 14:18:23 +02:00
commit 3054102d3b
44 changed files with 10119 additions and 1922 deletions

View file

@ -8,6 +8,7 @@
'use strict';
var appPath, browser, canvas, currentTaskIdx, manifest, stdout;
var inFlightRequests = 0;
function queryParams() {
var qs = window.location.search.substring(1);
@ -38,16 +39,28 @@ 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);
currentTaskIdx = 0, nextTask();
currentTaskIdx = 0;
nextTask();
}
};
r.send(null);
}
window.onload = load;
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() {
// If there is a pdfDoc on the last task executed, destroy it to free memory.
@ -55,6 +68,8 @@ function nextTask() {
task.pdfDoc.destroy();
delete task.pdfDoc;
}
cleanup();
if (currentTaskIdx == manifest.length) {
return done();
}
@ -63,39 +78,34 @@ function nextTask() {
log('Loading file "' + task.file + '"\n');
var r = new XMLHttpRequest();
r.open('GET', task.file);
r.mozResponseType = r.responseType = 'arraybuffer';
r.onreadystatechange = function() {
getPdf(task.file, function nextTaskGetPdf(data) {
var failure;
if (r.readyState == 4) {
var data = r.mozResponseArrayBuffer || r.mozResponse ||
r.responseArrayBuffer || r.response;
try {
task.pdfDoc = new WorkerPDFDoc(data);
// task.pdfDoc = new PDFDoc(new Stream(data));
} catch (e) {
failure = 'load PDF doc : ' + e.toString();
}
task.pageNum = task.firstPage || 1, nextPage(task, failure);
try {
task.pdfDoc = new PDFDoc(data);
} catch (e) {
failure = 'load PDF doc : ' + e.toString();
}
};
r.send(null);
task.pageNum = task.firstPage || 1;
nextPage(task, failure);
});
}
function isLastPage(task) {
return (task.pageNum > task.pdfDoc.numPages);
return task.pageNum > task.pdfDoc.numPages || task.pageNum > task.pageLimit;
}
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();
++currentTaskIdx;
nextTask();
return;
}
@ -104,11 +114,19 @@ function nextPage(task, loadError) {
log(' Round ' + (1 + task.round) + '\n');
task.pageNum = 1;
} else {
++currentTaskIdx, nextTask();
++currentTaskIdx;
nextTask();
return;
}
}
if (task.skipPages && task.skipPages.indexOf(task.pageNum) >= 0) {
log(' skipping page ' + task.pageNum + '/' + task.pdfDoc.numPages +
'... ');
snapshotCurrentPage(task, '');
return;
}
var page = null;
if (!failure) {
@ -128,8 +146,8 @@ function nextPage(task, loadError) {
page.startRendering(
ctx,
function(e) {
snapshotCurrentPage(page, task, (!failure && e) ?
function nextPageStartRendering(e) {
snapshotCurrentPage(task, (!failure && e) ?
('render : ' + e) : failure);
}
);
@ -141,21 +159,22 @@ function nextPage(task, loadError) {
if (failure) {
// Skip right to snapshotting if there was a failure, since the
// fonts might be in an inconsistent state.
snapshotCurrentPage(page, task, failure);
snapshotCurrentPage(task, failure);
}
}
function snapshotCurrentPage(page, task, failure) {
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() {
++task.pageNum, nextPage(task);
function snapshotCurrentPageSetTimeout() {
++task.pageNum;
nextPage(task);
},
backoff
);
@ -188,11 +207,11 @@ function done() {
}
}
var inFlightRequests = 0;
function sendTaskResult(snapshot, task, failure) {
var result = { browser: browser,
id: task.id,
numPages: task.pdfDoc ? task.pdfDoc.numPages : 0,
numPages: task.pdfDoc ?
(task.pageLimit || task.pdfDoc.numPages) : 0,
failure: failure,
file: task.file,
round: task.round,
@ -203,11 +222,11 @@ 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--;
}
}
};
document.getElementById('inFlightCount').innerHTML = inFlightRequests++;
r.send(JSON.stringify(result));
}

18
test/pdfs/.gitignore vendored
View file

@ -1,3 +1,15 @@
pdf.pdf
intelisa.pdf
openweb_tm-PRINT.pdf
*.pdf
!tracemonkey.pdf
!ArabicCIDTrueType.pdf
!ThuluthFeatures.pdf
!arial_unicode_ab_cidfont.pdf
!arial_unicode_en_cidfont.pdf
!asciihexdecode.pdf
!canvas.pdf
!complex_ttf_font.pdf
!extgstate.pdf
!rotation.pdf
!simpletype3font.pdf
!sizes.pdf

BIN
test/pdfs/ThuluthFeatures.pdf Executable file

Binary file not shown.

105
test/pdfs/extgstate.pdf Normal file
View file

@ -0,0 +1,105 @@
%PDF-1.4
%öäüß
1 0 obj
<<
/Type /Catalog
/Version /1.4
/Pages 2 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/Kids [3 0 R]
/Count 1
>>
endobj
3 0 obj
<<
/Type /Page
/MediaBox [0 0 612 792]
/Resources 4 0 R
/Parent 2 0 R
/Contents 5 0 R
>>
endobj
4 0 obj
<<
/ExtGState 6 0 R
/Font 7 0 R
/XObject <<
>>
>>
endobj
5 0 obj
<<
/Length 8 0 R
>>
stream
/GS1 gs
/F0 12 Tf
BT
100 700 Td
(I should be courier!) Tj
ET
50 600 m
400 600 l
S
endstream
endobj
6 0 obj
<<
/GS1 9 0 R
>>
endobj
7 0 obj
<<
/F0 10 0 R
>>
endobj
8 0 obj
82
endobj
9 0 obj
<<
/Type /ExtGState
/LW 10
/LC 1
/LJ 2
/ML 0.3000000119
/D [[0.0917000026 183.3300018311]
0]
/Font [10 0 R 36]
>>
endobj
10 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Courier
/Encoding /WinAnsiEncoding
>>
endobj
xref
0 11
0000000000 65535 f
0000000015 00000 n
0000000078 00000 n
0000000135 00000 n
0000000239 00000 n
0000000304 00000 n
0000000441 00000 n
0000000473 00000 n
0000000505 00000 n
0000000523 00000 n
0000000653 00000 n
trailer
<<
/Root 1 0 R
/ID [<BFFF29B7D1C75EC69AC080682C2AFC5B> <BFFF29B7D1C75EC69AC080682C2AFC5B>]
/Size 11
>>
startxref
749
%%EOF

1
test/pdfs/f1040.pdf.link Normal file
View file

@ -0,0 +1 @@
http://www.irs.gov/pub/irs-pdf/f1040.pdf

View file

@ -0,0 +1 @@
http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf

View file

@ -0,0 +1 @@
https://issues.apache.org/jira/secure/attachment/12421789/survey.pdf

View file

@ -0,0 +1 @@
http://www.bottledwater.org/public/pdf/IBWA05ModelCode_Mar2.pdf

View file

@ -0,0 +1,141 @@
%PDF-1.4
%öäüß
1 0 obj
<<
/Type /Catalog
/Version /1.4
/Pages 2 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/Kids [3 0 R]
/Count 1
>>
endobj
3 0 obj
<<
/Type /Page
/MediaBox [0 0 612 792]
/Parent 2 0 R
/Resources 4 0 R
/Contents 5 0 R
>>
endobj
4 0 obj
<<
/Font 6 0 R
/XObject <<
>>
>>
endobj
5 0 obj
<<
/Length 7 0 R
>>
stream
/F0 12 Tf
BT
100 700 Td
(ababab) Tj
ET
endstream
endobj
6 0 obj
<<
/F0 8 0 R
>>
endobj
7 0 obj
39
endobj
8 0 obj
<<
/Type /Font
/Subtype /Type3
/FontBBox [0 0 750 750]
/FontMatrix [0.001 0 0 0.001 0 0]
/CharProcs 9 0 R
/Encoding 10 0 R
/FirstChar 97
/LastChar 98
/Widths [1000 1000]
/FontDescriptor 11 0 R
>>
endobj
9 0 obj
<<
/square 12 0 R
/triangle 13 0 R
>>
endobj
10 0 obj
<<
/Type /Encoding
/Differences [97 /square /triangle]
>>
endobj
11 0 obj
<<
/Type /FontDescriptor
/FontName /SandT
/Flags 262178
/Ascent 0
/CapHeight 0
/Descent 0
/ItalicAngle 0
/StemV 0
/FontBBox [0 0 750 750]
>>
endobj
12 0 obj
<<
/Length 14 0 R
>>
stream
1000 0 0 0 750 750 d1 0 0 750 750 re f
endstream
endobj
13 0 obj
<<
/Length 15 0 R
>>
stream
1000 0 0 0 750 750 d1 0 0 m 375 750 l 750 0 l f
endstream
endobj
14 0 obj
38
endobj
15 0 obj
47
endobj
xref
0 16
0000000000 65535 f
0000000015 00000 n
0000000078 00000 n
0000000135 00000 n
0000000239 00000 n
0000000287 00000 n
0000000381 00000 n
0000000412 00000 n
0000000430 00000 n
0000000641 00000 n
0000000694 00000 n
0000000768 00000 n
0000000925 00000 n
0000001020 00000 n
0000001124 00000 n
0000001143 00000 n
trailer
<<
/Root 1 0 R
/ID [<DD02410A8B7AD4A0EE0D50E4180FABAC> <DD02410A8B7AD4A0EE0D50E4180FABAC>]
/Size 16
>>
startxref
1162
%%EOF

View file

@ -0,0 +1 @@
http://www.tcpdf.org/examples/example_033.pdf

View file

@ -0,0 +1 @@
http://www.sanface.com/pdf/test.pdf

View file

@ -0,0 +1 @@
https://docs.rice.edu/confluence/download/attachments/4588376/unix01.pdf?version=1

View file

@ -0,0 +1 @@
http://www.mit.edu/~6.033/writing-samples/usmanm_dp1.pdf

1
test/pdfs/vesta.pdf.link Normal file
View file

@ -0,0 +1 @@
http://www-csag.ucsd.edu/~jburke/Vesta/Vesta_Overview.pdf

View file

@ -0,0 +1 @@
http://www.airgid.com/book/wdsg_fitc.pdf

View file

@ -0,0 +1 @@
http://www.cdc.gov/ncidod/dvbid/westnile/languages/chinese.pdf

View file

@ -0,0 +1,2 @@
browser_manifest.json

View file

@ -23,6 +23,8 @@ class TestOptions(OptionParser):
OptionParser.__init__(self, **kwargs)
self.add_option("-m", "--masterMode", action="store_true", dest="masterMode",
help="Run the script in master mode.", default=False)
self.add_option("--noPrompts", action="store_true", dest="noPrompts",
help="Uses default answers (intended for CLOUD TESTS only!).", default=False)
self.add_option("--manifestFile", action="store", type="string", dest="manifestFile",
help="A JSON file in the form of test_manifest.json (the default).")
self.add_option("-b", "--browser", action="store", type="string", dest="browser",
@ -321,7 +323,7 @@ def setUp(options):
if options.masterMode and os.path.isdir(TMPDIR):
print 'Temporary snapshot dir tmp/ is still around.'
print 'tmp/ can be removed if it has nothing you need.'
if prompt('SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY'):
if options.noPrompts or prompt('SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY'):
subprocess.call(( 'rm', '-rf', 'tmp' ))
assert not os.path.isdir(TMPDIR)
@ -414,8 +416,9 @@ def checkEq(task, results, browser, masterMode):
path = os.path.join(pfx, str(page + 1))
if not os.access(path, os.R_OK):
print 'WARNING: no reference snapshot', path
State.numEqNoSnapshot += 1
if not masterMode:
print 'WARNING: no reference snapshot', path
else:
f = open(path)
ref = f.read()
@ -432,9 +435,9 @@ def checkEq(task, results, browser, masterMode):
# NB: this follows the format of Mozilla reftest
# output so that we can reuse its reftest-analyzer
# script
print >>eqLog, 'REFTEST TEST-UNEXPECTED-FAIL |', browser +'-'+ taskId +'-page'+ str(page + 1), '| image comparison (==)'
print >>eqLog, 'REFTEST IMAGE 1 (TEST):', snapshot
print >>eqLog, 'REFTEST IMAGE 2 (REFERENCE):', ref
eqLog.write('REFTEST TEST-UNEXPECTED-FAIL | ' + browser +'-'+ taskId +'-page'+ str(page + 1) + ' | image comparison (==)\n')
eqLog.write('REFTEST IMAGE 1 (TEST): ' + snapshot + '\n')
eqLog.write('REFTEST IMAGE 2 (REFERENCE): ' + ref + '\n')
passed = False
State.numEqFailures += 1
@ -444,8 +447,9 @@ def checkEq(task, results, browser, masterMode):
try:
os.makedirs(tmpTaskDir)
except OSError, e:
print >>sys.stderr, 'Creating', tmpTaskDir, 'failed!'
if e.errno != 17: # file exists
print >>sys.stderr, 'Creating', tmpTaskDir, 'failed!'
of = open(os.path.join(tmpTaskDir, str(page + 1)), 'w')
of.write(snapshot)
of.close()
@ -453,7 +457,6 @@ def checkEq(task, results, browser, masterMode):
if passed:
print 'TEST-PASS | eq test', task['id'], '| in', browser
def checkFBF(task, results, browser):
round0, round1 = results[0], results[1]
assert len(round0) == len(round1)
@ -503,10 +506,10 @@ def maybeUpdateRefImages(options, browser):
print ' Yes! The references in tmp/ can be synced with ref/.'
if options.reftest:
startReftest(browser, options)
if not prompt('Would you like to update the master copy in ref/?'):
if options.noPrompts or not prompt('Would you like to update the master copy in ref/?'):
print ' OK, not updating.'
else:
sys.stdout.write(' Updating ... ')
sys.stdout.write(' Updating ref/ ... ')
# XXX unclear what to do on errors here ...
# NB: do *NOT* pass --delete to rsync. That breaks this
@ -539,7 +542,8 @@ def runTests(options, browsers):
teardownBrowsers(browsers)
t2 = time.time()
print "Runtime was", int(t2 - t1), "seconds"
if State.eqLog:
State.eqLog.close();
if options.masterMode:
maybeUpdateRefImages(options, browsers[0])
elif options.reftest and State.numEqFailures > 0:

View file

@ -69,6 +69,17 @@
"rounds": 1,
"type": "load"
},
{ "id": "thuluthfont-pdf",
"file": "pdfs/ThuluthFeatures.pdf",
"rounds": 1,
"type": "eq"
},
{ "id": "wnv_chinese-pdf",
"file": "pdfs/wnv_chinese.pdf",
"link": true,
"rounds": 1,
"type": "eq"
},
{ "id": "i9-pdf",
"file": "pdfs/i9.pdf",
"link": true,
@ -115,5 +126,78 @@
"link": true,
"rounds": 1,
"type": "eq"
},
{ "id": "wdsg_fitc",
"file": "pdfs/wdsg_fitc.pdf",
"link": true,
"rounds": 1,
"type": "eq"
},
{ "id": "unix01",
"file": "pdfs/unix01.pdf",
"link": true,
"rounds": 1,
"type": "eq"
},
{ "id": "fips197",
"file": "pdfs/fips197.pdf",
"link": true,
"rounds": 1,
"type": "load"
},
{ "id": "txt2pdf",
"file": "pdfs/txt2pdf.pdf",
"link": true,
"rounds": 1,
"type": "load"
},
{ "id": "f1040",
"file": "pdfs/f1040.pdf",
"link": true,
"rounds": 1,
"type": "load"
},
{ "id": "hudsonsurvey",
"file": "pdfs/hudsonsurvey.pdf",
"link": true,
"rounds": 1,
"type": "load"
},
{ "id": "extgstate",
"file": "pdfs/extgstate.pdf",
"link": false,
"rounds": 1,
"type": "load"
},
{ "id": "usmanm-bad",
"file": "pdfs/usmanm-bad.pdf",
"link": true,
"rounds": 1,
"type": "eq"
},
{ "id": "vesta-bad",
"file": "pdfs/vesta.pdf",
"link": true,
"rounds": 1,
"type": "load"
},
{ "id": "ibwa-bad",
"file": "pdfs/ibwa-bad.pdf",
"link": true,
"rounds": 1,
"skipPages": [ 16 ],
"type": "load"
},
{ "id": "tcpdf_033",
"file": "pdfs/tcpdf_033.pdf",
"link": true,
"rounds": 1,
"type": "eq"
},
{ "id": "simpletype3font",
"file": "pdfs/simpletype3font.pdf",
"link": false,
"rounds": 1,
"type": "eq"
}
]

View file

@ -7,6 +7,8 @@
<script type="text/javascript" src="/crypto.js"></script>
<script type="text/javascript" src="/glyphlist.js"></script>
<script type="text/javascript" src="/metrics.js"></script>
<script type="text/javascript" src="/charsets.js"></script>
<script type="text/javascript" src="/cidmaps.js"></script>
<script type="text/javascript" src="driver.js"></script>
<script type="text/javascript" src="../worker.js"></script>
<script type="text/javascript" src="../worker/message_handler.js"></script>
@ -17,6 +19,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>