pdfjs-dist 2.0.489 → 2.2.228

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 (169) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +18515 -11402
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +48266 -37137
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/external/url/url-lib.js +627 -0
  10. package/image_decoders/pdf.image_decoders.js +11350 -0
  11. package/image_decoders/pdf.image_decoders.js.map +1 -0
  12. package/image_decoders/pdf.image_decoders.min.js +1 -0
  13. package/lib/core/annotation.js +587 -242
  14. package/lib/core/arithmetic_decoder.js +275 -245
  15. package/lib/core/bidi.js +65 -6
  16. package/lib/core/ccitt.js +173 -18
  17. package/lib/core/ccitt_stream.js +15 -6
  18. package/lib/core/cff_parser.js +433 -61
  19. package/lib/core/charsets.js +5 -4
  20. package/lib/core/chunked_stream.js +400 -152
  21. package/lib/core/cmap.js +326 -87
  22. package/lib/core/colorspace.js +874 -594
  23. package/lib/core/core_utils.js +147 -0
  24. package/lib/core/crypto.js +290 -45
  25. package/lib/core/document.js +560 -268
  26. package/lib/core/encodings.js +19 -10
  27. package/lib/core/evaluator.js +1005 -360
  28. package/lib/core/font_renderer.js +331 -97
  29. package/lib/core/fonts.js +812 -195
  30. package/lib/core/function.js +284 -71
  31. package/lib/core/glyphlist.js +4 -3
  32. package/lib/core/image.js +169 -62
  33. package/lib/core/image_utils.js +111 -0
  34. package/lib/core/jbig2.js +479 -66
  35. package/lib/core/jbig2_stream.js +19 -8
  36. package/lib/core/jpeg_stream.js +38 -13
  37. package/lib/core/jpg.js +253 -29
  38. package/lib/core/jpx.js +396 -6
  39. package/lib/core/jpx_stream.js +18 -6
  40. package/lib/core/metrics.js +15 -15
  41. package/lib/core/murmurhash3.js +56 -34
  42. package/lib/core/obj.js +1354 -488
  43. package/lib/core/operator_list.js +144 -31
  44. package/lib/core/parser.js +539 -191
  45. package/lib/core/pattern.js +148 -14
  46. package/lib/core/pdf_manager.js +323 -133
  47. package/lib/core/primitives.js +111 -24
  48. package/lib/core/ps_parser.js +134 -45
  49. package/lib/core/standard_fonts.js +17 -17
  50. package/lib/core/stream.js +313 -34
  51. package/lib/core/type1_parser.js +143 -13
  52. package/lib/core/unicode.js +32 -5
  53. package/lib/core/worker.js +217 -190
  54. package/lib/core/worker_stream.js +277 -0
  55. package/lib/display/annotation_layer.js +450 -133
  56. package/lib/display/api.js +1597 -784
  57. package/lib/display/api_compatibility.js +11 -13
  58. package/lib/display/canvas.js +360 -44
  59. package/lib/display/content_disposition.js +83 -32
  60. package/lib/display/display_utils.js +747 -0
  61. package/lib/display/fetch_stream.js +221 -90
  62. package/lib/display/font_loader.js +468 -236
  63. package/lib/display/metadata.js +38 -16
  64. package/lib/display/network.js +635 -428
  65. package/lib/display/network_utils.js +32 -19
  66. package/lib/display/node_stream.js +367 -175
  67. package/lib/display/pattern_helper.js +81 -31
  68. package/lib/display/svg.js +1235 -519
  69. package/lib/display/text_layer.js +153 -29
  70. package/lib/display/transport_stream.js +345 -94
  71. package/lib/display/webgl.js +64 -18
  72. package/lib/display/worker_options.js +5 -4
  73. package/lib/display/xml_parser.js +166 -53
  74. package/lib/examples/node/domstubs.js +60 -4
  75. package/lib/pdf.js +36 -14
  76. package/lib/pdf.worker.js +5 -3
  77. package/lib/shared/compatibility.js +158 -564
  78. package/lib/shared/global_scope.js +2 -2
  79. package/lib/shared/is_node.js +4 -4
  80. package/lib/shared/message_handler.js +521 -0
  81. package/lib/shared/streams_polyfill.js +21 -17
  82. package/lib/shared/url_polyfill.js +56 -0
  83. package/lib/shared/util.js +243 -710
  84. package/lib/test/unit/annotation_spec.js +870 -401
  85. package/lib/test/unit/api_spec.js +657 -345
  86. package/lib/test/unit/bidi_spec.js +7 -7
  87. package/lib/test/unit/cff_parser_spec.js +54 -11
  88. package/lib/test/unit/clitests_helper.js +10 -8
  89. package/lib/test/unit/cmap_spec.js +95 -41
  90. package/lib/test/unit/colorspace_spec.js +115 -63
  91. package/lib/test/unit/core_utils_spec.js +191 -0
  92. package/lib/test/unit/crypto_spec.js +17 -5
  93. package/lib/test/unit/custom_spec.js +43 -55
  94. package/lib/test/unit/display_svg_spec.js +34 -18
  95. package/lib/test/unit/display_utils_spec.js +273 -0
  96. package/lib/test/unit/document_spec.js +8 -13
  97. package/lib/test/unit/encodings_spec.js +25 -45
  98. package/lib/test/unit/evaluator_spec.js +38 -15
  99. package/lib/test/unit/fetch_stream_spec.js +109 -0
  100. package/lib/test/unit/function_spec.js +17 -5
  101. package/lib/test/unit/jasmine-boot.js +33 -20
  102. package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
  103. package/lib/test/unit/metadata_spec.js +71 -11
  104. package/lib/test/unit/murmurhash3_spec.js +3 -3
  105. package/lib/test/unit/network_spec.js +19 -54
  106. package/lib/test/unit/network_utils_spec.js +91 -14
  107. package/lib/test/unit/node_stream_spec.js +56 -32
  108. package/lib/test/unit/parser_spec.js +162 -71
  109. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  110. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  111. package/lib/test/unit/pdf_history_spec.js +21 -9
  112. package/lib/test/unit/primitives_spec.js +53 -20
  113. package/lib/test/unit/stream_spec.js +12 -4
  114. package/lib/test/unit/test_utils.js +273 -56
  115. package/lib/test/unit/testreporter.js +21 -3
  116. package/lib/test/unit/type1_parser_spec.js +8 -6
  117. package/lib/test/unit/ui_utils_spec.js +454 -16
  118. package/lib/test/unit/unicode_spec.js +18 -15
  119. package/lib/test/unit/util_spec.js +87 -128
  120. package/lib/web/annotation_layer_builder.js +39 -22
  121. package/lib/web/app.js +1290 -588
  122. package/lib/web/app_options.js +100 -62
  123. package/lib/web/base_viewer.js +511 -182
  124. package/lib/web/chromecom.js +261 -117
  125. package/lib/web/debugger.js +166 -22
  126. package/lib/web/download_manager.js +32 -13
  127. package/lib/web/firefox_print_service.js +20 -10
  128. package/lib/web/firefoxcom.js +315 -80
  129. package/lib/web/genericcom.js +89 -30
  130. package/lib/web/genericl10n.js +142 -30
  131. package/lib/web/grab_to_pan.js +28 -4
  132. package/lib/web/interfaces.js +170 -47
  133. package/lib/web/overlay_manager.js +235 -85
  134. package/lib/web/password_prompt.js +22 -14
  135. package/lib/web/pdf_attachment_viewer.js +38 -18
  136. package/lib/web/pdf_cursor_tools.js +39 -16
  137. package/lib/web/pdf_document_properties.js +255 -136
  138. package/lib/web/pdf_find_bar.js +84 -40
  139. package/lib/web/pdf_find_controller.js +495 -184
  140. package/lib/web/pdf_find_utils.js +111 -0
  141. package/lib/web/pdf_history.js +190 -53
  142. package/lib/web/pdf_link_service.js +138 -77
  143. package/lib/web/pdf_outline_viewer.js +122 -46
  144. package/lib/web/pdf_page_view.js +191 -67
  145. package/lib/web/pdf_presentation_mode.js +99 -34
  146. package/lib/web/pdf_print_service.js +61 -13
  147. package/lib/web/pdf_rendering_queue.js +28 -9
  148. package/lib/web/pdf_sidebar.js +141 -81
  149. package/lib/web/pdf_sidebar_resizer.js +42 -16
  150. package/lib/web/pdf_single_page_viewer.js +74 -66
  151. package/lib/web/pdf_thumbnail_view.js +104 -33
  152. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  153. package/lib/web/pdf_viewer.component.js +112 -32
  154. package/lib/web/pdf_viewer.js +91 -52
  155. package/lib/web/preferences.js +284 -89
  156. package/lib/web/secondary_toolbar.js +165 -40
  157. package/lib/web/text_layer_builder.js +134 -59
  158. package/lib/web/toolbar.js +78 -43
  159. package/lib/web/ui_utils.js +462 -136
  160. package/lib/web/view_history.js +215 -67
  161. package/lib/web/viewer_compatibility.js +4 -13
  162. package/package.json +5 -4
  163. package/web/pdf_viewer.css +79 -11
  164. package/web/pdf_viewer.js +6107 -3748
  165. package/web/pdf_viewer.js.map +1 -1
  166. package/lib/display/dom_utils.js +0 -309
  167. package/lib/test/unit/dom_utils_spec.js +0 -89
  168. package/lib/test/unit/fonts_spec.js +0 -81
  169. 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() {
@@ -911,6 +1095,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
911
1095
  var strokeColor = this.current.strokeColor;
912
1096
  ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
913
1097
  ctx.globalAlpha = this.current.strokeAlpha;
1098
+
914
1099
  if (strokeColor && strokeColor.hasOwnProperty('type') && strokeColor.type === 'Pattern') {
915
1100
  ctx.save();
916
1101
  ctx.strokeStyle = strokeColor.getPattern(ctx, this);
@@ -919,9 +1104,11 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
919
1104
  } else {
920
1105
  ctx.stroke();
921
1106
  }
1107
+
922
1108
  if (consumePath) {
923
1109
  this.consumePath();
924
1110
  }
1111
+
925
1112
  ctx.globalAlpha = this.current.fillAlpha;
926
1113
  },
