Browse Source

PDF.js version 1.8.359 - See mozilla/pdf.js@5958dafd8c5d1cb8e2e20d946e58017d6156907a

master v1.8.359
pdfjsbot 8 years ago
parent
commit
4265b34c64
  1. 2
      bower.json
  2. 30
      build/pdf.combined.js
  3. 2
      build/pdf.combined.js.map
  4. 30
      build/pdf.js
  5. 2
      build/pdf.js.map
  6. 12
      build/pdf.min.js
  7. 4
      build/pdf.worker.js
  8. 2
      build/pdf.worker.js.map
  9. 11
      lib/display/api.js
  10. 11
      lib/display/canvas.js
  11. 4
      lib/display/global.js
  12. 4
      lib/pdf.js
  13. 4
      lib/pdf.worker.js
  14. 84
      lib/test/unit/api_spec.js
  15. 115
      lib/test/unit/custom_spec.js
  16. 2
      lib/test/unit/jasmine-boot.js
  17. 21
      lib/test/unit/test_utils.js
  18. 2
      package.json

2
bower.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.8.357", "version": "1.8.359",
"main": [ "main": [
"build/pdf.js", "build/pdf.js",
"build/pdf.worker.js" "build/pdf.worker.js"

30
build/pdf.combined.js

@ -12741,7 +12741,12 @@ var InternalRenderTask = function InternalRenderTaskClosure() {
} }
var params = this.params; var params = this.params;
this.gfx = new _canvas.CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, this.canvasFactory, params.imageLayer); this.gfx = new _canvas.CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, this.canvasFactory, params.imageLayer);
this.gfx.beginDrawing(params.transform, params.viewport, transparency); this.gfx.beginDrawing({
transform: params.transform,
viewport: params.viewport,
transparency: transparency,
background: params.background
});
this.operatorListIdx = 0; this.operatorListIdx = 0;
this.graphicsReady = true; this.graphicsReady = true;
if (this.graphicsReadyCallback) { if (this.graphicsReadyCallback) {
@ -12822,8 +12827,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
}(); }();
var version, build; var version, build;
{ {
exports.version = version = '1.8.357'; exports.version = version = '1.8.359';
exports.build = build = 'ca3cf6e7'; exports.build = build = '5958dafd';
} }
exports.getDocument = getDocument; exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort; exports.LoopbackPort = LoopbackPort;
@ -28229,8 +28234,8 @@ if (!_util.globalScope.PDFJS) {
} }
var PDFJS = _util.globalScope.PDFJS; var PDFJS = _util.globalScope.PDFJS;
{ {
PDFJS.version = '1.8.357'; PDFJS.version = '1.8.359';
PDFJS.build = 'ca3cf6e7'; PDFJS.build = '5958dafd';
} }
PDFJS.pdfBug = false; PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) { if (PDFJS.verbosity !== undefined) {
@ -41979,11 +41984,17 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
var NORMAL_CLIP = {}; var NORMAL_CLIP = {};
var EO_CLIP = {}; var EO_CLIP = {};
CanvasGraphics.prototype = { CanvasGraphics.prototype = {
beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport, transparency) { beginDrawing: function beginDrawing(_ref) {
var transform = _ref.transform,
viewport = _ref.viewport,
transparency = _ref.transparency,
_ref$background = _ref.background,
background = _ref$background === undefined ? null : _ref$background;
var width = this.ctx.canvas.width; var width = this.ctx.canvas.width;
var height = this.ctx.canvas.height; var height = this.ctx.canvas.height;
this.ctx.save(); this.ctx.save();
this.ctx.fillStyle = 'rgb(255, 255, 255)'; this.ctx.fillStyle = background || 'rgb(255, 255, 255)';
this.ctx.fillRect(0, 0, width, height); this.ctx.fillRect(0, 0, width, height);
this.ctx.restore(); this.ctx.restore();
if (transparency) { if (transparency) {
@ -42004,6 +42015,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
this.imageLayer.beginLayout(); this.imageLayer.beginLayout();
} }
}, },
executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) { executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
var argsArray = operatorList.argsArray; var argsArray = operatorList.argsArray;
var fnArray = operatorList.fnArray; var fnArray = operatorList.fnArray;
@ -43816,8 +43828,8 @@ exports.TilingPattern = TilingPattern;
"use strict"; "use strict";
var pdfjsVersion = '1.8.357'; var pdfjsVersion = '1.8.359';
var pdfjsBuild = 'ca3cf6e7'; var pdfjsBuild = '5958dafd';
var pdfjsSharedUtil = __w_pdfjs_require__(0); var pdfjsSharedUtil = __w_pdfjs_require__(0);
var pdfjsDisplayGlobal = __w_pdfjs_require__(26); var pdfjsDisplayGlobal = __w_pdfjs_require__(26);
var pdfjsDisplayAPI = __w_pdfjs_require__(10); var pdfjsDisplayAPI = __w_pdfjs_require__(10);

2
build/pdf.combined.js.map

File diff suppressed because one or more lines are too long

30
build/pdf.js

@ -3449,7 +3449,12 @@ var InternalRenderTask = function InternalRenderTaskClosure() {
} }
var params = this.params; var params = this.params;
this.gfx = new _canvas.CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, this.canvasFactory, params.imageLayer); this.gfx = new _canvas.CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, this.canvasFactory, params.imageLayer);
this.gfx.beginDrawing(params.transform, params.viewport, transparency); this.gfx.beginDrawing({
transform: params.transform,
viewport: params.viewport,
transparency: transparency,
background: params.background
});
this.operatorListIdx = 0; this.operatorListIdx = 0;
this.graphicsReady = true; this.graphicsReady = true;
if (this.graphicsReadyCallback) { if (this.graphicsReadyCallback) {
@ -3530,8 +3535,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
}(); }();
var version, build; var version, build;
{ {
exports.version = version = '1.8.357'; exports.version = version = '1.8.359';
exports.build = build = 'ca3cf6e7'; exports.build = build = '5958dafd';
} }
exports.getDocument = getDocument; exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort; exports.LoopbackPort = LoopbackPort;
@ -5504,8 +5509,8 @@ if (!_util.globalScope.PDFJS) {
} }
var PDFJS = _util.globalScope.PDFJS; var PDFJS = _util.globalScope.PDFJS;
{ {
PDFJS.version = '1.8.357'; PDFJS.version = '1.8.359';
PDFJS.build = 'ca3cf6e7'; PDFJS.build = '5958dafd';
} }
PDFJS.pdfBug = false; PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) { if (PDFJS.verbosity !== undefined) {
@ -6163,11 +6168,17 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
var NORMAL_CLIP = {}; var NORMAL_CLIP = {};
var EO_CLIP = {}; var EO_CLIP = {};
CanvasGraphics.prototype = { CanvasGraphics.prototype = {
beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport, transparency) { beginDrawing: function beginDrawing(_ref) {
var transform = _ref.transform,
viewport = _ref.viewport,
transparency = _ref.transparency,
_ref$background = _ref.background,
background = _ref$background === undefined ? null : _ref$background;
var width = this.ctx.canvas.width; var width = this.ctx.canvas.width;
var height = this.ctx.canvas.height; var height = this.ctx.canvas.height;
this.ctx.save(); this.ctx.save();
this.ctx.fillStyle = 'rgb(255, 255, 255)'; this.ctx.fillStyle = background || 'rgb(255, 255, 255)';
this.ctx.fillRect(0, 0, width, height); this.ctx.fillRect(0, 0, width, height);
this.ctx.restore(); this.ctx.restore();
if (transparency) { if (transparency) {
@ -6188,6 +6199,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
this.imageLayer.beginLayout(); this.imageLayer.beginLayout();
} }
}, },
executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) { executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
var argsArray = operatorList.argsArray; var argsArray = operatorList.argsArray;
var fnArray = operatorList.fnArray; var fnArray = operatorList.fnArray;
@ -8000,8 +8012,8 @@ exports.TilingPattern = TilingPattern;
"use strict"; "use strict";
var pdfjsVersion = '1.8.357'; var pdfjsVersion = '1.8.359';
var pdfjsBuild = 'ca3cf6e7'; var pdfjsBuild = '5958dafd';
var pdfjsSharedUtil = __w_pdfjs_require__(0); var pdfjsSharedUtil = __w_pdfjs_require__(0);
var pdfjsDisplayGlobal = __w_pdfjs_require__(9); var pdfjsDisplayGlobal = __w_pdfjs_require__(9);
var pdfjsDisplayAPI = __w_pdfjs_require__(3); var pdfjsDisplayAPI = __w_pdfjs_require__(3);

2
build/pdf.js.map

File diff suppressed because one or more lines are too long

12
build/pdf.min.js vendored

File diff suppressed because one or more lines are too long

4
build/pdf.worker.js vendored

@ -37144,8 +37144,8 @@ exports.Type1Parser = Type1Parser;
"use strict"; "use strict";
var pdfjsVersion = '1.8.357'; var pdfjsVersion = '1.8.359';
var pdfjsBuild = 'ca3cf6e7'; var pdfjsBuild = '5958dafd';
var pdfjsCoreWorker = __w_pdfjs_require__(8); var pdfjsCoreWorker = __w_pdfjs_require__(8);
{ {
__w_pdfjs_require__(19); __w_pdfjs_require__(19);

2
build/pdf.worker.js.map vendored

File diff suppressed because one or more lines are too long

11
lib/display/api.js

@ -1332,7 +1332,12 @@ var InternalRenderTask = function InternalRenderTaskClosure() {
} }
var params = this.params; var params = this.params;
this.gfx = new _canvas.CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, this.canvasFactory, params.imageLayer); this.gfx = new _canvas.CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, this.canvasFactory, params.imageLayer);
this.gfx.beginDrawing(params.transform, params.viewport, transparency); this.gfx.beginDrawing({
transform: params.transform,
viewport: params.viewport,
transparency: transparency,
background: params.background
});
this.operatorListIdx = 0; this.operatorListIdx = 0;
this.graphicsReady = true; this.graphicsReady = true;
if (this.graphicsReadyCallback) { if (this.graphicsReadyCallback) {
@ -1413,8 +1418,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
}(); }();
var version, build; var version, build;
{ {
exports.version = version = '1.8.357'; exports.version = version = '1.8.359';
exports.build = build = 'ca3cf6e7'; exports.build = build = '5958dafd';
} }
exports.getDocument = getDocument; exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort; exports.LoopbackPort = LoopbackPort;

11
lib/display/canvas.js

@ -559,11 +559,17 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
var NORMAL_CLIP = {}; var NORMAL_CLIP = {};
var EO_CLIP = {}; var EO_CLIP = {};
CanvasGraphics.prototype = { CanvasGraphics.prototype = {
beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport, transparency) { beginDrawing: function beginDrawing(_ref) {
var transform = _ref.transform,
viewport = _ref.viewport,
transparency = _ref.transparency,
_ref$background = _ref.background,
background = _ref$background === undefined ? null : _ref$background;
var width = this.ctx.canvas.width; var width = this.ctx.canvas.width;
var height = this.ctx.canvas.height; var height = this.ctx.canvas.height;
this.ctx.save(); this.ctx.save();
this.ctx.fillStyle = 'rgb(255, 255, 255)'; this.ctx.fillStyle = background || 'rgb(255, 255, 255)';
this.ctx.fillRect(0, 0, width, height); this.ctx.fillRect(0, 0, width, height);
this.ctx.restore(); this.ctx.restore();
if (transparency) { if (transparency) {
@ -584,6 +590,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
this.imageLayer.beginLayout(); this.imageLayer.beginLayout();
} }
}, },
executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) { executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
var argsArray = operatorList.argsArray; var argsArray = operatorList.argsArray;
var fnArray = operatorList.fnArray; var fnArray = operatorList.fnArray;

4
lib/display/global.js

@ -39,8 +39,8 @@ if (!_util.globalScope.PDFJS) {
} }
var PDFJS = _util.globalScope.PDFJS; var PDFJS = _util.globalScope.PDFJS;
{ {
PDFJS.version = '1.8.357'; PDFJS.version = '1.8.359';
PDFJS.build = 'ca3cf6e7'; PDFJS.build = '5958dafd';
} }
PDFJS.pdfBug = false; PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) { if (PDFJS.verbosity !== undefined) {

4
lib/pdf.js

@ -14,8 +14,8 @@
*/ */
'use strict'; 'use strict';
var pdfjsVersion = '1.8.357'; var pdfjsVersion = '1.8.359';
var pdfjsBuild = 'ca3cf6e7'; var pdfjsBuild = '5958dafd';
var pdfjsSharedUtil = require('./shared/util.js'); var pdfjsSharedUtil = require('./shared/util.js');
var pdfjsDisplayGlobal = require('./display/global.js'); var pdfjsDisplayGlobal = require('./display/global.js');
var pdfjsDisplayAPI = require('./display/api.js'); var pdfjsDisplayAPI = require('./display/api.js');

4
lib/pdf.worker.js vendored

@ -14,8 +14,8 @@
*/ */
'use strict'; 'use strict';
var pdfjsVersion = '1.8.357'; var pdfjsVersion = '1.8.359';
var pdfjsBuild = 'ca3cf6e7'; var pdfjsBuild = '5958dafd';
var pdfjsCoreWorker = require('./core/worker.js'); var pdfjsCoreWorker = require('./core/worker.js');
{ {
require('./core/network.js'); require('./core/network.js');

84
lib/test/unit/api_spec.js

@ -16,36 +16,20 @@
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _test_utils = require('./test_utils');
var _util = require('../../shared/util'); var _util = require('../../shared/util');
var _dom_utils = require('../../display/dom_utils'); var _dom_utils = require('../../display/dom_utils');
var _api = require('../../display/api'); var _api = require('../../display/api');
var _test_utils = require('./test_utils');
var _global = require('../../display/global'); var _global = require('../../display/global');
var TEST_PDFS_PATH = {
dom: '../pdfs/',
node: './test/pdfs/'
};
function buildGetDocumentParams(filename, options) {
var params = Object.create(null);
if ((0, _util.isNodeJS)()) {
params.data = _test_utils.NodeFileReaderFactory.fetch({ path: TEST_PDFS_PATH.node + filename });
} else {
params.url = new URL(TEST_PDFS_PATH.dom + filename, window.location).href;
}
for (var option in options) {
params[option] = options[option];
}
return params;
}
describe('api', function () { describe('api', function () {
var basicApiFileName = 'basicapi.pdf'; var basicApiFileName = 'basicapi.pdf';
var basicApiFileLength = 105779; var basicApiFileLength = 105779;
var basicApiGetDocumentParams = buildGetDocumentParams(basicApiFileName); var basicApiGetDocumentParams = (0, _test_utils.buildGetDocumentParams)(basicApiFileName);
var CanvasFactory = void 0; var CanvasFactory = void 0;
beforeAll(function (done) { beforeAll(function (done) {
if ((0, _util.isNodeJS)()) { if ((0, _util.isNodeJS)()) {
@ -121,11 +105,11 @@ describe('api', function () {
it('creates pdf doc from typed array', function (done) { it('creates pdf doc from typed array', function (done) {
var typedArrayPdf; var typedArrayPdf;
if ((0, _util.isNodeJS)()) { if ((0, _util.isNodeJS)()) {
typedArrayPdf = _test_utils.NodeFileReaderFactory.fetch({ path: TEST_PDFS_PATH.node + basicApiFileName }); typedArrayPdf = _test_utils.NodeFileReaderFactory.fetch({ path: _test_utils.TEST_PDFS_PATH.node + basicApiFileName });
} else { } else {
var nonBinaryRequest = _global.PDFJS.disableWorker; var nonBinaryRequest = _global.PDFJS.disableWorker;
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.open('GET', TEST_PDFS_PATH.dom + basicApiFileName, false); request.open('GET', _test_utils.TEST_PDFS_PATH.dom + basicApiFileName, false);
if (!nonBinaryRequest) { if (!nonBinaryRequest) {
try { try {
request.responseType = 'arraybuffer'; request.responseType = 'arraybuffer';
@ -154,7 +138,7 @@ describe('api', function () {
}); });
}); });
it('creates pdf doc from invalid PDF file', function (done) { it('creates pdf doc from invalid PDF file', function (done) {
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('bug1020226.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug1020226.pdf'));
loadingTask.promise.then(function () { loadingTask.promise.then(function () {
done.fail('shall fail loading'); done.fail('shall fail loading');
}).catch(function (error) { }).catch(function (error) {
@ -166,7 +150,7 @@ describe('api', function () {
if ((0, _util.isNodeJS)()) { if ((0, _util.isNodeJS)()) {
pending('XMLHttpRequest is not supported in Node.js.'); pending('XMLHttpRequest is not supported in Node.js.');
} }
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('non-existent.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('non-existent.pdf'));
loadingTask.promise.then(function (error) { loadingTask.promise.then(function (error) {
done.fail('shall fail loading'); done.fail('shall fail loading');
}).catch(function (error) { }).catch(function (error) {
@ -175,7 +159,7 @@ describe('api', function () {
}); });
}); });
it('creates pdf doc from PDF file protected with user and owner password', function (done) { it('creates pdf doc from PDF file protected with user and owner password', function (done) {
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('pr6531_1.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('pr6531_1.pdf'));
var isPasswordNeededResolved = false; var isPasswordNeededResolved = false;
var passwordNeededCapability = (0, _util.createPromiseCapability)(); var passwordNeededCapability = (0, _util.createPromiseCapability)();
var isPasswordIncorrectResolved = false; var isPasswordIncorrectResolved = false;
@ -205,7 +189,7 @@ describe('api', function () {
}); });
it('creates pdf doc from PDF file protected with only a user password', function (done) { it('creates pdf doc from PDF file protected with only a user password', function (done) {
var filename = 'pr6531_2.pdf'; var filename = 'pr6531_2.pdf';
var passwordNeededLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: '' })); var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: '' }));
var result1 = passwordNeededLoadingTask.promise.then(function () { var result1 = passwordNeededLoadingTask.promise.then(function () {
done.fail('shall fail with no password'); done.fail('shall fail with no password');
return Promise.reject(new Error('loadingTask should be rejected')); return Promise.reject(new Error('loadingTask should be rejected'));
@ -214,7 +198,7 @@ describe('api', function () {
expect(data.code).toEqual(_util.PasswordResponses.NEED_PASSWORD); expect(data.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
return passwordNeededLoadingTask.destroy(); return passwordNeededLoadingTask.destroy();
}); });
var passwordIncorrectLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: 'qwerty' })); var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: 'qwerty' }));
var result2 = passwordIncorrectLoadingTask.promise.then(function () { var result2 = passwordIncorrectLoadingTask.promise.then(function () {
done.fail('shall fail with wrong password'); done.fail('shall fail with wrong password');
return Promise.reject(new Error('loadingTask should be rejected')); return Promise.reject(new Error('loadingTask should be rejected'));
@ -223,7 +207,7 @@ describe('api', function () {
expect(data.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD); expect(data.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
return passwordIncorrectLoadingTask.destroy(); return passwordIncorrectLoadingTask.destroy();
}); });
var passwordAcceptedLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: 'asdfasdf' })); var passwordAcceptedLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: 'asdfasdf' }));
var result3 = passwordAcceptedLoadingTask.promise.then(function (data) { var result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
expect(data instanceof _api.PDFDocumentProxy).toEqual(true); expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
return passwordAcceptedLoadingTask.destroy(); return passwordAcceptedLoadingTask.destroy();
@ -236,8 +220,8 @@ describe('api', function () {
}); });
it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) { it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) {
var filename = 'issue3371.pdf'; var filename = 'issue3371.pdf';
var passwordNeededLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename)); var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename));
var passwordIncorrectLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: 'qwerty' })); var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: 'qwerty' }));
var passwordNeededDestroyed = void 0; var passwordNeededDestroyed = void 0;
passwordNeededLoadingTask.onPassword = function (callback, reason) { passwordNeededLoadingTask.onPassword = function (callback, reason) {
if (reason === _util.PasswordResponses.NEED_PASSWORD) { if (reason === _util.PasswordResponses.NEED_PASSWORD) {
@ -317,7 +301,7 @@ describe('api', function () {
}); });
it('worker created and can be used in getDocument', function (done) { it('worker created and can be used in getDocument', function (done) {
var worker = new _global.PDFJS.PDFWorker('test1'); var worker = new _global.PDFJS.PDFWorker('test1');
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams(basicApiFileName, { worker: worker })); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, { worker: worker }));
loadingTask.promise.then(function () { loadingTask.promise.then(function () {
var docWorker = loadingTask._worker; var docWorker = loadingTask._worker;
expect(!!docWorker).toEqual(false); expect(!!docWorker).toEqual(false);
@ -469,7 +453,7 @@ describe('api', function () {
}); });
}); });
it('gets destinations, from /Names (NameTree) dictionary', function (done) { it('gets destinations, from /Names (NameTree) dictionary', function (done) {
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6204.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
var promise = loadingTask.promise.then(function (pdfDocument) { var promise = loadingTask.promise.then(function (pdfDocument) {
return pdfDocument.getDestinations(); return pdfDocument.getDestinations();
}); });
@ -490,7 +474,7 @@ describe('api', function () {
}); });
}); });
it('gets a destination, from /Names (NameTree) dictionary', function (done) { it('gets a destination, from /Names (NameTree) dictionary', function (done) {
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6204.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
var promise = loadingTask.promise.then(function (pdfDocument) { var promise = loadingTask.promise.then(function (pdfDocument) {
return pdfDocument.getDestination('Page.1'); return pdfDocument.getDestination('Page.1');
}); });
@ -505,7 +489,7 @@ describe('api', function () {
}); });
}); });
it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) { it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) {
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6204.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
var promise = loadingTask.promise.then(function (pdfDocument) { var promise = loadingTask.promise.then(function (pdfDocument) {
return pdfDocument.getDestination('non-existent-named-destination'); return pdfDocument.getDestination('non-existent-named-destination');
}); });
@ -526,19 +510,19 @@ describe('api', function () {
}); });
}); });
it('gets page labels', function (done) { it('gets page labels', function (done) {
var loadingTask0 = (0, _api.getDocument)(buildGetDocumentParams('bug793632.pdf')); var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug793632.pdf'));
var promise0 = loadingTask0.promise.then(function (pdfDoc) { var promise0 = loadingTask0.promise.then(function (pdfDoc) {
return pdfDoc.getPageLabels(); return pdfDoc.getPageLabels();
}); });
var loadingTask1 = (0, _api.getDocument)(buildGetDocumentParams('issue1453.pdf')); var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue1453.pdf'));
var promise1 = loadingTask1.promise.then(function (pdfDoc) { var promise1 = loadingTask1.promise.then(function (pdfDoc) {
return pdfDoc.getPageLabels(); return pdfDoc.getPageLabels();
}); });
var loadingTask2 = (0, _api.getDocument)(buildGetDocumentParams('rotation.pdf')); var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('rotation.pdf'));
var promise2 = loadingTask2.promise.then(function (pdfDoc) { var promise2 = loadingTask2.promise.then(function (pdfDoc) {
return pdfDoc.getPageLabels(); return pdfDoc.getPageLabels();
}); });
var loadingTask3 = (0, _api.getDocument)(buildGetDocumentParams('bad-PageLabels.pdf')); var loadingTask3 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bad-PageLabels.pdf'));
var promise3 = loadingTask3.promise.then(function (pdfDoc) { var promise3 = loadingTask3.promise.then(function (pdfDoc) {
return pdfDoc.getPageLabels(); return pdfDoc.getPageLabels();
}); });
@ -565,7 +549,7 @@ describe('api', function () {
if ((0, _util.isNodeJS)()) { if ((0, _util.isNodeJS)()) {
pending('TODO: Use a non-linked test-case.'); pending('TODO: Use a non-linked test-case.');
} }
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('bug766138.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug766138.pdf'));
var promise = loadingTask.promise.then(function (pdfDoc) { var promise = loadingTask.promise.then(function (pdfDoc) {
return pdfDoc.getAttachments(); return pdfDoc.getAttachments();
}); });
@ -590,7 +574,7 @@ describe('api', function () {
}); });
var viewerPrintRegExp = /\bprint\s*\(/; var viewerPrintRegExp = /\bprint\s*\(/;
it('gets javascript with printing instructions (Print action)', function (done) { it('gets javascript with printing instructions (Print action)', function (done) {
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('bug1001080.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug1001080.pdf'));
var promise = loadingTask.promise.then(function (doc) { var promise = loadingTask.promise.then(function (doc) {
return doc.getJavaScript(); return doc.getJavaScript();
}); });
@ -603,7 +587,7 @@ describe('api', function () {
}); });
}); });
it('gets javascript with printing instructions (JS action)', function (done) { it('gets javascript with printing instructions (JS action)', function (done) {
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6106.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6106.pdf'));
var promise = loadingTask.promise.then(function (doc) { var promise = loadingTask.promise.then(function (doc) {
return doc.getJavaScript(); return doc.getJavaScript();
}); });
@ -616,7 +600,7 @@ describe('api', function () {
}); });
}); });
it('gets non-existent outline', function (done) { it('gets non-existent outline', function (done) {
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('tracemonkey.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
var promise = loadingTask.promise.then(function (pdfDocument) { var promise = loadingTask.promise.then(function (pdfDocument) {
return pdfDocument.getOutline(); return pdfDocument.getOutline();
}); });
@ -649,7 +633,7 @@ describe('api', function () {
}); });
}); });
it('gets outline containing a url', function (done) { it('gets outline containing a url', function (done) {
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue3214.pdf')); var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue3214.pdf'));
loadingTask.promise.then(function (pdfDocument) { loadingTask.promise.then(function (pdfDocument) {
pdfDocument.getOutline().then(function (outline) { pdfDocument.getOutline().then(function (outline) {
expect(outline instanceof Array).toEqual(true); expect(outline instanceof Array).toEqual(true);
@ -716,8 +700,8 @@ describe('api', function () {
}); });
}); });
it('checks that fingerprints are unique', function (done) { it('checks that fingerprints are unique', function (done) {
var loadingTask1 = (0, _api.getDocument)(buildGetDocumentParams('issue4436r.pdf')); var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4436r.pdf'));
var loadingTask2 = (0, _api.getDocument)(buildGetDocumentParams('issue4575.pdf')); var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4575.pdf'));
var promises = [loadingTask1.promise, loadingTask2.promise]; var promises = [loadingTask1.promise, loadingTask2.promise];
Promise.all(promises).then(function (data) { Promise.all(promises).then(function (data) {
var fingerprint1 = data[0].fingerprint; var fingerprint1 = data[0].fingerprint;
@ -796,19 +780,19 @@ describe('api', function () {
}); });
it('gets annotations containing relative URLs (bug 766086)', function (done) { it('gets annotations containing relative URLs (bug 766086)', function (done) {
var filename = 'bug766086.pdf'; var filename = 'bug766086.pdf';
var defaultLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename)); var defaultLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename));
var defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) { var defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) {
return pdfDoc.getPage(1).then(function (pdfPage) { return pdfDoc.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations(); return pdfPage.getAnnotations();
}); });
}); });
var docBaseUrlLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf' })); var docBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf' }));
var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) { var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) {
return pdfDoc.getPage(1).then(function (pdfPage) { return pdfDoc.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations(); return pdfPage.getAnnotations();
}); });
}); });
var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { docBaseUrl: 'qwerty.pdf' })); var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { docBaseUrl: 'qwerty.pdf' }));
var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) { var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) {
return pdfDoc.getPage(1).then(function (pdfPage) { return pdfDoc.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations(); return pdfPage.getAnnotations();
@ -901,9 +885,9 @@ describe('api', function () {
if ((0, _util.isNodeJS)()) { if ((0, _util.isNodeJS)()) {
pending('TODO: Support Canvas testing in Node.js.'); pending('TODO: Support Canvas testing in Node.js.');
} }
var pdf1 = buildGetDocumentParams('tracemonkey.pdf'); var pdf1 = (0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf');
var pdf2 = buildGetDocumentParams('TAMReview.pdf'); var pdf2 = (0, _test_utils.buildGetDocumentParams)('TAMReview.pdf');
var pdf3 = buildGetDocumentParams('issue6068.pdf'); var pdf3 = (0, _test_utils.buildGetDocumentParams)('issue6068.pdf');
var loadingTasks = []; var loadingTasks = [];
var pdfDocuments = []; var pdfDocuments = [];
function renderPDF(filename) { function renderPDF(filename) {

115
lib/test/unit/custom_spec.js

@ -0,0 +1,115 @@
/* Copyright 2017 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
var _test_utils = require('./test_utils');
var _dom_utils = require('../../display/dom_utils');
var _api = require('../../display/api');
var _util = require('../../shared/util');
var _global = require('../../display/global');
function getTopLeftPixel(canvasContext) {
var imgData = canvasContext.getImageData(0, 0, 1, 1);
return {
r: imgData.data[0],
g: imgData.data[1],
b: imgData.data[2],
a: imgData.data[3]
};
}
describe('custom canvas rendering', function () {
var transparentGetDocumentParams = (0, _test_utils.buildGetDocumentParams)('transparent.pdf');
var CanvasFactory = void 0;
var loadingTask = void 0;
var page = void 0;
beforeAll(function (done) {
if ((0, _util.isNodeJS)()) {
_global.PDFJS.pdfjsNext = true;
} else {
CanvasFactory = new _dom_utils.DOMCanvasFactory();
}
loadingTask = (0, _api.getDocument)(transparentGetDocumentParams);
loadingTask.promise.then(function (doc) {
return doc.getPage(1);
}).then(function (data) {
page = data;
done();
}).catch(function (reason) {
done.fail(reason);
});
});
afterAll(function (done) {
CanvasFactory = null;
page = null;
loadingTask.destroy().then(done);
});
it('renders to canvas with a default white background', function (done) {
if ((0, _util.isNodeJS)()) {
pending('TODO: Support Canvas testing in Node.js.');
}
var viewport = page.getViewport(1);
var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
page.render({
canvasContext: canvasAndCtx.context,
viewport: viewport
}).then(function () {
var _getTopLeftPixel = getTopLeftPixel(canvasAndCtx.context),
r = _getTopLeftPixel.r,
g = _getTopLeftPixel.g,
b = _getTopLeftPixel.b,
a = _getTopLeftPixel.a;
CanvasFactory.destroy(canvasAndCtx);
expect(r).toEqual(255);
expect(g).toEqual(255);
expect(b).toEqual(255);
expect(a).toEqual(255);
done();
}).catch(function (reason) {
done(reason);
});
});
it('renders to canvas with a custom background', function (done) {
if ((0, _util.isNodeJS)()) {
pending('TODO: Support Canvas testing in Node.js.');
}
var viewport = page.getViewport(1);
var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
page.render({
canvasContext: canvasAndCtx.context,
viewport: viewport,
background: 'rgba(255,0,0,1.0)'
}).then(function () {
var _getTopLeftPixel2 = getTopLeftPixel(canvasAndCtx.context),
r = _getTopLeftPixel2.r,
g = _getTopLeftPixel2.g,
b = _getTopLeftPixel2.b,
a = _getTopLeftPixel2.a;
CanvasFactory.destroy(canvasAndCtx);
expect(r).toEqual(255);
expect(g).toEqual(0);
expect(b).toEqual(0);
expect(a).toEqual(255);
done();
}).catch(function (reason) {
done(reason);
});
});
});

2
lib/test/unit/jasmine-boot.js

@ -15,7 +15,7 @@
'use strict'; 'use strict';
function initializePDFJS(callback) { function initializePDFJS(callback) {
Promise.all(['pdfjs/display/global', 'pdfjs-test/unit/annotation_spec', 'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/bidi_spec', 'pdfjs-test/unit/cff_parser_spec', 'pdfjs-test/unit/cmap_spec', 'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/document_spec', 'pdfjs-test/unit/dom_utils_spec', 'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/fonts_spec', 'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec', 'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/ui_utils_spec', 'pdfjs-test/unit/unicode_spec', 'pdfjs-test/unit/util_spec'].map(function (moduleName) { Promise.all(['pdfjs/display/global', 'pdfjs-test/unit/annotation_spec', 'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/bidi_spec', 'pdfjs-test/unit/cff_parser_spec', 'pdfjs-test/unit/cmap_spec', 'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/document_spec', 'pdfjs-test/unit/dom_utils_spec', 'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/fonts_spec', 'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec', 'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/ui_utils_spec', 'pdfjs-test/unit/unicode_spec', 'pdfjs-test/unit/util_spec', 'pdfjs-test/unit/custom_spec'].map(function (moduleName) {
return SystemJS.import(moduleName); return SystemJS.import(moduleName);
})).then(function (modules) { })).then(function (modules) {
var displayGlobal = modules[0]; var displayGlobal = modules[0];

21
lib/test/unit/test_utils.js

@ -17,7 +17,7 @@
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.NodeCMapReaderFactory = exports.NodeFileReaderFactory = undefined; exports.TEST_PDFS_PATH = exports.buildGetDocumentParams = exports.NodeCMapReaderFactory = exports.NodeFileReaderFactory = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@ -42,6 +42,23 @@ var NodeFileReaderFactory = function () {
return NodeFileReaderFactory; return NodeFileReaderFactory;
}(); }();
var TEST_PDFS_PATH = {
dom: '../pdfs/',
node: './test/pdfs/'
};
function buildGetDocumentParams(filename, options) {
var params = Object.create(null);
if ((0, _util.isNodeJS)()) {
params.data = NodeFileReaderFactory.fetch({ path: TEST_PDFS_PATH.node + filename });
} else {
params.url = new URL(TEST_PDFS_PATH.dom + filename, window.location).href;
}
for (var option in options) {
params[option] = options[option];
}
return params;
}
var NodeCMapReaderFactory = function () { var NodeCMapReaderFactory = function () {
function NodeCMapReaderFactory(_ref) { function NodeCMapReaderFactory(_ref) {
var _ref$baseUrl = _ref.baseUrl, var _ref$baseUrl = _ref.baseUrl,
@ -87,3 +104,5 @@ var NodeCMapReaderFactory = function () {
exports.NodeFileReaderFactory = NodeFileReaderFactory; exports.NodeFileReaderFactory = NodeFileReaderFactory;
exports.NodeCMapReaderFactory = NodeCMapReaderFactory; exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
exports.buildGetDocumentParams = buildGetDocumentParams;
exports.TEST_PDFS_PATH = TEST_PDFS_PATH;

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.8.357", "version": "1.8.359",
"main": "build/pdf.js", "main": "build/pdf.js",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [

Loading…
Cancel
Save