pdfjs-dist 2.0.550 → 2.3.200

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 (168) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +21618 -14369
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +22758 -11399
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/image_decoders/pdf.image_decoders.js +11500 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +767 -258
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +433 -61
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +428 -157
  20. package/lib/core/cmap.js +326 -87
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/core_utils.js +173 -0
  23. package/lib/core/crypto.js +290 -45
  24. package/lib/core/document.js +575 -272
  25. package/lib/core/encodings.js +19 -10
  26. package/lib/core/evaluator.js +1032 -351
  27. package/lib/core/font_renderer.js +331 -97
  28. package/lib/core/fonts.js +813 -196
  29. package/lib/core/function.js +253 -27
  30. package/lib/core/glyphlist.js +5 -3
  31. package/lib/core/image.js +169 -62
  32. package/lib/core/image_utils.js +111 -0
  33. package/lib/core/jbig2.js +502 -72
  34. package/lib/core/jbig2_stream.js +19 -8
  35. package/lib/core/jpeg_stream.js +38 -13
  36. package/lib/core/jpg.js +293 -52
  37. package/lib/core/jpx.js +419 -12
  38. package/lib/core/jpx_stream.js +18 -6
  39. package/lib/core/metrics.js +15 -15
  40. package/lib/core/murmurhash3.js +56 -34
  41. package/lib/core/obj.js +1368 -500
  42. package/lib/core/operator_list.js +159 -43
  43. package/lib/core/parser.js +544 -199
  44. package/lib/core/pattern.js +170 -21
  45. package/lib/core/pdf_manager.js +324 -134
  46. package/lib/core/primitives.js +169 -61
  47. package/lib/core/ps_parser.js +134 -45
  48. package/lib/core/standard_fonts.js +17 -17
  49. package/lib/core/stream.js +327 -34
  50. package/lib/core/type1_parser.js +148 -8
  51. package/lib/core/unicode.js +32 -5
  52. package/lib/core/worker.js +215 -229
  53. package/lib/core/worker_stream.js +277 -0
  54. package/lib/display/annotation_layer.js +618 -192
  55. package/lib/display/api.js +1798 -882
  56. package/lib/display/api_compatibility.js +5 -10
  57. package/lib/display/canvas.js +366 -45
  58. package/lib/display/content_disposition.js +71 -24
  59. package/lib/display/display_utils.js +777 -0
  60. package/lib/display/fetch_stream.js +205 -87
  61. package/lib/display/font_loader.js +468 -236
  62. package/lib/display/metadata.js +38 -16
  63. package/lib/display/network.js +635 -428
  64. package/lib/display/network_utils.js +38 -19
  65. package/lib/display/node_stream.js +367 -175
  66. package/lib/display/pattern_helper.js +103 -36
  67. package/lib/display/svg.js +1232 -519
  68. package/lib/display/text_layer.js +208 -75
  69. package/lib/display/transport_stream.js +345 -94
  70. package/lib/display/webgl.js +64 -18
  71. package/lib/display/worker_options.js +5 -4
  72. package/lib/display/xml_parser.js +166 -53
  73. package/lib/examples/node/domstubs.js +60 -4
  74. package/lib/pdf.js +35 -14
  75. package/lib/pdf.worker.js +5 -3
  76. package/lib/shared/compatibility.js +170 -572
  77. package/lib/shared/global_scope.js +2 -2
  78. package/lib/shared/is_node.js +4 -4
  79. package/lib/shared/message_handler.js +216 -163
  80. package/lib/shared/streams_polyfill.js +21 -17
  81. package/lib/shared/util.js +495 -385
  82. package/lib/test/unit/annotation_spec.js +1464 -401
  83. package/lib/test/unit/api_spec.js +718 -361
  84. package/lib/test/unit/bidi_spec.js +7 -7
  85. package/lib/test/unit/cff_parser_spec.js +54 -11
  86. package/lib/test/unit/clitests_helper.js +9 -10
  87. package/lib/test/unit/cmap_spec.js +95 -41
  88. package/lib/test/unit/colorspace_spec.js +115 -63
  89. package/lib/test/unit/core_utils_spec.js +191 -0
  90. package/lib/test/unit/crypto_spec.js +17 -5
  91. package/lib/test/unit/custom_spec.js +43 -55
  92. package/lib/test/unit/display_svg_spec.js +34 -18
  93. package/lib/test/unit/display_utils_spec.js +273 -0
  94. package/lib/test/unit/document_spec.js +8 -13
  95. package/lib/test/unit/encodings_spec.js +25 -45
  96. package/lib/test/unit/evaluator_spec.js +59 -20
  97. package/lib/test/unit/fetch_stream_spec.js +111 -0
  98. package/lib/test/unit/function_spec.js +17 -5
  99. package/lib/test/unit/jasmine-boot.js +33 -20
  100. package/lib/test/unit/message_handler_spec.js +30 -13
  101. package/lib/test/unit/metadata_spec.js +71 -11
  102. package/lib/test/unit/murmurhash3_spec.js +3 -3
  103. package/lib/test/unit/network_spec.js +22 -55
  104. package/lib/test/unit/network_utils_spec.js +105 -14
  105. package/lib/test/unit/node_stream_spec.js +58 -34
  106. package/lib/test/unit/parser_spec.js +162 -71
  107. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  108. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  109. package/lib/test/unit/pdf_history_spec.js +21 -9
  110. package/lib/test/unit/primitives_spec.js +55 -22
  111. package/lib/test/unit/stream_spec.js +12 -4
  112. package/lib/test/unit/test_utils.js +273 -56
  113. package/lib/test/unit/testreporter.js +21 -3
  114. package/lib/test/unit/type1_parser_spec.js +9 -7
  115. package/lib/test/unit/ui_utils_spec.js +236 -36
  116. package/lib/test/unit/unicode_spec.js +18 -15
  117. package/lib/test/unit/util_spec.js +87 -128
  118. package/lib/web/annotation_layer_builder.js +39 -22
  119. package/lib/web/app.js +1252 -609
  120. package/lib/web/app_options.js +103 -65
  121. package/lib/web/base_viewer.js +522 -242
  122. package/lib/web/chromecom.js +259 -117
  123. package/lib/web/debugger.js +166 -22
  124. package/lib/web/download_manager.js +31 -12
  125. package/lib/web/firefox_print_service.js +27 -14
  126. package/lib/web/firefoxcom.js +318 -78
  127. package/lib/web/genericcom.js +89 -30
  128. package/lib/web/genericl10n.js +142 -30
  129. package/lib/web/grab_to_pan.js +28 -4
  130. package/lib/web/interfaces.js +174 -47
  131. package/lib/web/overlay_manager.js +235 -85
  132. package/lib/web/password_prompt.js +22 -14
  133. package/lib/web/pdf_attachment_viewer.js +38 -18
  134. package/lib/web/pdf_cursor_tools.js +39 -16
  135. package/lib/web/pdf_document_properties.js +255 -136
  136. package/lib/web/pdf_find_bar.js +84 -40
  137. package/lib/web/pdf_find_controller.js +495 -184
  138. package/lib/web/pdf_find_utils.js +111 -0
  139. package/lib/web/pdf_history.js +190 -53
  140. package/lib/web/pdf_link_service.js +144 -79
  141. package/lib/web/pdf_outline_viewer.js +124 -47
  142. package/lib/web/pdf_page_view.js +194 -74
  143. package/lib/web/pdf_presentation_mode.js +99 -34
  144. package/lib/web/pdf_print_service.js +59 -13
  145. package/lib/web/pdf_rendering_queue.js +28 -9
  146. package/lib/web/pdf_sidebar.js +144 -81
  147. package/lib/web/pdf_sidebar_resizer.js +42 -16
  148. package/lib/web/pdf_single_page_viewer.js +74 -66
  149. package/lib/web/pdf_thumbnail_view.js +104 -33
  150. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  151. package/lib/web/pdf_viewer.component.js +112 -32
  152. package/lib/web/pdf_viewer.js +82 -87
  153. package/lib/web/preferences.js +284 -91
  154. package/lib/web/secondary_toolbar.js +132 -59
  155. package/lib/web/text_layer_builder.js +134 -59
  156. package/lib/web/toolbar.js +80 -43
  157. package/lib/web/ui_utils.js +400 -134
  158. package/lib/web/view_history.js +215 -67
  159. package/lib/web/viewer_compatibility.js +3 -8
  160. package/package.json +3 -2
  161. package/web/pdf_viewer.css +23 -15
  162. package/web/pdf_viewer.js +3429 -1245
  163. package/web/pdf_viewer.js.map +1 -1
  164. package/external/streams/streams-lib.js +0 -3962
  165. package/lib/display/dom_utils.js +0 -429
  166. package/lib/test/unit/dom_utils_spec.js +0 -89
  167. package/lib/test/unit/fonts_spec.js +0 -81
  168. package/lib/web/dom_events.js +0 -137
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2019 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,16 +19,16 @@
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.CanvasGraphics = undefined;
27
+ exports.CanvasGraphics = void 0;
28
28
 
