Skip to content

Commit

Permalink
Merge pull request #6209 from Rob--W/parallel-rendering
Browse files Browse the repository at this point in the history
Fix font rendering when rendering multiple PDFs in parallel
  • Loading branch information
timvandermeij committed Nov 25, 2015
2 parents 0819d71 + 07f2a43 commit 5fcd779
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions test/unit/api_spec.js
@@ -1,7 +1,7 @@
/* globals PDFJS, expect, it, describe, Promise, combineUrl, waitsFor,
InvalidPDFException, MissingPDFException, StreamType, FontType,
PDFDocumentProxy, PasswordException, PasswordResponses,
PDFPageProxy, createPromiseCapability */
PDFPageProxy, createPromiseCapability, afterEach */

'use strict';

Expand All @@ -16,7 +16,7 @@ describe('api', function() {
},
function(error) {
// Shouldn't get here.
expect(false).toEqual(true);
expect(error).toEqual('the promise should not have been rejected');
});
waitsFor(function() {
return resolved;
Expand Down Expand Up @@ -523,4 +523,69 @@ describe('api', function() {
});
});
});
describe('Multiple PDFJS instances', function() {
// Regression test for https://github.com/mozilla/pdf.js/issues/6205
// A PDF using the Helvetica font.
var pdf1 = combineUrl(window.location.href, '../pdfs/tracemonkey.pdf');
// A PDF using the Times font.
var pdf2 = combineUrl(window.location.href, '../pdfs/TAMReview.pdf');
// A PDF using the Arial font.
var pdf3 = combineUrl(window.location.href, '../pdfs/issue6068.pdf');
var pdfDocuments = [];

// Render the first page of the given PDF file.
// Fulfills the promise with the base64-encoded version of the PDF.
function renderPDF(filename) {
return PDFJS.getDocument(filename)
.then(function(pdf) {
pdfDocuments.push(pdf);
return pdf.getPage(1);
}).then(function(page) {
var c = document.createElement('canvas');
var v = page.getViewport(1.2);
c.width = v.width;
c.height = v.height;
return page.render({
canvasContext: c.getContext('2d'),
viewport: v,
}).then(function() {
return c.toDataURL();
});
});
}

afterEach(function() {
// Issue 6205 reported an issue with font rendering, so clear the loaded
// fonts so that we can see whether loading PDFs in parallel does not
// cause any issues with the rendered fonts.
var destroyPromises = pdfDocuments.map(function(pdfDocument) {
return pdfDocument.destroy();
});
waitsForPromiseResolved(Promise.all(destroyPromises), function() {});
});

it('should correctly render PDFs in parallel', function() {
var baseline1, baseline2, baseline3;
var promiseDone = renderPDF(pdf1).then(function(data1) {
baseline1 = data1;
return renderPDF(pdf2);
}).then(function(data2) {
baseline2 = data2;
return renderPDF(pdf3);
}).then(function(data3) {
baseline3 = data3;
return Promise.all([
renderPDF(pdf1),
renderPDF(pdf2),
renderPDF(pdf3),
]);
}).then(function(dataUrls) {
expect(dataUrls[0]).toEqual(baseline1);
expect(dataUrls[1]).toEqual(baseline2);
expect(dataUrls[2]).toEqual(baseline3);
return true;
});
waitsForPromiseResolved(promiseDone, function() {});
});
});
});

0 comments on commit 5fcd779

Please sign in to comment.