pdfjs-dist 2.0.943 → 2.4.456

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (192) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8286 -14230
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +57878 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. package/lib/web/dom_events.js +0 -140
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2018 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,22 +19,18 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _test_utils = require('./test_utils');
24
+ var _test_utils = require("./test_utils.js");
25
25
 
26
- var _dom_utils = require('../../display/dom_utils');
26
+ var _display_utils = require("../../display/display_utils.js");
27
27
 
28
- var _api = require('../../display/api');
28
+ var _api = require("../../display/api.js");
29
29
 
30
- var _is_node = require('../../shared/is_node');
31
-
32
- var _is_node2 = _interopRequireDefault(_is_node);
33
-
34
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
+ var _is_node = require("../../shared/is_node.js");
35
31
 
36
32
  function getTopLeftPixel(canvasContext) {
37
- var imgData = canvasContext.getImageData(0, 0, 1, 1);
33
+ const imgData = canvasContext.getImageData(0, 0, 1, 1);
38
34
  return {
39
35
  r: imgData.data[0],
40
36
  g: imgData.data[1],
@@ -42,81 +38,71 @@ function getTopLeftPixel(canvasContext) {
42
38
  a: imgData.data[3]
43
39
  };
44
40
  }
45
- describe('custom canvas rendering', function () {
46
- var transparentGetDocumentParams = (0, _test_utils.buildGetDocumentParams)('transparent.pdf');
47
- var CanvasFactory = void 0;
48
- var loadingTask = void 0;
49
- var page = void 0;
41
+
42
+ describe("custom canvas rendering", function () {
43
+ const transparentGetDocumentParams = (0, _test_utils.buildGetDocumentParams)("transparent.pdf");
44
+ let CanvasFactory;
45
+ let loadingTask;
46
+ let page;
50
47
  beforeAll(function (done) {
51
- if ((0, _is_node2.default)()) {} else {
52
- CanvasFactory = new _dom_utils.DOMCanvasFactory();
48
+ if (_is_node.isNodeJS) {
49
+ CanvasFactory = new _test_utils.NodeCanvasFactory();
50
+ } else {
51
+ CanvasFactory = new _display_utils.DOMCanvasFactory();
53
52
  }
53
+
54
54
  loadingTask = (0, _api.getDocument)(transparentGetDocumentParams);
55
55
  loadingTask.promise.then(function (doc) {
56
56
  return doc.getPage(1);
57
57
  }).then(function (data) {
58
58
  page = data;
59
59
  done();
60
- }).catch(function (reason) {
61
- done.fail(reason);
62
- });
60
+ }).catch(done.fail);
63
61
  });
64
62
  afterAll(function (done) {
65
63
  CanvasFactory = null;
66
64
  page = null;
67
65
  loadingTask.destroy().then(done);
68
66
  });
69
- it('renders to canvas with a default white background', function (done) {
70
- if ((0, _is_node2.default)()) {
71
- pending('TODO: Support Canvas testing in Node.js.');
72
- }
73
- var viewport = page.getViewport(1);
67
+ it("renders to canvas with a default white background", function (done) {
68
+ var viewport = page.getViewport({
69
+ scale: 1
70
+ });
74
71
  var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
75
- page.render({
72
+ const renderTask = page.render({
76
73
  canvasContext: canvasAndCtx.context,
77
- viewport: viewport
78
- }).then(function () {
79
- var _getTopLeftPixel = getTopLeftPixel(canvasAndCtx.context),
80
- r = _getTopLeftPixel.r,
81
- g = _getTopLeftPixel.g,
82
- b = _getTopLeftPixel.b,
83
- a = _getTopLeftPixel.a;
84
-
74
+ viewport
75
+ });
76
+ renderTask.promise.then(function () {
77
+ expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({
78
+ r: 255,
79
+ g: 255,
80
+ b: 255,
81
+ a: 255
82
+ });
85
83
  CanvasFactory.destroy(canvasAndCtx);
86
- expect(r).toEqual(255);
87
- expect(g).toEqual(255);
88
- expect(b).toEqual(255);
89
- expect(a).toEqual(255);
90
84
  done();
91
- }).catch(function (reason) {
92
- done(reason);
93
- });
85
+ }).catch(done.fail);
94
86
  });
95
- it('renders to canvas with a custom background', function (done) {
96
- if ((0, _is_node2.default)()) {
97
- pending('TODO: Support Canvas testing in Node.js.');
98
- }
99
- var viewport = page.getViewport(1);
87
+ it("renders to canvas with a custom background", function (done) {
88
+ var viewport = page.getViewport({
89
+ scale: 1
90
+ });
100
91
  var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
101
- page.render({
92
+ const renderTask = page.render({
102
93
  canvasContext: canvasAndCtx.context,
103
- viewport: viewport,
104
- background: 'rgba(255,0,0,1.0)'
105
- }).then(function () {
106
- var _getTopLeftPixel2 = getTopLeftPixel(canvasAndCtx.context),
107
- r = _getTopLeftPixel2.r,
108
- g = _getTopLeftPixel2.g,
109
- b = _getTopLeftPixel2.b,
110
- a = _getTopLeftPixel2.a;
111
-
94
+ viewport,
95
+ background: "rgba(255,0,0,1.0)"
96
+ });
97
+ renderTask.promise.then(function () {
98
+ expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({
99
+ r: 255,
100
+ g: 0,
101
+ b: 0,
102
+ a: 255
103
+ });
112
104
  CanvasFactory.destroy(canvasAndCtx);
113
- expect(r).toEqual(255);
114
- expect(g).toEqual(0);
115
- expect(b).toEqual(0);
116
- expect(a).toEqual(255);
117
105
  done();
118
- }).catch(function (reason) {
119
- done(reason);
120
- });
106
+ }).catch(done.fail);
121
107
  });
122
108
  });
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2018 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,55 +19,62 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _domstubs = require('../../examples/node/domstubs');
24
+ var _domstubs = require("../../examples/node/domstubs.js");
25
25
 
26
- var _test_utils = require('./test_utils');
26
+ var _test_utils = require("./test_utils.js");
27
27
 
28
- var _api = require('../../display/api');
28
+ var _api = require("../../display/api.js");
29
29
 
30
- var _is_node = require('../../shared/is_node');
30
+ var _is_node = require("../../shared/is_node.js");
31
31
 
32
- var _is_node2 = _interopRequireDefault(_is_node);
32
+ var _util = require("../../shared/util.js");
33
33
 
34
- var _util = require('../../shared/util');
34
+ var _svg = require("../../display/svg.js");
35
35
 
36
- var _svg = require('../../display/svg');
36
+ const XLINK_NS = "http://www.w3.org/1999/xlink";
37
37
 
38
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
-
40
- var XLINK_NS = 'http://www.w3.org/1999/xlink';
41
38
  function withZlib(isZlibRequired, callback) {
42
39
  if (isZlibRequired) {
43
- if (!(0, _is_node2.default)()) {
44
- throw new Error('zlib test can only be run in Node.js');
40
+ if (!_is_node.isNodeJS) {
41
+ throw new Error("zlib test can only be run in Node.js");
45
42
  }
43
+
46
44
  return callback();
47
45
  }
48
- if (!(0, _is_node2.default)()) {
46
+
47
+ if (!_is_node.isNodeJS) {
49
48
  return callback();
50
49
  }
51
- var zlib = require('zlib');
50
+
51
+ var zlib = require("zlib");
52
+
52
53
  var deflateSync = zlib.deflateSync;
53
54
  zlib.deflateSync = disabledDeflateSync;
55
+
54
56
  function disabledDeflateSync() {
55
- throw new Error('zlib.deflateSync is explicitly disabled for testing.');
57
+ throw new Error("zlib.deflateSync is explicitly disabled for testing.");
56
58
  }
59
+
57
60
  function restoreDeflateSync() {
58
61
  if (zlib.deflateSync === disabledDeflateSync) {
59
62
  zlib.deflateSync = deflateSync;
60
63
  }
61
64
  }
65
+
62
66
  var promise = callback();
63
67
  promise.then(restoreDeflateSync, restoreDeflateSync);
64
68
  return promise;
65
69
  }
66
- describe('SVGGraphics', function () {
70
+
71
+ describe("SVGGraphics", function () {
67
72
  var loadingTask;
68
73
  var page;
69
74
  beforeAll(function (done) {
70
- loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('xobject-image.pdf', { nativeImageDecoderSupport: _util.NativeImageDecoding.DISPLAY }));
75
+ loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("xobject-image.pdf", {
76
+ nativeImageDecoderSupport: _util.NativeImageDecoding.DISPLAY
77
+ }));
71
78
  loadingTask.promise.then(function (doc) {
72
79
  doc.getPage(1).then(function (firstPage) {
73
80
  page = firstPage;
@@ -78,7 +85,7 @@ describe('SVGGraphics', function () {
78
85
  afterAll(function (done) {
79
86
  loadingTask.destroy().then(done);
80
87
  });
81
- describe('paintImageXObject', function () {
88
+ describe("paintImageXObject", function () {
82
89
  function getSVGImage() {
83
90
  var svgGfx;
84
91
  return page.getOperatorList().then(function (opList) {
@@ -88,55 +95,63 @@ describe('SVGGraphics', function () {
88
95
  }).then(function () {
89
96
  var svgImg;
90
97
  var elementContainer = {
91
- appendChild: function appendChild(element) {
98
+ appendChild(element) {
92
99
  svgImg = element;
93
100
  }
101
+
94
102
  };
95
- var xobjectObjId = 'img_p0_1';
96
- if ((0, _is_node2.default)()) {
103
+ var xobjectObjId = "img_p0_1";
104
+
105
+ if (_is_node.isNodeJS) {
97
106
  (0, _domstubs.setStubs)(global);
98
107
  }
108
+
99
109
  try {
100
110
  var imgData = svgGfx.objs.get(xobjectObjId);
101
111
  svgGfx.paintInlineImageXObject(imgData, elementContainer);
102
112
  } finally {
103
- if ((0, _is_node2.default)()) {
113
+ if (_is_node.isNodeJS) {
104
114
  (0, _domstubs.unsetStubs)(global);
105
115
  }
106
116
  }
117
+
107
118
  return svgImg;
108
119
  });
109
120
  }
121
+
110
122
  it('should fail require("zlib") unless in Node.js', function () {
111
123
  function testFunc() {
112
- require('zlib');
124
+ require("zlib");
113
125
  }
126
+
114
127
  expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
115
- if ((0, _is_node2.default)()) {
128
+
129
+ if (_is_node.isNodeJS) {
116
130
  expect(testFunc).not.toThrow();
117
131
  } else {
118
132
  expect(testFunc).toThrow();
119
133
  }
120
134
  });
121
- it('should produce a reasonably small svg:image', function (done) {
122
- if (!(0, _is_node2.default)()) {
123
- pending('zlib.deflateSync is not supported in non-Node environments.');
135
+ it("should produce a reasonably small svg:image", function (done) {
136
+ if (!_is_node.isNodeJS) {
137
+ pending("zlib.deflateSync is not supported in non-Node environments.");
124
138
  }
139
+
125
140
  withZlib(true, getSVGImage).then(function (svgImg) {
126
- expect(svgImg.nodeName).toBe('svg:image');
127
- expect(svgImg.getAttributeNS(null, 'width')).toBe('200px');
128
- expect(svgImg.getAttributeNS(null, 'height')).toBe('100px');
129
- var imgUrl = svgImg.getAttributeNS(XLINK_NS, 'href');
141
+ expect(svgImg.nodeName).toBe("svg:image");
142
+ expect(svgImg.getAttributeNS(null, "width")).toBe("200px");
143
+ expect(svgImg.getAttributeNS(null, "height")).toBe("100px");
144
+ var imgUrl = svgImg.getAttributeNS(XLINK_NS, "href");
130
145
  expect(imgUrl).toMatch(/^data:image\/png;base64,/);
131
146
  expect(imgUrl.length).toBeLessThan(367);
132
147
  }).then(done, done.fail);
133
148
  });
134
- it('should be able to produce a svg:image without zlib', function (done) {
149
+ it("should be able to produce a svg:image without zlib", function (done) {
135
150
  withZlib(false, getSVGImage).then(function (svgImg) {
136
- expect(svgImg.nodeName).toBe('svg:image');
137
- expect(svgImg.getAttributeNS(null, 'width')).toBe('200px');
138
- expect(svgImg.getAttributeNS(null, 'height')).toBe('100px');
139
- var imgUrl = svgImg.getAttributeNS(XLINK_NS, 'href');
151
+ expect(svgImg.nodeName).toBe("svg:image");
152
+ expect(svgImg.getAttributeNS(null, "width")).toBe("200px");
153
+ expect(svgImg.getAttributeNS(null, "height")).toBe("100px");
154
+ var imgUrl = svgImg.getAttributeNS(XLINK_NS, "href");
140
155
  expect(imgUrl).toMatch(/^data:image\/png;base64,/);
141
156
  expect(imgUrl.length).toBe(80246);
142
157
  }).then(done, done.fail);
@@ -0,0 +1,263 @@
1
+ /**
2
+ * @licstart The following is the entire license notice for the
3
+ * Javascript code in this page
4
+ *
5
+ * Copyright 2020 Mozilla Foundation
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * @licend The above is the entire license notice for the
20
+ * Javascript code in this page
21
+ */
22
+ "use strict";
23
+
24
+ var _display_utils = require("../../display/display_utils.js");
25
+
26
+ var _is_node = require("../../shared/is_node.js");
27
+
28
+ describe("display_utils", function () {
29
+ describe("DOMCanvasFactory", function () {
30
+ let canvasFactory;
31
+ beforeAll(function (done) {
32
+ canvasFactory = new _display_utils.DOMCanvasFactory();
33
+ done();
34
+ });
35
+ afterAll(function () {
36
+ canvasFactory = null;
37
+ });
38
+ it("`create` should throw an error if the dimensions are invalid", function () {
39
+ expect(function () {
40
+ return canvasFactory.create(-1, 1);
41
+ }).toThrow(new Error("Invalid canvas size"));
42
+ expect(function () {
43
+ return canvasFactory.create(1, -1);
44
+ }).toThrow(new Error("Invalid canvas size"));
45
+ });
46
+ it("`create` should return a canvas if the dimensions are valid", function () {
47
+ if (_is_node.isNodeJS) {
48
+ pending("Document is not supported in Node.js.");
49
+ }
50
+
51
+ const {
52
+ canvas,
53
+ context
54
+ } = canvasFactory.create(20, 40);
55
+ expect(canvas instanceof HTMLCanvasElement).toBe(true);
56
+ expect(context instanceof CanvasRenderingContext2D).toBe(true);
57
+ expect(canvas.width).toBe(20);
58
+ expect(canvas.height).toBe(40);
59
+ });
60
+ it("`reset` should throw an error if no canvas is provided", function () {
61
+ const canvasAndContext = {
62
+ canvas: null,
63
+ context: null
64
+ };
65
+ expect(function () {
66
+ return canvasFactory.reset(canvasAndContext, 20, 40);
67
+ }).toThrow(new Error("Canvas is not specified"));
68
+ });
69
+ it("`reset` should throw an error if the dimensions are invalid", function () {
70
+ const canvasAndContext = {
71
+ canvas: "foo",
72
+ context: "bar"
73
+ };
74
+ expect(function () {
75
+ return canvasFactory.reset(canvasAndContext, -1, 1);
76
+ }).toThrow(new Error("Invalid canvas size"));
77
+ expect(function () {
78
+ return canvasFactory.reset(canvasAndContext, 1, -1);
79
+ }).toThrow(new Error("Invalid canvas size"));
80
+ });
81
+ it("`reset` should alter the canvas/context if the dimensions are valid", function () {
82
+ if (_is_node.isNodeJS) {
83
+ pending("Document is not supported in Node.js.");
84
+ }
85
+
86
+ const canvasAndContext = canvasFactory.create(20, 40);
87
+ canvasFactory.reset(canvasAndContext, 60, 80);
88
+ const {
89
+ canvas,
90
+ context
91
+ } = canvasAndContext;
92
+ expect(canvas instanceof HTMLCanvasElement).toBe(true);
93
+ expect(context instanceof CanvasRenderingContext2D).toBe(true);
94
+ expect(canvas.width).toBe(60);
95
+ expect(canvas.height).toBe(80);
96
+ });
97
+ it("`destroy` should throw an error if no canvas is provided", function () {
98
+ expect(function () {
99
+ return canvasFactory.destroy({});
100
+ }).toThrow(new Error("Canvas is not specified"));
101
+ });
102
+ it("`destroy` should clear the canvas/context", function () {
103
+ if (_is_node.isNodeJS) {
104
+ pending("Document is not supported in Node.js.");
105
+ }
106
+
107
+ const canvasAndContext = canvasFactory.create(20, 40);
108
+ canvasFactory.destroy(canvasAndContext);
109
+ const {
110
+ canvas,
111
+ context
112
+ } = canvasAndContext;
113
+ expect(canvas).toBe(null);
114
+ expect(context).toBe(null);
115
+ });
116
+ });
117
+ describe("DOMSVGFactory", function () {
118
+ let svgFactory;
119
+ beforeAll(function (done) {
120
+ svgFactory = new _display_utils.DOMSVGFactory();
121
+ done();
122
+ });
123
+ afterAll(function () {
124
+ svgFactory = null;
125
+ });
126
+ it("`create` should throw an error if the dimensions are invalid", function () {
127
+ expect(function () {
128
+ return svgFactory.create(-1, 0);
129
+ }).toThrow(new Error("Invalid SVG dimensions"));
130
+ expect(function () {
131
+ return svgFactory.create(0, -1);
132
+ }).toThrow(new Error("Invalid SVG dimensions"));
133
+ });
134
+ it("`create` should return an SVG element if the dimensions are valid", function () {
135
+ if (_is_node.isNodeJS) {
136
+ pending("Document is not supported in Node.js.");
137
+ }
138
+
139
+ const svg = svgFactory.create(20, 40);
140
+ expect(svg instanceof SVGSVGElement).toBe(true);
141
+ expect(svg.getAttribute("version")).toBe("1.1");
142
+ expect(svg.getAttribute("width")).toBe("20px");
143
+ expect(svg.getAttribute("height")).toBe("40px");
144
+ expect(svg.getAttribute("preserveAspectRatio")).toBe("none");
145
+ expect(svg.getAttribute("viewBox")).toBe("0 0 20 40");
146
+ });
147
+ it("`createElement` should throw an error if the type is not a string", function () {
148
+ expect(function () {
149
+ return svgFactory.createElement(true);
150
+ }).toThrow(new Error("Invalid SVG element type"));
151
+ });
152
+ it("`createElement` should return an SVG element if the type is valid", function () {
153
+ if (_is_node.isNodeJS) {
154
+ pending("Document is not supported in Node.js.");
155
+ }
156
+
157
+ const svg = svgFactory.createElement("svg:rect");
158
+ expect(svg instanceof SVGRectElement).toBe(true);
159
+ });
160
+ });
161
+ describe("getFilenameFromUrl", function () {
162
+ it("should get the filename from an absolute URL", function () {
163
+ const url = "https://server.org/filename.pdf";
164
+ expect((0, _display_utils.getFilenameFromUrl)(url)).toEqual("filename.pdf");
165
+ });
166
+ it("should get the filename from a relative URL", function () {
167
+ const url = "../../filename.pdf";
168
+ expect((0, _display_utils.getFilenameFromUrl)(url)).toEqual("filename.pdf");
169
+ });
170
+ it("should get the filename from a URL with an anchor", function () {
171
+ const url = "https://server.org/filename.pdf#foo";
172
+ expect((0, _display_utils.getFilenameFromUrl)(url)).toEqual("filename.pdf");
173
+ });
174
+ it("should get the filename from a URL with query parameters", function () {
175
+ const url = "https://server.org/filename.pdf?foo=bar";
176
+ expect((0, _display_utils.getFilenameFromUrl)(url)).toEqual("filename.pdf");
177
+ });
178
+ });
179
+ describe("isValidFetchUrl", function () {
180
+ it("handles invalid Fetch URLs", function () {
181
+ expect((0, _display_utils.isValidFetchUrl)(null)).toEqual(false);
182
+ expect((0, _display_utils.isValidFetchUrl)(100)).toEqual(false);
183
+ expect((0, _display_utils.isValidFetchUrl)("foo")).toEqual(false);
184
+ expect((0, _display_utils.isValidFetchUrl)("/foo", 100)).toEqual(false);
185
+ });
186
+ it("handles relative Fetch URLs", function () {
187
+ expect((0, _display_utils.isValidFetchUrl)("/foo", "file://www.example.com")).toEqual(false);
188
+ expect((0, _display_utils.isValidFetchUrl)("/foo", "http://www.example.com")).toEqual(true);
189
+ });
190
+ it("handles unsupported Fetch protocols", function () {
191
+ expect((0, _display_utils.isValidFetchUrl)("file://www.example.com")).toEqual(false);
192
+ expect((0, _display_utils.isValidFetchUrl)("ftp://www.example.com")).toEqual(false);
193
+ });
194
+ it("handles supported Fetch protocols", function () {
195
+ expect((0, _display_utils.isValidFetchUrl)("http://www.example.com")).toEqual(true);
196
+ expect((0, _display_utils.isValidFetchUrl)("https://www.example.com")).toEqual(true);
197
+ });
198
+ });
199
+ describe("PDFDateString", function () {
200
+ describe("toDateObject", function () {
201
+ it("converts PDF date strings to JavaScript `Date` objects", function () {
202
+ const expectations = {
203
+ undefined: null,
204
+ null: null,
205
+ 42: null,
206
+ "2019": null,
207
+ D2019: null,
208
+ "D:": null,
209
+ "D:201": null,
210
+ "D:2019": new Date(Date.UTC(2019, 0, 1, 0, 0, 0)),
211
+ "D:20190": new Date(Date.UTC(2019, 0, 1, 0, 0, 0)),
212
+ "D:201900": new Date(Date.UTC(2019, 0, 1, 0, 0, 0)),
213
+ "D:201913": new Date(Date.UTC(2019, 0, 1, 0, 0, 0)),
214
+ "D:201902": new Date(Date.UTC(2019, 1, 1, 0, 0, 0)),
215
+ "D:2019020": new Date(Date.UTC(2019, 1, 1, 0, 0, 0)),
216
+ "D:20190200": new Date(Date.UTC(2019, 1, 1, 0, 0, 0)),
217
+ "D:20190232": new Date(Date.UTC(2019, 1, 1, 0, 0, 0)),
218
+ "D:20190203": new Date(Date.UTC(2019, 1, 3, 0, 0, 0)),
219
+ "D:20190431": new Date(Date.UTC(2019, 4, 1, 0, 0, 0)),
220
+ "D:201902030": new Date(Date.UTC(2019, 1, 3, 0, 0, 0)),
221
+ "D:2019020300": new Date(Date.UTC(2019, 1, 3, 0, 0, 0)),
222
+ "D:2019020324": new Date(Date.UTC(2019, 1, 3, 0, 0, 0)),
223
+ "D:2019020304": new Date(Date.UTC(2019, 1, 3, 4, 0, 0)),
224
+ "D:20190203040": new Date(Date.UTC(2019, 1, 3, 4, 0, 0)),
225
+ "D:201902030400": new Date(Date.UTC(2019, 1, 3, 4, 0, 0)),
226
+ "D:201902030460": new Date(Date.UTC(2019, 1, 3, 4, 0, 0)),
227
+ "D:201902030405": new Date(Date.UTC(2019, 1, 3, 4, 5, 0)),
228
+ "D:2019020304050": new Date(Date.UTC(2019, 1, 3, 4, 5, 0)),
229
+ "D:20190203040500": new Date(Date.UTC(2019, 1, 3, 4, 5, 0)),
230
+ "D:20190203040560": new Date(Date.UTC(2019, 1, 3, 4, 5, 0)),
231
+ "D:20190203040506": new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
232
+ "D:20190203040506F": new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
233
+ "D:20190203040506Z": new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
234
+ "D:20190203040506-": new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
235
+ "D:20190203040506+": new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
236
+ "D:20190203040506+'": new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
237
+ "D:20190203040506+0": new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
238
+ "D:20190203040506+01": new Date(Date.UTC(2019, 1, 3, 3, 5, 6)),
239
+ "D:20190203040506+00'": new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
240
+ "D:20190203040506+24'": new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
241
+ "D:20190203040506+01'": new Date(Date.UTC(2019, 1, 3, 3, 5, 6)),
242
+ "D:20190203040506+01'0": new Date(Date.UTC(2019, 1, 3, 3, 5, 6)),
243
+ "D:20190203040506+01'00": new Date(Date.UTC(2019, 1, 3, 3, 5, 6)),
244
+ "D:20190203040506+01'60": new Date(Date.UTC(2019, 1, 3, 3, 5, 6)),
245
+ "D:20190203040506+0102": new Date(Date.UTC(2019, 1, 3, 3, 3, 6)),
246
+ "D:20190203040506+01'02": new Date(Date.UTC(2019, 1, 3, 3, 3, 6)),
247
+ "D:20190203040506+01'02'": new Date(Date.UTC(2019, 1, 3, 3, 3, 6)),
248
+ "D:20190203040506+05'07": new Date(Date.UTC(2019, 1, 2, 22, 58, 6))
249
+ };
250
+
251
+ for (const [input, expectation] of Object.entries(expectations)) {
252
+ const result = _display_utils.PDFDateString.toDateObject(input);
253
+
254
+ if (result) {
255
+ expect(result.getTime()).toEqual(expectation.getTime());
256
+ } else {
257
+ expect(result).toEqual(expectation);
258
+ }
259
+ }
260
+ });
261
+ });
262
+ });
263
+ });
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2018 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,29 +19,24 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _document = require('../../core/document');
24
+ var _test_utils = require("./test_utils.js");
25
25
 
26
- describe('document', function () {
27
- describe('Page', function () {
28
- it('should create correct objId using the idFactory', function () {
29
- var page1 = new _document.Page({
30
- pdfManager: {},
31
- pageIndex: 0
32
- });
33
- var page2 = new _document.Page({
34
- pdfManager: {},
35
- pageIndex: 1
36
- });
37
- var idFactory1 = page1.idFactory,
38
- idFactory2 = page2.idFactory;
39
- expect(idFactory1.createObjId()).toEqual('p0_1');
40
- expect(idFactory1.createObjId()).toEqual('p0_2');
41
- expect(idFactory2.createObjId()).toEqual('p1_1');
42
- expect(idFactory2.createObjId()).toEqual('p1_2');
43
- expect(idFactory1.createObjId()).toEqual('p0_3');
44
- expect(idFactory1.createObjId()).toEqual('p0_4');
26
+ describe("document", function () {
27
+ describe("Page", function () {
28
+ it("should create correct objId using the idFactory", function () {
29
+ const idFactory1 = (0, _test_utils.createIdFactory)(0);
30
+ const idFactory2 = (0, _test_utils.createIdFactory)(1);
31
+ expect(idFactory1.createObjId()).toEqual("p0_1");
32
+ expect(idFactory1.createObjId()).toEqual("p0_2");
33
+ expect(idFactory1.getDocId()).toEqual("g_d0");
34
+ expect(idFactory2.createObjId()).toEqual("p1_1");
35
+ expect(idFactory2.createObjId()).toEqual("p1_2");
36
+ expect(idFactory2.getDocId()).toEqual("g_d0");
37
+ expect(idFactory1.createObjId()).toEqual("p0_3");
38
+ expect(idFactory1.createObjId()).toEqual("p0_4");
39
+ expect(idFactory1.getDocId()).toEqual("g_d0");
45
40
  });
46
41
  });
47
42
  });