pdfjs-dist 2.0.943 → 2.1.266

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