29
- var _util = require('../shared/util');
29
+ var _util = require("../shared/util");
30
30
 
31
- var _pattern_helper = require('./pattern_helper');
31
+ var _pattern_helper = require("./pattern_helper");
32
32
 
33
33
  var MIN_FONT_SIZE = 16;
34
34
  var MAX_FONT_SIZE = 100;
@@ -41,7 +41,9 @@ var IsLittleEndianCached = {
41
41
  get value() {
42
42
  return (0, _util.shadow)(IsLittleEndianCached, 'value', (0, _util.isLittleEndian)());
43
43
  }
44
+
44
45
  };
46
+
45
47
  function addContextCurrentTransform(ctx) {
46
48
  if (!ctx.mozCurrentTransform) {
47
49
  ctx._originalSave = ctx.save;
@@ -72,59 +74,79 @@ function addContextCurrentTransform(ctx) {
72
74
  return [d / ad_bc, b / bc_ad, c / bc_ad, a / ad_bc, (d * e - c * f) / bc_ad, (b * e - a * f) / ad_bc];
73
75
  }
74
76
  });
77
+
75
78
  ctx.save = function ctxSave() {
76
79
  var old = this._transformMatrix;
80
+
77
81
  this._transformStack.push(old);
82
+
78
83
  this._transformMatrix = old.slice(0, 6);
84
+
79
85
  this._originalSave();
80
86
  };
87
+
81
88
  ctx.restore = function ctxRestore() {
82
89
  var prev = this._transformStack.pop();
90
+
83
91
  if (prev) {
84
92
  this._transformMatrix = prev;
93
+
85
94
  this._originalRestore();
86
95
  }
87
96
  };
97
+
88
98
  ctx.translate = function ctxTranslate(x, y) {
89
99
  var m = this._transformMatrix;
90
100
  m[4] = m[0] * x + m[2] * y + m[4];
91
101
  m[5] = m[1] * x + m[3] * y + m[5];
102
+
92
103
  this._originalTranslate(x, y);
93
104
  };
105
+
94
106
  ctx.scale = function ctxScale(x, y) {
95
107
  var m = this._transformMatrix;
96
108
  m[0] = m[0] * x;
97
109
  m[1] = m[1] * x;
98
110
  m[2] = m[2] * y;
99
111
  m[3] = m[3] * y;
112
+
100
113
  this._originalScale(x, y);
101
114
  };
115
+
102
116
  ctx.transform = function ctxTransform(a, b, c, d, e, f) {
103
117
  var m = this._transformMatrix;
104
118
  this._transformMatrix = [m[0] * a + m[2] * b, m[1] * a + m[3] * b, m[0] * c + m[2] * d, m[1] * c + m[3] * d, m[0] * e + m[2] * f + m[4], m[1] * e + m[3] * f + m[5]];
119
+
105
120
  ctx._originalTransform(a, b, c, d, e, f);
106
121
  };
122
+
107
123
  ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
108
124
  this._transformMatrix = [a, b, c, d, e, f];
125
+
109
126
  ctx._originalSetTransform(a, b, c, d, e, f);
110
127
  };
128
+
111
129
  ctx.rotate = function ctxRotate(angle) {
112
130
  var cosValue = Math.cos(angle);
113
131
  var sinValue = Math.sin(angle);
114
132
  var m = this._transformMatrix;
115
133
  this._transformMatrix = [m[0] * cosValue + m[2] * sinValue, m[1] * cosValue + m[3] * sinValue, m[0] * -sinValue + m[2] * cosValue, m[1] * -sinValue + m[3] * cosValue, m[4], m[5]];
134
+
116
135
  this._originalRotate(angle);
117
136
  };
118
137
  }
119
138
  }
