pdfjs-dist 2.6.347 → 2.7.570

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 (158) hide show
  1. package/README.md +3 -3
  2. package/bower.json +1 -1
  3. package/build/pdf.js +2050 -1087
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +18219 -10436
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/es5/build/pdf.d.ts +1 -0
  10. package/es5/build/pdf.js +6623 -6654
  11. package/es5/build/pdf.js.map +1 -1
  12. package/es5/build/pdf.min.js +1 -1
  13. package/es5/build/pdf.worker.js +20815 -13888
  14. package/es5/build/pdf.worker.js.map +1 -1
  15. package/es5/build/pdf.worker.min.js +1 -1
  16. package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
  17. package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
  18. package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
  19. package/es5/web/pdf_viewer.css +18 -15
  20. package/es5/web/pdf_viewer.js +1094 -514
  21. package/es5/web/pdf_viewer.js.map +1 -1
  22. package/image_decoders/pdf.image_decoders.js +774 -168
  23. package/image_decoders/pdf.image_decoders.js.map +1 -1
  24. package/image_decoders/pdf.image_decoders.min.js +1 -1
  25. package/lib/core/annotation.js +556 -108
  26. package/lib/core/cff_parser.js +7 -1
  27. package/lib/core/charsets.js +1 -1
  28. package/lib/core/cmap.js +20 -1
  29. package/lib/core/core_utils.js +162 -3
  30. package/lib/core/crypto.js +1 -1
  31. package/lib/core/default_appearance.js +132 -0
  32. package/lib/core/document.js +115 -9
  33. package/lib/core/encodings.js +1 -1
  34. package/lib/core/evaluator.js +168 -74
  35. package/lib/core/fonts.js +97 -11
  36. package/lib/core/function.js +5 -10
  37. package/lib/core/glyphlist.js +11 -4529
  38. package/lib/core/image_utils.js +30 -1
  39. package/lib/core/jpg.js +1 -1
  40. package/lib/core/jpx.js +5 -5
  41. package/lib/core/murmurhash3.js +1 -1
  42. package/lib/core/obj.js +123 -39
  43. package/lib/core/pattern.js +4 -4
  44. package/lib/core/primitives.js +24 -5
  45. package/lib/core/standard_fonts.js +1 -1
  46. package/lib/core/stream.js +5 -1
  47. package/lib/core/unicode.js +15 -1387
  48. package/lib/core/worker.js +58 -17
  49. package/lib/core/writer.js +68 -4
  50. package/lib/display/annotation_layer.js +712 -119
  51. package/lib/display/annotation_storage.js +21 -4
  52. package/lib/display/api.js +88 -18
  53. package/lib/display/canvas.js +414 -375
  54. package/lib/display/display_utils.js +11 -4
  55. package/lib/display/fetch_stream.js +3 -3
  56. package/lib/display/font_loader.js +2 -3
  57. package/lib/display/metadata.js +54 -20
  58. package/lib/display/node_stream.js +1 -1
  59. package/lib/display/optional_content_config.js +1 -1
  60. package/lib/display/pattern_helper.js +109 -113
  61. package/lib/display/svg.js +5 -5
  62. package/lib/display/text_layer.js +54 -54
  63. package/lib/display/transport_stream.js +4 -4
  64. package/lib/display/webgl.js +65 -68
  65. package/lib/examples/node/domstubs.js +9 -4
  66. package/lib/pdf.js +2 -2
  67. package/lib/pdf.sandbox.js +311 -0
  68. package/lib/pdf.worker.js +2 -2
  69. package/lib/shared/scripting_utils.js +84 -0
  70. package/lib/shared/util.js +129 -14
  71. package/lib/{display → shared}/xml_parser.js +112 -4
  72. package/lib/test/unit/annotation_spec.js +831 -109
  73. package/lib/test/unit/annotation_storage_spec.js +28 -10
  74. package/lib/test/unit/api_spec.js +190 -160
  75. package/lib/test/unit/bidi_spec.js +6 -6
  76. package/lib/test/unit/cff_parser_spec.js +73 -73
  77. package/lib/test/unit/clitests_helper.js +2 -0
  78. package/lib/test/unit/cmap_spec.js +48 -74
  79. package/lib/test/unit/core_utils_spec.js +34 -0
  80. package/lib/test/unit/crypto_spec.js +162 -199
  81. package/lib/test/unit/custom_spec.js +7 -18
  82. package/lib/test/unit/default_appearance_spec.js +54 -0
  83. package/lib/test/unit/display_svg_spec.js +24 -19
  84. package/lib/test/unit/display_utils_spec.js +1 -1
  85. package/lib/test/unit/document_spec.js +187 -20
  86. package/lib/test/unit/evaluator_spec.js +30 -30
  87. package/lib/test/unit/function_spec.js +165 -165
  88. package/lib/test/unit/jasmine-boot.js +52 -53
  89. package/lib/test/unit/metadata_spec.js +2 -2
  90. package/lib/test/unit/murmurhash3_spec.js +29 -16
  91. package/lib/test/unit/network_spec.js +21 -21
  92. package/lib/test/unit/pdf_find_controller_spec.js +131 -69
  93. package/lib/test/unit/pdf_find_utils_spec.js +10 -10
  94. package/lib/test/unit/scripting_spec.js +1104 -0
  95. package/lib/test/unit/stream_spec.js +8 -8
  96. package/lib/test/unit/test_utils.js +16 -19
  97. package/lib/test/unit/testreporter.js +11 -4
  98. package/lib/test/unit/type1_parser_spec.js +23 -23
  99. package/lib/test/unit/ui_utils_spec.js +78 -35
  100. package/lib/test/unit/unicode_spec.js +7 -7
  101. package/lib/test/unit/util_spec.js +26 -3
  102. package/lib/test/unit/writer_spec.js +16 -1
  103. package/lib/test/unit/xml_spec.js +117 -0
  104. package/lib/web/annotation_layer_builder.js +18 -6
  105. package/lib/web/app.js +579 -161
  106. package/lib/web/app_options.js +14 -0
  107. package/lib/web/base_tree_viewer.js +50 -0
  108. package/lib/web/base_viewer.js +350 -14
  109. package/lib/web/chromecom.js +9 -1
  110. package/lib/web/debugger.js +1 -2
  111. package/lib/web/download_manager.js +0 -15
  112. package/lib/web/firefox_print_service.js +6 -4
  113. package/lib/web/firefoxcom.js +84 -69
  114. package/lib/web/generic_scripting.js +55 -0
  115. package/lib/web/genericcom.js +9 -1
  116. package/lib/web/grab_to_pan.js +1 -1
  117. package/lib/web/interfaces.js +9 -3
  118. package/lib/web/pdf_attachment_viewer.js +1 -3
  119. package/lib/web/pdf_cursor_tools.js +20 -13
  120. package/lib/web/pdf_document_properties.js +48 -61
  121. package/lib/web/pdf_find_bar.js +1 -3
  122. package/lib/web/pdf_find_controller.js +58 -12
  123. package/lib/web/pdf_history.js +43 -21
  124. package/lib/web/pdf_layer_viewer.js +1 -9
  125. package/lib/web/pdf_link_service.js +108 -78
  126. package/lib/web/pdf_outline_viewer.js +166 -10
  127. package/lib/web/pdf_page_view.js +14 -14
  128. package/lib/web/pdf_presentation_mode.js +21 -31
  129. package/lib/web/pdf_rendering_queue.js +8 -1
  130. package/lib/web/pdf_sidebar.js +62 -107
  131. package/lib/web/pdf_sidebar_resizer.js +11 -21
  132. package/lib/web/pdf_single_page_viewer.js +8 -0
  133. package/lib/web/pdf_thumbnail_view.js +26 -26
  134. package/lib/web/pdf_thumbnail_viewer.js +13 -2
  135. package/lib/web/pdf_viewer.component.js +2 -2
  136. package/lib/web/pdf_viewer.js +3 -1
  137. package/lib/web/preferences.js +33 -44
  138. package/lib/web/text_layer_builder.js +2 -9
  139. package/lib/web/ui_utils.js +78 -46
  140. package/lib/web/viewer_compatibility.js +1 -2
  141. package/package.json +4 -1
  142. package/types/display/annotation_layer.d.ts +18 -3
  143. package/types/display/api.d.ts +110 -54
  144. package/types/display/canvas.d.ts +1 -1
  145. package/types/display/display_utils.d.ts +96 -95
  146. package/types/display/fetch_stream.d.ts +2 -2
  147. package/types/display/metadata.d.ts +4 -0
  148. package/types/display/pattern_helper.d.ts +1 -1
  149. package/types/display/text_layer.d.ts +7 -7
  150. package/types/display/transport_stream.d.ts +1 -1
  151. package/types/shared/scripting_utils.d.ts +12 -0
  152. package/types/shared/util.d.ts +281 -250
  153. package/types/shared/xml_parser.d.ts +64 -0
  154. package/web/pdf_viewer.css +18 -15
  155. package/web/pdf_viewer.js +809 -408
  156. package/web/pdf_viewer.js.map +1 -1
  157. package/webpack.js +1 -1
  158. package/types/display/xml_parser.d.ts +0 -35