927
1114
  closeStroke: function CanvasGraphics_closeStroke() {
@@ -934,23 +1121,29 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
934
1121
  var fillColor = this.current.fillColor;
935
1122
  var isPatternFill = this.current.patternFill;
936
1123
  var needRestore = false;
1124
+
937
1125
  if (isPatternFill) {
938
1126
  ctx.save();
1127
+
939
1128
  if (this.baseTransform) {
940
1129
  ctx.setTransform.apply(ctx, this.baseTransform);
941
1130
  }
1131
+
942
1132
  ctx.fillStyle = fillColor.getPattern(ctx, this);
943
1133
  needRestore = true;
944
1134
  }
1135
+
945
1136
  if (this.pendingEOFill) {
946
1137
  ctx.fill('evenodd');
947
1138
  this.pendingEOFill = false;
948
1139
  } else {
949
1140
  ctx.fill();
950
1141
  }
1142
+
951
1143
  if (needRestore) {
952
1144
  ctx.restore();
953
1145
  }
1146
+
954
1147
  if (consumePath) {
955
1148
  this.consumePath();
956
1149
  }
@@ -995,18 +1188,22 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
995
1188
  endText: function CanvasGraphics_endText() {
996
1189
  var paths = this.pendingTextPaths;
997
1190
  var ctx = this.ctx;
1191
+
998
1192
  if (paths === undefined) {
999
1193
  ctx.beginPath();
1000
1194
  return;
1001
1195
  }
1196
+
1002
1197
  ctx.save();
1003
1198
  ctx.beginPath();
1199
+
1004
1200
  for (var i = 0; i < paths.length; i++) {
1005
1201
  var path = paths[i];
1006
1202
  ctx.setTransform.apply(ctx, path.transform);
1007
1203
  ctx.translate(path.x, path.y);
1008
1204
  path.addToPath(ctx, path.fontSize);
1009
1205
  }
1206
+
1010
1207
  ctx.restore();
1011
1208
  ctx.clip();
1012
1209
  ctx.beginPath();
@@ -1027,32 +1224,38 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1027
1224
  setFont: function CanvasGraphics_setFont(fontRefName, size) {
1028
1225
  var fontObj = this.commonObjs.get(fontRefName);
1029
1226
  var current = this.current;
1227
+
1030
1228
  if (!fontObj) {
1031
- throw new Error('Can\'t find font for ' + fontRefName);
1229
+ throw new Error("Can't find font for ".concat(fontRefName));
1032
1230
  }
1231
+
1033
1232
  current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
1233
+
1034
1234
  if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
1035
1235
  (0, _util.warn)('Invalid font matrix for font ' + fontRefName);
1036
1236
  }
1237
+
1037
1238
  if (size < 0) {
1038
1239
  size = -size;
1039
1240
  current.fontDirection = -1;
1040
1241
  } else {
1041
1242
  current.fontDirection = 1;
1042
1243
  }
1244
+
1043
1245
  this.current.font = fontObj;
1044
1246
  this.current.fontSize = size;
1247
+
1045
1248
  if (fontObj.isType3Font) {
1046
1249
  return;
1047
1250
  }
1251
+
1048
1252
  var name = fontObj.loadedName || 'sans-serif';
1049
1253
  var bold = fontObj.black ? '900' : fontObj.bold ? 'bold' : 'normal';
1050
1254
  var italic = fontObj.italic ? 'italic' : 'normal';
1051
- var typeface = '"' + name + '", ' + fontObj.fallbackName;
1255
+ var typeface = "\"".concat(name, "\", ").concat(fontObj.fallbackName);
1052
1256
  var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
1053
1257
  this.current.fontSizeScale = size / browserFontSize;
1054
- var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
1055
- this.ctx.font = rule;
1258
+ this.ctx.font = "".concat(italic, " ").concat(bold, " ").concat(browserFontSize, "px ").concat(typeface);
1056
1259
  },
1057
1260
  setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
1058
1261
  this.current.textRenderingMode = mode;
@@ -1087,32 +1290,40 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1087
1290
  var isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
1088
1291
  var patternFill = current.patternFill && font.data;
1089
1292
  var addToPath;
1293
+
1090
1294
  if (font.disableFontFace || isAddToPathSet || patternFill) {
1091
1295
  addToPath = font.getPathGenerator(this.commonObjs, character);
1092
1296
  }
1297
+
1093
1298
  if (font.disableFontFace || patternFill) {
1094
1299
  ctx.save();
1095
1300
  ctx.translate(x, y);
1096
1301
  ctx.beginPath();
1097
1302
  addToPath(ctx, fontSize);
1303
+
1098
1304
  if (patternTransform) {
1099
1305
  ctx.setTransform.apply(ctx, patternTransform);
1100
1306
  }
1307
+
1101
1308
  if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1102
1309
  ctx.fill();
1103
1310
  }
1311
+
1104
1312
  if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1105
1313
  ctx.stroke();
1106
1314
  }