139
+
120
140
  var CachedCanvases = function CachedCanvasesClosure() {
121
141
  function CachedCanvases(canvasFactory) {
122
142
  this.canvasFactory = canvasFactory;
123
143
  this.cache = Object.create(null);
124
144
  }
145
+
125
146
  CachedCanvases.prototype = {
126
147
  getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
127
148
  var canvasEntry;
149
+
128
150
  if (this.cache[id] !== undefined) {
129
151
  canvasEntry = this.cache[id];
130
152
  this.canvasFactory.reset(canvasEntry, width, height);
@@ -133,9 +155,11 @@ var CachedCanvases = function CachedCanvasesClosure() {
133
155
  canvasEntry = this.canvasFactory.create(width, height);
134
156
  this.cache[id] = canvasEntry;
135
157
  }
158
+
136
159
  if (trackTransform) {
137
160
  addContextCurrentTransform(canvasEntry.context);
138
161
  }
162
+
139
163
  return canvasEntry;
140
164
  },
141
165
  clear: function clear() {
@@ -148,6 +172,7 @@ var CachedCanvases = function CachedCanvasesClosure() {
148
172
  };
149
173
  return CachedCanvases;
150
174
  }();
175
+
151
176
  function compileType3Glyph(imgData) {
152
177
  var POINT_TO_PROCESS_LIMIT = 1000;
153
178
  var width = imgData.width,
@@ -163,96 +188,126 @@ function compileType3Glyph(imgData) {
163
188
  var data = new Uint8Array(lineSize * height),
164
189
  pos = 0,
165
190
  ii;
191
+
166
192
  for (i = 0, ii = data0.length; i < ii; i++) {
167
193
  var mask = 128,
168
194
  elem = data0[i];
195
+
169
196
  while (mask > 0) {
170
197
  data[pos++] = elem & mask ? 0 : 255;
171
198
  mask >>= 1;
172
199
  }
173
200
  }
201
+
174
202
  var count = 0;
175
203
  pos = 0;
204
+
176
205
  if (data[pos] !== 0) {
177
206
  points[0] = 1;
178
207
  ++count;
179
208
  }
209
+
180
210
  for (j = 1; j < width; j++) {
181
211
  if (data[pos] !== data[pos + 1]) {
182
212
  points[j] = data[pos] ? 2 : 1;
183
213
  ++count;
184
214
  }
215
+
185
216
  pos++;
186
217
  }
218
+
187
219
  if (data[pos] !== 0) {
188
220
  points[j] = 2;
189
221
  ++count;
190
222
  }
223
+
191
224
  for (i = 1; i < height; i++) {
192
225
  pos = i * lineSize;
193
226
  j0 = i * width1;
227
+
194
228
  if (data[pos - lineSize] !== data[pos]) {
195
229
  points[j0] = data[pos] ? 1 : 8;
196
230
  ++count;
197
231
  }
232
+
198
233
  var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
234
+
199
235
  for (j = 1; j < width; j++) {
200
236
  sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
237
+
201
238
  if (POINT_TYPES[sum]) {
202
239
  points[j0 + j] = POINT_TYPES[sum];
203
240
  ++count;
204
241
  }
242
+
205
243
  pos++;
206
244
  }
245
+
207
246
  if (data[pos - lineSize] !== data[pos]) {
208
247
  points[j0 + j] = data[pos] ? 2 : 4;
209
248
  ++count;
210
249
  }
250
+
211
251
  if (count > POINT_TO_PROCESS_LIMIT) {
212
252
  return null;
213
253
  }
214
254
  }
255
+
215
256
  pos = lineSize * (height - 1);
216
257
  j0 = i * width1;
258
+
217
259
  if (data[pos] !== 0) {
218
260
  points[j0] = 8;
219
261
  ++count;
220
262
  }
263
+
221
264
  for (j = 1; j < width; j++) {
222
265
  if (data[pos] !== data[pos + 1]) {
223
266
  points[j0 + j] = data[pos] ? 4 : 8;
224
267
  ++count;
225
268
  }
269
+
226
270
  pos++;
227
271
  }
272
+
228
273
  if (data[pos] !== 0) {
229
274
  points[j0 + j] = 4;
230
275
  ++count;
231
276
  }
277
+
232
278
  if (count > POINT_TO_PROCESS_LIMIT) {
233
279
  return null;
234
280
  }
281
+
235
282
  var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
236
283
  var outlines = [];
284
+
237
285
  for (i = 0; count && i <= height; i++) {
238
286
  var p = i * width1;
239
287
  var end = p + width;
288
+
240
289
  while (p < end && !points[p]) {
241
290
  p++;
242
291
  }
292
+
243
293
  if (p === end) {
244
294
  continue;
245
295
  }
296
+
246
297
  var coords = [p % width1, i];
247
298
  var type = points[p],
248
299
  p0 = p,
249
300
  pp;
301
+
250
302
  do {
251
303
  var step = steps[type];
304
+
252
305
  do {
253
306
  p += step;
254
307
  } while (!points[p]);
308
+
255
309
  pp = points[p];
310
+
256
311
  if (pp !== 5 && pp !== 10) {
257
312
  type = pp;
258
313
  points[p] = 0;
@@ -260,31 +315,42 @@ function compileType3Glyph(imgData) {
260
315
  type = pp & 0x33 * type >> 4;
261
316
  points[p] &= type >> 2 | type << 2;
262
317
  }
318
+
263
319
  coords.push(p % width1);
264
320
  coords.push(p / width1 | 0);
265
- --count;
321
+
322
+ if (!points[p]) {
323
+ --count;
324
+ }
266
325
  } while (p0 !== p);
326
+
267
327
  outlines.push(coords);
268
328
  --i;
269
329
  }
330
+
270
331
  var drawOutline = function drawOutline(c) {
271
332
  c.save();
272
333
  c.scale(1 / width, -1 / height);
273
334
  c.translate(0, -height);
274
335
  c.beginPath();
336
+
275
337
  for (var i = 0, ii = outlines.length; i < ii; i++) {
276
338
  var o = outlines[i];
277
339
  c.moveTo(o[0], o[1]);
340
+
278
341
  for (var j = 2, jj = o.length; j < jj; j += 2) {
279
342
  c.lineTo(o[j], o[j + 1]);
280
343
  }
281
344
  }
345
+
282
346
  c.fill();
283
347
  c.beginPath();
284
348
  c.restore();
285
349
  };
350
+
286
351
  return drawOutline;
287
352
  }
353
+
288
354
  var CanvasExtraState = function CanvasExtraStateClosure() {
289
355
  function CanvasExtraState() {
290
356
  this.alphaIsShape = false;
@@ -312,6 +378,7 @@ var CanvasExtraState = function CanvasExtraStateClosure() {
312
378
  this.activeSMask = null;
313
379
  this.resumeSMaskCtx = null;
314
380
  }
381
+
315
382
  CanvasExtraState.prototype = {
316
383
  clone: function CanvasExtraState_clone() {
317
384
  return Object.create(this);
@@ -323,9 +390,11 @@ var CanvasExtraState = function CanvasExtraStateClosure() {
323
390
  };
324
391
  return CanvasExtraState;
325
392
  }();
393
+
326
394
  var CanvasGraphics = function CanvasGraphicsClosure() {
327
395
  var EXECUTION_TIME = 15;
328
396
  var EXECUTION_STEPS = 10;
397
+
329
398
  function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, webGLContext, imageLayer) {
330
399
  this.ctx = canvasCtx;
331
400
  this.current = new CanvasExtraState();
@@ -348,16 +417,20 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
348
417
  this.smaskCounter = 0;
349
418
  this.tempSMask = null;
350
419
  this.cachedCanvases = new CachedCanvases(this.canvasFactory);
420
+
351
421
  if (canvasCtx) {
352
422
  addContextCurrentTransform(canvasCtx);
353
423
  }
354
- this.cachedGetSinglePixelWidth = null;
424
+
425
+ this._cachedGetSinglePixelWidth = null;
355
426
  }
427
+
356
428
  function putBinaryImageData(ctx, imgData) {
357
429
  if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
358
430
  ctx.putImageData(imgData, 0, 0);
359
431
  return;
360
432
  }
433
+
361
434
  var height = imgData.height,
362
435
  width = imgData.width;
363
436
  var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
@@ -369,6 +442,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
369
442
  var src = imgData.data;
370
443
  var dest = chunkImgData.data;
371
444
  var i, j, thisChunkHeight, elemsInThisChunk;
445
+
372
446
  if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
373
447
  var srcLength = src.byteLength;
374
448
  var dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
@@ -376,9 +450,11 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
376
450
  var fullSrcDiff = width + 7 >> 3;
377
451
  var white = 0xFFFFFFFF;
378
452
  var black = IsLittleEndianCached.value ? 0xFF000000 : 0x000000FF;
453
+
379
454
  for (i = 0; i < totalChunks; i++) {
380
455
  thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
381
456
  destPos = 0;
457
+
382
458
  for (j = 0; j < thisChunkHeight; j++) {
383
459
  var srcDiff = srcLength - srcPos;
384
460
  var k = 0;
@@ -386,6 +462,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
386
462
  var kEndUnrolled = kEnd & ~7;
387
463
  var mask = 0;
388
464
  var srcByte = 0;
465
+
389
466
  for (; k < kEndUnrolled; k += 8) {
390
467
  srcByte = src[srcPos++];
391
468
  dest32[destPos++] = srcByte & 128 ? white : black;
@@ -397,29 +474,35 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
397
474
  dest32[destPos++] = srcByte & 2 ? white : black;
398
475
  dest32[destPos++] = srcByte & 1 ? white : black;
399
476
  }
477
+
400
478
  for (; k < kEnd; k++) {
401
479
  if (mask === 0) {
402
480
  srcByte = src[srcPos++];
403
481
  mask = 128;
404
482
  }
483
+
405
484
  dest32[destPos++] = srcByte & mask ? white : black;
406
485
  mask >>= 1;
407
486
  }
408
487
  }
488
+
409
489
  while (destPos < dest32DataLength) {
410
490
  dest32[destPos++] = 0;
411
491
  }
492
+
412
493
  ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
413
494
  }
414
495
  } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
415
496
  j = 0;
416
497
  elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
498
+
417
499
  for (i = 0; i < fullChunks; i++) {
418
500
  dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
419
501
  srcPos += elemsInThisChunk;
420
502
  ctx.putImageData(chunkImgData, 0, j);
421
503
  j += FULL_CHUNK_HEIGHT;
422
504
  }
505
+
423
506
  if (i < totalChunks) {
424
507
  elemsInThisChunk = width * partialChunkHeight * 4;
425
508
  dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
@@ -428,24 +511,29 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
428
511
  } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
429
512
  thisChunkHeight = FULL_CHUNK_HEIGHT;
430
513
  elemsInThisChunk = width * thisChunkHeight;
514
+
431
515
  for (i = 0; i < totalChunks; i++) {
432
516
  if (i >= fullChunks) {
433
517
  thisChunkHeight = partialChunkHeight;
434
518
  elemsInThisChunk = width * thisChunkHeight;
435
519
  }
520
+
436
521
  destPos = 0;
522
+
437
523
  for (j = elemsInThisChunk; j--;) {
438
524
  dest[destPos++] = src[srcPos++];
439
525
  dest[destPos++] = src[srcPos++];
440
526
  dest[destPos++] = src[srcPos++];
441
527
  dest[destPos++] = 255;
442
528
  }
529
+
443
530
  ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
444
531
  }
445
532
  } else {
446
- throw new Error('bad image kind: ' + imgData.kind);
533
+ throw new Error("bad image kind: ".concat(imgData.kind));
447
534
  }
448
535
  }
536
+
449
537
  function putBinaryImageMask(ctx, imgData) {
450
538
  var height = imgData.height,
451
539
  width = imgData.width;
@@ -456,37 +544,47 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
456
544
  var srcPos = 0;
457
545
  var src = imgData.data;
458
546
  var dest = chunkImgData.data;
547
+
459
548
  for (var i = 0; i < totalChunks; i++) {
460
549
  var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
461
550
  var destPos = 3;
551
+
462
552
  for (var j = 0; j < thisChunkHeight; j++) {
463
553
  var mask = 0;
554
+
464
555
  for (var k = 0; k < width; k++) {
465
556
  if (!mask) {
466
557
  var elem = src[srcPos++];
467
558
  mask = 128;
468
559
  }
560
+
469
561
  dest[destPos] = elem & mask ? 0 : 255;
470
562
  destPos += 4;
471
563
  mask >>= 1;
472
564
  }
473
565
  }
566
+
474
567
  ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
475
568
  }
476
569
  }
570
+
477
571
  function copyCtxState(sourceCtx, destCtx) {
478
572
  var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha', 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit', 'globalCompositeOperation', 'font'];
573
+
479
574
  for (var i = 0, ii = properties.length; i < ii; i++) {
480
575
  var property = properties[i];
576
+
481
577
  if (sourceCtx[property] !== undefined) {
482
578
  destCtx[property] = sourceCtx[property];
483
579
  }
484
580
  }
581
+
485
582
  if (sourceCtx.setLineDash !== undefined) {
486
583
  destCtx.setLineDash(sourceCtx.getLineDash());
487
584
  destCtx.lineDashOffset = sourceCtx.lineDashOffset;
488
585
  }
489
586
  }
587
+
490
588
  function resetCtxToDefault(ctx) {
491
589
  ctx.strokeStyle = '#000000';
492
590
  ctx.fillStyle = '#000000';
@@ -498,15 +596,19 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
498
596
  ctx.miterLimit = 10;
499
597
  ctx.globalCompositeOperation = 'source-over';
500
598
  ctx.font = '10px sans-serif';
599
+
501
600
  if (ctx.setLineDash !== undefined) {
502
601
  ctx.setLineDash([]);
503
602
  ctx.lineDashOffset = 0;
504
603
  }
505
604
  }
605
+
506
606
  function composeSMaskBackdrop(bytes, r0, g0, b0) {
507
607
  var length = bytes.length;
608
+
508
609
  for (var i = 3; i < length; i += 4) {
509
610
  var alpha = bytes[i];
611
+
510
612
  if (alpha === 0) {
511
613
  bytes[i - 3] = r0;
512
614
  bytes[i - 2] = g0;
@@ -519,50 +621,62 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
519
621
  }
520
622
  }
521
623
  }
624
+
522
625
  function composeSMaskAlpha(maskData, layerData, transferMap) {
523
626
  var length = maskData.length;
524
627
  var scale = 1 / 255;
628
+
525
629
  for (var i = 3; i < length; i += 4) {
526
630
  var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
527
631
  layerData[i] = layerData[i] * alpha * scale | 0;
528
632
  }
529
633
  }
634
+
530
635
  function composeSMaskLuminosity(maskData, layerData, transferMap) {
531
636
  var length = maskData.length;
637
+
532
638
  for (var i = 3; i < length; i += 4) {
533
639
  var y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
534
640
  layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
535
641
  }
536
642
  }
643
+
537
644
  function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
538
645
  var hasBackdrop = !!backdrop;
539
646
  var r0 = hasBackdrop ? backdrop[0] : 0;
540
647
  var g0 = hasBackdrop ? backdrop[1] : 0;
541
648
  var b0 = hasBackdrop ? backdrop[2] : 0;
542
649
  var composeFn;
650
+
543
651
  if (subtype === 'Luminosity') {
544
652
  composeFn = composeSMaskLuminosity;
545
653
  } else {
546
654
  composeFn = composeSMaskAlpha;
547
655
  }
656
+
548
657
  var PIXELS_TO_PROCESS = 1048576;
549
658
  var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
659
+
550
660
  for (var row = 0; row < height; row += chunkSize) {
551
661
  var chunkHeight = Math.min(chunkSize, height - row);
552
662
  var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
553
663
  var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
664
+
554
665
  if (hasBackdrop) {
555
666
  composeSMaskBackdrop(maskData.data, r0, g0, b0);
556
667
  }
668
+
557
669
  composeFn(maskData.data, layerData.data, transferMap);
558
670
  maskCtx.putImageData(layerData, 0, row);
559
671
  }
560
672
  }
673
+
561
674
  function composeSMask(ctx, smask, layerCtx, webGLContext) {
562
675
  var mask = smask.canvas;
563
676
  var maskCtx = smask.context;
564
677
  ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
565
678
  var backdrop = smask.backdrop || null;
679
+
566
680
  if (!smask.transferMap && webGLContext.isEnabled) {
567
681
  var composed = webGLContext.composeSMask({
568
682
  layer: layerCtx.canvas,
@@ -576,9 +690,11 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
576
690
  ctx.drawImage(composed, smask.offsetX, smask.offsetY);
577
691
  return;
578
692
  }
693
+
579
694
  genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
580
695
  ctx.drawImage(mask, 0, 0);
581
696
  }
697
+
582
698
  var LINE_CAP_STYLES = ['butt', 'round', 'square'];
583
699
  var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
584
700
  var NORMAL_CLIP = {};
@@ -587,16 +703,17 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
587
703
  beginDrawing: function beginDrawing(_ref) {
588
704
  var transform = _ref.transform,
589
705
  viewport = _ref.viewport,
590
- transparency = _ref.transparency,
706
+ _ref$transparency = _ref.transparency,
707
+ transparency = _ref$transparency === void 0 ? false : _ref$transparency,
591
708
  _ref$background = _ref.background,
592
- background = _ref$background === undefined ? null : _ref$background;
593
-
709
+ background = _ref$background === void 0 ? null : _ref$background;
594
710
  var width = this.ctx.canvas.width;
595
711
  var height = this.ctx.canvas.height;
596
712
  this.ctx.save();
597
713
  this.ctx.fillStyle = background || 'rgb(255, 255, 255)';
598
714
  this.ctx.fillRect(0, 0, width, height);
599
715
  this.ctx.restore();
716
+
600
717
  if (transparency) {
601
718
  var transparentCanvas = this.cachedCanvases.getCanvas('transparent', width, height, true);
602
719
  this.compositeCtx = this.ctx;
@@ -605,61 +722,91 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
605
722
  this.ctx.save();
606
723
  this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
607
724
  }
725
+
608
726
  this.ctx.save();
609
727
  resetCtxToDefault(this.ctx);
728
+
610
729
  if (transform) {
611
730
  this.ctx.transform.apply(this.ctx, transform);
612
731
  }
732
+
613
733
  this.ctx.transform.apply(this.ctx, viewport.transform);
614
734
  this.baseTransform = this.ctx.mozCurrentTransform.slice();
735
+
615
736
  if (this.imageLayer) {
616
737
  this.imageLayer.beginLayout();
617
738
  }
618
739
  },
619
-
620
740
  executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
621
741
  var argsArray = operatorList.argsArray;
622
742
  var fnArray = operatorList.fnArray;
623
743
  var i = executionStartIdx || 0;
624
744
  var argsArrayLen = argsArray.length;
745
+
625
746
  if (argsArrayLen === i) {
626
747
  return i;
627
748
  }
749
+
628
750
  var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === 'function';
629
751
  var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
630
752
  var steps = 0;
631
753
  var commonObjs = this.commonObjs;
632
754
  var objs = this.objs;
633
755
  var fnId;
756
+
634
757
  while (true) {
635
758
  if (stepper !== undefined && i === stepper.nextBreakPoint) {
636
759
  stepper.breakIt(i, continueCallback);
637
760
  return i;
638
761
  }
762
+
639
763
  fnId = fnArray[i];
764
+
640
765
  if (fnId !== _util.OPS.dependency) {
641
766
  this[fnId].apply(this, argsArray[i]);
642
767
  } else {
643
- var deps = argsArray[i];
644
- for (var n = 0, nn = deps.length; n < nn; n++) {
645
- var depObjId = deps[n];
646
- var common = depObjId[0] === 'g' && depObjId[1] === '_';
647
- var objsPool = common ? commonObjs : objs;
648
- if (!objsPool.isResolved(depObjId)) {
649
- objsPool.get(depObjId, continueCallback);
650
- return i;
768
+ var _iteratorNormalCompletion = true;
769
+ var _didIteratorError = false;
770
+ var _iteratorError = undefined;
771
+
772
+ try {
773
+ for (var _iterator = argsArray[i][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
774
+ var depObjId = _step.value;
775
+ var objsPool = depObjId.startsWith('g_') ? commonObjs : objs;
776
+
777
+ if (!objsPool.has(depObjId)) {
778
+ objsPool.get(depObjId, continueCallback);
779
+ return i;
780
+ }
781
+ }
782
+ } catch (err) {
783
+ _didIteratorError = true;
784
+ _iteratorError = err;
785
+ } finally {
786
+ try {
787
+ if (!_iteratorNormalCompletion && _iterator["return"] != null) {
788
+ _iterator["return"]();
789
+ }
790
+ } finally {
791
+ if (_didIteratorError) {
792
+ throw _iteratorError;
793
+ }
651
794
  }
652
795
  }
653
796
  }
797
+
654
798
  i++;
799
+
655
800
  if (i === argsArrayLen) {
656
801
  return i;
657
802
  }
803
+
658
804
  if (chunkOperations && ++steps > EXECUTION_STEPS) {
659
805
  if (Date.now() > endTime) {
660
806
  continueCallback();
661
807
  return i;
662
808
  }
809
+
663
810
  steps = 0;
664
811
  }
665
812
  }
@@ -668,7 +815,9 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
668
815
  if (this.current.activeSMask !== null) {
669
816
  this.endSMaskGroup();
670
817
  }
818
+
671
819
  this.ctx.restore();
820
+
672
821
  if (this.transparentCanvas) {
673
822
  this.ctx = this.compositeCtx;
674
823
  this.ctx.save();
@@ -677,8 +826,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
677
826
  this.ctx.restore();
678
827
  this.transparentCanvas = null;
679
828
  }
829
+
680
830
  this.cachedCanvases.clear();
681
831
  this.webGLContext.clear();
832
+
682
833
  if (this.imageLayer) {
683
834
  this.imageLayer.endLayout();
684
835
  }
@@ -698,53 +849,66 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
698
849
  },
699
850
  setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
700
851
  var ctx = this.ctx;
852
+
701
853
  if (ctx.setLineDash !== undefined) {
702
854
  ctx.setLineDash(dashArray);
703
855
  ctx.lineDashOffset = dashPhase;
704
856
  }
705
857
  },
706
- setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {},
707
- setFlatness: function CanvasGraphics_setFlatness(flatness) {},
858
+ setRenderingIntent: function setRenderingIntent(intent) {},
859
+ setFlatness: function setFlatness(flatness) {},
708
860
  setGState: function CanvasGraphics_setGState(states) {
709
861
  for (var i = 0, ii = states.length; i < ii; i++) {
710
862
  var state = states[i];
711
863
  var key = state[0];
712
864
  var value = state[1];
865
+
713
866
  switch (key) {
714
867
  case 'LW':
715
868
  this.setLineWidth(value);
716
869
  break;
870
+
717
871
  case 'LC':
718
872
  this.setLineCap(value);
719
873
  break;
874
+
720
875
  case 'LJ':
721
876
  this.setLineJoin(value);
722
877
  break;
878
+
723
879
  case 'ML':
724
880
  this.setMiterLimit(value);
725
881
  break;
882
+
726
883
  case 'D':
727
884
  this.setDash(value[0], value[1]);
728
885
  break;
886
+
729
887
  case 'RI':
730
888
  this.setRenderingIntent(value);
731
889
  break;
890
+
732
891
  case 'FL':
733
892
  this.setFlatness(value);
734
893
  break;
894
+
735
895
  case 'Font':
736
896
  this.setFont(value[0], value[1]);
737
897
  break;
898
+
738
899
  case 'CA':
739
900
  this.current.strokeAlpha = state[1];
740
901
  break;
902
+
741
903
  case 'ca':
742
904
  this.current.fillAlpha = state[1];
743
905
  this.ctx.globalAlpha = state[1];
744
906
  break;
907
+
745
908
  case 'BM':
746
909
  this.ctx.globalCompositeOperation = value;
747
910
  break;
911
+
748
912
  case 'SMask':
749
913
  if (this.current.activeSMask) {
750
914
  if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
@@ -753,10 +917,13 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
753
917
  this.endSMaskGroup();
754
918
  }
755
919
  }
920
+
756
921
  this.current.activeSMask = value ? this.tempSMask : null;
922
+
757
923
  if (this.current.activeSMask) {
758
924
  this.beginSMaskGroup();
759
925
  }
926
+
760
927
  this.tempSMask = null;
761
928
  break;
762
929
  }
@@ -791,7 +958,9 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
791
958
  this.ctx.save();
792
959
  copyCtxState(groupCtx, this.ctx);
793
960
  this.current.resumeSMaskCtx = groupCtx;
961
+
794
962
  var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
963
+
795
964
  this.ctx.transform.apply(this.ctx, deltaTransform);
796
965
  groupCtx.save();
797
966
  groupCtx.setTransform(1, 0, 0, 1, 0, 0);
@@ -812,7 +981,9 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
812
981
  composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
813
982
  this.ctx.restore();
814
983
  copyCtxState(groupCtx, this.ctx);
984
+
815
985
  var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
986
+
816
987
  this.ctx.transform.apply(this.ctx, deltaTransform);
817
988
  },
818
989
  save: function CanvasGraphics_save() {
@@ -826,25 +997,28 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
826
997
  if (this.current.resumeSMaskCtx) {
827
998
  this.resumeSMaskGroup();
828
999
  }
1000
+
829
1001
  if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
830
1002
  this.endSMaskGroup();
831
1003
  }
1004
+
832
1005
  if (this.stateStack.length !== 0) {
833
1006
  this.current = this.stateStack.pop();
834
1007
  this.ctx.restore();
835
1008
  this.pendingClip = null;
836
- this.cachedGetSinglePixelWidth = null;
1009
+ this._cachedGetSinglePixelWidth = null;
837
1010
  }
838
1011
  },
839
1012
  transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
840
1013
  this.ctx.transform(a, b, c, d, e, f);
841
- this.cachedGetSinglePixelWidth = null;
1014
+ this._cachedGetSinglePixelWidth = null;
842
1015
  },
843
1016
  constructPath: function CanvasGraphics_constructPath(ops, args) {
844
1017
  var ctx = this.ctx;
845
1018
  var current = this.current;
846
1019
  var x = current.x,
847
1020
  y = current.y;
1021
+
848
1022
  for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
849
1023
  switch (ops[i] | 0) {
850
1024
  case _util.OPS.rectangle:
@@ -852,12 +1026,15 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
852
1026
  y = args[j++];
853
1027
  var width = args[j++];
854
1028
  var height = args[j++];
1029
+
855
1030
  if (width === 0) {
856
1031
  width = this.getSinglePixelWidth();
857
1032
  }
1033
+
858
1034
  if (height === 0) {
859
1035
  height = this.getSinglePixelWidth();
860
1036
  }
1037
+
861
1038
  var xw = x + width;
862
1039
  var yh = y + height;
863
1040
  this.ctx.moveTo(x, y);
@@ -867,39 +1044,46 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
867
1044
  this.ctx.lineTo(x, y);
868
1045
  this.ctx.closePath();
869
1046
  break;
1047
+
870
1048
  case _util.OPS.moveTo:
871
1049
  x = args[j++];
872
1050
  y = args[j++];
873
1051
  ctx.moveTo(x, y);
874
1052
  break;
1053
+
875
1054
  case _util.OPS.lineTo:
876
1055
  x = args[j++];
877
1056
  y = args[j++];
878
1057
  ctx.lineTo(x, y);
879
1058
  break;
1059
+
880
1060
  case _util.OPS.curveTo:
881
1061
  x = args[j + 4];
882
1062
  y = args[j + 5];
883
1063
  ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
884
1064
  j += 6;
885
1065
  break;
1066
+
886
1067
  case _util.OPS.curveTo2:
887
1068
  ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
888
1069
  x = args[j + 2];
889
1070
  y = args[j + 3];
890
1071
  j += 4;
891
1072
  break;
1073
+
892
1074
  case _util.OPS.curveTo3:
893
1075
  x = args[j + 2];
894
1076
  y = args[j + 3];
895
1077
  ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
896
1078
  j += 4;
897
1079
  break;
1080
+
898
1081
  case _util.OPS.closePath:
899
1082
  ctx.closePath();
900
1083
  break;
901
1084
  }
902
1085
  }
1086
+
903
1087
  current.setCurrentPoint(x, y);
904
1088
  },
905
1089
  closePath: function CanvasGraphics_closePath() {
@@ -909,19 +1093,27 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
909
1093
  consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
910
1094
  var ctx = this.ctx;
911
1095
  var strokeColor = this.current.strokeColor;
912
- ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
913
1096
  ctx.globalAlpha = this.current.strokeAlpha;
1097
+
914
1098
  if (strokeColor && strokeColor.hasOwnProperty('type') && strokeColor.type === 'Pattern') {
915
1099
  ctx.save();
1100
+ var transform = ctx.mozCurrentTransform;
1101
+
1102
+ var scale = _util.Util.singularValueDecompose2dScale(transform)[0];
1103
+
916
1104
  ctx.strokeStyle = strokeColor.getPattern(ctx, this);
1105
+ ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth * scale);
917
1106
  ctx.stroke();
918
1107
  ctx.restore();
919
1108
  } else {
1109
+ ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
920
1110
  ctx.stroke();
921
1111
  }
1112
+
922
1113
  if (consumePath) {
923
1114
  this.consumePath();
924
1115
  }
1116
+
925
1117
  ctx.globalAlpha = this.current.fillAlpha;
926
1118
  },
927
1119
  closeStroke: function CanvasGraphics_closeStroke() {
@@ -934,23 +1126,29 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
934
1126
  var fillColor = this.current.fillColor;
935
1127
  var isPatternFill = this.current.patternFill;
936
1128
  var needRestore = false;
1129
+
937
1130
  if (isPatternFill) {
938
1131
  ctx.save();
1132
+
939
1133
  if (this.baseTransform) {
940
1134
  ctx.setTransform.apply(ctx, this.baseTransform);
941
1135
  }
1136
+
942
1137
  ctx.fillStyle = fillColor.getPattern(ctx, this);
943
1138
  needRestore = true;
944
1139
  }
1140
+
945
1141
  if (this.pendingEOFill) {
946
1142
  ctx.fill('evenodd');
947
1143
  this.pendingEOFill = false;
948
1144
  } else {
949
1145
  ctx.fill();
950
1146
  }
1147
+
951
1148
  if (needRestore) {
952
1149
  ctx.restore();
953
1150
  }
1151
+
954
1152
  if (consumePath) {
955
1153
  this.consumePath();
956
1154
  }
@@ -995,18 +1193,22 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
995
1193
  endText: function CanvasGraphics_endText() {
996
1194
  var paths = this.pendingTextPaths;
997
1195
  var ctx = this.ctx;
1196
+
998
1197
  if (paths === undefined) {
999
1198
  ctx.beginPath();
1000
1199
  return;
1001
1200
  }
1201
+
1002
1202
  ctx.save();
1003
1203
  ctx.beginPath();
1204
+
1004
1205
  for (var i = 0; i < paths.length; i++) {
1005
1206
  var path = paths[i];
1006
1207
  ctx.setTransform.apply(ctx, path.transform);
1007
1208
  ctx.translate(path.x, path.y);
1008
1209
  path.addToPath(ctx, path.fontSize);
1009
1210
  }
1211
+
1010
1212
  ctx.restore();
1011
1213
  ctx.clip();
1012
1214
  ctx.beginPath();
@@ -1027,32 +1229,38 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1027
1229
  setFont: function CanvasGraphics_setFont(fontRefName, size) {
1028
1230
  var fontObj = this.commonObjs.get(fontRefName);
1029
1231
  var current = this.current;
1232
+
1030
1233
  if (!fontObj) {
1031
- throw new Error('Can\'t find font for ' + fontRefName);
1234
+ throw new Error("Can't find font for ".concat(fontRefName));
1032
1235
  }
1236
+
1033
1237
  current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
1238
+
1034
1239
  if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
1035
1240
  (0, _util.warn)('Invalid font matrix for font ' + fontRefName);
1036
1241
  }
1242
+
1037
1243
  if (size < 0) {
1038
1244
  size = -size;
1039
1245
  current.fontDirection = -1;
1040
1246
  } else {
1041
1247
  current.fontDirection = 1;
1042
1248
  }
1249
+
1043
1250
  this.current.font = fontObj;
1044
1251
  this.current.fontSize = size;
1252
+
1045
1253
  if (fontObj.isType3Font) {
1046
1254
  return;
1047
1255
  }
1256
+
1048
1257
  var name = fontObj.loadedName || 'sans-serif';
1049
1258
  var bold = fontObj.black ? '900' : fontObj.bold ? 'bold' : 'normal';
1050
1259
  var italic = fontObj.italic ? 'italic' : 'normal';
1051
- var typeface = '"' + name + '", ' + fontObj.fallbackName;
1260
+ var typeface = "\"".concat(name, "\", ").concat(fontObj.fallbackName);
1052
1261
  var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
1053
1262
  this.current.fontSizeScale = size / browserFontSize;
1054
- var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
1055
- this.ctx.font = rule;
1263
+ this.ctx.font = "".concat(italic, " ").concat(bold, " ").concat(browserFontSize, "px ").concat(typeface);
1056
1264
  },
1057
1265
  setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
1058
1266
  this.current.textRenderingMode = mode;
@@ -1087,32 +1295,40 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1087
1295
  var isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
1088
1296
  var patternFill = current.patternFill && font.data;
1089
1297
  var addToPath;
1298
+
1090
1299
  if (font.disableFontFace || isAddToPathSet || patternFill) {
1091
1300
  addToPath = font.getPathGenerator(this.commonObjs, character);
1092
1301
  }
1302
+
1093
1303
  if (font.disableFontFace || patternFill) {
1094
1304
  ctx.save();
1095
1305
  ctx.translate(x, y);
1096
1306
  ctx.beginPath();
1097
1307
  addToPath(ctx, fontSize);
1308
+
1098
1309
  if (patternTransform) {
1099
1310
  ctx.setTransform.apply(ctx, patternTransform);
1100
1311
  }
1312
+
1101
1313
  if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1102
1314
  ctx.fill();
1103
1315
  }
1316
+
1104
1317
  if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1105
1318
  ctx.stroke();
1106
1319
  }
1320
+
1107
1321
  ctx.restore();
1108
1322
  } else {
1109
1323
  if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1110
1324
  ctx.fillText(character, x, y);
1111
1325
  }
