pdfjs-dist 2.0.943 → 2.4.456

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