1315
+
1107
1316
  ctx.restore();
1108
1317
  } else {
1109
1318
  if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1110
1319
  ctx.fillText(character, x, y);
1111
1320
  }
1321
+
1112
1322
  if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1113
1323
  ctx.strokeText(character, x, y);
1114
1324
  }
1115
1325
  }
1326
+
1116
1327
  if (isAddToPathSet) {
1117
1328
  var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
1118
1329
  paths.push({
@@ -1126,29 +1337,38 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1126
1337
  },
1127
1338
 
1128
1339
  get isFontSubpixelAAEnabled() {
1129
- var ctx = this.canvasFactory.create(10, 10).context;
1340
+ var _this$cachedCanvases$ = this.cachedCanvases.getCanvas('isFontSubpixelAAEnabled', 10, 10),
1341
+ ctx = _this$cachedCanvases$.context;
1342
+
1130
1343
  ctx.scale(1.5, 1);
1131
1344
  ctx.fillText('I', 0, 10);
1132
1345
  var data = ctx.getImageData(0, 0, 10, 10).data;
1133
1346
  var enabled = false;
1347
+
1134
1348
  for (var i = 3; i < data.length; i += 4) {
1135
1349
  if (data[i] > 0 && data[i] < 255) {
1136
1350
  enabled = true;
1137
1351
  break;
1138
1352
  }
1139
1353
  }
1354
+
1140
1355
  return (0, _util.shadow)(this, 'isFontSubpixelAAEnabled', enabled);
1141
1356
  },
1357
+
1142
1358
  showText: function CanvasGraphics_showText(glyphs) {
1143
1359
  var current = this.current;
1144
1360
  var font = current.font;
1361
+
1145
1362
  if (font.isType3Font) {
1146
1363
  return this.showType3Text(glyphs);
1147
1364
  }
1365
+
1148
1366
  var fontSize = current.fontSize;
1367
+
1149
1368
  if (fontSize === 0) {
1150
- return;
1369
+ return undefined;
1151
1370
  }
1371
+
1152
1372
  var ctx = this.ctx;
1153
1373
  var fontSizeScale = current.fontSizeScale;
1154
1374
  var charSpacing = current.charSpacing;
@@ -1162,7 +1382,8 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1162
1382
  var widthAdvanceScale = fontSize * current.fontMatrix[0];
1163
1383
  var simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
1164
1384
  ctx.save();
1165
- var patternTransform = void 0;
1385
+ var patternTransform;
1386
+
1166
1387
  if (current.patternFill) {
1167
1388
  ctx.save();
1168
1389
  var pattern = current.fillColor.getPattern(ctx, this);
@@ -1170,43 +1391,54 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1170
1391
  ctx.restore();
1171
1392
  ctx.fillStyle = pattern;
1172
1393
  }
1394
+
1173
1395
  ctx.transform.apply(ctx, current.textMatrix);
1174
1396
  ctx.translate(current.x, current.y + current.textRise);
1397
+
1175
1398
  if (fontDirection > 0) {
1176
1399
  ctx.scale(textHScale, -1);
1177
1400
  } else {
1178
1401
  ctx.scale(textHScale, 1);
1179
1402
  }
1403
+
1180
1404
  var lineWidth = current.lineWidth;
1181
1405
  var scale = current.textMatrixScale;
1406
+
1182
1407
  if (scale === 0 || lineWidth === 0) {
1183
1408
  var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
1409
+
1184
1410
  if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1185
- this.cachedGetSinglePixelWidth = null;
1411
+ this._cachedGetSinglePixelWidth = null;
1186
1412
  lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
1187
1413
  }
1188
1414
  } else {
1189
1415
  lineWidth /= scale;
1190
1416
  }
1417
+
1191
1418
  if (fontSizeScale !== 1.0) {
1192
1419
  ctx.scale(fontSizeScale, fontSizeScale);
1193
1420
  lineWidth /= fontSizeScale;
1194
1421
  }
1422
+
1195
1423
  ctx.lineWidth = lineWidth;
1196
1424
  var x = 0,
1197
1425
  i;
1426
+
1198
1427
  for (i = 0; i < glyphsLength; ++i) {
1199
1428
  var glyph = glyphs[i];
1429
+
1200
1430
  if ((0, _util.isNum)(glyph)) {
1201
1431
  x += spacingDir * glyph * fontSize / 1000;
1202
1432
  continue;
1203
1433
  }
1434
+
1204
1435
  var restoreNeeded = false;
1205
1436
  var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
1206
1437
  var character = glyph.fontChar;
1207
1438
  var accent = glyph.accent;
1208
1439
  var scaledX, scaledY, scaledAccentX, scaledAccentY;
1209
1440
  var width = glyph.width;
1441
+
1210
1442
  if (vertical) {
1211
1443
  var vmetric, vx, vy;
1212
1444
  vmetric = glyph.vmetric || defaultVMetrics;
@@ -1220,8 +1452,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1220
1452
  scaledX = x / fontSizeScale;
1221
1453
  scaledY = 0;
1222
1454
  }
1455
+
1223
1456
  if (font.remeasure && width > 0) {
1224
1457
  var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
1458
+
1225
1459
  if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
1226
1460
  var characterScaleX = width / measuredWidth;
1227
1461
  restoreNeeded = true;
@@ -1232,11 +1466,13 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1232
1466
  scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
1233
1467
  }
1234
1468
  }
1469
+
1235
1470
  if (glyph.isInFont || font.missingFile) {
1236
1471
  if (simpleFillText && !accent) {
1237
1472
  ctx.fillText(character, scaledX, scaledY);
1238
1473
  } else {
1239
1474
  this.paintChar(character, scaledX, scaledY, patternTransform);
1475
+
1240
1476
  if (accent) {
1241
1477
  scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
1242
1478
  scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
@@ -1244,17 +1480,21 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1244
1480
  }
1245
1481
  }
1246
1482
  }
1483
+
1247
1484
  var charWidth = width * widthAdvanceScale + spacing * fontDirection;
1248
1485
  x += charWidth;
1486
+
1249
1487
  if (restoreNeeded) {
1250
1488
  ctx.restore();
1251
1489
  }
1252
1490
  }
1491
+
1253
1492
  if (vertical) {
1254
1493
  current.y -= x * textHScale;
1255
1494
  } else {
1256
1495
  current.x += x * textHScale;
1257
1496
  }
1497
+
1258
1498
  ctx.restore();
1259
1499
  },