1326
+
1112
1327
  if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1113
1328
  ctx.strokeText(character, x, y);
1114
1329
  }
1115
1330
  }
1331
+
1116
1332
  if (isAddToPathSet) {
1117
1333
  var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
1118
1334
  paths.push({
@@ -1126,29 +1342,38 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1126
1342
  },
1127
1343
 
1128
1344
  get isFontSubpixelAAEnabled() {
1129
- var ctx = this.canvasFactory.create(10, 10).context;
1345
+ var _this$cachedCanvases$ = this.cachedCanvases.getCanvas('isFontSubpixelAAEnabled', 10, 10),
1346
+ ctx = _this$cachedCanvases$.context;
1347
+
1130
1348
  ctx.scale(1.5, 1);
1131
1349
  ctx.fillText('I', 0, 10);
1132
1350
  var data = ctx.getImageData(0, 0, 10, 10).data;
1133
1351
  var enabled = false;
1352
+
1134
1353
  for (var i = 3; i < data.length; i += 4) {
1135
1354
  if (data[i] > 0 && data[i] < 255) {
1136
1355
  enabled = true;
1137
1356
  break;
1138
1357
  }
1139
1358
  }
1359
+
1140
1360
  return (0, _util.shadow)(this, 'isFontSubpixelAAEnabled', enabled);
1141
1361
  },
1362
+
1142
1363
  showText: function CanvasGraphics_showText(glyphs) {
1143
1364
  var current = this.current;
1144
1365
  var font = current.font;
1366
+
1145
1367
  if (font.isType3Font) {
1146
1368
  return this.showType3Text(glyphs);
1147
1369
  }
1370
+
1148
1371
  var fontSize = current.fontSize;
1372
+
1149
1373
  if (fontSize === 0) {
1150
- return;
1374
+ return undefined;
1151
1375
  }
1376
+
1152
1377
  var ctx = this.ctx;
1153
1378
  var fontSizeScale = current.fontSizeScale;
1154
1379
  var charSpacing = current.charSpacing;
@@ -1162,7 +1387,8 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1162
1387
  var widthAdvanceScale = fontSize * current.fontMatrix[0];
1163
1388
  var simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
1164
1389
  ctx.save();
1165
- var patternTransform = void 0;
1390
+ var patternTransform;
1391
+
1166
1392
  if (current.patternFill) {
1167
1393
  ctx.save();
1168
1394
  var pattern = current.fillColor.getPattern(ctx, this);
@@ -1170,43 +1396,54 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1170
1396
  ctx.restore();
1171
1397
  ctx.fillStyle = pattern;
1172
1398
  }
1399
+
1173
1400
  ctx.transform.apply(ctx, current.textMatrix);
1174
1401
  ctx.translate(current.x, current.y + current.textRise);
1402
+
1175
1403
  if (fontDirection > 0) {
1176
1404
  ctx.scale(textHScale, -1);
1177
1405
  } else {
1178
1406
  ctx.scale(textHScale, 1);
1179
1407
  }
1408
+
1180
1409
  var lineWidth = current.lineWidth;
1181
1410
  var scale = current.textMatrixScale;
1411
+
1182
1412
  if (scale === 0 || lineWidth === 0) {
1183
1413
  var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
1414
+
1184
1415
  if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1185
- this.cachedGetSinglePixelWidth = null;
1416
+ this._cachedGetSinglePixelWidth = null;
1186
1417
  lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
1187
1418
  }
1188
1419
  } else {
1189
1420
  lineWidth /= scale;
1190
1421
  }
1422
+
1191
1423
  if (fontSizeScale !== 1.0) {
1192
1424
  ctx.scale(fontSizeScale, fontSizeScale);
1193
1425
  lineWidth /= fontSizeScale;
1194
1426
  }
1427
+
1195
1428
  ctx.lineWidth = lineWidth;
1196
1429
  var x = 0,
1197
1430
  i;
1431
+
1198
1432
  for (i = 0; i < glyphsLength; ++i) {
1199
1433
  var glyph = glyphs[i];
1434
+
1200
1435
  if ((0, _util.isNum)(glyph)) {
1201
1436
  x += spacingDir * glyph * fontSize / 1000;
1202
1437
  continue;
1203
1438
  }
1439
+
1204
1440
  var restoreNeeded = false;
1205
1441
  var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
1206
1442
  var character = glyph.fontChar;
1207
1443
  var accent = glyph.accent;
1208
1444
  var scaledX, scaledY, scaledAccentX, scaledAccentY;
1209
1445
  var width = glyph.width;
1446
+
1210
1447
  if (vertical) {
1211
1448
  var vmetric, vx, vy;
1212
1449
  vmetric = glyph.vmetric || defaultVMetrics;
@@ -1220,8 +1457,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1220
1457
  scaledX = x / fontSizeScale;
1221
1458
  scaledY = 0;
1222
1459
  }
1460
+
1223
1461
  if (font.remeasure && width > 0) {
1224
1462
  var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
1463
+
1225
1464
  if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
1226
1465
  var characterScaleX = width / measuredWidth;
1227
1466
  restoreNeeded = true;
@@ -1232,11 +1471,13 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1232
1471
  scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
1233
1472
  }
1234
1473
  }
1474
+
1235
1475
  if (glyph.isInFont || font.missingFile) {
1236
1476
  if (simpleFillText && !accent) {
1237
1477
  ctx.fillText(character, scaledX, scaledY);
1238
1478
  } else {
1239
1479
  this.paintChar(character, scaledX, scaledY, patternTransform);
1480
+
1240
1481
  if (accent) {
1241
1482
  scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
1242
1483
  scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
@@ -1244,17 +1485,21 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1244
1485
  }
1245
1486
  }
1246
1487
  }
1488
+
1247
1489
  var charWidth = width * widthAdvanceScale + spacing * fontDirection;
1248
1490
  x += charWidth;
1491
+
1249
1492
  if (restoreNeeded) {
1250
1493
  ctx.restore();
1251
1494
  }
1252
1495
  }
1496
+
1253
1497
  if (vertical) {
1254
1498
  current.y -= x * textHScale;
1255
1499
  } else {
1256
1500
  current.x += x * textHScale;
1257
1501
  }
1502
+
1258
1503
  ctx.restore();
1259
1504
  },
