pdfjs-dist 2.1.266 → 2.2.228

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (166) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +3349 -2324
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +2804 -1975
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/image_decoders/pdf.image_decoders.js +431 -511
  10. package/image_decoders/pdf.image_decoders.js.map +1 -1
  11. package/image_decoders/pdf.image_decoders.min.js +1 -1
  12. package/lib/core/annotation.js +294 -224
  13. package/lib/core/arithmetic_decoder.js +1 -1
  14. package/lib/core/bidi.js +1 -1
  15. package/lib/core/ccitt.js +1 -1
  16. package/lib/core/ccitt_stream.js +1 -1
  17. package/lib/core/cff_parser.js +61 -12
  18. package/lib/core/charsets.js +1 -1
  19. package/lib/core/chunked_stream.js +24 -14
  20. package/lib/core/cmap.js +17 -13
  21. package/lib/core/colorspace.js +1 -1
  22. package/lib/core/core_utils.js +147 -0
  23. package/lib/core/crypto.js +1 -1
  24. package/lib/core/document.js +47 -40
  25. package/lib/core/encodings.js +1 -1
  26. package/lib/core/evaluator.js +346 -279
  27. package/lib/core/font_renderer.js +1 -1
  28. package/lib/core/fonts.js +23 -11
  29. package/lib/core/function.js +1 -1
  30. package/lib/core/glyphlist.js +2 -2
  31. package/lib/core/image.js +2 -2
  32. package/lib/core/image_utils.js +111 -0
  33. package/lib/core/jbig2.js +1 -1
  34. package/lib/core/jbig2_stream.js +1 -1
  35. package/lib/core/jpeg_stream.js +1 -1
  36. package/lib/core/jpg.js +2 -1
  37. package/lib/core/jpx.js +1 -1
  38. package/lib/core/jpx_stream.js +1 -1
  39. package/lib/core/metrics.js +13 -13
  40. package/lib/core/murmurhash3.js +37 -33
  41. package/lib/core/obj.js +245 -41
  42. package/lib/core/operator_list.js +43 -32
  43. package/lib/core/parser.js +228 -133
  44. package/lib/core/pattern.js +4 -2
  45. package/lib/core/pdf_manager.js +17 -15
  46. package/lib/core/primitives.js +40 -6
  47. package/lib/core/ps_parser.js +1 -1
  48. package/lib/core/standard_fonts.js +9 -9
  49. package/lib/core/stream.js +1 -1
  50. package/lib/core/type1_parser.js +1 -1
  51. package/lib/core/unicode.js +2 -2
  52. package/lib/core/worker.js +54 -171
  53. package/lib/core/worker_stream.js +277 -0
  54. package/lib/display/annotation_layer.js +112 -33
  55. package/lib/display/api.js +211 -123
  56. package/lib/display/api_compatibility.js +1 -1
  57. package/lib/display/canvas.js +40 -19
  58. package/lib/display/content_disposition.js +1 -1
  59. package/lib/display/display_utils.js +747 -0
  60. package/lib/display/fetch_stream.js +19 -12
  61. package/lib/display/font_loader.js +11 -8
  62. package/lib/display/metadata.js +1 -1
  63. package/lib/display/network.js +563 -521
  64. package/lib/display/network_utils.js +1 -1
  65. package/lib/display/node_stream.js +21 -12
  66. package/lib/display/pattern_helper.js +24 -25
  67. package/lib/display/svg.js +1068 -565
  68. package/lib/display/text_layer.js +24 -14
  69. package/lib/display/transport_stream.js +192 -70
  70. package/lib/display/webgl.js +1 -1
  71. package/lib/display/worker_options.js +1 -1
  72. package/lib/display/xml_parser.js +1 -1
  73. package/lib/examples/node/domstubs.js +4 -1
  74. package/lib/pdf.js +20 -15
  75. package/lib/pdf.worker.js +3 -3
  76. package/lib/shared/compatibility.js +6 -6
  77. package/lib/shared/global_scope.js +1 -1
  78. package/lib/shared/is_node.js +2 -2
  79. package/lib/shared/message_handler.js +7 -7
  80. package/lib/shared/streams_polyfill.js +1 -1
  81. package/lib/shared/url_polyfill.js +1 -1
  82. package/lib/shared/util.js +13 -125
  83. package/lib/test/unit/annotation_spec.js +278 -93
  84. package/lib/test/unit/api_spec.js +198 -188
  85. package/lib/test/unit/bidi_spec.js +1 -1
  86. package/lib/test/unit/cff_parser_spec.js +15 -1
  87. package/lib/test/unit/clitests_helper.js +3 -3
  88. package/lib/test/unit/cmap_spec.js +20 -20
  89. package/lib/test/unit/colorspace_spec.js +17 -12
  90. package/lib/test/unit/core_utils_spec.js +191 -0
  91. package/lib/test/unit/crypto_spec.js +1 -1
  92. package/lib/test/unit/custom_spec.js +8 -8
  93. package/lib/test/unit/display_svg_spec.js +8 -8
  94. package/lib/test/unit/display_utils_spec.js +273 -0
  95. package/lib/test/unit/document_spec.js +7 -12
  96. package/lib/test/unit/encodings_spec.js +5 -5
  97. package/lib/test/unit/evaluator_spec.js +8 -10
  98. package/lib/test/unit/fetch_stream_spec.js +109 -0
  99. package/lib/test/unit/function_spec.js +1 -1
  100. package/lib/test/unit/jasmine-boot.js +4 -4
  101. package/lib/test/unit/message_handler_spec.js +1 -1
  102. package/lib/test/unit/metadata_spec.js +1 -1
  103. package/lib/test/unit/murmurhash3_spec.js +1 -1
  104. package/lib/test/unit/network_spec.js +5 -55
  105. package/lib/test/unit/network_utils_spec.js +51 -1
  106. package/lib/test/unit/node_stream_spec.js +8 -8
  107. package/lib/test/unit/parser_spec.js +150 -86
  108. package/lib/test/unit/pdf_find_controller_spec.js +1 -1
  109. package/lib/test/unit/pdf_find_utils_spec.js +1 -1
  110. package/lib/test/unit/pdf_history_spec.js +1 -1
  111. package/lib/test/unit/primitives_spec.js +30 -17
  112. package/lib/test/unit/stream_spec.js +1 -1
  113. package/lib/test/unit/test_utils.js +197 -43
  114. package/lib/test/unit/testreporter.js +1 -1
  115. package/lib/test/unit/type1_parser_spec.js +1 -1
  116. package/lib/test/unit/ui_utils_spec.js +20 -20
  117. package/lib/test/unit/unicode_spec.js +5 -5
  118. package/lib/test/unit/util_spec.js +1 -164
  119. package/lib/web/annotation_layer_builder.js +1 -1
  120. package/lib/web/app.js +104 -60
  121. package/lib/web/app_options.js +45 -37
  122. package/lib/web/base_viewer.js +7 -7
  123. package/lib/web/chromecom.js +8 -8
  124. package/lib/web/debugger.js +7 -7
  125. package/lib/web/download_manager.js +3 -2
  126. package/lib/web/firefox_print_service.js +4 -2
  127. package/lib/web/firefoxcom.js +50 -19
  128. package/lib/web/genericcom.js +8 -8
  129. package/lib/web/genericl10n.js +10 -10
  130. package/lib/web/grab_to_pan.js +3 -1
  131. package/lib/web/interfaces.js +13 -13
  132. package/lib/web/overlay_manager.js +10 -10
  133. package/lib/web/password_prompt.js +2 -2
  134. package/lib/web/pdf_attachment_viewer.js +1 -1
  135. package/lib/web/pdf_cursor_tools.js +1 -1
  136. package/lib/web/pdf_document_properties.js +188 -119
  137. package/lib/web/pdf_find_bar.js +1 -1
  138. package/lib/web/pdf_find_controller.js +3 -3
  139. package/lib/web/pdf_find_utils.js +1 -1
  140. package/lib/web/pdf_history.js +1 -1
  141. package/lib/web/pdf_link_service.js +2 -2
  142. package/lib/web/pdf_outline_viewer.js +53 -28
  143. package/lib/web/pdf_page_view.js +9 -18
  144. package/lib/web/pdf_presentation_mode.js +1 -1
  145. package/lib/web/pdf_print_service.js +5 -3
  146. package/lib/web/pdf_rendering_queue.js +4 -7
  147. package/lib/web/pdf_sidebar.js +24 -17
  148. package/lib/web/pdf_sidebar_resizer.js +1 -1
  149. package/lib/web/pdf_single_page_viewer.js +1 -1
  150. package/lib/web/pdf_thumbnail_view.js +2 -2
  151. package/lib/web/pdf_thumbnail_viewer.js +3 -3
  152. package/lib/web/pdf_viewer.component.js +3 -3
  153. package/lib/web/pdf_viewer.js +3 -3
  154. package/lib/web/preferences.js +30 -30
  155. package/lib/web/secondary_toolbar.js +1 -1
  156. package/lib/web/text_layer_builder.js +23 -45
  157. package/lib/web/toolbar.js +1 -1
  158. package/lib/web/ui_utils.js +14 -14
  159. package/lib/web/view_history.js +15 -15
  160. package/lib/web/viewer_compatibility.js +1 -1
  161. package/package.json +1 -1
  162. package/web/pdf_viewer.css +21 -10
  163. package/web/pdf_viewer.js +126 -194
  164. package/web/pdf_viewer.js.map +1 -1
  165. package/lib/display/dom_utils.js +0 -494
  166. package/lib/test/unit/dom_utils_spec.js +0 -89
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2018 Mozilla Foundation
5
+ * Copyright 2019 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -28,11 +28,33 @@ exports.SVGGraphics = void 0;
28
28
 
29
29
  var _util = require("../shared/util");
30
30
 
31
- var _dom_utils = require("./dom_utils");
31
+ var _display_utils = require("./display_utils");
32
32
 
33
33
  var _is_node = _interopRequireDefault(require("../shared/is_node"));
34
34
 
35
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
36
+
37
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
38
+
39
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
40
+
41
+ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
42
+
43
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
44
+
45
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
46
+
47
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
48
+
49
+ function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
50
+
51
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
52
+
53
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
54
+
55
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
56
+
57
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
36
58
 