1260
1500
  showType3Text: function CanvasGraphics_showType3Text(glyphs) {
@@ -1271,39 +1511,49 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1271
1511
  var glyphsLength = glyphs.length;
1272
1512
  var isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
1273
1513
  var i, glyph, width, spacingLength;
1514
+
1274
1515
  if (isTextInvisible || fontSize === 0) {
1275
1516
  return;
1276
1517
  }
1277
- this.cachedGetSinglePixelWidth = null;
1518
+
1519
+ this._cachedGetSinglePixelWidth = null;
1278
1520
  ctx.save();
1279
1521
  ctx.transform.apply(ctx, current.textMatrix);
1280
1522
  ctx.translate(current.x, current.y);
1281
1523
  ctx.scale(textHScale, fontDirection);
1524
+
1282
1525
  for (i = 0; i < glyphsLength; ++i) {
1283
1526
  glyph = glyphs[i];
1527
+
1284
1528
  if ((0, _util.isNum)(glyph)) {
1285
1529
  spacingLength = spacingDir * glyph * fontSize / 1000;
1286
1530
  this.ctx.translate(spacingLength, 0);
1287
1531
  current.x += spacingLength * textHScale;
1288
1532
  continue;
1289
1533
  }
1534
+
1290
1535
  var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
1291
1536
  var operatorList = font.charProcOperatorList[glyph.operatorListId];
1537
+
1292
1538
  if (!operatorList) {
1293
- (0, _util.warn)('Type3 character "' + glyph.operatorListId + '" is not available.');
1539
+ (0, _util.warn)("Type3 character \"".concat(glyph.operatorListId, "\" is not available."));
1294
1540
  continue;
1295
1541
  }
1542
+
1296
1543
  this.processingType3 = glyph;
1297
1544
  this.save();
1298
1545
  ctx.scale(fontSize, fontSize);
1299
1546
  ctx.transform.apply(ctx, fontMatrix);
1300
1547
  this.executeOperatorList(operatorList);
1301
1548
  this.restore();
1549
+
1302
1550
  var transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
1551
+
1303
1552
  width = transformed[0] * fontSize + spacing;
1304
1553
  ctx.translate(width, 0);
1305
1554
  current.x += width * textHScale;
1306
1555
  }
1556
+
1307
1557
  ctx.restore();
1308
1558
  this.processingType3 = null;
1309
1559
  },