1260
1505
  showType3Text: function CanvasGraphics_showType3Text(glyphs) {
@@ -1271,39 +1516,49 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1271
1516
  var glyphsLength = glyphs.length;
1272
1517
  var isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
1273
1518
  var i, glyph, width, spacingLength;
1519
+
1274
1520
  if (isTextInvisible || fontSize === 0) {
1275
1521
  return;
1276
1522
  }
1277
- this.cachedGetSinglePixelWidth = null;
1523
+
1524
+ this._cachedGetSinglePixelWidth = null;
1278
1525
  ctx.save();
1279
1526
  ctx.transform.apply(ctx, current.textMatrix);
1280
1527
  ctx.translate(current.x, current.y);
1281
1528
  ctx.scale(textHScale, fontDirection);
1529
+
1282
1530
  for (i = 0; i < glyphsLength; ++i) {
1283
1531
  glyph = glyphs[i];
1532
+
1284
1533
  if ((0, _util.isNum)(glyph)) {
1285
1534
  spacingLength = spacingDir * glyph * fontSize / 1000;
1286
1535
  this.ctx.translate(spacingLength, 0);
1287
1536
  current.x += spacingLength * textHScale;
1288
1537
  continue;
1289
1538
  }
1539
+
1290
1540
  var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
1291
1541
  var operatorList = font.charProcOperatorList[glyph.operatorListId];
1542
+
1292
1543
  if (!operatorList) {
1293
- (0, _util.warn)('Type3 character "' + glyph.operatorListId + '" is not available.');
1544
+ (0, _util.warn)("Type3 character \"".concat(glyph.operatorListId, "\" is not available."));
1294
1545
  continue;
1295
1546
  }
1547
+
1296
1548
  this.processingType3 = glyph;
1297
1549
  this.save();
1298
1550
  ctx.scale(fontSize, fontSize);
1299
1551
  ctx.transform.apply(ctx, fontMatrix);
1300
1552
  this.executeOperatorList(operatorList);
1301
1553
  this.restore();
1554
+
1302
1555
  var transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
1556
+
1303
1557
  width = transformed[0] * fontSize + spacing;
1304
1558
  ctx.translate(width, 0);
1305
1559
  current.x += width * textHScale;
1306
1560
  }
1561
+
1307
1562
  ctx.restore();
1308
1563
  this.processingType3 = null;
1309
1564
  },
