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
@@ -25,16 +25,16 @@ var _bidi = require("../../core/bidi.js");
25
25
 
26
26
  describe("bidi", function () {
27
27
  it("should mark text as RTL if more than 30% of text is RTL", function () {
28
- var test = "\u0645\u0635\u0631 Egypt";
29
- var result = "Egypt \u0631\u0635\u0645";
30
- var bidiText = (0, _bidi.bidi)(test, -1, false);
28
+ const test = "\u0645\u0635\u0631 Egypt";
29
+ const result = "Egypt \u0631\u0635\u0645";
30
+ const bidiText = (0, _bidi.bidi)(test, -1, false);
31
31
  expect(bidiText.str).toEqual(result);
32
32
  expect(bidiText.dir).toEqual("rtl");
33
33
  });
34
34
  it("should mark text as LTR if less than 30% of text is RTL", function () {
35
- var test = "Egypt is known as \u0645\u0635\u0631 in Arabic.";
36
- var result = "Egypt is known as \u0631\u0635\u0645 in Arabic.";
37
- var bidiText = (0, _bidi.bidi)(test, -1, false);
35
+ const test = "Egypt is known as \u0645\u0635\u0631 in Arabic.";
36
+ const result = "Egypt is known as \u0631\u0635\u0645 in Arabic.";
37
+ const bidiText = (0, _bidi.bidi)(test, -1, false);
38
38
  expect(bidiText.str).toEqual(result);
39
39
  expect(bidiText.dir).toEqual("ltr");
40
40
  });
@@ -29,28 +29,28 @@ var _stream = require("../../core/stream.js");
29
29
 
30
30
  describe("CFFParser", function () {
31
31
  function createWithNullProto(obj) {
32
- var result = Object.create(null);
32
+ const result = Object.create(null);
33
33
 
34
- for (var i in obj) {
34
+ for (const i in obj) {
35
35
  result[i] = obj[i];
36
36
  }
37
37
 
38
38
  return result;
39
39
  }
40
40
 
41
- var privateDictStub = {
41
+ const privateDictStub = {
42
42
  getByName(name) {
43
43
  return 0;
44
44
  }
45
45
 
46
46
  };
47
- var fontData, parser, cff;
47
+ let fontData, parser, cff;
48
48
  beforeAll(function (done) {
49
- var exampleFont = "0100040100010101134142434445462b" + "54696d65732d526f6d616e000101011f" + "f81b00f81c02f81d03f819041c6f000d" + "fb3cfb6efa7cfa1605e911b8f1120003" + "01010813183030312e30303754696d65" + "7320526f6d616e54696d657300000002" + "010102030e0e7d99f92a99fb7695f773" + "8b06f79a93fc7c8c077d99f85695f75e" + "9908fb6e8cf87393f7108b09a70adf0b" + "f78e14";
50
- var fontArr = [];
49
+ const exampleFont = "0100040100010101134142434445462b" + "54696d65732d526f6d616e000101011f" + "f81b00f81c02f81d03f819041c6f000d" + "fb3cfb6efa7cfa1605e911b8f1120003" + "01010813183030312e30303754696d65" + "7320526f6d616e54696d657300000002" + "010102030e0e7d99f92a99fb7695f773" + "8b06f79a93fc7c8c077d99f85695f75e" + "9908fb6e8cf87393f7108b09a70adf0b" + "f78e14";
50
+ const fontArr = [];
51
51
 
52
- for (var i = 0, ii = exampleFont.length; i < ii; i += 2) {
53
- var hex = exampleFont.substring(i, i + 2);
52
+ for (let i = 0, ii = exampleFont.length; i < ii; i += 2) {
53
+ const hex = exampleFont.substring(i, i + 2);
54
54
  fontArr.push(parseInt(hex, 16));
55
55
  }
56
56
 
@@ -70,25 +70,25 @@ describe("CFFParser", function () {
70
70
  done();
71
71
  });
72
72
  it("parses header", function () {
73
- var header = cff.header;
73
+ const header = cff.header;
74
74
  expect(header.major).toEqual(1);
75
75
  expect(header.minor).toEqual(0);
76
76
  expect(header.hdrSize).toEqual(4);
77
77
  expect(header.offSize).toEqual(1);
78
78
  });
79
79
  it("parses name index", function () {
80
- var names = cff.names;
80
+ const names = cff.names;
81
81
  expect(names.length).toEqual(1);
82
82
  expect(names[0]).toEqual("ABCDEF+Times-Roman");
83
83
  });
84
84
  it("parses string index", function () {
85
- var strings = cff.strings;
85
+ const strings = cff.strings;
86
86
  expect(strings.count).toEqual(3);
87
87
  expect(strings.get(0)).toEqual(".notdef");
88
88
  expect(strings.get(391)).toEqual("001.007");
89
89
  });
90
90
  it("parses top dict", function () {
91
- var topDict = cff.topDict;
91
+ const topDict = cff.topDict;
92
92
  expect(topDict.getByName("version")).toEqual(391);
93
93
  expect(topDict.getByName("FullName")).toEqual(392);
94
94
  expect(topDict.getByName("FamilyName")).toEqual(393);
@@ -99,30 +99,30 @@ describe("CFFParser", function () {
99
99
  expect(topDict.getByName("Private")).toEqual([45, 102]);
100
100
  });
101
101
  it("refuses to add topDict key with invalid value (bug 1068432)", function () {
102
- var topDict = cff.topDict;
103
- var defaultValue = topDict.getByName("UnderlinePosition");
102
+ const topDict = cff.topDict;
103
+ const defaultValue = topDict.getByName("UnderlinePosition");
104
104
  topDict.setByKey(3075, [NaN]);
105
105
  expect(topDict.getByName("UnderlinePosition")).toEqual(defaultValue);
106
106
  });
107
107
  it("ignores reserved commands in parseDict, and refuses to add privateDict " + "keys with invalid values (bug 1308536)", function () {
108
- var bytes = new Uint8Array([64, 39, 31, 30, 252, 114, 137, 115, 79, 30, 197, 119, 2, 99, 127, 6]);
108
+ const bytes = new Uint8Array([64, 39, 31, 30, 252, 114, 137, 115, 79, 30, 197, 119, 2, 99, 127, 6]);
109
109
  parser.bytes = bytes;
110
- var topDict = cff.topDict;
110
+ const topDict = cff.topDict;
111
111
  topDict.setByName("Private", [bytes.length, 0]);
112
112
 
113
- var parsePrivateDict = function () {
113
+ const parsePrivateDict = function () {
114
114
  parser.parsePrivateDict(topDict);
115
115
  };
116
116
 
117
117
  expect(parsePrivateDict).not.toThrow();
118
- var privateDict = topDict.privateDict;
118
+ const privateDict = topDict.privateDict;
119
119
  expect(privateDict.getByName("BlueValues")).toBeNull();
120
120
  });
121
121
  it("parses a CharString having cntrmask", function () {
122
- var bytes = new Uint8Array([0, 1, 1, 0, 38, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 1, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 3, 20, 22, 22, 14]);
122
+ const bytes = new Uint8Array([0, 1, 1, 0, 38, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 1, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 3, 20, 22, 22, 14]);
123
123
  parser.bytes = bytes;
124
- var charStringsIndex = parser.parseIndex(0).obj;
125
- var charStrings = parser.parseCharStrings({
124
+ const charStringsIndex = parser.parseIndex(0).obj;
125
+ const charStrings = parser.parseCharStrings({
126
126
  charStrings: charStringsIndex,
127
127
  privateDict: privateDictStub
128
128
  }).charStrings;
@@ -132,10 +132,10 @@ describe("CFFParser", function () {
132
132
  it("parses a CharString endchar with 4 args w/seac enabled", function () {
133
133
  const cffParser = new _cff_parser.CFFParser(fontData, {}, true);
134
134
  cffParser.parse();
135
- var bytes = new Uint8Array([0, 1, 1, 0, 237, 247, 22, 247, 72, 204, 247, 86, 14]);
135
+ const bytes = new Uint8Array([0, 1, 1, 0, 237, 247, 22, 247, 72, 204, 247, 86, 14]);
136
136
  cffParser.bytes = bytes;
137
- var charStringsIndex = cffParser.parseIndex(0).obj;
138
- var result = cffParser.parseCharStrings({
137
+ const charStringsIndex = cffParser.parseIndex(0).obj;
138
+ const result = cffParser.parseCharStrings({
139
139
  charStrings: charStringsIndex,
140
140
  privateDict: privateDictStub
141
141
  });
@@ -151,10 +151,10 @@ describe("CFFParser", function () {
151
151
  it("parses a CharString endchar with 4 args w/seac disabled", function () {
152
152
  const cffParser = new _cff_parser.CFFParser(fontData, {}, false);
153
153
  cffParser.parse();
154
- var bytes = new Uint8Array([0, 1, 1, 0, 237, 247, 22, 247, 72, 204, 247, 86, 14]);
154
+ const bytes = new Uint8Array([0, 1, 1, 0, 237, 247, 22, 247, 72, 204, 247, 86, 14]);
155
155
  cffParser.bytes = bytes;
156
- var charStringsIndex = cffParser.parseIndex(0).obj;
157
- var result = cffParser.parseCharStrings({
156
+ const charStringsIndex = cffParser.parseIndex(0).obj;
157
+ const result = cffParser.parseCharStrings({
158
158
  charStrings: charStringsIndex,
159
159
  privateDict: privateDictStub
160
160
  });
@@ -163,10 +163,10 @@ describe("CFFParser", function () {
163
163
  expect(result.seacs.length).toEqual(0);
164
164
  });
165
165
  it("parses a CharString endchar no args", function () {
166
- var bytes = new Uint8Array([0, 1, 1, 0, 14]);
166
+ const bytes = new Uint8Array([0, 1, 1, 0, 14]);
167
167
  parser.bytes = bytes;
168
- var charStringsIndex = parser.parseIndex(0).obj;
169
- var result = parser.parseCharStrings({
168
+ const charStringsIndex = parser.parseIndex(0).obj;
169
+ const result = parser.parseCharStrings({
170
170
  charStrings: charStringsIndex,
171
171
  privateDict: privateDictStub
172
172
  });
@@ -175,68 +175,68 @@ describe("CFFParser", function () {
175
175
  expect(result.seacs.length).toEqual(0);
176
176
  });
177
177
  it("parses predefined charsets", function () {
178
- var charset = parser.parseCharsets(0, 0, null, true);
178
+ const charset = parser.parseCharsets(0, 0, null, true);
179
179
  expect(charset.predefined).toEqual(true);
180
180
  });
181
181
  it("parses charset format 0", function () {
182
- var bytes = new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x02]);
182
+ const bytes = new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x02]);
183
183
  parser.bytes = bytes;
184
- var charset = parser.parseCharsets(3, 2, new _cff_parser.CFFStrings(), false);
184
+ let charset = parser.parseCharsets(3, 2, new _cff_parser.CFFStrings(), false);
185
185
  expect(charset.charset[1]).toEqual("exclam");
186
186
  charset = parser.parseCharsets(3, 2, new _cff_parser.CFFStrings(), true);
187
187
  expect(charset.charset[1]).toEqual(2);
188
188
  });
189
189
  it("parses charset format 1", function () {
190
- var bytes = new Uint8Array([0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x01]);
190
+ const bytes = new Uint8Array([0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x01]);
191
191
  parser.bytes = bytes;
192
- var charset = parser.parseCharsets(3, 2, new _cff_parser.CFFStrings(), false);
192
+ let charset = parser.parseCharsets(3, 2, new _cff_parser.CFFStrings(), false);
193
193
  expect(charset.charset).toEqual([".notdef", "quoteright", "parenleft"]);
194
194
  charset = parser.parseCharsets(3, 2, new _cff_parser.CFFStrings(), true);
195
195
  expect(charset.charset).toEqual([0, 8, 9]);
196
196
  });
197
197
  it("parses charset format 2", function () {
198
- var bytes = new Uint8Array([0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0x00, 0x01]);
198
+ const bytes = new Uint8Array([0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0x00, 0x01]);
199
199
  parser.bytes = bytes;
200
- var charset = parser.parseCharsets(3, 2, new _cff_parser.CFFStrings(), false);
200
+ let charset = parser.parseCharsets(3, 2, new _cff_parser.CFFStrings(), false);
201
201
  expect(charset.charset).toEqual([".notdef", "quoteright", "parenleft"]);
202
202
  charset = parser.parseCharsets(3, 2, new _cff_parser.CFFStrings(), true);
203
203
  expect(charset.charset).toEqual([0, 8, 9]);
204
204
  });
205
205
  it("parses encoding format 0", function () {
206
- var bytes = new Uint8Array([0x00, 0x00, 0x00, 0x01, 0x08]);
206
+ const bytes = new Uint8Array([0x00, 0x00, 0x00, 0x01, 0x08]);
207
207
  parser.bytes = bytes;
208
- var encoding = parser.parseEncoding(2, {}, new _cff_parser.CFFStrings(), null);
208
+ const encoding = parser.parseEncoding(2, {}, new _cff_parser.CFFStrings(), null);
209
209
  expect(encoding.encoding).toEqual(createWithNullProto({
210
210
  0x8: 1
211
211
  }));
212
212
  });
213
213
  it("parses encoding format 1", function () {
214
- var bytes = new Uint8Array([0x00, 0x00, 0x01, 0x01, 0x07, 0x01]);
214
+ const bytes = new Uint8Array([0x00, 0x00, 0x01, 0x01, 0x07, 0x01]);
215
215
  parser.bytes = bytes;
216
- var encoding = parser.parseEncoding(2, {}, new _cff_parser.CFFStrings(), null);
216
+ const encoding = parser.parseEncoding(2, {}, new _cff_parser.CFFStrings(), null);
217
217
  expect(encoding.encoding).toEqual(createWithNullProto({
218
218
  0x7: 0x01,
219
219
  0x08: 0x02
220
220
  }));
221
221
  });
222
222
  it("parses fdselect format 0", function () {
223
- var bytes = new Uint8Array([0x00, 0x00, 0x01]);
223
+ const bytes = new Uint8Array([0x00, 0x00, 0x01]);
224
224
  parser.bytes = bytes.slice();
225
- var fdSelect = parser.parseFDSelect(0, 2);
225
+ const fdSelect = parser.parseFDSelect(0, 2);
226
226
  expect(fdSelect.fdSelect).toEqual([0, 1]);
227
227
  expect(fdSelect.format).toEqual(0);
228
228
  });
229
229
  it("parses fdselect format 3", function () {
230
- var bytes = new Uint8Array([0x03, 0x00, 0x02, 0x00, 0x00, 0x09, 0x00, 0x02, 0x0a, 0x00, 0x04]);
230
+ const bytes = new Uint8Array([0x03, 0x00, 0x02, 0x00, 0x00, 0x09, 0x00, 0x02, 0x0a, 0x00, 0x04]);
231
231
  parser.bytes = bytes.slice();
232
- var fdSelect = parser.parseFDSelect(0, 4);
232
+ const fdSelect = parser.parseFDSelect(0, 4);
233
233
  expect(fdSelect.fdSelect).toEqual([9, 9, 0xa, 0xa]);
234
234
  expect(fdSelect.format).toEqual(3);
235
235
  });
236
236
  it("parses invalid fdselect format 3 (bug 1146106)", function () {
237
- var bytes = new Uint8Array([0x03, 0x00, 0x02, 0x00, 0x01, 0x09, 0x00, 0x02, 0x0a, 0x00, 0x04]);
237
+ const bytes = new Uint8Array([0x03, 0x00, 0x02, 0x00, 0x01, 0x09, 0x00, 0x02, 0x0a, 0x00, 0x04]);
238
238
  parser.bytes = bytes.slice();
239
- var fdSelect = parser.parseFDSelect(0, 4);
239
+ const fdSelect = parser.parseFDSelect(0, 4);
240
240
  expect(fdSelect.fdSelect).toEqual([9, 9, 0xa, 0xa]);
241
241
  expect(fdSelect.format).toEqual(3);
242
242
  });
@@ -252,7 +252,7 @@ describe("CFFCompiler", function () {
252
252
  }
253
253
 
254
254
  it("encodes integers", function () {
255
- var c = new _cff_parser.CFFCompiler();
255
+ const c = new _cff_parser.CFFCompiler();
256
256
  expect(c.encodeInteger(0)).toEqual([0x8b]);
257
257
  expect(c.encodeInteger(100)).toEqual([0xef]);
258
258
  expect(c.encodeInteger(-100)).toEqual([0x27]);
@@ -264,20 +264,20 @@ describe("CFFCompiler", function () {
264
264
  expect(c.encodeInteger(-100000)).toEqual([0x1d, 0xff, 0xfe, 0x79, 0x60]);
265
265
  });
266
266
  it("encodes floats", function () {
267
- var c = new _cff_parser.CFFCompiler();
267
+ const c = new _cff_parser.CFFCompiler();
268
268
  expect(c.encodeFloat(-2.25)).toEqual([0x1e, 0xe2, 0xa2, 0x5f]);
269
269
  expect(c.encodeFloat(5e-11)).toEqual([0x1e, 0x5c, 0x11, 0xff]);
270
270
  });
271
271
  it("sanitizes name index", function () {
272
- var c = new _cff_parser.CFFCompiler();
273
- var nameIndexCompiled = c.compileNameIndex(["[a"]);
274
- var parser = testParser(nameIndexCompiled);
275
- var nameIndex = parser.parseIndex(0);
276
- var names = parser.parseNameIndex(nameIndex.obj);
272
+ const c = new _cff_parser.CFFCompiler();
273
+ let nameIndexCompiled = c.compileNameIndex(["[a"]);
274
+ let parser = testParser(nameIndexCompiled);
275
+ let nameIndex = parser.parseIndex(0);
276
+ let names = parser.parseNameIndex(nameIndex.obj);
277
277
  expect(names).toEqual(["_a"]);
278
- var longName = "";
278
+ let longName = "";
279
279
 
280
- for (var i = 0; i < 129; i++) {
280
+ for (let i = 0; i < 129; i++) {
281
281
  longName += "_";
282
282
  }
283
283
 
@@ -288,35 +288,35 @@ describe("CFFCompiler", function () {
288
288
  expect(names[0].length).toEqual(127);
289
289
  });
290
290
  it("compiles fdselect format 0", function () {
291
- var fdSelect = new _cff_parser.CFFFDSelect(0, [3, 2, 1]);
292
- var c = new _cff_parser.CFFCompiler();
293
- var out = c.compileFDSelect(fdSelect);
291
+ const fdSelect = new _cff_parser.CFFFDSelect(0, [3, 2, 1]);
292
+ const c = new _cff_parser.CFFCompiler();
293
+ const out = c.compileFDSelect(fdSelect);
294
294
  expect(out).toEqual([0, 3, 2, 1]);
295
295
  });
296
296
  it("compiles fdselect format 3", function () {
297
- var fdSelect = new _cff_parser.CFFFDSelect(3, [0, 0, 1, 1]);
298
- var c = new _cff_parser.CFFCompiler();
299
- var out = c.compileFDSelect(fdSelect);
297
+ const fdSelect = new _cff_parser.CFFFDSelect(3, [0, 0, 1, 1]);
298
+ const c = new _cff_parser.CFFCompiler();
299
+ const out = c.compileFDSelect(fdSelect);
300
300
  expect(out).toEqual([3, 0, 2, 0, 0, 0, 0, 2, 1, 0, 4]);
301
301
  });
302
302
  it("compiles fdselect format 3, single range", function () {
303
- var fdSelect = new _cff_parser.CFFFDSelect(3, [0, 0]);
304
- var c = new _cff_parser.CFFCompiler();
305
- var out = c.compileFDSelect(fdSelect);
303
+ const fdSelect = new _cff_parser.CFFFDSelect(3, [0, 0]);
304
+ const c = new _cff_parser.CFFCompiler();
305
+ const out = c.compileFDSelect(fdSelect);
306
306
  expect(out).toEqual([3, 0, 1, 0, 0, 0, 0, 2]);
307
307
  });
308
308
  it("compiles charset of CID font", function () {
309
- var charset = new _cff_parser.CFFCharset();
310
- var c = new _cff_parser.CFFCompiler();
311
- var numGlyphs = 7;
312
- var out = c.compileCharset(charset, numGlyphs, new _cff_parser.CFFStrings(), true);
309
+ const charset = new _cff_parser.CFFCharset();
310
+ const c = new _cff_parser.CFFCompiler();
311
+ const numGlyphs = 7;
312
+ const out = c.compileCharset(charset, numGlyphs, new _cff_parser.CFFStrings(), true);
313
313
  expect(out).toEqual([2, 0, 0, 0, numGlyphs - 1]);
314
314
  });
315
315
  it("compiles charset of non CID font", function () {
316
- var charset = new _cff_parser.CFFCharset(false, 0, ["space", "exclam"]);
317
- var c = new _cff_parser.CFFCompiler();
318
- var numGlyphs = 3;
319
- var out = c.compileCharset(charset, numGlyphs, new _cff_parser.CFFStrings(), false);
316
+ const charset = new _cff_parser.CFFCharset(false, 0, ["space", "exclam"]);
317
+ const c = new _cff_parser.CFFCompiler();
318
+ const numGlyphs = 3;
319
+ const out = c.compileCharset(charset, numGlyphs, new _cff_parser.CFFStrings(), false);
320
320
  expect(out).toEqual([0, 0, 1, 0, 2]);
321
321
  });
322
322
  });
@@ -29,6 +29,8 @@ var _node_stream = require("../../display/node_stream.js");
29
29
 
30
30
  var _api = require("../../display/api.js");
31
31
 
32
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
33
+
32
34
  if (!_is_node.isNodeJS) {
33
35
  throw new Error("The `gulp unittestcli` command can only be used in Node.js environments.");
34
36
  }
@@ -23,37 +23,21 @@
23
23
 
24
24
  var _cmap = require("../../core/cmap.js");
25
25
 
26
- var _display_utils = require("../../display/display_utils.js");
26
+ var _test_utils = require("./test_utils.js");
27
27
 
28
- var _is_node = require("../../shared/is_node.js");
28
+ var _api = require("../../display/api.js");
29
29
 
30
30
  var _primitives = require("../../core/primitives.js");
31
31
 
32
- var _node_utils = require("../../display/node_utils.js");
33
-
34
32
  var _stream = require("../../core/stream.js");
35
33
 
36
- var cMapUrl = {
37
- dom: "../../external/bcmaps/",
38
- node: "./external/bcmaps/"
39
- };
40
- var cMapPacked = true;
41
34
  describe("cmap", function () {
42
- var fetchBuiltInCMap;
35
+ let fetchBuiltInCMap;
43
36
  beforeAll(function (done) {
44
- var CMapReaderFactory;
45
-
46
- if (_is_node.isNodeJS) {
47
- CMapReaderFactory = new _node_utils.NodeCMapReaderFactory({
48
- baseUrl: cMapUrl.node,
49
- isCompressed: cMapPacked
50
- });
51
- } else {
52
- CMapReaderFactory = new _display_utils.DOMCMapReaderFactory({
53
- baseUrl: cMapUrl.dom,
54
- isCompressed: cMapPacked
55
- });
56
- }
37
+ const CMapReaderFactory = new _api.DefaultCMapReaderFactory({
38
+ baseUrl: _test_utils.CMAP_PARAMS.cMapUrl,
39
+ isCompressed: _test_utils.CMAP_PARAMS.cMapPacked
40
+ });
57
41
 
58
42
  fetchBuiltInCMap = function (name) {
59
43
  return CMapReaderFactory.fetch({
@@ -67,10 +51,10 @@ describe("cmap", function () {
67
51
  fetchBuiltInCMap = null;
68
52
  });
69
53
  it("parses beginbfchar", function (done) {
70
- var str = "2 beginbfchar\n" + "<03> <00>\n" + "<04> <01>\n" + "endbfchar\n";
71
- var stream = new _stream.StringStream(str);
54
+ const str = "2 beginbfchar\n" + "<03> <00>\n" + "<04> <01>\n" + "endbfchar\n";
55
+ const stream = new _stream.StringStream(str);
72
56
 
73
- var cmapPromise = _cmap.CMapFactory.create({
57
+ const cmapPromise = _cmap.CMapFactory.create({
74
58
  encoding: stream
75
59
  });
76
60
 
@@ -84,10 +68,10 @@ describe("cmap", function () {
84
68
  });
85
69
  });
86
70
  it("parses beginbfrange with range", function (done) {
87
- var str = "1 beginbfrange\n" + "<06> <0B> 0\n" + "endbfrange\n";
88
- var stream = new _stream.StringStream(str);
71
+ const str = "1 beginbfrange\n" + "<06> <0B> 0\n" + "endbfrange\n";
72
+ const stream = new _stream.StringStream(str);
89
73
 
90
- var cmapPromise = _cmap.CMapFactory.create({
74
+ const cmapPromise = _cmap.CMapFactory.create({
91
75
  encoding: stream
92
76
  });
93
77
 
@@ -102,10 +86,10 @@ describe("cmap", function () {
102
86
  });
103
87
  });
104
88
  it("parses beginbfrange with array", function (done) {
105
- var str = "1 beginbfrange\n" + "<0D> <12> [ 0 1 2 3 4 5 ]\n" + "endbfrange\n";
106
- var stream = new _stream.StringStream(str);
89
+ const str = "1 beginbfrange\n" + "<0D> <12> [ 0 1 2 3 4 5 ]\n" + "endbfrange\n";
90
+ const stream = new _stream.StringStream(str);
107
91
 
108
- var cmapPromise = _cmap.CMapFactory.create({
92
+ const cmapPromise = _cmap.CMapFactory.create({
109
93
  encoding: stream
110
94
  });
111
95
 
@@ -120,10 +104,10 @@ describe("cmap", function () {
120
104
  });
121
105
  });
122
106
  it("parses begincidchar", function (done) {
123
- var str = "1 begincidchar\n" + "<14> 0\n" + "endcidchar\n";
124
- var stream = new _stream.StringStream(str);
107
+ const str = "1 begincidchar\n" + "<14> 0\n" + "endcidchar\n";
108
+ const stream = new _stream.StringStream(str);
125
109
 
126
- var cmapPromise = _cmap.CMapFactory.create({
110
+ const cmapPromise = _cmap.CMapFactory.create({
127
111
  encoding: stream
128
112
  });
129
113
 
@@ -136,10 +120,10 @@ describe("cmap", function () {
136
120
  });
137
121
  });
138
122
  it("parses begincidrange", function (done) {
139
- var str = "1 begincidrange\n" + "<0016> <001B> 0\n" + "endcidrange\n";
140
- var stream = new _stream.StringStream(str);
123
+ const str = "1 begincidrange\n" + "<0016> <001B> 0\n" + "endcidrange\n";
124
+ const stream = new _stream.StringStream(str);
141
125
 
142
- var cmapPromise = _cmap.CMapFactory.create({
126
+ const cmapPromise = _cmap.CMapFactory.create({
143
127
  encoding: stream
144
128
  });
145
129
 
@@ -154,15 +138,15 @@ describe("cmap", function () {
154
138
  });
155
139
  });
156
140
  it("decodes codespace ranges", function (done) {
157
- var str = "1 begincodespacerange\n" + "<01> <02>\n" + "<00000003> <00000004>\n" + "endcodespacerange\n";
158
- var stream = new _stream.StringStream(str);
141
+ const str = "1 begincodespacerange\n" + "<01> <02>\n" + "<00000003> <00000004>\n" + "endcodespacerange\n";
142
+ const stream = new _stream.StringStream(str);
159
143
 
160
- var cmapPromise = _cmap.CMapFactory.create({
144
+ const cmapPromise = _cmap.CMapFactory.create({
161
145
  encoding: stream
162
146
  });
163
147
 
164
148
  cmapPromise.then(function (cmap) {
165
- var c = {};
149
+ const c = {};
166
150
  cmap.readCharCode(String.fromCharCode(1), 0, c);
167
151
  expect(c.charcode).toEqual(1);
168
152
  expect(c.length).toEqual(1);
@@ -175,15 +159,15 @@ describe("cmap", function () {
175
159
  });
176
160
  });
177
161
  it("decodes 4 byte codespace ranges", function (done) {
178
- var str = "1 begincodespacerange\n" + "<8EA1A1A1> <8EA1FEFE>\n" + "endcodespacerange\n";
179
- var stream = new _stream.StringStream(str);
162
+ const str = "1 begincodespacerange\n" + "<8EA1A1A1> <8EA1FEFE>\n" + "endcodespacerange\n";
163
+ const stream = new _stream.StringStream(str);
180
164
 
181
- var cmapPromise = _cmap.CMapFactory.create({
165
+ const cmapPromise = _cmap.CMapFactory.create({
182
166
  encoding: stream
183
167
  });
184
168
 
185
169
  cmapPromise.then(function (cmap) {
186
- var c = {};
170
+ const c = {};
187
171
  cmap.readCharCode(String.fromCharCode(0x8e, 0xa1, 0xa1, 0xa1), 0, c);
188
172
  expect(c.charcode).toEqual(0x8ea1a1a1);
189
173
  expect(c.length).toEqual(4);
@@ -193,10 +177,10 @@ describe("cmap", function () {
193
177
  });
194
178
  });
195
179
  it("read usecmap", function (done) {
196
- var str = "/Adobe-Japan1-1 usecmap\n";
197
- var stream = new _stream.StringStream(str);
180
+ const str = "/Adobe-Japan1-1 usecmap\n";
181
+ const stream = new _stream.StringStream(str);
198
182
 
199
- var cmapPromise = _cmap.CMapFactory.create({
183
+ const cmapPromise = _cmap.CMapFactory.create({
200
184
  encoding: stream,
201
185
  fetchBuiltInCMap,
202
186
  useCMap: null
@@ -214,10 +198,10 @@ describe("cmap", function () {
214
198
  });
215
199
  });
216
200
  it("parses cmapname", function (done) {
217
- var str = "/CMapName /Identity-H def\n";
218
- var stream = new _stream.StringStream(str);
201
+ const str = "/CMapName /Identity-H def\n";
202
+ const stream = new _stream.StringStream(str);
219
203
 
220
- var cmapPromise = _cmap.CMapFactory.create({
204
+ const cmapPromise = _cmap.CMapFactory.create({
221
205
  encoding: stream
222
206
  });
223
207
 
@@ -229,10 +213,10 @@ describe("cmap", function () {
229
213
  });
230
214
  });
231
215
  it("parses wmode", function (done) {
232
- var str = "/WMode 1 def\n";
233
- var stream = new _stream.StringStream(str);
216
+ const str = "/WMode 1 def\n";
217
+ const stream = new _stream.StringStream(str);
234
218
 
235
- var cmapPromise = _cmap.CMapFactory.create({
219
+ const cmapPromise = _cmap.CMapFactory.create({
236
220
  encoding: stream
237
221
  });
238
222
 
@@ -244,7 +228,7 @@ describe("cmap", function () {
244
228
  });
245
229
  });
246
230
  it("loads built in cmap", function (done) {
247
- var cmapPromise = _cmap.CMapFactory.create({
231
+ const cmapPromise = _cmap.CMapFactory.create({
248
232
  encoding: _primitives.Name.get("Adobe-Japan1-1"),
249
233
  fetchBuiltInCMap,
250
234
  useCMap: null
@@ -262,7 +246,7 @@ describe("cmap", function () {
262
246
  });
263
247
  });
264
248
  it("loads built in identity cmap", function (done) {
265
- var cmapPromise = _cmap.CMapFactory.create({
249
+ const cmapPromise = _cmap.CMapFactory.create({
266
250
  encoding: _primitives.Name.get("Identity-H"),
267
251
  fetchBuiltInCMap,
268
252
  useCMap: null
@@ -281,7 +265,7 @@ describe("cmap", function () {
281
265
  });
282
266
  });
283
267
  it("attempts to load a non-existent built-in CMap", function (done) {
284
- var cmapPromise = _cmap.CMapFactory.create({
268
+ const cmapPromise = _cmap.CMapFactory.create({
285
269
  encoding: _primitives.Name.get("null"),
286
270
  fetchBuiltInCMap,
287
271
  useCMap: null
@@ -297,13 +281,13 @@ describe("cmap", function () {
297
281
  });
298
282
  it("attempts to load a built-in CMap without the necessary API parameters", function (done) {
299
283
  function tmpFetchBuiltInCMap(name) {
300
- var CMapReaderFactory = _is_node.isNodeJS ? new _node_utils.NodeCMapReaderFactory({}) : new _display_utils.DOMCMapReaderFactory({});
284
+ const CMapReaderFactory = new _api.DefaultCMapReaderFactory({});
301
285
  return CMapReaderFactory.fetch({
302
286
  name
303
287
  });
304
288
  }
305
289
 
306
- var cmapPromise = _cmap.CMapFactory.create({
290
+ const cmapPromise = _cmap.CMapFactory.create({
307
291
  encoding: _primitives.Name.get("Adobe-Japan1-1"),
308
292
  fetchBuiltInCMap: tmpFetchBuiltInCMap,
309
293
  useCMap: null
@@ -319,20 +303,10 @@ describe("cmap", function () {
319
303
  });
320
304
  it("attempts to load a built-in CMap with inconsistent API parameters", function (done) {
321
305
  function tmpFetchBuiltInCMap(name) {
322
- let CMapReaderFactory;
323
-
324
- if (_is_node.isNodeJS) {
325
- CMapReaderFactory = new _node_utils.NodeCMapReaderFactory({
326
- baseUrl: cMapUrl.node,
327
- isCompressed: false
328
- });
329
- } else {
330
- CMapReaderFactory = new _display_utils.DOMCMapReaderFactory({
331
- baseUrl: cMapUrl.dom,
332
- isCompressed: false
333
- });
334
- }
335
-
306
+ const CMapReaderFactory = new _api.DefaultCMapReaderFactory({
307
+ baseUrl: _test_utils.CMAP_PARAMS.cMapUrl,
308
+ isCompressed: false
309
+ });
336
310
  return CMapReaderFactory.fetch({
337
311
  name
338
312
  });
@@ -208,4 +208,38 @@ describe("core_utils", function () {
208
208
  expect((0, _core_utils.isWhiteSpace)(undefined)).toEqual(false);
209
209
  });
210
210
  });
211
+ describe("parseXFAPath", function () {
212
+ it("should get a correctly parsed path", function () {
213
+ const path = "foo.bar[12].oof[3].rab.FOO[123].BAR[456]";
214
+ expect((0, _core_utils.parseXFAPath)(path)).toEqual([{
215
+ name: "foo",
216
+ pos: 0
217
+ }, {
218
+ name: "bar",
219
+ pos: 12
220
+ }, {
221
+ name: "oof",
222
+ pos: 3
223
+ }, {
224
+ name: "rab",
225
+ pos: 0
226
+ }, {
227
+ name: "FOO",
228
+ pos: 123
229
+ }, {
230
+ name: "BAR",
231
+ pos: 456
232
+ }]);
233
+ });
234
+ });
235
+ describe("escapePDFName", function () {
236
+ it("should escape PDF name", function () {
237
+ expect((0, _core_utils.escapePDFName)("hello")).toEqual("hello");
238
+ expect((0, _core_utils.escapePDFName)("\xfehello")).toEqual("#fehello");
239
+ expect((0, _core_utils.escapePDFName)("he\xfell\xffo")).toEqual("he#fell#ffo");
240
+ expect((0, _core_utils.escapePDFName)("\xfehe\xfell\xffo\xff")).toEqual("#fehe#fell#ffo#ff");
241
+ expect((0, _core_utils.escapePDFName)("#h#e#l#l#o")).toEqual("#23h#23e#23l#23l#23o");
242
+ expect((0, _core_utils.escapePDFName)("#()<>[]{}/%")).toEqual("#23#28#29#3c#3e#5b#5d#7b#7d#2f#25");
243
+ });
244
+ });
211
245
  });