@@ -1317,6 +1567,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1317
1567
  var _this = this;
1318
1568
 
1319
1569
  var pattern;
1570
+
1320
1571
  if (IR[0] === 'TilingPattern') {
1321
1572
  var color = IR[1];
1322
1573
  var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
@@ -1329,6 +1580,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1329
1580
  } else {
1330
1581
  pattern = (0, _pattern_helper.getShadingPatternFromIR)(IR);
1331
1582
  }
1583
+
1332
1584
  return pattern;
1333
1585
  },
1334
1586
  setStrokeColorN: function CanvasGraphics_setStrokeColorN() {
@@ -1340,11 +1592,13 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1340
1592
  },
1341
1593
  setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
1342
1594
  var color = _util.Util.makeCssRgb(r, g, b);
1595
+
1343
1596
  this.ctx.strokeStyle = color;
1344
1597
  this.current.strokeColor = color;
1345
1598
  },
1346
1599
  setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
1347
1600
  var color = _util.Util.makeCssRgb(r, g, b);
1601
+
1348
1602
  this.ctx.fillStyle = color;
1349
1603
  this.current.fillColor = color;
1350
1604
  this.current.patternFill = false;
@@ -1355,14 +1609,20 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1355
1609
  var pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
1356
1610
  ctx.fillStyle = pattern.getPattern(ctx, this, true);