@@ -1317,6 +1572,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1317
1572
  var _this = this;
1318
1573
 
1319
1574
  var pattern;
1575
+
1320
1576
  if (IR[0] === 'TilingPattern') {
1321
1577
  var color = IR[1];
1322
1578
  var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
@@ -1329,6 +1585,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1329
1585
  } else {
1330
1586
  pattern = (0, _pattern_helper.getShadingPatternFromIR)(IR);
1331
1587
  }
1588
+
1332
1589
  return pattern;
1333
1590
  },
1334
1591
  setStrokeColorN: function CanvasGraphics_setStrokeColorN() {
@@ -1340,11 +1597,13 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1340
1597
  },
1341
1598
  setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
1342
1599
  var color = _util.Util.makeCssRgb(r, g, b);
1600
+
1343
1601
  this.ctx.strokeStyle = color;
1344
1602
  this.current.strokeColor = color;
1345
1603
  },
1346
1604
  setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
1347
1605
  var color = _util.Util.makeCssRgb(r, g, b);
1606
+
1348
1607
  this.ctx.fillStyle = color;
1349
1608
  this.current.fillColor = color;
1350
1609
  this.current.patternFill = false;
@@ -1355,14 +1614,20 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1355
1614
  var pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
1356
1615
  ctx.fillStyle = pattern.getPattern(ctx, this, true);
