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