pdfjs-dist 2.6.347 → 2.7.570

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 (158) hide show
  1. package/README.md +3 -3
  2. package/bower.json +1 -1
  3. package/build/pdf.js +2050 -1087
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +18219 -10436
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/es5/build/pdf.d.ts +1 -0
  10. package/es5/build/pdf.js +6623 -6654
  11. package/es5/build/pdf.js.map +1 -1
  12. package/es5/build/pdf.min.js +1 -1
  13. package/es5/build/pdf.worker.js +20815 -13888
  14. package/es5/build/pdf.worker.js.map +1 -1
  15. package/es5/build/pdf.worker.min.js +1 -1
  16. package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
  17. package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
  18. package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
  19. package/es5/web/pdf_viewer.css +18 -15
  20. package/es5/web/pdf_viewer.js +1094 -514
  21. package/es5/web/pdf_viewer.js.map +1 -1
  22. package/image_decoders/pdf.image_decoders.js +774 -168
  23. package/image_decoders/pdf.image_decoders.js.map +1 -1
  24. package/image_decoders/pdf.image_decoders.min.js +1 -1
  25. package/lib/core/annotation.js +556 -108
  26. package/lib/core/cff_parser.js +7 -1
  27. package/lib/core/charsets.js +1 -1
  28. package/lib/core/cmap.js +20 -1
  29. package/lib/core/core_utils.js +162 -3
  30. package/lib/core/crypto.js +1 -1
  31. package/lib/core/default_appearance.js +132 -0
  32. package/lib/core/document.js +115 -9
  33. package/lib/core/encodings.js +1 -1
  34. package/lib/core/evaluator.js +168 -74
  35. package/lib/core/fonts.js +97 -11
  36. package/lib/core/function.js +5 -10
  37. package/lib/core/glyphlist.js +11 -4529
  38. package/lib/core/image_utils.js +30 -1
  39. package/lib/core/jpg.js +1 -1
  40. package/lib/core/jpx.js +5 -5
  41. package/lib/core/murmurhash3.js +1 -1
  42. package/lib/core/obj.js +123 -39
  43. package/lib/core/pattern.js +4 -4
  44. package/lib/core/primitives.js +24 -5
  45. package/lib/core/standard_fonts.js +1 -1
  46. package/lib/core/stream.js +5 -1
  47. package/lib/core/unicode.js +15 -1387
  48. package/lib/core/worker.js +58 -17
  49. package/lib/core/writer.js +68 -4
  50. package/lib/display/annotation_layer.js +712 -119
  51. package/lib/display/annotation_storage.js +21 -4
  52. package/lib/display/api.js +88 -18
  53. package/lib/display/canvas.js +414 -375
  54. package/lib/display/display_utils.js +11 -4
  55. package/lib/display/fetch_stream.js +3 -3
  56. package/lib/display/font_loader.js +2 -3
  57. package/lib/display/metadata.js +54 -20
  58. package/lib/display/node_stream.js +1 -1
  59. package/lib/display/optional_content_config.js +1 -1
  60. package/lib/display/pattern_helper.js +109 -113
  61. package/lib/display/svg.js +5 -5
  62. package/lib/display/text_layer.js +54 -54
  63. package/lib/display/transport_stream.js +4 -4
  64. package/lib/display/webgl.js +65 -68
  65. package/lib/examples/node/domstubs.js +9 -4
  66. package/lib/pdf.js +2 -2
  67. package/lib/pdf.sandbox.js +311 -0
  68. package/lib/pdf.worker.js +2 -2
  69. package/lib/shared/scripting_utils.js +84 -0
  70. package/lib/shared/util.js +129 -14
  71. package/lib/{display → shared}/xml_parser.js +112 -4
  72. package/lib/test/unit/annotation_spec.js +831 -109
  73. package/lib/test/unit/annotation_storage_spec.js +28 -10
  74. package/lib/test/unit/api_spec.js +190 -160
  75. package/lib/test/unit/bidi_spec.js +6 -6
  76. package/lib/test/unit/cff_parser_spec.js +73 -73
  77. package/lib/test/unit/clitests_helper.js +2 -0
  78. package/lib/test/unit/cmap_spec.js +48 -74
  79. package/lib/test/unit/core_utils_spec.js +34 -0
  80. package/lib/test/unit/crypto_spec.js +162 -199
  81. package/lib/test/unit/custom_spec.js +7 -18
  82. package/lib/test/unit/default_appearance_spec.js +54 -0
  83. package/lib/test/unit/display_svg_spec.js +24 -19
  84. package/lib/test/unit/display_utils_spec.js +1 -1
  85. package/lib/test/unit/document_spec.js +187 -20
  86. package/lib/test/unit/evaluator_spec.js +30 -30
  87. package/lib/test/unit/function_spec.js +165 -165
  88. package/lib/test/unit/jasmine-boot.js +52 -53
  89. package/lib/test/unit/metadata_spec.js +2 -2
  90. package/lib/test/unit/murmurhash3_spec.js +29 -16
  91. package/lib/test/unit/network_spec.js +21 -21
  92. package/lib/test/unit/pdf_find_controller_spec.js +131 -69
  93. package/lib/test/unit/pdf_find_utils_spec.js +10 -10
  94. package/lib/test/unit/scripting_spec.js +1104 -0
  95. package/lib/test/unit/stream_spec.js +8 -8
  96. package/lib/test/unit/test_utils.js +16 -19
  97. package/lib/test/unit/testreporter.js +11 -4
  98. package/lib/test/unit/type1_parser_spec.js +23 -23
  99. package/lib/test/unit/ui_utils_spec.js +78 -35
  100. package/lib/test/unit/unicode_spec.js +7 -7
  101. package/lib/test/unit/util_spec.js +26 -3
  102. package/lib/test/unit/writer_spec.js +16 -1
  103. package/lib/test/unit/xml_spec.js +117 -0
  104. package/lib/web/annotation_layer_builder.js +18 -6
  105. package/lib/web/app.js +579 -161
  106. package/lib/web/app_options.js +14 -0
  107. package/lib/web/base_tree_viewer.js +50 -0
  108. package/lib/web/base_viewer.js +350 -14
  109. package/lib/web/chromecom.js +9 -1
  110. package/lib/web/debugger.js +1 -2
  111. package/lib/web/download_manager.js +0 -15
  112. package/lib/web/firefox_print_service.js +6 -4
  113. package/lib/web/firefoxcom.js +84 -69
  114. package/lib/web/generic_scripting.js +55 -0
  115. package/lib/web/genericcom.js +9 -1
  116. package/lib/web/grab_to_pan.js +1 -1
  117. package/lib/web/interfaces.js +9 -3
  118. package/lib/web/pdf_attachment_viewer.js +1 -3
  119. package/lib/web/pdf_cursor_tools.js +20 -13
  120. package/lib/web/pdf_document_properties.js +48 -61
  121. package/lib/web/pdf_find_bar.js +1 -3
  122. package/lib/web/pdf_find_controller.js +58 -12
  123. package/lib/web/pdf_history.js +43 -21
  124. package/lib/web/pdf_layer_viewer.js +1 -9
  125. package/lib/web/pdf_link_service.js +108 -78
  126. package/lib/web/pdf_outline_viewer.js +166 -10
  127. package/lib/web/pdf_page_view.js +14 -14
  128. package/lib/web/pdf_presentation_mode.js +21 -31
  129. package/lib/web/pdf_rendering_queue.js +8 -1
  130. package/lib/web/pdf_sidebar.js +62 -107
  131. package/lib/web/pdf_sidebar_resizer.js +11 -21
  132. package/lib/web/pdf_single_page_viewer.js +8 -0
  133. package/lib/web/pdf_thumbnail_view.js +26 -26
  134. package/lib/web/pdf_thumbnail_viewer.js +13 -2
  135. package/lib/web/pdf_viewer.component.js +2 -2
  136. package/lib/web/pdf_viewer.js +3 -1
  137. package/lib/web/preferences.js +33 -44
  138. package/lib/web/text_layer_builder.js +2 -9
  139. package/lib/web/ui_utils.js +78 -46
  140. package/lib/web/viewer_compatibility.js +1 -2
  141. package/package.json +4 -1
  142. package/types/display/annotation_layer.d.ts +18 -3
  143. package/types/display/api.d.ts +110 -54
  144. package/types/display/canvas.d.ts +1 -1
  145. package/types/display/display_utils.d.ts +96 -95
  146. package/types/display/fetch_stream.d.ts +2 -2
  147. package/types/display/metadata.d.ts +4 -0
  148. package/types/display/pattern_helper.d.ts +1 -1
  149. package/types/display/text_layer.d.ts +7 -7
  150. package/types/display/transport_stream.d.ts +1 -1
  151. package/types/shared/scripting_utils.d.ts +12 -0
  152. package/types/shared/util.d.ts +281 -250
  153. package/types/shared/xml_parser.d.ts +64 -0
  154. package/web/pdf_viewer.css +18 -15
  155. package/web/pdf_viewer.js +809 -408
  156. package/web/pdf_viewer.js.map +1 -1
  157. package/webpack.js +1 -1
  158. package/types/display/xml_parser.d.ts +0 -35
