pdfjs-dist 2.2.228 → 2.6.347

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 (229) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +8816 -19300
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +27185 -35746
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +26665 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/es5/build/pdf.min.js +22 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +61231 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/build/pdf.worker.min.js +22 -0
  17. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  18. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  19. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  20. package/es5/web/images/annotation-check.svg +11 -0
  21. package/es5/web/images/annotation-comment.svg +16 -0
  22. package/es5/web/images/annotation-help.svg +26 -0
  23. package/es5/web/images/annotation-insert.svg +10 -0
  24. package/es5/web/images/annotation-key.svg +11 -0
  25. package/es5/web/images/annotation-newparagraph.svg +11 -0
  26. package/es5/web/images/annotation-noicon.svg +7 -0
  27. package/es5/web/images/annotation-note.svg +42 -0
  28. package/es5/web/images/annotation-paragraph.svg +16 -0
  29. package/es5/web/images/loading-icon.gif +0 -0
  30. package/es5/web/images/shadow.png +0 -0
  31. package/es5/web/pdf_viewer.css +406 -0
  32. package/es5/web/pdf_viewer.js +7886 -0
  33. package/es5/web/pdf_viewer.js.map +1 -0
  34. package/image_decoders/pdf.image_decoders.js +1498 -4832
  35. package/image_decoders/pdf.image_decoders.js.map +1 -1
  36. package/image_decoders/pdf.image_decoders.min.js +22 -1
  37. package/lib/README.md +7 -0
  38. package/lib/core/annotation.js +1144 -927
  39. package/lib/core/arithmetic_decoder.js +81 -97
  40. package/lib/core/bidi.js +54 -46
  41. package/lib/core/ccitt.js +88 -81
  42. package/lib/core/ccitt_stream.js +15 -14
  43. package/lib/core/cff_parser.js +747 -716
  44. package/lib/core/charsets.js +4 -4
  45. package/lib/core/chunked_stream.js +462 -553
  46. package/lib/core/cmap.js +231 -277
  47. package/lib/core/colorspace.js +715 -857
  48. package/lib/core/core_utils.js +57 -52
  49. package/lib/core/crypto.js +416 -437
  50. package/lib/core/document.js +629 -670
  51. package/lib/core/encodings.js +15 -15
  52. package/lib/core/evaluator.js +3229 -2800
  53. package/lib/core/font_renderer.js +135 -178
  54. package/lib/core/fonts.js +602 -534
  55. package/lib/core/function.js +355 -279
  56. package/lib/core/glyphlist.js +4527 -4526
  57. package/lib/core/image.js +442 -439
  58. package/lib/core/image_utils.js +221 -61
  59. package/lib/core/jbig2.js +325 -316
  60. package/lib/core/jbig2_stream.js +18 -17
  61. package/lib/core/jpeg_stream.js +21 -26
  62. package/lib/core/jpg.js +289 -233
  63. package/lib/core/jpx.js +161 -143
  64. package/lib/core/jpx_stream.js +28 -28
  65. package/lib/core/metrics.js +2928 -2928
  66. package/lib/core/murmurhash3.js +87 -102
  67. package/lib/core/obj.js +1343 -1300
  68. package/lib/core/operator_list.js +90 -67
  69. package/lib/core/parser.js +990 -987
  70. package/lib/core/pattern.js +105 -77
  71. package/lib/core/pdf_manager.js +149 -316
  72. package/lib/core/primitives.js +156 -104
  73. package/lib/core/ps_parser.js +175 -214
  74. package/lib/core/standard_fonts.js +237 -236
  75. package/lib/core/stream.js +94 -74
  76. package/lib/core/type1_parser.js +89 -69
  77. package/lib/core/unicode.js +1654 -1654
  78. package/lib/core/worker.js +275 -290
  79. package/lib/core/worker_stream.js +101 -210
  80. package/lib/core/writer.js +242 -0
  81. package/lib/display/annotation_layer.js +772 -1041
  82. package/lib/display/annotation_storage.js +89 -0
  83. package/lib/display/api.js +1575 -1868
  84. package/lib/display/api_compatibility.js +12 -17
  85. package/lib/display/canvas.js +370 -222
  86. package/lib/display/content_disposition.js +40 -59
  87. package/lib/display/display_utils.js +341 -536
  88. package/lib/display/fetch_stream.js +188 -304
  89. package/lib/display/font_loader.js +282 -414
  90. package/lib/display/metadata.js +81 -99
  91. package/lib/display/network.js +362 -511
  92. package/lib/display/network_utils.js +25 -18
  93. package/lib/display/node_stream.js +283 -465
  94. package/lib/display/node_utils.js +87 -0
  95. package/lib/display/optional_content_config.js +184 -0
  96. package/lib/display/pattern_helper.js +93 -44
  97. package/lib/display/svg.js +1163 -1401
  98. package/lib/display/text_layer.js +154 -137
  99. package/lib/display/transport_stream.js +237 -375
  100. package/lib/display/webgl.js +70 -83
  101. package/lib/display/worker_options.js +3 -3
  102. package/lib/display/xml_parser.js +303 -392
  103. package/lib/examples/node/domstubs.js +37 -37
  104. package/lib/pdf.js +220 -58
  105. package/lib/pdf.worker.js +14 -6
  106. package/lib/shared/compatibility.js +3 -246
  107. package/lib/shared/is_node.js +7 -6
  108. package/lib/shared/message_handler.js +327 -332
  109. package/lib/shared/util.js +271 -306
  110. package/lib/test/unit/annotation_spec.js +1902 -763
  111. package/lib/test/unit/annotation_storage_spec.js +83 -0
  112. package/lib/test/unit/api_spec.js +790 -592
  113. package/lib/test/unit/bidi_spec.js +7 -7
  114. package/lib/test/unit/cff_parser_spec.js +73 -72
  115. package/lib/test/unit/clitests_helper.js +7 -9
  116. package/lib/test/unit/cmap_spec.js +86 -88
  117. package/lib/test/unit/colorspace_spec.js +346 -154
  118. package/lib/test/unit/core_utils_spec.js +125 -105
  119. package/lib/test/unit/crypto_spec.js +232 -185
  120. package/lib/test/unit/custom_spec.js +150 -24
  121. package/lib/test/unit/display_svg_spec.js +34 -39
  122. package/lib/test/unit/display_utils_spec.js +139 -149
  123. package/lib/test/unit/document_spec.js +128 -17
  124. package/lib/test/unit/encodings_spec.js +12 -34
  125. package/lib/test/unit/evaluator_spec.js +112 -91
  126. package/lib/test/unit/fetch_stream_spec.js +31 -29
  127. package/lib/test/unit/function_spec.js +206 -204
  128. package/lib/test/unit/jasmine-boot.js +48 -32
  129. package/lib/test/unit/message_handler_spec.js +173 -159
  130. package/lib/test/unit/metadata_spec.js +71 -71
  131. package/lib/test/unit/murmurhash3_spec.js +12 -12
  132. package/lib/test/unit/network_spec.js +13 -11
  133. package/lib/test/unit/network_utils_spec.js +158 -144
  134. package/lib/test/unit/node_stream_spec.js +76 -90
  135. package/lib/test/unit/parser_spec.js +108 -114
  136. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  137. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  138. package/lib/test/unit/pdf_history_spec.js +32 -32
  139. package/lib/test/unit/primitives_spec.js +337 -156
  140. package/lib/test/unit/stream_spec.js +16 -14
  141. package/lib/test/unit/test_utils.js +91 -304
  142. package/lib/test/unit/testreporter.js +33 -22
  143. package/lib/test/unit/type1_parser_spec.js +42 -42
  144. package/lib/test/unit/ui_utils_spec.js +299 -461
  145. package/lib/test/unit/unicode_spec.js +42 -42
  146. package/lib/test/unit/util_spec.js +129 -149
  147. package/lib/test/unit/writer_spec.js +84 -0
  148. package/lib/web/annotation_layer_builder.js +78 -111
  149. package/lib/web/app.js +1542 -1267
  150. package/lib/web/app_options.js +76 -91
  151. package/lib/web/base_tree_viewer.js +100 -0
  152. package/lib/web/base_viewer.js +869 -834
  153. package/lib/web/chromecom.js +165 -252
  154. package/lib/web/debugger.js +149 -205
  155. package/lib/web/download_manager.js +34 -58
  156. package/lib/web/firefox_print_service.js +62 -34
  157. package/lib/web/firefoxcom.js +206 -374
  158. package/lib/web/genericcom.js +26 -108
  159. package/lib/web/genericl10n.js +24 -153
  160. package/lib/web/grab_to_pan.js +30 -30
  161. package/lib/web/interfaces.js +80 -254
  162. package/lib/web/overlay_manager.js +70 -246
  163. package/lib/web/password_prompt.js +38 -64
  164. package/lib/web/pdf_attachment_viewer.js +150 -126
  165. package/lib/web/pdf_cursor_tools.js +75 -102
  166. package/lib/web/pdf_document_properties.js +229 -383
  167. package/lib/web/pdf_find_bar.js +136 -170
  168. package/lib/web/pdf_find_controller.js +492 -548
  169. package/lib/web/pdf_find_utils.js +13 -13
  170. package/lib/web/pdf_history.js +397 -406
  171. package/lib/web/pdf_layer_viewer.js +208 -0
  172. package/lib/web/pdf_link_service.js +304 -348
  173. package/lib/web/pdf_outline_viewer.js +119 -212
  174. package/lib/web/pdf_page_view.js +474 -513
  175. package/lib/web/pdf_presentation_mode.js +308 -357
  176. package/lib/web/pdf_print_service.js +96 -110
  177. package/lib/web/pdf_rendering_queue.js +87 -108
  178. package/lib/web/pdf_sidebar.js +286 -302
  179. package/lib/web/pdf_sidebar_resizer.js +92 -119
  180. package/lib/web/pdf_single_page_viewer.js +77 -126
  181. package/lib/web/pdf_thumbnail_view.js +289 -297
  182. package/lib/web/pdf_thumbnail_viewer.js +202 -206
  183. package/lib/web/pdf_viewer.component.js +20 -21
  184. package/lib/web/pdf_viewer.js +55 -115
  185. package/lib/web/preferences.js +69 -273
  186. package/lib/web/secondary_toolbar.js +164 -196
  187. package/lib/web/text_layer_builder.js +284 -319
  188. package/lib/web/toolbar.js +217 -210
  189. package/lib/web/ui_utils.js +274 -421
  190. package/lib/web/view_history.js +52 -226
  191. package/lib/web/viewer_compatibility.js +21 -6
  192. package/package.json +4 -9
  193. package/types/display/annotation_layer.d.ts +61 -0
  194. package/types/display/annotation_storage.d.ts +36 -0
  195. package/types/display/api.d.ts +1107 -0
  196. package/types/display/api_compatibility.d.ts +1 -0
  197. package/types/display/canvas.d.ts +4 -0
  198. package/types/display/content_disposition.d.ts +7 -0
  199. package/types/display/display_utils.d.ts +243 -0
  200. package/types/display/fetch_stream.d.ts +67 -0
  201. package/types/display/font_loader.d.ts +19 -0
  202. package/types/display/metadata.d.ts +9 -0
  203. package/types/display/network.d.ts +80 -0
  204. package/types/display/network_utils.d.ts +14 -0
  205. package/types/display/node_stream.d.ts +72 -0
  206. package/types/display/node_utils.d.ts +6 -0
  207. package/types/display/optional_content_config.d.ts +12 -0
  208. package/types/display/pattern_helper.d.ts +5 -0
  209. package/types/display/svg.d.ts +2 -0
  210. package/types/display/text_layer.d.ts +83 -0
  211. package/types/display/transport_stream.d.ts +57 -0
  212. package/types/display/webgl.d.ts +20 -0
  213. package/types/display/worker_options.d.ts +27 -0
  214. package/types/display/xml_parser.d.ts +35 -0
  215. package/types/pdf.d.ts +33 -0
  216. package/types/shared/compatibility.d.ts +1 -0
  217. package/types/shared/is_node.d.ts +1 -0
  218. package/types/shared/message_handler.d.ts +62 -0
  219. package/types/shared/util.d.ts +421 -0
  220. package/web/images/shadow.png +0 -0
  221. package/web/pdf_viewer.css +29 -27
  222. package/web/pdf_viewer.js +3524 -4746
  223. package/web/pdf_viewer.js.map +1 -1
  224. package/webpack.js +6 -5
  225. package/external/streams/streams-lib.js +0 -3962
  226. package/external/url/url-lib.js +0 -627
  227. package/lib/shared/streams_polyfill.js +0 -43
  228. package/lib/shared/url_polyfill.js +0 -56
  229. package/web/images/texture.png +0 -0
