diff --git a/src/api.js b/src/api.js index 82e85681c..3d683af07 100644 --- a/src/api.js +++ b/src/api.js @@ -15,7 +15,6 @@ // all requirements to run parts of pdf.js in a web worker. // Right now, the requirement is, that an Uint8Array is still an Uint8Array // as it arrives on the worker. Chrome added this with version 15. - globalScope.PDFJS.disableWorker = true; if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') { var workerSrc = PDFJS.workerSrc; if (typeof workerSrc === 'undefined') { @@ -203,7 +202,7 @@ getPage: function WorkerTransport_getPage(n, promise) { if (this.pageCache[n - 1]) { - promise.resolve(pageCache[n - 1]); + promise.resolve(this.pageCache[n - 1]); return; } if ((n - 1) in this.pagePromises) { diff --git a/test/driver.js b/test/driver.js index a1dc4b242..600f53c9c 100644 --- a/test/driver.js +++ b/test/driver.js @@ -100,13 +100,24 @@ function nextTask() { getPdf(task.file, function nextTaskGetPdf(data) { var failure; + function continuation() { + task.pageNum = task.firstPage || 1; + nextPage(task, failure); + } try { - task.pdfDoc = new PDFJS.PDFDoc(data); + var promise = PDFJS.getDocument(data); + promise.then(function(doc) { + task.pdfDoc = doc; + continuation(); + }, function(e) { + failure = 'load PDF doc : ' + e; + continuation(); + }); + return; } catch (e) { failure = 'load PDF doc : ' + exceptionToString(e); } - task.pageNum = task.firstPage || 1; - nextPage(task, failure); + continuation(); }); } @@ -163,45 +174,43 @@ function nextPage(task, loadError) { log(' loading page ' + task.pageNum + '/' + task.pdfDoc.numPages + '... '); var ctx = canvas.getContext('2d'); - page = task.pdfDoc.getPage(task.pageNum); + task.pdfDoc.getPage(task.pageNum).then(function(page) { + var pdfToCssUnitsCoef = 96.0 / 72.0; + // using mediaBox for the canvas size + var pageWidth = page.width; + var pageHeight = page.height; + canvas.width = pageWidth * pdfToCssUnitsCoef; + canvas.height = pageHeight * pdfToCssUnitsCoef; + clear(ctx); - var pdfToCssUnitsCoef = 96.0 / 72.0; - // using mediaBox for the canvas size - var pageWidth = page.width; - var pageHeight = page.height; - canvas.width = pageWidth * pdfToCssUnitsCoef; - canvas.height = pageHeight * pdfToCssUnitsCoef; - clear(ctx); - - // using the text layer builder that does nothing to test - // text layer creation operations - var textLayerBuilder = { - beginLayout: function nullTextLayerBuilderBeginLayout() {}, - endLayout: function nullTextLayerBuilderEndLayout() {}, - appendText: function nullTextLayerBuilderAppendText(text, fontName, - fontSize) {} - }; - - page.startRendering( - ctx, - function nextPageStartRendering(error) { - var failureMessage = false; - if (error) - failureMessage = 'render : ' + error.message; - snapshotCurrentPage(task, failureMessage); + // using the text layer builder that does nothing to test + // text layer creation operations + var textLayerBuilder = { + beginLayout: function nullTextLayerBuilderBeginLayout() {}, + endLayout: function nullTextLayerBuilderEndLayout() {}, + appendText: function nullTextLayerBuilderAppendText(text, fontName, + fontSize) {} + }; + var renderContext = { + canvasContext: ctx, + textLayer: textLayerBuilder, + viewport: page.getViewport(1) + }; + page.render(renderContext).then(function() { + snapshotCurrentPage(task, false); }, - textLayerBuilder - ); + function(error) { + snapshotCurrentPage(task, 'render : ' + error); + }); + }, + function(error) { + snapshotCurrentPage(task, 'render : ' + error); + }); } catch (e) { failure = 'page setup : ' + exceptionToString(e); + snapshotCurrentPage(task, failure); } } - - if (failure) { - // Skip right to snapshotting if there was a failure, since the - // fonts might be in an inconsistent state. - snapshotCurrentPage(task, failure); - } } function snapshotCurrentPage(task, failure) { diff --git a/test/test_slave.html b/test/test_slave.html index 50bb067e1..7c2097110 100644 --- a/test/test_slave.html +++ b/test/test_slave.html @@ -5,6 +5,7 @@ +