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,18 +19,21 @@
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.getTilingPatternIR = exports.Pattern = undefined;
27
+ exports.getTilingPatternIR = getTilingPatternIR;
28
+ exports.Pattern = void 0;
28
29
 
29
- var _util = require('../shared/util');
30
+ var _util = require("../shared/util.js");
30
31
 
31
- var _colorspace = require('./colorspace');
32
+ var _colorspace = require("./colorspace.js");
32
33
 
33
- var _primitives = require('./primitives');
34
+ var _primitives = require("./primitives.js");
35
+
36
+ var _core_utils = require("./core_utils.js");
34
37
 
35
38
  var ShadingType = {
36
39
  FUNCTION_BASED: 1,
@@ -41,67 +44,92 @@ var ShadingType = {
41
44
  COONS_PATCH_MESH: 6,
42
45
  TENSOR_PATCH_MESH: 7
43
46
  };
47
+
44
48
  var Pattern = function PatternClosure() {
45
49
  function Pattern() {
46
- (0, _util.unreachable)('should not call Pattern constructor');
50
+ (0, _util.unreachable)("should not call Pattern constructor");
47
51
  }
52
+
48
53
  Pattern.prototype = {
49
54
  getPattern: function Pattern_getPattern(ctx) {
50
- (0, _util.unreachable)('Should not call Pattern.getStyle: ' + ctx);
55
+ (0, _util.unreachable)(`Should not call Pattern.getStyle: ${ctx}`);
51
56
  }
52
57
  };
58
+
53
59
  Pattern.parseShading = function (shading, matrix, xref, res, handler, pdfFunctionFactory) {
54
60
  var dict = (0, _primitives.isStream)(shading) ? shading.dict : shading;
55
- var type = dict.get('ShadingType');
61
+ var type = dict.get("ShadingType");
62
+
56
63
  try {
57
64
  switch (type) {
58
65
  case ShadingType.AXIAL:
59
66
  case ShadingType.RADIAL:
60
67
  return new Shadings.RadialAxial(dict, matrix, xref, res, pdfFunctionFactory);
68
+
61
69
  case ShadingType.FREE_FORM_MESH:
62
70
  case ShadingType.LATTICE_FORM_MESH:
63
71
  case ShadingType.COONS_PATCH_MESH:
64
72
  case ShadingType.TENSOR_PATCH_MESH:
65
73
  return new Shadings.Mesh(shading, matrix, xref, res, pdfFunctionFactory);
74
+
66
75
  default:
67
- throw new _util.FormatError('Unsupported ShadingType: ' + type);
76
+ throw new _util.FormatError("Unsupported ShadingType: " + type);
68
77
  }
69
78
  } catch (ex) {
70
- if (ex instanceof _util.MissingDataException) {
79
+ if (ex instanceof _core_utils.MissingDataException) {
71
80
  throw ex;
72
81
  }
73
- handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.shadingPattern });
82
+
83
+ handler.send("UnsupportedFeature", {
84
+ featureId: _util.UNSUPPORTED_FEATURES.shadingPattern
85
+ });
74
86
  (0, _util.warn)(ex);
75
87
  return new Shadings.Dummy();
76
88
  }
77
89
  };
90
+
78
91
  return Pattern;
79
92
  }();
93
+
94
+ exports.Pattern = Pattern;
80
95
  var Shadings = {};
81
96
  Shadings.SMALL_NUMBER = 1e-6;