@@ -30,13 +30,12 @@ var _util = require("../shared/util.js");
30
30
 
31
31
  var _pattern_helper = require("./pattern_helper.js");
32
32
 
33
- var MIN_FONT_SIZE = 16;
34
- var MAX_FONT_SIZE = 100;
35
- var MAX_GROUP_SIZE = 4096;
36
- var MIN_WIDTH_FACTOR = 0.65;
37
- var COMPILE_TYPE3_GLYPHS = true;
38
- var MAX_SIZE_TO_COMPILE = 1000;
39
- var FULL_CHUNK_HEIGHT = 16;
33
+ const MIN_FONT_SIZE = 16;
34
+ const MAX_FONT_SIZE = 100;
35
+ const MAX_GROUP_SIZE = 4096;
36
+ const COMPILE_TYPE3_GLYPHS = true;
37
+ const MAX_SIZE_TO_COMPILE = 1000;
38
+ const FULL_CHUNK_HEIGHT = 16;
40
39
 
41
40
  function addContextCurrentTransform(ctx) {
42
41
  if (!ctx.mozCurrentTransform) {
@@ -56,21 +55,21 @@ function addContextCurrentTransform(ctx) {
56
55
  });
57
56
  Object.defineProperty(ctx, "mozCurrentTransformInverse", {
58
57
  get: function getCurrentTransformInverse() {
59
- var m = this._transformMatrix;
60
- var a = m[0],
61
- b = m[1],
62
- c = m[2],
63
- d = m[3],
64
- e = m[4],
65
- f = m[5];
66
- var ad_bc = a * d - b * c;
67
- var bc_ad = b * c - a * d;
58
+ const m = this._transformMatrix;
59
+ const a = m[0],
60
+ b = m[1],
61
+ c = m[2],
62
+ d = m[3],
63
+ e = m[4],
64
+ f = m[5];
65
+ const ad_bc = a * d - b * c;
66
+ const bc_ad = b * c - a * d;
68
67
  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];
69
68
  }
70
69
  });
71
70
 