@@ -21,73 +21,71 @@
21
21
  */
22
22
  "use strict";
23
23
 
24
- function initializePDFJS(callback) {
25
- Promise.all(["pdfjs/display/api.js", "pdfjs/display/worker_options.js", "pdfjs/display/network.js", "pdfjs/display/fetch_stream.js", "pdfjs/shared/is_node.js", "pdfjs-test/unit/annotation_spec.js", "pdfjs-test/unit/annotation_storage_spec.js", "pdfjs-test/unit/api_spec.js", "pdfjs-test/unit/bidi_spec.js", "pdfjs-test/unit/cff_parser_spec.js", "pdfjs-test/unit/cmap_spec.js", "pdfjs-test/unit/colorspace_spec.js", "pdfjs-test/unit/core_utils_spec.js", "pdfjs-test/unit/crypto_spec.js", "pdfjs-test/unit/custom_spec.js", "pdfjs-test/unit/display_svg_spec.js", "pdfjs-test/unit/display_utils_spec.js", "pdfjs-test/unit/document_spec.js", "pdfjs-test/unit/encodings_spec.js", "pdfjs-test/unit/evaluator_spec.js", "pdfjs-test/unit/function_spec.js", "pdfjs-test/unit/fetch_stream_spec.js", "pdfjs-test/unit/message_handler_spec.js", "pdfjs-test/unit/metadata_spec.js", "pdfjs-test/unit/murmurhash3_spec.js", "pdfjs-test/unit/network_spec.js", "pdfjs-test/unit/network_utils_spec.js", "pdfjs-test/unit/parser_spec.js", "pdfjs-test/unit/pdf_find_controller_spec.js", "pdfjs-test/unit/pdf_find_utils_spec.js", "pdfjs-test/unit/pdf_history_spec.js", "pdfjs-test/unit/primitives_spec.js", "pdfjs-test/unit/stream_spec.js", "pdfjs-test/unit/type1_parser_spec.js", "pdfjs-test/unit/ui_utils_spec.js", "pdfjs-test/unit/unicode_spec.js", "pdfjs-test/unit/util_spec.js", "pdfjs-test/unit/writer_spec.js"].map(function (moduleName) {
26
- return SystemJS.import(moduleName);
27
- })).then(function (modules) {
28
- const displayApi = modules[0];
29
- const {
30
- GlobalWorkerOptions
31
- } = modules[1];
32
- const {
33
- PDFNetworkStream
34
- } = modules[2];
35
- const {
36
- PDFFetchStream
37
- } = modules[3];
38
- const {
39
- isNodeJS
40
- } = modules[4];
41
-
42
- if (isNodeJS) {
43
- throw new Error("The `gulp unittest` command cannot be used in Node.js environments.");
44
- }
24
+ var _worker_options = require("pdfjs/display/worker_options.js");
45
25
 
46
- if (typeof Response !== "undefined" && "body" in Response.prototype && typeof ReadableStream !== "undefined") {
47
- displayApi.setPDFNetworkStreamFactory(function (params) {
48
- return new PDFFetchStream(params);
49
- });
50
- } else {
51
- displayApi.setPDFNetworkStreamFactory(function (params) {
52
- return new PDFNetworkStream(params);
53
- });
54
- }
26
+ var _is_node = require("pdfjs/shared/is_node.js");
55
27
 
56
- GlobalWorkerOptions.workerSrc = "../../build/generic/build/pdf.worker.js";
57
- callback();
58
- });
28
+ var _fetch_stream = require("pdfjs/display/fetch_stream.js");
29
+
30
+ var _network = require("pdfjs/display/network.js");
31
+
32
+ var _api = require("pdfjs/display/api.js");
33
+
34
+ var _testreporter = require("./testreporter.js");
35
+
36
+ async function initializePDFJS(callback) {
37
+ await Promise.all(["pdfjs-test/unit/annotation_spec.js", "pdfjs-test/unit/annotation_storage_spec.js", "pdfjs-test/unit/api_spec.js", "pdfjs-test/unit/bidi_spec.js", "pdfjs-test/unit/cff_parser_spec.js", "pdfjs-test/unit/cmap_spec.js", "pdfjs-test/unit/colorspace_spec.js", "pdfjs-test/unit/core_utils_spec.js", "pdfjs-test/unit/crypto_spec.js", "pdfjs-test/unit/custom_spec.js", "pdfjs-test/unit/default_appearance_spec.js", "pdfjs-test/unit/display_svg_spec.js", "pdfjs-test/unit/display_utils_spec.js", "pdfjs-test/unit/document_spec.js", "pdfjs-test/unit/encodings_spec.js", "pdfjs-test/unit/evaluator_spec.js", "pdfjs-test/unit/function_spec.js", "pdfjs-test/unit/fetch_stream_spec.js", "pdfjs-test/unit/message_handler_spec.js", "pdfjs-test/unit/metadata_spec.js", "pdfjs-test/unit/murmurhash3_spec.js", "pdfjs-test/unit/network_spec.js", "pdfjs-test/unit/network_utils_spec.js", "pdfjs-test/unit/parser_spec.js", "pdfjs-test/unit/pdf_find_controller_spec.js", "pdfjs-test/unit/pdf_find_utils_spec.js", "pdfjs-test/unit/pdf_history_spec.js", "pdfjs-test/unit/primitives_spec.js", "pdfjs-test/unit/scripting_spec.js", "pdfjs-test/unit/stream_spec.js", "pdfjs-test/unit/type1_parser_spec.js", "pdfjs-test/unit/ui_utils_spec.js", "pdfjs-test/unit/unicode_spec.js", "pdfjs-test/unit/util_spec.js", "pdfjs-test/unit/writer_spec.js", "pdfjs-test/unit/xml_spec.js"].map(function (moduleName) {
38
+ return import(moduleName);
39
+ }));
40
+
41
+ if (_is_node.isNodeJS) {
42
+ throw new Error("The `gulp unittest` command cannot be used in Node.js environments.");
43
+ }
44
+
45
+ if (typeof Response !== "undefined" && "body" in Response.prototype && typeof ReadableStream !== "undefined") {
46
+ (0, _api.setPDFNetworkStreamFactory)(function (params) {
47
+ return new _fetch_stream.PDFFetchStream(params);
48
+ });
49
+ } else {
50
+ (0, _api.setPDFNetworkStreamFactory)(function (params) {
51
+ return new _network.PDFNetworkStream(params);
52
+ });
53
+ }
54
+
55
+ _worker_options.GlobalWorkerOptions.workerSrc = "../../build/generic/build/pdf.worker.js";
56
+ callback();
59
57
  }
60
58
 
61
59
  (function () {
62
60
  window.jasmine = jasmineRequire.core(jasmineRequire);
63
61
  jasmineRequire.html(jasmine);
64
- var env = jasmine.getEnv();
65
- var jasmineInterface = jasmineRequire.interface(jasmine, env);
62
+ const env = jasmine.getEnv();
63
+ const jasmineInterface = jasmineRequire.interface(jasmine, env);
66
64
  extend(window, jasmineInterface);
67
- var queryString = new jasmine.QueryString({
65
+ const queryString = new jasmine.QueryString({
68
66
  getWindowLocation() {
69
67
  return window.location;
70
68
  }
71
69
 
72
70
  });
73
- var config = {
71
+ const config = {
74
72
  failFast: queryString.getParam("failFast"),
75
73
  oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
76
74
  hideDisabled: queryString.getParam("hideDisabled")
77
75
  };
78
- var random = queryString.getParam("random");
76
+ const random = queryString.getParam("random");
79
77
 
80
78
  if (random !== undefined && random !== "") {
81
79
  config.random = random;
82
80
  }
83
81
 
84
- var seed = queryString.getParam("seed");
82
+ const seed = queryString.getParam("seed");
85
83
 
86
84
  if (seed) {
87
85
  config.seed = seed;
88
86
  }
89
87
 
90
- var htmlReporter = new jasmine.HtmlReporter({
88
+ const htmlReporter = new jasmine.HtmlReporter({
91
89
  env,
92
90
 
93
91
  navigateWithNewParam(key, value) {
@@ -115,11 +113,11 @@ function initializePDFJS(callback) {
115
113
  env.addReporter(htmlReporter);
116
114
 
117
115
  if (queryString.getParam("browser")) {
118
- var testReporter = new TestReporter(queryString.getParam("browser"));
116
+ const testReporter = new _testreporter.TestReporter(queryString.getParam("browser"));
119
117
  env.addReporter(testReporter);
120
118
  }
121
119
 
122
- var specFilter = new jasmine.HtmlSpecFilter({
120
+ const specFilter = new jasmine.HtmlSpecFilter({
123
121
  filterString() {
124
122
  return queryString.getParam("spec");
125
123
  }
@@ -132,24 +130,25 @@ function initializePDFJS(callback) {
132
130
 
133
131
  env.configure(config);
134
132
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
135
- var currentWindowOnload = window.onload;
136
133
 
137
- window.onload = function () {
138
- if (currentWindowOnload) {
139
- currentWindowOnload();
134
+ function extend(destination, source) {
135
+ for (const property in source) {
136
+ destination[property] = source[property];
140
137
  }
141
138
 
139
+ return destination;
140
+ }
141
+
142
+ function unitTestInit() {
142
143
  initializePDFJS(function () {
143
144
  htmlReporter.initialize();
144
145
  env.execute();
145
146
  });
146
- };
147
-
148
- function extend(destination, source) {
149
- for (var property in source) {
150
- destination[property] = source[property];
151
- }
147
+ }
152
148
 
153
- return destination;
149
+ if (document.readyState === "interactive" || document.readyState === "complete") {
150
+ unitTestInit();
151
+ } else {
152
+ document.addEventListener("DOMContentLoaded", unitTestInit, true);
154
153
  }
155
154
  })();
@@ -56,7 +56,7 @@ describe("metadata", function () {
56
56
  expect(metadata.get("dc:title")).toEqual("L'Odissee thématique logo Odisséé - décembre 2008.pub");
57
57
  expect(metadata.get("dc:qux")).toEqual(null);
58
58
  expect(metadata.getAll()).toEqual({
59
- "dc:creator": "ODIS",
59
+ "dc:creator": ["ODIS"],
60
60
  "dc:title": "L'Odissee thématique logo Odisséé - décembre 2008.pub",
61
61
  "xap:creatortool": "PDFCreator Version 0.9.6"
62
62
  });
@@ -74,7 +74,7 @@ describe("metadata", function () {
74
74
  expect(metadata.get("dc:title")).toEqual("");
75
75
  expect(metadata.get("dc:qux")).toEqual(null);
76
76
  expect(metadata.getAll()).toEqual({
77
- "dc:creator": "",
77
+ "dc:creator": [""],
78
78
  "dc:description": "",
79
79
  "dc:format": "application/pdf",
80
80
  "dc:subject": "",
@@ -25,47 +25,60 @@ var _murmurhash = require("../../core/murmurhash3.js");
25
25
 
26
26
  describe("MurmurHash3_64", function () {
27
27
  it("instantiates without seed", function () {
28
- var hash = new _murmurhash.MurmurHash3_64();
28
+ const hash = new _murmurhash.MurmurHash3_64();
29
29
  expect(hash).toEqual(jasmine.any(_murmurhash.MurmurHash3_64));
30
30
  });
31
31
  it("instantiates with seed", function () {
32
- var hash = new _murmurhash.MurmurHash3_64(1);
32
+ const hash = new _murmurhash.MurmurHash3_64(1);
33
33
  expect(hash).toEqual(jasmine.any(_murmurhash.MurmurHash3_64));
34
34
  });
35
- var hexDigestExpected = "f61cfdbfdae0f65e";
36
- var sourceText = "test";
37
- var sourceCharCodes = [116, 101, 115, 116];
35
+ const hexDigestExpected = "f61cfdbfdae0f65e";
36
+ const sourceText = "test";
37
+ const sourceCharCodes = [116, 101, 115, 116];
38
38
  it("correctly generates a hash from a string", function () {
39
- var hash = new _murmurhash.MurmurHash3_64();
39
+ const hash = new _murmurhash.MurmurHash3_64();
40
40
  hash.update(sourceText);
41
41
  expect(hash.hexdigest()).toEqual(hexDigestExpected);
42
42
  });
43
43
  it("correctly generates a hash from a Uint8Array", function () {
44
- var hash = new _murmurhash.MurmurHash3_64();
44
+ const hash = new _murmurhash.MurmurHash3_64();
45
45
  hash.update(new Uint8Array(sourceCharCodes));
46
46
  expect(hash.hexdigest()).toEqual(hexDigestExpected);
47
47
  });
48
48
  it("correctly generates a hash from a Uint32Array", function () {
49
- var hash = new _murmurhash.MurmurHash3_64();
49
+ const hash = new _murmurhash.MurmurHash3_64();
50
50
  hash.update(new Uint32Array(new Uint8Array(sourceCharCodes).buffer));
51
51
  expect(hash.hexdigest()).toEqual(hexDigestExpected);
52
52
  });
53
53
  it("changes the hash after update without seed", function () {
54
- var hash = new _murmurhash.MurmurHash3_64();
55
- var hexdigest1, hexdigest2;
54
+ const hash = new _murmurhash.MurmurHash3_64();
56
55
  hash.update(sourceText);
57
- hexdigest1 = hash.hexdigest();
56
+ const hexdigest1 = hash.hexdigest();
58
57
  hash.update(sourceText);
59
- hexdigest2 = hash.hexdigest();
58
+ const hexdigest2 = hash.hexdigest();
60
59
  expect(hexdigest1).not.toEqual(hexdigest2);
61
60
  });
62
61
  it("changes the hash after update with seed", function () {
63
- var hash = new _murmurhash.MurmurHash3_64(1);
64
- var hexdigest1, hexdigest2;
62
+ const hash = new _murmurhash.MurmurHash3_64(1);
65
63
  hash.update(sourceText);
66
- hexdigest1 = hash.hexdigest();
64
+ const hexdigest1 = hash.hexdigest();
67
65
  hash.update(sourceText);
68
- hexdigest2 = hash.hexdigest();
66
+ const hexdigest2 = hash.hexdigest();
69
67
  expect(hexdigest1).not.toEqual(hexdigest2);
70
68
  });
69
+ it("generates correct hashes for TypedArrays which share the same " + "underlying ArrayBuffer (issue 12533)", function () {
70
+ const typedArray = new Uint8Array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
71
+ const startArray = new Uint8Array(typedArray.buffer, 0, 10);
72
+ const endArray = new Uint8Array(typedArray.buffer, 10, 10);
73
+ expect(startArray).not.toEqual(endArray);
74
+ const startHash = new _murmurhash.MurmurHash3_64();
75
+ startHash.update(startArray);
76
+ const startHexdigest = startHash.hexdigest();
77
+ const endHash = new _murmurhash.MurmurHash3_64();
78
+ endHash.update(endArray);
79
+ const endHexdigest = endHash.hexdigest();
80
+ expect(startHexdigest).not.toEqual(endHexdigest);
81
+ expect(startHexdigest).toEqual("a49de339cc5b0819");
82
+ expect(endHexdigest).toEqual("f81a92d9e214ab35");
83
+ });
71
84
  });
@@ -26,25 +26,25 @@ var _util = require("../../shared/util.js");
26
26
  var _network = require("../../display/network.js");
27
27
 
28
28
  describe("network", function () {
29
- var pdf1 = new URL("../pdfs/tracemonkey.pdf", window.location).href;
30
- var pdf1Length = 1016315;
29
+ const pdf1 = new URL("../pdfs/tracemonkey.pdf", window.location).href;
30
+ const pdf1Length = 1016315;
31
31
  it("read without stream and range", function (done) {
32
- var stream = new _network.PDFNetworkStream({
32
+ const stream = new _network.PDFNetworkStream({
33
33
  url: pdf1,
34
34
  rangeChunkSize: 65536,
35
35
  disableStream: true,
36
36
  disableRange: true
37
37
  });
38
- var fullReader = stream.getFullReader();
39
- var isStreamingSupported, isRangeSupported;
40
- var promise = fullReader.headersReady.then(function () {
38
+ const fullReader = stream.getFullReader();
39
+ let isStreamingSupported, isRangeSupported;
40
+ const promise = fullReader.headersReady.then(function () {
41
41
  isStreamingSupported = fullReader.isStreamingSupported;
42
42
  isRangeSupported = fullReader.isRangeSupported;
43
43
  });
44
- var len = 0,
44
+ let len = 0,
45
45
  count = 0;
46
46
 
47
- var read = function () {
47
+ const read = function () {
48
48
  return fullReader.read().then(function (result) {
49
49
  if (result.done) {
50
50
  return undefined;
@@ -56,7 +56,7 @@ describe("network", function () {
56
56
  });
57
57
  };
58
58
 
59
- var readPromise = Promise.all([read(), promise]);
59
+ const readPromise = Promise.all([read(), promise]);
60
60
  readPromise.then(function (page) {
61
61
  expect(len).toEqual(pdf1Length);
62
62
  expect(count).toEqual(1);
@@ -68,33 +68,33 @@ describe("network", function () {
68
68
  });
69
69
  });
70
70
  it("read custom ranges", function (done) {
71
- var rangeSize = 32768;
72
- var stream = new _network.PDFNetworkStream({
71
+ const rangeSize = 32768;
72
+ const stream = new _network.PDFNetworkStream({
73
73
  url: pdf1,
74
74
  length: pdf1Length,
75
75
  rangeChunkSize: rangeSize,
76
76
  disableStream: true,
77
77
  disableRange: false
78
78
  });
79
- var fullReader = stream.getFullReader();
80
- var isStreamingSupported, isRangeSupported, fullReaderCancelled;
81
- var promise = fullReader.headersReady.then(function () {
79
+ const fullReader = stream.getFullReader();
80
+ let isStreamingSupported, isRangeSupported, fullReaderCancelled;
81
+ const promise = fullReader.headersReady.then(function () {
82
82
  isStreamingSupported = fullReader.isStreamingSupported;
83
83
  isRangeSupported = fullReader.isRangeSupported;
84
84
  fullReader.cancel(new _util.AbortException("Don't need fullReader."));
85
85
  fullReaderCancelled = true;
86
86
  });
87
- var tailSize = pdf1Length % rangeSize || rangeSize;
88
- var range1Reader = stream.getRangeReader(pdf1Length - tailSize - rangeSize, pdf1Length - tailSize);
89
- var range2Reader = stream.getRangeReader(pdf1Length - tailSize, pdf1Length);
90
- var result1 = {
87
+ const tailSize = pdf1Length % rangeSize || rangeSize;
88
+ const range1Reader = stream.getRangeReader(pdf1Length - tailSize - rangeSize, pdf1Length - tailSize);
89
+ const range2Reader = stream.getRangeReader(pdf1Length - tailSize, pdf1Length);
90
+ const result1 = {
91
91
  value: 0
92
92
  },
93
- result2 = {
93
+ result2 = {
94
94
  value: 0
95
95
  };
96
96
 
97
- var read = function (reader, lenResult) {
97
+ const read = function (reader, lenResult) {
98
98
  return reader.read().then(function (result) {
99
99
  if (result.done) {
100
100
  return undefined;
@@ -105,7 +105,7 @@ describe("network", function () {
105
105
  });
106
106
  };
107
107
 
108
- var readPromises = Promise.all([read(range1Reader, result1), read(range2Reader, result2), promise]);
108
+ const readPromises = Promise.all([read(range1Reader, result1), read(range2Reader, result2), promise]);
109
109
  readPromises.then(function () {
110
110
  expect(result1.value).toEqual(rangeSize);
111
111
  expect(result2.value).toEqual(tailSize);
@@ -31,6 +31,8 @@ var _pdf_find_controller = require("../../web/pdf_find_controller.js");
31
31
 
32
32
  var _pdf_link_service = require("../../web/pdf_link_service.js");
33
33
 
34
+ const tracemonkeyFileName = "tracemonkey.pdf";
35
+
34
36
  class MockLinkService extends _pdf_link_service.SimpleLinkService {
35
37
  constructor() {
36
38
  super();
@@ -56,68 +58,80 @@ class MockLinkService extends _pdf_link_service.SimpleLinkService {
56
58
 
57
59
  }
58
60
 
59
- describe("pdf_find_controller", function () {
60
- let eventBus;
61
- let pdfFindController;
62
- beforeEach(function (done) {
63
- const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
64
- loadingTask.promise.then(function (pdfDocument) {
65
- eventBus = new _ui_utils.EventBus();
66
- const linkService = new MockLinkService();
67
- linkService.setDocument(pdfDocument);
68
- pdfFindController = new _pdf_find_controller.PDFFindController({
69
- linkService,
70
- eventBus
71
- });
72
- pdfFindController.setDocument(pdfDocument);
73
- done();
74
- });
75
- });
76
- afterEach(function () {
77
- eventBus = null;
78
- pdfFindController = null;
61
+ async function initPdfFindController(filename) {
62
+ const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename || tracemonkeyFileName));
63
+ const pdfDocument = await loadingTask.promise;
64
+ const eventBus = new _ui_utils.EventBus();
65
+ const linkService = new MockLinkService();
66
+ linkService.setDocument(pdfDocument);
67
+ const pdfFindController = new _pdf_find_controller.PDFFindController({
68
+ linkService,
69
+ eventBus
79
70
  });
71
+ pdfFindController.setDocument(pdfDocument);
72
+ return {
73
+ eventBus,
74
+ pdfFindController
75
+ };
76
+ }
80
77
 
81
- function testSearch({
82
- parameters,
83
- matchesPerPage,
84
- selectedMatch
85
- }) {
86
- return new Promise(function (resolve) {
87
- pdfFindController.executeCommand("find", parameters);
88
- let totalPages = matchesPerPage.length;
89
-
90
- for (let i = totalPages - 1; i >= 0; i--) {
91
- if (matchesPerPage[i] > 0) {
92
- totalPages = i + 1;
93
- break;
94
- }
78
+ function testSearch({
79
+ eventBus,
80
+ pdfFindController,
81
+ parameters,
82
+ matchesPerPage,
83
+ selectedMatch,
84
+ pageMatches = null,
85
+ pageMatchesLength = null
86
+ }) {
87
+ return new Promise(function (resolve) {
88
+ pdfFindController.executeCommand("find", parameters);
89
+ let totalPages = matchesPerPage.length;
90
+
91
+ for (let i = totalPages - 1; i >= 0; i--) {
92
+ if (matchesPerPage[i] > 0) {
93
+ totalPages = i + 1;
94
+ break;
95
95
  }
96
+ }
96
97
 
97
- const totalMatches = matchesPerPage.reduce((a, b) => {
98
- return a + b;
99
- });
100
- eventBus.on("updatefindmatchescount", function onUpdateFindMatchesCount(evt) {
101
- if (pdfFindController.pageMatches.length !== totalPages) {
102
- return;
103
- }
104
-
105
- eventBus.off("updatefindmatchescount", onUpdateFindMatchesCount);
106
- expect(evt.matchesCount.total).toBe(totalMatches);
107
-
108
- for (let i = 0; i < totalPages; i++) {
109
- expect(pdfFindController.pageMatches[i].length).toEqual(matchesPerPage[i]);
110
- }
111
-
112
- expect(pdfFindController.selected.pageIdx).toEqual(selectedMatch.pageIndex);
113
- expect(pdfFindController.selected.matchIdx).toEqual(selectedMatch.matchIndex);
114
- resolve();
115
- });
98
+ const totalMatches = matchesPerPage.reduce((a, b) => {
99
+ return a + b;
116
100
  });
117
- }
101
+ eventBus.on("updatefindmatchescount", function onUpdateFindMatchesCount(evt) {
102
+ if (pdfFindController.pageMatches.length !== totalPages) {
103
+ return;
104
+ }
105
+
106
+ eventBus.off("updatefindmatchescount", onUpdateFindMatchesCount);
107
+ expect(evt.matchesCount.total).toBe(totalMatches);
108
+
109
+ for (let i = 0; i < totalPages; i++) {
110
+ expect(pdfFindController.pageMatches[i].length).toEqual(matchesPerPage[i]);
111
+ }
112
+
113
+ expect(pdfFindController.selected.pageIdx).toEqual(selectedMatch.pageIndex);
114
+ expect(pdfFindController.selected.matchIdx).toEqual(selectedMatch.matchIndex);
115
+
116
+ if (pageMatches) {
117
+ expect(pdfFindController.pageMatches).toEqual(pageMatches);
118
+ expect(pdfFindController.pageMatchesLength).toEqual(pageMatchesLength);
119
+ }
120
+
121
+ resolve();
122
+ });
123
+ });
124
+ }
118
125
 
119
- it("performs a normal search", function (done) {
120
- testSearch({
126
+ describe("pdf_find_controller", function () {
127
+ it("performs a normal search", async function () {
128
+ const {
129
+ eventBus,
130
+ pdfFindController
131
+ } = await initPdfFindController();
132
+ await testSearch({
133
+ eventBus,
134
+ pdfFindController,
121
135
  parameters: {
122
136
  query: "Dynamic",
123
137
  caseSensitive: false,
@@ -130,10 +144,16 @@ describe("pdf_find_controller", function () {
130
144
  pageIndex: 0,
131
145
  matchIndex: 0
132
146
  }
133
- }).then(done);
147
+ });
134
148
  });
135
- it("performs a normal search and finds the previous result", function (done) {
136
- testSearch({
149
+ it("performs a normal search and finds the previous result", async function () {
150
+ const {
151
+ eventBus,
152
+ pdfFindController
153
+ } = await initPdfFindController();
154
+ await testSearch({
155
+ eventBus,
156
+ pdfFindController,
137
157
  parameters: {
138
158
  query: "conference",
139
159
  caseSensitive: false,
@@ -146,10 +166,16 @@ describe("pdf_find_controller", function () {
146
166
  pageIndex: 13,
147
167
  matchIndex: 4
148
168
  }
149
- }).then(done);
169
+ });
150
170
  });
151
- it("performs a case sensitive search", function (done) {
152
- testSearch({
171
+ it("performs a case sensitive search", async function () {
172
+ const {
173
+ eventBus,
174
+ pdfFindController
175
+ } = await initPdfFindController();
176
+ await testSearch({
177
+ eventBus,
178
+ pdfFindController,
153
179
  parameters: {
154
180
  query: "Dynamic",
155
181
  caseSensitive: true,
@@ -162,10 +188,16 @@ describe("pdf_find_controller", function () {
162
188
  pageIndex: 0,
163
189
  matchIndex: 0
164
190
  }
165
- }).then(done);
191
+ });
166
192
  });
167
- it("performs an entire word search", function (done) {
168
- testSearch({
193
+ it("performs an entire word search", async function () {
194
+ const {
195
+ eventBus,
196
+ pdfFindController
197
+ } = await initPdfFindController();
198
+ await testSearch({
199
+ eventBus,
200
+ pdfFindController,
169
201
  parameters: {
170
202
  query: "Government",
171
203
  caseSensitive: false,
@@ -178,10 +210,16 @@ describe("pdf_find_controller", function () {
178
210
  pageIndex: 12,
179
211
  matchIndex: 0
180
212
  }
181
- }).then(done);
213
+ });
182
214
  });
183
- it("performs a multiple term (no phrase) search", function (done) {
184
- testSearch({
215
+ it("performs a multiple term (no phrase) search", async function () {
216
+ const {
217
+ eventBus,
218
+ pdfFindController
219
+ } = await initPdfFindController();
220
+ await testSearch({
221
+ eventBus,
222
+ pdfFindController,
185
223
  parameters: {
186
224
  query: "alternate solution",
187
225
  caseSensitive: false,
@@ -194,6 +232,30 @@ describe("pdf_find_controller", function () {
194
232
  pageIndex: 5,
195
233
  matchIndex: 0
196
234
  }
197
- }).then(done);
235
+ });
236
+ });
237
+ it("performs a normal search, where the text is normalized", async function () {
238
+ const {
239
+ eventBus,
240
+ pdfFindController
241
+ } = await initPdfFindController("fraction-highlight.pdf");
242
+ await testSearch({
243
+ eventBus,
244
+ pdfFindController,
245
+ parameters: {
246
+ query: "fraction",
247
+ caseSensitive: false,
248
+ entireWord: false,
249
+ phraseSearch: true,
250
+ findPrevious: false
251
+ },
252
+ matchesPerPage: [3],
253
+ selectedMatch: {
254
+ pageIndex: 0,
255
+ matchIndex: 0
256
+ },
257
+ pageMatches: [[19, 48, 66]],
258
+ pageMatchesLength: [[8, 8, 8]]
259
+ });
198
260
  });
199
261
  });
@@ -29,10 +29,10 @@ describe("pdf_find_utils", function () {
29
29
  const characters = {
30
30
  A: _pdf_find_utils.CharacterType.ALPHA_LETTER,
31
31
  a: _pdf_find_utils.CharacterType.ALPHA_LETTER,
32
- "0": _pdf_find_utils.CharacterType.ALPHA_LETTER,
33
- "5": _pdf_find_utils.CharacterType.ALPHA_LETTER,
34
- Ä: _pdf_find_utils.CharacterType.ALPHA_LETTER,
35
- ä: _pdf_find_utils.CharacterType.ALPHA_LETTER,
32
+ 0: _pdf_find_utils.CharacterType.ALPHA_LETTER,
33
+ 5: _pdf_find_utils.CharacterType.ALPHA_LETTER,
34
+ "\xC4": _pdf_find_utils.CharacterType.ALPHA_LETTER,
35
+ "\xE4": _pdf_find_utils.CharacterType.ALPHA_LETTER,
36
36
  _: _pdf_find_utils.CharacterType.ALPHA_LETTER,
37
37
  " ": _pdf_find_utils.CharacterType.SPACE,
38
38
  "\t": _pdf_find_utils.CharacterType.SPACE,
@@ -45,12 +45,12 @@ describe("pdf_find_utils", function () {
45
45
  ";": _pdf_find_utils.CharacterType.PUNCT,
46
46
  ":": _pdf_find_utils.CharacterType.PUNCT,
47
47
  "\u2122": _pdf_find_utils.CharacterType.ALPHA_LETTER,
48
- ล: _pdf_find_utils.CharacterType.THAI_LETTER,
49
- 䀀: _pdf_find_utils.CharacterType.HAN_LETTER,
50
- 縷: _pdf_find_utils.CharacterType.HAN_LETTER,
51
- ダ: _pdf_find_utils.CharacterType.KATAKANA_LETTER,
52
- ぐ: _pdf_find_utils.CharacterType.HIRAGANA_LETTER,
53
- タ: _pdf_find_utils.CharacterType.HALFWIDTH_KATAKANA_LETTER
48
+ "\u0E25": _pdf_find_utils.CharacterType.THAI_LETTER,
49
+ "\u4000": _pdf_find_utils.CharacterType.HAN_LETTER,
50
+ "\uF950": _pdf_find_utils.CharacterType.HAN_LETTER,
51
+ "\u30C0": _pdf_find_utils.CharacterType.KATAKANA_LETTER,
52
+ "\u3050": _pdf_find_utils.CharacterType.HIRAGANA_LETTER,
53
+ "\uFF80": _pdf_find_utils.CharacterType.HALFWIDTH_KATAKANA_LETTER
54
54
  };
55
55
 
56
56
  for (const character in characters) {