1357
1611
  var inv = ctx.mozCurrentTransformInverse;
1612
+
1358
1613
  if (inv) {
1359
1614
  var canvas = ctx.canvas;
1360
1615
  var width = canvas.width;
1361
1616
  var height = canvas.height;
1617
+
1362
1618
  var bl = _util.Util.applyTransform([0, 0], inv);
1619
+
1363
1620
  var br = _util.Util.applyTransform([0, height], inv);
1621
+
1364
1622
  var ul = _util.Util.applyTransform([width, 0], inv);
1623
+
1365
1624
  var ur = _util.Util.applyTransform([width, height], inv);
1625
+
1366
1626
  var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
1367
1627
  var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
1368
1628
  var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
@@ -1371,6 +1631,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1371
1631
  } else {
1372
1632
  this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
1373
1633
  }
1634
+
1374
1635
  this.restore();
1375
1636
  },
1376
1637
  beginInlineImage: function CanvasGraphics_beginInlineImage() {
@@ -1382,11 +1643,14 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1382
1643
  paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
1383
1644
  this.save();
1384
1645
  this.baseTransformStack.push(this.baseTransform);
1646
+
1385
1647
  if (Array.isArray(matrix) && matrix.length === 6) {
1386
1648
  this.transform.apply(this, matrix);
1387
1649
  }
1650
+
1388
1651
  this.baseTransform = this.ctx.mozCurrentTransform;
1389
- if (Array.isArray(bbox) && bbox.length === 4) {
1652
+
1653
+ if (bbox) {
1390
1654
  var width = bbox[2] - bbox[0];
1391
1655
  var height = bbox[3] - bbox[1];
1392
1656
  this.ctx.rect(bbox[0], bbox[1], width, height);
@@ -1401,20 +1665,27 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1401
1665
  beginGroup: function CanvasGraphics_beginGroup(group) {
1402
1666
  this.save();
1403
1667
  var currentCtx = this.ctx;
1668
+
1404
1669
  if (!group.isolated) {
1405
1670
  (0, _util.info)('TODO: Support non-isolated groups.');
1406
1671
  }
1672
+
1407
1673
  if (group.knockout) {
1408
1674
  (0, _util.warn)('Knockout groups not supported.');
1409
1675
  }
1676
+
1410
1677
  var currentTransform = currentCtx.mozCurrentTransform;
1678
+
1411
1679
  if (group.matrix) {
1412
1680
  currentCtx.transform.apply(currentCtx, group.matrix);
1413
1681
  }
1682
+
1414
1683
  if (!group.bbox) {
1415
1684
  throw new Error('Bounding box is required.');
1416
1685
  }
1686
+
1417
1687
  var bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
1688
+
1418
1689
  var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
1419
1690
  bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
1420
1691
  var offsetX = Math.floor(bounds[0]);
@@ -1423,23 +1694,29 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1423
1694
  var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
1424
1695
  var scaleX = 1,
1425
1696
  scaleY = 1;
1697
+
1426
1698
  if (drawnWidth > MAX_GROUP_SIZE) {
1427
1699
  scaleX = drawnWidth / MAX_GROUP_SIZE;
1428
1700
  drawnWidth = MAX_GROUP_SIZE;
1429
1701
  }
1702
+
1430
1703
  if (drawnHeight > MAX_GROUP_SIZE) {
1431
1704
  scaleY = drawnHeight / MAX_GROUP_SIZE;
1432
1705
  drawnHeight = MAX_GROUP_SIZE;
1433
1706
  }
1707
+
1434
1708
  var cacheId = 'groupAt' + this.groupLevel;
1709
+
1435
1710
  if (group.smask) {
1436
1711
  cacheId += '_smask_' + this.smaskCounter++ % 2;
1437
1712
  }
1713
+
1438
1714
  var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
1439
1715
  var groupCtx = scratchCanvas.context;
1440
1716
  groupCtx.scale(1 / scaleX, 1 / scaleY);
1441
1717
  groupCtx.translate(-offsetX, -offsetY);
1442
1718
  groupCtx.transform.apply(groupCtx, currentTransform);
1719
+
1443
1720
  if (group.smask) {
1444
1721
  this.smaskStack.push({
1445
1722
  canvas: scratchCanvas.canvas,
@@ -1458,6 +1735,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1458
1735
  currentCtx.translate(offsetX, offsetY);
1459
1736
  currentCtx.scale(scaleX, scaleY);
1460
1737
  }
1738
+
1461
1739
  copyCtxState(currentCtx, groupCtx);
1462
1740
  this.ctx = groupCtx;
1463
1741
  this.setGState([['BM', 'source-over'], ['ca', 1], ['CA', 1]]);
@@ -1469,20 +1747,24 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1469
1747
  this.groupLevel--;
1470
1748
  var groupCtx = this.ctx;
1471
1749
  this.ctx = this.groupStack.pop();
1750
+
1472
1751
  if (this.ctx.imageSmoothingEnabled !== undefined) {
1473
1752
  this.ctx.imageSmoothingEnabled = false;
1474
1753
  } else {
1475
1754
  this.ctx.mozImageSmoothingEnabled = false;
1476
1755
  }
1756
+
1477
1757
  if (group.smask) {
1478
1758
  this.tempSMask = this.smaskStack.pop();
1479
1759
  } else {
1480
1760
  this.ctx.drawImage(groupCtx.canvas, 0, 0);
1481
1761
  }
1762
+
1482
1763
  this.restore();
1483
1764
  },
1484
1765
  beginAnnotations: function CanvasGraphics_beginAnnotations() {
1485
1766
  this.save();
1767
+
1486
1768
  if (this.baseTransform) {
1487
1769
  this.ctx.setTransform.apply(this.ctx, this.baseTransform);
1488
1770
  }
@@ -1494,6 +1776,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1494
1776
  this.save();
1495
1777
  resetCtxToDefault(this.ctx);
1496
1778
  this.current = new CanvasExtraState();
1779
+
1497
1780
  if (Array.isArray(rect) && rect.length === 4) {
1498
1781
  var width = rect[2] - rect[0];
1499
1782
  var height = rect[3] - rect[1];
@@ -1501,6 +1784,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1501
1784
  this.clip();
1502
1785
  this.endPath();
1503
1786
  }
1787
+
1504
1788
  this.transform.apply(this, transform);
1505
1789
  this.transform.apply(this, matrix);
1506
1790
  },
@@ -1508,15 +1792,18 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1508
1792
  this.restore();
1509
1793
  },
1510
1794
  paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
1511
- var domImage = this.objs.get(objId);
1795
+ var domImage = this.processingType3 ? this.commonObjs.get(objId) : this.objs.get(objId);
1796
+
1512
1797
  if (!domImage) {
1513
1798
  (0, _util.warn)('Dependent image isn\'t ready yet');
1514
1799
  return;
1515
1800
  }
1801
+
1516
1802
  this.save();
1517
1803
  var ctx = this.ctx;
1518
1804
  ctx.scale(1 / w, -1 / h);
1519
1805
  ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height, 0, -h, w, h);
1806
+
1520
1807
  if (this.imageLayer) {
1521
1808
  var currentTransform = ctx.mozCurrentTransformInverse;
1522
1809
  var position = this.getCanvasPosition(0, 0);
@@ -1528,6 +1815,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1528
1815
  height: h / currentTransform[3]
1529
1816
  });
1530
1817
  }
1818
+
1531
1819
  this.restore();
1532
1820
  },
