UNPKG

58.9 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2019 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * Javascript code in this page
21 */
22"use strict";
23
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.SVGGraphics = void 0;
28
29var _util = require("../shared/util");
30
31var _display_utils = require("./display_utils");
32
33var _is_node = _interopRequireDefault(require("../shared/is_node"));
34
35function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
36
37function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
38
39function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
40
41function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
42
43function _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
45function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
46
47function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
48
49function _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
51function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
52
53function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
54
55function _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
57function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
58
59var SVGGraphics = function SVGGraphics() {
60 throw new Error('Not implemented: SVGGraphics');
61};
62
63exports.SVGGraphics = SVGGraphics;
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
153 var SVG_DEFAULTS = {
154 fontStyle: 'normal',
155 fontWeight: 'normal',
156 fillColor: '#000000'
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'];
162
163 var convertImgDataToPng = function () {
164 var PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
165 var CHUNK_WRAPPER_SIZE = 12;
166 var crcTable = new Int32Array(256);
167
168 for (var i = 0; i < 256; i++) {
169 var c = i;
170
171 for (var h = 0; h < 8; h++) {
172 if (c & 1) {
173 c = 0xedB88320 ^ c >> 1 & 0x7fffffff;
174 } else {
175 c = c >> 1 & 0x7fffffff;
176 }
177 }
178
179 crcTable[i] = c;
180 }
181
182 function crc32(data, start, end) {
183 var crc = -1;
184
185 for (var _i = start; _i < end; _i++) {
186 var a = (crc ^ data[_i]) & 0xff;
187 var b = crcTable[a];
188 crc = crc >>> 8 ^ b;
189 }
190
191 return crc ^ -1;
192 }
193
194 function writePngChunk(type, body, data, offset) {
195 var p = offset;
196 var len = body.length;
197 data[p] = len >> 24 & 0xff;
198 data[p + 1] = len >> 16 & 0xff;
199 data[p + 2] = len >> 8 & 0xff;
200 data[p + 3] = len & 0xff;
201 p += 4;
202 data[p] = type.charCodeAt(0) & 0xff;
203 data[p + 1] = type.charCodeAt(1) & 0xff;
204 data[p + 2] = type.charCodeAt(2) & 0xff;
205 data[p + 3] = type.charCodeAt(3) & 0xff;
206 p += 4;
207 data.set(body, p);
208 p += body.length;
209 var crc = crc32(data, offset + 4, p);
210 data[p] = crc >> 24 & 0xff;
211 data[p + 1] = crc >> 16 & 0xff;
212 data[p + 2] = crc >> 8 & 0xff;
213 data[p + 3] = crc & 0xff;
214 }
215
216 function adler32(data, start, end) {
217 var a = 1;
218 var b = 0;
219
220 for (var _i2 = start; _i2 < end; ++_i2) {
221 a = (a + (data[_i2] & 0xff)) % 65521;
222 b = (b + a) % 65521;
223 }
224
225 return b << 16 | a;
226 }
227
228 function deflateSync(literals) {
229 if (!(0, _is_node["default"])()) {
230 return deflateSyncUncompressed(literals);
231 }
232
233 try {
234 var input;
235
236 if (parseInt(process.versions.node) >= 8) {
237 input = literals;
238 } else {
239 input = new Buffer(literals);
240 }
241
242 var output = require('zlib').deflateSync(input, {
243 level: 9
244 });
245
246 return output instanceof Uint8Array ? output : new Uint8Array(output);
247 } catch (e) {
248 (0, _util.warn)('Not compressing PNG because zlib.deflateSync is unavailable: ' + e);
249 }
250
251 return deflateSyncUncompressed(literals);
252 }
253
254 function deflateSyncUncompressed(literals) {
255 var len = literals.length;
256 var maxBlockLength = 0xFFFF;
257 var deflateBlocks = Math.ceil(len / maxBlockLength);
258 var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
259 var pi = 0;
260 idat[pi++] = 0x78;
261 idat[pi++] = 0x9c;
262 var pos = 0;
263
264 while (len > maxBlockLength) {
265 idat[pi++] = 0x00;
266 idat[pi++] = 0xff;
267 idat[pi++] = 0xff;
268 idat[pi++] = 0x00;
269 idat[pi++] = 0x00;
270 idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
271 pi += maxBlockLength;
272 pos += maxBlockLength;
273 len -= maxBlockLength;
274 }
275
276 idat[pi++] = 0x01;
277 idat[pi++] = len & 0xff;
278 idat[pi++] = len >> 8 & 0xff;
279 idat[pi++] = ~len & 0xffff & 0xff;
280 idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
281 idat.set(literals.subarray(pos), pi);
282 pi += literals.length - pos;
283 var adler = adler32(literals, 0, literals.length);
284 idat[pi++] = adler >> 24 & 0xff;
285 idat[pi++] = adler >> 16 & 0xff;
286 idat[pi++] = adler >> 8 & 0xff;
287 idat[pi++] = adler & 0xff;
288 return idat;
289 }
290
291 function encode(imgData, kind, forceDataSchema, isMask) {
292 var width = imgData.width;
293 var height = imgData.height;
294 var bitDepth, colorType, lineSize;
295 var bytes = imgData.data;
296
297 switch (kind) {
298 case _util.ImageKind.GRAYSCALE_1BPP:
299 colorType = 0;
300 bitDepth = 1;
301 lineSize = width + 7 >> 3;
302 break;
303
304 case _util.ImageKind.RGB_24BPP:
305 colorType = 2;
306 bitDepth = 8;
307 lineSize = width * 3;
308 break;
309
310 case _util.ImageKind.RGBA_32BPP:
311 colorType = 6;
312 bitDepth = 8;
313 lineSize = width * 4;
314 break;
315
316 default:
317 throw new Error('invalid format');
318 }
319
320 var literals = new Uint8Array((1 + lineSize) * height);
321 var offsetLiterals = 0,
322 offsetBytes = 0;
323
324 for (var y = 0; y < height; ++y) {
325 literals[offsetLiterals++] = 0;
326 literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
327 offsetBytes += lineSize;
328 offsetLiterals += lineSize;
329 }
330
331 if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
332 offsetLiterals = 0;
333
334 for (var _y = 0; _y < height; _y++) {
335 offsetLiterals++;
336
337 for (var _i3 = 0; _i3 < lineSize; _i3++) {
338 literals[offsetLiterals++] ^= 0xFF;
339 }
340 }
341 }
342
343 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]);
344 var idat = deflateSync(literals);
345 var pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
346 var data = new Uint8Array(pngLength);
347 var offset = 0;
348 data.set(PNG_HEADER, offset);
349 offset += PNG_HEADER.length;
350 writePngChunk('IHDR', ihdr, data, offset);
351 offset += CHUNK_WRAPPER_SIZE + ihdr.length;
352 writePngChunk('IDATA', idat, data, offset);
353 offset += CHUNK_WRAPPER_SIZE + idat.length;
354 writePngChunk('IEND', new Uint8Array(0), data, offset);
355 return (0, _util.createObjectURL)(data, 'image/png', forceDataSchema);
356 }
357
358 return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
359 var kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
360 return encode(imgData, kind, forceDataSchema, isMask);
361 };
362 }();
363
364 var SVGExtraState =
365 /*#__PURE__*/
366 function () {
367 function SVGExtraState() {
368 _classCallCheck(this, SVGExtraState);
369
370 this.fontSizeScale = 1;
371 this.fontWeight = SVG_DEFAULTS.fontWeight;
372 this.fontSize = 0;
373 this.textMatrix = _util.IDENTITY_MATRIX;
374 this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
375 this.leading = 0;
376 this.textRenderingMode = _util.TextRenderingMode.FILL;
377 this.textMatrixScale = 1;
378 this.x = 0;
379 this.y = 0;
380 this.lineX = 0;
381 this.lineY = 0;
382 this.charSpacing = 0;
383 this.wordSpacing = 0;
384 this.textHScale = 1;
385 this.textRise = 0;
386 this.fillColor = SVG_DEFAULTS.fillColor;
387 this.strokeColor = '#000000';
388 this.fillAlpha = 1;
389 this.strokeAlpha = 1;
390 this.lineWidth = 1;
391 this.lineJoin = '';
392 this.lineCap = '';
393 this.miterLimit = 0;
394 this.dashArray = [];
395 this.dashPhase = 0;
396 this.dependencies = [];
397 this.activeClipUrl = null;
398 this.clipGroup = null;
399 this.maskId = '';
400 }
401
402 _createClass(SVGExtraState, [{
403 key: "clone",
404 value: function clone() {
405 return Object.create(this);
406 }
407 }, {
408 key: "setCurrentPoint",
409 value: function setCurrentPoint(x, y) {
410 this.x = x;
411 this.y = y;
412 }
413 }]);
414
415 return SVGExtraState;
416 }();
417
418 var clipCount = 0;
419 var maskCount = 0;
420 var shadingCount = 0;
421
422 exports.SVGGraphics = SVGGraphics =
423 /*#__PURE__*/
424 function () {
425 function SVGGraphics(commonObjs, objs, forceDataSchema) {
426 _classCallCheck(this, SVGGraphics);
427
428 this.svgFactory = new _display_utils.DOMSVGFactory();
429 this.current = new SVGExtraState();
430 this.transformMatrix = _util.IDENTITY_MATRIX;
431 this.transformStack = [];
432 this.extraStack = [];
433 this.commonObjs = commonObjs;
434 this.objs = objs;
435 this.pendingClip = null;
436 this.pendingEOFill = false;
437 this.embedFonts = false;
438 this.embeddedFonts = Object.create(null);
439 this.cssStyle = null;
440 this.forceDataSchema = !!forceDataSchema;
441 this._operatorIdMapping = [];
442
443 for (var op in _util.OPS) {
444 this._operatorIdMapping[_util.OPS[op]] = op;
445 }
446 }
447
448 _createClass(SVGGraphics, [{
449 key: "save",
450 value: function save() {
451 this.transformStack.push(this.transformMatrix);
452 var old = this.current;
453 this.extraStack.push(old);
454 this.current = old.clone();
455 }
456 }, {
457 key: "restore",
458 value: function restore() {
459 this.transformMatrix = this.transformStack.pop();
460 this.current = this.extraStack.pop();
461 this.pendingClip = null;
462 this.tgrp = null;
463 }
464 }, {
465 key: "group",
466 value: function group(items) {
467 this.save();
468 this.executeOpTree(items);
469 this.restore();
470 }
471 }, {
472 key: "loadDependencies",
473 value: function loadDependencies(operatorList) {
474 var _this = this;
475
476 var fnArray = operatorList.fnArray;
477 var argsArray = operatorList.argsArray;
478
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;
487
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 }
514 }
515 }
516 }
517
518 return Promise.all(this.current.dependencies);
519 }
520 }, {
521 key: "transform",
522 value: function transform(a, b, c, d, e, f) {
523 var transformMatrix = [a, b, c, d, e, f];
524 this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
525 this.tgrp = null;
526 }
527 }, {
528 key: "getSVG",
529 value: function getSVG(operatorList, viewport) {
530 var _this2 = this;
531
532 this.viewport = viewport;
533
534 var svgElement = this._initialize(viewport);
535
536 return this.loadDependencies(operatorList).then(function () {
537 _this2.transformMatrix = _util.IDENTITY_MATRIX;
538
539 _this2.executeOpTree(_this2.convertOpList(operatorList));
540
541 return svgElement;
542 });
543 }
544 }, {
545 key: "convertOpList",
546 value: function convertOpList(operatorList) {
547 var operatorIdMapping = this._operatorIdMapping;
548 var argsArray = operatorList.argsArray;
549 var fnArray = operatorList.fnArray;
550 var opList = [];
551
552 for (var i = 0, ii = fnArray.length; i < ii; i++) {
553 var fnId = fnArray[i];
554 opList.push({
555 'fnId': fnId,
556 'fn': operatorIdMapping[fnId],
557 'args': argsArray[i]
558 });
559 }
560
561 return opListToTree(opList);
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;
668
669 case _util.OPS.shadingFill:
670 this.shadingFill(args[0]);
671 break;
672
673 case _util.OPS.setDash:
674 this.setDash(args[0], args[1]);
675 break;
676
677 case _util.OPS.setRenderingIntent:
678 this.setRenderingIntent(args[0]);
679 break;
680
681 case _util.OPS.setFlatness:
682 this.setFlatness(args[0]);
683 break;
684
685 case _util.OPS.setGState:
686 this.setGState(args[0]);
687 break;
688
689 case _util.OPS.fill:
690 this.fill();
691 break;
692
693 case _util.OPS.eoFill:
694 this.eoFill();
695 break;
696
697 case _util.OPS.stroke:
698 this.stroke();
699 break;
700
701 case _util.OPS.fillStroke:
702 this.fillStroke();
703 break;
704
705 case _util.OPS.eoFillStroke:
706 this.eoFillStroke();
707 break;
708
709 case _util.OPS.clip:
710 this.clip('nonzero');
711 break;
712
713 case _util.OPS.eoClip:
714 this.clip('evenodd');
715 break;
716
717 case _util.OPS.paintSolidColorImageMask:
718 this.paintSolidColorImageMask();
719 break;
720
721 case _util.OPS.paintJpegXObject:
722 this.paintJpegXObject(args[0], args[1], args[2]);
723 break;
724
725 case _util.OPS.paintImageXObject:
726 this.paintImageXObject(args[0]);
727 break;
728
729 case _util.OPS.paintInlineImageXObject:
730 this.paintInlineImageXObject(args[0]);
731 break;
732
733 case _util.OPS.paintImageMaskXObject:
734 this.paintImageMaskXObject(args[0]);
735 break;
736
737 case _util.OPS.paintFormXObjectBegin:
738 this.paintFormXObjectBegin(args[0], args[1]);
739 break;
740
741 case _util.OPS.paintFormXObjectEnd:
742 this.paintFormXObjectEnd();
743 break;
744
745 case _util.OPS.closePath:
746 this.closePath();
747 break;
748
749 case _util.OPS.closeStroke:
750 this.closeStroke();
751 break;
752
753 case _util.OPS.closeFillStroke:
754 this.closeFillStroke();
755 break;
756
757 case _util.OPS.closeEOFillStroke:
758 this.closeEOFillStroke();
759 break;
760
761 case _util.OPS.nextLine:
762 this.nextLine();
763 break;
764
765 case _util.OPS.transform:
766 this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
767 break;
768
769 case _util.OPS.constructPath:
770 this.constructPath(args[0], args[1]);
771 break;
772
773 case _util.OPS.endPath:
774 this.endPath();
775 break;
776
777 case 92:
778 this.group(opTreeElement.items);
779 break;
780
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 }
798 }
799 }
800 }
801 }, {
802 key: "setWordSpacing",
803 value: function setWordSpacing(wordSpacing) {
804 this.current.wordSpacing = wordSpacing;
805 }
806 }, {
807 key: "setCharSpacing",
808 value: function setCharSpacing(charSpacing) {
809 this.current.charSpacing = charSpacing;
810 }
811 }, {
812 key: "nextLine",
813 value: function nextLine() {
814 this.moveText(0, this.current.leading);
815 }
816 }, {
817 key: "setTextMatrix",
818 value: function setTextMatrix(a, b, c, d, e, f) {
819 var current = this.current;
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;
824 current.xcoords = [];
825 current.tspan = this.svgFactory.createElement('svg:tspan');
826 current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
827 current.tspan.setAttributeNS(null, 'font-size', "".concat(pf(current.fontSize), "px"));
828 current.tspan.setAttributeNS(null, 'y', pf(-current.y));
829 current.txtElement = this.svgFactory.createElement('svg:text');
830 current.txtElement.appendChild(current.tspan);
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) {
849 var current = this.current;
850 current.x = current.lineX += x;
851 current.y = current.lineY += y;
852 current.xcoords = [];
853 current.tspan = this.svgFactory.createElement('svg:tspan');
854 current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
855 current.tspan.setAttributeNS(null, 'font-size', "".concat(pf(current.fontSize), "px"));
856 current.tspan.setAttributeNS(null, 'y', pf(-current.y));
857 }
858 }, {
859 key: "showText",
860 value: function showText(glyphs) {
861 var current = this.current;
862 var font = current.font;
863 var fontSize = current.fontSize;
864
865 if (fontSize === 0) {
866 return;
867 }
868
869 var charSpacing = current.charSpacing;
870 var wordSpacing = current.wordSpacing;
871 var fontDirection = current.fontDirection;
872 var textHScale = current.textHScale * fontDirection;
873 var vertical = font.vertical;
874 var widthAdvanceScale = fontSize * current.fontMatrix[0];
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 }
891
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;
896
897 if (!glyph.isInFont && !font.missingFile) {
898 x += charWidth;
899 continue;
900 }
901
902 current.xcoords.push(current.x + x * textHScale);
903 current.tspan.textContent += character;
904 x += charWidth;
905 }
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 }
919 }
920
921 if (vertical) {
922 current.y -= x * textHScale;
923 } else {
924 current.x += x * textHScale;
925 }
926
927 current.tspan.setAttributeNS(null, 'x', current.xcoords.map(pf).join(' '));
928 current.tspan.setAttributeNS(null, 'y', pf(-current.y));
929 current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
930 current.tspan.setAttributeNS(null, 'font-size', "".concat(pf(current.fontSize), "px"));
931
932 if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
933 current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
934 }
935
936 if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
937 current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
938 }
939
940 var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
941
942 if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
943 if (current.fillColor !== SVG_DEFAULTS.fillColor) {
944 current.tspan.setAttributeNS(null, 'fill', current.fillColor);
945 }
946
947 if (current.fillAlpha < 1) {
948 current.tspan.setAttributeNS(null, 'fill-opacity', current.fillAlpha);
949 }
950 } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
951 current.tspan.setAttributeNS(null, 'fill', 'transparent');
952 } else {
953 current.tspan.setAttributeNS(null, 'fill', 'none');
954 }
955
956 if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
957 var lineWidthScale = 1 / (current.textMatrixScale || 1);
958
959 this._setStrokeAttributes(current.tspan, lineWidthScale);
960 }
961
962 var textMatrix = current.textMatrix;
963
964 if (current.textRise !== 0) {
965 textMatrix = textMatrix.slice();
966 textMatrix[5] += current.textRise;
967 }
968
969 current.txtElement.setAttributeNS(null, 'transform', "".concat(pm(textMatrix), " scale(1, -1)"));
970 current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
971 current.txtElement.appendChild(current.tspan);
972 current.txtgrp.appendChild(current.txtElement);
973
974 this._ensureTransformGroup().appendChild(current.txtElement);
975 }
976 }, {
977 key: "setLeadingMoveText",
978 value: function setLeadingMoveText(x, y) {
979 this.setLeading(-y);
980 this.moveText(x, y);
981 }
982 }, {
983 key: "addFontStyle",
984 value: function addFontStyle(fontObj) {
985 if (!this.cssStyle) {
986 this.cssStyle = this.svgFactory.createElement('svg:style');
987 this.cssStyle.setAttributeNS(null, 'type', 'text/css');
988 this.defs.appendChild(this.cssStyle);
989 }
990
991 var url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
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) {
997 var current = this.current;
998 var fontObj = this.commonObjs.get(details[0]);
999 var size = details[1];
1000 current.font = fontObj;
1001
1002 if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) {
1003 this.addFontStyle(fontObj);
1004 this.embeddedFonts[fontObj.loadedName] = fontObj;
1005 }
1006
1007 current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
1008 var bold = fontObj.black ? fontObj.bold ? 'bolder' : 'bold' : fontObj.bold ? 'bold' : 'normal';
1009 var italic = fontObj.italic ? 'italic' : 'normal';
1010
1011 if (size < 0) {
1012 size = -size;
1013 current.fontDirection = -1;
1014 } else {
1015 current.fontDirection = 1;
1016 }
1017
1018 current.fontSize = size;
1019 current.fontFamily = fontObj.loadedName;
1020 current.fontWeight = bold;
1021 current.fontStyle = italic;
1022 current.tspan = this.svgFactory.createElement('svg:tspan');
1023 current.tspan.setAttributeNS(null, 'y', pf(-current.y));
1024 current.xcoords = [];
1025 }
1026 }, {
1027 key: "endText",
1028 value: function endText() {
1029 var current = this.current;
1030
1031 if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement && current.txtElement.hasChildNodes()) {
1032 current.element = current.txtElement;
1033 this.clip('nonzero');
1034 this.endPath();
1035 }
1036 }
1037 }, {
1038 key: "setLineWidth",
1039 value: function setLineWidth(width) {
1040 if (width > 0) {
1041 this.current.lineWidth = width;
1042 }
1043 }
1044 }, {
1045 key: "setLineCap",
1046 value: function setLineCap(style) {
1047 this.current.lineCap = LINE_CAP_STYLES[style];
1048 }
1049 }, {
1050 key: "setLineJoin",
1051 value: function setLineJoin(style) {
1052 this.current.lineJoin = LINE_JOIN_STYLES[style];
1053 }
1054 }, {
1055 key: "setMiterLimit",
1056 value: function setMiterLimit(limit) {
1057 this.current.miterLimit = limit;
1058 }
1059 }, {
1060 key: "setStrokeAlpha",
1061 value: function setStrokeAlpha(strokeAlpha) {
1062 this.current.strokeAlpha = strokeAlpha;
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) {
1072 this.current.fillAlpha = fillAlpha;
1073 }
1074 }, {
1075 key: "setFillRGBColor",
1076 value: function setFillRGBColor(r, g, b) {
1077 this.current.fillColor = _util.Util.makeCssRgb(r, g, b);
1078 this.current.tspan = this.svgFactory.createElement('svg:tspan');
1079 this.current.xcoords = [];
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) {
1281 this.current.dashArray = dashArray;
1282 this.current.dashPhase = dashPhase;
1283 }
1284 }, {
1285 key: "constructPath",
1286 value: function constructPath(ops, args) {
1287 var current = this.current;
1288 var x = current.x,
1289 y = current.y;
1290 var d = [];
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 }
1361 }
1362 }
1363
1364 d = d.join(' ');
1365
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 }
1373
1374 current.path.setAttributeNS(null, 'd', d);
1375 current.path.setAttributeNS(null, 'fill', 'none');
1376 current.element = current.path;
1377 current.setCurrentPoint(x, y);
1378 }
1379 }, {
1380 key: "endPath",
1381 value: function endPath() {
1382 var current = this.current;
1383 current.path = null;
1384
1385 if (!this.pendingClip) {
1386 return;
1387 }
1388
1389 if (!current.element) {
1390 this.pendingClip = null;
1391 return;
1392 }
1393
1394 var clipId = "clippath".concat(clipCount++);
1395 var clipPath = this.svgFactory.createElement('svg:clipPath');
1396 clipPath.setAttributeNS(null, 'id', clipId);
1397 clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
1398 var clipElement = current.element.cloneNode(true);
1399
1400 if (this.pendingClip === 'evenodd') {
1401 clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
1402 } else {
1403 clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
1404 }
1405
1406 this.pendingClip = null;
1407 clipPath.appendChild(clipElement);
1408 this.defs.appendChild(clipPath);
1409
1410 if (current.activeClipUrl) {
1411 current.clipGroup = null;
1412 this.extraStack.forEach(function (prev) {
1413 prev.clipGroup = null;
1414 });
1415 clipPath.setAttributeNS(null, 'clip-path', current.activeClipUrl);
1416 }
1417
1418 current.activeClipUrl = "url(#".concat(clipId, ")");
1419 this.tgrp = null;
1420 }
1421 }, {
1422 key: "clip",
1423 value: function clip(type) {
1424 this.pendingClip = type;
1425 }
1426 }, {
1427 key: "closePath",
1428 value: function closePath() {
1429 var current = this.current;
1430
1431 if (current.path) {
1432 var d = "".concat(current.path.getAttributeNS(null, 'd'), "Z");
1433 current.path.setAttributeNS(null, 'd', d);
1434 }
1435 }
1436 }, {
1437 key: "setLeading",
1438 value: function setLeading(leading) {
1439 this.current.leading = -leading;
1440 }
1441 }, {
1442 key: "setTextRise",
1443 value: function setTextRise(textRise) {
1444 this.current.textRise = textRise;
1445 }
1446 }, {
1447 key: "setTextRenderingMode",
1448 value: function setTextRenderingMode(textRenderingMode) {
1449 this.current.textRenderingMode = textRenderingMode;
1450 }
1451 }, {
1452 key: "setHScale",
1453 value: function setHScale(scale) {
1454 this.current.textHScale = scale / 100;
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 }
1533 }
1534 }
1535 }
1536 }, {
1537 key: "fill",
1538 value: function fill() {
1539 var current = this.current;
1540
1541 if (current.element) {
1542 current.element.setAttributeNS(null, 'fill', current.fillColor);
1543 current.element.setAttributeNS(null, 'fill-opacity', current.fillAlpha);
1544 this.endPath();
1545 }
1546 }
1547 }, {
1548 key: "stroke",
1549 value: function stroke() {
1550 var current = this.current;
1551
1552 if (current.element) {
1553 this._setStrokeAttributes(current.element);
1554
1555 current.element.setAttributeNS(null, 'fill', 'none');
1556 this.endPath();
1557 }
1558 }
1559 }, {
1560 key: "_setStrokeAttributes",
1561 value: function _setStrokeAttributes(element) {
1562 var lineWidthScale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
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
1572 element.setAttributeNS(null, 'stroke', current.strokeColor);
1573 element.setAttributeNS(null, 'stroke-opacity', current.strokeAlpha);
1574 element.setAttributeNS(null, 'stroke-miterlimit', pf(current.miterLimit));
1575 element.setAttributeNS(null, 'stroke-linecap', current.lineCap);
1576 element.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
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() {
1584 if (this.current.element) {
1585 this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
1586 }
1587
1588 this.fill();
1589 }
1590 }, {
1591 key: "fillStroke",
1592 value: function fillStroke() {
1593 this.stroke();
1594 this.fill();
1595 }
1596 }, {
1597 key: "eoFillStroke",
1598 value: function eoFillStroke() {
1599 if (this.current.element) {
1600 this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
1601 }
1602
1603 this.fillStroke();
1604 }
1605 }, {
1606 key: "closeStroke",
1607 value: function closeStroke() {
1608 this.closePath();
1609 this.stroke();
1610 }
1611 }, {
1612 key: "closeFillStroke",
1613 value: function closeFillStroke() {
1614 this.closePath();
1615 this.fillStroke();
1616 }
1617 }, {
1618 key: "closeEOFillStroke",
1619 value: function closeEOFillStroke() {
1620 this.closePath();
1621 this.eoFillStroke();
1622 }
1623 }, {
1624 key: "paintSolidColorImageMask",
1625 value: function paintSolidColorImageMask() {
1626 var rect = this.svgFactory.createElement('svg:rect');
1627 rect.setAttributeNS(null, 'x', '0');
1628 rect.setAttributeNS(null, 'y', '0');
1629 rect.setAttributeNS(null, 'width', '1px');
1630 rect.setAttributeNS(null, 'height', '1px');
1631 rect.setAttributeNS(null, 'fill', this.current.fillColor);
1632
1633 this._ensureTransformGroup().appendChild(rect);
1634 }
1635 }, {
1636 key: "paintJpegXObject",
1637 value: function paintJpegXObject(objId, w, h) {
1638 var imgObj = this.objs.get(objId);
1639 var imgEl = this.svgFactory.createElement('svg:image');
1640 imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
1641 imgEl.setAttributeNS(null, 'width', pf(w));
1642 imgEl.setAttributeNS(null, 'height', pf(h));
1643 imgEl.setAttributeNS(null, 'x', '0');
1644 imgEl.setAttributeNS(null, 'y', pf(-h));
1645 imgEl.setAttributeNS(null, 'transform', "scale(".concat(pf(1 / w), " ").concat(pf(-1 / h), ")"));
1646
1647 this._ensureTransformGroup().appendChild(imgEl);
1648 }
1649 }, {
1650 key: "paintImageXObject",
1651 value: function paintImageXObject(objId) {
1652 var imgData = this.objs.get(objId);
1653
1654 if (!imgData) {
1655 (0, _util.warn)("Dependent image with object ID ".concat(objId, " is not ready yet"));
1656 return;
1657 }
1658
1659 this.paintInlineImageXObject(imgData);
1660 }
1661 }, {
1662 key: "paintInlineImageXObject",
1663 value: function paintInlineImageXObject(imgData, mask) {
1664 var width = imgData.width;
1665 var height = imgData.height;
1666 var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
1667 var cliprect = this.svgFactory.createElement('svg:rect');
1668 cliprect.setAttributeNS(null, 'x', '0');
1669 cliprect.setAttributeNS(null, 'y', '0');
1670 cliprect.setAttributeNS(null, 'width', pf(width));
1671 cliprect.setAttributeNS(null, 'height', pf(height));
1672 this.current.element = cliprect;
1673 this.clip('nonzero');
1674 var imgEl = this.svgFactory.createElement('svg:image');
1675 imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
1676 imgEl.setAttributeNS(null, 'x', '0');
1677 imgEl.setAttributeNS(null, 'y', pf(-height));
1678 imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
1679 imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
1680 imgEl.setAttributeNS(null, 'transform', "scale(".concat(pf(1 / width), " ").concat(pf(-1 / height), ")"));
1681
1682 if (mask) {
1683 mask.appendChild(imgEl);
1684 } else {
1685 this._ensureTransformGroup().appendChild(imgEl);
1686 }
1687 }
1688 }, {
1689 key: "paintImageMaskXObject",
1690 value: function paintImageMaskXObject(imgData) {
1691 var current = this.current;
1692 var width = imgData.width;
1693 var height = imgData.height;
1694 var fillColor = current.fillColor;
1695 current.maskId = "mask".concat(maskCount++);
1696 var mask = this.svgFactory.createElement('svg:mask');
1697 mask.setAttributeNS(null, 'id', current.maskId);
1698 var rect = this.svgFactory.createElement('svg:rect');
1699 rect.setAttributeNS(null, 'x', '0');
1700 rect.setAttributeNS(null, 'y', '0');
1701 rect.setAttributeNS(null, 'width', pf(width));
1702 rect.setAttributeNS(null, 'height', pf(height));
1703 rect.setAttributeNS(null, 'fill', fillColor);
1704 rect.setAttributeNS(null, 'mask', "url(#".concat(current.maskId, ")"));
1705 this.defs.appendChild(mask);
1706
1707 this._ensureTransformGroup().appendChild(rect);
1708
1709 this.paintInlineImageXObject(imgData, mask);
1710 }
1711 }, {
1712 key: "paintFormXObjectBegin",
1713 value: function paintFormXObjectBegin(matrix, bbox) {
1714 if (Array.isArray(matrix) && matrix.length === 6) {
1715 this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
1716 }
1717
1718 if (bbox) {
1719 var width = bbox[2] - bbox[0];
1720 var height = bbox[3] - bbox[1];
1721 var cliprect = this.svgFactory.createElement('svg:rect');
1722 cliprect.setAttributeNS(null, 'x', bbox[0]);
1723 cliprect.setAttributeNS(null, 'y', bbox[1]);
1724 cliprect.setAttributeNS(null, 'width', pf(width));
1725 cliprect.setAttributeNS(null, 'height', pf(height));
1726 this.current.element = cliprect;
1727 this.clip('nonzero');
1728 this.endPath();
1729 }
1730 }
1731 }, {
1732 key: "paintFormXObjectEnd",
1733 value: function paintFormXObjectEnd() {}
1734 }, {
1735 key: "_initialize",
1736 value: function _initialize(viewport) {
1737 var svg = this.svgFactory.create(viewport.width, viewport.height);
1738 var definitions = this.svgFactory.createElement('svg:defs');
1739 svg.appendChild(definitions);
1740 this.defs = definitions;
1741 var rootGroup = this.svgFactory.createElement('svg:g');
1742 rootGroup.setAttributeNS(null, 'transform', pm(viewport.transform));
1743 svg.appendChild(rootGroup);
1744 this.svg = rootGroup;
1745 return svg;
1746 }
1747 }, {
1748 key: "_ensureClipGroup",
1749 value: function _ensureClipGroup() {
1750 if (!this.current.clipGroup) {
1751 var clipGroup = this.svgFactory.createElement('svg:g');
1752 clipGroup.setAttributeNS(null, 'clip-path', this.current.activeClipUrl);
1753 this.svg.appendChild(clipGroup);
1754 this.current.clipGroup = clipGroup;
1755 }
1756
1757 return this.current.clipGroup;
1758 }
1759 }, {
1760 key: "_ensureTransformGroup",
1761 value: function _ensureTransformGroup() {
1762 if (!this.tgrp) {
1763 this.tgrp = this.svgFactory.createElement('svg:g');
1764 this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
1765
1766 if (this.current.activeClipUrl) {
1767 this._ensureClipGroup().appendChild(this.tgrp);
1768 } else {
1769 this.svg.appendChild(this.tgrp);
1770 }
1771 }
1772
1773 return this.tgrp;
1774 }
1775 }]);
1776
1777 return SVGGraphics;
1778 }();
1779}
\No newline at end of file