pdfjs-dist 2.1.266 → 2.5.207
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/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8382 -18492
- 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 +20417 -29816
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25688 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +58239 -0
- package/es5/build/pdf.worker.js.map +1 -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/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +403 -0
- package/es5/web/pdf_viewer.js +7742 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1475 -4897
- 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 +750 -899
- 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 +235 -183
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +447 -542
- package/lib/core/cmap.js +222 -264
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +573 -660
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +1103 -868
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +570 -491
- package/lib/core/function.js +291 -288
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +145 -149
- package/lib/core/image_utils.js +170 -0
- 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 +284 -232
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2929 -2929
- package/lib/core/murmurhash3.js +90 -101
- package/lib/core/obj.js +1183 -1157
- package/lib/core/operator_list.js +99 -67
- package/lib/core/parser.js +972 -911
- package/lib/core/pattern.js +87 -70
- package/lib/core/pdf_manager.js +150 -315
- package/lib/core/primitives.js +83 -56
- 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 +87 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +193 -390
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +741 -972
- package/lib/display/api.js +1500 -1791
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +165 -165
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +515 -0
- package/lib/display/fetch_stream.js +183 -298
- package/lib/display/font_loader.js +273 -413
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +266 -359
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +285 -458
- package/lib/display/pattern_helper.js +113 -65
- package/lib/display/svg.js +1166 -901
- package/lib/display/text_layer.js +156 -132
- package/lib/display/transport_stream.js +262 -278
- 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 +40 -37
- package/lib/pdf.js +226 -59
- 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 +266 -416
- package/lib/test/unit/annotation_spec.js +1555 -701
- package/lib/test/unit/api_spec.js +802 -604
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +84 -69
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +74 -76
- package/lib/test/unit/colorspace_spec.js +166 -161
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +20 -22
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +16 -21
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +83 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +46 -30
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -61
- package/lib/test/unit/network_utils_spec.js +183 -119
- package/lib/test/unit/node_stream_spec.js +78 -92
- package/lib/test/unit/parser_spec.js +172 -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 +140 -125
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +131 -143
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +297 -459
- package/lib/test/unit/unicode_spec.js +38 -38
- package/lib/test/unit/util_spec.js +121 -305
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1328 -1214
- package/lib/web/app_options.js +105 -107
- package/lib/web/base_viewer.js +824 -838
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +39 -55
- package/lib/web/firefox_print_service.js +37 -27
- package/lib/web/firefoxcom.js +212 -363
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +32 -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 +113 -131
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +221 -306
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +491 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +140 -175
- package/lib/web/pdf_page_view.js +452 -523
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +84 -108
- package/lib/web/pdf_sidebar.js +276 -306
- 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 +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +82 -286
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +282 -339
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +267 -420
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +35 -25
- package/web/pdf_viewer.js +3489 -4855
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -494
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/lib/test/unit/dom_utils_spec.js +0 -89
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,37 +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
|
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
|
-
var SVGGraphics = function SVGGraphics() {
|
38
|
-
throw new Error('Not implemented: SVGGraphics');
|
35
|
+
let SVGGraphics = function () {
|
36
|
+
throw new Error("Not implemented: SVGGraphics");
|
39
37
|
};
|
40
38
|
|
41
39
|
exports.SVGGraphics = SVGGraphics;
|
42
40
|
{
|
43
|
-
|
44
|
-
fontStyle:
|
45
|
-
fontWeight:
|
46
|
-
fillColor:
|
41
|
+
const SVG_DEFAULTS = {
|
42
|
+
fontStyle: "normal",
|
43
|
+
fontWeight: "normal",
|
44
|
+
fillColor: "#000000"
|
47
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"];
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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);
|
53
55
|
|
54
|
-
for (
|
55
|
-
|
56
|
+
for (let i = 0; i < 256; i++) {
|
57
|
+
let c = i;
|
56
58
|
|
57
|
-
for (
|
59
|
+
for (let h = 0; h < 8; h++) {
|
58
60
|
if (c & 1) {
|
59
|
-
c =
|
61
|
+
c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
|
60
62
|
} else {
|
61
63
|
c = c >> 1 & 0x7fffffff;
|
62
64
|
}
|
@@ -66,11 +68,11 @@ exports.SVGGraphics = SVGGraphics;
|
|
66
68
|
}
|
67
69
|
|
68
70
|
function crc32(data, start, end) {
|
69
|
-
|
71
|
+
let crc = -1;
|
70
72
|
|
71
|
-
for (
|
72
|
-
|
73
|
-
|
73
|
+
for (let i = start; i < end; i++) {
|
74
|
+
const a = (crc ^ data[i]) & 0xff;
|
75
|
+
const b = crcTable[a];
|
74
76
|
crc = crc >>> 8 ^ b;
|
75
77
|
}
|
76
78
|
|
@@ -78,8 +80,8 @@ exports.SVGGraphics = SVGGraphics;
|
|
78
80
|
}
|
79
81
|
|
80
82
|
function writePngChunk(type, body, data, offset) {
|
81
|
-
|
82
|
-
|
83
|
+
let p = offset;
|
84
|
+
const len = body.length;
|
83
85
|
data[p] = len >> 24 & 0xff;
|
84
86
|
data[p + 1] = len >> 16 & 0xff;
|
85
87
|
data[p + 2] = len >> 8 & 0xff;
|
@@ -92,7 +94,7 @@ exports.SVGGraphics = SVGGraphics;
|
|
92
94
|
p += 4;
|
93
95
|
data.set(body, p);
|
94
96
|
p += body.length;
|
95
|
-
|
97
|
+
const crc = crc32(data, offset + 4, p);
|
96
98
|
data[p] = crc >> 24 & 0xff;
|
97
99
|
data[p + 1] = crc >> 16 & 0xff;
|
98
100
|
data[p + 2] = crc >> 8 & 0xff;
|
@@ -100,10 +102,10 @@ exports.SVGGraphics = SVGGraphics;
|
|
100
102
|
}
|
101
103
|
|
102
104
|
function adler32(data, start, end) {
|
103
|
-
|
104
|
-
|
105
|
+
let a = 1;
|
106
|
+
let b = 0;
|
105
107
|
|
106
|
-
for (
|
108
|
+
for (let i = start; i < end; ++i) {
|
107
109
|
a = (a + (data[i] & 0xff)) % 65521;
|
108
110
|
b = (b + a) % 65521;
|
109
111
|
}
|
@@ -112,40 +114,40 @@ exports.SVGGraphics = SVGGraphics;
|
|
112
114
|
}
|
113
115
|
|
114
116
|
function deflateSync(literals) {
|
115
|
-
if (!
|
117
|
+
if (!_is_node.isNodeJS) {
|
116
118
|
return deflateSyncUncompressed(literals);
|
117
119
|
}
|
118
120
|
|
119
121
|
try {
|
120
|
-
|
122
|
+
let input;
|
121
123
|
|
122
124
|
if (parseInt(process.versions.node) >= 8) {
|
123
125
|
input = literals;
|
124
126
|
} else {
|
125
|
-
input =
|
127
|
+
input = Buffer.from(literals);
|
126
128
|
}
|
127
129
|
|
128
|
-
|
130
|
+
const output = require("zlib").deflateSync(input, {
|
129
131
|
level: 9
|
130
132
|
});
|
131
133
|
|
132
134
|
return output instanceof Uint8Array ? output : new Uint8Array(output);
|
133
135
|
} catch (e) {
|
134
|
-
(0, _util.warn)(
|
136
|
+
(0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
|
135
137
|
}
|
136
138
|
|
137
139
|
return deflateSyncUncompressed(literals);
|
138
140
|
}
|
139
141
|
|
140
142
|
function deflateSyncUncompressed(literals) {
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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;
|
146
148
|
idat[pi++] = 0x78;
|
147
149
|
idat[pi++] = 0x9c;
|
148
|
-
|
150
|
+
let pos = 0;
|
149
151
|
|
150
152
|
while (len > maxBlockLength) {
|
151
153
|
idat[pi++] = 0x00;
|
@@ -166,7 +168,7 @@ exports.SVGGraphics = SVGGraphics;
|
|
166
168
|
idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
|
167
169
|
idat.set(literals.subarray(pos), pi);
|
168
170
|
pi += literals.length - pos;
|
169
|
-
|
171
|
+
const adler = adler32(literals, 0, literals.length);
|
170
172
|
idat[pi++] = adler >> 24 & 0xff;
|
171
173
|
idat[pi++] = adler >> 16 & 0xff;
|
172
174
|
idat[pi++] = adler >> 8 & 0xff;
|
@@ -175,10 +177,10 @@ exports.SVGGraphics = SVGGraphics;
|
|
175
177
|
}
|
176
178
|
|
177
179
|
function encode(imgData, kind, forceDataSchema, isMask) {
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
180
|
+
const width = imgData.width;
|
181
|
+
const height = imgData.height;
|
182
|
+
let bitDepth, colorType, lineSize;
|
183
|
+
const bytes = imgData.data;
|
182
184
|
|
183
185
|
switch (kind) {
|
184
186
|
case _util.ImageKind.GRAYSCALE_1BPP:
|
@@ -200,15 +202,14 @@ exports.SVGGraphics = SVGGraphics;
|
|
200
202
|
break;
|
201
203
|
|
202
204
|
default:
|
203
|
-
throw new Error(
|
205
|
+
throw new Error("invalid format");
|
204
206
|
}
|
205
207
|
|
206
|
-
|
207
|
-
|
208
|
+
const literals = new Uint8Array((1 + lineSize) * height);
|
209
|
+
let offsetLiterals = 0,
|
208
210
|
offsetBytes = 0;
|
209
|
-
var y, i;
|
210
211
|
|
211
|
-
for (y = 0; y < height; ++y) {
|
212
|
+
for (let y = 0; y < height; ++y) {
|
212
213
|
literals[offsetLiterals++] = 0;
|
213
214
|
literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
|
214
215
|
offsetBytes += lineSize;
|
@@ -218,38 +219,38 @@ exports.SVGGraphics = SVGGraphics;
|
|
218
219
|
if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
|
219
220
|
offsetLiterals = 0;
|
220
221
|
|
221
|
-
for (y = 0; y < height; y++) {
|
222
|
+
for (let y = 0; y < height; y++) {
|
222
223
|
offsetLiterals++;
|
223
224
|
|
224
|
-
for (i = 0; i < lineSize; i++) {
|
225
|
-
literals[offsetLiterals++] ^=
|
225
|
+
for (let i = 0; i < lineSize; i++) {
|
226
|
+
literals[offsetLiterals++] ^= 0xff;
|
226
227
|
}
|
227
228
|
}
|
228
229
|
}
|
229
230
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
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;
|
235
236
|
data.set(PNG_HEADER, offset);
|
236
237
|
offset += PNG_HEADER.length;
|
237
|
-
writePngChunk(
|
238
|
+
writePngChunk("IHDR", ihdr, data, offset);
|
238
239
|
offset += CHUNK_WRAPPER_SIZE + ihdr.length;
|
239
|
-
writePngChunk(
|
240
|
+
writePngChunk("IDATA", idat, data, offset);
|
240
241
|
offset += CHUNK_WRAPPER_SIZE + idat.length;
|
241
|
-
writePngChunk(
|
242
|
-
return (0, _util.createObjectURL)(data,
|
242
|
+
writePngChunk("IEND", new Uint8Array(0), data, offset);
|
243
|
+
return (0, _util.createObjectURL)(data, "image/png", forceDataSchema);
|
243
244
|
}
|
244
245
|
|
245
246
|
return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
|
246
|
-
|
247
|
+
const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
|
247
248
|
return encode(imgData, kind, forceDataSchema, isMask);
|
248
249
|
};
|
249
250
|
}();
|
250
251
|
|
251
|
-
|
252
|
-
|
252
|
+
class SVGExtraState {
|
253
|
+
constructor() {
|
253
254
|
this.fontSizeScale = 1;
|
254
255
|
this.fontWeight = SVG_DEFAULTS.fontWeight;
|
255
256
|
this.fontSize = 0;
|
@@ -257,6 +258,7 @@ exports.SVGGraphics = SVGGraphics;
|
|
257
258
|
this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
|
258
259
|
this.leading = 0;
|
259
260
|
this.textRenderingMode = _util.TextRenderingMode.FILL;
|
261
|
+
this.textMatrixScale = 1;
|
260
262
|
this.x = 0;
|
261
263
|
this.y = 0;
|
262
264
|
this.lineX = 0;
|
@@ -266,105 +268,106 @@ exports.SVGGraphics = SVGGraphics;
|
|
266
268
|
this.textHScale = 1;
|
267
269
|
this.textRise = 0;
|
268
270
|
this.fillColor = SVG_DEFAULTS.fillColor;
|
269
|
-
this.strokeColor =
|
271
|
+
this.strokeColor = "#000000";
|
270
272
|
this.fillAlpha = 1;
|
271
273
|
this.strokeAlpha = 1;
|
272
274
|
this.lineWidth = 1;
|
273
|
-
this.lineJoin =
|
274
|
-
this.lineCap =
|
275
|
+
this.lineJoin = "";
|
276
|
+
this.lineCap = "";
|
275
277
|
this.miterLimit = 0;
|
276
278
|
this.dashArray = [];
|
277
279
|
this.dashPhase = 0;
|
278
280
|
this.dependencies = [];
|
279
281
|
this.activeClipUrl = null;
|
280
282
|
this.clipGroup = null;
|
281
|
-
this.maskId =
|
283
|
+
this.maskId = "";
|
282
284
|
}
|
283
285
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
},
|
288
|
-
setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
|
289
|
-
this.x = x;
|
290
|
-
this.y = y;
|
291
|
-
}
|
292
|
-
};
|
293
|
-
return SVGExtraState;
|
294
|
-
}();
|
286
|
+
clone() {
|
287
|
+
return Object.create(this);
|
288
|
+
}
|
295
289
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
var opListLen = opList.length;
|
301
|
-
|
302
|
-
for (var x = 0; x < opListLen; x++) {
|
303
|
-
if (opList[x].fn === 'save') {
|
304
|
-
opTree.push({
|
305
|
-
'fnId': 92,
|
306
|
-
'fn': 'group',
|
307
|
-
'items': []
|
308
|
-
});
|
309
|
-
tmp.push(opTree);
|
310
|
-
opTree = opTree[opTree.length - 1].items;
|
311
|
-
continue;
|
312
|
-
}
|
290
|
+
setCurrentPoint(x, y) {
|
291
|
+
this.x = x;
|
292
|
+
this.y = y;
|
293
|
+
}
|
313
294
|
|
314
|
-
|
315
|
-
opTree = tmp.pop();
|
316
|
-
} else {
|
317
|
-
opTree.push(opList[x]);
|
318
|
-
}
|
319
|
-
}
|
295
|
+
}
|
320
296
|
|
321
|
-
|
322
|
-
|
297
|
+
function opListToTree(opList) {
|
298
|
+
let opTree = [];
|
299
|
+
const tmp = [];
|
323
300
|
|
324
|
-
|
325
|
-
if (
|
326
|
-
|
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;
|
327
311
|
}
|
328
312
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
return s;
|
313
|
+
if (opListElement.fn === "restore") {
|
314
|
+
opTree = tmp.pop();
|
315
|
+
} else {
|
316
|
+
opTree.push(opListElement);
|
334
317
|
}
|
318
|
+
}
|
335
319
|
|
336
|
-
|
337
|
-
|
338
|
-
} while (s[i] === '0');
|
320
|
+
return opTree;
|
321
|
+
}
|
339
322
|
|
340
|
-
|
323
|
+
function pf(value) {
|
324
|
+
if (Number.isInteger(value)) {
|
325
|
+
return value.toString();
|
341
326
|
}
|
342
327
|
|
343
|
-
|
344
|
-
|
345
|
-
if (m[1] === 0 && m[2] === 0) {
|
346
|
-
if (m[0] === 1 && m[3] === 1) {
|
347
|
-
return '';
|
348
|
-
}
|
328
|
+
const s = value.toFixed(10);
|
329
|
+
let i = s.length - 1;
|
349
330
|
|
350
|
-
|
351
|
-
|
331
|
+
if (s[i] !== "0") {
|
332
|
+
return s;
|
333
|
+
}
|
352
334
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
335
|
+
do {
|
336
|
+
i--;
|
337
|
+
} while (s[i] === "0");
|
338
|
+
|
339
|
+
return s.substring(0, s[i] === "." ? i : i + 1);
|
340
|
+
}
|
341
|
+
|
342
|
+
function pm(m) {
|
343
|
+
if (m[4] === 0 && m[5] === 0) {
|
344
|
+
if (m[1] === 0 && m[2] === 0) {
|
345
|
+
if (m[0] === 1 && m[3] === 1) {
|
346
|
+
return "";
|
360
347
|
}
|
348
|
+
|
349
|
+
return `scale(${pf(m[0])} ${pf(m[3])})`;
|
361
350
|
}
|
362
351
|
|
363
|
-
|
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
|
+
}
|
364
360
|
}
|
365
361
|
|
366
|
-
|
367
|
-
|
362
|
+
return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
|
363
|
+
}
|
364
|
+
|
365
|
+
let clipCount = 0;
|
366
|
+
let maskCount = 0;
|
367
|
+
let shadingCount = 0;
|
368
|
+
exports.SVGGraphics = SVGGraphics = class SVGGraphics {
|
369
|
+
constructor(commonObjs, objs, forceDataSchema = false) {
|
370
|
+
this.svgFactory = new _display_utils.DOMSVGFactory();
|
368
371
|
this.current = new SVGExtraState();
|
369
372
|
this.transformMatrix = _util.IDENTITY_MATRIX;
|
370
373
|
this.transformStack = [];
|
@@ -377,900 +380,1162 @@ exports.SVGGraphics = SVGGraphics;
|
|
377
380
|
this.embeddedFonts = Object.create(null);
|
378
381
|
this.cssStyle = null;
|
379
382
|
this.forceDataSchema = !!forceDataSchema;
|
383
|
+
this._operatorIdMapping = [];
|
384
|
+
|
385
|
+
for (const op in _util.OPS) {
|
386
|
+
this._operatorIdMapping[_util.OPS[op]] = op;
|
387
|
+
}
|
380
388
|
}
|
381
389
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
var fnArray = operatorList.fnArray;
|
410
|
-
var fnArrayLen = fnArray.length;
|
411
|
-
var argsArray = operatorList.argsArray;
|
412
|
-
|
413
|
-
for (var i = 0; i < fnArrayLen; i++) {
|
414
|
-
if (_util.OPS.dependency === fnArray[i]) {
|
415
|
-
var deps = argsArray[i];
|
416
|
-
|
417
|
-
for (var n = 0, nn = deps.length; n < nn; n++) {
|
418
|
-
var obj = deps[n];
|
419
|
-
var common = obj.substring(0, 2) === 'g_';
|
420
|
-
var promise;
|
421
|
-
|
422
|
-
if (common) {
|
423
|
-
promise = new Promise(function (resolve) {
|
424
|
-
_this.commonObjs.get(obj, resolve);
|
425
|
-
});
|
426
|
-
} else {
|
427
|
-
promise = new Promise(function (resolve) {
|
428
|
-
_this.objs.get(obj, resolve);
|
429
|
-
});
|
430
|
-
}
|
431
|
-
|
432
|
-
this.current.dependencies.push(promise);
|
433
|
-
}
|
434
|
-
}
|
390
|
+
save() {
|
391
|
+
this.transformStack.push(this.transformMatrix);
|
392
|
+
const old = this.current;
|
393
|
+
this.extraStack.push(old);
|
394
|
+
this.current = old.clone();
|
395
|
+
}
|
396
|
+
|
397
|
+
restore() {
|
398
|
+
this.transformMatrix = this.transformStack.pop();
|
399
|
+
this.current = this.extraStack.pop();
|
400
|
+
this.pendingClip = null;
|
401
|
+
this.tgrp = null;
|
402
|
+
}
|
403
|
+
|
404
|
+
group(items) {
|
405
|
+
this.save();
|
406
|
+
this.executeOpTree(items);
|
407
|
+
this.restore();
|
408
|
+
}
|
409
|
+
|
410
|
+
loadDependencies(operatorList) {
|
411
|
+
const fnArray = operatorList.fnArray;
|
412
|
+
const argsArray = operatorList.argsArray;
|
413
|
+
|
414
|
+
for (let i = 0, ii = fnArray.length; i < ii; i++) {
|
415
|
+
if (fnArray[i] !== _util.OPS.dependency) {
|
416
|
+
continue;
|
435
417
|
}
|
436
418
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
var _this2 = this;
|
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
|
+
}
|
426
|
+
}
|
446
427
|
|
447
|
-
|
428
|
+
return Promise.all(this.current.dependencies);
|
429
|
+
}
|
448
430
|
|
449
|
-
|
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
|
+
}
|
450
436
|
|
451
|
-
|
452
|
-
|
437
|
+
getSVG(operatorList, viewport) {
|
438
|
+
this.viewport = viewport;
|
453
439
|
|
454
|
-
|
440
|
+
const svgElement = this._initialize(viewport);
|
455
441
|
|
456
|
-
|
442
|
+
return this.loadDependencies(operatorList).then(() => {
|
443
|
+
this.transformMatrix = _util.IDENTITY_MATRIX;
|
444
|
+
this.executeOpTree(this.convertOpList(operatorList));
|
445
|
+
return svgElement;
|
446
|
+
});
|
447
|
+
}
|
457
448
|
|
458
|
-
|
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]
|
459
461
|
});
|
460
|
-
}
|
461
|
-
convertOpList: function SVGGraphics_convertOpList(operatorList) {
|
462
|
-
var argsArray = operatorList.argsArray;
|
463
|
-
var fnArray = operatorList.fnArray;
|
464
|
-
var fnArrayLen = fnArray.length;
|
465
|
-
var REVOPS = [];
|
466
|
-
var opList = [];
|
467
|
-
|
468
|
-
for (var op in _util.OPS) {
|
469
|
-
REVOPS[_util.OPS[op]] = op;
|
470
|
-
}
|
462
|
+
}
|
471
463
|
|
472
|
-
|
473
|
-
|
474
|
-
opList.push({
|
475
|
-
'fnId': fnId,
|
476
|
-
'fn': REVOPS[fnId],
|
477
|
-
'args': argsArray[x]
|
478
|
-
});
|
479
|
-
}
|
464
|
+
return opListToTree(opList);
|
465
|
+
}
|
480
466
|
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
467
|
+
executeOpTree(opTree) {
|
468
|
+
for (const opTreeElement of opTree) {
|
469
|
+
const fn = opTreeElement.fn;
|
470
|
+
const fnId = opTreeElement.fnId;
|
471
|
+
const args = opTreeElement.args;
|
485
472
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
473
|
+
switch (fnId | 0) {
|
474
|
+
case _util.OPS.beginText:
|
475
|
+
this.beginText();
|
476
|
+
break;
|
490
477
|
|
491
|
-
|
492
|
-
|
493
|
-
this.beginText();
|
494
|
-
break;
|
478
|
+
case _util.OPS.dependency:
|
479
|
+
break;
|
495
480
|
|
496
|
-
|
497
|
-
|
481
|
+
case _util.OPS.setLeading:
|
482
|
+
this.setLeading(args);
|
483
|
+
break;
|
498
484
|
|
499
|
-
|
500
|
-
|
501
|
-
|
485
|
+
case _util.OPS.setLeadingMoveText:
|
486
|
+
this.setLeadingMoveText(args[0], args[1]);
|
487
|
+
break;
|
502
488
|
|
503
|
-
|
504
|
-
|
505
|
-
|
489
|
+
case _util.OPS.setFont:
|
490
|
+
this.setFont(args);
|
491
|
+
break;
|
506
492
|
|
507
|
-
|
508
|
-
|
509
|
-
|
493
|
+
case _util.OPS.showText:
|
494
|
+
this.showText(args[0]);
|
495
|
+
break;
|
510
496
|
|
511
|
-
|
512
|
-
|
513
|
-
|
497
|
+
case _util.OPS.showSpacedText:
|
498
|
+
this.showText(args[0]);
|
499
|
+
break;
|
514
500
|
|
515
|
-
|
516
|
-
|
517
|
-
|
501
|
+
case _util.OPS.endText:
|
502
|
+
this.endText();
|
503
|
+
break;
|
518
504
|
|
519
|
-
|
520
|
-
|
521
|
-
|
505
|
+
case _util.OPS.moveText:
|
506
|
+
this.moveText(args[0], args[1]);
|
507
|
+
break;
|
522
508
|
|
523
|
-
|
524
|
-
|
525
|
-
|
509
|
+
case _util.OPS.setCharSpacing:
|
510
|
+
this.setCharSpacing(args[0]);
|
511
|
+
break;
|
526
512
|
|
527
|
-
|
528
|
-
|
529
|
-
|
513
|
+
case _util.OPS.setWordSpacing:
|
514
|
+
this.setWordSpacing(args[0]);
|
515
|
+
break;
|
530
516
|
|
531
|
-
|
532
|
-
|
533
|
-
|
517
|
+
case _util.OPS.setHScale:
|
518
|
+
this.setHScale(args[0]);
|
519
|
+
break;
|
534
520
|
|
535
|
-
|
536
|
-
|
537
|
-
|
521
|
+
case _util.OPS.setTextMatrix:
|
522
|
+
this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
|
523
|
+
break;
|
538
524
|
|
539
|
-
|
540
|
-
|
541
|
-
|
525
|
+
case _util.OPS.setTextRise:
|
526
|
+
this.setTextRise(args[0]);
|
527
|
+
break;
|
542
528
|
|
543
|
-
|
544
|
-
|
545
|
-
|
529
|
+
case _util.OPS.setTextRenderingMode:
|
530
|
+
this.setTextRenderingMode(args[0]);
|
531
|
+
break;
|
546
532
|
|
547
|
-
|
548
|
-
|
549
|
-
|
533
|
+
case _util.OPS.setLineWidth:
|
534
|
+
this.setLineWidth(args[0]);
|
535
|
+
break;
|
550
536
|
|
551
|
-
|
552
|
-
|
553
|
-
|
537
|
+
case _util.OPS.setLineJoin:
|
538
|
+
this.setLineJoin(args[0]);
|
539
|
+
break;
|
554
540
|
|
555
|
-
|
556
|
-
|
557
|
-
|
541
|
+
case _util.OPS.setLineCap:
|
542
|
+
this.setLineCap(args[0]);
|
543
|
+
break;
|
558
544
|
|
559
|
-
|
560
|
-
|
561
|
-
|
545
|
+
case _util.OPS.setMiterLimit:
|
546
|
+
this.setMiterLimit(args[0]);
|
547
|
+
break;
|
562
548
|
|
563
|
-
|
564
|
-
|
565
|
-
|
549
|
+
case _util.OPS.setFillRGBColor:
|
550
|
+
this.setFillRGBColor(args[0], args[1], args[2]);
|
551
|
+
break;
|
566
552
|
|
567
|
-
|
568
|
-
|
569
|
-
|
553
|
+
case _util.OPS.setStrokeRGBColor:
|
554
|
+
this.setStrokeRGBColor(args[0], args[1], args[2]);
|
555
|
+
break;
|
570
556
|
|
571
|
-
|
572
|
-
|
573
|
-
|
557
|
+
case _util.OPS.setStrokeColorN:
|
558
|
+
this.setStrokeColorN(args);
|
559
|
+
break;
|
574
560
|
|
575
|
-
|
576
|
-
|
577
|
-
|
561
|
+
case _util.OPS.setFillColorN:
|
562
|
+
this.setFillColorN(args);
|
563
|
+
break;
|
578
564
|
|
579
|
-
|
580
|
-
|
581
|
-
|
565
|
+
case _util.OPS.shadingFill:
|
566
|
+
this.shadingFill(args[0]);
|
567
|
+
break;
|
582
568
|
|
583
|
-
|
584
|
-
|
585
|
-
|
569
|
+
case _util.OPS.setDash:
|
570
|
+
this.setDash(args[0], args[1]);
|
571
|
+
break;
|
586
572
|
|
587
|
-
|
588
|
-
|
589
|
-
|
573
|
+
case _util.OPS.setRenderingIntent:
|
574
|
+
this.setRenderingIntent(args[0]);
|
575
|
+
break;
|
590
576
|
|
591
|
-
|
592
|
-
|
593
|
-
|
577
|
+
case _util.OPS.setFlatness:
|
578
|
+
this.setFlatness(args[0]);
|
579
|
+
break;
|
594
580
|
|
595
|
-
|
596
|
-
|
597
|
-
|
581
|
+
case _util.OPS.setGState:
|
582
|
+
this.setGState(args[0]);
|
583
|
+
break;
|
598
584
|
|
599
|
-
|
600
|
-
|
601
|
-
|
585
|
+
case _util.OPS.fill:
|
586
|
+
this.fill();
|
587
|
+
break;
|
602
588
|
|
603
|
-
|
604
|
-
|
605
|
-
|
589
|
+
case _util.OPS.eoFill:
|
590
|
+
this.eoFill();
|
591
|
+
break;
|
606
592
|
|
607
|
-
|
608
|
-
|
609
|
-
|
593
|
+
case _util.OPS.stroke:
|
594
|
+
this.stroke();
|
595
|
+
break;
|
610
596
|
|
611
|
-
|
612
|
-
|
613
|
-
|
597
|
+
case _util.OPS.fillStroke:
|
598
|
+
this.fillStroke();
|
599
|
+
break;
|
614
600
|
|
615
|
-
|
616
|
-
|
617
|
-
|
601
|
+
case _util.OPS.eoFillStroke:
|
602
|
+
this.eoFillStroke();
|
603
|
+
break;
|
618
604
|
|
619
|
-
|
620
|
-
|
621
|
-
|
605
|
+
case _util.OPS.clip:
|
606
|
+
this.clip("nonzero");
|
607
|
+
break;
|
622
608
|
|
623
|
-
|
624
|
-
|
625
|
-
|
609
|
+
case _util.OPS.eoClip:
|
610
|
+
this.clip("evenodd");
|
611
|
+
break;
|
626
612
|
|
627
|
-
|
628
|
-
|
629
|
-
|
613
|
+
case _util.OPS.paintSolidColorImageMask:
|
614
|
+
this.paintSolidColorImageMask();
|
615
|
+
break;
|
630
616
|
|
631
|
-
|
632
|
-
|
633
|
-
|
617
|
+
case _util.OPS.paintImageXObject:
|
618
|
+
this.paintImageXObject(args[0]);
|
619
|
+
break;
|
634
620
|
|
635
|
-
|
636
|
-
|
637
|
-
|
621
|
+
case _util.OPS.paintInlineImageXObject:
|
622
|
+
this.paintInlineImageXObject(args[0]);
|
623
|
+
break;
|
638
624
|
|
639
|
-
|
640
|
-
|
641
|
-
|
625
|
+
case _util.OPS.paintImageMaskXObject:
|
626
|
+
this.paintImageMaskXObject(args[0]);
|
627
|
+
break;
|
642
628
|
|
643
|
-
|
644
|
-
|
645
|
-
|
629
|
+
case _util.OPS.paintFormXObjectBegin:
|
630
|
+
this.paintFormXObjectBegin(args[0], args[1]);
|
631
|
+
break;
|
646
632
|
|
647
|
-
|
648
|
-
|
649
|
-
|
633
|
+
case _util.OPS.paintFormXObjectEnd:
|
634
|
+
this.paintFormXObjectEnd();
|
635
|
+
break;
|
650
636
|
|
651
|
-
|
652
|
-
|
653
|
-
|
637
|
+
case _util.OPS.closePath:
|
638
|
+
this.closePath();
|
639
|
+
break;
|
654
640
|
|
655
|
-
|
656
|
-
|
657
|
-
|
641
|
+
case _util.OPS.closeStroke:
|
642
|
+
this.closeStroke();
|
643
|
+
break;
|
658
644
|
|
659
|
-
|
660
|
-
|
661
|
-
|
645
|
+
case _util.OPS.closeFillStroke:
|
646
|
+
this.closeFillStroke();
|
647
|
+
break;
|
662
648
|
|
663
|
-
|
664
|
-
|
665
|
-
|
649
|
+
case _util.OPS.closeEOFillStroke:
|
650
|
+
this.closeEOFillStroke();
|
651
|
+
break;
|
666
652
|
|
667
|
-
|
668
|
-
|
669
|
-
|
653
|
+
case _util.OPS.nextLine:
|
654
|
+
this.nextLine();
|
655
|
+
break;
|
670
656
|
|
671
|
-
|
672
|
-
|
673
|
-
|
657
|
+
case _util.OPS.transform:
|
658
|
+
this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
|
659
|
+
break;
|
674
660
|
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
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;
|
679
676
|
}
|
680
|
-
}
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
677
|
+
}
|
678
|
+
}
|
679
|
+
|
680
|
+
setWordSpacing(wordSpacing) {
|
681
|
+
this.current.wordSpacing = wordSpacing;
|
682
|
+
}
|
683
|
+
|
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
|
+
}
|
721
|
+
|
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
|
+
}
|
733
|
+
|
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;
|
730
761
|
}
|
731
762
|
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
continue;
|
751
|
-
}
|
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;
|
780
|
+
}
|
752
781
|
|
753
|
-
|
754
|
-
|
755
|
-
var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
|
756
|
-
var charWidth = width * widthAdvanceScale + spacing * fontDirection;
|
782
|
+
if (glyph.isInFont || font.missingFile) {
|
783
|
+
current.xcoords.push(current.x + scaledX);
|
757
784
|
|
758
|
-
if (
|
759
|
-
|
760
|
-
continue;
|
785
|
+
if (vertical) {
|
786
|
+
current.ycoords.push(-current.y + scaledY);
|
761
787
|
}
|
762
788
|
|
763
|
-
current.xcoords.push(current.x + x * textHScale);
|
764
789
|
current.tspan.textContent += character;
|
765
|
-
|
766
|
-
|
790
|
+
} else {}
|
791
|
+
|
792
|
+
let charWidth;
|
767
793
|
|
768
794
|
if (vertical) {
|
769
|
-
|
795
|
+
charWidth = width * widthAdvanceScale - spacing * fontDirection;
|
770
796
|
} else {
|
771
|
-
|
797
|
+
charWidth = width * widthAdvanceScale + spacing * fontDirection;
|
772
798
|
}
|
773
799
|
|
774
|
-
|
775
|
-
|
776
|
-
current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
|
777
|
-
current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
|
800
|
+
x += charWidth;
|
801
|
+
}
|
778
802
|
|
779
|
-
|
780
|
-
current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
|
781
|
-
}
|
803
|
+
current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
|
782
804
|
|
783
|
-
|
784
|
-
|
785
|
-
|
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
|
+
}
|
786
810
|
|
787
|
-
|
811
|
+
if (vertical) {
|
812
|
+
current.y -= x;
|
813
|
+
} else {
|
814
|
+
current.x += x * textHScale;
|
815
|
+
}
|
788
816
|
|
789
|
-
|
790
|
-
|
791
|
-
current.tspan.setAttributeNS(null, 'fill', current.fillColor);
|
792
|
-
}
|
817
|
+
current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
|
818
|
+
current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
|
793
819
|
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
} else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
|
798
|
-
current.tspan.setAttributeNS(null, 'fill', 'transparent');
|
799
|
-
} else {
|
800
|
-
current.tspan.setAttributeNS(null, 'fill', 'none');
|
801
|
-
}
|
820
|
+
if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
|
821
|
+
current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
|
822
|
+
}
|
802
823
|
|
803
|
-
|
804
|
-
|
805
|
-
|
824
|
+
if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
|
825
|
+
current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
|
826
|
+
}
|
806
827
|
|
807
|
-
|
828
|
+
const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
|
808
829
|
|
809
|
-
|
810
|
-
|
811
|
-
|
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);
|
812
833
|
}
|
813
834
|
|
814
|
-
current.
|
815
|
-
|
816
|
-
current.txtElement.appendChild(current.tspan);
|
817
|
-
current.txtgrp.appendChild(current.txtElement);
|
818
|
-
|
819
|
-
this._ensureTransformGroup().appendChild(current.txtElement);
|
820
|
-
},
|
821
|
-
setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
|
822
|
-
this.setLeading(-y);
|
823
|
-
this.moveText(x, y);
|
824
|
-
},
|
825
|
-
addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
|
826
|
-
if (!this.cssStyle) {
|
827
|
-
this.cssStyle = this.svgFactory.createElement('svg:style');
|
828
|
-
this.cssStyle.setAttributeNS(null, 'type', 'text/css');
|
829
|
-
this.defs.appendChild(this.cssStyle);
|
835
|
+
if (current.fillAlpha < 1) {
|
836
|
+
current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
|
830
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");
|
842
|
+
}
|
831
843
|
|
832
|
-
|
833
|
-
|
834
|
-
},
|
835
|
-
setFont: function SVGGraphics_setFont(details) {
|
836
|
-
var current = this.current;
|
837
|
-
var fontObj = this.commonObjs.get(details[0]);
|
838
|
-
var size = details[1];
|
839
|
-
this.current.font = fontObj;
|
840
|
-
|
841
|
-
if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) {
|
842
|
-
this.addFontStyle(fontObj);
|
843
|
-
this.embeddedFonts[fontObj.loadedName] = fontObj;
|
844
|
-
}
|
844
|
+
if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
845
|
+
const lineWidthScale = 1 / (current.textMatrixScale || 1);
|
845
846
|
|
846
|
-
current.
|
847
|
-
|
848
|
-
var italic = fontObj.italic ? 'italic' : 'normal';
|
847
|
+
this._setStrokeAttributes(current.tspan, lineWidthScale);
|
848
|
+
}
|
849
849
|
|
850
|
-
|
851
|
-
size = -size;
|
852
|
-
current.fontDirection = -1;
|
853
|
-
} else {
|
854
|
-
current.fontDirection = 1;
|
855
|
-
}
|
850
|
+
let textMatrix = current.textMatrix;
|
856
851
|
|
857
|
-
|
858
|
-
|
859
|
-
current.
|
860
|
-
|
861
|
-
current.tspan = this.svgFactory.createElement('svg:tspan');
|
862
|
-
current.tspan.setAttributeNS(null, 'y', pf(-current.y));
|
863
|
-
current.xcoords = [];
|
864
|
-
},
|
865
|
-
endText: function endText() {
|
866
|
-
var current = this.current;
|
867
|
-
|
868
|
-
if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement && current.txtElement.hasChildNodes()) {
|
869
|
-
current.element = current.txtElement;
|
870
|
-
this.clip('nonzero');
|
871
|
-
this.endPath();
|
872
|
-
}
|
873
|
-
},
|
874
|
-
setLineWidth: function SVGGraphics_setLineWidth(width) {
|
875
|
-
if (width > 0) {
|
876
|
-
this.current.lineWidth = width;
|
877
|
-
}
|
878
|
-
},
|
879
|
-
setLineCap: function SVGGraphics_setLineCap(style) {
|
880
|
-
this.current.lineCap = LINE_CAP_STYLES[style];
|
881
|
-
},
|
882
|
-
setLineJoin: function SVGGraphics_setLineJoin(style) {
|
883
|
-
this.current.lineJoin = LINE_JOIN_STYLES[style];
|
884
|
-
},
|
885
|
-
setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
|
886
|
-
this.current.miterLimit = limit;
|
887
|
-
},
|
888
|
-
setStrokeAlpha: function SVGGraphics_setStrokeAlpha(strokeAlpha) {
|
889
|
-
this.current.strokeAlpha = strokeAlpha;
|
890
|
-
},
|
891
|
-
setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
|
892
|
-
var color = _util.Util.makeCssRgb(r, g, b);
|
893
|
-
|
894
|
-
this.current.strokeColor = color;
|
895
|
-
},
|
896
|
-
setFillAlpha: function SVGGraphics_setFillAlpha(fillAlpha) {
|
897
|
-
this.current.fillAlpha = fillAlpha;
|
898
|
-
},
|
899
|
-
setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
|
900
|
-
var color = _util.Util.makeCssRgb(r, g, b);
|
901
|
-
|
902
|
-
this.current.fillColor = color;
|
903
|
-
this.current.tspan = this.svgFactory.createElement('svg:tspan');
|
904
|
-
this.current.xcoords = [];
|
905
|
-
},
|
906
|
-
setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
|
907
|
-
this.current.dashArray = dashArray;
|
908
|
-
this.current.dashPhase = dashPhase;
|
909
|
-
},
|
910
|
-
constructPath: function SVGGraphics_constructPath(ops, args) {
|
911
|
-
var current = this.current;
|
912
|
-
var x = current.x,
|
913
|
-
y = current.y;
|
914
|
-
current.path = this.svgFactory.createElement('svg:path');
|
915
|
-
var d = [];
|
916
|
-
var opLength = ops.length;
|
917
|
-
|
918
|
-
for (var i = 0, j = 0; i < opLength; i++) {
|
919
|
-
switch (ops[i] | 0) {
|
920
|
-
case _util.OPS.rectangle:
|
921
|
-
x = args[j++];
|
922
|
-
y = args[j++];
|
923
|
-
var width = args[j++];
|
924
|
-
var height = args[j++];
|
925
|
-
var xw = x + width;
|
926
|
-
var yh = y + height;
|
927
|
-
d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z');
|
928
|
-
break;
|
852
|
+
if (current.textRise !== 0) {
|
853
|
+
textMatrix = textMatrix.slice();
|
854
|
+
textMatrix[5] += current.textRise;
|
855
|
+
}
|
929
856
|
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
break;
|
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);
|
935
861
|
|
936
|
-
|
937
|
-
|
938
|
-
y = args[j++];
|
939
|
-
d.push('L', pf(x), pf(y));
|
940
|
-
break;
|
862
|
+
this._ensureTransformGroup().appendChild(current.txtElement);
|
863
|
+
}
|
941
864
|
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
j += 6;
|
947
|
-
break;
|
865
|
+
setLeadingMoveText(x, y) {
|
866
|
+
this.setLeading(-y);
|
867
|
+
this.moveText(x, y);
|
868
|
+
}
|
948
869
|
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
870
|
+
addFontStyle(fontObj) {
|
871
|
+
if (!fontObj.data) {
|
872
|
+
throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
|
873
|
+
}
|
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);
|
879
|
+
}
|
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;
|
894
|
+
}
|
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";
|
903
|
+
}
|
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;
|
912
|
+
}
|
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;
|
955
926
|
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
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();
|
931
|
+
}
|
932
|
+
}
|
933
|
+
|
934
|
+
setLineWidth(width) {
|
935
|
+
if (width > 0) {
|
936
|
+
this.current.lineWidth = width;
|
937
|
+
}
|
938
|
+
}
|
939
|
+
|
940
|
+
setLineCap(style) {
|
941
|
+
this.current.lineCap = LINE_CAP_STYLES[style];
|
942
|
+
}
|
943
|
+
|
944
|
+
setLineJoin(style) {
|
945
|
+
this.current.lineJoin = LINE_JOIN_STYLES[style];
|
946
|
+
}
|
947
|
+
|
948
|
+
setMiterLimit(limit) {
|
949
|
+
this.current.miterLimit = limit;
|
950
|
+
}
|
951
|
+
|
952
|
+
setStrokeAlpha(strokeAlpha) {
|
953
|
+
this.current.strokeAlpha = strokeAlpha;
|
954
|
+
}
|
955
|
+
|
956
|
+
setStrokeRGBColor(r, g, b) {
|
957
|
+
this.current.strokeColor = _util.Util.makeCssRgb(r, g, b);
|
958
|
+
}
|
959
|
+
|
960
|
+
setFillAlpha(fillAlpha) {
|
961
|
+
this.current.fillAlpha = fillAlpha;
|
962
|
+
}
|
963
|
+
|
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
|
+
}
|
970
|
+
|
971
|
+
setStrokeColorN(args) {
|
972
|
+
this.current.strokeColor = this._makeColorN_Pattern(args);
|
973
|
+
}
|
974
|
+
|
975
|
+
setFillColorN(args) {
|
976
|
+
this.current.fillColor = this._makeColorN_Pattern(args);
|
977
|
+
}
|
978
|
+
|
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);
|
1006
|
+
}
|
1007
|
+
|
1008
|
+
this._ensureTransformGroup().appendChild(rect);
|
1009
|
+
}
|
1010
|
+
|
1011
|
+
_makeColorN_Pattern(args) {
|
1012
|
+
if (args[0] === "TilingPattern") {
|
1013
|
+
return this._makeTilingPattern(args);
|
1014
|
+
}
|
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]);
|
961
1087
|
break;
|
962
1088
|
|
963
|
-
case
|
964
|
-
|
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);
|
965
1103
|
break;
|
1104
|
+
|
1105
|
+
default:
|
1106
|
+
throw new Error(`Unknown RadialAxial type: ${args[1]}`);
|
966
1107
|
}
|
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);
|
1114
|
+
}
|
1115
|
+
|
1116
|
+
this.defs.appendChild(gradient);
|
1117
|
+
return `url(#${shadingId})`;
|
1118
|
+
|
1119
|
+
case "Mesh":
|
1120
|
+
(0, _util.warn)("Unimplemented pattern Mesh");
|
1121
|
+
return null;
|
1122
|
+
|
1123
|
+
case "Dummy":
|
1124
|
+
return "hotpink";
|
1125
|
+
|
1126
|
+
default:
|
1127
|
+
throw new Error(`Unknown IR type: ${args[0]}`);
|
1128
|
+
}
|
1129
|
+
}
|
1130
|
+
|
1131
|
+
setDash(dashArray, dashPhase) {
|
1132
|
+
this.current.dashArray = dashArray;
|
1133
|
+
this.current.dashPhase = dashPhase;
|
1134
|
+
}
|
1135
|
+
|
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;
|
967
1191
|
}
|
1192
|
+
}
|
1193
|
+
|
1194
|
+
d = d.join(" ");
|
968
1195
|
|
969
|
-
|
970
|
-
current.path.
|
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");
|
971
1200
|
|
972
1201
|
this._ensureTransformGroup().appendChild(current.path);
|
1202
|
+
}
|
973
1203
|
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
return;
|
980
|
-
}
|
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
|
+
}
|
981
1209
|
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
var clipPath = this.svgFactory.createElement('svg:clipPath');
|
986
|
-
clipPath.setAttributeNS(null, 'id', clipId);
|
987
|
-
clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
|
988
|
-
var clipElement = current.element.cloneNode(true);
|
1210
|
+
endPath() {
|
1211
|
+
const current = this.current;
|
1212
|
+
current.path = null;
|
989
1213
|
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
|
994
|
-
}
|
1214
|
+
if (!this.pendingClip) {
|
1215
|
+
return;
|
1216
|
+
}
|
995
1217
|
|
1218
|
+
if (!current.element) {
|
996
1219
|
this.pendingClip = null;
|
997
|
-
|
998
|
-
|
1220
|
+
return;
|
1221
|
+
}
|
999
1222
|
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
clipPath.setAttributeNS(null, 'clip-path', current.activeClipUrl);
|
1006
|
-
}
|
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);
|
1007
1228
|
|
1008
|
-
|
1009
|
-
|
1010
|
-
}
|
1011
|
-
|
1012
|
-
|
1013
|
-
},
|
1014
|
-
closePath: function SVGGraphics_closePath() {
|
1015
|
-
var current = this.current;
|
1016
|
-
|
1017
|
-
if (current.path) {
|
1018
|
-
var d = current.path.getAttributeNS(null, 'd');
|
1019
|
-
d += 'Z';
|
1020
|
-
current.path.setAttributeNS(null, 'd', d);
|
1021
|
-
}
|
1022
|
-
},
|
1023
|
-
setLeading: function SVGGraphics_setLeading(leading) {
|
1024
|
-
this.current.leading = -leading;
|
1025
|
-
},
|
1026
|
-
setTextRise: function SVGGraphics_setTextRise(textRise) {
|
1027
|
-
this.current.textRise = textRise;
|
1028
|
-
},
|
1029
|
-
setTextRenderingMode: function setTextRenderingMode(textRenderingMode) {
|
1030
|
-
this.current.textRenderingMode = textRenderingMode;
|
1031
|
-
},
|
1032
|
-
setHScale: function SVGGraphics_setHScale(scale) {
|
1033
|
-
this.current.textHScale = scale / 100;
|
1034
|
-
},
|
1035
|
-
setGState: function SVGGraphics_setGState(states) {
|
1036
|
-
for (var i = 0, ii = states.length; i < ii; i++) {
|
1037
|
-
var state = states[i];
|
1038
|
-
var key = state[0];
|
1039
|
-
var value = state[1];
|
1040
|
-
|
1041
|
-
switch (key) {
|
1042
|
-
case 'LW':
|
1043
|
-
this.setLineWidth(value);
|
1044
|
-
break;
|
1229
|
+
if (this.pendingClip === "evenodd") {
|
1230
|
+
clipElement.setAttributeNS(null, "clip-rule", "evenodd");
|
1231
|
+
} else {
|
1232
|
+
clipElement.setAttributeNS(null, "clip-rule", "nonzero");
|
1233
|
+
}
|
1045
1234
|
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1235
|
+
this.pendingClip = null;
|
1236
|
+
clipPath.appendChild(clipElement);
|
1237
|
+
this.defs.appendChild(clipPath);
|
1049
1238
|
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
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);
|
1245
|
+
}
|
1053
1246
|
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1247
|
+
current.activeClipUrl = `url(#${clipId})`;
|
1248
|
+
this.tgrp = null;
|
1249
|
+
}
|
1057
1250
|
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1251
|
+
clip(type) {
|
1252
|
+
this.pendingClip = type;
|
1253
|
+
}
|
1061
1254
|
|
1062
|
-
|
1063
|
-
|
1064
|
-
break;
|
1255
|
+
closePath() {
|
1256
|
+
const current = this.current;
|
1065
1257
|
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1258
|
+
if (current.path) {
|
1259
|
+
const d = `${current.path.getAttributeNS(null, "d")}Z`;
|
1260
|
+
current.path.setAttributeNS(null, "d", d);
|
1261
|
+
}
|
1262
|
+
}
|
1069
1263
|
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1264
|
+
setLeading(leading) {
|
1265
|
+
this.current.leading = -leading;
|
1266
|
+
}
|
1073
1267
|
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
}
|
1078
|
-
}
|
1079
|
-
},
|
1080
|
-
fill: function SVGGraphics_fill() {
|
1081
|
-
var current = this.current;
|
1082
|
-
|
1083
|
-
if (current.element) {
|
1084
|
-
current.element.setAttributeNS(null, 'fill', current.fillColor);
|
1085
|
-
current.element.setAttributeNS(null, 'fill-opacity', current.fillAlpha);
|
1086
|
-
this.endPath();
|
1087
|
-
}
|
1088
|
-
},
|
1089
|
-
stroke: function SVGGraphics_stroke() {
|
1090
|
-
var current = this.current;
|
1268
|
+
setTextRise(textRise) {
|
1269
|
+
this.current.textRise = textRise;
|
1270
|
+
}
|
1091
1271
|
|
1092
|
-
|
1093
|
-
|
1272
|
+
setTextRenderingMode(textRenderingMode) {
|
1273
|
+
this.current.textRenderingMode = textRenderingMode;
|
1274
|
+
}
|
1094
1275
|
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
}
|
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;
|
1114
1294
|
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1295
|
+
case "LJ":
|
1296
|
+
this.setLineJoin(value);
|
1297
|
+
break;
|
1298
|
+
|
1299
|
+
case "ML":
|
1300
|
+
this.setMiterLimit(value);
|
1301
|
+
break;
|
1302
|
+
|
1303
|
+
case "D":
|
1304
|
+
this.setDash(value[0], value[1]);
|
1305
|
+
break;
|
1306
|
+
|
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;
|
1124
1330
|
}
|
1331
|
+
}
|
1332
|
+
}
|
1125
1333
|
|
1126
|
-
|
1127
|
-
|
1128
|
-
closeStroke: function SVGGraphics_closeStroke() {
|
1129
|
-
this.closePath();
|
1130
|
-
this.stroke();
|
1131
|
-
},
|
1132
|
-
closeFillStroke: function SVGGraphics_closeFillStroke() {
|
1133
|
-
this.closePath();
|
1134
|
-
this.fillStroke();
|
1135
|
-
},
|
1136
|
-
closeEOFillStroke: function closeEOFillStroke() {
|
1137
|
-
this.closePath();
|
1138
|
-
this.eoFillStroke();
|
1139
|
-
},
|
1140
|
-
paintSolidColorImageMask: function SVGGraphics_paintSolidColorImageMask() {
|
1141
|
-
var current = this.current;
|
1142
|
-
var rect = this.svgFactory.createElement('svg:rect');
|
1143
|
-
rect.setAttributeNS(null, 'x', '0');
|
1144
|
-
rect.setAttributeNS(null, 'y', '0');
|
1145
|
-
rect.setAttributeNS(null, 'width', '1px');
|
1146
|
-
rect.setAttributeNS(null, 'height', '1px');
|
1147
|
-
rect.setAttributeNS(null, 'fill', current.fillColor);
|
1148
|
-
|
1149
|
-
this._ensureTransformGroup().appendChild(rect);
|
1150
|
-
},
|
1151
|
-
paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
|
1152
|
-
var imgObj = this.objs.get(objId);
|
1153
|
-
var imgEl = this.svgFactory.createElement('svg:image');
|
1154
|
-
imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
|
1155
|
-
imgEl.setAttributeNS(null, 'width', pf(w));
|
1156
|
-
imgEl.setAttributeNS(null, 'height', pf(h));
|
1157
|
-
imgEl.setAttributeNS(null, 'x', '0');
|
1158
|
-
imgEl.setAttributeNS(null, 'y', pf(-h));
|
1159
|
-
imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
|
1334
|
+
fill() {
|
1335
|
+
const current = this.current;
|
1160
1336
|
|
1337
|
+
if (current.element) {
|
1338
|
+
current.element.setAttributeNS(null, "fill", current.fillColor);
|
1339
|
+
current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
|
1340
|
+
this.endPath();
|
1341
|
+
}
|
1342
|
+
}
|
1343
|
+
|
1344
|
+
stroke() {
|
1345
|
+
const current = this.current;
|
1346
|
+
|
1347
|
+
if (current.element) {
|
1348
|
+
this._setStrokeAttributes(current.element);
|
1349
|
+
|
1350
|
+
current.element.setAttributeNS(null, "fill", "none");
|
1351
|
+
this.endPath();
|
1352
|
+
}
|
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
|
+
});
|
1363
|
+
}
|
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");
|
1378
|
+
}
|
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");
|
1391
|
+
}
|
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 = this.objs.get(objId);
|
1424
|
+
|
1425
|
+
if (!imgData) {
|
1426
|
+
(0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
|
1427
|
+
return;
|
1428
|
+
}
|
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 {
|
1161
1455
|
this._ensureTransformGroup().appendChild(imgEl);
|
1162
|
-
}
|
1163
|
-
|
1164
|
-
var imgData = this.objs.get(objId);
|
1456
|
+
}
|
1457
|
+
}
|
1165
1458
|
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
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
|
+
}
|
1480
|
+
|
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]);
|
1484
|
+
}
|
1170
1485
|
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
cliprect.setAttributeNS(null,
|
1179
|
-
cliprect.setAttributeNS(null, 'y', '0');
|
1180
|
-
cliprect.setAttributeNS(null, 'width', pf(width));
|
1181
|
-
cliprect.setAttributeNS(null, 'height', pf(height));
|
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));
|
1182
1494
|
this.current.element = cliprect;
|
1183
|
-
this.clip(
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
imgEl.setAttributeNS(null, 'y', pf(-height));
|
1188
|
-
imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
|
1189
|
-
imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
|
1190
|
-
imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / width) + ' ' + pf(-1 / height) + ')');
|
1191
|
-
|
1192
|
-
if (mask) {
|
1193
|
-
mask.appendChild(imgEl);
|
1194
|
-
} else {
|
1195
|
-
this._ensureTransformGroup().appendChild(imgEl);
|
1196
|
-
}
|
1197
|
-
},
|
1198
|
-
paintImageMaskXObject: function SVGGraphics_paintImageMaskXObject(imgData) {
|
1199
|
-
var current = this.current;
|
1200
|
-
var width = imgData.width;
|
1201
|
-
var height = imgData.height;
|
1202
|
-
var fillColor = current.fillColor;
|
1203
|
-
current.maskId = 'mask' + maskCount++;
|
1204
|
-
var mask = this.svgFactory.createElement('svg:mask');
|
1205
|
-
mask.setAttributeNS(null, 'id', current.maskId);
|
1206
|
-
var rect = this.svgFactory.createElement('svg:rect');
|
1207
|
-
rect.setAttributeNS(null, 'x', '0');
|
1208
|
-
rect.setAttributeNS(null, 'y', '0');
|
1209
|
-
rect.setAttributeNS(null, 'width', pf(width));
|
1210
|
-
rect.setAttributeNS(null, 'height', pf(height));
|
1211
|
-
rect.setAttributeNS(null, 'fill', fillColor);
|
1212
|
-
rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId + ')');
|
1213
|
-
this.defs.appendChild(mask);
|
1214
|
-
|
1215
|
-
this._ensureTransformGroup().appendChild(rect);
|
1216
|
-
|
1217
|
-
this.paintInlineImageXObject(imgData, mask);
|
1218
|
-
},
|
1219
|
-
paintFormXObjectBegin: function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
|
1220
|
-
if (Array.isArray(matrix) && matrix.length === 6) {
|
1221
|
-
this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
|
1222
|
-
}
|
1495
|
+
this.clip("nonzero");
|
1496
|
+
this.endPath();
|
1497
|
+
}
|
1498
|
+
}
|
1223
1499
|
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
paintFormXObjectEnd: function SVGGraphics_paintFormXObjectEnd() {},
|
1238
|
-
_initialize: function _initialize(viewport) {
|
1239
|
-
var svg = this.svgFactory.create(viewport.width, viewport.height);
|
1240
|
-
var definitions = this.svgFactory.createElement('svg:defs');
|
1241
|
-
svg.appendChild(definitions);
|
1242
|
-
this.defs = definitions;
|
1243
|
-
var rootGroup = this.svgFactory.createElement('svg:g');
|
1244
|
-
rootGroup.setAttributeNS(null, 'transform', pm(viewport.transform));
|
1245
|
-
svg.appendChild(rootGroup);
|
1246
|
-
this.svg = rootGroup;
|
1247
|
-
return svg;
|
1248
|
-
},
|
1249
|
-
_ensureClipGroup: function SVGGraphics_ensureClipGroup() {
|
1250
|
-
if (!this.current.clipGroup) {
|
1251
|
-
var clipGroup = this.svgFactory.createElement('svg:g');
|
1252
|
-
clipGroup.setAttributeNS(null, 'clip-path', this.current.activeClipUrl);
|
1253
|
-
this.svg.appendChild(clipGroup);
|
1254
|
-
this.current.clipGroup = clipGroup;
|
1255
|
-
}
|
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
|
+
}
|
1256
1513
|
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
if (this.current.activeClipUrl) {
|
1265
|
-
this._ensureClipGroup().appendChild(this.tgrp);
|
1266
|
-
} else {
|
1267
|
-
this.svg.appendChild(this.tgrp);
|
1268
|
-
}
|
1269
|
-
}
|
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;
|
1520
|
+
}
|
1270
1521
|
|
1271
|
-
|
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
|
+
}
|
1272
1535
|
}
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1536
|
+
|
1537
|
+
return this.tgrp;
|
1538
|
+
}
|
1539
|
+
|
1540
|
+
};
|
1276
1541
|
}
|