1533
1821
  paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
@@ -1537,6 +1825,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1537
1825
  var fillColor = this.current.fillColor;
1538
1826
  var isPatternFill = this.current.patternFill;
1539
1827
  var glyph = this.processingType3;
1828
+
1540
1829
  if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
1541
1830
  if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
1542
1831
  glyph.compiled = compileType3Glyph({
@@ -1548,10 +1837,12 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1548
1837
  glyph.compiled = null;
1549
1838
  }
1550
1839
  }
1840
+
1551
1841
  if (glyph && glyph.compiled) {
1552
1842
  glyph.compiled(ctx);
1553
1843
  return;
1554
1844
  }
1845
+
1555
1846
  var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
1556
1847
  var maskCtx = maskCanvas.context;
1557
1848
  maskCtx.save();
@@ -1576,6 +1867,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1576
1867
  maskCtx.fillRect(0, 0, width, height);
1577
1868
  maskCtx.restore();
1578
1869
  var ctx = this.ctx;
1870
+
1579
1871
  for (var i = 0, ii = positions.length; i < ii; i += 2) {
1580
1872
  ctx.save();
1581
1873
  ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
@@ -1588,6 +1880,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1588
1880
  var ctx = this.ctx;
1589
1881
  var fillColor = this.current.fillColor;
1590
1882
  var isPatternFill = this.current.patternFill;
1883
+
1591
1884
  for (var i = 0, ii = images.length; i < ii; i++) {
1592
1885
  var image = images[i];
1593
1886
  var width = image.width,
@@ -1608,22 +1901,27 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1608
1901
  }
1609
1902
  },
1610
1903
  paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
1611
- var imgData = this.objs.get(objId);
1904
+ var imgData = this.processingType3 ? this.commonObjs.get(objId) : this.objs.get(objId);
1905
+
1612
1906
  if (!imgData) {
1613
1907
  (0, _util.warn)('Dependent image isn\'t ready yet');
1614
1908
  return;
1615
1909
  }
1910
+
1616
1911
  this.paintInlineImageXObject(imgData);
1617
1912
  },
1618
1913
  paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
1619
- var imgData = this.objs.get(objId);
1914
+ var imgData = this.processingType3 ? this.commonObjs.get(objId) : this.objs.get(objId);
1915
+
1620
1916
  if (!imgData) {
1621
1917
  (0, _util.warn)('Dependent image isn\'t ready yet');
1622
1918
  return;
1623
1919
  }
1920
+
1624
1921
  var width = imgData.width;
1625
1922
  var height = imgData.height;