1357
1616
  var inv = ctx.mozCurrentTransformInverse;
1617
+
1358
1618
  if (inv) {
1359
1619
  var canvas = ctx.canvas;
1360
1620
  var width = canvas.width;
1361
1621
  var height = canvas.height;
1622
+
1362
1623
  var bl = _util.Util.applyTransform([0, 0], inv);
1624
+
1363
1625
  var br = _util.Util.applyTransform([0, height], inv);
1626
+
1364
1627
  var ul = _util.Util.applyTransform([width, 0], inv);
1628
+
1365
1629
  var ur = _util.Util.applyTransform([width, height], inv);
1630
+
1366
1631
  var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
1367
1632
  var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
1368
1633
  var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
@@ -1371,6 +1636,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1371
1636
  } else {
1372
1637
  this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
1373
1638
  }
1639
+
1374
1640
  this.restore();
1375
1641
  },
1376
1642
  beginInlineImage: function CanvasGraphics_beginInlineImage() {
@@ -1382,11 +1648,14 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1382
1648
  paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
1383
1649
  this.save();
1384
1650
  this.baseTransformStack.push(this.baseTransform);
1651
+
1385
1652
  if (Array.isArray(matrix) && matrix.length === 6) {
1386
1653
  this.transform.apply(this, matrix);
1387
1654
  }
1655
+
1388
1656
  this.baseTransform = this.ctx.mozCurrentTransform;
1389
- if (Array.isArray(bbox) && bbox.length === 4) {
1657
+
1658
+ if (bbox) {
1390
1659
  var width = bbox[2] - bbox[0];
1391
1660
  var height = bbox[3] - bbox[1];
1392
1661
  this.ctx.rect(bbox[0], bbox[1], width, height);
@@ -1401,20 +1670,27 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1401
1670
  beginGroup: function CanvasGraphics_beginGroup(group) {
1402
1671
  this.save();
1403
1672
  var currentCtx = this.ctx;
1673
+
1404
1674
  if (!group.isolated) {
1405
1675
  (0, _util.info)('TODO: Support non-isolated groups.');
1406
1676
  }
1677
+
1407
1678
  if (group.knockout) {
1408
1679
  (0, _util.warn)('Knockout groups not supported.');
1409
1680
  }
1681
+
1410
1682
  var currentTransform = currentCtx.mozCurrentTransform;
1683
+
1411
1684
  if (group.matrix) {
1412
1685
  currentCtx.transform.apply(currentCtx, group.matrix);
1413
1686
  }
1687
+
1414
1688
  if (!group.bbox) {
1415
1689
  throw new Error('Bounding box is required.');
1416
1690
  }
1691
+
1417
1692
  var bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
1693
+
1418
1694
  var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
1419
1695
  bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
1420
1696
  var offsetX = Math.floor(bounds[0]);
@@ -1423,23 +1699,29 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1423
1699
  var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
1424
1700
  var scaleX = 1,
1425
1701
  scaleY = 1;
1702
+
1426
1703
  if (drawnWidth > MAX_GROUP_SIZE) {
1427
1704
  scaleX = drawnWidth / MAX_GROUP_SIZE;
1428
1705
  drawnWidth = MAX_GROUP_SIZE;
1429
1706
  }
1707
+
1430
1708
  if (drawnHeight > MAX_GROUP_SIZE) {
1431
1709
  scaleY = drawnHeight / MAX_GROUP_SIZE;
1432
1710
  drawnHeight = MAX_GROUP_SIZE;
1433
1711
  }
1712
+
1434
1713
  var cacheId = 'groupAt' + this.groupLevel;
1714
+
1435
1715
  if (group.smask) {
1436
1716
  cacheId += '_smask_' + this.smaskCounter++ % 2;
1437
1717
  }
1718
+
1438
1719
  var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
1439
1720
  var groupCtx = scratchCanvas.context;
1440
1721
  groupCtx.scale(1 / scaleX, 1 / scaleY);
1441
1722
  groupCtx.translate(-offsetX, -offsetY);
1442
1723
  groupCtx.transform.apply(groupCtx, currentTransform);
1724
+
1443
1725
  if (group.smask) {
1444
1726
  this.smaskStack.push({
1445
1727
  canvas: scratchCanvas.canvas,
@@ -1458,6 +1740,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1458
1740
  currentCtx.translate(offsetX, offsetY);
1459
1741
  currentCtx.scale(scaleX, scaleY);
1460
1742
  }
1743
+
1461
1744
  copyCtxState(currentCtx, groupCtx);
1462
1745
  this.ctx = groupCtx;
1463
1746
  this.setGState([['BM', 'source-over'], ['ca', 1], ['CA', 1]]);
@@ -1469,20 +1752,24 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1469
1752
  this.groupLevel--;
1470
1753
  var groupCtx = this.ctx;
1471
1754
  this.ctx = this.groupStack.pop();
1755
+
1472
1756
  if (this.ctx.imageSmoothingEnabled !== undefined) {
1473
1757
  this.ctx.imageSmoothingEnabled = false;
1474
1758
  } else {
1475
1759
  this.ctx.mozImageSmoothingEnabled = false;
1476
1760
  }
1761
+
1477
1762
  if (group.smask) {
1478
1763
  this.tempSMask = this.smaskStack.pop();
1479
1764
  } else {
1480
1765
  this.ctx.drawImage(groupCtx.canvas, 0, 0);
1481
1766
  }
1767
+
1482
1768
  this.restore();
1483
1769
  },
1484
1770
  beginAnnotations: function CanvasGraphics_beginAnnotations() {
1485
1771
  this.save();
1772
+
1486
1773
  if (this.baseTransform) {
1487
1774
  this.ctx.setTransform.apply(this.ctx, this.baseTransform);
1488
1775
  }
@@ -1494,6 +1781,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1494
1781
  this.save();
1495
1782
  resetCtxToDefault(this.ctx);
1496
1783
  this.current = new CanvasExtraState();
1784
+
1497
1785
  if (Array.isArray(rect) && rect.length === 4) {
1498
1786
  var width = rect[2] - rect[0];
1499
1787
  var height = rect[3] - rect[1];
@@ -1501,6 +1789,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1501
1789
  this.clip();
1502
1790
  this.endPath();
1503
1791
  }
1792
+
1504
1793
  this.transform.apply(this, transform);
1505
1794
  this.transform.apply(this, matrix);
1506
1795
  },
@@ -1508,15 +1797,18 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1508
1797
  this.restore();
1509
1798
  },
1510
1799
  paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
1511
- var domImage = this.objs.get(objId);
1800
+ var domImage = this.processingType3 ? this.commonObjs.get(objId) : this.objs.get(objId);
1801
+
1512
1802
  if (!domImage) {
1513
1803
  (0, _util.warn)('Dependent image isn\'t ready yet');
1514
1804
  return;
1515
1805
  }
1806
+
1516
1807
  this.save();
1517
1808
  var ctx = this.ctx;
1518
1809
  ctx.scale(1 / w, -1 / h);
1519
1810
  ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height, 0, -h, w, h);
1811
+
1520
1812
  if (this.imageLayer) {
1521
1813
  var currentTransform = ctx.mozCurrentTransformInverse;
1522
1814
  var position = this.getCanvasPosition(0, 0);
@@ -1528,6 +1820,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1528
1820
  height: h / currentTransform[3]
1529
1821
  });
1530
1822
  }
1823
+
1531
1824
  this.restore();
1532
1825
  },
