From eb17d81316e8ba01a9d27d7263769995f13b93b5 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 4 Jul 2011 16:14:04 -0400 Subject: [PATCH 1/2] fix test.py bug on windows and stomped failure messages --- test/test.py | 2 +- test/test_slave.html | 47 ++++++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/test/test.py b/test/test.py index 52e91476a..367347e88 100644 --- a/test/test.py +++ b/test/test.py @@ -99,7 +99,7 @@ class PDFTestHandler(BaseHTTPRequestHandler): self.send_header("Content-Type", MIMEs[ext]) self.send_header("Content-Length", os.path.getsize(path)) self.end_headers() - with open(path) as f: + with open(path, "rb") as f: self.wfile.write(f.read()) def do_GET(self): diff --git a/test/test_slave.html b/test/test_slave.html index 3180418fa..0bf254ad5 100644 --- a/test/test_slave.html +++ b/test/test_slave.html @@ -88,31 +88,35 @@ function nextPage() { } } - failure = ''; - log(" loading page "+ currentTask.pageNum +"... "); + var ctx, fonts, gfx; + if (!failure) { + log(" loading page "+ currentTask.pageNum +"... "); - var ctx = canvas.getContext("2d"); + ctx = canvas.getContext("2d"); - var fonts = []; - var gfx = null; - try { - gfx = new CanvasGraphics(ctx); - currentPage = pdfDoc.getPage(currentTask.pageNum); - currentPage.compile(gfx, fonts); - } catch(e) { - failure = 'compile: '+ e.toString(); + fonts = []; + gfx = null; + try { + gfx = new CanvasGraphics(ctx); + currentPage = pdfDoc.getPage(currentTask.pageNum); + currentPage.compile(gfx, fonts); + } catch(e) { + failure = 'compile: '+ e.toString(); + } } - try { - var pdfToCssUnitsCoef = 96.0 / 72.0; - // using mediaBox for the canvas size - var pageWidth = (currentPage.mediaBox[2] - currentPage.mediaBox[0]); - var pageHeight = (currentPage.mediaBox[3] - currentPage.mediaBox[1]); - canvas.width = pageWidth * pdfToCssUnitsCoef; - canvas.height = pageHeight * pdfToCssUnitsCoef; - clear(ctx); - } catch(e) { - failure = 'page setup: '+ e.toString(); + if (!failure) { + try { + var pdfToCssUnitsCoef = 96.0 / 72.0; + // using mediaBox for the canvas size + var pageWidth = (currentPage.mediaBox[2] - currentPage.mediaBox[0]); + var pageHeight = (currentPage.mediaBox[3] - currentPage.mediaBox[1]); + canvas.width = pageWidth * pdfToCssUnitsCoef; + canvas.height = pageHeight * pdfToCssUnitsCoef; + clear(ctx); + } catch(e) { + failure = 'page setup: '+ e.toString(); + } } if (!failure) { @@ -145,6 +149,7 @@ function snapshotCurrentPage(gfx) { log("done"+ (failure ? " (failed!)" : "") +"\n"); // Set up the next request + failure = ''; backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0; setTimeout(function() { ++currentTask.pageNum, nextPage(); From d4f49c05c5f4fbaeda24ec5b7b590ce36434a74d Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 4 Jul 2011 17:39:29 -0400 Subject: [PATCH 2/2] fix another binary-mode issue --- pdf.js | 1 + test/test.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index 814c99f75..48fa004e6 100644 --- a/pdf.js +++ b/pdf.js @@ -2971,6 +2971,7 @@ var Catalog = (function() { var PDFDoc = (function() { function constructor(stream) { + assertWellFormed(stream.length > 0, "stream must have data"); this.stream = stream; this.setup(); } diff --git a/test/test.py b/test/test.py index 367347e88..00b87f786 100644 --- a/test/test.py +++ b/test/test.py @@ -275,7 +275,7 @@ def downloadLinkedPDFs(manifestList): sys.stdout.flush() response = urllib2.urlopen(link) - with open(f, 'w') as out: + with open(f, 'wb') as out: out.write(response.read()) print 'done'