pdfjs-dist 2.0.943 → 2.4.456

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

Potentially problematic release.


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

Files changed (192) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8286 -14230
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +57878 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. package/lib/web/dom_events.js +0 -140
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2018 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,38 +19,42 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.Type1Parser = undefined;
27
+ exports.Type1Parser = void 0;
28
28
 
29
- var _util = require('../shared/util');
29
+ var _encodings = require("./encodings.js");
30
30
 
31
- var _encodings = require('./encodings');
31
+ var _core_utils = require("./core_utils.js");
32
32
 
33
- var _stream = require('./stream');
33
+ var _stream = require("./stream.js");
34
+
35
+ var _util = require("../shared/util.js");
34
36
 
35
37
  var HINTING_ENABLED = false;
38
+
36
39
  var Type1CharString = function Type1CharStringClosure() {
37
40
  var COMMAND_MAP = {
38
- 'hstem': [1],
39
- 'vstem': [3],
40
- 'vmoveto': [4],
41
- 'rlineto': [5],
42
- 'hlineto': [6],
43
- 'vlineto': [7],
44
- 'rrcurveto': [8],
45
- 'callsubr': [10],
46
- 'flex': [12, 35],
47
- 'drop': [12, 18],
48
- 'endchar': [14],
49
- 'rmoveto': [21],
50
- 'hmoveto': [22],
51
- 'vhcurveto': [30],
52
- 'hvcurveto': [31]
41
+ hstem: [1],
42
+ vstem: [3],
43
+ vmoveto: [4],
44
+ rlineto: [5],
45
+ hlineto: [6],
46
+ vlineto: [7],
47
+ rrcurveto: [8],
48
+ callsubr: [10],
49
+ flex: [12, 35],
50
+ drop: [12, 18],
51
+ endchar: [14],
52
+ rmoveto: [21],
53
+ hmoveto: [22],
54
+ vhcurveto: [30],
55
+ hvcurveto: [31]
53
56
  };
57
+
54
58
  function Type1CharString() {
55
59
  this.width = 0;
56
60
  this.lsb = 0;
@@ -58,78 +62,100 @@ var Type1CharString = function Type1CharStringClosure() {
58
62
  this.output = [];
59
63
  this.stack = [];
60
64
  }
65
+
61
66
  Type1CharString.prototype = {
62
67
  convert: function Type1CharString_convert(encoded, subrs, seacAnalysisEnabled) {
63
68
  var count = encoded.length;
64
69
  var error = false;
65
70
  var wx, sbx, subrNumber;
71
+
66
72
  for (var i = 0; i < count; i++) {
67
73
  var value = encoded[i];
74
+
68
75
  if (value < 32) {
69
76
  if (value === 12) {
70
77
  value = (value << 8) + encoded[++i];
71
78
  }
79
+
72
80
  switch (value) {
73
81
  case 1:
74
82
  if (!HINTING_ENABLED) {
75
83
  this.stack = [];
76
84
  break;
77
85
  }
86
+
78
87
  error = this.executeCommand(2, COMMAND_MAP.hstem);
79
88
  break;
89
+
80
90
  case 3:
81
91
  if (!HINTING_ENABLED) {
82
92
  this.stack = [];
83
93
  break;
84
94
  }
95
+
85
96
  error = this.executeCommand(2, COMMAND_MAP.vstem);
86
97
  break;
98
+
87
99
  case 4:
88
100
  if (this.flexing) {
89
101
  if (this.stack.length < 1) {
90
102
  error = true;
91
103
  break;
92
104
  }
105
+
93
106
  var dy = this.stack.pop();
94
107
  this.stack.push(0, dy);
95
108
  break;
96
109
  }
110
+
97
111
  error = this.executeCommand(1, COMMAND_MAP.vmoveto);
98
112
  break;
113
+
99
114
  case 5:
100
115
  error = this.executeCommand(2, COMMAND_MAP.rlineto);
101
116
  break;
117
+
102
118
  case 6:
103
119
  error = this.executeCommand(1, COMMAND_MAP.hlineto);
104
120
  break;
121
+
105
122
  case 7:
106
123
  error = this.executeCommand(1, COMMAND_MAP.vlineto);
107
124
  break;
125
+
108
126
  case 8:
109
127
  error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
110
128
  break;
129
+
111
130
  case 9:
112
131
  this.stack = [];
113
132
  break;
133
+
114
134
  case 10:
115
135
  if (this.stack.length < 1) {
116
136
  error = true;
117
137
  break;
118
138
  }
139
+
119
140
  subrNumber = this.stack.pop();
141
+
120
142
  if (!subrs[subrNumber]) {
121
143
  error = true;
122
144
  break;
123
145
  }
146
+
124
147
  error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
125
148
  break;
149
+
126
150
  case 11:
127
151
  return error;
152
+
128
153
  case 13:
129
154
  if (this.stack.length < 2) {
130
155
  error = true;
131
156
  break;
132
157
  }
158
+
133
159
  wx = this.stack.pop();
134
160
  sbx = this.stack.pop();
135
161
  this.lsb = sbx;
@@ -137,45 +163,58 @@ var Type1CharString = function Type1CharStringClosure() {
137
163
  this.stack.push(wx, sbx);
138
164
  error = this.executeCommand(2, COMMAND_MAP.hmoveto);
139
165
  break;
166
+
140
167
  case 14:
141
168
  this.output.push(COMMAND_MAP.endchar[0]);
142
169
  break;
170
+
143
171
  case 21:
144
172
  if (this.flexing) {
145
173
  break;
146
174
  }
175
+
147
176
  error = this.executeCommand(2, COMMAND_MAP.rmoveto);
148
177
  break;
178
+
149
179
  case 22:
150
180
  if (this.flexing) {
151
181
  this.stack.push(0);
152
182
  break;
153
183
  }
184
+
154
185
  error = this.executeCommand(1, COMMAND_MAP.hmoveto);
155
186
  break;
187
+
156
188
  case 30:
157
189
  error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
158
190
  break;
191
+
159
192
  case 31:
160
193
  error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
161
194
  break;
195
+
162
196
  case (12 << 8) + 0:
163
197
  this.stack = [];
164
198
  break;
199
+
165
200
  case (12 << 8) + 1:
166
201
  if (!HINTING_ENABLED) {
167
202
  this.stack = [];
168
203
  break;
169
204
  }
205
+
170
206
  error = this.executeCommand(2, COMMAND_MAP.vstem);
171
207
  break;
208
+
172
209
  case (12 << 8) + 2:
173
210
  if (!HINTING_ENABLED) {
174
211
  this.stack = [];
175
212
  break;
176
213
  }
214
+
177
215
  error = this.executeCommand(2, COMMAND_MAP.hstem);
178
216
  break;
217
+
179
218
  case (12 << 8) + 6:
180
219
  if (seacAnalysisEnabled) {
181
220
  this.seac = this.stack.splice(-4, 4);
@@ -183,12 +222,15 @@ var Type1CharString = function Type1CharStringClosure() {
183
222
  } else {
184
223
  error = this.executeCommand(4, COMMAND_MAP.endchar);
185
224
  }
225
+
186
226
  break;
227
+
187
228
  case (12 << 8) + 7:
188
229
  if (this.stack.length < 4) {
189
230
  error = true;
190
231
  break;
191
232
  }
233
+
192
234
  this.stack.pop();
193
235
  wx = this.stack.pop();
194
236
  var sby = this.stack.pop();
@@ -198,22 +240,27 @@ var Type1CharString = function Type1CharStringClosure() {
198
240
  this.stack.push(wx, sbx, sby);
199
241
  error = this.executeCommand(3, COMMAND_MAP.rmoveto);
200
242
  break;
243
+
201
244
  case (12 << 8) + 12:
202
245
  if (this.stack.length < 2) {
203
246
  error = true;
204
247
  break;
205
248
  }
249
+
206
250
  var num2 = this.stack.pop();
207
251
  var num1 = this.stack.pop();
208
252
  this.stack.push(num1 / num2);
209
253
  break;
254
+
210
255
  case (12 << 8) + 16:
211
256
  if (this.stack.length < 2) {
212
257
  error = true;
213
258
  break;
214
259
  }
260
+
215
261
  subrNumber = this.stack.pop();
216
262
  var numArgs = this.stack.pop();
263
+
217
264
  if (subrNumber === 0 && numArgs === 3) {
218
265
  var flexArgs = this.stack.splice(this.stack.length - 17, 17);
219
266
  this.stack.push(flexArgs[2] + flexArgs[0], flexArgs[3] + flexArgs[1], flexArgs[4], flexArgs[5], flexArgs[6], flexArgs[7], flexArgs[8], flexArgs[9], flexArgs[10], flexArgs[11], flexArgs[12], flexArgs[13], flexArgs[14]);
@@ -223,19 +270,25 @@ var Type1CharString = function Type1CharStringClosure() {
223
270
  } else if (subrNumber === 1 && numArgs === 0) {
224
271
  this.flexing = true;
225
272
  }
273
+
226
274
  break;
275
+
227
276
  case (12 << 8) + 17:
228
277
  break;
278
+
229
279
  case (12 << 8) + 33:
230
280
  this.stack = [];
231
281
  break;
282
+
232
283
  default:
233
284
  (0, _util.warn)('Unknown type 1 charstring command of "' + value + '"');
234
285
  break;
235
286
  }
287
+
236
288
  if (error) {
237
289
  break;
238
290
  }
291
+
239
292
  continue;
240
293
  } else if (value <= 246) {
241
294
  value = value - 139;
@@ -246,63 +299,83 @@ var Type1CharString = function Type1CharStringClosure() {
246
299
  } else {
247
300
  value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
248
301
  }
302
+
249
303
  this.stack.push(value);
250
304
  }
305
+
251
306
  return error;
252
307
  },
253
- executeCommand: function executeCommand(howManyArgs, command, keepStack) {
308
+
309
+ executeCommand(howManyArgs, command, keepStack) {
254
310
  var stackLength = this.stack.length;
311
+
255
312
  if (howManyArgs > stackLength) {
256
313
  return true;
257
314
  }
315
+
258
316
  var start = stackLength - howManyArgs;
317
+
259
318
  for (var i = start; i < stackLength; i++) {
260
319
  var value = this.stack[i];
320
+
261
321
  if (Number.isInteger(value)) {
262
322
  this.output.push(28, value >> 8 & 0xff, value & 0xff);
263
323
  } else {
264
324
  value = 65536 * value | 0;
265
- this.output.push(255, value >> 24 & 0xFF, value >> 16 & 0xFF, value >> 8 & 0xFF, value & 0xFF);
325
+ this.output.push(255, value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
266
326
  }
267
327
  }
328
+
268
329
  this.output.push.apply(this.output, command);
330
+
269
331
  if (keepStack) {
270
332
  this.stack.splice(start, howManyArgs);
271
333
  } else {
272
334
  this.stack.length = 0;
273
335
  }
336
+
274
337
  return false;
275
338
  }
339
+
276
340
  };
277
341
  return Type1CharString;
278
342
  }();
343
+
279
344
  var Type1Parser = function Type1ParserClosure() {
280
345
  var EEXEC_ENCRYPT_KEY = 55665;
281
346
  var CHAR_STRS_ENCRYPT_KEY = 4330;
347
+
282
348
  function isHexDigit(code) {
283
349
  return code >= 48 && code <= 57 || code >= 65 && code <= 70 || code >= 97 && code <= 102;
284
350
  }
351
+
285
352
  function decrypt(data, key, discardNumber) {
286
353
  if (discardNumber >= data.length) {
287
354
  return new Uint8Array(0);
288
355
  }
356
+
289
357
  var r = key | 0,
290
358
  c1 = 52845,
291
359
  c2 = 22719,
292
360
  i,
293
361
  j;
362
+
294
363
  for (i = 0; i < discardNumber; i++) {
295
364
  r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;
296
365
  }
366
+
297
367
  var count = data.length - discardNumber;
298
368
  var decrypted = new Uint8Array(count);
369
+
299
370
  for (i = discardNumber, j = 0; j < count; i++, j++) {
300
371
  var value = data[i];
301
372
  decrypted[j] = value ^ r >> 8;
302
373
  r = (value + r) * c1 + c2 & (1 << 16) - 1;
303
374
  }
375
+
304
376
  return decrypted;
305
377
  }
378
+
306
379
  function decryptAscii(data, key, discardNumber) {
307
380
  var r = key | 0,
308
381
  c1 = 52845,
@@ -311,48 +384,62 @@ var Type1Parser = function Type1ParserClosure() {
311
384
  maybeLength = count >>> 1;
312
385
  var decrypted = new Uint8Array(maybeLength);
313
386
  var i, j;
387
+
314
388
  for (i = 0, j = 0; i < count; i++) {
315
389
  var digit1 = data[i];
390
+
316
391
  if (!isHexDigit(digit1)) {
317
392
  continue;
318
393
  }
394
+
319
395
  i++;
320
396
  var digit2;
397
+
321
398
  while (i < count && !isHexDigit(digit2 = data[i])) {
322
399
  i++;
323
400
  }
401
+
324
402
  if (i < count) {
325
403
  var value = parseInt(String.fromCharCode(digit1, digit2), 16);
326
404
  decrypted[j++] = value ^ r >> 8;
327
405
  r = (value + r) * c1 + c2 & (1 << 16) - 1;
328
406
  }
329
407
  }
408
+
330
409
  return Array.prototype.slice.call(decrypted, discardNumber, j);
331
410
  }
411
+
332
412
  function isSpecial(c) {
333
- return c === 0x2F || c === 0x5B || c === 0x5D || c === 0x7B || c === 0x7D || c === 0x28 || c === 0x29;
413
+ return c === 0x2f || c === 0x5b || c === 0x5d || c === 0x7b || c === 0x7d || c === 0x28 || c === 0x29;
334
414
  }
415
+
335
416
  function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
336
417
  if (encrypted) {
337
418
  var data = stream.getBytes();
338
419
  var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]));
339
420
  stream = new _stream.Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
340
421
  }
422
+
341
423
  this.seacAnalysisEnabled = !!seacAnalysisEnabled;
342
424
  this.stream = stream;
343
425
  this.nextChar();
344
426
  }
427
+
345
428
  Type1Parser.prototype = {
346
429
  readNumberArray: function Type1Parser_readNumberArray() {
347
430
  this.getToken();
348
431
  var array = [];
432
+
349
433
  while (true) {
350
434
  var token = this.getToken();
351
- if (token === null || token === ']' || token === '}') {
435
+
436
+ if (token === null || token === "]" || token === "}") {
352
437
  break;
353
438
  }
439
+
354
440
  array.push(parseFloat(token || 0));
355
441
  }
442
+
356
443
  return array;
357
444
  },
358
445
  readNumber: function Type1Parser_readNumber() {
@@ -365,7 +452,7 @@ var Type1Parser = function Type1ParserClosure() {
365
452
  },
366
453
  readBoolean: function Type1Parser_readBoolean() {
367
454
  var token = this.getToken();
368
- return token === 'true' ? 1 : 0;
455
+ return token === "true" ? 1 : 0;
369
456
  },
370
457
  nextChar: function Type1_nextChar() {
371
458
  return this.currentChar = this.stream.getByte();
@@ -373,185 +460,245 @@ var Type1Parser = function Type1ParserClosure() {
373
460
  getToken: function Type1Parser_getToken() {
374
461
  var comment = false;
375
462
  var ch = this.currentChar;
463
+
376
464
  while (true) {
377
465
  if (ch === -1) {
378
466
  return null;
379
467
  }
468
+
380
469
  if (comment) {
381
- if (ch === 0x0A || ch === 0x0D) {
470
+ if (ch === 0x0a || ch === 0x0d) {
382
471
  comment = false;
383
472
  }
384
473
  } else if (ch === 0x25) {
385
474
  comment = true;
386
- } else if (!(0, _util.isSpace)(ch)) {
475
+ } else if (!(0, _core_utils.isWhiteSpace)(ch)) {
387
476
  break;
388
477
  }
478
+
389
479
  ch = this.nextChar();
390
480
  }
481
+
391
482
  if (isSpecial(ch)) {
392
483
  this.nextChar();
393
484
  return String.fromCharCode(ch);
394
485
  }
395
- var token = '';
486
+
487
+ var token = "";
488
+
396
489
  do {
397
490
  token += String.fromCharCode(ch);
398
491
  ch = this.nextChar();
399
- } while (ch >= 0 && !(0, _util.isSpace)(ch) && !isSpecial(ch));
492
+ } while (ch >= 0 && !(0, _core_utils.isWhiteSpace)(ch) && !isSpecial(ch));
493
+
400
494
  return token;
401
495
  },
402
496
  readCharStrings: function Type1Parser_readCharStrings(bytes, lenIV) {
403
497
  if (lenIV === -1) {
404
498
  return bytes;
405
499
  }
500
+
406
501
  return decrypt(bytes, CHAR_STRS_ENCRYPT_KEY, lenIV);
407
502
  },
408
- extractFontProgram: function Type1Parser_extractFontProgram() {
503
+ extractFontProgram: function Type1Parser_extractFontProgram(properties) {
409
504
  var stream = this.stream;
410
505
  var subrs = [],
411
506
  charstrings = [];
412
507
  var privateData = Object.create(null);
413
- privateData['lenIV'] = 4;
508
+ privateData["lenIV"] = 4;
414
509
  var program = {
415
510
  subrs: [],
416
511
  charstrings: [],
417
- properties: { 'privateData': privateData }
512
+ properties: {
513
+ privateData
514
+ }
418
515
  };
419
516
  var token, length, data, lenIV, encoded;
517
+
420
518
  while ((token = this.getToken()) !== null) {
421
- if (token !== '/') {
519
+ if (token !== "/") {
422
520
  continue;
423
521
  }
522
+
424
523
  token = this.getToken();
524
+
425
525
  switch (token) {
426
- case 'CharStrings':
526
+ case "CharStrings":
427
527
  this.getToken();
428
528
  this.getToken();
429
529
  this.getToken();
430
530
  this.getToken();
531
+
431
532
  while (true) {
432
533
  token = this.getToken();
433
- if (token === null || token === 'end') {
534
+
535
+ if (token === null || token === "end") {
434
536
  break;
435
537
  }
436
- if (token !== '/') {
538
+
539
+ if (token !== "/") {
437
540
  continue;
438
541
  }
542
+
439
543
  var glyph = this.getToken();
440
544
  length = this.readInt();
441
545
  this.getToken();
442
546
  data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
443
- lenIV = program.properties.privateData['lenIV'];
547
+ lenIV = program.properties.privateData["lenIV"];
444
548
  encoded = this.readCharStrings(data, lenIV);
445
549
  this.nextChar();
446
550
  token = this.getToken();
447
- if (token === 'noaccess') {
551
+
552
+ if (token === "noaccess") {
448
553
  this.getToken();
449
554
  }
555
+
450
556
  charstrings.push({
451
- glyph: glyph,
452
- encoded: encoded
557
+ glyph,
558
+ encoded
453
559
  });
454
560
  }
561
+
455
562
  break;
456
- case 'Subrs':
563
+
564
+ case "Subrs":
457
565
  this.readInt();
458
566
  this.getToken();
459
- while (this.getToken() === 'dup') {
567
+
568
+ while (this.getToken() === "dup") {
460
569
  var index = this.readInt();
461
570
  length = this.readInt();
462
571
  this.getToken();
463
572
  data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
464
- lenIV = program.properties.privateData['lenIV'];
573
+ lenIV = program.properties.privateData["lenIV"];
465
574
  encoded = this.readCharStrings(data, lenIV);
466
575
  this.nextChar();
467
576
  token = this.getToken();
468
- if (token === 'noaccess') {
577
+
578
+ if (token === "noaccess") {
469
579
  this.getToken();
470
580
  }
581
+
471
582
  subrs[index] = encoded;
472
583
  }
584
+
473
585
  break;
474
- case 'BlueValues':
475
- case 'OtherBlues':
476
- case 'FamilyBlues':
477
- case 'FamilyOtherBlues':
586
+
587
+ case "BlueValues":
588
+ case "OtherBlues":
589
+ case "FamilyBlues":
590
+ case "FamilyOtherBlues":
478
591
  var blueArray = this.readNumberArray();
592
+
479
593
  if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {
480
594
  program.properties.privateData[token] = blueArray;
481
595
  }
596
+
482
597
  break;
483
- case 'StemSnapH':
484
- case 'StemSnapV':
598
+
599
+ case "StemSnapH":
600
+ case "StemSnapV":
485
601
  program.properties.privateData[token] = this.readNumberArray();
486
602
  break;
487
- case 'StdHW':
488
- case 'StdVW':
603
+
604
+ case "StdHW":
605
+ case "StdVW":
489
606
  program.properties.privateData[token] = this.readNumberArray()[0];
490
607
  break;
491
- case 'BlueShift':
492
- case 'lenIV':
493
- case 'BlueFuzz':
494
- case 'BlueScale':
495
- case 'LanguageGroup':
496
- case 'ExpansionFactor':
608
+
609
+ case "BlueShift":
610
+ case "lenIV":
611
+ case "BlueFuzz":
612
+ case "BlueScale":
613
+ case "LanguageGroup":
614
+ case "ExpansionFactor":
497
615
  program.properties.privateData[token] = this.readNumber();
498
616
  break;
499
- case 'ForceBold':
617
+
618
+ case "ForceBold":
500
619
  program.properties.privateData[token] = this.readBoolean();
501
620
  break;
502
621
  }
503
622
  }
623
+
504
624
  for (var i = 0; i < charstrings.length; i++) {
505
625
  glyph = charstrings[i].glyph;
506
626
  encoded = charstrings[i].encoded;
507
627
  var charString = new Type1CharString();
508
628
  var error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);
509
629
  var output = charString.output;
630
+
510
631
  if (error) {
511
632
  output = [14];
512
633
  }
513
- program.charstrings.push({
634
+
635
+ const charStringObject = {
514
636
  glyphName: glyph,
515
637
  charstring: output,
516
638
  width: charString.width,
517
639
  lsb: charString.lsb,
518
640
  seac: charString.seac
519
- });
641
+ };
642
+
643
+ if (glyph === ".notdef") {
644
+ program.charstrings.unshift(charStringObject);
645
+ } else {
646
+ program.charstrings.push(charStringObject);
647
+ }
648
+
649
+ if (properties.builtInEncoding) {
650
+ const index = properties.builtInEncoding.indexOf(glyph);
651
+
652
+ if (index > -1 && properties.widths[index] === undefined && index >= properties.firstChar && index <= properties.lastChar) {
653
+ properties.widths[index] = charString.width;
654
+ }
655
+ }
520
656
  }
657
+
521
658
  return program;
522
659
  },
523
660
  extractFontHeader: function Type1Parser_extractFontHeader(properties) {
524
661
  var token;
662
+
525
663
  while ((token = this.getToken()) !== null) {
526
- if (token !== '/') {
664
+ if (token !== "/") {
527
665
  continue;
528
666
  }
667
+
529
668
  token = this.getToken();
669
+
530
670
  switch (token) {
531
- case 'FontMatrix':
671
+ case "FontMatrix":
532
672
  var matrix = this.readNumberArray();
533
673
  properties.fontMatrix = matrix;
534
674
  break;
535
- case 'Encoding':
675
+
676
+ case "Encoding":
536
677
  var encodingArg = this.getToken();
537
678
  var encoding;
679
+
538
680
  if (!/^\d+$/.test(encodingArg)) {
539
681
  encoding = (0, _encodings.getEncoding)(encodingArg);
540
682
  } else {
541
683
  encoding = [];
542
684
  var size = parseInt(encodingArg, 10) | 0;
543
685
  this.getToken();
686
+
544
687
  for (var j = 0; j < size; j++) {
545
688
  token = this.getToken();
546
- while (token !== 'dup' && token !== 'def') {
689
+
690
+ while (token !== "dup" && token !== "def") {
547
691
  token = this.getToken();
692
+
548
693
  if (token === null) {
549
694
  return;
550
695
  }
551
696
  }
552
- if (token === 'def') {
697
+
698
+ if (token === "def") {
553
699
  break;
554
700
  }
701
+
555
702
  var index = this.readInt();
556
703
  this.getToken();
557
704
  var glyph = this.getToken();
@@ -559,9 +706,11 @@ var Type1Parser = function Type1ParserClosure() {
559
706
  this.getToken();
560
707
  }
561
708
  }
709
+
562
710
  properties.builtInEncoding = encoding;
563
711
  break;
564
- case 'FontBBox':
712
+
713
+ case "FontBBox":
565
714
  var fontBBox = this.readNumberArray();
566
715
  properties.ascent = Math.max(fontBBox[3], fontBBox[1]);
567
716
  properties.descent = Math.min(fontBBox[1], fontBBox[3]);
@@ -573,4 +722,5 @@ var Type1Parser = function Type1ParserClosure() {
573
722
  };
574
723
  return Type1Parser;
575
724
  }();
725
+
576
726
  exports.Type1Parser = Type1Parser;