1533
1826
  paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
@@ -1537,6 +1830,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1537
1830
  var fillColor = this.current.fillColor;
1538
1831
  var isPatternFill = this.current.patternFill;
1539
1832
  var glyph = this.processingType3;
1833
+
1540
1834
  if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
1541
1835
  if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
1542
1836
  glyph.compiled = compileType3Glyph({
@@ -1548,10 +1842,12 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1548
1842
  glyph.compiled = null;
1549
1843
  }
1550
1844
  }
1845
+
1551
1846
  if (glyph && glyph.compiled) {
1552
1847
  glyph.compiled(ctx);
1553
1848
  return;
1554
1849
  }
1850
+
1555
1851
  var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
1556
1852
  var maskCtx = maskCanvas.context;
1557
1853
  maskCtx.save();
@@ -1576,6 +1872,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1576
1872
  maskCtx.fillRect(0, 0, width, height);
1577
1873
  maskCtx.restore();
1578
1874
  var ctx = this.ctx;
1875
+
1579
1876
  for (var i = 0, ii = positions.length; i < ii; i += 2) {
1580
1877
  ctx.save();
1581
1878
  ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
@@ -1588,6 +1885,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1588
1885
  var ctx = this.ctx;
1589
1886
  var fillColor = this.current.fillColor;
1590
1887
  var isPatternFill = this.current.patternFill;
1888
+
1591
1889
  for (var i = 0, ii = images.length; i < ii; i++) {
1592
1890
  var image = images[i];
1593
1891
  var width = image.width,
@@ -1608,22 +1906,27 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1608
1906
  }
1609
1907
  },
1610
1908
  paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
1611
- var imgData = this.objs.get(objId);
1909
+ var imgData = this.processingType3 ? this.commonObjs.get(objId) : this.objs.get(objId);
1910
+
1612
1911
  if (!imgData) {
1613
1912
  (0, _util.warn)('Dependent image isn\'t ready yet');
1614
1913
  return;
1615
1914
  }
1915
+
1616
1916
  this.paintInlineImageXObject(imgData);
1617
1917
  },
1618
1918
  paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
1619
- var imgData = this.objs.get(objId);
1919
+ var imgData = this.processingType3 ? this.commonObjs.get(objId) : this.objs.get(objId);
1920
+
1620
1921
  if (!imgData) {
1621
1922
  (0, _util.warn)('Dependent image isn\'t ready yet');
1622
1923
  return;
1623
1924
  }
1925
+
1624
1926
  var width = imgData.width;
1625
1927
  var height = imgData.height;
1626
1928
  var map = [];
1929
+
1627
1930
  for (var i = 0, ii = positions.length; i < ii; i += 2) {
1628
1931
  map.push({
1629
1932
  transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
@@ -1633,6 +1936,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1633
1936
  h: height
1634
1937
  });
1635
1938
  }
1939
+
1636
1940
  this.paintInlineImageXObjectGroup(imgData, map);
1637
1941
  },
1638
1942
  paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
@@ -1649,6 +1953,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1649
1953
  d = currentTransform[3];
1650
1954
  var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
1651
1955
  var imgToPaint, tmpCanvas;
1956
+
1652
1957
  if (typeof HTMLElement === 'function' && imgData instanceof HTMLElement || !imgData.data) {
1653
1958
  imgToPaint = imgData;
1654
1959
  } else {
@@ -1657,20 +1962,25 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1657
1962
  putBinaryImageData(tmpCtx, imgData);
1658
1963
  imgToPaint = tmpCanvas.canvas;
1659
1964
  }
1965
+
1660
1966
  var paintWidth = width,
1661
1967
  paintHeight = height;
1662
1968
  var tmpCanvasId = 'prescale1';
1969
+
1663
1970
  while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
1664
1971
  var newWidth = paintWidth,
1665
1972
  newHeight = paintHeight;
1973
+
1666
1974
  if (widthScale > 2 && paintWidth > 1) {
1667
1975
  newWidth = Math.ceil(paintWidth / 2);
1668
1976
  widthScale /= paintWidth / newWidth;
1669
1977
  }
1978
+
1670
1979
  if (heightScale > 2 && paintHeight > 1) {
1671
1980
  newHeight = Math.ceil(paintHeight / 2);
1672
1981
  heightScale /= paintHeight / newHeight;
1673
1982
  }
1983
+
1674
1984
  tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
1675
1985
  tmpCtx = tmpCanvas.context;
1676
1986
  tmpCtx.clearRect(0, 0, newWidth, newHeight);
@@ -1680,7 +1990,9 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1680
1990
  paintHeight = newHeight;
1681
1991
  tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
1682
1992
  }
1993
+
1683
1994
  ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
1995
+
1684
1996
  if (this.imageLayer) {
1685
1997
  var position = this.getCanvasPosition(0, -height);
1686
1998
  this.imageLayer.appendImage({
@@ -1691,6 +2003,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1691
2003
  height: height / currentTransform[3]
1692
2004
  });
1693
2005
  }
2006
+
1694
2007
  this.restore();
1695
2008
  },
1696
2009
  paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
@@ -1700,12 +2013,14 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1700
2013
  var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
1701
2014
  var tmpCtx = tmpCanvas.context;
1702
2015
  putBinaryImageData(tmpCtx, imgData);
2016
+
1703
2017
  for (var i = 0, ii = map.length; i < ii; i++) {
1704
2018
  var entry = map[i];
1705
2019
  ctx.save();
1706
2020
  ctx.transform.apply(ctx, entry.transform);
1707
2021
  ctx.scale(1, -1);
1708
2022
  ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
2023
+
1709
2024
  if (this.imageLayer) {
1710
2025
  var position = this.getCanvasPosition(entry.x, entry.y);
1711
2026
  this.imageLayer.appendImage({
@@ -1716,6 +2031,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1716
2031
  height: h
1717
2032
  });
1718
2033
  }
2034
+
1719
2035
  ctx.restore();
1720
2036
  }
1721
2037
  },
@@ -1734,33 +2050,38 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1734
2050
  endCompat: function CanvasGraphics_endCompat() {},
1735
2051
  consumePath: function CanvasGraphics_consumePath() {
1736
2052
  var ctx = this.ctx;
2053
+
1737
2054
  if (this.pendingClip) {
1738
2055
  if (this.pendingClip === EO_CLIP) {
1739
2056
  ctx.clip('evenodd');
1740
2057
  } else {
1741
2058
  ctx.clip();
1742
2059
  }
2060
+
1743
2061
  this.pendingClip = null;
1744
2062
  }
2063
+
1745
2064
  ctx.beginPath();
1746
2065
  },
1747
- getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
1748
- if (this.cachedGetSinglePixelWidth === null) {
1749
- this.ctx.save();
2066
+ getSinglePixelWidth: function getSinglePixelWidth(scale) {
2067
+ if (this._cachedGetSinglePixelWidth === null) {
1750
2068
  var inverse = this.ctx.mozCurrentTransformInverse;
1751
- this.ctx.restore();
1752
- this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
2069
+ this._cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
1753
2070
  }
1754
- return this.cachedGetSinglePixelWidth;
2071
+
2072
+ return this._cachedGetSinglePixelWidth;
1755
2073
  },
1756
2074
  getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
1757
2075
  var transform = this.ctx.mozCurrentTransform;
1758
2076
  return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
1759
2077
  }
1760
2078
  };
2079
+
1761
2080
  for (var op in _util.OPS) {
1762
2081
  CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
1763
2082
  }
2083
+
1764
2084
  return CanvasGraphics;
1765
2085
  }();
2086
+
1766
2087
  exports.CanvasGraphics = CanvasGraphics;