97
+
82
98
  Shadings.RadialAxial = function RadialAxialClosure() {
83
99
  function RadialAxial(dict, matrix, xref, res, pdfFunctionFactory) {
84
100
  this.matrix = matrix;
85
- this.coordsArr = dict.getArray('Coords');
86
- this.shadingType = dict.get('ShadingType');
87
- this.type = 'Pattern';
88
- var cs = dict.get('ColorSpace', 'CS');
101
+ this.coordsArr = dict.getArray("Coords");
102
+ this.shadingType = dict.get("ShadingType");
103
+ this.type = "Pattern";
104
+ var cs = dict.get("ColorSpace", "CS");
89
105
  cs = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
90
106
  this.cs = cs;
107
+ const bbox = dict.getArray("BBox");
108
+
109
+ if (Array.isArray(bbox) && bbox.length === 4) {
110
+ this.bbox = _util.Util.normalizeRect(bbox);
111
+ } else {
112
+ this.bbox = null;
113
+ }
114
+
91
115
  var t0 = 0.0,
92
116
  t1 = 1.0;
93
- if (dict.has('Domain')) {
94
- var domainArr = dict.getArray('Domain');
117
+
118
+ if (dict.has("Domain")) {
119
+ var domainArr = dict.getArray("Domain");
95
120
  t0 = domainArr[0];
96
121
  t1 = domainArr[1];
97
122
  }
123
+
98
124
  var extendStart = false,
99
125
  extendEnd = false;
100
- if (dict.has('Extend')) {
101
- var extendArr = dict.getArray('Extend');
126
+
127
+ if (dict.has("Extend")) {
128
+ var extendArr = dict.getArray("Extend");
102
129
  extendStart = extendArr[0];
103
130
  extendEnd = extendArr[1];
104
131
  }
132
+
105
133
  if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
106
134
  var x1 = this.coordsArr[0];
107
135
  var y1 = this.coordsArr[1];
@@ -110,81 +138,101 @@ Shadings.RadialAxial = function RadialAxialClosure() {
110
138
  var y2 = this.coordsArr[4];
111
139
  var r2 = this.coordsArr[5];
112
140
  var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
141
+
113
142
  if (r1 <= r2 + distance && r2 <= r1 + distance) {
114
- (0, _util.warn)('Unsupported radial gradient.');
143
+ (0, _util.warn)("Unsupported radial gradient.");
115
144
  }
116
145
  }
146
+
117
147
  this.extendStart = extendStart;
118
148
  this.extendEnd = extendEnd;
119
- var fnObj = dict.get('Function');
149
+ var fnObj = dict.get("Function");
120
150
  var fn = pdfFunctionFactory.createFromArray(fnObj);
121
- var diff = t1 - t0;
122
- var step = diff / 10;
151
+ const NUMBER_OF_SAMPLES = 10;
152
+ const step = (t1 - t0) / NUMBER_OF_SAMPLES;
123
153
  var colorStops = this.colorStops = [];
154
+
124
155
  if (t0 >= t1 || step <= 0) {
125
- (0, _util.info)('Bad shading domain.');
156
+ (0, _util.info)("Bad shading domain.");
126
157
  return;
127
158
  }
159
+
128
160
  var color = new Float32Array(cs.numComps),
129
161
  ratio = new Float32Array(1);
130
162
  var rgbColor;
131
- for (var i = t0; i <= t1; i += step) {
132
- ratio[0] = i;
163
+
164
+ for (let i = 0; i <= NUMBER_OF_SAMPLES; i++) {
165
+ ratio[0] = t0 + i * step;
133
166
  fn(ratio, 0, color, 0);
134
167
  rgbColor = cs.getRgb(color, 0);
168
+
135
169
  var cssColor = _util.Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
136
- colorStops.push([(i - t0) / diff, cssColor]);
170
+
171
+ colorStops.push([i / NUMBER_OF_SAMPLES, cssColor]);
137
172
  }
138
- var background = 'transparent';
139
- if (dict.has('Background')) {
140
- rgbColor = cs.getRgb(dict.get('Background'), 0);
173
+
174
+ var background = "transparent";
175
+
176
+ if (dict.has("Background")) {
177
+ rgbColor = cs.getRgb(dict.get("Background"), 0);
141
178
  background = _util.Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
142
179
  }
180
+
143
181
  if (!extendStart) {
144
182
  colorStops.unshift([0, background]);
145
183
  colorStops[1][0] += Shadings.SMALL_NUMBER;
146
184
  }
185
+
147
186
  if (!extendEnd) {
148
187
  colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
149
188
  colorStops.push([1, background]);
150
189
  }
190
+
151
191
  this.colorStops = colorStops;
152
192
  }
193
+
153
194
  RadialAxial.prototype = {
154
195
  getIR: function RadialAxial_getIR() {
155
196
  var coordsArr = this.coordsArr;
156
197
  var shadingType = this.shadingType;
157
198
  var type, p0, p1, r0, r1;
199
+
158
200
  if (shadingType === ShadingType.AXIAL) {
159
201
  p0 = [coordsArr[0], coordsArr[1]];
160
202
  p1 = [coordsArr[2], coordsArr[3]];
161
203
  r0 = null;
162
204
  r1 = null;
163
- type = 'axial';
205
+ type = "axial";
164
206
  } else if (shadingType === ShadingType.RADIAL) {
165
207
  p0 = [coordsArr[0], coordsArr[1]];
166
208
  p1 = [coordsArr[3], coordsArr[4]];
167
209
  r0 = coordsArr[2];
168
210
  r1 = coordsArr[5];
169
- type = 'radial';
211
+ type = "radial";
170
212
  } else {
171
- (0, _util.unreachable)('getPattern type unknown: ' + shadingType);
213
+ (0, _util.unreachable)(`getPattern type unknown: ${shadingType}`);
172
214
  }
215
+
173
216
  var matrix = this.matrix;
217
+
174
218
  if (matrix) {
175
219
  p0 = _util.Util.applyTransform(p0, matrix);
176
220
  p1 = _util.Util.applyTransform(p1, matrix);
221
+
177
222
  if (shadingType === ShadingType.RADIAL) {
178
223
  var scale = _util.Util.singularValueDecompose2dScale(matrix);
224
+
179
225
  r0 *= scale[0];
180
226
  r1 *= scale[1];
181
227
  }
182
228
  }
183
- return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
229
+
230
+ return ["RadialAxial", type, this.bbox, this.colorStops, p0, p1, r0, r1];
184
231
  }
185
232
  };
186
233
  return RadialAxial;
187
234
  }();
235
+
188
236
  Shadings.Mesh = function MeshClosure() {
189
237
  function MeshStreamReader(stream, context) {
190
238
  this.stream = stream;
@@ -196,41 +244,52 @@ Shadings.Mesh = function MeshClosure() {
196
244
  var csNumComps = context.colorSpace.numComps;
197
245
  this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
198
246
  }
247
+
199
248
  MeshStreamReader.prototype = {
200
249
  get hasData() {
201
250
  if (this.stream.end) {
202
251
  return this.stream.pos < this.stream.end;
203
252
  }
253
+
204
254
  if (this.bufferLength > 0) {
205
255
  return true;
206
256
  }
257
+
207
258
  var nextByte = this.stream.getByte();
259
+
208
260
  if (nextByte < 0) {
209
261
  return false;
210
262
  }
263
+
211
264
  this.buffer = nextByte;
212
265
  this.bufferLength = 8;
213
266
  return true;
214
267
  },
268
+
215
269
  readBits: function MeshStreamReader_readBits(n) {
216
270
  var buffer = this.buffer;
217
271
  var bufferLength = this.bufferLength;
272
+
218
273
  if (n === 32) {
219
274
  if (bufferLength === 0) {
220
275
  return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
221
276
  }
277
+
222
278
  buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
223
279
  var nextByte = this.stream.getByte();
224
280
  this.buffer = nextByte & (1 << bufferLength) - 1;
225
- return (buffer << 8 - bufferLength | (nextByte & 0xFF) >> bufferLength) >>> 0;
281
+ return (buffer << 8 - bufferLength | (nextByte & 0xff) >> bufferLength) >>> 0;
226
282
  }
283
+
227
284
  if (n === 8 && bufferLength === 0) {
228
285
  return this.stream.getByte();
229
286
  }
287
+
230
288
  while (bufferLength < n) {
231
289
  buffer = buffer << 8 | this.stream.getByte();
232
290
  bufferLength += 8;
233
291
  }
292
+
234
293
  bufferLength -= n;
235
294
  this.bufferLength = bufferLength;
236
295
  this.buffer = buffer & (1 << bufferLength) - 1;
@@ -257,62 +316,77 @@ Shadings.Mesh = function MeshClosure() {
257
316
  var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
258
317
  var decode = this.context.decode;
259
318
  var components = this.tmpCompsBuf;
319
+
260
320
  for (var i = 0, j = 4; i < numComps; i++, j += 2) {
261
321
  var ci = this.readBits(bitsPerComponent);
262
322
  components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
263
323
  }
324
+
264
325
  var color = this.tmpCsCompsBuf;
326
+
265
327
  if (this.context.colorFn) {
266
328
  this.context.colorFn(components, 0, color, 0);
267
329
  }
330
+
268
331
  return this.context.colorSpace.getRgb(color, 0);
269
332
  }
270
333
  };
334
+
271
335
  function decodeType4Shading(mesh, reader) {
272
336
  var coords = mesh.coords;
273
337
  var colors = mesh.colors;
274
338
  var operators = [];
275
339
  var ps = [];
276
340
  var verticesLeft = 0;
341
+
277
342
  while (reader.hasData) {
278
343
  var f = reader.readFlag();
279
344
  var coord = reader.readCoordinate();
280
345
  var color = reader.readComponents();
346
+
281
347
  if (verticesLeft === 0) {
282
348
  if (!(0 <= f && f <= 2)) {
283
- throw new _util.FormatError('Unknown type4 flag');
349
+ throw new _util.FormatError("Unknown type4 flag");
284
350
  }
351
+
285
352
  switch (f) {
286
353
  case 0:
287
354
  verticesLeft = 3;
288
355
  break;
356
+
289
357
  case 1:
290
358
  ps.push(ps[ps.length - 2], ps[ps.length - 1]);
291
359
  verticesLeft = 1;
292
360
  break;
361
+
293
362
  case 2:
294
363
  ps.push(ps[ps.length - 3], ps[ps.length - 1]);
295
364
  verticesLeft = 1;
296
365
  break;
297
366
  }
367
+
298
368
  operators.push(f);
299
369
  }
370
+
300
371
  ps.push(coords.length);
301
372
  coords.push(coord);
302
373
  colors.push(color);
303
374
  verticesLeft--;
304
375
  reader.align();
305
376
  }
377
+
306
378
  mesh.figures.push({
307
- type: 'triangles',
379
+ type: "triangles",
308
380
  coords: new Int32Array(ps),
309
381
  colors: new Int32Array(ps)
310
382
  });
311
383
  }
384
+
312
385
  function decodeType5Shading(mesh, reader, verticesPerRow) {
313
386
  var coords = mesh.coords;
314
387
  var colors = mesh.colors;
315
388
  var ps = [];
389
+
316
390
  while (reader.hasData) {
317
391
  var coord = reader.readCoordinate();
318
392
  var color = reader.readComponents();
@@ -320,37 +394,45 @@ Shadings.Mesh = function MeshClosure() {
320
394
  coords.push(coord);
321
395
  colors.push(color);
322
396
  }
397
+
323
398
  mesh.figures.push({
324
- type: 'lattice',
399
+ type: "lattice",
325
400
  coords: new Int32Array(ps),
326
401
  colors: new Int32Array(ps),
327
- verticesPerRow: verticesPerRow
402
+ verticesPerRow
328
403
  });
329
404
  }
405
+
330
406
  var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
331
407
  var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
332
408
  var TRIANGLE_DENSITY = 20;
409
+
333
410
  var getB = function getBClosure() {
334
411
  function buildB(count) {
335
412
  var lut = [];
413
+
336
414
  for (var i = 0; i <= count; i++) {
337
415
  var t = i / count,
338
416
  t_ = 1 - t;
339
417
  lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_, 3 * t * t * t_, t * t * t]));
340
418
  }
419
+
341
420
  return lut;
342
421
  }
422
+
343
423
  var cache = [];
344
424
  return function getB(count) {
345
425
  if (!cache[count]) {
346
426
  cache[count] = buildB(count);
347
427
  }
428
+
348
429
  return cache[count];
349
430
  };
350
431
  }();
432
+
351
433
  function buildFigureFromPatch(mesh, index) {
352
434
  var figure = mesh.figures[index];
353
- (0, _util.assert)(figure.type === 'patch', 'Unexpected patch mesh figure');
435
+ (0, _util.assert)(figure.type === "patch", "Unexpected patch mesh figure");
354
436
  var coords = mesh.coords,
355
437
  colors = mesh.colors;
356
438
  var pi = figure.coords;
@@ -375,6 +457,7 @@ Shadings.Mesh = function MeshClosure() {
375
457
  c3 = colors[ci[3]];
376
458
  var bRow = getB(splitYBy),
377
459
  bCol = getB(splitXBy);
460
+
378
461
  for (var row = 0; row <= splitYBy; row++) {
379
462
  cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
380
463
  cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
@@ -382,13 +465,16 @@ Shadings.Mesh = function MeshClosure() {
382
465
  cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
383
466
  cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
384
467
  cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
468
+
385
469
  for (var col = 0; col <= splitXBy; col++, k++) {
386
470
  if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
387
471
  continue;
388
472
  }
473
+
389
474
  var x = 0,
390
475
  y = 0;
391
476
  var q = 0;
477
+
392
478
  for (var i = 0; i <= 3; i++) {
393
479
  for (var j = 0; j <= 3; j++, q++) {
394
480
  var m = bRow[row][i] * bCol[col][j];
@@ -396,6 +482,7 @@ Shadings.Mesh = function MeshClosure() {
396
482
  y += coords[pi[q]][1] * m;
397
483
  }
398
484
  }
485
+
399
486
  figureCoords[k] = coords.length;
400
487
  coords.push([x, y]);
401
488
  figureColors[k] = colors.length;
@@ -406,6 +493,7 @@ Shadings.Mesh = function MeshClosure() {
406
493
  colors.push(newColor);
407
494
  }
408
495
  }
496
+
409
497
  figureCoords[0] = pi[0];
410
498
  figureColors[0] = ci[0];
411
499
  figureCoords[splitXBy] = pi[3];
@@ -415,32 +503,41 @@ Shadings.Mesh = function MeshClosure() {
415
503
  figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
416
504
  figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
417
505
  mesh.figures[index] = {
418
- type: 'lattice',
506
+ type: "lattice",
419
507
  coords: figureCoords,
420
508
  colors: figureColors,
421
- verticesPerRow: verticesPerRow
509
+ verticesPerRow
422
510
  };
423
511
  }
512
+
424
513
  function decodeType6Shading(mesh, reader) {
425
514
  var coords = mesh.coords;
426
515
  var colors = mesh.colors;
427
516
  var ps = new Int32Array(16);
428
517
  var cs = new Int32Array(4);
518
+
429
519
  while (reader.hasData) {
430
520
  var f = reader.readFlag();
521
+
431
522
  if (!(0 <= f && f <= 3)) {
432
- throw new _util.FormatError('Unknown type6 flag');
523
+ throw new _util.FormatError("Unknown type6 flag");
433
524
  }
525
+
434
526
  var i, ii;
435
527
  var pi = coords.length;
528
+
436
529
  for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
437
530
  coords.push(reader.readCoordinate());
438
531
  }
532
+
439
533
  var ci = colors.length;
534
+
440
535
  for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
441
536
  colors.push(reader.readComponents());
442
537
  }
538
+
443
539
  var tmp1, tmp2, tmp3, tmp4;
540
+
444
541
  switch (f) {
445
542
  case 0:
446
543
  ps[12] = pi + 3;
@@ -460,6 +557,7 @@ Shadings.Mesh = function MeshClosure() {
460
557
  cs[0] = ci;
461
558
  cs[1] = ci + 3;
462
559
  break;
560
+
463
561
  case 1:
464
562
  tmp1 = ps[12];
465
563
  tmp2 = ps[13];
@@ -484,6 +582,7 @@ Shadings.Mesh = function MeshClosure() {
484
582
  cs[0] = tmp1;
485
583
  cs[1] = ci + 1;
486
584
  break;
585
+
487
586
  case 2:
488
587
  tmp1 = ps[15];
489
588
  tmp2 = ps[11];
@@ -505,6 +604,7 @@ Shadings.Mesh = function MeshClosure() {
505
604
  cs[0] = tmp1;
506
605
  cs[1] = ci + 1;
507
606
  break;
607
+
508
608
  case 3:
509
609
  ps[12] = ps[0];
510
610
  ps[13] = pi + 0;
@@ -524,6 +624,7 @@ Shadings.Mesh = function MeshClosure() {
524
624
  cs[1] = ci + 1;
525
625
  break;
526
626
  }
627
+
527
628
  ps[5] = coords.length;
528
629
  coords.push([(-4 * coords[ps[0]][0] - coords[ps[15]][0] + 6 * (coords[ps[4]][0] + coords[ps[1]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9, (-4 * coords[ps[0]][1] - coords[ps[15]][1] + 6 * (coords[ps[4]][1] + coords[ps[1]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9]);
529
630
  ps[6] = coords.length;
@@ -533,32 +634,41 @@ Shadings.Mesh = function MeshClosure() {
533
634
  ps[10] = coords.length;
534
635
  coords.push([(-4 * coords[ps[15]][0] - coords[ps[0]][0] + 6 * (coords[ps[11]][0] + coords[ps[14]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9, (-4 * coords[ps[15]][1] - coords[ps[0]][1] + 6 * (coords[ps[11]][1] + coords[ps[14]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9]);
535
636
  mesh.figures.push({
536
- type: 'patch',
637
+ type: "patch",
537
638
  coords: new Int32Array(ps),
538
639
  colors: new Int32Array(cs)
539
640
  });
540
641
  }
541
642
  }
643
+
542
644
  function decodeType7Shading(mesh, reader) {
543
645
  var coords = mesh.coords;
544
646
  var colors = mesh.colors;
545
647
  var ps = new Int32Array(16);
546
648
  var cs = new Int32Array(4);
649
+
547
650
  while (reader.hasData) {
548
651
  var f = reader.readFlag();
652
+
549
653
  if (!(0 <= f && f <= 3)) {
550
- throw new _util.FormatError('Unknown type7 flag');
654
+ throw new _util.FormatError("Unknown type7 flag");
551
655
  }
656
+
552
657
  var i, ii;
553
658
  var pi = coords.length;
659
+
554
660
  for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
555
661
  coords.push(reader.readCoordinate());
556
662
  }
663
+
557
664
  var ci = colors.length;
665
+
558
666
  for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
559
667
  colors.push(reader.readComponents());
560
668
  }
669
+
561
670
  var tmp1, tmp2, tmp3, tmp4;
671
+
562
672
  switch (f) {
563
673
  case 0:
564
674
  ps[12] = pi + 3;
@@ -582,6 +692,7 @@ Shadings.Mesh = function MeshClosure() {
582
692
  cs[0] = ci;
583
693
  cs[1] = ci + 3;
584
694
  break;
695
+
585
696
  case 1:
586
697
  tmp1 = ps[12];
587
698
  tmp2 = ps[13];
@@ -610,6 +721,7 @@ Shadings.Mesh = function MeshClosure() {
610
721
  cs[0] = tmp1;
611
722
  cs[1] = ci + 1;
612
723
  break;
724
+
613
725
  case 2:
614
726
  tmp1 = ps[15];
615
727
  tmp2 = ps[11];
@@ -635,6 +747,7 @@ Shadings.Mesh = function MeshClosure() {
635
747
  cs[0] = tmp1;
636
748
  cs[1] = ci + 1;
637
749
  break;
750
+
638
751
  case 3:
639
752
  ps[12] = ps[0];
640
753
  ps[13] = pi + 0;
@@ -658,18 +771,21 @@ Shadings.Mesh = function MeshClosure() {
658
771
  cs[1] = ci + 1;
659
772
  break;
660
773
  }
774
+
661
775
  mesh.figures.push({
662
- type: 'patch',
776
+ type: "patch",
663
777
  coords: new Int32Array(ps),
664
778
  colors: new Int32Array(cs)
665
779
  });
666
780
  }
667
781
  }
782
+
668
783
  function updateBounds(mesh) {
669
784
  var minX = mesh.coords[0][0],
670
785
  minY = mesh.coords[0][1],
671
786
  maxX = minX,
672
787
  maxY = minY;
788
+
673
789
  for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
674
790
  var x = mesh.coords[i][0],
675
791
  y = mesh.coords[i][1];
@@ -678,128 +794,161 @@ Shadings.Mesh = function MeshClosure() {
678
794
  maxX = maxX < x ? x : maxX;
679
795
  maxY = maxY < y ? y : maxY;
680
796
  }
797
+
681
798
  mesh.bounds = [minX, minY, maxX, maxY];
682
799
  }
800
+
683
801
  function packData(mesh) {
684
802
  var i, ii, j, jj;
685
803
  var coords = mesh.coords;
686
804
  var coordsPacked = new Float32Array(coords.length * 2);
805
+
687
806
  for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
688
807
  var xy = coords[i];
689
808
  coordsPacked[j++] = xy[0];
690
809
  coordsPacked[j++] = xy[1];
691
810
  }
811
+
692
812
  mesh.coords = coordsPacked;
693
813
  var colors = mesh.colors;
694
814
  var colorsPacked = new Uint8Array(colors.length * 3);
815
+
695
816
  for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
696
817
  var c = colors[i];
697
818
  colorsPacked[j++] = c[0];
698
819
  colorsPacked[j++] = c[1];
699
820
  colorsPacked[j++] = c[2];
700
821
  }
822
+
701
823
  mesh.colors = colorsPacked;
702
824
  var figures = mesh.figures;
825
+
703
826
  for (i = 0, ii = figures.length; i < ii; i++) {
704
827
  var figure = figures[i],
705
828
  ps = figure.coords,
706
829
  cs = figure.colors;
830
+
707
831
  for (j = 0, jj = ps.length; j < jj; j++) {
708
832
  ps[j] *= 2;
709
833
  cs[j] *= 3;
710
834
  }
711
835
  }
712
836
  }
837
+
713
838
  function Mesh(stream, matrix, xref, res, pdfFunctionFactory) {
714
839
  if (!(0, _primitives.isStream)(stream)) {
715
- throw new _util.FormatError('Mesh data is not a stream');
840
+ throw new _util.FormatError("Mesh data is not a stream");
716
841
  }
842
+
717
843
  var dict = stream.dict;
718
844
  this.matrix = matrix;
719
- this.shadingType = dict.get('ShadingType');
720
- this.type = 'Pattern';
721
- this.bbox = dict.getArray('BBox');
722
- var cs = dict.get('ColorSpace', 'CS');
845
+ this.shadingType = dict.get("ShadingType");
846
+ this.type = "Pattern";
847
+ const bbox = dict.getArray("BBox");
848
+
849
+ if (Array.isArray(bbox) && bbox.length === 4) {
850
+ this.bbox = _util.Util.normalizeRect(bbox);
851
+ } else {
852
+ this.bbox = null;
853
+ }
854
+
855
+ var cs = dict.get("ColorSpace", "CS");
723
856
  cs = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
724
857
  this.cs = cs;
725
- this.background = dict.has('Background') ? cs.getRgb(dict.get('Background'), 0) : null;
726
- var fnObj = dict.get('Function');
858
+ this.background = dict.has("Background") ? cs.getRgb(dict.get("Background"), 0) : null;
859
+ var fnObj = dict.get("Function");
727
860
  var fn = fnObj ? pdfFunctionFactory.createFromArray(fnObj) : null;
728
861
  this.coords = [];
729
862
  this.colors = [];
730
863
  this.figures = [];
731
864
  var decodeContext = {
732
- bitsPerCoordinate: dict.get('BitsPerCoordinate'),
733
- bitsPerComponent: dict.get('BitsPerComponent'),
734
- bitsPerFlag: dict.get('BitsPerFlag'),
735
- decode: dict.getArray('Decode'),
865
+ bitsPerCoordinate: dict.get("BitsPerCoordinate"),
866
+ bitsPerComponent: dict.get("BitsPerComponent"),
867
+ bitsPerFlag: dict.get("BitsPerFlag"),
868
+ decode: dict.getArray("Decode"),
736
869
  colorFn: fn,
737
870
  colorSpace: cs,
738
871
  numComps: fn ? 1 : cs.numComps
739
872
  };
740
873
  var reader = new MeshStreamReader(stream, decodeContext);
741
874
  var patchMesh = false;
875
+
742
876
  switch (this.shadingType) {
743
877
  case ShadingType.FREE_FORM_MESH:
744
878
  decodeType4Shading(this, reader);
745
879
  break;
880
+
746
881
  case ShadingType.LATTICE_FORM_MESH:
747
- var verticesPerRow = dict.get('VerticesPerRow') | 0;
882
+ var verticesPerRow = dict.get("VerticesPerRow") | 0;
883
+
748
884
  if (verticesPerRow < 2) {
749
- throw new _util.FormatError('Invalid VerticesPerRow');
885
+ throw new _util.FormatError("Invalid VerticesPerRow");
750
886
  }
887
+
751
888
  decodeType5Shading(this, reader, verticesPerRow);
752
889
  break;
890
+
753
891
  case ShadingType.COONS_PATCH_MESH:
754
892
  decodeType6Shading(this, reader);
755
893
  patchMesh = true;
756
894
  break;
895
+
757
896
  case ShadingType.TENSOR_PATCH_MESH:
758
897
  decodeType7Shading(this, reader);
759
898
  patchMesh = true;
760
899
  break;
900
+
761
901
  default:
762
- (0, _util.unreachable)('Unsupported mesh type.');
902
+ (0, _util.unreachable)("Unsupported mesh type.");
763
903
  break;
764
904
  }
905
+
765
906
  if (patchMesh) {
766
907
  updateBounds(this);
908
+
767
909
  for (var i = 0, ii = this.figures.length; i < ii; i++) {
768
910
  buildFigureFromPatch(this, i);
769
911
  }
770
912
  }
913
+
771
914
  updateBounds(this);
772
915
  packData(this);
773
916
  }
917
+
774
918
  Mesh.prototype = {
775
919
  getIR: function Mesh_getIR() {
776
- return ['Mesh', this.shadingType, this.coords, this.colors, this.figures, this.bounds, this.matrix, this.bbox, this.background];
920
+ return ["Mesh", this.shadingType, this.coords, this.colors, this.figures, this.bounds, this.matrix, this.bbox, this.background];
777
921
  }
778
922
  };
779
923
  return Mesh;
780
924
  }();
925
+
781
926
  Shadings.Dummy = function DummyClosure() {
782
927
  function Dummy() {
783
- this.type = 'Pattern';
928
+ this.type = "Pattern";
784
929
  }
930
+
785
931
  Dummy.prototype = {
786
932
  getIR: function Dummy_getIR() {
787
- return ['Dummy'];
933
+ return ["Dummy"];
788
934
  }
789
935
  };
790
936
  return Dummy;
791
937
  }();
938
+
792
939
  function getTilingPatternIR(operatorList, dict, args) {
793
- var matrix = dict.getArray('Matrix');
794
- var bbox = _util.Util.normalizeRect(dict.getArray('BBox'));
795
- var xstep = dict.get('XStep');
796
- var ystep = dict.get('YStep');
797
- var paintType = dict.get('PaintType');
798
- var tilingType = dict.get('TilingType');
940
+ const matrix = dict.getArray("Matrix");
941
+
942
+ const bbox = _util.Util.normalizeRect(dict.getArray("BBox"));
943
+
944
+ const xstep = dict.get("XStep");
945
+ const ystep = dict.get("YStep");
946
+ const paintType = dict.get("PaintType");
947
+ const tilingType = dict.get("TilingType");
948
+
799
949
  if (bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) {
800
- throw new _util.FormatError('Invalid getTilingPatternIR /BBox array: [' + bbox + '].');
950
+ throw new _util.FormatError(`Invalid getTilingPatternIR /BBox array: [${bbox}].`);
801
951
  }
802
- return ['TilingPattern', args, operatorList, matrix, bbox, xstep, ystep, paintType, tilingType];
803
- }
804
- exports.Pattern = Pattern;
805
- exports.getTilingPatternIR = getTilingPatternIR;
952
+
953
+ return ["TilingPattern", args, operatorList, matrix, bbox, xstep, ystep, paintType, tilingType];
954
+ }