@@ -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 2019 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.
@@ -21,311 +21,492 @@
21
21
  */
22
22
  "use strict";
23
23
 
24
- var _primitives = require("../../core/primitives");
24
+ var _primitives = require("../../core/primitives.js");
25
25
 
26
- var _test_utils = require("./test_utils");
26
+ var _stream = require("../../core/stream.js");
27
27
 
28
- describe('primitives', function () {
29
- describe('Name', function () {
30
- it('should retain the given name', function () {
31
- var givenName = 'Font';
28
+ var _test_utils = require("./test_utils.js");
32
29
 
33
- var name = _primitives.Name.get(givenName);
30
+ describe("primitives", function () {
31
+ describe("Name", function () {
32
+ it("should retain the given name", function () {
33
+ const givenName = "Font";
34
+
35
+ const name = _primitives.Name.get(givenName);
34
36
 
35
37
  expect(name.name).toEqual(givenName);
36
38
  });
37
- it('should create only one object for a name and cache it', function () {
38
- var firstFont = _primitives.Name.get('Font');
39
+ it("should create only one object for a name and cache it", function () {
40
+ const firstFont = _primitives.Name.get("Font");
39
41
 
40
- var secondFont = _primitives.Name.get('Font');
42
+ const secondFont = _primitives.Name.get("Font");
41
43
 
42
- var firstSubtype = _primitives.Name.get('Subtype');
44
+ const firstSubtype = _primitives.Name.get("Subtype");
43
45
 
44
- var secondSubtype = _primitives.Name.get('Subtype');
46
+ const secondSubtype = _primitives.Name.get("Subtype");
45
47
 
46
48
  expect(firstFont).toBe(secondFont);
47
49
  expect(firstSubtype).toBe(secondSubtype);
48
50
  expect(firstFont).not.toBe(firstSubtype);
49
51
  });
50
52
  });
51
- describe('Cmd', function () {
52
- it('should retain the given cmd name', function () {
53
- var givenCmd = 'BT';
53
+ describe("Cmd", function () {
54
+ it("should retain the given cmd name", function () {
55
+ const givenCmd = "BT";
54
56
 
55
- var cmd = _primitives.Cmd.get(givenCmd);
57
+ const cmd = _primitives.Cmd.get(givenCmd);
56
58
 
57
59
  expect(cmd.cmd).toEqual(givenCmd);
58
60
  });
59
- it('should create only one object for a command and cache it', function () {
60
- var firstBT = _primitives.Cmd.get('BT');
61
+ it("should create only one object for a command and cache it", function () {
62
+ const firstBT = _primitives.Cmd.get("BT");
61
63
 
62
- var secondBT = _primitives.Cmd.get('BT');
64
+ const secondBT = _primitives.Cmd.get("BT");
63
65
 
64
- var firstET = _primitives.Cmd.get('ET');
66
+ const firstET = _primitives.Cmd.get("ET");
65
67
 
66
- var secondET = _primitives.Cmd.get('ET');
68
+ const secondET = _primitives.Cmd.get("ET");
67
69
 
68
70
  expect(firstBT).toBe(secondBT);
69
71
  expect(firstET).toBe(secondET);
70
72
  expect(firstBT).not.toBe(firstET);
71
73
  });
72
74
  });
73
- describe('Dict', function () {
74
- var checkInvalidHasValues = function checkInvalidHasValues(dict) {
75
+ describe("Dict", function () {
76
+ const checkInvalidHasValues = function (dict) {
75
77
  expect(dict.has()).toBeFalsy();
76
- expect(dict.has('Prev')).toBeFalsy();
78
+ expect(dict.has("Prev")).toBeFalsy();
77
79
  };
78
80
 
79
- var checkInvalidKeyValues = function checkInvalidKeyValues(dict) {
81
+ const checkInvalidKeyValues = function (dict) {
80
82
  expect(dict.get()).toBeUndefined();
81
- expect(dict.get('Prev')).toBeUndefined();
82
- expect(dict.get('Decode', 'D')).toBeUndefined();
83
- expect(dict.get('FontFile', 'FontFile2', 'FontFile3')).toBeNull();
83
+ expect(dict.get("Prev")).toBeUndefined();
84
+ expect(dict.get("Decode", "D")).toBeUndefined();
85
+ expect(dict.get("FontFile", "FontFile2", "FontFile3")).toBeUndefined();
84
86
  };
85
87
 
86
- var emptyDict, dictWithSizeKey, dictWithManyKeys;
87
- var storedSize = 42;
88
- var testFontFile = 'file1';
89
- var testFontFile2 = 'file2';
90
- var testFontFile3 = 'file3';
88
+ let emptyDict, dictWithSizeKey, dictWithManyKeys;
89
+ const storedSize = 42;
90
+ const testFontFile = "file1";
91
+ const testFontFile2 = "file2";
92
+ const testFontFile3 = "file3";
91
93
  beforeAll(function (done) {
92
94
  emptyDict = new _primitives.Dict();
93
95
  dictWithSizeKey = new _primitives.Dict();
94
- dictWithSizeKey.set('Size', storedSize);
96
+ dictWithSizeKey.set("Size", storedSize);
95
97
  dictWithManyKeys = new _primitives.Dict();
96
- dictWithManyKeys.set('FontFile', testFontFile);
97
- dictWithManyKeys.set('FontFile2', testFontFile2);
98
- dictWithManyKeys.set('FontFile3', testFontFile3);
98
+ dictWithManyKeys.set("FontFile", testFontFile);
99
+ dictWithManyKeys.set("FontFile2", testFontFile2);
100
+ dictWithManyKeys.set("FontFile3", testFontFile3);
99
101
  done();
100
102
  });
101
103
  afterAll(function () {
102
104
  emptyDict = dictWithSizeKey = dictWithManyKeys = null;
103
105
  });
104
- it('should return invalid values for unknown keys', function () {
106
+ it("should allow assigning an XRef table after creation", function () {
107
+ const dict = new _primitives.Dict(null);
108
+ expect(dict.xref).toEqual(null);
109
+ const xref = new _test_utils.XRefMock([]);
110
+ dict.assignXref(xref);
111
+ expect(dict.xref).toEqual(xref);
112
+ });
113
+ it("should return correct size", function () {
114
+ const dict = new _primitives.Dict(null);
115
+ expect(dict.size).toEqual(0);
116
+ dict.set("Type", _primitives.Name.get("Page"));
117
+ expect(dict.size).toEqual(1);
118
+ dict.set("Contents", _primitives.Ref.get(10, 0));
119
+ expect(dict.size).toEqual(2);
120
+ });
121
+ it("should return invalid values for unknown keys", function () {
105
122
  checkInvalidHasValues(emptyDict);
106
123
  checkInvalidKeyValues(emptyDict);
107
124
  });
108
- it('should return correct value for stored Size key', function () {
109
- expect(dictWithSizeKey.has('Size')).toBeTruthy();
110
- expect(dictWithSizeKey.get('Size')).toEqual(storedSize);
111
- expect(dictWithSizeKey.get('Prev', 'Size')).toEqual(storedSize);
112
- expect(dictWithSizeKey.get('Prev', 'Root', 'Size')).toEqual(storedSize);
125
+ it("should return correct value for stored Size key", function () {
126
+ expect(dictWithSizeKey.has("Size")).toBeTruthy();
127
+ expect(dictWithSizeKey.get("Size")).toEqual(storedSize);
128
+ expect(dictWithSizeKey.get("Prev", "Size")).toEqual(storedSize);
129
+ expect(dictWithSizeKey.get("Prev", "Root", "Size")).toEqual(storedSize);
113
130
  });
114
- it('should return invalid values for unknown keys when Size key is stored', function () {
131
+ it("should return invalid values for unknown keys when Size key is stored", function () {
115
132
  checkInvalidHasValues(dictWithSizeKey);
116
133
  checkInvalidKeyValues(dictWithSizeKey);
117
134
  });
118
- it('should return correct value for stored Size key with undefined value', function () {
119
- var dict = new _primitives.Dict();
120
- dict.set('Size');
121
- expect(dict.has('Size')).toBeTruthy();
135
+ it("should not accept to set a key with an undefined value", function () {
136
+ const dict = new _primitives.Dict();
137
+ expect(function () {
138
+ dict.set("Size");
139
+ }).toThrow(new Error('Dict.set: The "value" cannot be undefined.'));
140
+ expect(dict.has("Size")).toBeFalsy();
122
141
  checkInvalidKeyValues(dict);
123
142
  });
124
- it('should return correct values for multiple stored keys', function () {
125
- expect(dictWithManyKeys.has('FontFile')).toBeTruthy();
126
- expect(dictWithManyKeys.has('FontFile2')).toBeTruthy();
127
- expect(dictWithManyKeys.has('FontFile3')).toBeTruthy();
128
- expect(dictWithManyKeys.get('FontFile3')).toEqual(testFontFile3);
129
- expect(dictWithManyKeys.get('FontFile2', 'FontFile3')).toEqual(testFontFile2);
130
- expect(dictWithManyKeys.get('FontFile', 'FontFile2', 'FontFile3')).toEqual(testFontFile);
143
+ it("should return correct values for multiple stored keys", function () {
144
+ expect(dictWithManyKeys.has("FontFile")).toBeTruthy();
145
+ expect(dictWithManyKeys.has("FontFile2")).toBeTruthy();
146
+ expect(dictWithManyKeys.has("FontFile3")).toBeTruthy();
147
+ expect(dictWithManyKeys.get("FontFile3")).toEqual(testFontFile3);
148
+ expect(dictWithManyKeys.get("FontFile2", "FontFile3")).toEqual(testFontFile2);
149
+ expect(dictWithManyKeys.get("FontFile", "FontFile2", "FontFile3")).toEqual(testFontFile);
131
150
  });
132
- it('should asynchronously fetch unknown keys', function (done) {
133
- var keyPromises = [dictWithManyKeys.getAsync('Size'), dictWithSizeKey.getAsync('FontFile', 'FontFile2', 'FontFile3')];
151
+ it("should asynchronously fetch unknown keys", function (done) {
152
+ const keyPromises = [dictWithManyKeys.getAsync("Size"), dictWithSizeKey.getAsync("FontFile", "FontFile2", "FontFile3")];
134
153
  Promise.all(keyPromises).then(function (values) {
135
154
  expect(values[0]).toBeUndefined();
136
- expect(values[1]).toBeNull();
155
+ expect(values[1]).toBeUndefined();
137
156
  done();
138
- })["catch"](function (reason) {
157
+ }).catch(function (reason) {
139
158
  done.fail(reason);
140
159
  });
141
160
  });
142
- it('should asynchronously fetch correct values for multiple stored keys', function (done) {
143
- var keyPromises = [dictWithManyKeys.getAsync('FontFile3'), dictWithManyKeys.getAsync('FontFile2', 'FontFile3'), dictWithManyKeys.getAsync('FontFile', 'FontFile2', 'FontFile3')];
161
+ it("should asynchronously fetch correct values for multiple stored keys", function (done) {
162
+ const keyPromises = [dictWithManyKeys.getAsync("FontFile3"), dictWithManyKeys.getAsync("FontFile2", "FontFile3"), dictWithManyKeys.getAsync("FontFile", "FontFile2", "FontFile3")];
144
163
  Promise.all(keyPromises).then(function (values) {
145
164
  expect(values[0]).toEqual(testFontFile3);
146
165
  expect(values[1]).toEqual(testFontFile2);
147
166
  expect(values[2]).toEqual(testFontFile);
148
167
  done();
149
- })["catch"](function (reason) {
168
+ }).catch(function (reason) {
150
169
  done.fail(reason);
151
170
  });
152
171
  });
153
- it('should callback for each stored key', function () {
154
- var callbackSpy = jasmine.createSpy('spy on callback in dictionary');
172
+ it("should callback for each stored key", function () {
173
+ const callbackSpy = jasmine.createSpy("spy on callback in dictionary");
155
174
  dictWithManyKeys.forEach(callbackSpy);
156
175
  expect(callbackSpy).toHaveBeenCalled();
157
- var callbackSpyCalls = callbackSpy.calls;
158
- expect(callbackSpyCalls.argsFor(0)).toEqual(['FontFile', testFontFile]);
159
- expect(callbackSpyCalls.argsFor(1)).toEqual(['FontFile2', testFontFile2]);
160
- expect(callbackSpyCalls.argsFor(2)).toEqual(['FontFile3', testFontFile3]);
176
+ const callbackSpyCalls = callbackSpy.calls;
177
+ expect(callbackSpyCalls.argsFor(0)).toEqual(["FontFile", testFontFile]);
178
+ expect(callbackSpyCalls.argsFor(1)).toEqual(["FontFile2", testFontFile2]);
179
+ expect(callbackSpyCalls.argsFor(2)).toEqual(["FontFile3", testFontFile3]);
161
180
  expect(callbackSpyCalls.count()).toEqual(3);
162
181
  });
163
- it('should handle keys pointing to indirect objects, both sync and async', function (done) {
164
- var fontRef = _primitives.Ref.get(1, 0);
182
+ it("should handle keys pointing to indirect objects, both sync and async", function (done) {
183
+ const fontRef = _primitives.Ref.get(1, 0);
165
184
 
166
- var xref = new _test_utils.XRefMock([{
185
+ const xref = new _test_utils.XRefMock([{
167
186
  ref: fontRef,
168
187
  data: testFontFile
169
188
  }]);
170
- var fontDict = new _primitives.Dict(xref);
171
- fontDict.set('FontFile', fontRef);
172
- expect(fontDict.getRaw('FontFile')).toEqual(fontRef);
173
- expect(fontDict.get('FontFile', 'FontFile2', 'FontFile3')).toEqual(testFontFile);
174
- fontDict.getAsync('FontFile', 'FontFile2', 'FontFile3').then(function (value) {
189
+ const fontDict = new _primitives.Dict(xref);
190
+ fontDict.set("FontFile", fontRef);
191
+ expect(fontDict.getRaw("FontFile")).toEqual(fontRef);
192
+ expect(fontDict.get("FontFile", "FontFile2", "FontFile3")).toEqual(testFontFile);
193
+ fontDict.getAsync("FontFile", "FontFile2", "FontFile3").then(function (value) {
175
194
  expect(value).toEqual(testFontFile);
176
195
  done();
177
- })["catch"](function (reason) {
196
+ }).catch(function (reason) {
178
197
  done.fail(reason);
179
198
  });
180
199
  });
181
- it('should handle arrays containing indirect objects', function () {
182
- var minCoordRef = _primitives.Ref.get(1, 0),
183
- maxCoordRef = _primitives.Ref.get(2, 0);
200
+ it("should handle arrays containing indirect objects", function () {
201
+ const minCoordRef = _primitives.Ref.get(1, 0);
202
+
203
+ const maxCoordRef = _primitives.Ref.get(2, 0);
184
204
 
185
- var minCoord = 0,
186
- maxCoord = 1;
187
- var xref = new _test_utils.XRefMock([{
205
+ const minCoord = 0;
206
+ const maxCoord = 1;
207
+ const xref = new _test_utils.XRefMock([{
188
208
  ref: minCoordRef,
189
209
  data: minCoord
190
210
  }, {
191
211
  ref: maxCoordRef,
192
212
  data: maxCoord
193
213
  }]);
194
- var xObjectDict = new _primitives.Dict(xref);
195
- xObjectDict.set('BBox', [minCoord, maxCoord, minCoordRef, maxCoordRef]);
196
- expect(xObjectDict.get('BBox')).toEqual([minCoord, maxCoord, minCoordRef, maxCoordRef]);
197
- expect(xObjectDict.getArray('BBox')).toEqual([minCoord, maxCoord, minCoord, maxCoord]);
198
- });
199
- it('should get all key names', function () {
200
- var expectedKeys = ['FontFile', 'FontFile2', 'FontFile3'];
201
- var keys = dictWithManyKeys.getKeys();
214
+ const xObjectDict = new _primitives.Dict(xref);
215
+ xObjectDict.set("BBox", [minCoord, maxCoord, minCoordRef, maxCoordRef]);
216
+ expect(xObjectDict.get("BBox")).toEqual([minCoord, maxCoord, minCoordRef, maxCoordRef]);
217
+ expect(xObjectDict.getArray("BBox")).toEqual([minCoord, maxCoord, minCoord, maxCoord]);
218
+ });
219
+ it("should get all key names", function () {
220
+ const expectedKeys = ["FontFile", "FontFile2", "FontFile3"];
221
+ const keys = dictWithManyKeys.getKeys();
202
222
  expect(keys.sort()).toEqual(expectedKeys);
203
223
  });
204
- it('should create only one object for Dict.empty', function () {
205
- var firstDictEmpty = _primitives.Dict.empty;
206
- var secondDictEmpty = _primitives.Dict.empty;
224
+ it("should get all raw values", function () {
225
+ const expectedRawValues1 = [testFontFile, testFontFile2, testFontFile3];
226
+ const rawValues1 = dictWithManyKeys.getRawValues();
227
+ expect(rawValues1.sort()).toEqual(expectedRawValues1);
228
+
229
+ const typeName = _primitives.Name.get("Page");
230
+
231
+ const resources = new _primitives.Dict(null),
232
+ resourcesRef = _primitives.Ref.get(5, 0);
233
+
234
+ const contents = new _stream.StringStream("data"),
235
+ contentsRef = _primitives.Ref.get(10, 0);
236
+
237
+ const xref = new _test_utils.XRefMock([{
238
+ ref: resourcesRef,
239
+ data: resources
240
+ }, {
241
+ ref: contentsRef,
242
+ data: contents
243
+ }]);
244
+ const dict = new _primitives.Dict(xref);
245
+ dict.set("Type", typeName);
246
+ dict.set("Resources", resourcesRef);
247
+ dict.set("Contents", contentsRef);
248
+ const expectedRawValues2 = [contentsRef, resourcesRef, typeName];
249
+ const rawValues2 = dict.getRawValues();
250
+ expect(rawValues2.sort()).toEqual(expectedRawValues2);
251
+ });
252
+ it("should create only one object for Dict.empty", function () {
253
+ const firstDictEmpty = _primitives.Dict.empty;
254
+ const secondDictEmpty = _primitives.Dict.empty;
207
255
  expect(firstDictEmpty).toBe(secondDictEmpty);
208
256
  expect(firstDictEmpty).not.toBe(emptyDict);
209
257
  });
210
- it('should correctly merge dictionaries', function () {
211
- var expectedKeys = ['FontFile', 'FontFile2', 'FontFile3', 'Size'];
212
- var fontFileDict = new _primitives.Dict();
213
- fontFileDict.set('FontFile', 'Type1 font file');
258
+ it("should correctly merge dictionaries", function () {
259
+ const expectedKeys = ["FontFile", "FontFile2", "FontFile3", "Size"];
260
+ const fontFileDict = new _primitives.Dict();
261
+ fontFileDict.set("FontFile", "Type1 font file");
214
262
 
215
- var mergedDict = _primitives.Dict.merge(null, [dictWithManyKeys, dictWithSizeKey, fontFileDict]);
263
+ const mergedDict = _primitives.Dict.merge({
264
+ xref: null,
265
+ dictArray: [dictWithManyKeys, dictWithSizeKey, fontFileDict]
266
+ });
216
267
 
217
- var mergedKeys = mergedDict.getKeys();
268
+ const mergedKeys = mergedDict.getKeys();
218
269
  expect(mergedKeys.sort()).toEqual(expectedKeys);
219
- expect(mergedDict.get('FontFile')).toEqual(testFontFile);
270
+ expect(mergedDict.get("FontFile")).toEqual(testFontFile);
271
+ });
272
+ it("should correctly merge sub-dictionaries", function () {
273
+ const localFontDict = new _primitives.Dict();
274
+ localFontDict.set("F1", "Local font one");
275
+ const globalFontDict = new _primitives.Dict();
276
+ globalFontDict.set("F1", "Global font one");
277
+ globalFontDict.set("F2", "Global font two");
278
+ globalFontDict.set("F3", "Global font three");
279
+ const localDict = new _primitives.Dict();
280
+ localDict.set("Font", localFontDict);
281
+ const globalDict = new _primitives.Dict();
282
+ globalDict.set("Font", globalFontDict);
283
+
284
+ const mergedDict = _primitives.Dict.merge({
285
+ xref: null,
286
+ dictArray: [localDict, globalDict]
287
+ });
288
+
289
+ const mergedSubDict = _primitives.Dict.merge({
290
+ xref: null,
291
+ dictArray: [localDict, globalDict],
292
+ mergeSubDicts: true
293
+ });
294
+
295
+ const mergedFontDict = mergedDict.get("Font");
296
+ const mergedSubFontDict = mergedSubDict.get("Font");
297
+ expect(mergedFontDict instanceof _primitives.Dict).toEqual(true);
298
+ expect(mergedSubFontDict instanceof _primitives.Dict).toEqual(true);
299
+ const mergedFontDictKeys = mergedFontDict.getKeys();
300
+ const mergedSubFontDictKeys = mergedSubFontDict.getKeys();
301
+ expect(mergedFontDictKeys).toEqual(["F1"]);
302
+ expect(mergedSubFontDictKeys).toEqual(["F1", "F2", "F3"]);
303
+ const mergedFontDictValues = mergedFontDict.getRawValues();
304
+ const mergedSubFontDictValues = mergedSubFontDict.getRawValues();
305
+ expect(mergedFontDictValues).toEqual(["Local font one"]);
306
+ expect(mergedSubFontDictValues).toEqual(["Local font one", "Global font two", "Global font three"]);
220
307
  });
221
308
  });
222
- describe('Ref', function () {
223
- it('should retain the stored values', function () {
224
- var storedNum = 4;
225
- var storedGen = 2;
309
+ describe("Ref", function () {
310
+ it("should get a string representation", function () {
311
+ const nonZeroRef = _primitives.Ref.get(4, 2);
312
+
313
+ expect(nonZeroRef.toString()).toEqual("4R2");
226
314
 
227
- var ref = _primitives.Ref.get(storedNum, storedGen);
315
+ const zeroRef = _primitives.Ref.get(4, 0);
316
+
317
+ expect(zeroRef.toString()).toEqual("4R");
318
+ });
319
+ it("should retain the stored values", function () {
320
+ const storedNum = 4;
321
+ const storedGen = 2;
322
+
323
+ const ref = _primitives.Ref.get(storedNum, storedGen);
228
324
 
229
325
  expect(ref.num).toEqual(storedNum);
230
326
  expect(ref.gen).toEqual(storedGen);
231
327
  });
328
+ it("should create only one object for a reference and cache it", function () {
329
+ const firstRef = _primitives.Ref.get(4, 2);
330
+
331
+ const secondRef = _primitives.Ref.get(4, 2);
332
+
333
+ const firstOtherRef = _primitives.Ref.get(5, 2);
334
+
335
+ const secondOtherRef = _primitives.Ref.get(5, 2);
336
+
337
+ expect(firstRef).toBe(secondRef);
338
+ expect(firstOtherRef).toBe(secondOtherRef);
339
+ expect(firstRef).not.toBe(firstOtherRef);
340
+ });
232
341
  });
233
- describe('RefSet', function () {
234
- it('should have a stored value', function () {
235
- var ref = _primitives.Ref.get(4, 2);
342
+ describe("RefSet", function () {
343
+ it("should have a stored value", function () {
344
+ const ref = _primitives.Ref.get(4, 2);
236
345
 
237
- var refset = new _primitives.RefSet();
346
+ const refset = new _primitives.RefSet();
238
347
  refset.put(ref);
239
348
  expect(refset.has(ref)).toBeTruthy();
240
349
  });
241
- it('should not have an unknown value', function () {
242
- var ref = _primitives.Ref.get(4, 2);
350
+ it("should not have an unknown value", function () {
351
+ const ref = _primitives.Ref.get(4, 2);
243
352
 
244
- var refset = new _primitives.RefSet();
353
+ const refset = new _primitives.RefSet();
245
354
  expect(refset.has(ref)).toBeFalsy();
246
355
  refset.put(ref);
247
356
 
248
- var anotherRef = _primitives.Ref.get(2, 4);
357
+ const anotherRef = _primitives.Ref.get(2, 4);
249
358
 
250
359
  expect(refset.has(anotherRef)).toBeFalsy();
251
360
  });
252
361
  });
253
- describe('isName', function () {
254
- it('handles non-names', function () {
255
- var nonName = {};
362
+ describe("RefSetCache", function () {
363
+ const ref1 = _primitives.Ref.get(4, 2);
364
+
365
+ const ref2 = _primitives.Ref.get(5, 2);
366
+
367
+ const obj1 = _primitives.Name.get("foo");
368
+
369
+ const obj2 = _primitives.Name.get("bar");
370
+
371
+ let cache;
372
+ beforeEach(function (done) {
373
+ cache = new _primitives.RefSetCache();
374
+ done();
375
+ });
376
+ afterEach(function () {
377
+ cache = null;
378
+ });
379
+ it("should put, have and get a value", function () {
380
+ cache.put(ref1, obj1);
381
+ expect(cache.has(ref1)).toBeTruthy();
382
+ expect(cache.has(ref2)).toBeFalsy();
383
+ expect(cache.get(ref1)).toBe(obj1);
384
+ });
385
+ it("should put, have and get a value by alias", function () {
386
+ cache.put(ref1, obj1);
387
+ cache.putAlias(ref2, ref1);
388
+ expect(cache.has(ref1)).toBeTruthy();
389
+ expect(cache.has(ref2)).toBeTruthy();
390
+ expect(cache.get(ref1)).toBe(obj1);
391
+ expect(cache.get(ref2)).toBe(obj1);
392
+ });
393
+ it("should report the size of the cache", function () {
394
+ cache.put(ref1, obj1);
395
+ expect(cache.size).toEqual(1);
396
+ cache.put(ref2, obj2);
397
+ expect(cache.size).toEqual(2);
398
+ });
399
+ it("should clear the cache", function () {
400
+ cache.put(ref1, obj1);
401
+ expect(cache.size).toEqual(1);
402
+ cache.clear();
403
+ expect(cache.size).toEqual(0);
404
+ });
405
+ it("should support iteration", function () {
406
+ cache.put(ref1, obj1);
407
+ cache.put(ref2, obj2);
408
+ const values = [];
409
+ cache.forEach(function (value) {
410
+ values.push(value);
411
+ });
412
+ expect(values).toEqual([obj1, obj2]);
413
+ });
414
+ });
415
+ describe("isEOF", function () {
416
+ it("handles non-EOF", function () {
417
+ const nonEOF = "foo";
418
+ expect((0, _primitives.isEOF)(nonEOF)).toEqual(false);
419
+ });
420
+ it("handles EOF", function () {
421
+ expect((0, _primitives.isEOF)(_primitives.EOF)).toEqual(true);
422
+ });
423
+ });
424
+ describe("isName", function () {
425
+ it("handles non-names", function () {
426
+ const nonName = {};
256
427
  expect((0, _primitives.isName)(nonName)).toEqual(false);
257
428
  });
258
- it('handles names', function () {
259
- var name = _primitives.Name.get('Font');
429
+ it("handles names", function () {
430
+ const name = _primitives.Name.get("Font");
260
431
 
261
432
  expect((0, _primitives.isName)(name)).toEqual(true);
262
433
  });
263
- it('handles names with name check', function () {
264
- var name = _primitives.Name.get('Font');
434
+ it("handles names with name check", function () {
435
+ const name = _primitives.Name.get("Font");
265
436
 
266
- expect((0, _primitives.isName)(name, 'Font')).toEqual(true);
267
- expect((0, _primitives.isName)(name, 'Subtype')).toEqual(false);
437
+ expect((0, _primitives.isName)(name, "Font")).toEqual(true);
438
+ expect((0, _primitives.isName)(name, "Subtype")).toEqual(false);
268
439
  });
269
440
  });
270
- describe('isCmd', function () {
271
- it('handles non-commands', function () {
272
- var nonCmd = {};
441
+ describe("isCmd", function () {
442
+ it("handles non-commands", function () {
443
+ const nonCmd = {};
273
444
  expect((0, _primitives.isCmd)(nonCmd)).toEqual(false);
274
445
  });
275
- it('handles commands', function () {
276
- var cmd = _primitives.Cmd.get('BT');
446
+ it("handles commands", function () {
447
+ const cmd = _primitives.Cmd.get("BT");
277
448
 
278
449
  expect((0, _primitives.isCmd)(cmd)).toEqual(true);
279
450
  });
280
- it('handles commands with cmd check', function () {
281
- var cmd = _primitives.Cmd.get('BT');
451
+ it("handles commands with cmd check", function () {
452
+ const cmd = _primitives.Cmd.get("BT");
282
453
 
283
- expect((0, _primitives.isCmd)(cmd, 'BT')).toEqual(true);
284
- expect((0, _primitives.isCmd)(cmd, 'ET')).toEqual(false);
454
+ expect((0, _primitives.isCmd)(cmd, "BT")).toEqual(true);
455
+ expect((0, _primitives.isCmd)(cmd, "ET")).toEqual(false);
285
456
  });
286
457
  });
287
- describe('isDict', function () {
288
- it('handles non-dictionaries', function () {
289
- var nonDict = {};
458
+ describe("isDict", function () {
459
+ it("handles non-dictionaries", function () {
460
+ const nonDict = {};
290
461
  expect((0, _primitives.isDict)(nonDict)).toEqual(false);
291
462
  });
292
- it('handles empty dictionaries with type check', function () {
293
- var dict = _primitives.Dict.empty;
463
+ it("handles empty dictionaries with type check", function () {
464
+ const dict = _primitives.Dict.empty;
294
465
  expect((0, _primitives.isDict)(dict)).toEqual(true);
295
- expect((0, _primitives.isDict)(dict, 'Page')).toEqual(false);
466
+ expect((0, _primitives.isDict)(dict, "Page")).toEqual(false);
296
467
  });
297
- it('handles dictionaries with type check', function () {
298
- var dict = new _primitives.Dict();
299
- dict.set('Type', _primitives.Name.get('Page'));
300
- expect((0, _primitives.isDict)(dict, 'Page')).toEqual(true);
301
- expect((0, _primitives.isDict)(dict, 'Contents')).toEqual(false);
468
+ it("handles dictionaries with type check", function () {
469
+ const dict = new _primitives.Dict();
470
+ dict.set("Type", _primitives.Name.get("Page"));
471
+ expect((0, _primitives.isDict)(dict, "Page")).toEqual(true);
472
+ expect((0, _primitives.isDict)(dict, "Contents")).toEqual(false);
302
473
  });
303
474
  });
304
- describe('isRef', function () {
305
- it('handles non-refs', function () {
306
- var nonRef = {};
475
+ describe("isRef", function () {
476
+ it("handles non-refs", function () {
477
+ const nonRef = {};
307
478
  expect((0, _primitives.isRef)(nonRef)).toEqual(false);
308
479
  });
309
- it('handles refs', function () {
310
- var ref = _primitives.Ref.get(1, 0);
480
+ it("handles refs", function () {
481
+ const ref = _primitives.Ref.get(1, 0);
311
482
 
312
483
  expect((0, _primitives.isRef)(ref)).toEqual(true);
313
484
  });
314
485
  });
315
- describe('isRefsEqual', function () {
316
- it('should handle Refs pointing to the same object', function () {
317
- var ref1 = _primitives.Ref.get(1, 0);
486
+ describe("isRefsEqual", function () {
487
+ it("should handle Refs pointing to the same object", function () {
488
+ const ref1 = _primitives.Ref.get(1, 0);
318
489
 
319
- var ref2 = _primitives.Ref.get(1, 0);
490
+ const ref2 = _primitives.Ref.get(1, 0);
320
491
 
321
492
  expect((0, _primitives.isRefsEqual)(ref1, ref2)).toEqual(true);
322
493
  });
323
- it('should handle Refs pointing to different objects', function () {
324
- var ref1 = _primitives.Ref.get(1, 0);
494
+ it("should handle Refs pointing to different objects", function () {
495
+ const ref1 = _primitives.Ref.get(1, 0);
325
496
 
326
- var ref2 = _primitives.Ref.get(2, 0);
497
+ const ref2 = _primitives.Ref.get(2, 0);
327
498
 
328
499
  expect((0, _primitives.isRefsEqual)(ref1, ref2)).toEqual(false);
329
500
  });
330
501
  });
502
+ describe("isStream", function () {
503
+ it("handles non-streams", function () {
504
+ const nonStream = {};
505
+ expect((0, _primitives.isStream)(nonStream)).toEqual(false);
506
+ });
507
+ it("handles streams", function () {
508
+ const stream = new _stream.StringStream("foo");
509
+ expect((0, _primitives.isStream)(stream)).toEqual(true);
510
+ });
511
+ });
331
512
  });