72
71
  ctx.save = function ctxSave() {
73
- var old = this._transformMatrix;
72
+ const old = this._transformMatrix;
74
73
 
75
74
  this._transformStack.push(old);
76
75
 
@@ -80,7 +79,7 @@ function addContextCurrentTransform(ctx) {
80
79
  };
81
80
 
82
81
  ctx.restore = function ctxRestore() {
83
- var prev = this._transformStack.pop();
82
+ const prev = this._transformStack.pop();
84
83
 
85
84
  if (prev) {
86
85
  this._transformMatrix = prev;
@@ -90,7 +89,7 @@ function addContextCurrentTransform(ctx) {
90
89
  };
91
90
 
92
91
  ctx.translate = function ctxTranslate(x, y) {
93
- var m = this._transformMatrix;
92
+ const m = this._transformMatrix;
94
93
  m[4] = m[0] * x + m[2] * y + m[4];
95
94
  m[5] = m[1] * x + m[3] * y + m[5];
96
95
 
@@ -98,7 +97,7 @@ function addContextCurrentTransform(ctx) {
98
97
  };
99
98
 
100
99
  ctx.scale = function ctxScale(x, y) {
101
- var m = this._transformMatrix;
100
+ const m = this._transformMatrix;
102
101
  m[0] = m[0] * x;
103
102
  m[1] = m[1] * x;
104
103
  m[2] = m[2] * y;
@@ -108,7 +107,7 @@ function addContextCurrentTransform(ctx) {
108
107
  };
109
108
 
110
109
  ctx.transform = function ctxTransform(a, b, c, d, e, f) {
111
- var m = this._transformMatrix;
110
+ const m = this._transformMatrix;
112
111
  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]];
113
112
 
114
113
  ctx._originalTransform(a, b, c, d, e, f);
@@ -121,9 +120,9 @@ function addContextCurrentTransform(ctx) {
121
120
  };
122
121
 
123
122
  ctx.rotate = function ctxRotate(angle) {
124
- var cosValue = Math.cos(angle);
125
- var sinValue = Math.sin(angle);
126
- var m = this._transformMatrix;
123
+ const cosValue = Math.cos(angle);
124
+ const sinValue = Math.sin(angle);
125
+ const m = this._transformMatrix;
127
126
  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]];
128
127
 
129
128
  this._originalRotate(angle);
@@ -131,7 +130,7 @@ function addContextCurrentTransform(ctx) {
131
130
  }
132
131
  }
133
132
 
134
- var CachedCanvases = function CachedCanvasesClosure() {
133
+ const CachedCanvases = function CachedCanvasesClosure() {
135
134
  function CachedCanvases(canvasFactory) {
136
135
  this.canvasFactory = canvasFactory;
137
136
  this.cache = Object.create(null);
@@ -139,7 +138,7 @@ var CachedCanvases = function CachedCanvasesClosure() {
139
138
 
140
139
  CachedCanvases.prototype = {
141
140
  getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
142
- var canvasEntry;
141
+ let canvasEntry;
143
142
 
144
143
  if (this.cache[id] !== undefined) {
145
144
  canvasEntry = this.cache[id];
@@ -158,8 +157,8 @@ var CachedCanvases = function CachedCanvasesClosure() {
158
157
  },
159
158
 
160
159
  clear() {
161
- for (var id in this.cache) {
162
- var canvasEntry = this.cache[id];
160
+ for (const id in this.cache) {
161
+ const canvasEntry = this.cache[id];
163
162
  this.canvasFactory.destroy(canvasEntry);
164
163
  delete this.cache[id];
165
164
  }
@@ -170,24 +169,21 @@ var CachedCanvases = function CachedCanvasesClosure() {
170
169
  }();
171
170
 
172
171
  function compileType3Glyph(imgData) {
173
- var POINT_TO_PROCESS_LIMIT = 1000;
174
- var width = imgData.width,
175
- height = imgData.height;
176
- var i,
177
- j,
178
- j0,
179
- width1 = width + 1;
180
- var points = new Uint8Array(width1 * (height + 1));
181
- var POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
182
- var lineSize = width + 7 & ~7,
183
- data0 = imgData.data;
184
- var data = new Uint8Array(lineSize * height),
185
- pos = 0,
186
- ii;
172
+ const POINT_TO_PROCESS_LIMIT = 1000;
173
+ const width = imgData.width,
174
+ height = imgData.height,
175
+ width1 = width + 1;
176
+ let i, ii, j, j0;
177
+ const points = new Uint8Array(width1 * (height + 1));
178
+ const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
179
+ const lineSize = width + 7 & ~7,
180
+ data0 = imgData.data;
181
+ const data = new Uint8Array(lineSize * height);
182
+ let pos = 0;
187
183
 
188
184
  for (i = 0, ii = data0.length; i < ii; i++) {
189
- var mask = 128,
190
- elem = data0[i];
185
+ const elem = data0[i];
186
+ let mask = 128;
191
187
 
192
188
  while (mask > 0) {
193
189
  data[pos++] = elem & mask ? 0 : 255;
@@ -195,7 +191,7 @@ function compileType3Glyph(imgData) {
195
191
  }
196
192
  }
197
193
 
198
- var count = 0;
194
+ let count = 0;
199
195
  pos = 0;
200
196
 
201
197
  if (data[pos] !== 0) {
@@ -226,7 +222,7 @@ function compileType3Glyph(imgData) {
226
222
  ++count;
227
223
  }
228
224
 
229
- var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
225
+ let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
230
226
 
231
227
  for (j = 1; j < width; j++) {
232
228
  sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
@@ -275,12 +271,12 @@ function compileType3Glyph(imgData) {
275
271
  return null;
276
272
  }
277
273
 
278
- var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
279
- var outlines = [];
274
+ const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
275
+ const outlines = [];
280
276
 
281
277
  for (i = 0; count && i <= height; i++) {
282
- var p = i * width1;
283
- var end = p + width;
278
+ let p = i * width1;
279
+ const end = p + width;
284
280
 
285
281
  while (p < end && !points[p]) {
286
282
  p++;
@@ -290,19 +286,18 @@ function compileType3Glyph(imgData) {
290
286
  continue;
291
287
  }
292
288
 
293
- var coords = [p % width1, i];
294
- var type = points[p],
295
- p0 = p,
296
- pp;
289
+ const coords = [p % width1, i];
290
+ const p0 = p;
291
+ let type = points[p];
297
292
 
298
293
  do {
299
- var step = steps[type];
294
+ const step = steps[type];
300
295
 
301
296
  do {
302
297
  p += step;
303
298
  } while (!points[p]);
304
299
 
305
- pp = points[p];
300
+ const pp = points[p];
306
301
 
307
302
  if (pp !== 5 && pp !== 10) {
308
303
  type = pp;
@@ -324,14 +319,14 @@ function compileType3Glyph(imgData) {
324
319
  --i;
325
320
  }
326
321
 
327
- var drawOutline = function (c) {
322
+ const drawOutline = function (c) {
328
323
  c.save();
329
324
  c.scale(1 / width, -1 / height);
330
325
  c.translate(0, -height);
331
326
  c.beginPath();
332
327
 
333
328
  for (let k = 0, kk = outlines.length; k < kk; k++) {
334
- var o = outlines[k];
329
+ const o = outlines[k];
335
330
  c.moveTo(o[0], o[1]);
336
331
 
337
332
  for (let l = 2, ll = o.length; l < ll; l += 2) {
@@ -347,7 +342,7 @@ function compileType3Glyph(imgData) {
347
342
  return drawOutline;
348
343
  }
349
344
 
350
- var CanvasExtraState = function CanvasExtraStateClosure() {
345
+ const CanvasExtraState = function CanvasExtraStateClosure() {
351
346
  function CanvasExtraState() {
352
347
  this.alphaIsShape = false;
353
348
  this.fontSize = 0;
@@ -388,9 +383,9 @@ var CanvasExtraState = function CanvasExtraStateClosure() {
388
383
  return CanvasExtraState;
389
384
  }();
390
385
 
391
- var CanvasGraphics = function CanvasGraphicsClosure() {
392
- var EXECUTION_TIME = 15;
393
- var EXECUTION_STEPS = 10;
386
+ const CanvasGraphics = function CanvasGraphicsClosure() {
387
+ const EXECUTION_TIME = 15;
388
+ const EXECUTION_STEPS = 10;
394
389
 
395
390
  function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, webGLContext, imageLayer, optionalContentConfig) {
396
391
  this.ctx = canvasCtx;
@@ -431,17 +426,17 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
431
426
  return;
432
427
  }
433
428
 
434
- var height = imgData.height,
435
- width = imgData.width;
436
- var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
437
- var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
438
- var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
439
- var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
440
- var srcPos = 0,
429
+ const height = imgData.height,
430
+ width = imgData.width;
431
+ const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
432
+ const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
433
+ const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
434
+ const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
435
+ let srcPos = 0,
441
436
  destPos;
442
- var src = imgData.data;
443
- var dest = chunkImgData.data;
444
- var i, j, thisChunkHeight, elemsInThisChunk;
437
+ const src = imgData.data;
438
+ const dest = chunkImgData.data;
439
+ let i, j, thisChunkHeight, elemsInThisChunk;
445
440
  let transferMapRed, transferMapGreen, transferMapBlue, transferMapGray;
446
441
 
447
442
  if (transferMaps) {
@@ -463,12 +458,12 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
463
458
  }
464
459
 
465
460
  if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
466
- var srcLength = src.byteLength;
467
- var dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
468
- var dest32DataLength = dest32.length;
469
- var fullSrcDiff = width + 7 >> 3;
470
- var white = 0xffffffff;
471
- var black = _util.IsLittleEndianCached.value ? 0xff000000 : 0x000000ff;
461
+ const srcLength = src.byteLength;
462
+ const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
463
+ const dest32DataLength = dest32.length;
464
+ const fullSrcDiff = width + 7 >> 3;
465
+ let white = 0xffffffff;
466
+ let black = _util.IsLittleEndianCached.value ? 0xff000000 : 0x000000ff;
472
467
 
473
468
  if (transferMapGray) {
474
469
  if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) {
@@ -481,12 +476,12 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
481
476
  destPos = 0;
482
477
 
483
478
  for (j = 0; j < thisChunkHeight; j++) {
484
- var srcDiff = srcLength - srcPos;
479
+ const srcDiff = srcLength - srcPos;
485
480
  let k = 0;
486
- var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
487
- var kEndUnrolled = kEnd & ~7;
488
- var mask = 0;
489
- var srcByte = 0;
481
+ const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
482
+ const kEndUnrolled = kEnd & ~7;
483
+ let mask = 0;
484
+ let srcByte = 0;
490
485
 
491
486
  for (; k < kEndUnrolled; k += 8) {
492
487
  srcByte = src[srcPos++];
@@ -612,26 +607,27 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
612
607
  }
613
608
 
614
609
  function putBinaryImageMask(ctx, imgData) {
615
- var height = imgData.height,
616
- width = imgData.width;
617
- var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
618
- var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
619
- var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
620
- var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
621
- var srcPos = 0;
622
- var src = imgData.data;
623
- var dest = chunkImgData.data;
624
-
625
- for (var i = 0; i < totalChunks; i++) {
626
- var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
627
- var destPos = 3;
628
-
629
- for (var j = 0; j < thisChunkHeight; j++) {
630
- var mask = 0;
631
-
632
- for (var k = 0; k < width; k++) {
610
+ const height = imgData.height,
611
+ width = imgData.width;
612
+ const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
613
+ const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
614
+ const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
615
+ const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
616
+ let srcPos = 0;
617
+ const src = imgData.data;
618
+ const dest = chunkImgData.data;
619
+
620
+ for (let i = 0; i < totalChunks; i++) {
621
+ const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
622
+ let destPos = 3;
623
+
624
+ for (let j = 0; j < thisChunkHeight; j++) {
625
+ let elem,
626
+ mask = 0;
627
+
628
+ for (let k = 0; k < width; k++) {
633
629
  if (!mask) {
634
- var elem = src[srcPos++];
630
+ elem = src[srcPos++];
635
631
  mask = 128;
636
632
  }
637
633
 
@@ -646,10 +642,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
646
642
  }
647
643
 
648
644
  function copyCtxState(sourceCtx, destCtx) {
649
- var properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
645
+ const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
650
646
 
651
- for (var i = 0, ii = properties.length; i < ii; i++) {
652
- var property = properties[i];
647
+ for (let i = 0, ii = properties.length; i < ii; i++) {
648
+ const property = properties[i];
653
649
 
654
650
  if (sourceCtx[property] !== undefined) {
655
651
  destCtx[property] = sourceCtx[property];
@@ -681,17 +677,17 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
681
677
  }
682
678
 
683
679
  function composeSMaskBackdrop(bytes, r0, g0, b0) {
684
- var length = bytes.length;
680
+ const length = bytes.length;
685
681
 
686
- for (var i = 3; i < length; i += 4) {
687
- var alpha = bytes[i];
682
+ for (let i = 3; i < length; i += 4) {
683
+ const alpha = bytes[i];
688
684
 
689
685
  if (alpha === 0) {
690
686
  bytes[i - 3] = r0;
691
687
  bytes[i - 2] = g0;
692
688
  bytes[i - 1] = b0;
693
689
  } else if (alpha < 255) {
694
- var alpha_ = 255 - alpha;
690
+ const alpha_ = 255 - alpha;
695
691
  bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
696
692
  bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
697
693
  bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
@@ -700,30 +696,30 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
700
696
  }
701
697
 
702
698
  function composeSMaskAlpha(maskData, layerData, transferMap) {
703
- var length = maskData.length;
704
- var scale = 1 / 255;
699
+ const length = maskData.length;
700
+ const scale = 1 / 255;
705
701
 
706
- for (var i = 3; i < length; i += 4) {
707
- var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
702
+ for (let i = 3; i < length; i += 4) {
703
+ const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
708
704
  layerData[i] = layerData[i] * alpha * scale | 0;
709
705
  }
710
706
  }
711
707
 
712
708
  function composeSMaskLuminosity(maskData, layerData, transferMap) {
713
- var length = maskData.length;
709
+ const length = maskData.length;
714
710
 
715
- for (var i = 3; i < length; i += 4) {
716
- var y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
711
+ for (let i = 3; i < length; i += 4) {
712
+ const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
717
713
  layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
718
714
  }
719
715
  }
720
716
 
721
717
  function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
722
- var hasBackdrop = !!backdrop;
723
- var r0 = hasBackdrop ? backdrop[0] : 0;
724
- var g0 = hasBackdrop ? backdrop[1] : 0;
725
- var b0 = hasBackdrop ? backdrop[2] : 0;
726
- var composeFn;
718
+ const hasBackdrop = !!backdrop;
719
+ const r0 = hasBackdrop ? backdrop[0] : 0;
720
+ const g0 = hasBackdrop ? backdrop[1] : 0;
721
+ const b0 = hasBackdrop ? backdrop[2] : 0;
722
+ let composeFn;
727
723
 
728
724
  if (subtype === "Luminosity") {
729
725
  composeFn = composeSMaskLuminosity;
@@ -731,13 +727,13 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
731
727
  composeFn = composeSMaskAlpha;
732
728
  }
733
729
 
734
- var PIXELS_TO_PROCESS = 1048576;
735
- var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
730
+ const PIXELS_TO_PROCESS = 1048576;
731
+ const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
736
732
 
737
- for (var row = 0; row < height; row += chunkSize) {
738
- var chunkHeight = Math.min(chunkSize, height - row);
739
- var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
740
- var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
733
+ for (let row = 0; row < height; row += chunkSize) {
734
+ const chunkHeight = Math.min(chunkSize, height - row);
735
+ const maskData = maskCtx.getImageData(0, row, width, chunkHeight);
736
+ const layerData = layerCtx.getImageData(0, row, width, chunkHeight);
741
737
 
742
738
  if (hasBackdrop) {
743
739
  composeSMaskBackdrop(maskData.data, r0, g0, b0);
@@ -749,10 +745,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
749
745
  }
750
746
 
751
747
  function composeSMask(ctx, smask, layerCtx, webGLContext) {
752
- var mask = smask.canvas;
753
- var maskCtx = smask.context;
748
+ const mask = smask.canvas;
749
+ const maskCtx = smask.context;
754
750
  ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
755
- var backdrop = smask.backdrop || null;
751
+ const backdrop = smask.backdrop || null;
756
752
 
757
753
  if (!smask.transferMap && webGLContext.isEnabled) {
758
754
  const composed = webGLContext.composeSMask({
@@ -772,10 +768,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
772
768
  ctx.drawImage(mask, 0, 0);
773
769
  }
774
770
 
775
- var LINE_CAP_STYLES = ["butt", "round", "square"];
776
- var LINE_JOIN_STYLES = ["miter", "round", "bevel"];
777
- var NORMAL_CLIP = {};
778
- var EO_CLIP = {};
771
+ const LINE_CAP_STYLES = ["butt", "round", "square"];
772
+ const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
773
+ const NORMAL_CLIP = {};
774
+ const EO_CLIP = {};
779
775
  CanvasGraphics.prototype = {
780
776
  beginDrawing({
781
777
  transform,
@@ -783,15 +779,15 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
783
779
  transparency = false,
784
780
  background = null
785
781
  }) {
786
- var width = this.ctx.canvas.width;
787
- var height = this.ctx.canvas.height;
782
+ const width = this.ctx.canvas.width;
783
+ const height = this.ctx.canvas.height;
788
784
  this.ctx.save();
789
785
  this.ctx.fillStyle = background || "rgb(255, 255, 255)";
790
786
  this.ctx.fillRect(0, 0, width, height);
791
787
  this.ctx.restore();
792
788
 
793
789
  if (transparency) {
794
- var transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height, true);
790
+ const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height, true);
795
791
  this.compositeCtx = this.ctx;
796
792
  this.transparentCanvas = transparentCanvas.canvas;
797
793
  this.ctx = transparentCanvas.context;
@@ -808,6 +804,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
808
804
 
809
805
  this.ctx.transform.apply(this.ctx, viewport.transform);
810
806
  this.baseTransform = this.ctx.mozCurrentTransform.slice();
807
+ this._combinedScaleFactor = Math.hypot(this.baseTransform[0], this.baseTransform[2]);
811
808
 
812
809
  if (this.imageLayer) {
813
810
  this.imageLayer.beginLayout();
@@ -815,21 +812,21 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
815
812
  },
816
813
 
817
814
  executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
818
- var argsArray = operatorList.argsArray;
819
- var fnArray = operatorList.fnArray;
820
- var i = executionStartIdx || 0;
821
- var argsArrayLen = argsArray.length;
815
+ const argsArray = operatorList.argsArray;
816
+ const fnArray = operatorList.fnArray;
817
+ let i = executionStartIdx || 0;
818
+ const argsArrayLen = argsArray.length;
822
819
 
823
820
  if (argsArrayLen === i) {
824
821
  return i;
825
822
  }
826
823
 
827
- var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
828
- var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
829
- var steps = 0;
830
- var commonObjs = this.commonObjs;
831
- var objs = this.objs;
832
- var fnId;
824
+ const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
825
+ const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
826
+ let steps = 0;
827
+ const commonObjs = this.commonObjs;
828
+ const objs = this.objs;
829
+ let fnId;
833
830
 
834
831
  while (true) {
835
832
  if (stepper !== undefined && i === stepper.nextBreakPoint) {
@@ -869,8 +866,8 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
869
866
  }
870
867
  },
871
868
  endDrawing: function CanvasGraphics_endDrawing() {
872
- if (this.current.activeSMask !== null) {
873
- this.endSMaskGroup();
869
+ while (this.stateStack.length || this.current.activeSMask !== null) {
870
+ this.restore();
874
871
  }
875
872
 
876
873
  this.ctx.restore();
@@ -905,7 +902,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
905
902
  this.ctx.miterLimit = limit;
906
903
  },
907
904
  setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
908
- var ctx = this.ctx;
905
+ const ctx = this.ctx;
909
906
 
910
907
  if (ctx.setLineDash !== undefined) {
911
908
  ctx.setLineDash(dashArray);
@@ -918,10 +915,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
918
915
  setFlatness(flatness) {},
919
916
 
920
917
  setGState: function CanvasGraphics_setGState(states) {
921
- for (var i = 0, ii = states.length; i < ii; i++) {
922
- var state = states[i];
923
- var key = state[0];
924
- var value = state[1];
918
+ for (let i = 0, ii = states.length; i < ii; i++) {
919
+ const state = states[i];
920
+ const key = state[0];
921
+ const value = state[1];
925
922
 
926
923
  switch (key) {
927
924
  case "LW":
@@ -993,15 +990,15 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
993
990
  }
994
991
  },
995
992
  beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
996
- var activeSMask = this.current.activeSMask;
997
- var drawnWidth = activeSMask.canvas.width;
998
- var drawnHeight = activeSMask.canvas.height;
999
- var cacheId = "smaskGroupAt" + this.groupLevel;
1000
- var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
1001
- var currentCtx = this.ctx;
1002
- var currentTransform = currentCtx.mozCurrentTransform;
993
+ const activeSMask = this.current.activeSMask;
994
+ const drawnWidth = activeSMask.canvas.width;
995
+ const drawnHeight = activeSMask.canvas.height;
996
+ const cacheId = "smaskGroupAt" + this.groupLevel;
997
+ const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
998
+ const currentCtx = this.ctx;
999
+ const currentTransform = currentCtx.mozCurrentTransform;
1003
1000
  this.ctx.save();
1004
- var groupCtx = scratchCanvas.context;
1001
+ const groupCtx = scratchCanvas.context;
1005
1002
  groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
1006
1003
  groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
1007
1004
  groupCtx.transform.apply(groupCtx, currentTransform);
@@ -1013,7 +1010,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1013
1010
  this.groupLevel++;
1014
1011
  },
1015
1012
  suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
1016
- var groupCtx = this.ctx;
1013
+ const groupCtx = this.ctx;
1017
1014
  this.groupLevel--;
1018
1015
  this.ctx = this.groupStack.pop();
1019
1016
  composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
@@ -1022,7 +1019,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1022
1019
  copyCtxState(groupCtx, this.ctx);
1023
1020
  this.current.resumeSMaskCtx = groupCtx;
1024
1021
 
1025
- var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
1022
+ const deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
1026
1023
 
1027
1024
  this.ctx.transform.apply(this.ctx, deltaTransform);
1028
1025
  groupCtx.save();
@@ -1030,28 +1027,28 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1030
1027
  groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
1031
1028
  groupCtx.restore();
1032
1029
  },
1033
- resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
1034
- var groupCtx = this.current.resumeSMaskCtx;
1035
- var currentCtx = this.ctx;
1030
+ resumeSMaskGroup: function CanvasGraphics_resumeSMaskGroup() {
1031
+ const groupCtx = this.current.resumeSMaskCtx;
1032
+ const currentCtx = this.ctx;
1036
1033
  this.ctx = groupCtx;
1037
1034
  this.groupStack.push(currentCtx);
1038
1035
  this.groupLevel++;
1039
1036
  },
1040
1037
  endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
1041
- var groupCtx = this.ctx;
1038
+ const groupCtx = this.ctx;
1042
1039
  this.groupLevel--;
1043
1040
  this.ctx = this.groupStack.pop();
1044
1041
  composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
1045
1042
  this.ctx.restore();
1046
1043
  copyCtxState(groupCtx, this.ctx);
1047
1044
 
1048
- var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
1045
+ const deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
1049
1046
 
1050
1047
  this.ctx.transform.apply(this.ctx, deltaTransform);
1051
1048
  },
1052
1049
  save: function CanvasGraphics_save() {
1053
1050
  this.ctx.save();
1054
- var old = this.current;
1051
+ const old = this.current;
1055
1052
  this.stateStack.push(old);
1056
1053
  this.current = old.clone();
1057
1054
  this.current.resumeSMaskCtx = null;
@@ -1070,6 +1067,8 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1070
1067
  this.ctx.restore();
1071
1068
  this.pendingClip = null;
1072
1069
  this._cachedGetSinglePixelWidth = null;
1070
+ } else {
1071
+ this.current.activeSMask = null;
1073
1072
  }
1074
1073
  },
1075
1074
  transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
@@ -1077,34 +1076,30 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1077
1076
  this._cachedGetSinglePixelWidth = null;
1078
1077
  },
1079
1078
  constructPath: function CanvasGraphics_constructPath(ops, args) {
1080
- var ctx = this.ctx;
1081
- var current = this.current;
1082
- var x = current.x,
1079
+ const ctx = this.ctx;
1080
+ const current = this.current;
1081
+ let x = current.x,
1083
1082
  y = current.y;
1084
1083
 
1085
- for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
1084
+ for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
1086
1085
  switch (ops[i] | 0) {
1087
1086
  case _util.OPS.rectangle:
1088
1087
  x = args[j++];
1089
1088
  y = args[j++];
1090
- var width = args[j++];
1091
- var height = args[j++];
1092
-
1093
- if (width === 0 && ctx.lineWidth < this.getSinglePixelWidth()) {
1094
- width = this.getSinglePixelWidth();
1095
- }
1089
+ const width = args[j++];
1090
+ const height = args[j++];
1091
+ const xw = x + width;
1092
+ const yh = y + height;
1093
+ ctx.moveTo(x, y);
1096
1094
 
1097
- if (height === 0 && ctx.lineWidth < this.getSinglePixelWidth()) {
1098
- height = this.getSinglePixelWidth();
1095
+ if (width === 0 || height === 0) {
1096
+ ctx.lineTo(xw, yh);
1097
+ } else {
1098
+ ctx.lineTo(xw, y);
1099
+ ctx.lineTo(xw, yh);
1100
+ ctx.lineTo(x, yh);
1099
1101
  }
1100
1102
 
1101
- var xw = x + width;
1102
- var yh = y + height;
1103
- ctx.moveTo(x, y);
1104
- ctx.lineTo(xw, y);
1105
- ctx.lineTo(xw, yh);
1106
- ctx.lineTo(x, yh);
1107
- ctx.lineTo(x, y);
1108
1103
  ctx.closePath();
1109
1104
  break;
1110
1105
 
@@ -1154,24 +1149,43 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1154
1149
  },
1155
1150
  stroke: function CanvasGraphics_stroke(consumePath) {
1156
1151
  consumePath = typeof consumePath !== "undefined" ? consumePath : true;
1157
- var ctx = this.ctx;
1158
- var strokeColor = this.current.strokeColor;
1152
+ const ctx = this.ctx;
1153
+ const strokeColor = this.current.strokeColor;
1159
1154
  ctx.globalAlpha = this.current.strokeAlpha;
1160
1155
 
1161
1156
  if (this.contentVisible) {
1162
- if (strokeColor && strokeColor.hasOwnProperty("type") && strokeColor.type === "Pattern") {
1157
+ if (typeof strokeColor === "object" && strokeColor?.getPattern) {
1163
1158
  ctx.save();
1164
1159
  const transform = ctx.mozCurrentTransform;
1165
1160
 
1166
1161
  const scale = _util.Util.singularValueDecompose2dScale(transform)[0];
1167
1162
 
1168
1163
  ctx.strokeStyle = strokeColor.getPattern(ctx, this);
1169
- ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth * scale);
1164
+ const lineWidth = this.getSinglePixelWidth();
1165
+ const scaledLineWidth = this.current.lineWidth * scale;
1166
+
1167
+ if (lineWidth < 0 && -lineWidth >= scaledLineWidth) {
1168
+ ctx.resetTransform();
1169
+ ctx.lineWidth = Math.round(this._combinedScaleFactor);
1170
+ } else {
1171
+ ctx.lineWidth = Math.max(lineWidth, scaledLineWidth);
1172
+ }
1173
+
1170
1174
  ctx.stroke();
1171
1175
  ctx.restore();
1172
1176
  } else {
1173
- ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
1174
- ctx.stroke();
1177
+ const lineWidth = this.getSinglePixelWidth();
1178
+
1179
+ if (lineWidth < 0 && -lineWidth >= this.current.lineWidth) {
1180
+ ctx.save();
1181
+ ctx.resetTransform();
1182
+ ctx.lineWidth = Math.round(this._combinedScaleFactor);
1183
+ ctx.stroke();
1184
+ ctx.restore();
1185
+ } else {
1186
+ ctx.lineWidth = Math.max(lineWidth, this.current.lineWidth);
1187
+ ctx.stroke();
1188
+ }
1175
1189
  }
1176
1190
  }
1177
1191
 
@@ -1187,10 +1201,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1187
1201
  },
1188
1202
  fill: function CanvasGraphics_fill(consumePath) {
1189
1203
  consumePath = typeof consumePath !== "undefined" ? consumePath : true;
1190
- var ctx = this.ctx;
1191
- var fillColor = this.current.fillColor;
1192
- var isPatternFill = this.current.patternFill;
1193
- var needRestore = false;
1204
+ const ctx = this.ctx;
1205
+ const fillColor = this.current.fillColor;
1206
+ const isPatternFill = this.current.patternFill;
1207
+ let needRestore = false;
1194
1208
 
1195
1209
  if (isPatternFill) {
1196
1210
  ctx.save();
@@ -1258,8 +1272,8 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1258
1272
  this.current.y = this.current.lineY = 0;
1259
1273
  },
1260
1274
  endText: function CanvasGraphics_endText() {
1261
- var paths = this.pendingTextPaths;
1262
- var ctx = this.ctx;
1275
+ const paths = this.pendingTextPaths;
1276
+ const ctx = this.ctx;
1263
1277
 
1264
1278
  if (paths === undefined) {
1265
1279
  ctx.beginPath();
@@ -1269,8 +1283,8 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1269
1283
  ctx.save();
1270
1284
  ctx.beginPath();
1271
1285
 
1272
- for (var i = 0; i < paths.length; i++) {
1273
- var path = paths[i];
1286
+ for (let i = 0; i < paths.length; i++) {
1287
+ const path = paths[i];
1274
1288
  ctx.setTransform.apply(ctx, path.transform);
1275
1289
  ctx.translate(path.x, path.y);
1276
1290
  path.addToPath(ctx, path.fontSize);
@@ -1294,14 +1308,14 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1294
1308
  this.current.leading = -leading;
1295
1309
  },
1296
1310
  setFont: function CanvasGraphics_setFont(fontRefName, size) {
1297
- var fontObj = this.commonObjs.get(fontRefName);
1298
- var current = this.current;
1311
+ const fontObj = this.commonObjs.get(fontRefName);
1312
+ const current = this.current;
1299
1313
 
1300
1314
  if (!fontObj) {
1301
1315
  throw new Error(`Can't find font for ${fontRefName}`);
1302
1316
  }
1303
1317
 
1304
- current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
1318
+ current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
1305
1319
 
1306
1320
  if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
1307
1321
  (0, _util.warn)("Invalid font matrix for font " + fontRefName);
@@ -1321,7 +1335,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1321
1335
  return;
1322
1336
  }
1323
1337
 
1324
- var name = fontObj.loadedName || "sans-serif";
1338
+ const name = fontObj.loadedName || "sans-serif";
1325
1339
  let bold = "normal";
1326
1340
 
1327
1341
  if (fontObj.black) {
@@ -1330,8 +1344,8 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1330
1344
  bold = "bold";
1331
1345
  }
1332
1346
 
1333
- var italic = fontObj.italic ? "italic" : "normal";
1334
- var typeface = `"${name}", ${fontObj.fallbackName}`;
1347
+ const italic = fontObj.italic ? "italic" : "normal";
1348
+ const typeface = `"${name}", ${fontObj.fallbackName}`;
1335
1349
  let browserFontSize = size;
1336
1350
 
1337
1351
  if (size < MIN_FONT_SIZE) {
@@ -1367,16 +1381,16 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1367
1381
  this.moveText(0, this.current.leading);
1368
1382
  },
1369
1383
 
1370
- paintChar(character, x, y, patternTransform) {
1371
- var ctx = this.ctx;
1372
- var current = this.current;
1373
- var font = current.font;
1374
- var textRenderingMode = current.textRenderingMode;
1375
- var fontSize = current.fontSize / current.fontSizeScale;
1376
- var fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
1377
- var isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
1384
+ paintChar(character, x, y, patternTransform, resetLineWidthToOne) {
1385
+ const ctx = this.ctx;
1386
+ const current = this.current;
1387
+ const font = current.font;
1388
+ const textRenderingMode = current.textRenderingMode;
1389
+ const fontSize = current.fontSize / current.fontSizeScale;
1390
+ const fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
1391
+ const isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
1378
1392
  const patternFill = current.patternFill && !font.missingFile;
1379
- var addToPath;
1393
+ let addToPath;
1380
1394
 
1381
1395
  if (font.disableFontFace || isAddToPathSet || patternFill) {
1382
1396
  addToPath = font.getPathGenerator(this.commonObjs, character);
@@ -1397,6 +1411,11 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1397
1411
  }
1398
1412
 
1399
1413
  if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1414
+ if (resetLineWidthToOne) {
1415
+ ctx.resetTransform();
1416
+ ctx.lineWidth = Math.round(this._combinedScaleFactor);
1417
+ }
1418
+
1400
1419
  ctx.stroke();
1401
1420
  }
1402
1421
 
@@ -1407,12 +1426,21 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1407
1426
  }
1408
1427
 
1409
1428
  if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1410
- ctx.strokeText(character, x, y);
1429
+ if (resetLineWidthToOne) {
1430
+ ctx.save();
1431
+ ctx.moveTo(x, y);
1432
+ ctx.resetTransform();
1433
+ ctx.lineWidth = Math.round(this._combinedScaleFactor);
1434
+ ctx.strokeText(character, 0, 0);
1435
+ ctx.restore();
1436
+ } else {
1437
+ ctx.strokeText(character, x, y);
1438
+ }
1411
1439
  }
1412
1440
  }
1413
1441
 
1414
1442
  if (isAddToPathSet) {
1415
- var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
1443
+ const paths = this.pendingTextPaths || (this.pendingTextPaths = []);
1416
1444
  paths.push({
1417
1445
  transform: ctx.mozCurrentTransform,
1418
1446
  x,
@@ -1429,10 +1457,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1429
1457
  } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
1430
1458
  ctx.scale(1.5, 1);
1431
1459
  ctx.fillText("I", 0, 10);
1432
- var data = ctx.getImageData(0, 0, 10, 10).data;
1433
- var enabled = false;
1460
+ const data = ctx.getImageData(0, 0, 10, 10).data;
1461
+ let enabled = false;
1434
1462
 
1435
- for (var i = 3; i < data.length; i += 4) {
1463
+ for (let i = 3; i < data.length; i += 4) {
1436
1464
  if (data[i] > 0 && data[i] < 255) {
1437
1465
  enabled = true;
1438
1466
  break;
@@ -1443,31 +1471,31 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1443
1471
  },
1444
1472
 
1445
1473
  showText: function CanvasGraphics_showText(glyphs) {
1446
- var current = this.current;
1447
- var font = current.font;
1474
+ const current = this.current;
1475
+ const font = current.font;
1448
1476
 
1449
1477
  if (font.isType3Font) {
1450
1478
  return this.showType3Text(glyphs);
1451
1479
  }
1452
1480
 
1453
- var fontSize = current.fontSize;
1481
+ const fontSize = current.fontSize;
1454
1482
 
1455
1483
  if (fontSize === 0) {
1456
1484
  return undefined;
1457
1485
  }
1458
1486
 
1459
- var ctx = this.ctx;
1460
- var fontSizeScale = current.fontSizeScale;
1461
- var charSpacing = current.charSpacing;
1462
- var wordSpacing = current.wordSpacing;
1463
- var fontDirection = current.fontDirection;
1464
- var textHScale = current.textHScale * fontDirection;
1465
- var glyphsLength = glyphs.length;
1466
- var vertical = font.vertical;
1467
- var spacingDir = vertical ? 1 : -1;
1468
- var defaultVMetrics = font.defaultVMetrics;
1469
- var widthAdvanceScale = fontSize * current.fontMatrix[0];
1470
- var simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
1487
+ const ctx = this.ctx;
1488
+ const fontSizeScale = current.fontSizeScale;
1489
+ const charSpacing = current.charSpacing;
1490
+ const wordSpacing = current.wordSpacing;
1491
+ const fontDirection = current.fontDirection;
1492
+ const textHScale = current.textHScale * fontDirection;
1493
+ const glyphsLength = glyphs.length;
1494
+ const vertical = font.vertical;
1495
+ const spacingDir = vertical ? 1 : -1;
1496
+ const defaultVMetrics = font.defaultVMetrics;
1497
+ const widthAdvanceScale = fontSize * current.fontMatrix[0];
1498
+ const simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
1471
1499
  ctx.save();
1472
1500
  let patternTransform;
1473
1501
 
@@ -1488,15 +1516,17 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1488
1516
  ctx.scale(textHScale, 1);
1489
1517
  }
1490
1518
 
1491
- var lineWidth = current.lineWidth;
1492
- var scale = current.textMatrixScale;
1519
+ let lineWidth = current.lineWidth;
1520
+ let resetLineWidthToOne = false;
1521
+ const scale = current.textMatrixScale;
1493
1522
 
1494
1523
  if (scale === 0 || lineWidth === 0) {
1495
- var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
1524
+ const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
1496
1525
 
1497
1526
  if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
1498
1527
  this._cachedGetSinglePixelWidth = null;
1499
- lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
1528
+ lineWidth = this.getSinglePixelWidth();
1529
+ resetLineWidthToOne = lineWidth < 0;
1500
1530
  }
1501
1531
  } else {
1502
1532
  lineWidth /= scale;
@@ -1508,30 +1538,28 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1508
1538
  }
1509
1539
 
1510
1540
  ctx.lineWidth = lineWidth;
1511
- var x = 0,
1541
+ let x = 0,
1512
1542
  i;
1513
1543
 
1514
1544
  for (i = 0; i < glyphsLength; ++i) {
1515
- var glyph = glyphs[i];
1545
+ const glyph = glyphs[i];
1516
1546
 
1517
1547
  if ((0, _util.isNum)(glyph)) {
1518
1548
  x += spacingDir * glyph * fontSize / 1000;
1519
1549
  continue;
1520
1550
  }
1521
1551
 
1522
- var restoreNeeded = false;
1523
- var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
1524
- var character = glyph.fontChar;
1525
- var accent = glyph.accent;
1526
- var scaledX, scaledY, scaledAccentX, scaledAccentY;
1527
- var width = glyph.width;
1552
+ let restoreNeeded = false;
1553
+ const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
1554
+ const character = glyph.fontChar;
1555
+ const accent = glyph.accent;
1556
+ let scaledX, scaledY;
1557
+ let width = glyph.width;
1528
1558
 
1529
1559
  if (vertical) {
1530
- var vmetric, vx, vy;
1531
- vmetric = glyph.vmetric || defaultVMetrics;
1532
- vx = glyph.vmetric ? vmetric[1] : width * 0.5;
1533
- vx = -vx * widthAdvanceScale;
1534
- vy = vmetric[2] * widthAdvanceScale;
1560
+ const vmetric = glyph.vmetric || defaultVMetrics;
1561
+ const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
1562
+ const vy = vmetric[2] * widthAdvanceScale;
1535
1563
  width = vmetric ? -vmetric[0] : width;
1536
1564
  scaledX = vx / fontSizeScale;
1537
1565
  scaledY = (x + vy) / fontSizeScale;
@@ -1541,10 +1569,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1541
1569
  }
1542
1570
 
1543
1571
  if (font.remeasure && width > 0) {
1544
- var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
1572
+ const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
1545
1573
 
1546
1574
  if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
1547
- var characterScaleX = width / measuredWidth;
1575
+ const characterScaleX = width / measuredWidth;
1548
1576
  restoreNeeded = true;
1549
1577
  ctx.save();
1550
1578
  ctx.scale(characterScaleX, 1);
@@ -1558,17 +1586,17 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1558
1586
  if (simpleFillText && !accent) {
1559
1587
  ctx.fillText(character, scaledX, scaledY);
1560
1588
  } else {
1561
- this.paintChar(character, scaledX, scaledY, patternTransform);
1589
+ this.paintChar(character, scaledX, scaledY, patternTransform, resetLineWidthToOne);
1562
1590
 
1563
1591
  if (accent) {
1564
- scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
1565
- scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
1566
- this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
1592
+ const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
1593
+ const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
1594
+ this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform, resetLineWidthToOne);
1567
1595
  }
1568
1596
  }
1569
1597
  }
1570
1598
 
1571
- var charWidth;
1599
+ let charWidth;
1572
1600
 
1573
1601
  if (vertical) {
1574
1602
  charWidth = width * widthAdvanceScale - spacing * fontDirection;
@@ -1592,19 +1620,19 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1592
1620
  ctx.restore();
1593
1621
  },
1594
1622
  showType3Text: function CanvasGraphics_showType3Text(glyphs) {
1595
- var ctx = this.ctx;
1596
- var current = this.current;
1597
- var font = current.font;
1598
- var fontSize = current.fontSize;
1599
- var fontDirection = current.fontDirection;
1600
- var spacingDir = font.vertical ? 1 : -1;
1601
- var charSpacing = current.charSpacing;
1602
- var wordSpacing = current.wordSpacing;
1603
- var textHScale = current.textHScale * fontDirection;
1604
- var fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
1605
- var glyphsLength = glyphs.length;
1606
- var isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
1607
- var i, glyph, width, spacingLength;
1623
+ const ctx = this.ctx;
1624
+ const current = this.current;
1625
+ const font = current.font;
1626
+ const fontSize = current.fontSize;
1627
+ const fontDirection = current.fontDirection;
1628
+ const spacingDir = font.vertical ? 1 : -1;
1629
+ const charSpacing = current.charSpacing;
1630
+ const wordSpacing = current.wordSpacing;
1631
+ const textHScale = current.textHScale * fontDirection;
1632
+ const fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
1633
+ const glyphsLength = glyphs.length;
1634
+ const isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
1635
+ let i, glyph, width, spacingLength;
1608
1636
 
1609
1637
  if (isTextInvisible || fontSize === 0) {
1610
1638
  return;
@@ -1626,8 +1654,8 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1626
1654
  continue;
1627
1655
  }
1628
1656
 
1629
- var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
1630
- var operatorList = font.charProcOperatorList[glyph.operatorListId];
1657
+ const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
1658
+ const operatorList = font.charProcOperatorList[glyph.operatorListId];
1631
1659
 
1632
1660
  if (!operatorList) {
1633
1661
  (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
@@ -1643,7 +1671,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1643
1671
  this.restore();
1644
1672
  }
1645
1673
 
1646
- var transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
1674
+ const transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
1647
1675
 
1648
1676
  width = transformed[0] * fontSize + spacing;
1649
1677
  ctx.translate(width, 0);
@@ -1660,12 +1688,12 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1660
1688
  this.endPath();
1661
1689
  },
1662
1690
  getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
1663
- var pattern;
1691
+ let pattern;
1664
1692
 
1665
1693
  if (IR[0] === "TilingPattern") {
1666
- var color = IR[1];
1667
- var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
1668
- var canvasGraphicsFactory = {
1694
+ const color = IR[1];
1695
+ const baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
1696
+ const canvasGraphicsFactory = {
1669
1697
  createCanvasGraphics: ctx => {
1670
1698
  return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext);
1671
1699
  }
@@ -1685,13 +1713,13 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1685
1713
  this.current.patternFill = true;
1686
1714
  },
1687
1715
  setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
1688
- var color = _util.Util.makeCssRgb(r, g, b);
1716
+ const color = _util.Util.makeHexColor(r, g, b);
1689
1717
 
1690
1718
  this.ctx.strokeStyle = color;
1691
1719
  this.current.strokeColor = color;
1692
1720
  },
1693
1721
  setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
1694
- var color = _util.Util.makeCssRgb(r, g, b);
1722
+ const color = _util.Util.makeHexColor(r, g, b);
1695
1723
 
1696
1724
  this.ctx.fillStyle = color;
1697
1725
  this.current.fillColor = color;
@@ -1702,29 +1730,29 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1702
1730
  return;
1703
1731
  }
1704
1732
 
1705
- var ctx = this.ctx;
1733
+ const ctx = this.ctx;
1706
1734
  this.save();
1707
- var pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
1735
+ const pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
1708
1736
  ctx.fillStyle = pattern.getPattern(ctx, this, true);
1709
- var inv = ctx.mozCurrentTransformInverse;
1737
+ const inv = ctx.mozCurrentTransformInverse;
1710
1738
 
1711
1739
  if (inv) {
1712
- var canvas = ctx.canvas;
1713
- var width = canvas.width;
1714
- var height = canvas.height;
1740
+ const canvas = ctx.canvas;
1741
+ const width = canvas.width;
1742
+ const height = canvas.height;
1715
1743
 
1716
- var bl = _util.Util.applyTransform([0, 0], inv);
1744
+ const bl = _util.Util.applyTransform([0, 0], inv);
1717
1745
 
1718
- var br = _util.Util.applyTransform([0, height], inv);
1746
+ const br = _util.Util.applyTransform([0, height], inv);
1719
1747
 
1720
- var ul = _util.Util.applyTransform([width, 0], inv);
1748
+ const ul = _util.Util.applyTransform([width, 0], inv);
1721
1749
 
1722
- var ur = _util.Util.applyTransform([width, height], inv);
1750
+ const ur = _util.Util.applyTransform([width, height], inv);
1723
1751
 
1724
- var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
1725
- var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
1726
- var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
1727
- var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
1752
+ const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
1753
+ const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
1754
+ const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
1755
+ const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
1728
1756
  this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
1729
1757
  } else {
1730
1758
  this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
@@ -1753,8 +1781,8 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1753
1781
  this.baseTransform = this.ctx.mozCurrentTransform;
1754
1782
 
1755
1783
  if (bbox) {
1756
- var width = bbox[2] - bbox[0];
1757
- var height = bbox[3] - bbox[1];
1784
+ const width = bbox[2] - bbox[0];
1785
+ const height = bbox[3] - bbox[1];
1758
1786
  this.ctx.rect(bbox[0], bbox[1], width, height);
1759
1787
  this.clip();
1760
1788
  this.endPath();
@@ -1774,7 +1802,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1774
1802
  }
1775
1803
 
1776
1804
  this.save();
1777
- var currentCtx = this.ctx;
1805
+ const currentCtx = this.ctx;
1778
1806
 
1779
1807
  if (!group.isolated) {
1780
1808
  (0, _util.info)("TODO: Support non-isolated groups.");
@@ -1784,7 +1812,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1784
1812
  (0, _util.warn)("Knockout groups not supported.");
1785
1813
  }
1786
1814
 
1787
- var currentTransform = currentCtx.mozCurrentTransform;
1815
+ const currentTransform = currentCtx.mozCurrentTransform;
1788
1816
 
1789
1817
  if (group.matrix) {
1790
1818
  currentCtx.transform.apply(currentCtx, group.matrix);
@@ -1794,15 +1822,15 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1794
1822
  throw new Error("Bounding box is required.");
1795
1823
  }
1796
1824
 
1797
- var bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
1825
+ let bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
1798
1826
 
1799
- var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
1827
+ const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
1800
1828
  bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
1801
- var offsetX = Math.floor(bounds[0]);
1802
- var offsetY = Math.floor(bounds[1]);
1803
- var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
1804
- var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
1805
- var scaleX = 1,
1829
+ const offsetX = Math.floor(bounds[0]);
1830
+ const offsetY = Math.floor(bounds[1]);
1831
+ let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
1832
+ let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
1833
+ let scaleX = 1,
1806
1834
  scaleY = 1;
1807
1835
 
1808
1836
  if (drawnWidth > MAX_GROUP_SIZE) {
@@ -1815,14 +1843,14 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1815
1843
  drawnHeight = MAX_GROUP_SIZE;
1816
1844
  }
1817
1845
 
1818
- var cacheId = "groupAt" + this.groupLevel;
1846
+ let cacheId = "groupAt" + this.groupLevel;
1819
1847
 
1820
1848
  if (group.smask) {
1821
1849
  cacheId += "_smask_" + this.smaskCounter++ % 2;
1822
1850
  }
1823
1851
 
1824
- var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
1825
- var groupCtx = scratchCanvas.context;
1852
+ const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
1853
+ const groupCtx = scratchCanvas.context;
1826
1854
  groupCtx.scale(1 / scaleX, 1 / scaleY);
1827
1855
  groupCtx.translate(-offsetX, -offsetY);
1828
1856
  groupCtx.transform.apply(groupCtx, currentTransform);
@@ -1859,7 +1887,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1859
1887
  }
1860
1888
 
1861
1889
  this.groupLevel--;
1862
- var groupCtx = this.ctx;
1890
+ const groupCtx = this.ctx;
1863
1891
  this.ctx = this.groupStack.pop();
1864
1892
 
1865
1893
  if (this.ctx.imageSmoothingEnabled !== undefined) {
@@ -1892,8 +1920,8 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1892
1920
  this.current = new CanvasExtraState();
1893
1921
 
1894
1922
  if (Array.isArray(rect) && rect.length === 4) {
1895
- var width = rect[2] - rect[0];
1896
- var height = rect[3] - rect[1];
1923
+ const width = rect[2] - rect[0];
1924
+ const height = rect[3] - rect[1];
1897
1925
  this.ctx.rect(rect[0], rect[1], width, height);
1898
1926
  this.clip();
1899
1927
  this.endPath();
@@ -1910,12 +1938,12 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1910
1938
  return;
1911
1939
  }
1912
1940
 
1913
- var ctx = this.ctx;
1914
- var width = img.width,
1915
- height = img.height;
1916
- var fillColor = this.current.fillColor;
1917
- var isPatternFill = this.current.patternFill;
1918
- var glyph = this.processingType3;
1941
+ const ctx = this.ctx;
1942
+ const width = img.width,
1943
+ height = img.height;
1944
+ const fillColor = this.current.fillColor;
1945
+ const isPatternFill = this.current.patternFill;
1946
+ const glyph = this.processingType3;
1919
1947
 
1920
1948
  if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
1921
1949
  if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
@@ -1929,13 +1957,13 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1929
1957
  }
1930
1958
  }
1931
1959
 
1932
- if (glyph && glyph.compiled) {
1960
+ if (glyph?.compiled) {
1933
1961
  glyph.compiled(ctx);
1934
1962
  return;
1935
1963
  }
1936
1964
 
1937
- var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
1938
- var maskCtx = maskCanvas.context;
1965
+ const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
1966
+ const maskCtx = maskCanvas.context;
1939
1967
  maskCtx.save();
1940
1968
  putBinaryImageMask(maskCtx, img);
1941
1969
  maskCtx.globalCompositeOperation = "source-in";
@@ -1950,21 +1978,21 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1950
1978
  return;
1951
1979
  }
1952
1980
 
1953
- var width = imgData.width;
1954
- var height = imgData.height;
1955
- var fillColor = this.current.fillColor;
1956
- var isPatternFill = this.current.patternFill;
1957
- var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
1958
- var maskCtx = maskCanvas.context;
1981
+ const width = imgData.width;
1982
+ const height = imgData.height;
1983
+ const fillColor = this.current.fillColor;
1984
+ const isPatternFill = this.current.patternFill;
1985
+ const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
1986
+ const maskCtx = maskCanvas.context;
1959
1987
  maskCtx.save();
1960
1988
  putBinaryImageMask(maskCtx, imgData);
1961
1989
  maskCtx.globalCompositeOperation = "source-in";
1962
1990
  maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
1963
1991
  maskCtx.fillRect(0, 0, width, height);
1964
1992
  maskCtx.restore();
1965
- var ctx = this.ctx;
1993
+ const ctx = this.ctx;
1966
1994
 
1967
- for (var i = 0, ii = positions.length; i < ii; i += 2) {
1995
+ for (let i = 0, ii = positions.length; i < ii; i += 2) {
1968
1996
  ctx.save();
1969
1997
  ctx.transform(scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]);
1970
1998
  ctx.scale(1, -1);
@@ -1978,16 +2006,16 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
1978
2006
  return;
1979
2007
  }
1980
2008
 
1981
- var ctx = this.ctx;
1982
- var fillColor = this.current.fillColor;
1983
- var isPatternFill = this.current.patternFill;
2009
+ const ctx = this.ctx;
2010
+ const fillColor = this.current.fillColor;
2011
+ const isPatternFill = this.current.patternFill;
1984
2012
 
1985
- for (var i = 0, ii = images.length; i < ii; i++) {
1986
- var image = images[i];
1987
- var width = image.width,
1988
- height = image.height;
1989
- var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
1990
- var maskCtx = maskCanvas.context;
2013
+ for (let i = 0, ii = images.length; i < ii; i++) {
2014
+ const image = images[i];
2015
+ const width = image.width,
2016
+ height = image.height;
2017
+ const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
2018
+ const maskCtx = maskCanvas.context;
1991
2019
  maskCtx.save();
1992
2020
  putBinaryImageMask(maskCtx, image);
1993
2021
  maskCtx.globalCompositeOperation = "source-in";
@@ -2027,11 +2055,11 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
2027
2055
  return;
2028
2056
  }
2029
2057
 
2030
- var width = imgData.width;
2031
- var height = imgData.height;
2032
- var map = [];
2058
+ const width = imgData.width;
2059
+ const height = imgData.height;
2060
+ const map = [];
2033
2061
 
2034
- for (var i = 0, ii = positions.length; i < ii; i += 2) {
2062
+ for (let i = 0, ii = positions.length; i < ii; i += 2) {
2035
2063
  map.push({
2036
2064
  transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
2037
2065
  x: 0,
@@ -2048,35 +2076,35 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
2048
2076
  return;
2049
2077
  }
2050
2078
 
2051
- var width = imgData.width;
2052
- var height = imgData.height;
2053
- var ctx = this.ctx;
2079
+ const width = imgData.width;
2080
+ const height = imgData.height;
2081
+ const ctx = this.ctx;
2054
2082
  this.save();
2055
2083
  ctx.scale(1 / width, -1 / height);
2056
- var currentTransform = ctx.mozCurrentTransformInverse;
2057
- var a = currentTransform[0],
2058
- b = currentTransform[1];
2059
- var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
2060
- var c = currentTransform[2],
2061
- d = currentTransform[3];
2062
- var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
2063
- var imgToPaint, tmpCanvas;
2084
+ const currentTransform = ctx.mozCurrentTransformInverse;
2085
+ const a = currentTransform[0],
2086
+ b = currentTransform[1];
2087
+ let widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
2088
+ const c = currentTransform[2],
2089
+ d = currentTransform[3];
2090
+ let heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
2091
+ let imgToPaint, tmpCanvas, tmpCtx;
2064
2092
 
2065
2093
  if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
2066
2094
  imgToPaint = imgData;
2067
2095
  } else {
2068
2096
  tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
2069
- var tmpCtx = tmpCanvas.context;
2097
+ tmpCtx = tmpCanvas.context;
2070
2098
  putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
2071
2099
  imgToPaint = tmpCanvas.canvas;
2072
2100
  }
2073
2101
 
2074
- var paintWidth = width,
2102
+ let paintWidth = width,
2075
2103
  paintHeight = height;
2076
- var tmpCanvasId = "prescale1";
2104
+ let tmpCanvasId = "prescale1";
2077
2105
 
2078
2106
  while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
2079
- var newWidth = paintWidth,
2107
+ let newWidth = paintWidth,
2080
2108
  newHeight = paintHeight;
2081
2109
 
2082
2110
  if (widthScale > 2 && paintWidth > 1) {
@@ -2102,7 +2130,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
2102
2130
  ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
2103
2131
 
2104
2132
  if (this.imageLayer) {
2105
- var position = this.getCanvasPosition(0, -height);
2133
+ const position = this.getCanvasPosition(0, -height);
2106
2134
  this.imageLayer.appendImage({
2107
2135
  imgData,
2108
2136
  left: position[0],
@@ -2119,22 +2147,22 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
2119
2147
  return;
2120
2148
  }
2121
2149
 
2122
- var ctx = this.ctx;
2123
- var w = imgData.width;
2124
- var h = imgData.height;
2125
- var tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
2126
- var tmpCtx = tmpCanvas.context;
2150
+ const ctx = this.ctx;
2151
+ const w = imgData.width;
2152
+ const h = imgData.height;
2153
+ const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
2154
+ const tmpCtx = tmpCanvas.context;
2127
2155
  putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
2128
2156
 
2129
- for (var i = 0, ii = map.length; i < ii; i++) {
2130
- var entry = map[i];
2157
+ for (let i = 0, ii = map.length; i < ii; i++) {
2158
+ const entry = map[i];
2131
2159
  ctx.save();
2132
2160
  ctx.transform.apply(ctx, entry.transform);
2133
2161
  ctx.scale(1, -1);
2134
2162
  ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
2135
2163
 
2136
2164
  if (this.imageLayer) {
2137
- var position = this.getCanvasPosition(entry.x, entry.y);
2165
+ const position = this.getCanvasPosition(entry.x, entry.y);
2138
2166
  this.imageLayer.appendImage({
2139
2167
  imgData,
2140
2168
  left: position[0],
@@ -2181,7 +2209,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
2181
2209
  beginCompat: function CanvasGraphics_beginCompat() {},
2182
2210
  endCompat: function CanvasGraphics_endCompat() {},
2183
2211
  consumePath: function CanvasGraphics_consumePath() {
2184
- var ctx = this.ctx;
2212
+ const ctx = this.ctx;
2185
2213
 
2186
2214
  if (this.pendingClip) {
2187
2215
  if (this.pendingClip === EO_CLIP) {
@@ -2196,17 +2224,28 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
2196
2224
  ctx.beginPath();
2197
2225
  },
2198
2226
 
2199
- getSinglePixelWidth(scale) {
2227
+ getSinglePixelWidth() {
2200
2228
  if (this._cachedGetSinglePixelWidth === null) {
2201
- const inverse = this.ctx.mozCurrentTransformInverse;
2202
- this._cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
2229
+ const m = this.ctx.mozCurrentTransform;
2230
+ const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
2231
+ const sqNorm1 = m[0] ** 2 + m[2] ** 2;
2232
+ const sqNorm2 = m[1] ** 2 + m[3] ** 2;
2233
+ const pixelHeight = Math.sqrt(Math.max(sqNorm1, sqNorm2)) / absDet;
2234
+
2235
+ if (sqNorm1 !== sqNorm2 && this._combinedScaleFactor * pixelHeight > 1) {
2236
+ this._cachedGetSinglePixelWidth = -(this._combinedScaleFactor * pixelHeight);
2237
+ } else if (absDet > Number.EPSILON) {
2238
+ this._cachedGetSinglePixelWidth = pixelHeight * 1.0000001;
2239
+ } else {
2240
+ this._cachedGetSinglePixelWidth = 1;
2241
+ }
2203
2242
  }
2204
2243
 
2205
2244
  return this._cachedGetSinglePixelWidth;
2206
2245
  },
2207
2246
 
2208
2247
  getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
2209
- var transform = this.ctx.mozCurrentTransform;
2248
+ const transform = this.ctx.mozCurrentTransform;
2210
2249
  return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
2211
2250
  },
2212
2251
  isContentVisible: function CanvasGraphics_isContentVisible() {
@@ -2220,7 +2259,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() {
2220
2259
  }
2221
2260
  };
2222
2261
 
2223
- for (var op in _util.OPS) {
2262
+ for (const op in _util.OPS) {
2224
2263
  CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
2225
2264
  }
2226
2265