1626
1923
  var map = [];
1924
+
1627
1925
  for (var i = 0, ii = positions.length; i < ii; i += 2) {
1628
1926
  map.push({
1629
1927
  transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
@@ -1633,6 +1931,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1633
1931
  h: height
1634
1932
  });
1635
1933
  }
1934
+
1636
1935
  this.paintInlineImageXObjectGroup(imgData, map);
1637
1936
  },
1638
1937
  paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
@@ -1649,6 +1948,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1649
1948
  d = currentTransform[3];
1650
1949
  var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
1651
1950
  var imgToPaint, tmpCanvas;
1951
+
1652
1952
  if (typeof HTMLElement === 'function' && imgData instanceof HTMLElement || !imgData.data) {
1653
1953
  imgToPaint = imgData;
1654
1954
  } else {
@@ -1657,20 +1957,25 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1657
1957
  putBinaryImageData(tmpCtx, imgData);
1658
1958
  imgToPaint = tmpCanvas.canvas;
1659
1959
  }
1960
+
1660
1961
  var paintWidth = width,
1661
1962
  paintHeight = height;
1662
1963
  var tmpCanvasId = 'prescale1';
1964
+
1663
1965
  while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
1664
1966
  var newWidth = paintWidth,
1665
1967
  newHeight = paintHeight;
1968
+
1666
1969
  if (widthScale > 2 && paintWidth > 1) {
1667
1970
  newWidth = Math.ceil(paintWidth / 2);
1668
1971
  widthScale /= paintWidth / newWidth;
1669
1972
  }
1973
+
1670
1974
  if (heightScale > 2 && paintHeight > 1) {
1671
1975
  newHeight = Math.ceil(paintHeight / 2);
1672
1976
  heightScale /= paintHeight / newHeight;
1673
1977
  }
1978
+
1674
1979
  tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
1675
1980
  tmpCtx = tmpCanvas.context;
1676
1981
  tmpCtx.clearRect(0, 0, newWidth, newHeight);
@@ -1680,7 +1985,9 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1680
1985
  paintHeight = newHeight;
1681
1986
  tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
1682
1987
  }
1988
+
1683
1989
  ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
1990
+
1684
1991
  if (this.imageLayer) {
1685
1992
  var position = this.getCanvasPosition(0, -height);
1686
1993
  this.imageLayer.appendImage({
@@ -1691,6 +1998,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1691
1998
  height: height / currentTransform[3]
1692
1999
  });
1693
2000
  }
2001
+
1694
2002
  this.restore();
1695
2003
  },
1696
2004
  paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
@@ -1700,12 +2008,14 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1700
2008
  var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
1701
2009
  var tmpCtx = tmpCanvas.context;
1702
2010
  putBinaryImageData(tmpCtx, imgData);
2011
+
1703
2012
  for (var i = 0, ii = map.length; i < ii; i++) {
1704
2013
  var entry = map[i];
1705
2014
  ctx.save();
1706
2015
  ctx.transform.apply(ctx, entry.transform);
1707
2016
  ctx.scale(1, -1);
1708
2017
  ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
2018
+
1709
2019
  if (this.imageLayer) {
1710
2020
  var position = this.getCanvasPosition(entry.x, entry.y);
1711
2021
  this.imageLayer.appendImage({
@@ -1716,6 +2026,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1716
2026
  height: h
1717
2027
  });
1718
2028
  }
2029
+
1719
2030
  ctx.restore();
1720
2031
  }
1721
2032
  },
@@ -1734,33 +2045,38 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1734
2045
  endCompat: function CanvasGraphics_endCompat() {},
1735
2046
  consumePath: function CanvasGraphics_consumePath() {
1736
2047
  var ctx = this.ctx;
2048
+
1737
2049
  if (this.pendingClip) {
1738
2050
  if (this.pendingClip === EO_CLIP) {
1739
2051
  ctx.clip('evenodd');
1740
2052
  } else {
1741
2053
  ctx.clip();
1742
2054
  }
2055
+
1743
2056
  this.pendingClip = null;
1744
2057
  }
2058
+
1745
2059
  ctx.beginPath();
1746
2060
  },
1747
- getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
1748
- if (this.cachedGetSinglePixelWidth === null) {
1749
- this.ctx.save();
2061
+ getSinglePixelWidth: function getSinglePixelWidth(scale) {
2062
+ if (this._cachedGetSinglePixelWidth === null) {
1750
2063
  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]));
2064
+ this._cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
1753
2065
  }
1754
- return this.cachedGetSinglePixelWidth;
2066
+
2067
+ return this._cachedGetSinglePixelWidth;
1755
2068
  },
1756
2069
  getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
1757
2070
  var transform = this.ctx.mozCurrentTransform;
1758
2071
  return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
1759
2072
  }
1760
2073
  };
2074
+
1761
2075
  for (var op in _util.OPS) {
1762
2076
  CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
1763
2077
  }
2078
+
1764
2079
  return CanvasGraphics;
1765
2080
  }();
2081
+
1766
2082
  exports.CanvasGraphics = CanvasGraphics;