Test refactoring for async api.
This commit is contained in:
parent
3b83a42a91
commit
5608f8e445
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -5,6 +5,7 @@
|
||||
<style type="text/css"></style>
|
||||
<script type="text/javascript" src="/src/core.js"></script>
|
||||
<script type="text/javascript" src="/src/util.js"></script>
|
||||
<script type="text/javascript" src="/src/api.js"></script>
|
||||
<script type="text/javascript" src="/src/canvas.js"></script>
|
||||
<script type="text/javascript" src="/src/obj.js"></script>
|
||||
<script type="text/javascript" src="/src/function.js"></script>
|
||||
|
Loading…
Reference in New Issue
Block a user