37
59
  var SVGGraphics = function SVGGraphics() {
38
60
  throw new Error('Not implemented: SVGGraphics');
@@ -40,13 +62,105 @@ var SVGGraphics = function SVGGraphics() {
40
62
 
41
63
  exports.SVGGraphics = SVGGraphics;
42
64
  {
65
+ var opListToTree = function opListToTree(opList) {
66
+ var opTree = [];
67
+ var tmp = [];
68
+ var _iteratorNormalCompletion = true;
69
+ var _didIteratorError = false;
70
+ var _iteratorError = undefined;
71
+
72
+ try {
73
+ for (var _iterator = opList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
74
+ var opListElement = _step.value;
75
+
76
+ if (opListElement.fn === 'save') {
77
+ opTree.push({
78
+ 'fnId': 92,
79
+ 'fn': 'group',
80
+ 'items': []
81
+ });
82
+ tmp.push(opTree);
83
+ opTree = opTree[opTree.length - 1].items;
84
+ continue;
85
+ }
86
+
87
+ if (opListElement.fn === 'restore') {
88
+ opTree = tmp.pop();
89
+ } else {
90
+ opTree.push(opListElement);
91
+ }
92
+ }
93
+ } catch (err) {
94
+ _didIteratorError = true;
95
+ _iteratorError = err;
96
+ } finally {
97
+ try {
98
+ if (!_iteratorNormalCompletion && _iterator["return"] != null) {
99
+ _iterator["return"]();
100
+ }
101
+ } finally {
102
+ if (_didIteratorError) {
103
+ throw _iteratorError;
104
+ }
105
+ }
106
+ }
107
+
108
+ return opTree;
109
+ };
110
+
111
+ var pf = function pf(value) {
112
+ if (Number.isInteger(value)) {
113
+ return value.toString();
114
+ }
115
+
116
+ var s = value.toFixed(10);
117
+ var i = s.length - 1;
118
+
119
+ if (s[i] !== '0') {
120
+ return s;
121
+ }
122
+
123
+ do {
124
+ i--;
125
+ } while (s[i] === '0');
126
+
127
+ return s.substring(0, s[i] === '.' ? i : i + 1);
128
+ };
129
+
130
+ var pm = function pm(m) {
131
+ if (m[4] === 0 && m[5] === 0) {
132
+ if (m[1] === 0 && m[2] === 0) {
133
+ if (m[0] === 1 && m[3] === 1) {
134
+ return '';
135
+ }
136
+
137
+ return "scale(".concat(pf(m[0]), " ").concat(pf(m[3]), ")");
138
+ }
139
+
140
+ if (m[0] === m[3] && m[1] === -m[2]) {
141
+ var a = Math.acos(m[0]) * 180 / Math.PI;
142
+ return "rotate(".concat(pf(a), ")");
143
+ }
144
+ } else {
145
+ if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
146
+ return "translate(".concat(pf(m[4]), " ").concat(pf(m[5]), ")");
147
+ }
148
+ }
149
+
150
+ return "matrix(".concat(pf(m[0]), " ").concat(pf(m[1]), " ").concat(pf(m[2]), " ").concat(pf(m[3]), " ").concat(pf(m[4]), " ") + "".concat(pf(m[5]), ")");
151
+ };
152
+
43
153
  var SVG_DEFAULTS = {
44
154
  fontStyle: 'normal',
45
155
  fontWeight: 'normal',
46
156
  fillColor: '#000000'
47
157
  };
158
+ var XML_NS = 'http://www.w3.org/XML/1998/namespace';
159
+ var XLINK_NS = 'http://www.w3.org/1999/xlink';
160
+ var LINE_CAP_STYLES = ['butt', 'round', 'square'];
161
+ var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
48
162
 
49
- var convertImgDataToPng = function convertImgDataToPngClosure() {
163
+ var convertImgDataToPng = function () {
50
164
  var PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
51
165
  var CHUNK_WRAPPER_SIZE = 12;
52
166
  var crcTable = new Int32Array(256);
@@ -68,8 +182,8 @@ exports.SVGGraphics = SVGGraphics;
68
182
  function crc32(data, start, end) {
69
183
  var crc = -1;
70
184
 
71
- for (var i = start; i < end; i++) {
72
- var a = (crc ^ data[i]) & 0xff;
185
+ for (var _i = start; _i < end; _i++) {
186
+ var a = (crc ^ data[_i]) & 0xff;
73
187
  var b = crcTable[a];
74
188
  crc = crc >>> 8 ^ b;
75
189
  }
@@ -103,8 +217,8 @@ exports.SVGGraphics = SVGGraphics;
103
217
  var a = 1;
104
218
  var b = 0;
105
219
 
106
- for (var i = start; i < end; ++i) {
107
- a = (a + (data[i] & 0xff)) % 65521;
220
+ for (var _i2 = start; _i2 < end; ++_i2) {
221
+ a = (a + (data[_i2] & 0xff)) % 65521;
108
222
  b = (b + a) % 65521;
109
223
  }
110
224
 
@@ -112,7 +226,7 @@ exports.SVGGraphics = SVGGraphics;
112
226
  }
113
227
 
114
228
  function deflateSync(literals) {
115
- if (!(0, _is_node.default)()) {
229
+ if (!(0, _is_node["default"])()) {
116
230
  return deflateSyncUncompressed(literals);
117
231
  }
118
232
 
@@ -206,9 +320,8 @@ exports.SVGGraphics = SVGGraphics;
206
320
  var literals = new Uint8Array((1 + lineSize) * height);
207
321
  var offsetLiterals = 0,
208
322
  offsetBytes = 0;
209
- var y, i;
210
323
 
211
- for (y = 0; y < height; ++y) {
324
+ for (var y = 0; y < height; ++y) {
212
325
  literals[offsetLiterals++] = 0;
213
326
  literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
214
327
  offsetBytes += lineSize;
@@ -218,10 +331,10 @@ exports.SVGGraphics = SVGGraphics;
218
331
  if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
219
332
  offsetLiterals = 0;
220
333
 
221
- for (y = 0; y < height; y++) {
334
+ for (var _y = 0; _y < height; _y++) {
222
335
  offsetLiterals++;
223
336
 
224
- for (i = 0; i < lineSize; i++) {
337
+ for (var _i3 = 0; _i3 < lineSize; _i3++) {
225
338
  literals[offsetLiterals++] ^= 0xFF;
226
339
  }
227
340
  }
@@ -248,8 +361,12 @@ exports.SVGGraphics = SVGGraphics;
248
361
  };
249
362
  }();
250
363
 
251
- var SVGExtraState = function SVGExtraStateClosure() {
364
+ var SVGExtraState =
365
+ /*#__PURE__*/
366
+ function () {
252
367
  function SVGExtraState() {
368
+ _classCallCheck(this, SVGExtraState);
369
+
253
370
  this.fontSizeScale = 1;
254
371
  this.fontWeight = SVG_DEFAULTS.fontWeight;
255
372
  this.fontSize = 0;
@@ -257,6 +374,7 @@ exports.SVGGraphics = SVGGraphics;
257
374
  this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
258
375
  this.leading = 0;
259
376
  this.textRenderingMode = _util.TextRenderingMode.FILL;
377
+ this.textMatrixScale = 1;
260
378
  this.x = 0;
261
379
  this.y = 0;
262
380
  this.lineX = 0;
@@ -281,90 +399,33 @@ exports.SVGGraphics = SVGGraphics;
281
399
  this.maskId = '';
282
400
  }
283
401
 
284
- SVGExtraState.prototype = {
285
- clone: function SVGExtraState_clone() {
402
+ _createClass(SVGExtraState, [{
403
+ key: "clone",
404
+ value: function clone() {
286
405
  return Object.create(this);
287
- },
288
- setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
406
+ }
407
+ }, {
408
+ key: "setCurrentPoint",
409
+ value: function setCurrentPoint(x, y) {
289
410
  this.x = x;
290
411
  this.y = y;
291
412
  }
292
- };
413
+ }]);
414
+
293
415
  return SVGExtraState;
294
416
  }();
295
417
 
296
- exports.SVGGraphics = SVGGraphics = function SVGGraphicsClosure() {
297
- function opListToTree(opList) {
298
- var opTree = [];
299
- var tmp = [];
300
- var opListLen = opList.length;
301
-
302
- for (var x = 0; x < opListLen; x++) {
303
- if (opList[x].fn === 'save') {
304
- opTree.push({
305
- 'fnId': 92,
306
- 'fn': 'group',
307
- 'items': []
308
- });
309
- tmp.push(opTree);
310
- opTree = opTree[opTree.length - 1].items;
311
- continue;
312
- }
313
-
314
- if (opList[x].fn === 'restore') {
315
- opTree = tmp.pop();
316
- } else {
317
- opTree.push(opList[x]);
318
- }
319
- }
320
-
321
- return opTree;
322
- }
323
-
324
- function pf(value) {
325
- if (Number.isInteger(value)) {
326
- return value.toString();
327
- }
328
-
329
- var s = value.toFixed(10);
330
- var i = s.length - 1;
331
-
332
- if (s[i] !== '0') {
333
- return s;
334
- }
335
-
336
- do {
337
- i--;
338
- } while (s[i] === '0');
339
-
340
- return s.substring(0, s[i] === '.' ? i : i + 1);
341
- }
342
-
343
- function pm(m) {
344
- if (m[4] === 0 && m[5] === 0) {
345
- if (m[1] === 0 && m[2] === 0) {
346
- if (m[0] === 1 && m[3] === 1) {
347
- return '';
348
- }
349
-
350
- return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
351
- }
352
-
353
- if (m[0] === m[3] && m[1] === -m[2]) {
354
- var a = Math.acos(m[0]) * 180 / Math.PI;
355
- return 'rotate(' + pf(a) + ')';
356
- }
357
- } else {
358
- if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
359
- return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
360
- }
361
- }
362
-
363
- return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' + pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
364
- }
418
+ var clipCount = 0;
419
+ var maskCount = 0;
420
+ var shadingCount = 0;
365
421
 
422
+ exports.SVGGraphics = SVGGraphics =
423
+ /*#__PURE__*/
424
+ function () {
366
425
  function SVGGraphics(commonObjs, objs, forceDataSchema) {
367
- this.svgFactory = new _dom_utils.DOMSVGFactory();
426
+ _classCallCheck(this, SVGGraphics);
427
+
428
+ this.svgFactory = new _display_utils.DOMSVGFactory();
368
429
  this.current = new SVGExtraState();
369
430
  this.transformMatrix = _util.IDENTITY_MATRIX;
370
431
  this.transformStack = [];
@@ -377,71 +438,95 @@ exports.SVGGraphics = SVGGraphics;
377
438
  this.embeddedFonts = Object.create(null);
378
439
  this.cssStyle = null;
379
440
  this.forceDataSchema = !!forceDataSchema;
441
+ this._operatorIdMapping = [];
442
+
443
+ for (var op in _util.OPS) {
444
+ this._operatorIdMapping[_util.OPS[op]] = op;
445
+ }
380
446
  }
381
447
 
382
- var XML_NS = 'http://www.w3.org/XML/1998/namespace';
383
- var XLINK_NS = 'http://www.w3.org/1999/xlink';
384
- var LINE_CAP_STYLES = ['butt', 'round', 'square'];
385
- var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
386
- var clipCount = 0;
387
- var maskCount = 0;
388
- SVGGraphics.prototype = {
389
- save: function SVGGraphics_save() {
448
+ _createClass(SVGGraphics, [{
449
+ key: "save",
450
+ value: function save() {
390
451
  this.transformStack.push(this.transformMatrix);
391
452
  var old = this.current;
392
453
  this.extraStack.push(old);
393
454
  this.current = old.clone();
394
- },
395
- restore: function SVGGraphics_restore() {
455
+ }
456
+ }, {
457
+ key: "restore",
458
+ value: function restore() {
396
459
  this.transformMatrix = this.transformStack.pop();
397
460
  this.current = this.extraStack.pop();
398
461
  this.pendingClip = null;
399
462
  this.tgrp = null;
400
- },
401
- group: function SVGGraphics_group(items) {
463
+ }
464
+ }, {
465
+ key: "group",
466
+ value: function group(items) {
402
467
  this.save();
403
468
  this.executeOpTree(items);
404
469
  this.restore();
405
- },
406
- loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
470
+ }
471
+ }, {
472
+ key: "loadDependencies",
473
+ value: function loadDependencies(operatorList) {
407
474
  var _this = this;
408
475
 
409
476
  var fnArray = operatorList.fnArray;
410
- var fnArrayLen = fnArray.length;
411
477
  var argsArray = operatorList.argsArray;
412
478
 
413
- for (var i = 0; i < fnArrayLen; i++) {
414
- if (_util.OPS.dependency === fnArray[i]) {
415
- var deps = argsArray[i];
416
-
417
- for (var n = 0, nn = deps.length; n < nn; n++) {
418
- var obj = deps[n];
419
- var common = obj.substring(0, 2) === 'g_';
420
- var promise;
421
-
422
- if (common) {
423
- promise = new Promise(function (resolve) {
424
- _this.commonObjs.get(obj, resolve);
425
- });
426
- } else {
427
- promise = new Promise(function (resolve) {
428
- _this.objs.get(obj, resolve);
429
- });
430
- }
479
+ for (var i = 0, ii = fnArray.length; i < ii; i++) {
480
+ if (fnArray[i] !== _util.OPS.dependency) {
481
+ continue;
482
+ }
483
+
484
+ var _iteratorNormalCompletion2 = true;
485
+ var _didIteratorError2 = false;
486
+ var _iteratorError2 = undefined;
431
487
 
432
- this.current.dependencies.push(promise);
488
+ try {
489
+ var _loop = function _loop() {
490
+ var obj = _step2.value;
491
+ var objsPool = obj.startsWith('g_') ? _this.commonObjs : _this.objs;
492
+ var promise = new Promise(function (resolve) {
493
+ objsPool.get(obj, resolve);
494
+ });
495
+
496
+ _this.current.dependencies.push(promise);
497
+ };
498
+
499
+ for (var _iterator2 = argsArray[i][Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
500
+ _loop();
501
+ }
502
+ } catch (err) {
503
+ _didIteratorError2 = true;
504
+ _iteratorError2 = err;
505
+ } finally {
506
+ try {
507
+ if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
508
+ _iterator2["return"]();
509
+ }
510
+ } finally {
511
+ if (_didIteratorError2) {
512
+ throw _iteratorError2;
513
+ }
433
514
  }
434
515
  }
435
516
  }
436
517
 
437
518
  return Promise.all(this.current.dependencies);
438
- },
439
- transform: function SVGGraphics_transform(a, b, c, d, e, f) {
519
+ }
520
+ }, {
521
+ key: "transform",
522
+ value: function transform(a, b, c, d, e, f) {
440
523
  var transformMatrix = [a, b, c, d, e, f];
441
524
  this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
442
525
  this.tgrp = null;
443
- },
444
- getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
526
+ }
527
+ }, {
528
+ key: "getSVG",
529
+ value: function getSVG(operatorList, viewport) {
445
530
  var _this2 = this;
446
531
 
447
532
  this.viewport = viewport;
@@ -451,276 +536,328 @@ exports.SVGGraphics = SVGGraphics;
451
536
  return this.loadDependencies(operatorList).then(function () {
452
537
  _this2.transformMatrix = _util.IDENTITY_MATRIX;
453
538
 
454
- var opTree = _this2.convertOpList(operatorList);
455
-
456
- _this2.executeOpTree(opTree);
539
+ _this2.executeOpTree(_this2.convertOpList(operatorList));
457
540
 
458
541
  return svgElement;
459
542
  });
460
- },
461
- convertOpList: function SVGGraphics_convertOpList(operatorList) {
543
+ }
544
+ }, {
545
+ key: "convertOpList",
546
+ value: function convertOpList(operatorList) {
547
+ var operatorIdMapping = this._operatorIdMapping;
462
548
  var argsArray = operatorList.argsArray;
463
549
  var fnArray = operatorList.fnArray;
464
- var fnArrayLen = fnArray.length;
465
- var REVOPS = [];
466
550
  var opList = [];
467
551
 
468
- for (var op in _util.OPS) {
469
- REVOPS[_util.OPS[op]] = op;
470
- }
471
-
472
- for (var x = 0; x < fnArrayLen; x++) {
473
- var fnId = fnArray[x];
552
+ for (var i = 0, ii = fnArray.length; i < ii; i++) {
553
+ var fnId = fnArray[i];
474
554
  opList.push({
475
555
  'fnId': fnId,
476
- 'fn': REVOPS[fnId],
477
- 'args': argsArray[x]
556
+ 'fn': operatorIdMapping[fnId],
557
+ 'args': argsArray[i]
478
558
  });
479
559
  }
480
560
 
481
561
  return opListToTree(opList);
482
- },
483
- executeOpTree: function SVGGraphics_executeOpTree(opTree) {
484
- var opTreeLen = opTree.length;
485
-
486
- for (var x = 0; x < opTreeLen; x++) {
487
- var fn = opTree[x].fn;
488
- var fnId = opTree[x].fnId;
489
- var args = opTree[x].args;
490
-
491
- switch (fnId | 0) {
492
- case _util.OPS.beginText:
493
- this.beginText();
494
- break;
495
-
496
- case _util.OPS.dependency:
497
- break;
498
-
499
- case _util.OPS.setLeading:
500
- this.setLeading(args);
501
- break;
502
-
503
- case _util.OPS.setLeadingMoveText:
504
- this.setLeadingMoveText(args[0], args[1]);
505
- break;
506
-
507
- case _util.OPS.setFont:
508
- this.setFont(args);
509
- break;
510
-
511
- case _util.OPS.showText:
512
- this.showText(args[0]);
513
- break;
514
-
515
- case _util.OPS.showSpacedText:
516
- this.showText(args[0]);
517
- break;
518
-
519
- case _util.OPS.endText:
520
- this.endText();
521
- break;
522
-
523
- case _util.OPS.moveText:
524
- this.moveText(args[0], args[1]);
525
- break;
526
-
527
- case _util.OPS.setCharSpacing:
528
- this.setCharSpacing(args[0]);
529
- break;
530
-
531
- case _util.OPS.setWordSpacing:
532
- this.setWordSpacing(args[0]);
533
- break;
534
-
535
- case _util.OPS.setHScale:
536
- this.setHScale(args[0]);
537
- break;
538
-
539
- case _util.OPS.setTextMatrix:
540
- this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
541
- break;
542
-
543
- case _util.OPS.setTextRise:
544
- this.setTextRise(args[0]);
545
- break;
546
-
547
- case _util.OPS.setTextRenderingMode:
548
- this.setTextRenderingMode(args[0]);
549
- break;
562
+ }
563
+ }, {
564
+ key: "executeOpTree",
565
+ value: function executeOpTree(opTree) {
566
+ var _iteratorNormalCompletion3 = true;
567
+ var _didIteratorError3 = false;
568
+ var _iteratorError3 = undefined;
569
+
570
+ try {
571
+ for (var _iterator3 = opTree[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
572
+ var opTreeElement = _step3.value;
573
+ var fn = opTreeElement.fn;
574
+ var fnId = opTreeElement.fnId;
575
+ var args = opTreeElement.args;
576
+
577
+ switch (fnId | 0) {
578
+ case _util.OPS.beginText:
579
+ this.beginText();
580
+ break;
581
+
582
+ case _util.OPS.dependency:
583
+ break;
584
+
585
+ case _util.OPS.setLeading:
586
+ this.setLeading(args);
587
+ break;
588
+
589
+ case _util.OPS.setLeadingMoveText:
590
+ this.setLeadingMoveText(args[0], args[1]);
591
+ break;
592
+
593
+ case _util.OPS.setFont:
594
+ this.setFont(args);
595
+ break;
596
+
597
+ case _util.OPS.showText:
598
+ this.showText(args[0]);
599
+ break;
600
+
601
+ case _util.OPS.showSpacedText:
602
+ this.showText(args[0]);
603
+ break;
604
+
605
+ case _util.OPS.endText:
606
+ this.endText();
607
+ break;
608
+
609
+ case _util.OPS.moveText:
610
+ this.moveText(args[0], args[1]);
611
+ break;
612
+
613
+ case _util.OPS.setCharSpacing:
614
+ this.setCharSpacing(args[0]);
615
+ break;
616
+
617
+ case _util.OPS.setWordSpacing:
618
+ this.setWordSpacing(args[0]);
619
+ break;
620
+
621
+ case _util.OPS.setHScale:
622
+ this.setHScale(args[0]);
623
+ break;
624
+
625
+ case _util.OPS.setTextMatrix:
626
+ this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
627
+ break;
628
+
629
+ case _util.OPS.setTextRise:
630
+ this.setTextRise(args[0]);
631
+ break;
632
+
633
+ case _util.OPS.setTextRenderingMode:
634
+ this.setTextRenderingMode(args[0]);
635
+ break;
636
+
637
+ case _util.OPS.setLineWidth:
638
+ this.setLineWidth(args[0]);
639
+ break;
640
+
641
+ case _util.OPS.setLineJoin:
642
+ this.setLineJoin(args[0]);
643
+ break;
644
+
645
+ case _util.OPS.setLineCap:
646
+ this.setLineCap(args[0]);
647
+ break;
648
+
649
+ case _util.OPS.setMiterLimit:
650
+ this.setMiterLimit(args[0]);
651
+ break;
652
+
653
+ case _util.OPS.setFillRGBColor:
654
+ this.setFillRGBColor(args[0], args[1], args[2]);
655
+ break;
656
+
657
+ case _util.OPS.setStrokeRGBColor:
658
+ this.setStrokeRGBColor(args[0], args[1], args[2]);
659
+ break;
660
+
661
+ case _util.OPS.setStrokeColorN:
662
+ this.setStrokeColorN(args);
663
+ break;
664
+
665
+ case _util.OPS.setFillColorN:
666
+ this.setFillColorN(args);
667
+ break;
550
668
 
551
- case _util.OPS.setLineWidth:
552
- this.setLineWidth(args[0]);
553
- break;
669
+ case _util.OPS.shadingFill:
670
+ this.shadingFill(args[0]);
671
+ break;
554
672
 
555
- case _util.OPS.setLineJoin:
556
- this.setLineJoin(args[0]);
557
- break;
673
+ case _util.OPS.setDash:
674
+ this.setDash(args[0], args[1]);
675
+ break;
558
676
 
559
- case _util.OPS.setLineCap:
560
- this.setLineCap(args[0]);
561
- break;
677
+ case _util.OPS.setRenderingIntent:
678
+ this.setRenderingIntent(args[0]);
679
+ break;
562
680
 
563
- case _util.OPS.setMiterLimit:
564
- this.setMiterLimit(args[0]);
565
- break;
681
+ case _util.OPS.setFlatness:
682
+ this.setFlatness(args[0]);
683
+ break;
566
684
 
567
- case _util.OPS.setFillRGBColor:
568
- this.setFillRGBColor(args[0], args[1], args[2]);
569
- break;
685
+ case _util.OPS.setGState:
686
+ this.setGState(args[0]);
687
+ break;
570
688
 
571
- case _util.OPS.setStrokeRGBColor:
572
- this.setStrokeRGBColor(args[0], args[1], args[2]);
573
- break;
689
+ case _util.OPS.fill:
690
+ this.fill();
691
+ break;
574
692
 
575
- case _util.OPS.setDash:
576
- this.setDash(args[0], args[1]);
577
- break;
578
-
579
- case _util.OPS.setGState:
580
- this.setGState(args[0]);
581
- break;
582
-
583
- case _util.OPS.fill:
584
- this.fill();
585
- break;
586
-
587
- case _util.OPS.eoFill:
588
- this.eoFill();
589
- break;
693
+ case _util.OPS.eoFill:
694
+ this.eoFill();
695
+ break;
590
696
 
591
- case _util.OPS.stroke:
592
- this.stroke();
593
- break;
697
+ case _util.OPS.stroke:
698
+ this.stroke();
699
+ break;
594
700
 
595
- case _util.OPS.fillStroke:
596
- this.fillStroke();
597
- break;
701
+ case _util.OPS.fillStroke:
702
+ this.fillStroke();
703
+ break;
598
704
 
599
- case _util.OPS.eoFillStroke:
600
- this.eoFillStroke();
601
- break;
705
+ case _util.OPS.eoFillStroke:
706
+ this.eoFillStroke();
707
+ break;
602
708
 
603
- case _util.OPS.clip:
604
- this.clip('nonzero');
605
- break;
709
+ case _util.OPS.clip:
710
+ this.clip('nonzero');
711
+ break;
606
712
 
607
- case _util.OPS.eoClip:
608
- this.clip('evenodd');
609
- break;
713
+ case _util.OPS.eoClip:
714
+ this.clip('evenodd');
715
+ break;
610
716
 
611
- case _util.OPS.paintSolidColorImageMask:
612
- this.paintSolidColorImageMask();
613
- break;
717
+ case _util.OPS.paintSolidColorImageMask:
718
+ this.paintSolidColorImageMask();
719
+ break;
614
720
 
615
- case _util.OPS.paintJpegXObject:
616
- this.paintJpegXObject(args[0], args[1], args[2]);
617
- break;
721
+ case _util.OPS.paintJpegXObject:
722
+ this.paintJpegXObject(args[0], args[1], args[2]);
723
+ break;
618
724
 
619
- case _util.OPS.paintImageXObject:
620
- this.paintImageXObject(args[0]);
621
- break;
725
+ case _util.OPS.paintImageXObject:
726
+ this.paintImageXObject(args[0]);
727
+ break;
622
728
 
623
- case _util.OPS.paintInlineImageXObject:
624
- this.paintInlineImageXObject(args[0]);
625
- break;
729
+ case _util.OPS.paintInlineImageXObject:
730
+ this.paintInlineImageXObject(args[0]);
731
+ break;
626
732
 
627
- case _util.OPS.paintImageMaskXObject:
628
- this.paintImageMaskXObject(args[0]);
629
- break;
733
+ case _util.OPS.paintImageMaskXObject:
734
+ this.paintImageMaskXObject(args[0]);
735
+ break;
630
736
 
631
- case _util.OPS.paintFormXObjectBegin:
632
- this.paintFormXObjectBegin(args[0], args[1]);
633
- break;
737
+ case _util.OPS.paintFormXObjectBegin:
738
+ this.paintFormXObjectBegin(args[0], args[1]);
739
+ break;
634
740
 
635
- case _util.OPS.paintFormXObjectEnd:
636
- this.paintFormXObjectEnd();
637
- break;
741
+ case _util.OPS.paintFormXObjectEnd:
742
+ this.paintFormXObjectEnd();
743
+ break;
638
744
 
639
- case _util.OPS.closePath:
640
- this.closePath();
641
- break;
745
+ case _util.OPS.closePath:
746
+ this.closePath();
747
+ break;
642
748
 
643
- case _util.OPS.closeStroke:
644
- this.closeStroke();
645
- break;
749
+ case _util.OPS.closeStroke:
750
+ this.closeStroke();
751
+ break;
646
752
 
647
- case _util.OPS.closeFillStroke:
648
- this.closeFillStroke();
649
- break;
753
+ case _util.OPS.closeFillStroke:
754
+ this.closeFillStroke();
755
+ break;
650
756
 
651
- case _util.OPS.closeEOFillStroke:
652
- this.closeEOFillStroke();
653
- break;
757
+ case _util.OPS.closeEOFillStroke:
758
+ this.closeEOFillStroke();
759
+ break;
654
760
 
655
- case _util.OPS.nextLine:
656
- this.nextLine();
657
- break;
761
+ case _util.OPS.nextLine:
762
+ this.nextLine();
763
+ break;
658
764
 
659
- case _util.OPS.transform:
660
- this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
661
- break;
765
+ case _util.OPS.transform:
766
+ this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
767
+ break;
662
768
 
663
- case _util.OPS.constructPath:
664
- this.constructPath(args[0], args[1]);
665
- break;
769
+ case _util.OPS.constructPath:
770
+ this.constructPath(args[0], args[1]);
771
+ break;
666
772
 
667
- case _util.OPS.endPath:
668
- this.endPath();
669
- break;
773
+ case _util.OPS.endPath:
774
+ this.endPath();
775
+ break;
670
776
 
671
- case 92:
672
- this.group(opTree[x].items);
673
- break;
777
+ case 92:
778
+ this.group(opTreeElement.items);
779
+ break;
674
780
 
675
- default:
676
- (0, _util.warn)('Unimplemented operator ' + fn);
677
- break;
781
+ default:
782
+ (0, _util.warn)("Unimplemented operator ".concat(fn));
783
+ break;
784
+ }
785
+ }
786
+ } catch (err) {
787
+ _didIteratorError3 = true;
788
+ _iteratorError3 = err;
789
+ } finally {
790
+ try {
791
+ if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
792
+ _iterator3["return"]();
793
+ }
794
+ } finally {
795
+ if (_didIteratorError3) {
796
+ throw _iteratorError3;
797
+ }
678
798
  }
679
799
  }
680
- },
681
- setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
800
+ }
801
+ }, {
802
+ key: "setWordSpacing",
803
+ value: function setWordSpacing(wordSpacing) {
682
804
  this.current.wordSpacing = wordSpacing;
683
- },
684
- setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
805
+ }
806
+ }, {
807
+ key: "setCharSpacing",
808
+ value: function setCharSpacing(charSpacing) {
685
809
  this.current.charSpacing = charSpacing;
686
- },
687
- nextLine: function SVGGraphics_nextLine() {
810
+ }
811
+ }, {
812
+ key: "nextLine",
813
+ value: function nextLine() {
688
814
  this.moveText(0, this.current.leading);
689
- },
690
- setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
815
+ }
816
+ }, {
817
+ key: "setTextMatrix",
818
+ value: function setTextMatrix(a, b, c, d, e, f) {
691
819
  var current = this.current;
692
- this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
693
- this.current.x = this.current.lineX = 0;
694
- this.current.y = this.current.lineY = 0;
820
+ current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
821
+ current.textMatrixScale = Math.sqrt(a * a + b * b);
822
+ current.x = current.lineX = 0;
823
+ current.y = current.lineY = 0;
695
824
  current.xcoords = [];
696
825
  current.tspan = this.svgFactory.createElement('svg:tspan');
697
826
  current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
698
- current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
827
+ current.tspan.setAttributeNS(null, 'font-size', "".concat(pf(current.fontSize), "px"));
699
828
  current.tspan.setAttributeNS(null, 'y', pf(-current.y));
700
829
  current.txtElement = this.svgFactory.createElement('svg:text');
701
830
  current.txtElement.appendChild(current.tspan);
702
- },
703
- beginText: function SVGGraphics_beginText() {
704
- this.current.x = this.current.lineX = 0;
705
- this.current.y = this.current.lineY = 0;
706
- this.current.textMatrix = _util.IDENTITY_MATRIX;
707
- this.current.lineMatrix = _util.IDENTITY_MATRIX;
708
- this.current.tspan = this.svgFactory.createElement('svg:tspan');
709
- this.current.txtElement = this.svgFactory.createElement('svg:text');
710
- this.current.txtgrp = this.svgFactory.createElement('svg:g');
711
- this.current.xcoords = [];
712
- },
713
- moveText: function SVGGraphics_moveText(x, y) {
831
+ }
832
+ }, {
833
+ key: "beginText",
834
+ value: function beginText() {
835
+ var current = this.current;
836
+ current.x = current.lineX = 0;
837
+ current.y = current.lineY = 0;
838
+ current.textMatrix = _util.IDENTITY_MATRIX;
839
+ current.lineMatrix = _util.IDENTITY_MATRIX;
840
+ current.textMatrixScale = 1;
841
+ current.tspan = this.svgFactory.createElement('svg:tspan');
842
+ current.txtElement = this.svgFactory.createElement('svg:text');
843
+ current.txtgrp = this.svgFactory.createElement('svg:g');
844
+ current.xcoords = [];
845
+ }
846
+ }, {
847
+ key: "moveText",
848
+ value: function moveText(x, y) {
714
849
  var current = this.current;
715
- this.current.x = this.current.lineX += x;
716
- this.current.y = this.current.lineY += y;
850
+ current.x = current.lineX += x;
851
+ current.y = current.lineY += y;
717
852
  current.xcoords = [];
718
853
  current.tspan = this.svgFactory.createElement('svg:tspan');
719
854
  current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
720
- current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
855
+ current.tspan.setAttributeNS(null, 'font-size', "".concat(pf(current.fontSize), "px"));
721
856
  current.tspan.setAttributeNS(null, 'y', pf(-current.y));
722
- },
723
- showText: function SVGGraphics_showText(glyphs) {
857
+ }
858
+ }, {
859
+ key: "showText",
860
+ value: function showText(glyphs) {
724
861
  var current = this.current;
725
862
  var font = current.font;
726
863
  var fontSize = current.fontSize;
@@ -733,36 +870,52 @@ exports.SVGGraphics = SVGGraphics;
733
870
  var wordSpacing = current.wordSpacing;
734
871
  var fontDirection = current.fontDirection;
735
872
  var textHScale = current.textHScale * fontDirection;
736
- var glyphsLength = glyphs.length;
737
873
  var vertical = font.vertical;
738
874
  var widthAdvanceScale = fontSize * current.fontMatrix[0];
739
- var x = 0,
740
- i;
741
-
742
- for (i = 0; i < glyphsLength; ++i) {
743
- var glyph = glyphs[i];
875
+ var x = 0;
876
+ var _iteratorNormalCompletion4 = true;
877
+ var _didIteratorError4 = false;
878
+ var _iteratorError4 = undefined;
879
+
880
+ try {
881
+ for (var _iterator4 = glyphs[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
882
+ var glyph = _step4.value;
883
+
884
+ if (glyph === null) {
885
+ x += fontDirection * wordSpacing;
886
+ continue;
887
+ } else if ((0, _util.isNum)(glyph)) {
888
+ x += -glyph * fontSize * 0.001;
889
+ continue;
890
+ }
744
891
 
745
- if (glyph === null) {
746
- x += fontDirection * wordSpacing;
747
- continue;
748
- } else if ((0, _util.isNum)(glyph)) {
749
- x += -glyph * fontSize * 0.001;
750
- continue;
751
- }
892
+ var width = glyph.width;
893
+ var character = glyph.fontChar;
894
+ var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
895
+ var charWidth = width * widthAdvanceScale + spacing * fontDirection;
752
896
 
753
- var width = glyph.width;
754
- var character = glyph.fontChar;
755
- var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
756
- var charWidth = width * widthAdvanceScale + spacing * fontDirection;
897
+ if (!glyph.isInFont && !font.missingFile) {
898
+ x += charWidth;
899
+ continue;
900
+ }
757
901
 
758
- if (!glyph.isInFont && !font.missingFile) {
902
+ current.xcoords.push(current.x + x * textHScale);
903
+ current.tspan.textContent += character;
759
904
  x += charWidth;
760
- continue;
761
905
  }
762
-
763
- current.xcoords.push(current.x + x * textHScale);
764
- current.tspan.textContent += character;
765
- x += charWidth;
906
+ } catch (err) {
907
+ _didIteratorError4 = true;
908
+ _iteratorError4 = err;
909
+ } finally {
910
+ try {
911
+ if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
912
+ _iterator4["return"]();
913
+ }
914
+ } finally {
915
+ if (_didIteratorError4) {
916
+ throw _iteratorError4;
917
+ }
918
+ }
766
919
  }
767
920
 
768
921
  if (vertical) {
@@ -774,7 +927,7 @@ exports.SVGGraphics = SVGGraphics;
774
927
  current.tspan.setAttributeNS(null, 'x', current.xcoords.map(pf).join(' '));
775
928
  current.tspan.setAttributeNS(null, 'y', pf(-current.y));
776
929
  current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
777
- current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
930
+ current.tspan.setAttributeNS(null, 'font-size', "".concat(pf(current.fontSize), "px"));
778
931
 
779
932
  if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
780
933
  current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
@@ -801,7 +954,9 @@ exports.SVGGraphics = SVGGraphics;
801
954
  }
802
955
 
803
956
  if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
804
- this._setStrokeAttributes(current.tspan);
957
+ var lineWidthScale = 1 / (current.textMatrixScale || 1);
958
+
959
+ this._setStrokeAttributes(current.tspan, lineWidthScale);
805
960
  }
806
961
 
807
962
  var textMatrix = current.textMatrix;
@@ -811,18 +966,22 @@ exports.SVGGraphics = SVGGraphics;
811
966
  textMatrix[5] += current.textRise;
812
967
  }
813
968
 
814
- current.txtElement.setAttributeNS(null, 'transform', pm(textMatrix) + ' scale(1, -1)');
969
+ current.txtElement.setAttributeNS(null, 'transform', "".concat(pm(textMatrix), " scale(1, -1)"));
815
970
  current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
816
971
  current.txtElement.appendChild(current.tspan);
817
972
  current.txtgrp.appendChild(current.txtElement);
818
973
 
819
974
  this._ensureTransformGroup().appendChild(current.txtElement);
820
- },
821
- setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
975
+ }
976
+ }, {
977
+ key: "setLeadingMoveText",
978
+ value: function setLeadingMoveText(x, y) {
822
979
  this.setLeading(-y);
823
980
  this.moveText(x, y);
824
- },
825
- addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
981
+ }
982
+ }, {
983
+ key: "addFontStyle",
984
+ value: function addFontStyle(fontObj) {
826
985
  if (!this.cssStyle) {
827
986
  this.cssStyle = this.svgFactory.createElement('svg:style');
828
987
  this.cssStyle.setAttributeNS(null, 'type', 'text/css');
@@ -830,13 +989,15 @@ exports.SVGGraphics = SVGGraphics;
830
989
  }
831
990
 
832
991
  var url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
833
- this.cssStyle.textContent += '@font-face { font-family: "' + fontObj.loadedName + '";' + ' src: url(' + url + '); }\n';
834
- },
835
- setFont: function SVGGraphics_setFont(details) {
992
+ this.cssStyle.textContent += "@font-face { font-family: \"".concat(fontObj.loadedName, "\";") + " src: url(".concat(url, "); }\n");
993
+ }
994
+ }, {
995
+ key: "setFont",
996
+ value: function setFont(details) {
836
997
  var current = this.current;
837
998
  var fontObj = this.commonObjs.get(details[0]);
838
999
  var size = details[1];
839
- this.current.font = fontObj;
1000
+ current.font = fontObj;
840
1001
 
841
1002
  if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) {
842
1003
  this.addFontStyle(fontObj);
@@ -861,8 +1022,10 @@ exports.SVGGraphics = SVGGraphics;
861
1022
  current.tspan = this.svgFactory.createElement('svg:tspan');
862
1023
  current.tspan.setAttributeNS(null, 'y', pf(-current.y));
863
1024
  current.xcoords = [];
864
- },
865
- endText: function endText() {
1025
+ }
1026
+ }, {
1027
+ key: "endText",
1028
+ value: function endText() {
866
1029
  var current = this.current;
867
1030
 
868
1031
  if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement && current.txtElement.hasChildNodes()) {
@@ -870,118 +1033,365 @@ exports.SVGGraphics = SVGGraphics;
870
1033
  this.clip('nonzero');
871
1034
  this.endPath();
872
1035
  }
873
- },
874
- setLineWidth: function SVGGraphics_setLineWidth(width) {
1036
+ }
1037
+ }, {
1038
+ key: "setLineWidth",
1039
+ value: function setLineWidth(width) {
875
1040
  if (width > 0) {
876
1041
  this.current.lineWidth = width;
877
1042
  }
878
- },
879
- setLineCap: function SVGGraphics_setLineCap(style) {
1043
+ }
1044
+ }, {
1045
+ key: "setLineCap",
1046
+ value: function setLineCap(style) {
880
1047
  this.current.lineCap = LINE_CAP_STYLES[style];
881
- },
882
- setLineJoin: function SVGGraphics_setLineJoin(style) {
1048
+ }
1049
+ }, {
1050
+ key: "setLineJoin",
1051
+ value: function setLineJoin(style) {
883
1052
  this.current.lineJoin = LINE_JOIN_STYLES[style];
884
- },
885
- setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
1053
+ }
1054
+ }, {
1055
+ key: "setMiterLimit",
1056
+ value: function setMiterLimit(limit) {
886
1057
  this.current.miterLimit = limit;
887
- },
888
- setStrokeAlpha: function SVGGraphics_setStrokeAlpha(strokeAlpha) {
1058
+ }
1059
+ }, {
1060
+ key: "setStrokeAlpha",
1061
+ value: function setStrokeAlpha(strokeAlpha) {
889
1062
  this.current.strokeAlpha = strokeAlpha;
890
- },
891
- setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
892
- var color = _util.Util.makeCssRgb(r, g, b);
893
-
894
- this.current.strokeColor = color;
895
- },
896
- setFillAlpha: function SVGGraphics_setFillAlpha(fillAlpha) {
1063
+ }
1064
+ }, {
1065
+ key: "setStrokeRGBColor",
1066
+ value: function setStrokeRGBColor(r, g, b) {
1067
+ this.current.strokeColor = _util.Util.makeCssRgb(r, g, b);
1068
+ }
1069
+ }, {
1070
+ key: "setFillAlpha",
1071
+ value: function setFillAlpha(fillAlpha) {
897
1072
  this.current.fillAlpha = fillAlpha;
898
- },
899
- setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
900
- var color = _util.Util.makeCssRgb(r, g, b);
901
-
902
- this.current.fillColor = color;
1073
+ }
1074
+ }, {
1075
+ key: "setFillRGBColor",
1076
+ value: function setFillRGBColor(r, g, b) {
1077
+ this.current.fillColor = _util.Util.makeCssRgb(r, g, b);
903
1078
  this.current.tspan = this.svgFactory.createElement('svg:tspan');
904
1079
  this.current.xcoords = [];
905
- },
906
- setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
1080
+ }
1081
+ }, {
1082
+ key: "setStrokeColorN",
1083
+ value: function setStrokeColorN(args) {
1084
+ this.current.strokeColor = this._makeColorN_Pattern(args);
1085
+ }
1086
+ }, {
1087
+ key: "setFillColorN",
1088
+ value: function setFillColorN(args) {
1089
+ this.current.fillColor = this._makeColorN_Pattern(args);
1090
+ }
1091
+ }, {
1092
+ key: "shadingFill",
1093
+ value: function shadingFill(args) {
1094
+ var width = this.viewport.width;
1095
+ var height = this.viewport.height;
1096
+
1097
+ var inv = _util.Util.inverseTransform(this.transformMatrix);
1098
+
1099
+ var bl = _util.Util.applyTransform([0, 0], inv);
1100
+
1101
+ var br = _util.Util.applyTransform([0, height], inv);
1102
+
1103
+ var ul = _util.Util.applyTransform([width, 0], inv);
1104
+
1105
+ var ur = _util.Util.applyTransform([width, height], inv);
1106
+
1107
+ var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
1108
+ var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
1109
+ var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
1110
+ var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
1111
+ var rect = this.svgFactory.createElement('svg:rect');
1112
+ rect.setAttributeNS(null, 'x', x0);
1113
+ rect.setAttributeNS(null, 'y', y0);
1114
+ rect.setAttributeNS(null, 'width', x1 - x0);
1115
+ rect.setAttributeNS(null, 'height', y1 - y0);
1116
+ rect.setAttributeNS(null, 'fill', this._makeShadingPattern(args));
1117
+
1118
+ this._ensureTransformGroup().appendChild(rect);
1119
+ }
1120
+ }, {
1121
+ key: "_makeColorN_Pattern",
1122
+ value: function _makeColorN_Pattern(args) {
1123
+ if (args[0] === 'TilingPattern') {
1124
+ return this._makeTilingPattern(args);
1125
+ }
1126
+
1127
+ return this._makeShadingPattern(args);
1128
+ }
1129
+ }, {
1130
+ key: "_makeTilingPattern",
1131
+ value: function _makeTilingPattern(args) {
1132
+ var color = args[1];
1133
+ var operatorList = args[2];
1134
+ var matrix = args[3] || _util.IDENTITY_MATRIX;
1135
+
1136
+ var _args$ = _slicedToArray(args[4], 4),
1137
+ x0 = _args$[0],
1138
+ y0 = _args$[1],
1139
+ x1 = _args$[2],
1140
+ y1 = _args$[3];
1141
+
1142
+ var xstep = args[5];
1143
+ var ystep = args[6];
1144
+ var paintType = args[7];
1145
+ var tilingId = "shading".concat(shadingCount++);
1146
+
1147
+ var _Util$applyTransform = _util.Util.applyTransform([x0, y0], matrix),
1148
+ _Util$applyTransform2 = _slicedToArray(_Util$applyTransform, 2),
1149
+ tx0 = _Util$applyTransform2[0],
1150
+ ty0 = _Util$applyTransform2[1];
1151
+
1152
+ var _Util$applyTransform3 = _util.Util.applyTransform([x1, y1], matrix),
1153
+ _Util$applyTransform4 = _slicedToArray(_Util$applyTransform3, 2),
1154
+ tx1 = _Util$applyTransform4[0],
1155
+ ty1 = _Util$applyTransform4[1];
1156
+
1157
+ var _Util$singularValueDe = _util.Util.singularValueDecompose2dScale(matrix),
1158
+ _Util$singularValueDe2 = _slicedToArray(_Util$singularValueDe, 2),
1159
+ xscale = _Util$singularValueDe2[0],
1160
+ yscale = _Util$singularValueDe2[1];
1161
+
1162
+ var txstep = xstep * xscale;
1163
+ var tystep = ystep * yscale;
1164
+ var tiling = this.svgFactory.createElement('svg:pattern');
1165
+ tiling.setAttributeNS(null, 'id', tilingId);
1166
+ tiling.setAttributeNS(null, 'patternUnits', 'userSpaceOnUse');
1167
+ tiling.setAttributeNS(null, 'width', txstep);
1168
+ tiling.setAttributeNS(null, 'height', tystep);
1169
+ tiling.setAttributeNS(null, 'x', "".concat(tx0));
1170
+ tiling.setAttributeNS(null, 'y', "".concat(ty0));
1171
+ var svg = this.svg;
1172
+ var transformMatrix = this.transformMatrix;
1173
+ var fillColor = this.current.fillColor;
1174
+ var strokeColor = this.current.strokeColor;
1175
+ var bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
1176
+ this.svg = bbox;
1177
+ this.transformMatrix = matrix;
1178
+
1179
+ if (paintType === 2) {
1180
+ var cssColor = _util.Util.makeCssRgb.apply(_util.Util, _toConsumableArray(color));
1181
+
1182
+ this.current.fillColor = cssColor;
1183
+ this.current.strokeColor = cssColor;
1184
+ }
1185
+
1186
+ this.executeOpTree(this.convertOpList(operatorList));
1187
+ this.svg = svg;
1188
+ this.transformMatrix = transformMatrix;
1189
+ this.current.fillColor = fillColor;
1190
+ this.current.strokeColor = strokeColor;
1191
+ tiling.appendChild(bbox.childNodes[0]);
1192
+ this.defs.appendChild(tiling);
1193
+ return "url(#".concat(tilingId, ")");
1194
+ }
1195
+ }, {
1196
+ key: "_makeShadingPattern",
1197
+ value: function _makeShadingPattern(args) {
1198
+ switch (args[0]) {
1199
+ case 'RadialAxial':
1200
+ var shadingId = "shading".concat(shadingCount++);
1201
+ var colorStops = args[2];
1202
+ var gradient;
1203
+
1204
+ switch (args[1]) {
1205
+ case 'axial':
1206
+ var point0 = args[3];
1207
+ var point1 = args[4];
1208
+ gradient = this.svgFactory.createElement('svg:linearGradient');
1209
+ gradient.setAttributeNS(null, 'id', shadingId);
1210
+ gradient.setAttributeNS(null, 'gradientUnits', 'userSpaceOnUse');
1211
+ gradient.setAttributeNS(null, 'x1', point0[0]);
1212
+ gradient.setAttributeNS(null, 'y1', point0[1]);
1213
+ gradient.setAttributeNS(null, 'x2', point1[0]);
1214
+ gradient.setAttributeNS(null, 'y2', point1[1]);
1215
+ break;
1216
+
1217
+ case 'radial':
1218
+ var focalPoint = args[3];
1219
+ var circlePoint = args[4];
1220
+ var focalRadius = args[5];
1221
+ var circleRadius = args[6];
1222
+ gradient = this.svgFactory.createElement('svg:radialGradient');
1223
+ gradient.setAttributeNS(null, 'id', shadingId);
1224
+ gradient.setAttributeNS(null, 'gradientUnits', 'userSpaceOnUse');
1225
+ gradient.setAttributeNS(null, 'cx', circlePoint[0]);
1226
+ gradient.setAttributeNS(null, 'cy', circlePoint[1]);
1227
+ gradient.setAttributeNS(null, 'r', circleRadius);
1228
+ gradient.setAttributeNS(null, 'fx', focalPoint[0]);
1229
+ gradient.setAttributeNS(null, 'fy', focalPoint[1]);
1230
+ gradient.setAttributeNS(null, 'fr', focalRadius);
1231
+ break;
1232
+
1233
+ default:
1234
+ throw new Error("Unknown RadialAxial type: ".concat(args[1]));
1235
+ }
1236
+
1237
+ var _iteratorNormalCompletion5 = true;
1238
+ var _didIteratorError5 = false;
1239
+ var _iteratorError5 = undefined;
1240
+
1241
+ try {
1242
+ for (var _iterator5 = colorStops[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
1243
+ var colorStop = _step5.value;
1244
+ var stop = this.svgFactory.createElement('svg:stop');
1245
+ stop.setAttributeNS(null, 'offset', colorStop[0]);
1246
+ stop.setAttributeNS(null, 'stop-color', colorStop[1]);
1247
+ gradient.appendChild(stop);
1248
+ }
1249
+ } catch (err) {
1250
+ _didIteratorError5 = true;
1251
+ _iteratorError5 = err;
1252
+ } finally {
1253
+ try {
1254
+ if (!_iteratorNormalCompletion5 && _iterator5["return"] != null) {
1255
+ _iterator5["return"]();
1256
+ }
1257
+ } finally {
1258
+ if (_didIteratorError5) {
1259
+ throw _iteratorError5;
1260
+ }
1261
+ }
1262
+ }
1263
+
1264
+ this.defs.appendChild(gradient);
1265
+ return "url(#".concat(shadingId, ")");
1266
+
1267
+ case 'Mesh':
1268
+ (0, _util.warn)('Unimplemented pattern Mesh');
1269
+ return null;
1270
+
1271
+ case 'Dummy':
1272
+ return 'hotpink';
1273
+
1274
+ default:
1275
+ throw new Error("Unknown IR type: ".concat(args[0]));
1276
+ }
1277
+ }
1278
+ }, {
1279
+ key: "setDash",
1280
+ value: function setDash(dashArray, dashPhase) {
907
1281
  this.current.dashArray = dashArray;
908
1282
  this.current.dashPhase = dashPhase;
909
- },
910
- constructPath: function SVGGraphics_constructPath(ops, args) {
1283
+ }
1284
+ }, {
1285
+ key: "constructPath",
1286
+ value: function constructPath(ops, args) {
911
1287
  var current = this.current;
912
1288
  var x = current.x,
913
1289
  y = current.y;
914
- current.path = this.svgFactory.createElement('svg:path');
915
1290
  var d = [];
916
- var opLength = ops.length;
917
-
918
- for (var i = 0, j = 0; i < opLength; i++) {
919
- switch (ops[i] | 0) {
920
- case _util.OPS.rectangle:
921
- x = args[j++];
922
- y = args[j++];
923
- var width = args[j++];
924
- var height = args[j++];
925
- var xw = x + width;
926
- var yh = y + height;
927
- d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z');
928
- break;
929
-
930
- case _util.OPS.moveTo:
931
- x = args[j++];
932
- y = args[j++];
933
- d.push('M', pf(x), pf(y));
934
- break;
935
-
936
- case _util.OPS.lineTo:
937
- x = args[j++];
938
- y = args[j++];
939
- d.push('L', pf(x), pf(y));
940
- break;
941
-
942
- case _util.OPS.curveTo:
943
- x = args[j + 4];
944
- y = args[j + 5];
945
- d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
946
- j += 6;
947
- break;
948
-
949
- case _util.OPS.curveTo2:
950
- x = args[j + 2];
951
- y = args[j + 3];
952
- d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
953
- j += 4;
954
- break;
955
-
956
- case _util.OPS.curveTo3:
957
- x = args[j + 2];
958
- y = args[j + 3];
959
- d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
960
- j += 4;
961
- break;
962
-
963
- case _util.OPS.closePath:
964
- d.push('Z');
965
- break;
1291
+ var j = 0;
1292
+ var _iteratorNormalCompletion6 = true;
1293
+ var _didIteratorError6 = false;
1294
+ var _iteratorError6 = undefined;
1295
+
1296
+ try {
1297
+ for (var _iterator6 = ops[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
1298
+ var op = _step6.value;
1299
+
1300
+ switch (op | 0) {
1301
+ case _util.OPS.rectangle:
1302
+ x = args[j++];
1303
+ y = args[j++];
1304
+ var width = args[j++];
1305
+ var height = args[j++];
1306
+ var xw = x + width;
1307
+ var yh = y + height;
1308
+ d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z');
1309
+ break;
1310
+
1311
+ case _util.OPS.moveTo:
1312
+ x = args[j++];
1313
+ y = args[j++];
1314
+ d.push('M', pf(x), pf(y));
1315
+ break;
1316
+
1317
+ case _util.OPS.lineTo:
1318
+ x = args[j++];
1319
+ y = args[j++];
1320
+ d.push('L', pf(x), pf(y));
1321
+ break;
1322
+
1323
+ case _util.OPS.curveTo:
1324
+ x = args[j + 4];
1325
+ y = args[j + 5];
1326
+ d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
1327
+ j += 6;
1328
+ break;
1329
+
1330
+ case _util.OPS.curveTo2:
1331
+ x = args[j + 2];
1332
+ y = args[j + 3];
1333
+ d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
1334
+ j += 4;
1335
+ break;
1336
+
1337
+ case _util.OPS.curveTo3:
1338
+ x = args[j + 2];
1339
+ y = args[j + 3];
1340
+ d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
1341
+ j += 4;
1342
+ break;
1343
+
1344
+ case _util.OPS.closePath:
1345
+ d.push('Z');
1346
+ break;
1347
+ }
1348
+ }
1349
+ } catch (err) {
1350
+ _didIteratorError6 = true;
1351
+ _iteratorError6 = err;
1352
+ } finally {
1353
+ try {
1354
+ if (!_iteratorNormalCompletion6 && _iterator6["return"] != null) {
1355
+ _iterator6["return"]();
1356
+ }
1357
+ } finally {
1358
+ if (_didIteratorError6) {
1359
+ throw _iteratorError6;
1360
+ }
966
1361
  }
967
1362
  }
968
1363
 
969
- current.path.setAttributeNS(null, 'd', d.join(' '));
970
- current.path.setAttributeNS(null, 'fill', 'none');
1364
+ d = d.join(' ');
971
1365
 
972
- this._ensureTransformGroup().appendChild(current.path);
1366
+ if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
1367
+ d = current.path.getAttributeNS(null, 'd') + d;
1368
+ } else {
1369
+ current.path = this.svgFactory.createElement('svg:path');
1370
+
1371
+ this._ensureTransformGroup().appendChild(current.path);
1372
+ }
973
1373
 
1374
+ current.path.setAttributeNS(null, 'd', d);
1375
+ current.path.setAttributeNS(null, 'fill', 'none');
974
1376
  current.element = current.path;
975
1377
  current.setCurrentPoint(x, y);
976
- },
977
- endPath: function SVGGraphics_endPath() {
1378
+ }
1379
+ }, {
1380
+ key: "endPath",
1381
+ value: function endPath() {
1382
+ var current = this.current;
1383
+ current.path = null;
1384
+
978
1385
  if (!this.pendingClip) {
979
1386
  return;
980
1387
  }
981
1388
 
982
- var current = this.current;
983
- var clipId = 'clippath' + clipCount;
984
- clipCount++;
1389
+ if (!current.element) {
1390
+ this.pendingClip = null;
1391
+ return;
1392
+ }
1393
+
1394
+ var clipId = "clippath".concat(clipCount++);
985
1395
  var clipPath = this.svgFactory.createElement('svg:clipPath');
986
1396
  clipPath.setAttributeNS(null, 'id', clipId);
987
1397
  clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
@@ -1005,79 +1415,127 @@ exports.SVGGraphics = SVGGraphics;
1005
1415
  clipPath.setAttributeNS(null, 'clip-path', current.activeClipUrl);
1006
1416
  }
1007
1417
 
1008
- current.activeClipUrl = 'url(#' + clipId + ')';
1418
+ current.activeClipUrl = "url(#".concat(clipId, ")");
1009
1419
  this.tgrp = null;
1010
- },
1011
- clip: function SVGGraphics_clip(type) {
1420
+ }
1421
+ }, {
1422
+ key: "clip",
1423
+ value: function clip(type) {
1012
1424
  this.pendingClip = type;
1013
- },
1014
- closePath: function SVGGraphics_closePath() {
1425
+ }
1426
+ }, {
1427
+ key: "closePath",
1428
+ value: function closePath() {
1015
1429
  var current = this.current;
1016
1430
 
1017
1431
  if (current.path) {
1018
- var d = current.path.getAttributeNS(null, 'd');
1019
- d += 'Z';
1432
+ var d = "".concat(current.path.getAttributeNS(null, 'd'), "Z");
1020
1433
  current.path.setAttributeNS(null, 'd', d);
1021
1434
  }
1022
- },
1023
- setLeading: function SVGGraphics_setLeading(leading) {
1435
+ }
1436
+ }, {
1437
+ key: "setLeading",
1438
+ value: function setLeading(leading) {
1024
1439
  this.current.leading = -leading;
1025
- },
1026
- setTextRise: function SVGGraphics_setTextRise(textRise) {
1440
+ }
1441
+ }, {
1442
+ key: "setTextRise",
1443
+ value: function setTextRise(textRise) {
1027
1444
  this.current.textRise = textRise;
1028
- },
1029
- setTextRenderingMode: function setTextRenderingMode(textRenderingMode) {
1445
+ }
1446
+ }, {
1447
+ key: "setTextRenderingMode",
1448
+ value: function setTextRenderingMode(textRenderingMode) {
1030
1449
  this.current.textRenderingMode = textRenderingMode;
1031
- },
1032
- setHScale: function SVGGraphics_setHScale(scale) {
1450
+ }
1451
+ }, {
1452
+ key: "setHScale",
1453
+ value: function setHScale(scale) {
1033
1454
  this.current.textHScale = scale / 100;
1034
- },
1035
- setGState: function SVGGraphics_setGState(states) {
1036
- for (var i = 0, ii = states.length; i < ii; i++) {
1037
- var state = states[i];
1038
- var key = state[0];
1039
- var value = state[1];
1040
-
1041
- switch (key) {
1042
- case 'LW':
1043
- this.setLineWidth(value);
1044
- break;
1045
-
1046
- case 'LC':
1047
- this.setLineCap(value);
1048
- break;
1049
-
1050
- case 'LJ':
1051
- this.setLineJoin(value);
1052
- break;
1053
-
1054
- case 'ML':
1055
- this.setMiterLimit(value);
1056
- break;
1057
-
1058
- case 'D':
1059
- this.setDash(value[0], value[1]);
1060
- break;
1061
-
1062
- case 'Font':
1063
- this.setFont(value);
1064
- break;
1065
-
1066
- case 'CA':
1067
- this.setStrokeAlpha(value);
1068
- break;
1069
-
1070
- case 'ca':
1071
- this.setFillAlpha(value);
1072
- break;
1073
-
1074
- default:
1075
- (0, _util.warn)('Unimplemented graphic state ' + key);
1076
- break;
1455
+ }
1456
+ }, {
1457
+ key: "setRenderingIntent",
1458
+ value: function setRenderingIntent(intent) {}
1459
+ }, {
1460
+ key: "setFlatness",
1461
+ value: function setFlatness(flatness) {}
1462
+ }, {
1463
+ key: "setGState",
1464
+ value: function setGState(states) {
1465
+ var _iteratorNormalCompletion7 = true;
1466
+ var _didIteratorError7 = false;
1467
+ var _iteratorError7 = undefined;
1468
+
1469
+ try {
1470
+ for (var _iterator7 = states[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
1471
+ var _step7$value = _slicedToArray(_step7.value, 2),
1472
+ key = _step7$value[0],
1473
+ value = _step7$value[1];
1474
+
1475
+ switch (key) {
1476
+ case 'LW':
1477
+ this.setLineWidth(value);
1478
+ break;
1479
+
1480
+ case 'LC':
1481
+ this.setLineCap(value);
1482
+ break;
1483
+
1484
+ case 'LJ':
1485
+ this.setLineJoin(value);
1486
+ break;
1487
+
1488
+ case 'ML':
1489
+ this.setMiterLimit(value);
1490
+ break;
1491
+
1492
+ case 'D':
1493
+ this.setDash(value[0], value[1]);
1494
+ break;
1495
+
1496
+ case 'RI':
1497
+ this.setRenderingIntent(value);
1498
+ break;
1499
+
1500
+ case 'FL':
1501
+ this.setFlatness(value);
1502
+ break;
1503
+
1504
+ case 'Font':
1505
+ this.setFont(value);
1506
+ break;
1507
+
1508
+ case 'CA':
1509
+ this.setStrokeAlpha(value);
1510
+ break;
1511
+
1512
+ case 'ca':
1513
+ this.setFillAlpha(value);
1514
+ break;
1515
+
1516
+ default:
1517
+ (0, _util.warn)("Unimplemented graphic state operator ".concat(key));
1518
+ break;
1519
+ }
1520
+ }
1521
+ } catch (err) {
1522
+ _didIteratorError7 = true;
1523
+ _iteratorError7 = err;
1524
+ } finally {
1525
+ try {
1526
+ if (!_iteratorNormalCompletion7 && _iterator7["return"] != null) {
1527
+ _iterator7["return"]();
1528
+ }
1529
+ } finally {
1530
+ if (_didIteratorError7) {
1531
+ throw _iteratorError7;
1532
+ }
1077
1533
  }
1078
1534
  }
1079
- },
1080
- fill: function SVGGraphics_fill() {
1535
+ }
1536
+ }, {
1537
+ key: "fill",
1538
+ value: function fill() {
1081
1539
  var current = this.current;
1082
1540
 
1083
1541
  if (current.element) {
@@ -1085,8 +1543,10 @@ exports.SVGGraphics = SVGGraphics;
1085
1543
  current.element.setAttributeNS(null, 'fill-opacity', current.fillAlpha);
1086
1544
  this.endPath();
1087
1545
  }
1088
- },
1089
- stroke: function SVGGraphics_stroke() {
1546
+ }
1547
+ }, {
1548
+ key: "stroke",
1549
+ value: function stroke() {
1090
1550
  var current = this.current;
1091
1551
 
1092
1552
  if (current.element) {
@@ -1095,60 +1555,86 @@ exports.SVGGraphics = SVGGraphics;
1095
1555
  current.element.setAttributeNS(null, 'fill', 'none');
1096
1556
  this.endPath();
1097
1557
  }
1098
- },
1099
- _setStrokeAttributes: function _setStrokeAttributes(element) {
1558
+ }
1559
+ }, {
1560
+ key: "_setStrokeAttributes",
1561
+ value: function _setStrokeAttributes(element) {
1562
+ var lineWidthScale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1100
1563
  var current = this.current;
1564
+ var dashArray = current.dashArray;
1565
+
1566
+ if (lineWidthScale !== 1 && dashArray.length > 0) {
1567
+ dashArray = dashArray.map(function (value) {
1568
+ return lineWidthScale * value;
1569
+ });
1570
+ }
1571
+
1101
1572
  element.setAttributeNS(null, 'stroke', current.strokeColor);
1102
1573
  element.setAttributeNS(null, 'stroke-opacity', current.strokeAlpha);
1103
1574
  element.setAttributeNS(null, 'stroke-miterlimit', pf(current.miterLimit));
1104
1575
  element.setAttributeNS(null, 'stroke-linecap', current.lineCap);
1105
1576
  element.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
1106
- element.setAttributeNS(null, 'stroke-width', pf(current.lineWidth) + 'px');
1107
- element.setAttributeNS(null, 'stroke-dasharray', current.dashArray.map(pf).join(' '));
1108
- element.setAttributeNS(null, 'stroke-dashoffset', pf(current.dashPhase) + 'px');
1109
- },
1110
- eoFill: function SVGGraphics_eoFill() {
1577
+ element.setAttributeNS(null, 'stroke-width', pf(lineWidthScale * current.lineWidth) + 'px');
1578
+ element.setAttributeNS(null, 'stroke-dasharray', dashArray.map(pf).join(' '));
1579
+ element.setAttributeNS(null, 'stroke-dashoffset', pf(lineWidthScale * current.dashPhase) + 'px');
1580
+ }
1581
+ }, {
1582
+ key: "eoFill",
1583
+ value: function eoFill() {
1111
1584
  if (this.current.element) {
1112
1585
  this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
1113
1586
  }
1114
1587
 
1115
1588
  this.fill();
1116
- },
1117
- fillStroke: function SVGGraphics_fillStroke() {
1589
+ }
1590
+ }, {
1591
+ key: "fillStroke",
1592
+ value: function fillStroke() {
1118
1593
  this.stroke();
1119
1594
  this.fill();
1120
- },
1121
- eoFillStroke: function SVGGraphics_eoFillStroke() {
1595
+ }
1596
+ }, {
1597
+ key: "eoFillStroke",
1598
+ value: function eoFillStroke() {
1122
1599
  if (this.current.element) {
1123
1600
  this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
1124
1601
  }
1125
1602
 
1126
1603
  this.fillStroke();
1127
- },
1128
- closeStroke: function SVGGraphics_closeStroke() {
1604
+ }
1605
+ }, {
1606
+ key: "closeStroke",
1607
+ value: function closeStroke() {
1129
1608
  this.closePath();
1130
1609
  this.stroke();
1131
- },
1132
- closeFillStroke: function SVGGraphics_closeFillStroke() {
1610
+ }
1611
+ }, {
1612
+ key: "closeFillStroke",
1613
+ value: function closeFillStroke() {
1133
1614
  this.closePath();
1134
1615
  this.fillStroke();
1135
- },
1136
- closeEOFillStroke: function closeEOFillStroke() {
1616
+ }
1617
+ }, {
1618
+ key: "closeEOFillStroke",
1619
+ value: function closeEOFillStroke() {
1137
1620
  this.closePath();
1138
1621
  this.eoFillStroke();
1139
- },
1140
- paintSolidColorImageMask: function SVGGraphics_paintSolidColorImageMask() {
1141
- var current = this.current;
1622
+ }
1623
+ }, {
1624
+ key: "paintSolidColorImageMask",
1625
+ value: function paintSolidColorImageMask() {
1142
1626
  var rect = this.svgFactory.createElement('svg:rect');
1143
1627
  rect.setAttributeNS(null, 'x', '0');
1144
1628
  rect.setAttributeNS(null, 'y', '0');
1145
1629
  rect.setAttributeNS(null, 'width', '1px');
1146
1630
  rect.setAttributeNS(null, 'height', '1px');
1147
- rect.setAttributeNS(null, 'fill', current.fillColor);
1631
+ rect.setAttributeNS(null, 'fill', this.current.fillColor);
1148
1632
 
1149
1633
  this._ensureTransformGroup().appendChild(rect);
1150
- },
1151
- paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
1634
+ }
1635
+ }, {
1636
+ key: "paintJpegXObject",
1637
+ value: function paintJpegXObject(objId, w, h) {
1152
1638
  var imgObj = this.objs.get(objId);
1153
1639
  var imgEl = this.svgFactory.createElement('svg:image');
1154
1640
  imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
@@ -1156,21 +1642,25 @@ exports.SVGGraphics = SVGGraphics;
1156
1642
  imgEl.setAttributeNS(null, 'height', pf(h));
1157
1643
  imgEl.setAttributeNS(null, 'x', '0');
1158
1644
  imgEl.setAttributeNS(null, 'y', pf(-h));
1159
- imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
1645
+ imgEl.setAttributeNS(null, 'transform', "scale(".concat(pf(1 / w), " ").concat(pf(-1 / h), ")"));
1160
1646
 
1161
1647
  this._ensureTransformGroup().appendChild(imgEl);
1162
- },
1163
- paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
1648
+ }
1649
+ }, {
1650
+ key: "paintImageXObject",
1651
+ value: function paintImageXObject(objId) {
1164
1652
  var imgData = this.objs.get(objId);
1165
1653
 
1166
1654
  if (!imgData) {
1167
- (0, _util.warn)('Dependent image isn\'t ready yet');
1655
+ (0, _util.warn)("Dependent image with object ID ".concat(objId, " is not ready yet"));
1168
1656
  return;
1169
1657
  }
1170
1658
 
1171
1659
  this.paintInlineImageXObject(imgData);
1172
- },
1173
- paintInlineImageXObject: function SVGGraphics_paintInlineImageXObject(imgData, mask) {
1660
+ }
1661
+ }, {
1662
+ key: "paintInlineImageXObject",
1663
+ value: function paintInlineImageXObject(imgData, mask) {
1174
1664
  var width = imgData.width;
1175
1665
  var height = imgData.height;
1176
1666
  var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
@@ -1187,20 +1677,22 @@ exports.SVGGraphics = SVGGraphics;
1187
1677
  imgEl.setAttributeNS(null, 'y', pf(-height));
1188
1678
  imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
1189
1679
  imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
1190
- imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / width) + ' ' + pf(-1 / height) + ')');
1680
+ imgEl.setAttributeNS(null, 'transform', "scale(".concat(pf(1 / width), " ").concat(pf(-1 / height), ")"));
1191
1681
 
1192
1682
  if (mask) {
1193
1683
  mask.appendChild(imgEl);
1194
1684
  } else {
1195
1685
  this._ensureTransformGroup().appendChild(imgEl);
1196
1686
  }
1197
- },
1198
- paintImageMaskXObject: function SVGGraphics_paintImageMaskXObject(imgData) {
1687
+ }
1688
+ }, {
1689
+ key: "paintImageMaskXObject",
1690
+ value: function paintImageMaskXObject(imgData) {
1199
1691
  var current = this.current;
1200
1692
  var width = imgData.width;
1201
1693
  var height = imgData.height;
1202
1694
  var fillColor = current.fillColor;
1203
- current.maskId = 'mask' + maskCount++;
1695
+ current.maskId = "mask".concat(maskCount++);
1204
1696
  var mask = this.svgFactory.createElement('svg:mask');
1205
1697
  mask.setAttributeNS(null, 'id', current.maskId);
1206
1698
  var rect = this.svgFactory.createElement('svg:rect');
@@ -1209,14 +1701,16 @@ exports.SVGGraphics = SVGGraphics;
1209
1701
  rect.setAttributeNS(null, 'width', pf(width));
1210
1702
  rect.setAttributeNS(null, 'height', pf(height));
1211
1703
  rect.setAttributeNS(null, 'fill', fillColor);
1212
- rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId + ')');
1704
+ rect.setAttributeNS(null, 'mask', "url(#".concat(current.maskId, ")"));
1213
1705
  this.defs.appendChild(mask);
1214
1706
 
1215
1707
  this._ensureTransformGroup().appendChild(rect);
1216
1708
 
1217
1709
  this.paintInlineImageXObject(imgData, mask);
1218
- },
1219
- paintFormXObjectBegin: function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
1710
+ }
1711
+ }, {
1712
+ key: "paintFormXObjectBegin",
1713
+ value: function paintFormXObjectBegin(matrix, bbox) {
1220
1714
  if (Array.isArray(matrix) && matrix.length === 6) {
1221
1715
  this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
1222
1716
  }
@@ -1233,9 +1727,13 @@ exports.SVGGraphics = SVGGraphics;
1233
1727
  this.clip('nonzero');
1234
1728
  this.endPath();
1235
1729
  }
1236
- },
1237
- paintFormXObjectEnd: function SVGGraphics_paintFormXObjectEnd() {},
1238
- _initialize: function _initialize(viewport) {
1730
+ }
1731
+ }, {
1732
+ key: "paintFormXObjectEnd",
1733
+ value: function paintFormXObjectEnd() {}
1734
+ }, {
1735
+ key: "_initialize",
1736
+ value: function _initialize(viewport) {
1239
1737
  var svg = this.svgFactory.create(viewport.width, viewport.height);
1240
1738
  var definitions = this.svgFactory.createElement('svg:defs');
1241
1739
  svg.appendChild(definitions);
@@ -1245,8 +1743,10 @@ exports.SVGGraphics = SVGGraphics;
1245
1743
  svg.appendChild(rootGroup);
1246
1744
  this.svg = rootGroup;
1247
1745
  return svg;
1248
- },
1249
- _ensureClipGroup: function SVGGraphics_ensureClipGroup() {
1746
+ }
1747
+ }, {
1748
+ key: "_ensureClipGroup",
1749
+ value: function _ensureClipGroup() {
1250
1750
  if (!this.current.clipGroup) {
1251
1751
  var clipGroup = this.svgFactory.createElement('svg:g');
1252
1752
  clipGroup.setAttributeNS(null, 'clip-path', this.current.activeClipUrl);
@@ -1255,8 +1755,10 @@ exports.SVGGraphics = SVGGraphics;
1255
1755
  }
1256
1756
 
1257
1757
  return this.current.clipGroup;
1258
- },
1259
- _ensureTransformGroup: function SVGGraphics_ensureTransformGroup() {
1758
+ }
1759
+ }, {
1760
+ key: "_ensureTransformGroup",
1761
+ value: function _ensureTransformGroup() {
1260
1762
  if (!this.tgrp) {
1261
1763
  this.tgrp = this.svgFactory.createElement('svg:g');
1262
1764
  this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
@@ -1270,7 +1772,8 @@ exports.SVGGraphics = SVGGraphics;
1270
1772
 
1271
1773
  return this.tgrp;
1272
1774
  }
1273
- };
1775
+ }]);
1776
+
1274
1777
  return SVGGraphics;
1275
1778
  }();
1276
1779
  }