1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | (function webpackUniversalModuleDefinition(root, factory) {
|
24 | if(typeof exports === 'object' && typeof module === 'object')
|
25 | module.exports = factory();
|
26 | else if(typeof define === 'function' && define.amd)
|
27 | define("pdfjs-dist/build/pdf", [], factory);
|
28 | else if(typeof exports === 'object')
|
29 | exports["pdfjs-dist/build/pdf"] = factory();
|
30 | else
|
31 | root["pdfjs-dist/build/pdf"] = root.pdfjsLib = factory();
|
32 | })(this, function() {
|
33 | return (function(modules) {
|
34 |
|
35 | var installedModules = {};
|
36 |
|
37 |
|
38 | function __w_pdfjs_require__(moduleId) {
|
39 |
|
40 |
|
41 | if(installedModules[moduleId]) {
|
42 | return installedModules[moduleId].exports;
|
43 | }
|
44 |
|
45 | var module = installedModules[moduleId] = {
|
46 | i: moduleId,
|
47 | l: false,
|
48 | exports: {}
|
49 | };
|
50 |
|
51 |
|
52 | modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__);
|
53 |
|
54 |
|
55 | module.l = true;
|
56 |
|
57 |
|
58 | return module.exports;
|
59 | }
|
60 |
|
61 |
|
62 |
|
63 | __w_pdfjs_require__.m = modules;
|
64 |
|
65 |
|
66 | __w_pdfjs_require__.c = installedModules;
|
67 |
|
68 |
|
69 | __w_pdfjs_require__.d = function(exports, name, getter) {
|
70 | if(!__w_pdfjs_require__.o(exports, name)) {
|
71 | Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
72 | }
|
73 | };
|
74 |
|
75 |
|
76 | __w_pdfjs_require__.r = function(exports) {
|
77 | if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
78 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
79 | }
|
80 | Object.defineProperty(exports, '__esModule', { value: true });
|
81 | };
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | __w_pdfjs_require__.t = function(value, mode) {
|
89 | if(mode & 1) value = __w_pdfjs_require__(value);
|
90 | if(mode & 8) return value;
|
91 | if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
92 | var ns = Object.create(null);
|
93 | __w_pdfjs_require__.r(ns);
|
94 | Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
95 | if(mode & 2 && typeof value != 'string') for(var key in value) __w_pdfjs_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
96 | return ns;
|
97 | };
|
98 |
|
99 |
|
100 | __w_pdfjs_require__.n = function(module) {
|
101 | var getter = module && module.__esModule ?
|
102 | function getDefault() { return module['default']; } :
|
103 | function getModuleExports() { return module; };
|
104 | __w_pdfjs_require__.d(getter, 'a', getter);
|
105 | return getter;
|
106 | };
|
107 |
|
108 |
|
109 | __w_pdfjs_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
110 |
|
111 |
|
112 | __w_pdfjs_require__.p = "";
|
113 |
|
114 |
|
115 |
|
116 | return __w_pdfjs_require__(__w_pdfjs_require__.s = 0);
|
117 | })
|
118 |
|
119 | ([
|
120 |
|
121 | (function(module, exports, __w_pdfjs_require__) {
|
122 |
|
123 | "use strict";
|
124 |
|
125 |
|
126 | Object.defineProperty(exports, "__esModule", {
|
127 | value: true
|
128 | });
|
129 | Object.defineProperty(exports, "addLinkAttributes", {
|
130 | enumerable: true,
|
131 | get: function () {
|
132 | return _display_utils.addLinkAttributes;
|
133 | }
|
134 | });
|
135 | Object.defineProperty(exports, "getFilenameFromUrl", {
|
136 | enumerable: true,
|
137 | get: function () {
|
138 | return _display_utils.getFilenameFromUrl;
|
139 | }
|
140 | });
|
141 | Object.defineProperty(exports, "LinkTarget", {
|
142 | enumerable: true,
|
143 | get: function () {
|
144 | return _display_utils.LinkTarget;
|
145 | }
|
146 | });
|
147 | Object.defineProperty(exports, "loadScript", {
|
148 | enumerable: true,
|
149 | get: function () {
|
150 | return _display_utils.loadScript;
|
151 | }
|
152 | });
|
153 | Object.defineProperty(exports, "PDFDateString", {
|
154 | enumerable: true,
|
155 | get: function () {
|
156 | return _display_utils.PDFDateString;
|
157 | }
|
158 | });
|
159 | Object.defineProperty(exports, "RenderingCancelledException", {
|
160 | enumerable: true,
|
161 | get: function () {
|
162 | return _display_utils.RenderingCancelledException;
|
163 | }
|
164 | });
|
165 | Object.defineProperty(exports, "build", {
|
166 | enumerable: true,
|
167 | get: function () {
|
168 | return _api.build;
|
169 | }
|
170 | });
|
171 | Object.defineProperty(exports, "getDocument", {
|
172 | enumerable: true,
|
173 | get: function () {
|
174 | return _api.getDocument;
|
175 | }
|
176 | });
|
177 | Object.defineProperty(exports, "LoopbackPort", {
|
178 | enumerable: true,
|
179 | get: function () {
|
180 | return _api.LoopbackPort;
|
181 | }
|
182 | });
|
183 | Object.defineProperty(exports, "PDFDataRangeTransport", {
|
184 | enumerable: true,
|
185 | get: function () {
|
186 | return _api.PDFDataRangeTransport;
|
187 | }
|
188 | });
|
189 | Object.defineProperty(exports, "PDFWorker", {
|
190 | enumerable: true,
|
191 | get: function () {
|
192 | return _api.PDFWorker;
|
193 | }
|
194 | });
|
195 | Object.defineProperty(exports, "version", {
|
196 | enumerable: true,
|
197 | get: function () {
|
198 | return _api.version;
|
199 | }
|
200 | });
|
201 | Object.defineProperty(exports, "CMapCompressionType", {
|
202 | enumerable: true,
|
203 | get: function () {
|
204 | return _util.CMapCompressionType;
|
205 | }
|
206 | });
|
207 | Object.defineProperty(exports, "createObjectURL", {
|
208 | enumerable: true,
|
209 | get: function () {
|
210 | return _util.createObjectURL;
|
211 | }
|
212 | });
|
213 | Object.defineProperty(exports, "createPromiseCapability", {
|
214 | enumerable: true,
|
215 | get: function () {
|
216 | return _util.createPromiseCapability;
|
217 | }
|
218 | });
|
219 | Object.defineProperty(exports, "createValidAbsoluteUrl", {
|
220 | enumerable: true,
|
221 | get: function () {
|
222 | return _util.createValidAbsoluteUrl;
|
223 | }
|
224 | });
|
225 | Object.defineProperty(exports, "InvalidPDFException", {
|
226 | enumerable: true,
|
227 | get: function () {
|
228 | return _util.InvalidPDFException;
|
229 | }
|
230 | });
|
231 | Object.defineProperty(exports, "MissingPDFException", {
|
232 | enumerable: true,
|
233 | get: function () {
|
234 | return _util.MissingPDFException;
|
235 | }
|
236 | });
|
237 | Object.defineProperty(exports, "OPS", {
|
238 | enumerable: true,
|
239 | get: function () {
|
240 | return _util.OPS;
|
241 | }
|
242 | });
|
243 | Object.defineProperty(exports, "PasswordResponses", {
|
244 | enumerable: true,
|
245 | get: function () {
|
246 | return _util.PasswordResponses;
|
247 | }
|
248 | });
|
249 | Object.defineProperty(exports, "PermissionFlag", {
|
250 | enumerable: true,
|
251 | get: function () {
|
252 | return _util.PermissionFlag;
|
253 | }
|
254 | });
|
255 | Object.defineProperty(exports, "removeNullCharacters", {
|
256 | enumerable: true,
|
257 | get: function () {
|
258 | return _util.removeNullCharacters;
|
259 | }
|
260 | });
|
261 | Object.defineProperty(exports, "shadow", {
|
262 | enumerable: true,
|
263 | get: function () {
|
264 | return _util.shadow;
|
265 | }
|
266 | });
|
267 | Object.defineProperty(exports, "UnexpectedResponseException", {
|
268 | enumerable: true,
|
269 | get: function () {
|
270 | return _util.UnexpectedResponseException;
|
271 | }
|
272 | });
|
273 | Object.defineProperty(exports, "UNSUPPORTED_FEATURES", {
|
274 | enumerable: true,
|
275 | get: function () {
|
276 | return _util.UNSUPPORTED_FEATURES;
|
277 | }
|
278 | });
|
279 | Object.defineProperty(exports, "Util", {
|
280 | enumerable: true,
|
281 | get: function () {
|
282 | return _util.Util;
|
283 | }
|
284 | });
|
285 | Object.defineProperty(exports, "VerbosityLevel", {
|
286 | enumerable: true,
|
287 | get: function () {
|
288 | return _util.VerbosityLevel;
|
289 | }
|
290 | });
|
291 | Object.defineProperty(exports, "AnnotationLayer", {
|
292 | enumerable: true,
|
293 | get: function () {
|
294 | return _annotation_layer.AnnotationLayer;
|
295 | }
|
296 | });
|
297 | Object.defineProperty(exports, "apiCompatibilityParams", {
|
298 | enumerable: true,
|
299 | get: function () {
|
300 | return _api_compatibility.apiCompatibilityParams;
|
301 | }
|
302 | });
|
303 | Object.defineProperty(exports, "GlobalWorkerOptions", {
|
304 | enumerable: true,
|
305 | get: function () {
|
306 | return _worker_options.GlobalWorkerOptions;
|
307 | }
|
308 | });
|
309 | Object.defineProperty(exports, "renderTextLayer", {
|
310 | enumerable: true,
|
311 | get: function () {
|
312 | return _text_layer.renderTextLayer;
|
313 | }
|
314 | });
|
315 | Object.defineProperty(exports, "SVGGraphics", {
|
316 | enumerable: true,
|
317 | get: function () {
|
318 | return _svg.SVGGraphics;
|
319 | }
|
320 | });
|
321 |
|
322 | var _display_utils = __w_pdfjs_require__(1);
|
323 |
|
324 | var _api = __w_pdfjs_require__(5);
|
325 |
|
326 | var _util = __w_pdfjs_require__(2);
|
327 |
|
328 | var _annotation_layer = __w_pdfjs_require__(16);
|
329 |
|
330 | var _api_compatibility = __w_pdfjs_require__(7);
|
331 |
|
332 | var _worker_options = __w_pdfjs_require__(10);
|
333 |
|
334 | var _text_layer = __w_pdfjs_require__(17);
|
335 |
|
336 | var _svg = __w_pdfjs_require__(18);
|
337 |
|
338 | const pdfjsVersion = '2.5.207';
|
339 | const pdfjsBuild = '0974d605';
|
340 | {
|
341 | const {
|
342 | isNodeJS
|
343 | } = __w_pdfjs_require__(4);
|
344 |
|
345 | if (isNodeJS) {
|
346 | const PDFNodeStream = __w_pdfjs_require__(19).PDFNodeStream;
|
347 |
|
348 | (0, _api.setPDFNetworkStreamFactory)(params => {
|
349 | return new PDFNodeStream(params);
|
350 | });
|
351 | } else {
|
352 | const PDFNetworkStream = __w_pdfjs_require__(22).PDFNetworkStream;
|
353 |
|
354 | let PDFFetchStream;
|
355 |
|
356 | if ((0, _display_utils.isFetchSupported)()) {
|
357 | PDFFetchStream = __w_pdfjs_require__(23).PDFFetchStream;
|
358 | }
|
359 |
|
360 | (0, _api.setPDFNetworkStreamFactory)(params => {
|
361 | if (PDFFetchStream && (0, _display_utils.isValidFetchUrl)(params.url)) {
|
362 | return new PDFFetchStream(params);
|
363 | }
|
364 |
|
365 | return new PDFNetworkStream(params);
|
366 | });
|
367 | }
|
368 | }
|
369 |
|
370 | }),
|
371 |
|
372 | (function(module, exports, __w_pdfjs_require__) {
|
373 |
|
374 | "use strict";
|
375 |
|
376 |
|
377 | Object.defineProperty(exports, "__esModule", {
|
378 | value: true
|
379 | });
|
380 | exports.addLinkAttributes = addLinkAttributes;
|
381 | exports.getFilenameFromUrl = getFilenameFromUrl;
|
382 | exports.isFetchSupported = isFetchSupported;
|
383 | exports.isValidFetchUrl = isValidFetchUrl;
|
384 | exports.loadScript = loadScript;
|
385 | exports.deprecated = deprecated;
|
386 | exports.PDFDateString = exports.StatTimer = exports.DOMSVGFactory = exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = exports.DEFAULT_LINK_REL = exports.LinkTarget = exports.RenderingCancelledException = exports.PageViewport = void 0;
|
387 |
|
388 | var _util = __w_pdfjs_require__(2);
|
389 |
|
390 | const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
|
391 | exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL;
|
392 | const SVG_NS = "http://www.w3.org/2000/svg";
|
393 |
|
394 | class DOMCanvasFactory {
|
395 | create(width, height) {
|
396 | if (width <= 0 || height <= 0) {
|
397 | throw new Error("Invalid canvas size");
|
398 | }
|
399 |
|
400 | const canvas = document.createElement("canvas");
|
401 | const context = canvas.getContext("2d");
|
402 | canvas.width = width;
|
403 | canvas.height = height;
|
404 | return {
|
405 | canvas,
|
406 | context
|
407 | };
|
408 | }
|
409 |
|
410 | reset(canvasAndContext, width, height) {
|
411 | if (!canvasAndContext.canvas) {
|
412 | throw new Error("Canvas is not specified");
|
413 | }
|
414 |
|
415 | if (width <= 0 || height <= 0) {
|
416 | throw new Error("Invalid canvas size");
|
417 | }
|
418 |
|
419 | canvasAndContext.canvas.width = width;
|
420 | canvasAndContext.canvas.height = height;
|
421 | }
|
422 |
|
423 | destroy(canvasAndContext) {
|
424 | if (!canvasAndContext.canvas) {
|
425 | throw new Error("Canvas is not specified");
|
426 | }
|
427 |
|
428 | canvasAndContext.canvas.width = 0;
|
429 | canvasAndContext.canvas.height = 0;
|
430 | canvasAndContext.canvas = null;
|
431 | canvasAndContext.context = null;
|
432 | }
|
433 |
|
434 | }
|
435 |
|
436 | exports.DOMCanvasFactory = DOMCanvasFactory;
|
437 |
|
438 | class DOMCMapReaderFactory {
|
439 | constructor({
|
440 | baseUrl = null,
|
441 | isCompressed = false
|
442 | }) {
|
443 | this.baseUrl = baseUrl;
|
444 | this.isCompressed = isCompressed;
|
445 | }
|
446 |
|
447 | async fetch({
|
448 | name
|
449 | }) {
|
450 | if (!this.baseUrl) {
|
451 | throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
|
452 | }
|
453 |
|
454 | if (!name) {
|
455 | throw new Error("CMap name must be specified.");
|
456 | }
|
457 |
|
458 | const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
|
459 | const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
|
460 |
|
461 | if (isFetchSupported() && isValidFetchUrl(url, document.baseURI)) {
|
462 | return fetch(url).then(async response => {
|
463 | if (!response.ok) {
|
464 | throw new Error(response.statusText);
|
465 | }
|
466 |
|
467 | let cMapData;
|
468 |
|
469 | if (this.isCompressed) {
|
470 | cMapData = new Uint8Array(await response.arrayBuffer());
|
471 | } else {
|
472 | cMapData = (0, _util.stringToBytes)(await response.text());
|
473 | }
|
474 |
|
475 | return {
|
476 | cMapData,
|
477 | compressionType
|
478 | };
|
479 | }).catch(reason => {
|
480 | throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}` + `CMap at: ${url}`);
|
481 | });
|
482 | }
|
483 |
|
484 | return new Promise((resolve, reject) => {
|
485 | const request = new XMLHttpRequest();
|
486 | request.open("GET", url, true);
|
487 |
|
488 | if (this.isCompressed) {
|
489 | request.responseType = "arraybuffer";
|
490 | }
|
491 |
|
492 | request.onreadystatechange = () => {
|
493 | if (request.readyState !== XMLHttpRequest.DONE) {
|
494 | return;
|
495 | }
|
496 |
|
497 | if (request.status === 200 || request.status === 0) {
|
498 | let cMapData;
|
499 |
|
500 | if (this.isCompressed && request.response) {
|
501 | cMapData = new Uint8Array(request.response);
|
502 | } else if (!this.isCompressed && request.responseText) {
|
503 | cMapData = (0, _util.stringToBytes)(request.responseText);
|
504 | }
|
505 |
|
506 | if (cMapData) {
|
507 | resolve({
|
508 | cMapData,
|
509 | compressionType
|
510 | });
|
511 | return;
|
512 | }
|
513 | }
|
514 |
|
515 | reject(new Error(request.statusText));
|
516 | };
|
517 |
|
518 | request.send(null);
|
519 | }).catch(reason => {
|
520 | throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}` + `CMap at: ${url}`);
|
521 | });
|
522 | }
|
523 |
|
524 | }
|
525 |
|
526 | exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
|
527 |
|
528 | class DOMSVGFactory {
|
529 | create(width, height) {
|
530 | (0, _util.assert)(width > 0 && height > 0, "Invalid SVG dimensions");
|
531 | const svg = document.createElementNS(SVG_NS, "svg:svg");
|
532 | svg.setAttribute("version", "1.1");
|
533 | svg.setAttribute("width", width + "px");
|
534 | svg.setAttribute("height", height + "px");
|
535 | svg.setAttribute("preserveAspectRatio", "none");
|
536 | svg.setAttribute("viewBox", "0 0 " + width + " " + height);
|
537 | return svg;
|
538 | }
|
539 |
|
540 | createElement(type) {
|
541 | (0, _util.assert)(typeof type === "string", "Invalid SVG element type");
|
542 | return document.createElementNS(SVG_NS, type);
|
543 | }
|
544 |
|
545 | }
|
546 |
|
547 | exports.DOMSVGFactory = DOMSVGFactory;
|
548 |
|
549 | class PageViewport {
|
550 | constructor({
|
551 | viewBox,
|
552 | scale,
|
553 | rotation,
|
554 | offsetX = 0,
|
555 | offsetY = 0,
|
556 | dontFlip = false
|
557 | }) {
|
558 | this.viewBox = viewBox;
|
559 | this.scale = scale;
|
560 | this.rotation = rotation;
|
561 | this.offsetX = offsetX;
|
562 | this.offsetY = offsetY;
|
563 | const centerX = (viewBox[2] + viewBox[0]) / 2;
|
564 | const centerY = (viewBox[3] + viewBox[1]) / 2;
|
565 | let rotateA, rotateB, rotateC, rotateD;
|
566 | rotation = rotation % 360;
|
567 | rotation = rotation < 0 ? rotation + 360 : rotation;
|
568 |
|
569 | switch (rotation) {
|
570 | case 180:
|
571 | rotateA = -1;
|
572 | rotateB = 0;
|
573 | rotateC = 0;
|
574 | rotateD = 1;
|
575 | break;
|
576 |
|
577 | case 90:
|
578 | rotateA = 0;
|
579 | rotateB = 1;
|
580 | rotateC = 1;
|
581 | rotateD = 0;
|
582 | break;
|
583 |
|
584 | case 270:
|
585 | rotateA = 0;
|
586 | rotateB = -1;
|
587 | rotateC = -1;
|
588 | rotateD = 0;
|
589 | break;
|
590 |
|
591 | case 0:
|
592 | rotateA = 1;
|
593 | rotateB = 0;
|
594 | rotateC = 0;
|
595 | rotateD = -1;
|
596 | break;
|
597 |
|
598 | default:
|
599 | throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
|
600 | }
|
601 |
|
602 | if (dontFlip) {
|
603 | rotateC = -rotateC;
|
604 | rotateD = -rotateD;
|
605 | }
|
606 |
|
607 | let offsetCanvasX, offsetCanvasY;
|
608 | let width, height;
|
609 |
|
610 | if (rotateA === 0) {
|
611 | offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
|
612 | offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
|
613 | width = Math.abs(viewBox[3] - viewBox[1]) * scale;
|
614 | height = Math.abs(viewBox[2] - viewBox[0]) * scale;
|
615 | } else {
|
616 | offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
|
617 | offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
|
618 | width = Math.abs(viewBox[2] - viewBox[0]) * scale;
|
619 | height = Math.abs(viewBox[3] - viewBox[1]) * scale;
|
620 | }
|
621 |
|
622 | this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
|
623 | this.width = width;
|
624 | this.height = height;
|
625 | }
|
626 |
|
627 | clone({
|
628 | scale = this.scale,
|
629 | rotation = this.rotation,
|
630 | offsetX = this.offsetX,
|
631 | offsetY = this.offsetY,
|
632 | dontFlip = false
|
633 | } = {}) {
|
634 | return new PageViewport({
|
635 | viewBox: this.viewBox.slice(),
|
636 | scale,
|
637 | rotation,
|
638 | offsetX,
|
639 | offsetY,
|
640 | dontFlip
|
641 | });
|
642 | }
|
643 |
|
644 | convertToViewportPoint(x, y) {
|
645 | return _util.Util.applyTransform([x, y], this.transform);
|
646 | }
|
647 |
|
648 | convertToViewportRectangle(rect) {
|
649 | const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
|
650 |
|
651 | const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
|
652 |
|
653 | return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
|
654 | }
|
655 |
|
656 | convertToPdfPoint(x, y) {
|
657 | return _util.Util.applyInverseTransform([x, y], this.transform);
|
658 | }
|
659 |
|
660 | }
|
661 |
|
662 | exports.PageViewport = PageViewport;
|
663 |
|
664 | class RenderingCancelledException extends _util.BaseException {
|
665 | constructor(msg, type) {
|
666 | super(msg);
|
667 | this.type = type;
|
668 | }
|
669 |
|
670 | }
|
671 |
|
672 | exports.RenderingCancelledException = RenderingCancelledException;
|
673 | const LinkTarget = {
|
674 | NONE: 0,
|
675 | SELF: 1,
|
676 | BLANK: 2,
|
677 | PARENT: 3,
|
678 | TOP: 4
|
679 | };
|
680 | exports.LinkTarget = LinkTarget;
|
681 |
|
682 | function addLinkAttributes(link, {
|
683 | url,
|
684 | target,
|
685 | rel,
|
686 | enabled = true
|
687 | } = {}) {
|
688 | (0, _util.assert)(url && typeof url === "string", 'addLinkAttributes: A valid "url" parameter must provided.');
|
689 | const urlNullRemoved = (0, _util.removeNullCharacters)(url);
|
690 |
|
691 | if (enabled) {
|
692 | link.href = link.title = urlNullRemoved;
|
693 | } else {
|
694 | link.href = "";
|
695 | link.title = `Disabled: ${urlNullRemoved}`;
|
696 |
|
697 | link.onclick = () => {
|
698 | return false;
|
699 | };
|
700 | }
|
701 |
|
702 | let targetStr = "";
|
703 |
|
704 | switch (target) {
|
705 | case LinkTarget.NONE:
|
706 | break;
|
707 |
|
708 | case LinkTarget.SELF:
|
709 | targetStr = "_self";
|
710 | break;
|
711 |
|
712 | case LinkTarget.BLANK:
|
713 | targetStr = "_blank";
|
714 | break;
|
715 |
|
716 | case LinkTarget.PARENT:
|
717 | targetStr = "_parent";
|
718 | break;
|
719 |
|
720 | case LinkTarget.TOP:
|
721 | targetStr = "_top";
|
722 | break;
|
723 | }
|
724 |
|
725 | link.target = targetStr;
|
726 | link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
|
727 | }
|
728 |
|
729 | function getFilenameFromUrl(url) {
|
730 | const anchor = url.indexOf("#");
|
731 | const query = url.indexOf("?");
|
732 | const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
|
733 | return url.substring(url.lastIndexOf("/", end) + 1, end);
|
734 | }
|
735 |
|
736 | class StatTimer {
|
737 | constructor() {
|
738 | this.started = Object.create(null);
|
739 | this.times = [];
|
740 | }
|
741 |
|
742 | time(name) {
|
743 | if (name in this.started) {
|
744 | (0, _util.warn)(`Timer is already running for ${name}`);
|
745 | }
|
746 |
|
747 | this.started[name] = Date.now();
|
748 | }
|
749 |
|
750 | timeEnd(name) {
|
751 | if (!(name in this.started)) {
|
752 | (0, _util.warn)(`Timer has not been started for ${name}`);
|
753 | }
|
754 |
|
755 | this.times.push({
|
756 | name,
|
757 | start: this.started[name],
|
758 | end: Date.now()
|
759 | });
|
760 | delete this.started[name];
|
761 | }
|
762 |
|
763 | toString() {
|
764 | const outBuf = [];
|
765 | let longest = 0;
|
766 |
|
767 | for (const time of this.times) {
|
768 | const name = time.name;
|
769 |
|
770 | if (name.length > longest) {
|
771 | longest = name.length;
|
772 | }
|
773 | }
|
774 |
|
775 | for (const time of this.times) {
|
776 | const duration = time.end - time.start;
|
777 | outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
|
778 | }
|
779 |
|
780 | return outBuf.join("");
|
781 | }
|
782 |
|
783 | }
|
784 |
|
785 | exports.StatTimer = StatTimer;
|
786 |
|
787 | function isFetchSupported() {
|
788 | return typeof fetch !== "undefined" && typeof Response !== "undefined" && "body" in Response.prototype && typeof ReadableStream !== "undefined";
|
789 | }
|
790 |
|
791 | function isValidFetchUrl(url, baseUrl) {
|
792 | try {
|
793 | const {
|
794 | protocol
|
795 | } = baseUrl ? new URL(url, baseUrl) : new URL(url);
|
796 | return protocol === "http:" || protocol === "https:";
|
797 | } catch (ex) {
|
798 | return false;
|
799 | }
|
800 | }
|
801 |
|
802 | function loadScript(src) {
|
803 | return new Promise((resolve, reject) => {
|
804 | const script = document.createElement("script");
|
805 | script.src = src;
|
806 | script.onload = resolve;
|
807 |
|
808 | script.onerror = function () {
|
809 | reject(new Error(`Cannot load script at: ${script.src}`));
|
810 | };
|
811 |
|
812 | (document.head || document.documentElement).appendChild(script);
|
813 | });
|
814 | }
|
815 |
|
816 | function deprecated(details) {
|
817 | console.log("Deprecated API usage: " + details);
|
818 | }
|
819 |
|
820 | let pdfDateStringRegex;
|
821 |
|
822 | class PDFDateString {
|
823 | static toDateObject(input) {
|
824 | if (!input || !(0, _util.isString)(input)) {
|
825 | return null;
|
826 | }
|
827 |
|
828 | if (!pdfDateStringRegex) {
|
829 | pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
|
830 | }
|
831 |
|
832 | const matches = pdfDateStringRegex.exec(input);
|
833 |
|
834 | if (!matches) {
|
835 | return null;
|
836 | }
|
837 |
|
838 | const year = parseInt(matches[1], 10);
|
839 | let month = parseInt(matches[2], 10);
|
840 | month = month >= 1 && month <= 12 ? month - 1 : 0;
|
841 | let day = parseInt(matches[3], 10);
|
842 | day = day >= 1 && day <= 31 ? day : 1;
|
843 | let hour = parseInt(matches[4], 10);
|
844 | hour = hour >= 0 && hour <= 23 ? hour : 0;
|
845 | let minute = parseInt(matches[5], 10);
|
846 | minute = minute >= 0 && minute <= 59 ? minute : 0;
|
847 | let second = parseInt(matches[6], 10);
|
848 | second = second >= 0 && second <= 59 ? second : 0;
|
849 | const universalTimeRelation = matches[7] || "Z";
|
850 | let offsetHour = parseInt(matches[8], 10);
|
851 | offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
|
852 | let offsetMinute = parseInt(matches[9], 10) || 0;
|
853 | offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
|
854 |
|
855 | if (universalTimeRelation === "-") {
|
856 | hour += offsetHour;
|
857 | minute += offsetMinute;
|
858 | } else if (universalTimeRelation === "+") {
|
859 | hour -= offsetHour;
|
860 | minute -= offsetMinute;
|
861 | }
|
862 |
|
863 | return new Date(Date.UTC(year, month, day, hour, minute, second));
|
864 | }
|
865 |
|
866 | }
|
867 |
|
868 | exports.PDFDateString = PDFDateString;
|
869 |
|
870 | }),
|
871 |
|
872 | (function(module, exports, __w_pdfjs_require__) {
|
873 |
|
874 | "use strict";
|
875 |
|
876 |
|
877 | Object.defineProperty(exports, "__esModule", {
|
878 | value: true
|
879 | });
|
880 | exports.arrayByteLength = arrayByteLength;
|
881 | exports.arraysToBytes = arraysToBytes;
|
882 | exports.assert = assert;
|
883 | exports.bytesToString = bytesToString;
|
884 | exports.createPromiseCapability = createPromiseCapability;
|
885 | exports.getVerbosityLevel = getVerbosityLevel;
|
886 | exports.info = info;
|
887 | exports.isArrayBuffer = isArrayBuffer;
|
888 | exports.isArrayEqual = isArrayEqual;
|
889 | exports.isBool = isBool;
|
890 | exports.isEmptyObj = isEmptyObj;
|
891 | exports.isNum = isNum;
|
892 | exports.isString = isString;
|
893 | exports.isSameOrigin = isSameOrigin;
|
894 | exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
|
895 | exports.removeNullCharacters = removeNullCharacters;
|
896 | exports.setVerbosityLevel = setVerbosityLevel;
|
897 | exports.shadow = shadow;
|
898 | exports.string32 = string32;
|
899 | exports.stringToBytes = stringToBytes;
|
900 | exports.stringToPDFString = stringToPDFString;
|
901 | exports.stringToUTF8String = stringToUTF8String;
|
902 | exports.utf8StringToString = utf8StringToString;
|
903 | exports.warn = warn;
|
904 | exports.unreachable = unreachable;
|
905 | exports.IsEvalSupportedCached = exports.IsLittleEndianCached = exports.createObjectURL = exports.FormatError = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.MissingPDFException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = exports.BaseException = void 0;
|
906 |
|
907 | __w_pdfjs_require__(3);
|
908 |
|
909 | const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
|
910 | exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
|
911 | const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
|
912 | exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
|
913 | const PermissionFlag = {
|
914 | PRINT: 0x04,
|
915 | MODIFY_CONTENTS: 0x08,
|
916 | COPY: 0x10,
|
917 | MODIFY_ANNOTATIONS: 0x20,
|
918 | FILL_INTERACTIVE_FORMS: 0x100,
|
919 | COPY_FOR_ACCESSIBILITY: 0x200,
|
920 | ASSEMBLE: 0x400,
|
921 | PRINT_HIGH_QUALITY: 0x800
|
922 | };
|
923 | exports.PermissionFlag = PermissionFlag;
|
924 | const TextRenderingMode = {
|
925 | FILL: 0,
|
926 | STROKE: 1,
|
927 | FILL_STROKE: 2,
|
928 | INVISIBLE: 3,
|
929 | FILL_ADD_TO_PATH: 4,
|
930 | STROKE_ADD_TO_PATH: 5,
|
931 | FILL_STROKE_ADD_TO_PATH: 6,
|
932 | ADD_TO_PATH: 7,
|
933 | FILL_STROKE_MASK: 3,
|
934 | ADD_TO_PATH_FLAG: 4
|
935 | };
|
936 | exports.TextRenderingMode = TextRenderingMode;
|
937 | const ImageKind = {
|
938 | GRAYSCALE_1BPP: 1,
|
939 | RGB_24BPP: 2,
|
940 | RGBA_32BPP: 3
|
941 | };
|
942 | exports.ImageKind = ImageKind;
|
943 | const AnnotationType = {
|
944 | TEXT: 1,
|
945 | LINK: 2,
|
946 | FREETEXT: 3,
|
947 | LINE: 4,
|
948 | SQUARE: 5,
|
949 | CIRCLE: 6,
|
950 | POLYGON: 7,
|
951 | POLYLINE: 8,
|
952 | HIGHLIGHT: 9,
|
953 | UNDERLINE: 10,
|
954 | SQUIGGLY: 11,
|
955 | STRIKEOUT: 12,
|
956 | STAMP: 13,
|
957 | CARET: 14,
|
958 | INK: 15,
|
959 | POPUP: 16,
|
960 | FILEATTACHMENT: 17,
|
961 | SOUND: 18,
|
962 | MOVIE: 19,
|
963 | WIDGET: 20,
|
964 | SCREEN: 21,
|
965 | PRINTERMARK: 22,
|
966 | TRAPNET: 23,
|
967 | WATERMARK: 24,
|
968 | THREED: 25,
|
969 | REDACT: 26
|
970 | };
|
971 | exports.AnnotationType = AnnotationType;
|
972 | const AnnotationStateModelType = {
|
973 | MARKED: "Marked",
|
974 | REVIEW: "Review"
|
975 | };
|
976 | exports.AnnotationStateModelType = AnnotationStateModelType;
|
977 | const AnnotationMarkedState = {
|
978 | MARKED: "Marked",
|
979 | UNMARKED: "Unmarked"
|
980 | };
|
981 | exports.AnnotationMarkedState = AnnotationMarkedState;
|
982 | const AnnotationReviewState = {
|
983 | ACCEPTED: "Accepted",
|
984 | REJECTED: "Rejected",
|
985 | CANCELLED: "Cancelled",
|
986 | COMPLETED: "Completed",
|
987 | NONE: "None"
|
988 | };
|
989 | exports.AnnotationReviewState = AnnotationReviewState;
|
990 | const AnnotationReplyType = {
|
991 | GROUP: "Group",
|
992 | REPLY: "R"
|
993 | };
|
994 | exports.AnnotationReplyType = AnnotationReplyType;
|
995 | const AnnotationFlag = {
|
996 | INVISIBLE: 0x01,
|
997 | HIDDEN: 0x02,
|
998 | PRINT: 0x04,
|
999 | NOZOOM: 0x08,
|
1000 | NOROTATE: 0x10,
|
1001 | NOVIEW: 0x20,
|
1002 | READONLY: 0x40,
|
1003 | LOCKED: 0x80,
|
1004 | TOGGLENOVIEW: 0x100,
|
1005 | LOCKEDCONTENTS: 0x200
|
1006 | };
|
1007 | exports.AnnotationFlag = AnnotationFlag;
|
1008 | const AnnotationFieldFlag = {
|
1009 | READONLY: 0x0000001,
|
1010 | REQUIRED: 0x0000002,
|
1011 | NOEXPORT: 0x0000004,
|
1012 | MULTILINE: 0x0001000,
|
1013 | PASSWORD: 0x0002000,
|
1014 | NOTOGGLETOOFF: 0x0004000,
|
1015 | RADIO: 0x0008000,
|
1016 | PUSHBUTTON: 0x0010000,
|
1017 | COMBO: 0x0020000,
|
1018 | EDIT: 0x0040000,
|
1019 | SORT: 0x0080000,
|
1020 | FILESELECT: 0x0100000,
|
1021 | MULTISELECT: 0x0200000,
|
1022 | DONOTSPELLCHECK: 0x0400000,
|
1023 | DONOTSCROLL: 0x0800000,
|
1024 | COMB: 0x1000000,
|
1025 | RICHTEXT: 0x2000000,
|
1026 | RADIOSINUNISON: 0x2000000,
|
1027 | COMMITONSELCHANGE: 0x4000000
|
1028 | };
|
1029 | exports.AnnotationFieldFlag = AnnotationFieldFlag;
|
1030 | const AnnotationBorderStyleType = {
|
1031 | SOLID: 1,
|
1032 | DASHED: 2,
|
1033 | BEVELED: 3,
|
1034 | INSET: 4,
|
1035 | UNDERLINE: 5
|
1036 | };
|
1037 | exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
|
1038 | const StreamType = {
|
1039 | UNKNOWN: "UNKNOWN",
|
1040 | FLATE: "FLATE",
|
1041 | LZW: "LZW",
|
1042 | DCT: "DCT",
|
1043 | JPX: "JPX",
|
1044 | JBIG: "JBIG",
|
1045 | A85: "A85",
|
1046 | AHX: "AHX",
|
1047 | CCF: "CCF",
|
1048 | RLX: "RLX"
|
1049 | };
|
1050 | exports.StreamType = StreamType;
|
1051 | const FontType = {
|
1052 | UNKNOWN: "UNKNOWN",
|
1053 | TYPE1: "TYPE1",
|
1054 | TYPE1C: "TYPE1C",
|
1055 | CIDFONTTYPE0: "CIDFONTTYPE0",
|
1056 | CIDFONTTYPE0C: "CIDFONTTYPE0C",
|
1057 | TRUETYPE: "TRUETYPE",
|
1058 | CIDFONTTYPE2: "CIDFONTTYPE2",
|
1059 | TYPE3: "TYPE3",
|
1060 | OPENTYPE: "OPENTYPE",
|
1061 | TYPE0: "TYPE0",
|
1062 | MMTYPE1: "MMTYPE1"
|
1063 | };
|
1064 | exports.FontType = FontType;
|
1065 | const VerbosityLevel = {
|
1066 | ERRORS: 0,
|
1067 | WARNINGS: 1,
|
1068 | INFOS: 5
|
1069 | };
|
1070 | exports.VerbosityLevel = VerbosityLevel;
|
1071 | const CMapCompressionType = {
|
1072 | NONE: 0,
|
1073 | BINARY: 1,
|
1074 | STREAM: 2
|
1075 | };
|
1076 | exports.CMapCompressionType = CMapCompressionType;
|
1077 | const OPS = {
|
1078 | dependency: 1,
|
1079 | setLineWidth: 2,
|
1080 | setLineCap: 3,
|
1081 | setLineJoin: 4,
|
1082 | setMiterLimit: 5,
|
1083 | setDash: 6,
|
1084 | setRenderingIntent: 7,
|
1085 | setFlatness: 8,
|
1086 | setGState: 9,
|
1087 | save: 10,
|
1088 | restore: 11,
|
1089 | transform: 12,
|
1090 | moveTo: 13,
|
1091 | lineTo: 14,
|
1092 | curveTo: 15,
|
1093 | curveTo2: 16,
|
1094 | curveTo3: 17,
|
1095 | closePath: 18,
|
1096 | rectangle: 19,
|
1097 | stroke: 20,
|
1098 | closeStroke: 21,
|
1099 | fill: 22,
|
1100 | eoFill: 23,
|
1101 | fillStroke: 24,
|
1102 | eoFillStroke: 25,
|
1103 | closeFillStroke: 26,
|
1104 | closeEOFillStroke: 27,
|
1105 | endPath: 28,
|
1106 | clip: 29,
|
1107 | eoClip: 30,
|
1108 | beginText: 31,
|
1109 | endText: 32,
|
1110 | setCharSpacing: 33,
|
1111 | setWordSpacing: 34,
|
1112 | setHScale: 35,
|
1113 | setLeading: 36,
|
1114 | setFont: 37,
|
1115 | setTextRenderingMode: 38,
|
1116 | setTextRise: 39,
|
1117 | moveText: 40,
|
1118 | setLeadingMoveText: 41,
|
1119 | setTextMatrix: 42,
|
1120 | nextLine: 43,
|
1121 | showText: 44,
|
1122 | showSpacedText: 45,
|
1123 | nextLineShowText: 46,
|
1124 | nextLineSetSpacingShowText: 47,
|
1125 | setCharWidth: 48,
|
1126 | setCharWidthAndBounds: 49,
|
1127 | setStrokeColorSpace: 50,
|
1128 | setFillColorSpace: 51,
|
1129 | setStrokeColor: 52,
|
1130 | setStrokeColorN: 53,
|
1131 | setFillColor: 54,
|
1132 | setFillColorN: 55,
|
1133 | setStrokeGray: 56,
|
1134 | setFillGray: 57,
|
1135 | setStrokeRGBColor: 58,
|
1136 | setFillRGBColor: 59,
|
1137 | setStrokeCMYKColor: 60,
|
1138 | setFillCMYKColor: 61,
|
1139 | shadingFill: 62,
|
1140 | beginInlineImage: 63,
|
1141 | beginImageData: 64,
|
1142 | endInlineImage: 65,
|
1143 | paintXObject: 66,
|
1144 | markPoint: 67,
|
1145 | markPointProps: 68,
|
1146 | beginMarkedContent: 69,
|
1147 | beginMarkedContentProps: 70,
|
1148 | endMarkedContent: 71,
|
1149 | beginCompat: 72,
|
1150 | endCompat: 73,
|
1151 | paintFormXObjectBegin: 74,
|
1152 | paintFormXObjectEnd: 75,
|
1153 | beginGroup: 76,
|
1154 | endGroup: 77,
|
1155 | beginAnnotations: 78,
|
1156 | endAnnotations: 79,
|
1157 | beginAnnotation: 80,
|
1158 | endAnnotation: 81,
|
1159 | paintJpegXObject: 82,
|
1160 | paintImageMaskXObject: 83,
|
1161 | paintImageMaskXObjectGroup: 84,
|
1162 | paintImageXObject: 85,
|
1163 | paintInlineImageXObject: 86,
|
1164 | paintInlineImageXObjectGroup: 87,
|
1165 | paintImageXObjectRepeat: 88,
|
1166 | paintImageMaskXObjectRepeat: 89,
|
1167 | paintSolidColorImageMask: 90,
|
1168 | constructPath: 91
|
1169 | };
|
1170 | exports.OPS = OPS;
|
1171 | const UNSUPPORTED_FEATURES = {
|
1172 | unknown: "unknown",
|
1173 | forms: "forms",
|
1174 | javaScript: "javaScript",
|
1175 | smask: "smask",
|
1176 | shadingPattern: "shadingPattern",
|
1177 | font: "font",
|
1178 | errorTilingPattern: "errorTilingPattern",
|
1179 | errorExtGState: "errorExtGState",
|
1180 | errorXObject: "errorXObject",
|
1181 | errorFontLoadType3: "errorFontLoadType3",
|
1182 | errorFontState: "errorFontState",
|
1183 | errorFontMissing: "errorFontMissing",
|
1184 | errorFontTranslate: "errorFontTranslate",
|
1185 | errorColorSpace: "errorColorSpace",
|
1186 | errorOperatorList: "errorOperatorList",
|
1187 | errorFontToUnicode: "errorFontToUnicode",
|
1188 | errorFontLoadNative: "errorFontLoadNative",
|
1189 | errorFontGetPath: "errorFontGetPath"
|
1190 | };
|
1191 | exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
|
1192 | const PasswordResponses = {
|
1193 | NEED_PASSWORD: 1,
|
1194 | INCORRECT_PASSWORD: 2
|
1195 | };
|
1196 | exports.PasswordResponses = PasswordResponses;
|
1197 | let verbosity = VerbosityLevel.WARNINGS;
|
1198 |
|
1199 | function setVerbosityLevel(level) {
|
1200 | if (Number.isInteger(level)) {
|
1201 | verbosity = level;
|
1202 | }
|
1203 | }
|
1204 |
|
1205 | function getVerbosityLevel() {
|
1206 | return verbosity;
|
1207 | }
|
1208 |
|
1209 | function info(msg) {
|
1210 | if (verbosity >= VerbosityLevel.INFOS) {
|
1211 | console.log(`Info: ${msg}`);
|
1212 | }
|
1213 | }
|
1214 |
|
1215 | function warn(msg) {
|
1216 | if (verbosity >= VerbosityLevel.WARNINGS) {
|
1217 | console.log(`Warning: ${msg}`);
|
1218 | }
|
1219 | }
|
1220 |
|
1221 | function unreachable(msg) {
|
1222 | throw new Error(msg);
|
1223 | }
|
1224 |
|
1225 | function assert(cond, msg) {
|
1226 | if (!cond) {
|
1227 | unreachable(msg);
|
1228 | }
|
1229 | }
|
1230 |
|
1231 | function isSameOrigin(baseUrl, otherUrl) {
|
1232 | let base;
|
1233 |
|
1234 | try {
|
1235 | base = new URL(baseUrl);
|
1236 |
|
1237 | if (!base.origin || base.origin === "null") {
|
1238 | return false;
|
1239 | }
|
1240 | } catch (e) {
|
1241 | return false;
|
1242 | }
|
1243 |
|
1244 | const other = new URL(otherUrl, base);
|
1245 | return base.origin === other.origin;
|
1246 | }
|
1247 |
|
1248 | function _isValidProtocol(url) {
|
1249 | if (!url) {
|
1250 | return false;
|
1251 | }
|
1252 |
|
1253 | switch (url.protocol) {
|
1254 | case "http:":
|
1255 | case "https:":
|
1256 | case "ftp:":
|
1257 | case "mailto:":
|
1258 | case "tel:":
|
1259 | return true;
|
1260 |
|
1261 | default:
|
1262 | return false;
|
1263 | }
|
1264 | }
|
1265 |
|
1266 | function createValidAbsoluteUrl(url, baseUrl) {
|
1267 | if (!url) {
|
1268 | return null;
|
1269 | }
|
1270 |
|
1271 | try {
|
1272 | const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
|
1273 |
|
1274 | if (_isValidProtocol(absoluteUrl)) {
|
1275 | return absoluteUrl;
|
1276 | }
|
1277 | } catch (ex) {}
|
1278 |
|
1279 | return null;
|
1280 | }
|
1281 |
|
1282 | function shadow(obj, prop, value) {
|
1283 | Object.defineProperty(obj, prop, {
|
1284 | value,
|
1285 | enumerable: true,
|
1286 | configurable: true,
|
1287 | writable: false
|
1288 | });
|
1289 | return value;
|
1290 | }
|
1291 |
|
1292 | const BaseException = function BaseExceptionClosure() {
|
1293 | function BaseException(message) {
|
1294 | if (this.constructor === BaseException) {
|
1295 | unreachable("Cannot initialize BaseException.");
|
1296 | }
|
1297 |
|
1298 | this.message = message;
|
1299 | this.name = this.constructor.name;
|
1300 | }
|
1301 |
|
1302 | BaseException.prototype = new Error();
|
1303 | BaseException.constructor = BaseException;
|
1304 | return BaseException;
|
1305 | }();
|
1306 |
|
1307 | exports.BaseException = BaseException;
|
1308 |
|
1309 | class PasswordException extends BaseException {
|
1310 | constructor(msg, code) {
|
1311 | super(msg);
|
1312 | this.code = code;
|
1313 | }
|
1314 |
|
1315 | }
|
1316 |
|
1317 | exports.PasswordException = PasswordException;
|
1318 |
|
1319 | class UnknownErrorException extends BaseException {
|
1320 | constructor(msg, details) {
|
1321 | super(msg);
|
1322 | this.details = details;
|
1323 | }
|
1324 |
|
1325 | }
|
1326 |
|
1327 | exports.UnknownErrorException = UnknownErrorException;
|
1328 |
|
1329 | class InvalidPDFException extends BaseException {}
|
1330 |
|
1331 | exports.InvalidPDFException = InvalidPDFException;
|
1332 |
|
1333 | class MissingPDFException extends BaseException {}
|
1334 |
|
1335 | exports.MissingPDFException = MissingPDFException;
|
1336 |
|
1337 | class UnexpectedResponseException extends BaseException {
|
1338 | constructor(msg, status) {
|
1339 | super(msg);
|
1340 | this.status = status;
|
1341 | }
|
1342 |
|
1343 | }
|
1344 |
|
1345 | exports.UnexpectedResponseException = UnexpectedResponseException;
|
1346 |
|
1347 | class FormatError extends BaseException {}
|
1348 |
|
1349 | exports.FormatError = FormatError;
|
1350 |
|
1351 | class AbortException extends BaseException {}
|
1352 |
|
1353 | exports.AbortException = AbortException;
|
1354 | const NullCharactersRegExp = /\x00/g;
|
1355 |
|
1356 | function removeNullCharacters(str) {
|
1357 | if (typeof str !== "string") {
|
1358 | warn("The argument for removeNullCharacters must be a string.");
|
1359 | return str;
|
1360 | }
|
1361 |
|
1362 | return str.replace(NullCharactersRegExp, "");
|
1363 | }
|
1364 |
|
1365 | function bytesToString(bytes) {
|
1366 | assert(bytes !== null && typeof bytes === "object" && bytes.length !== undefined, "Invalid argument for bytesToString");
|
1367 | const length = bytes.length;
|
1368 | const MAX_ARGUMENT_COUNT = 8192;
|
1369 |
|
1370 | if (length < MAX_ARGUMENT_COUNT) {
|
1371 | return String.fromCharCode.apply(null, bytes);
|
1372 | }
|
1373 |
|
1374 | const strBuf = [];
|
1375 |
|
1376 | for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
|
1377 | const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
|
1378 | const chunk = bytes.subarray(i, chunkEnd);
|
1379 | strBuf.push(String.fromCharCode.apply(null, chunk));
|
1380 | }
|
1381 |
|
1382 | return strBuf.join("");
|
1383 | }
|
1384 |
|
1385 | function stringToBytes(str) {
|
1386 | assert(typeof str === "string", "Invalid argument for stringToBytes");
|
1387 | const length = str.length;
|
1388 | const bytes = new Uint8Array(length);
|
1389 |
|
1390 | for (let i = 0; i < length; ++i) {
|
1391 | bytes[i] = str.charCodeAt(i) & 0xff;
|
1392 | }
|
1393 |
|
1394 | return bytes;
|
1395 | }
|
1396 |
|
1397 | function arrayByteLength(arr) {
|
1398 | if (arr.length !== undefined) {
|
1399 | return arr.length;
|
1400 | }
|
1401 |
|
1402 | assert(arr.byteLength !== undefined, "arrayByteLength - invalid argument.");
|
1403 | return arr.byteLength;
|
1404 | }
|
1405 |
|
1406 | function arraysToBytes(arr) {
|
1407 | const length = arr.length;
|
1408 |
|
1409 | if (length === 1 && arr[0] instanceof Uint8Array) {
|
1410 | return arr[0];
|
1411 | }
|
1412 |
|
1413 | let resultLength = 0;
|
1414 |
|
1415 | for (let i = 0; i < length; i++) {
|
1416 | resultLength += arrayByteLength(arr[i]);
|
1417 | }
|
1418 |
|
1419 | let pos = 0;
|
1420 | const data = new Uint8Array(resultLength);
|
1421 |
|
1422 | for (let i = 0; i < length; i++) {
|
1423 | let item = arr[i];
|
1424 |
|
1425 | if (!(item instanceof Uint8Array)) {
|
1426 | if (typeof item === "string") {
|
1427 | item = stringToBytes(item);
|
1428 | } else {
|
1429 | item = new Uint8Array(item);
|
1430 | }
|
1431 | }
|
1432 |
|
1433 | const itemLength = item.byteLength;
|
1434 | data.set(item, pos);
|
1435 | pos += itemLength;
|
1436 | }
|
1437 |
|
1438 | return data;
|
1439 | }
|
1440 |
|
1441 | function string32(value) {
|
1442 | return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
|
1443 | }
|
1444 |
|
1445 | function isLittleEndian() {
|
1446 | const buffer8 = new Uint8Array(4);
|
1447 | buffer8[0] = 1;
|
1448 | const view32 = new Uint32Array(buffer8.buffer, 0, 1);
|
1449 | return view32[0] === 1;
|
1450 | }
|
1451 |
|
1452 | const IsLittleEndianCached = {
|
1453 | get value() {
|
1454 | return shadow(this, "value", isLittleEndian());
|
1455 | }
|
1456 |
|
1457 | };
|
1458 | exports.IsLittleEndianCached = IsLittleEndianCached;
|
1459 |
|
1460 | function isEvalSupported() {
|
1461 | try {
|
1462 | new Function("");
|
1463 | return true;
|
1464 | } catch (e) {
|
1465 | return false;
|
1466 | }
|
1467 | }
|
1468 |
|
1469 | const IsEvalSupportedCached = {
|
1470 | get value() {
|
1471 | return shadow(this, "value", isEvalSupported());
|
1472 | }
|
1473 |
|
1474 | };
|
1475 | exports.IsEvalSupportedCached = IsEvalSupportedCached;
|
1476 | const rgbBuf = ["rgb(", 0, ",", 0, ",", 0, ")"];
|
1477 |
|
1478 | class Util {
|
1479 | static makeCssRgb(r, g, b) {
|
1480 | rgbBuf[1] = r;
|
1481 | rgbBuf[3] = g;
|
1482 | rgbBuf[5] = b;
|
1483 | return rgbBuf.join("");
|
1484 | }
|
1485 |
|
1486 | static transform(m1, m2) {
|
1487 | return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]];
|
1488 | }
|
1489 |
|
1490 | static applyTransform(p, m) {
|
1491 | const xt = p[0] * m[0] + p[1] * m[2] + m[4];
|
1492 | const yt = p[0] * m[1] + p[1] * m[3] + m[5];
|
1493 | return [xt, yt];
|
1494 | }
|
1495 |
|
1496 | static applyInverseTransform(p, m) {
|
1497 | const d = m[0] * m[3] - m[1] * m[2];
|
1498 | const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
|
1499 | const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
|
1500 | return [xt, yt];
|
1501 | }
|
1502 |
|
1503 | static getAxialAlignedBoundingBox(r, m) {
|
1504 | const p1 = Util.applyTransform(r, m);
|
1505 | const p2 = Util.applyTransform(r.slice(2, 4), m);
|
1506 | const p3 = Util.applyTransform([r[0], r[3]], m);
|
1507 | const p4 = Util.applyTransform([r[2], r[1]], m);
|
1508 | return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
|
1509 | }
|
1510 |
|
1511 | static inverseTransform(m) {
|
1512 | const d = m[0] * m[3] - m[1] * m[2];
|
1513 | return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
|
1514 | }
|
1515 |
|
1516 | static apply3dTransform(m, v) {
|
1517 | return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]];
|
1518 | }
|
1519 |
|
1520 | static singularValueDecompose2dScale(m) {
|
1521 | const transpose = [m[0], m[2], m[1], m[3]];
|
1522 | const a = m[0] * transpose[0] + m[1] * transpose[2];
|
1523 | const b = m[0] * transpose[1] + m[1] * transpose[3];
|
1524 | const c = m[2] * transpose[0] + m[3] * transpose[2];
|
1525 | const d = m[2] * transpose[1] + m[3] * transpose[3];
|
1526 | const first = (a + d) / 2;
|
1527 | const second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
|
1528 | const sx = first + second || 1;
|
1529 | const sy = first - second || 1;
|
1530 | return [Math.sqrt(sx), Math.sqrt(sy)];
|
1531 | }
|
1532 |
|
1533 | static normalizeRect(rect) {
|
1534 | const r = rect.slice(0);
|
1535 |
|
1536 | if (rect[0] > rect[2]) {
|
1537 | r[0] = rect[2];
|
1538 | r[2] = rect[0];
|
1539 | }
|
1540 |
|
1541 | if (rect[1] > rect[3]) {
|
1542 | r[1] = rect[3];
|
1543 | r[3] = rect[1];
|
1544 | }
|
1545 |
|
1546 | return r;
|
1547 | }
|
1548 |
|
1549 | static intersect(rect1, rect2) {
|
1550 | function compare(a, b) {
|
1551 | return a - b;
|
1552 | }
|
1553 |
|
1554 | const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare);
|
1555 | const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare);
|
1556 | const result = [];
|
1557 | rect1 = Util.normalizeRect(rect1);
|
1558 | rect2 = Util.normalizeRect(rect2);
|
1559 |
|
1560 | if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
|
1561 | result[0] = orderedX[1];
|
1562 | result[2] = orderedX[2];
|
1563 | } else {
|
1564 | return null;
|
1565 | }
|
1566 |
|
1567 | if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
|
1568 | result[1] = orderedY[1];
|
1569 | result[3] = orderedY[2];
|
1570 | } else {
|
1571 | return null;
|
1572 | }
|
1573 |
|
1574 | return result;
|
1575 | }
|
1576 |
|
1577 | }
|
1578 |
|
1579 | exports.Util = Util;
|
1580 | const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C, 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160, 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC];
|
1581 |
|
1582 | function stringToPDFString(str) {
|
1583 | const length = str.length,
|
1584 | strBuf = [];
|
1585 |
|
1586 | if (str[0] === "\xFE" && str[1] === "\xFF") {
|
1587 | for (let i = 2; i < length; i += 2) {
|
1588 | strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
|
1589 | }
|
1590 | } else if (str[0] === "\xFF" && str[1] === "\xFE") {
|
1591 | for (let i = 2; i < length; i += 2) {
|
1592 | strBuf.push(String.fromCharCode(str.charCodeAt(i + 1) << 8 | str.charCodeAt(i)));
|
1593 | }
|
1594 | } else {
|
1595 | for (let i = 0; i < length; ++i) {
|
1596 | const code = PDFStringTranslateTable[str.charCodeAt(i)];
|
1597 | strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
|
1598 | }
|
1599 | }
|
1600 |
|
1601 | return strBuf.join("");
|
1602 | }
|
1603 |
|
1604 | function stringToUTF8String(str) {
|
1605 | return decodeURIComponent(escape(str));
|
1606 | }
|
1607 |
|
1608 | function utf8StringToString(str) {
|
1609 | return unescape(encodeURIComponent(str));
|
1610 | }
|
1611 |
|
1612 | function isEmptyObj(obj) {
|
1613 | for (const key in obj) {
|
1614 | return false;
|
1615 | }
|
1616 |
|
1617 | return true;
|
1618 | }
|
1619 |
|
1620 | function isBool(v) {
|
1621 | return typeof v === "boolean";
|
1622 | }
|
1623 |
|
1624 | function isNum(v) {
|
1625 | return typeof v === "number";
|
1626 | }
|
1627 |
|
1628 | function isString(v) {
|
1629 | return typeof v === "string";
|
1630 | }
|
1631 |
|
1632 | function isArrayBuffer(v) {
|
1633 | return typeof v === "object" && v !== null && v.byteLength !== undefined;
|
1634 | }
|
1635 |
|
1636 | function isArrayEqual(arr1, arr2) {
|
1637 | if (arr1.length !== arr2.length) {
|
1638 | return false;
|
1639 | }
|
1640 |
|
1641 | return arr1.every(function (element, index) {
|
1642 | return element === arr2[index];
|
1643 | });
|
1644 | }
|
1645 |
|
1646 | function createPromiseCapability() {
|
1647 | const capability = Object.create(null);
|
1648 | let isSettled = false;
|
1649 | Object.defineProperty(capability, "settled", {
|
1650 | get() {
|
1651 | return isSettled;
|
1652 | }
|
1653 |
|
1654 | });
|
1655 | capability.promise = new Promise(function (resolve, reject) {
|
1656 | capability.resolve = function (data) {
|
1657 | isSettled = true;
|
1658 | resolve(data);
|
1659 | };
|
1660 |
|
1661 | capability.reject = function (reason) {
|
1662 | isSettled = true;
|
1663 | reject(reason);
|
1664 | };
|
1665 | });
|
1666 | return capability;
|
1667 | }
|
1668 |
|
1669 | const createObjectURL = function createObjectURLClosure() {
|
1670 | const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
1671 | return function createObjectURL(data, contentType, forceDataSchema = false) {
|
1672 | if (!forceDataSchema && URL.createObjectURL) {
|
1673 | const blob = new Blob([data], {
|
1674 | type: contentType
|
1675 | });
|
1676 | return URL.createObjectURL(blob);
|
1677 | }
|
1678 |
|
1679 | let buffer = `data:${contentType};base64,`;
|
1680 |
|
1681 | for (let i = 0, ii = data.length; i < ii; i += 3) {
|
1682 | const b1 = data[i] & 0xff;
|
1683 | const b2 = data[i + 1] & 0xff;
|
1684 | const b3 = data[i + 2] & 0xff;
|
1685 | const d1 = b1 >> 2,
|
1686 | d2 = (b1 & 3) << 4 | b2 >> 4;
|
1687 | const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
|
1688 | const d4 = i + 2 < ii ? b3 & 0x3f : 64;
|
1689 | buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
|
1690 | }
|
1691 |
|
1692 | return buffer;
|
1693 | };
|
1694 | }();
|
1695 |
|
1696 | exports.createObjectURL = createObjectURL;
|
1697 |
|
1698 | }),
|
1699 |
|
1700 | (function(module, exports, __w_pdfjs_require__) {
|
1701 |
|
1702 | "use strict";
|
1703 |
|
1704 |
|
1705 | var _is_node = __w_pdfjs_require__(4);
|
1706 |
|
1707 | ;
|
1708 |
|
1709 | }),
|
1710 |
|
1711 | (function(module, exports, __w_pdfjs_require__) {
|
1712 |
|
1713 | "use strict";
|
1714 |
|
1715 |
|
1716 | Object.defineProperty(exports, "__esModule", {
|
1717 | value: true
|
1718 | });
|
1719 | exports.isNodeJS = void 0;
|
1720 | const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !process.versions.electron;
|
1721 | exports.isNodeJS = isNodeJS;
|
1722 |
|
1723 | }),
|
1724 |
|
1725 | (function(module, exports, __w_pdfjs_require__) {
|
1726 |
|
1727 | "use strict";
|
1728 |
|
1729 |
|
1730 | Object.defineProperty(exports, "__esModule", {
|
1731 | value: true
|
1732 | });
|
1733 | exports.getDocument = getDocument;
|
1734 | exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory;
|
1735 | exports.build = exports.version = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFWorker = exports.PDFDataRangeTransport = exports.LoopbackPort = void 0;
|
1736 |
|
1737 | var _util = __w_pdfjs_require__(2);
|
1738 |
|
1739 | var _display_utils = __w_pdfjs_require__(1);
|
1740 |
|
1741 | var _font_loader = __w_pdfjs_require__(6);
|
1742 |
|
1743 | var _api_compatibility = __w_pdfjs_require__(7);
|
1744 |
|
1745 | var _canvas = __w_pdfjs_require__(8);
|
1746 |
|
1747 | var _worker_options = __w_pdfjs_require__(10);
|
1748 |
|
1749 | var _is_node = __w_pdfjs_require__(4);
|
1750 |
|
1751 | var _message_handler = __w_pdfjs_require__(11);
|
1752 |
|
1753 | var _metadata = __w_pdfjs_require__(12);
|
1754 |
|
1755 | var _transport_stream = __w_pdfjs_require__(14);
|
1756 |
|
1757 | var _webgl = __w_pdfjs_require__(15);
|
1758 |
|
1759 | const DEFAULT_RANGE_CHUNK_SIZE = 65536;
|
1760 | const RENDERING_CANCELLED_TIMEOUT = 100;
|
1761 | let createPDFNetworkStream;
|
1762 |
|
1763 | function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
1764 | createPDFNetworkStream = pdfNetworkStreamFactory;
|
1765 | }
|
1766 |
|
1767 | function getDocument(src) {
|
1768 | const task = new PDFDocumentLoadingTask();
|
1769 | let source;
|
1770 |
|
1771 | if (typeof src === "string") {
|
1772 | source = {
|
1773 | url: src
|
1774 | };
|
1775 | } else if ((0, _util.isArrayBuffer)(src)) {
|
1776 | source = {
|
1777 | data: src
|
1778 | };
|
1779 | } else if (src instanceof PDFDataRangeTransport) {
|
1780 | source = {
|
1781 | range: src
|
1782 | };
|
1783 | } else {
|
1784 | if (typeof src !== "object") {
|
1785 | throw new Error("Invalid parameter in getDocument, " + "need either Uint8Array, string or a parameter object");
|
1786 | }
|
1787 |
|
1788 | if (!src.url && !src.data && !src.range) {
|
1789 | throw new Error("Invalid parameter object: need either .data, .range or .url");
|
1790 | }
|
1791 |
|
1792 | source = src;
|
1793 | }
|
1794 |
|
1795 | const params = Object.create(null);
|
1796 | let rangeTransport = null,
|
1797 | worker = null;
|
1798 |
|
1799 | for (const key in source) {
|
1800 | if (key === "url" && typeof window !== "undefined") {
|
1801 | params[key] = new URL(source[key], window.location).href;
|
1802 | continue;
|
1803 | } else if (key === "range") {
|
1804 | rangeTransport = source[key];
|
1805 | continue;
|
1806 | } else if (key === "worker") {
|
1807 | worker = source[key];
|
1808 | continue;
|
1809 | } else if (key === "data" && !(source[key] instanceof Uint8Array)) {
|
1810 | const pdfBytes = source[key];
|
1811 |
|
1812 | if (typeof pdfBytes === "string") {
|
1813 | params[key] = (0, _util.stringToBytes)(pdfBytes);
|
1814 | } else if (typeof pdfBytes === "object" && pdfBytes !== null && !isNaN(pdfBytes.length)) {
|
1815 | params[key] = new Uint8Array(pdfBytes);
|
1816 | } else if ((0, _util.isArrayBuffer)(pdfBytes)) {
|
1817 | params[key] = new Uint8Array(pdfBytes);
|
1818 | } else {
|
1819 | throw new Error("Invalid PDF binary data: either typed array, " + "string or array-like object is expected in the " + "data property.");
|
1820 | }
|
1821 |
|
1822 | continue;
|
1823 | }
|
1824 |
|
1825 | params[key] = source[key];
|
1826 | }
|
1827 |
|
1828 | params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
|
1829 | params.CMapReaderFactory = params.CMapReaderFactory || _display_utils.DOMCMapReaderFactory;
|
1830 | params.ignoreErrors = params.stopAtErrors !== true;
|
1831 | params.fontExtraProperties = params.fontExtraProperties === true;
|
1832 | params.pdfBug = params.pdfBug === true;
|
1833 |
|
1834 | if (!Number.isInteger(params.maxImageSize)) {
|
1835 | params.maxImageSize = -1;
|
1836 | }
|
1837 |
|
1838 | if (typeof params.isEvalSupported !== "boolean") {
|
1839 | params.isEvalSupported = true;
|
1840 | }
|
1841 |
|
1842 | if (typeof params.disableFontFace !== "boolean") {
|
1843 | params.disableFontFace = _api_compatibility.apiCompatibilityParams.disableFontFace || false;
|
1844 | }
|
1845 |
|
1846 | if (typeof params.disableRange !== "boolean") {
|
1847 | params.disableRange = false;
|
1848 | }
|
1849 |
|
1850 | if (typeof params.disableStream !== "boolean") {
|
1851 | params.disableStream = false;
|
1852 | }
|
1853 |
|
1854 | if (typeof params.disableAutoFetch !== "boolean") {
|
1855 | params.disableAutoFetch = false;
|
1856 | }
|
1857 |
|
1858 | (0, _util.setVerbosityLevel)(params.verbosity);
|
1859 |
|
1860 | if (!worker) {
|
1861 | const workerParams = {
|
1862 | verbosity: params.verbosity,
|
1863 | port: _worker_options.GlobalWorkerOptions.workerPort
|
1864 | };
|
1865 | worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
|
1866 | task._worker = worker;
|
1867 | }
|
1868 |
|
1869 | const docId = task.docId;
|
1870 | worker.promise.then(function () {
|
1871 | if (task.destroyed) {
|
1872 | throw new Error("Loading aborted");
|
1873 | }
|
1874 |
|
1875 | const workerIdPromise = _fetchDocument(worker, params, rangeTransport, docId);
|
1876 |
|
1877 | const networkStreamPromise = new Promise(function (resolve) {
|
1878 | let networkStream;
|
1879 |
|
1880 | if (rangeTransport) {
|
1881 | networkStream = new _transport_stream.PDFDataTransportStream({
|
1882 | length: params.length,
|
1883 | initialData: params.initialData,
|
1884 | progressiveDone: params.progressiveDone,
|
1885 | disableRange: params.disableRange,
|
1886 | disableStream: params.disableStream
|
1887 | }, rangeTransport);
|
1888 | } else if (!params.data) {
|
1889 | networkStream = createPDFNetworkStream({
|
1890 | url: params.url,
|
1891 | length: params.length,
|
1892 | httpHeaders: params.httpHeaders,
|
1893 | withCredentials: params.withCredentials,
|
1894 | rangeChunkSize: params.rangeChunkSize,
|
1895 | disableRange: params.disableRange,
|
1896 | disableStream: params.disableStream
|
1897 | });
|
1898 | }
|
1899 |
|
1900 | resolve(networkStream);
|
1901 | });
|
1902 | return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
|
1903 | if (task.destroyed) {
|
1904 | throw new Error("Loading aborted");
|
1905 | }
|
1906 |
|
1907 | const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
|
1908 | messageHandler.postMessageTransfers = worker.postMessageTransfers;
|
1909 | const transport = new WorkerTransport(messageHandler, task, networkStream, params);
|
1910 | task._transport = transport;
|
1911 | messageHandler.send("Ready", null);
|
1912 | });
|
1913 | }).catch(task._capability.reject);
|
1914 | return task;
|
1915 | }
|
1916 |
|
1917 | function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
1918 | if (worker.destroyed) {
|
1919 | return Promise.reject(new Error("Worker was destroyed"));
|
1920 | }
|
1921 |
|
1922 | if (pdfDataRangeTransport) {
|
1923 | source.length = pdfDataRangeTransport.length;
|
1924 | source.initialData = pdfDataRangeTransport.initialData;
|
1925 | source.progressiveDone = pdfDataRangeTransport.progressiveDone;
|
1926 | }
|
1927 |
|
1928 | return worker.messageHandler.sendWithPromise("GetDocRequest", {
|
1929 | docId,
|
1930 | apiVersion: '2.5.207',
|
1931 | source: {
|
1932 | data: source.data,
|
1933 | url: source.url,
|
1934 | password: source.password,
|
1935 | disableAutoFetch: source.disableAutoFetch,
|
1936 | rangeChunkSize: source.rangeChunkSize,
|
1937 | length: source.length
|
1938 | },
|
1939 | maxImageSize: source.maxImageSize,
|
1940 | disableFontFace: source.disableFontFace,
|
1941 | postMessageTransfers: worker.postMessageTransfers,
|
1942 | docBaseUrl: source.docBaseUrl,
|
1943 | ignoreErrors: source.ignoreErrors,
|
1944 | isEvalSupported: source.isEvalSupported,
|
1945 | fontExtraProperties: source.fontExtraProperties
|
1946 | }).then(function (workerId) {
|
1947 | if (worker.destroyed) {
|
1948 | throw new Error("Worker was destroyed");
|
1949 | }
|
1950 |
|
1951 | return workerId;
|
1952 | });
|
1953 | }
|
1954 |
|
1955 | const PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() {
|
1956 | let nextDocumentId = 0;
|
1957 |
|
1958 | class PDFDocumentLoadingTask {
|
1959 | constructor() {
|
1960 | this._capability = (0, _util.createPromiseCapability)();
|
1961 | this._transport = null;
|
1962 | this._worker = null;
|
1963 | this.docId = "d" + nextDocumentId++;
|
1964 | this.destroyed = false;
|
1965 | this.onPassword = null;
|
1966 | this.onProgress = null;
|
1967 | this.onUnsupportedFeature = null;
|
1968 | }
|
1969 |
|
1970 | get promise() {
|
1971 | return this._capability.promise;
|
1972 | }
|
1973 |
|
1974 | destroy() {
|
1975 | this.destroyed = true;
|
1976 | const transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy();
|
1977 | return transportDestroyed.then(() => {
|
1978 | this._transport = null;
|
1979 |
|
1980 | if (this._worker) {
|
1981 | this._worker.destroy();
|
1982 |
|
1983 | this._worker = null;
|
1984 | }
|
1985 | });
|
1986 | }
|
1987 |
|
1988 | }
|
1989 |
|
1990 | return PDFDocumentLoadingTask;
|
1991 | }();
|
1992 |
|
1993 | class PDFDataRangeTransport {
|
1994 | constructor(length, initialData, progressiveDone = false) {
|
1995 | this.length = length;
|
1996 | this.initialData = initialData;
|
1997 | this.progressiveDone = progressiveDone;
|
1998 | this._rangeListeners = [];
|
1999 | this._progressListeners = [];
|
2000 | this._progressiveReadListeners = [];
|
2001 | this._progressiveDoneListeners = [];
|
2002 | this._readyCapability = (0, _util.createPromiseCapability)();
|
2003 | }
|
2004 |
|
2005 | addRangeListener(listener) {
|
2006 | this._rangeListeners.push(listener);
|
2007 | }
|
2008 |
|
2009 | addProgressListener(listener) {
|
2010 | this._progressListeners.push(listener);
|
2011 | }
|
2012 |
|
2013 | addProgressiveReadListener(listener) {
|
2014 | this._progressiveReadListeners.push(listener);
|
2015 | }
|
2016 |
|
2017 | addProgressiveDoneListener(listener) {
|
2018 | this._progressiveDoneListeners.push(listener);
|
2019 | }
|
2020 |
|
2021 | onDataRange(begin, chunk) {
|
2022 | for (const listener of this._rangeListeners) {
|
2023 | listener(begin, chunk);
|
2024 | }
|
2025 | }
|
2026 |
|
2027 | onDataProgress(loaded, total) {
|
2028 | this._readyCapability.promise.then(() => {
|
2029 | for (const listener of this._progressListeners) {
|
2030 | listener(loaded, total);
|
2031 | }
|
2032 | });
|
2033 | }
|
2034 |
|
2035 | onDataProgressiveRead(chunk) {
|
2036 | this._readyCapability.promise.then(() => {
|
2037 | for (const listener of this._progressiveReadListeners) {
|
2038 | listener(chunk);
|
2039 | }
|
2040 | });
|
2041 | }
|
2042 |
|
2043 | onDataProgressiveDone() {
|
2044 | this._readyCapability.promise.then(() => {
|
2045 | for (const listener of this._progressiveDoneListeners) {
|
2046 | listener();
|
2047 | }
|
2048 | });
|
2049 | }
|
2050 |
|
2051 | transportReady() {
|
2052 | this._readyCapability.resolve();
|
2053 | }
|
2054 |
|
2055 | requestDataRange(begin, end) {
|
2056 | (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
|
2057 | }
|
2058 |
|
2059 | abort() {}
|
2060 |
|
2061 | }
|
2062 |
|
2063 | exports.PDFDataRangeTransport = PDFDataRangeTransport;
|
2064 |
|
2065 | class PDFDocumentProxy {
|
2066 | constructor(pdfInfo, transport) {
|
2067 | this._pdfInfo = pdfInfo;
|
2068 | this._transport = transport;
|
2069 | }
|
2070 |
|
2071 | get numPages() {
|
2072 | return this._pdfInfo.numPages;
|
2073 | }
|
2074 |
|
2075 | get fingerprint() {
|
2076 | return this._pdfInfo.fingerprint;
|
2077 | }
|
2078 |
|
2079 | getPage(pageNumber) {
|
2080 | return this._transport.getPage(pageNumber);
|
2081 | }
|
2082 |
|
2083 | getPageIndex(ref) {
|
2084 | return this._transport.getPageIndex(ref);
|
2085 | }
|
2086 |
|
2087 | getDestinations() {
|
2088 | return this._transport.getDestinations();
|
2089 | }
|
2090 |
|
2091 | getDestination(id) {
|
2092 | return this._transport.getDestination(id);
|
2093 | }
|
2094 |
|
2095 | getPageLabels() {
|
2096 | return this._transport.getPageLabels();
|
2097 | }
|
2098 |
|
2099 | getPageLayout() {
|
2100 | return this._transport.getPageLayout();
|
2101 | }
|
2102 |
|
2103 | getPageMode() {
|
2104 | return this._transport.getPageMode();
|
2105 | }
|
2106 |
|
2107 | getViewerPreferences() {
|
2108 | return this._transport.getViewerPreferences();
|
2109 | }
|
2110 |
|
2111 | getOpenAction() {
|
2112 | return this._transport.getOpenAction();
|
2113 | }
|
2114 |
|
2115 | getOpenActionDestination() {
|
2116 | (0, _display_utils.deprecated)("getOpenActionDestination, use getOpenAction instead.");
|
2117 | return this.getOpenAction().then(function (openAction) {
|
2118 | return openAction && openAction.dest ? openAction.dest : null;
|
2119 | });
|
2120 | }
|
2121 |
|
2122 | getAttachments() {
|
2123 | return this._transport.getAttachments();
|
2124 | }
|
2125 |
|
2126 | getJavaScript() {
|
2127 | return this._transport.getJavaScript();
|
2128 | }
|
2129 |
|
2130 | getOutline() {
|
2131 | return this._transport.getOutline();
|
2132 | }
|
2133 |
|
2134 | getPermissions() {
|
2135 | return this._transport.getPermissions();
|
2136 | }
|
2137 |
|
2138 | getMetadata() {
|
2139 | return this._transport.getMetadata();
|
2140 | }
|
2141 |
|
2142 | getData() {
|
2143 | return this._transport.getData();
|
2144 | }
|
2145 |
|
2146 | getDownloadInfo() {
|
2147 | return this._transport.downloadInfoCapability.promise;
|
2148 | }
|
2149 |
|
2150 | getStats() {
|
2151 | return this._transport.getStats();
|
2152 | }
|
2153 |
|
2154 | cleanup() {
|
2155 | return this._transport.startCleanup();
|
2156 | }
|
2157 |
|
2158 | destroy() {
|
2159 | return this.loadingTask.destroy();
|
2160 | }
|
2161 |
|
2162 | get loadingParams() {
|
2163 | return this._transport.loadingParams;
|
2164 | }
|
2165 |
|
2166 | get loadingTask() {
|
2167 | return this._transport.loadingTask;
|
2168 | }
|
2169 |
|
2170 | }
|
2171 |
|
2172 | exports.PDFDocumentProxy = PDFDocumentProxy;
|
2173 |
|
2174 | class PDFPageProxy {
|
2175 | constructor(pageIndex, pageInfo, transport, pdfBug = false) {
|
2176 | this._pageIndex = pageIndex;
|
2177 | this._pageInfo = pageInfo;
|
2178 | this._transport = transport;
|
2179 | this._stats = pdfBug ? new _display_utils.StatTimer() : null;
|
2180 | this._pdfBug = pdfBug;
|
2181 | this.commonObjs = transport.commonObjs;
|
2182 | this.objs = new PDFObjects();
|
2183 | this.cleanupAfterRender = false;
|
2184 | this.pendingCleanup = false;
|
2185 | this.intentStates = Object.create(null);
|
2186 | this.destroyed = false;
|
2187 | }
|
2188 |
|
2189 | get pageNumber() {
|
2190 | return this._pageIndex + 1;
|
2191 | }
|
2192 |
|
2193 | get rotate() {
|
2194 | return this._pageInfo.rotate;
|
2195 | }
|
2196 |
|
2197 | get ref() {
|
2198 | return this._pageInfo.ref;
|
2199 | }
|
2200 |
|
2201 | get userUnit() {
|
2202 | return this._pageInfo.userUnit;
|
2203 | }
|
2204 |
|
2205 | get view() {
|
2206 | return this._pageInfo.view;
|
2207 | }
|
2208 |
|
2209 | getViewport({
|
2210 | scale,
|
2211 | rotation = this.rotate,
|
2212 | offsetX = 0,
|
2213 | offsetY = 0,
|
2214 | dontFlip = false
|
2215 | } = {}) {
|
2216 | return new _display_utils.PageViewport({
|
2217 | viewBox: this.view,
|
2218 | scale,
|
2219 | rotation,
|
2220 | offsetX,
|
2221 | offsetY,
|
2222 | dontFlip
|
2223 | });
|
2224 | }
|
2225 |
|
2226 | getAnnotations({
|
2227 | intent = null
|
2228 | } = {}) {
|
2229 | if (!this.annotationsPromise || this.annotationsIntent !== intent) {
|
2230 | this.annotationsPromise = this._transport.getAnnotations(this._pageIndex, intent);
|
2231 | this.annotationsIntent = intent;
|
2232 | }
|
2233 |
|
2234 | return this.annotationsPromise;
|
2235 | }
|
2236 |
|
2237 | render({
|
2238 | canvasContext,
|
2239 | viewport,
|
2240 | intent = "display",
|
2241 | enableWebGL = false,
|
2242 | renderInteractiveForms = false,
|
2243 | transform = null,
|
2244 | imageLayer = null,
|
2245 | canvasFactory = null,
|
2246 | background = null
|
2247 | }) {
|
2248 | if (this._stats) {
|
2249 | this._stats.time("Overall");
|
2250 | }
|
2251 |
|
2252 | const renderingIntent = intent === "print" ? "print" : "display";
|
2253 | this.pendingCleanup = false;
|
2254 |
|
2255 | if (!this.intentStates[renderingIntent]) {
|
2256 | this.intentStates[renderingIntent] = Object.create(null);
|
2257 | }
|
2258 |
|
2259 | const intentState = this.intentStates[renderingIntent];
|
2260 |
|
2261 | if (intentState.streamReaderCancelTimeout) {
|
2262 | clearTimeout(intentState.streamReaderCancelTimeout);
|
2263 | intentState.streamReaderCancelTimeout = null;
|
2264 | }
|
2265 |
|
2266 | const canvasFactoryInstance = canvasFactory || new _display_utils.DOMCanvasFactory();
|
2267 | const webGLContext = new _webgl.WebGLContext({
|
2268 | enable: enableWebGL
|
2269 | });
|
2270 |
|
2271 | if (!intentState.displayReadyCapability) {
|
2272 | intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
|
2273 | intentState.operatorList = {
|
2274 | fnArray: [],
|
2275 | argsArray: [],
|
2276 | lastChunk: false
|
2277 | };
|
2278 |
|
2279 | if (this._stats) {
|
2280 | this._stats.time("Page Request");
|
2281 | }
|
2282 |
|
2283 | this._pumpOperatorList({
|
2284 | pageIndex: this._pageIndex,
|
2285 | intent: renderingIntent,
|
2286 | renderInteractiveForms: renderInteractiveForms === true
|
2287 | });
|
2288 | }
|
2289 |
|
2290 | const complete = error => {
|
2291 | const i = intentState.renderTasks.indexOf(internalRenderTask);
|
2292 |
|
2293 | if (i >= 0) {
|
2294 | intentState.renderTasks.splice(i, 1);
|
2295 | }
|
2296 |
|
2297 | if (this.cleanupAfterRender || renderingIntent === "print") {
|
2298 | this.pendingCleanup = true;
|
2299 | }
|
2300 |
|
2301 | this._tryCleanup();
|
2302 |
|
2303 | if (error) {
|
2304 | internalRenderTask.capability.reject(error);
|
2305 |
|
2306 | this._abortOperatorList({
|
2307 | intentState,
|
2308 | reason: error
|
2309 | });
|
2310 | } else {
|
2311 | internalRenderTask.capability.resolve();
|
2312 | }
|
2313 |
|
2314 | if (this._stats) {
|
2315 | this._stats.timeEnd("Rendering");
|
2316 |
|
2317 | this._stats.timeEnd("Overall");
|
2318 | }
|
2319 | };
|
2320 |
|
2321 | const internalRenderTask = new InternalRenderTask({
|
2322 | callback: complete,
|
2323 | params: {
|
2324 | canvasContext,
|
2325 | viewport,
|
2326 | transform,
|
2327 | imageLayer,
|
2328 | background
|
2329 | },
|
2330 | objs: this.objs,
|
2331 | commonObjs: this.commonObjs,
|
2332 | operatorList: intentState.operatorList,
|
2333 | pageIndex: this._pageIndex,
|
2334 | canvasFactory: canvasFactoryInstance,
|
2335 | webGLContext,
|
2336 | useRequestAnimationFrame: renderingIntent !== "print",
|
2337 | pdfBug: this._pdfBug
|
2338 | });
|
2339 |
|
2340 | if (!intentState.renderTasks) {
|
2341 | intentState.renderTasks = [];
|
2342 | }
|
2343 |
|
2344 | intentState.renderTasks.push(internalRenderTask);
|
2345 | const renderTask = internalRenderTask.task;
|
2346 | intentState.displayReadyCapability.promise.then(transparency => {
|
2347 | if (this.pendingCleanup) {
|
2348 | complete();
|
2349 | return;
|
2350 | }
|
2351 |
|
2352 | if (this._stats) {
|
2353 | this._stats.time("Rendering");
|
2354 | }
|
2355 |
|
2356 | internalRenderTask.initializeGraphics(transparency);
|
2357 | internalRenderTask.operatorListChanged();
|
2358 | }).catch(complete);
|
2359 | return renderTask;
|
2360 | }
|
2361 |
|
2362 | getOperatorList() {
|
2363 | function operatorListChanged() {
|
2364 | if (intentState.operatorList.lastChunk) {
|
2365 | intentState.opListReadCapability.resolve(intentState.operatorList);
|
2366 | const i = intentState.renderTasks.indexOf(opListTask);
|
2367 |
|
2368 | if (i >= 0) {
|
2369 | intentState.renderTasks.splice(i, 1);
|
2370 | }
|
2371 | }
|
2372 | }
|
2373 |
|
2374 | const renderingIntent = "oplist";
|
2375 |
|
2376 | if (!this.intentStates[renderingIntent]) {
|
2377 | this.intentStates[renderingIntent] = Object.create(null);
|
2378 | }
|
2379 |
|
2380 | const intentState = this.intentStates[renderingIntent];
|
2381 | let opListTask;
|
2382 |
|
2383 | if (!intentState.opListReadCapability) {
|
2384 | opListTask = {};
|
2385 | opListTask.operatorListChanged = operatorListChanged;
|
2386 | intentState.opListReadCapability = (0, _util.createPromiseCapability)();
|
2387 | intentState.renderTasks = [];
|
2388 | intentState.renderTasks.push(opListTask);
|
2389 | intentState.operatorList = {
|
2390 | fnArray: [],
|
2391 | argsArray: [],
|
2392 | lastChunk: false
|
2393 | };
|
2394 |
|
2395 | if (this._stats) {
|
2396 | this._stats.time("Page Request");
|
2397 | }
|
2398 |
|
2399 | this._pumpOperatorList({
|
2400 | pageIndex: this._pageIndex,
|
2401 | intent: renderingIntent
|
2402 | });
|
2403 | }
|
2404 |
|
2405 | return intentState.opListReadCapability.promise;
|
2406 | }
|
2407 |
|
2408 | streamTextContent({
|
2409 | normalizeWhitespace = false,
|
2410 | disableCombineTextItems = false
|
2411 | } = {}) {
|
2412 | const TEXT_CONTENT_CHUNK_SIZE = 100;
|
2413 | return this._transport.messageHandler.sendWithStream("GetTextContent", {
|
2414 | pageIndex: this._pageIndex,
|
2415 | normalizeWhitespace: normalizeWhitespace === true,
|
2416 | combineTextItems: disableCombineTextItems !== true
|
2417 | }, {
|
2418 | highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
|
2419 |
|
2420 | size(textContent) {
|
2421 | return textContent.items.length;
|
2422 | }
|
2423 |
|
2424 | });
|
2425 | }
|
2426 |
|
2427 | getTextContent(params = {}) {
|
2428 | const readableStream = this.streamTextContent(params);
|
2429 | return new Promise(function (resolve, reject) {
|
2430 | function pump() {
|
2431 | reader.read().then(function ({
|
2432 | value,
|
2433 | done
|
2434 | }) {
|
2435 | if (done) {
|
2436 | resolve(textContent);
|
2437 | return;
|
2438 | }
|
2439 |
|
2440 | Object.assign(textContent.styles, value.styles);
|
2441 | textContent.items.push(...value.items);
|
2442 | pump();
|
2443 | }, reject);
|
2444 | }
|
2445 |
|
2446 | const reader = readableStream.getReader();
|
2447 | const textContent = {
|
2448 | items: [],
|
2449 | styles: Object.create(null)
|
2450 | };
|
2451 | pump();
|
2452 | });
|
2453 | }
|
2454 |
|
2455 | _destroy() {
|
2456 | this.destroyed = true;
|
2457 | this._transport.pageCache[this._pageIndex] = null;
|
2458 | const waitOn = [];
|
2459 | Object.keys(this.intentStates).forEach(intent => {
|
2460 | const intentState = this.intentStates[intent];
|
2461 |
|
2462 | this._abortOperatorList({
|
2463 | intentState,
|
2464 | reason: new Error("Page was destroyed."),
|
2465 | force: true
|
2466 | });
|
2467 |
|
2468 | if (intent === "oplist") {
|
2469 | return;
|
2470 | }
|
2471 |
|
2472 | intentState.renderTasks.forEach(function (renderTask) {
|
2473 | const renderCompleted = renderTask.capability.promise.catch(function () {});
|
2474 | waitOn.push(renderCompleted);
|
2475 | renderTask.cancel();
|
2476 | });
|
2477 | });
|
2478 | this.objs.clear();
|
2479 | this.annotationsPromise = null;
|
2480 | this.pendingCleanup = false;
|
2481 | return Promise.all(waitOn);
|
2482 | }
|
2483 |
|
2484 | cleanup(resetStats = false) {
|
2485 | this.pendingCleanup = true;
|
2486 | return this._tryCleanup(resetStats);
|
2487 | }
|
2488 |
|
2489 | _tryCleanup(resetStats = false) {
|
2490 | if (!this.pendingCleanup || Object.keys(this.intentStates).some(intent => {
|
2491 | const intentState = this.intentStates[intent];
|
2492 | return intentState.renderTasks.length !== 0 || !intentState.operatorList.lastChunk;
|
2493 | })) {
|
2494 | return false;
|
2495 | }
|
2496 |
|
2497 | Object.keys(this.intentStates).forEach(intent => {
|
2498 | delete this.intentStates[intent];
|
2499 | });
|
2500 | this.objs.clear();
|
2501 | this.annotationsPromise = null;
|
2502 |
|
2503 | if (resetStats && this._stats) {
|
2504 | this._stats = new _display_utils.StatTimer();
|
2505 | }
|
2506 |
|
2507 | this.pendingCleanup = false;
|
2508 | return true;
|
2509 | }
|
2510 |
|
2511 | _startRenderPage(transparency, intent) {
|
2512 | const intentState = this.intentStates[intent];
|
2513 |
|
2514 | if (!intentState) {
|
2515 | return;
|
2516 | }
|
2517 |
|
2518 | if (this._stats) {
|
2519 | this._stats.timeEnd("Page Request");
|
2520 | }
|
2521 |
|
2522 | if (intentState.displayReadyCapability) {
|
2523 | intentState.displayReadyCapability.resolve(transparency);
|
2524 | }
|
2525 | }
|
2526 |
|
2527 | _renderPageChunk(operatorListChunk, intentState) {
|
2528 | for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
|
2529 | intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
|
2530 | intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
|
2531 | }
|
2532 |
|
2533 | intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
|
2534 |
|
2535 | for (let i = 0; i < intentState.renderTasks.length; i++) {
|
2536 | intentState.renderTasks[i].operatorListChanged();
|
2537 | }
|
2538 |
|
2539 | if (operatorListChunk.lastChunk) {
|
2540 | this._tryCleanup();
|
2541 | }
|
2542 | }
|
2543 |
|
2544 | _pumpOperatorList(args) {
|
2545 | (0, _util.assert)(args.intent, 'PDFPageProxy._pumpOperatorList: Expected "intent" argument.');
|
2546 |
|
2547 | const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", args);
|
2548 |
|
2549 | const reader = readableStream.getReader();
|
2550 | const intentState = this.intentStates[args.intent];
|
2551 | intentState.streamReader = reader;
|
2552 |
|
2553 | const pump = () => {
|
2554 | reader.read().then(({
|
2555 | value,
|
2556 | done
|
2557 | }) => {
|
2558 | if (done) {
|
2559 | intentState.streamReader = null;
|
2560 | return;
|
2561 | }
|
2562 |
|
2563 | if (this._transport.destroyed) {
|
2564 | return;
|
2565 | }
|
2566 |
|
2567 | this._renderPageChunk(value, intentState);
|
2568 |
|
2569 | pump();
|
2570 | }, reason => {
|
2571 | intentState.streamReader = null;
|
2572 |
|
2573 | if (this._transport.destroyed) {
|
2574 | return;
|
2575 | }
|
2576 |
|
2577 | if (intentState.operatorList) {
|
2578 | intentState.operatorList.lastChunk = true;
|
2579 |
|
2580 | for (let i = 0; i < intentState.renderTasks.length; i++) {
|
2581 | intentState.renderTasks[i].operatorListChanged();
|
2582 | }
|
2583 |
|
2584 | this._tryCleanup();
|
2585 | }
|
2586 |
|
2587 | if (intentState.displayReadyCapability) {
|
2588 | intentState.displayReadyCapability.reject(reason);
|
2589 | } else if (intentState.opListReadCapability) {
|
2590 | intentState.opListReadCapability.reject(reason);
|
2591 | } else {
|
2592 | throw reason;
|
2593 | }
|
2594 | });
|
2595 | };
|
2596 |
|
2597 | pump();
|
2598 | }
|
2599 |
|
2600 | _abortOperatorList({
|
2601 | intentState,
|
2602 | reason,
|
2603 | force = false
|
2604 | }) {
|
2605 | (0, _util.assert)(reason instanceof Error || typeof reason === "object" && reason !== null, 'PDFPageProxy._abortOperatorList: Expected "reason" argument.');
|
2606 |
|
2607 | if (!intentState.streamReader) {
|
2608 | return;
|
2609 | }
|
2610 |
|
2611 | if (!force) {
|
2612 | if (intentState.renderTasks.length !== 0) {
|
2613 | return;
|
2614 | }
|
2615 |
|
2616 | if (reason instanceof _display_utils.RenderingCancelledException) {
|
2617 | intentState.streamReaderCancelTimeout = setTimeout(() => {
|
2618 | this._abortOperatorList({
|
2619 | intentState,
|
2620 | reason,
|
2621 | force: true
|
2622 | });
|
2623 |
|
2624 | intentState.streamReaderCancelTimeout = null;
|
2625 | }, RENDERING_CANCELLED_TIMEOUT);
|
2626 | return;
|
2627 | }
|
2628 | }
|
2629 |
|
2630 | intentState.streamReader.cancel(new _util.AbortException(reason && reason.message));
|
2631 | intentState.streamReader = null;
|
2632 |
|
2633 | if (this._transport.destroyed) {
|
2634 | return;
|
2635 | }
|
2636 |
|
2637 | Object.keys(this.intentStates).some(intent => {
|
2638 | if (this.intentStates[intent] === intentState) {
|
2639 | delete this.intentStates[intent];
|
2640 | return true;
|
2641 | }
|
2642 |
|
2643 | return false;
|
2644 | });
|
2645 | this.cleanup();
|
2646 | }
|
2647 |
|
2648 | get stats() {
|
2649 | return this._stats;
|
2650 | }
|
2651 |
|
2652 | }
|
2653 |
|
2654 | exports.PDFPageProxy = PDFPageProxy;
|
2655 |
|
2656 | class LoopbackPort {
|
2657 | constructor(defer = true) {
|
2658 | this._listeners = [];
|
2659 | this._defer = defer;
|
2660 | this._deferred = Promise.resolve(undefined);
|
2661 | }
|
2662 |
|
2663 | postMessage(obj, transfers) {
|
2664 | function cloneValue(value) {
|
2665 | if (typeof value !== "object" || value === null) {
|
2666 | return value;
|
2667 | }
|
2668 |
|
2669 | if (cloned.has(value)) {
|
2670 | return cloned.get(value);
|
2671 | }
|
2672 |
|
2673 | let buffer, result;
|
2674 |
|
2675 | if ((buffer = value.buffer) && (0, _util.isArrayBuffer)(buffer)) {
|
2676 | const transferable = transfers && transfers.includes(buffer);
|
2677 |
|
2678 | if (transferable) {
|
2679 | result = new value.constructor(buffer, value.byteOffset, value.byteLength);
|
2680 | } else {
|
2681 | result = new value.constructor(value);
|
2682 | }
|
2683 |
|
2684 | cloned.set(value, result);
|
2685 | return result;
|
2686 | }
|
2687 |
|
2688 | result = Array.isArray(value) ? [] : {};
|
2689 | cloned.set(value, result);
|
2690 |
|
2691 | for (const i in value) {
|
2692 | let desc,
|
2693 | p = value;
|
2694 |
|
2695 | while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
|
2696 | p = Object.getPrototypeOf(p);
|
2697 | }
|
2698 |
|
2699 | if (typeof desc.value === "undefined") {
|
2700 | continue;
|
2701 | }
|
2702 |
|
2703 | if (typeof desc.value === "function") {
|
2704 | if (value.hasOwnProperty && value.hasOwnProperty(i)) {
|
2705 | throw new Error(`LoopbackPort.postMessage - cannot clone: ${value[i]}`);
|
2706 | }
|
2707 |
|
2708 | continue;
|
2709 | }
|
2710 |
|
2711 | result[i] = cloneValue(desc.value);
|
2712 | }
|
2713 |
|
2714 | return result;
|
2715 | }
|
2716 |
|
2717 | if (!this._defer) {
|
2718 | this._listeners.forEach(listener => {
|
2719 | listener.call(this, {
|
2720 | data: obj
|
2721 | });
|
2722 | });
|
2723 |
|
2724 | return;
|
2725 | }
|
2726 |
|
2727 | const cloned = new WeakMap();
|
2728 | const e = {
|
2729 | data: cloneValue(obj)
|
2730 | };
|
2731 |
|
2732 | this._deferred.then(() => {
|
2733 | this._listeners.forEach(listener => {
|
2734 | listener.call(this, e);
|
2735 | });
|
2736 | });
|
2737 | }
|
2738 |
|
2739 | addEventListener(name, listener) {
|
2740 | this._listeners.push(listener);
|
2741 | }
|
2742 |
|
2743 | removeEventListener(name, listener) {
|
2744 | const i = this._listeners.indexOf(listener);
|
2745 |
|
2746 | this._listeners.splice(i, 1);
|
2747 | }
|
2748 |
|
2749 | terminate() {
|
2750 | this._listeners.length = 0;
|
2751 | }
|
2752 |
|
2753 | }
|
2754 |
|
2755 | exports.LoopbackPort = LoopbackPort;
|
2756 |
|
2757 | const PDFWorker = function PDFWorkerClosure() {
|
2758 | const pdfWorkerPorts = new WeakMap();
|
2759 | let isWorkerDisabled = false;
|
2760 | let fallbackWorkerSrc;
|
2761 | let nextFakeWorkerId = 0;
|
2762 | let fakeWorkerCapability;
|
2763 |
|
2764 | if (_is_node.isNodeJS && typeof require === "function") {
|
2765 | isWorkerDisabled = true;
|
2766 | fallbackWorkerSrc = "./pdf.worker.js";
|
2767 | } else if (typeof document === "object" && "currentScript" in document) {
|
2768 | const pdfjsFilePath = document.currentScript && document.currentScript.src;
|
2769 |
|
2770 | if (pdfjsFilePath) {
|
2771 | fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
|
2772 | }
|
2773 | }
|
2774 |
|
2775 | function getWorkerSrc() {
|
2776 | if (_worker_options.GlobalWorkerOptions.workerSrc) {
|
2777 | return _worker_options.GlobalWorkerOptions.workerSrc;
|
2778 | }
|
2779 |
|
2780 | if (typeof fallbackWorkerSrc !== "undefined") {
|
2781 | if (!_is_node.isNodeJS) {
|
2782 | (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
|
2783 | }
|
2784 |
|
2785 | return fallbackWorkerSrc;
|
2786 | }
|
2787 |
|
2788 | throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
|
2789 | }
|
2790 |
|
2791 | function getMainThreadWorkerMessageHandler() {
|
2792 | let mainWorkerMessageHandler;
|
2793 |
|
2794 | try {
|
2795 | mainWorkerMessageHandler = globalThis.pdfjsWorker && globalThis.pdfjsWorker.WorkerMessageHandler;
|
2796 | } catch (ex) {}
|
2797 |
|
2798 | return mainWorkerMessageHandler || null;
|
2799 | }
|
2800 |
|
2801 | function setupFakeWorkerGlobal() {
|
2802 | if (fakeWorkerCapability) {
|
2803 | return fakeWorkerCapability.promise;
|
2804 | }
|
2805 |
|
2806 | fakeWorkerCapability = (0, _util.createPromiseCapability)();
|
2807 |
|
2808 | const loader = async function () {
|
2809 | const mainWorkerMessageHandler = getMainThreadWorkerMessageHandler();
|
2810 |
|
2811 | if (mainWorkerMessageHandler) {
|
2812 | return mainWorkerMessageHandler;
|
2813 | }
|
2814 |
|
2815 | if (_is_node.isNodeJS && typeof require === "function") {
|
2816 | const worker = eval("require")(getWorkerSrc());
|
2817 | return worker.WorkerMessageHandler;
|
2818 | }
|
2819 |
|
2820 | await (0, _display_utils.loadScript)(getWorkerSrc());
|
2821 | return window.pdfjsWorker.WorkerMessageHandler;
|
2822 | };
|
2823 |
|
2824 | loader().then(fakeWorkerCapability.resolve, fakeWorkerCapability.reject);
|
2825 | return fakeWorkerCapability.promise;
|
2826 | }
|
2827 |
|
2828 | function createCDNWrapper(url) {
|
2829 | const wrapper = "importScripts('" + url + "');";
|
2830 | return URL.createObjectURL(new Blob([wrapper]));
|
2831 | }
|
2832 |
|
2833 | class PDFWorker {
|
2834 | constructor({
|
2835 | name = null,
|
2836 | port = null,
|
2837 | verbosity = (0, _util.getVerbosityLevel)()
|
2838 | } = {}) {
|
2839 | if (port && pdfWorkerPorts.has(port)) {
|
2840 | throw new Error("Cannot use more than one PDFWorker per port");
|
2841 | }
|
2842 |
|
2843 | this.name = name;
|
2844 | this.destroyed = false;
|
2845 | this.postMessageTransfers = true;
|
2846 | this.verbosity = verbosity;
|
2847 | this._readyCapability = (0, _util.createPromiseCapability)();
|
2848 | this._port = null;
|
2849 | this._webWorker = null;
|
2850 | this._messageHandler = null;
|
2851 |
|
2852 | if (port) {
|
2853 | pdfWorkerPorts.set(port, this);
|
2854 |
|
2855 | this._initializeFromPort(port);
|
2856 |
|
2857 | return;
|
2858 | }
|
2859 |
|
2860 | this._initialize();
|
2861 | }
|
2862 |
|
2863 | get promise() {
|
2864 | return this._readyCapability.promise;
|
2865 | }
|
2866 |
|
2867 | get port() {
|
2868 | return this._port;
|
2869 | }
|
2870 |
|
2871 | get messageHandler() {
|
2872 | return this._messageHandler;
|
2873 | }
|
2874 |
|
2875 | _initializeFromPort(port) {
|
2876 | this._port = port;
|
2877 | this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
|
2878 |
|
2879 | this._messageHandler.on("ready", function () {});
|
2880 |
|
2881 | this._readyCapability.resolve();
|
2882 | }
|
2883 |
|
2884 | _initialize() {
|
2885 | if (typeof Worker !== "undefined" && !isWorkerDisabled && !getMainThreadWorkerMessageHandler()) {
|
2886 | let workerSrc = getWorkerSrc();
|
2887 |
|
2888 | try {
|
2889 | if (!(0, _util.isSameOrigin)(window.location.href, workerSrc)) {
|
2890 | workerSrc = createCDNWrapper(new URL(workerSrc, window.location).href);
|
2891 | }
|
2892 |
|
2893 | const worker = new Worker(workerSrc);
|
2894 | const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
|
2895 |
|
2896 | const terminateEarly = () => {
|
2897 | worker.removeEventListener("error", onWorkerError);
|
2898 | messageHandler.destroy();
|
2899 | worker.terminate();
|
2900 |
|
2901 | if (this.destroyed) {
|
2902 | this._readyCapability.reject(new Error("Worker was destroyed"));
|
2903 | } else {
|
2904 | this._setupFakeWorker();
|
2905 | }
|
2906 | };
|
2907 |
|
2908 | const onWorkerError = () => {
|
2909 | if (!this._webWorker) {
|
2910 | terminateEarly();
|
2911 | }
|
2912 | };
|
2913 |
|
2914 | worker.addEventListener("error", onWorkerError);
|
2915 | messageHandler.on("test", data => {
|
2916 | worker.removeEventListener("error", onWorkerError);
|
2917 |
|
2918 | if (this.destroyed) {
|
2919 | terminateEarly();
|
2920 | return;
|
2921 | }
|
2922 |
|
2923 | if (data) {
|
2924 | this._messageHandler = messageHandler;
|
2925 | this._port = worker;
|
2926 | this._webWorker = worker;
|
2927 |
|
2928 | if (!data.supportTransfers) {
|
2929 | this.postMessageTransfers = false;
|
2930 | }
|
2931 |
|
2932 | this._readyCapability.resolve();
|
2933 |
|
2934 | messageHandler.send("configure", {
|
2935 | verbosity: this.verbosity
|
2936 | });
|
2937 | } else {
|
2938 | this._setupFakeWorker();
|
2939 |
|
2940 | messageHandler.destroy();
|
2941 | worker.terminate();
|
2942 | }
|
2943 | });
|
2944 | messageHandler.on("ready", data => {
|
2945 | worker.removeEventListener("error", onWorkerError);
|
2946 |
|
2947 | if (this.destroyed) {
|
2948 | terminateEarly();
|
2949 | return;
|
2950 | }
|
2951 |
|
2952 | try {
|
2953 | sendTest();
|
2954 | } catch (e) {
|
2955 | this._setupFakeWorker();
|
2956 | }
|
2957 | });
|
2958 |
|
2959 | const sendTest = () => {
|
2960 | const testObj = new Uint8Array([this.postMessageTransfers ? 255 : 0]);
|
2961 |
|
2962 | try {
|
2963 | messageHandler.send("test", testObj, [testObj.buffer]);
|
2964 | } catch (ex) {
|
2965 | (0, _util.warn)("Cannot use postMessage transfers.");
|
2966 | testObj[0] = 0;
|
2967 | messageHandler.send("test", testObj);
|
2968 | }
|
2969 | };
|
2970 |
|
2971 | sendTest();
|
2972 | return;
|
2973 | } catch (e) {
|
2974 | (0, _util.info)("The worker has been disabled.");
|
2975 | }
|
2976 | }
|
2977 |
|
2978 | this._setupFakeWorker();
|
2979 | }
|
2980 |
|
2981 | _setupFakeWorker() {
|
2982 | if (!isWorkerDisabled) {
|
2983 | (0, _util.warn)("Setting up fake worker.");
|
2984 | isWorkerDisabled = true;
|
2985 | }
|
2986 |
|
2987 | setupFakeWorkerGlobal().then(WorkerMessageHandler => {
|
2988 | if (this.destroyed) {
|
2989 | this._readyCapability.reject(new Error("Worker was destroyed"));
|
2990 |
|
2991 | return;
|
2992 | }
|
2993 |
|
2994 | const port = new LoopbackPort();
|
2995 | this._port = port;
|
2996 | const id = "fake" + nextFakeWorkerId++;
|
2997 | const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
|
2998 | WorkerMessageHandler.setup(workerHandler, port);
|
2999 | const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
|
3000 | this._messageHandler = messageHandler;
|
3001 |
|
3002 | this._readyCapability.resolve();
|
3003 |
|
3004 | messageHandler.send("configure", {
|
3005 | verbosity: this.verbosity
|
3006 | });
|
3007 | }).catch(reason => {
|
3008 | this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
|
3009 | });
|
3010 | }
|
3011 |
|
3012 | destroy() {
|
3013 | this.destroyed = true;
|
3014 |
|
3015 | if (this._webWorker) {
|
3016 | this._webWorker.terminate();
|
3017 |
|
3018 | this._webWorker = null;
|
3019 | }
|
3020 |
|
3021 | pdfWorkerPorts.delete(this._port);
|
3022 | this._port = null;
|
3023 |
|
3024 | if (this._messageHandler) {
|
3025 | this._messageHandler.destroy();
|
3026 |
|
3027 | this._messageHandler = null;
|
3028 | }
|
3029 | }
|
3030 |
|
3031 | static fromPort(params) {
|
3032 | if (!params || !params.port) {
|
3033 | throw new Error("PDFWorker.fromPort - invalid method signature.");
|
3034 | }
|
3035 |
|
3036 | if (pdfWorkerPorts.has(params.port)) {
|
3037 | return pdfWorkerPorts.get(params.port);
|
3038 | }
|
3039 |
|
3040 | return new PDFWorker(params);
|
3041 | }
|
3042 |
|
3043 | static getWorkerSrc() {
|
3044 | return getWorkerSrc();
|
3045 | }
|
3046 |
|
3047 | }
|
3048 |
|
3049 | return PDFWorker;
|
3050 | }();
|
3051 |
|
3052 | exports.PDFWorker = PDFWorker;
|
3053 |
|
3054 | class WorkerTransport {
|
3055 | constructor(messageHandler, loadingTask, networkStream, params) {
|
3056 | this.messageHandler = messageHandler;
|
3057 | this.loadingTask = loadingTask;
|
3058 | this.commonObjs = new PDFObjects();
|
3059 | this.fontLoader = new _font_loader.FontLoader({
|
3060 | docId: loadingTask.docId,
|
3061 | onUnsupportedFeature: this._onUnsupportedFeature.bind(this)
|
3062 | });
|
3063 | this._params = params;
|
3064 | this.CMapReaderFactory = new params.CMapReaderFactory({
|
3065 | baseUrl: params.cMapUrl,
|
3066 | isCompressed: params.cMapPacked
|
3067 | });
|
3068 | this.destroyed = false;
|
3069 | this.destroyCapability = null;
|
3070 | this._passwordCapability = null;
|
3071 | this._networkStream = networkStream;
|
3072 | this._fullReader = null;
|
3073 | this._lastProgress = null;
|
3074 | this.pageCache = [];
|
3075 | this.pagePromises = [];
|
3076 | this.downloadInfoCapability = (0, _util.createPromiseCapability)();
|
3077 | this.setupMessageHandler();
|
3078 | }
|
3079 |
|
3080 | destroy() {
|
3081 | if (this.destroyCapability) {
|
3082 | return this.destroyCapability.promise;
|
3083 | }
|
3084 |
|
3085 | this.destroyed = true;
|
3086 | this.destroyCapability = (0, _util.createPromiseCapability)();
|
3087 |
|
3088 | if (this._passwordCapability) {
|
3089 | this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
|
3090 | }
|
3091 |
|
3092 | const waitOn = [];
|
3093 | this.pageCache.forEach(function (page) {
|
3094 | if (page) {
|
3095 | waitOn.push(page._destroy());
|
3096 | }
|
3097 | });
|
3098 | this.pageCache.length = 0;
|
3099 | this.pagePromises.length = 0;
|
3100 | const terminated = this.messageHandler.sendWithPromise("Terminate", null);
|
3101 | waitOn.push(terminated);
|
3102 | Promise.all(waitOn).then(() => {
|
3103 | this.fontLoader.clear();
|
3104 |
|
3105 | if (this._networkStream) {
|
3106 | this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
|
3107 | }
|
3108 |
|
3109 | if (this.messageHandler) {
|
3110 | this.messageHandler.destroy();
|
3111 | this.messageHandler = null;
|
3112 | }
|
3113 |
|
3114 | this.destroyCapability.resolve();
|
3115 | }, this.destroyCapability.reject);
|
3116 | return this.destroyCapability.promise;
|
3117 | }
|
3118 |
|
3119 | setupMessageHandler() {
|
3120 | const {
|
3121 | messageHandler,
|
3122 | loadingTask
|
3123 | } = this;
|
3124 | messageHandler.on("GetReader", (data, sink) => {
|
3125 | (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
|
3126 | this._fullReader = this._networkStream.getFullReader();
|
3127 |
|
3128 | this._fullReader.onProgress = evt => {
|
3129 | this._lastProgress = {
|
3130 | loaded: evt.loaded,
|
3131 | total: evt.total
|
3132 | };
|
3133 | };
|
3134 |
|
3135 | sink.onPull = () => {
|
3136 | this._fullReader.read().then(function ({
|
3137 | value,
|
3138 | done
|
3139 | }) {
|
3140 | if (done) {
|
3141 | sink.close();
|
3142 | return;
|
3143 | }
|
3144 |
|
3145 | (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetReader - expected an ArrayBuffer.");
|
3146 | sink.enqueue(new Uint8Array(value), 1, [value]);
|
3147 | }).catch(reason => {
|
3148 | sink.error(reason);
|
3149 | });
|
3150 | };
|
3151 |
|
3152 | sink.onCancel = reason => {
|
3153 | this._fullReader.cancel(reason);
|
3154 | };
|
3155 | });
|
3156 | messageHandler.on("ReaderHeadersReady", data => {
|
3157 | const headersCapability = (0, _util.createPromiseCapability)();
|
3158 | const fullReader = this._fullReader;
|
3159 | fullReader.headersReady.then(() => {
|
3160 | if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
|
3161 | if (this._lastProgress && loadingTask.onProgress) {
|
3162 | loadingTask.onProgress(this._lastProgress);
|
3163 | }
|
3164 |
|
3165 | fullReader.onProgress = evt => {
|
3166 | if (loadingTask.onProgress) {
|
3167 | loadingTask.onProgress({
|
3168 | loaded: evt.loaded,
|
3169 | total: evt.total
|
3170 | });
|
3171 | }
|
3172 | };
|
3173 | }
|
3174 |
|
3175 | headersCapability.resolve({
|
3176 | isStreamingSupported: fullReader.isStreamingSupported,
|
3177 | isRangeSupported: fullReader.isRangeSupported,
|
3178 | contentLength: fullReader.contentLength
|
3179 | });
|
3180 | }, headersCapability.reject);
|
3181 | return headersCapability.promise;
|
3182 | });
|
3183 | messageHandler.on("GetRangeReader", (data, sink) => {
|
3184 | (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
|
3185 |
|
3186 | const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
|
3187 |
|
3188 | if (!rangeReader) {
|
3189 | sink.close();
|
3190 | return;
|
3191 | }
|
3192 |
|
3193 | sink.onPull = () => {
|
3194 | rangeReader.read().then(function ({
|
3195 | value,
|
3196 | done
|
3197 | }) {
|
3198 | if (done) {
|
3199 | sink.close();
|
3200 | return;
|
3201 | }
|
3202 |
|
3203 | (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetRangeReader - expected an ArrayBuffer.");
|
3204 | sink.enqueue(new Uint8Array(value), 1, [value]);
|
3205 | }).catch(reason => {
|
3206 | sink.error(reason);
|
3207 | });
|
3208 | };
|
3209 |
|
3210 | sink.onCancel = reason => {
|
3211 | rangeReader.cancel(reason);
|
3212 | };
|
3213 | });
|
3214 | messageHandler.on("GetDoc", ({
|
3215 | pdfInfo
|
3216 | }) => {
|
3217 | this._numPages = pdfInfo.numPages;
|
3218 |
|
3219 | loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
|
3220 | });
|
3221 | messageHandler.on("DocException", function (ex) {
|
3222 | let reason;
|
3223 |
|
3224 | switch (ex.name) {
|
3225 | case "PasswordException":
|
3226 | reason = new _util.PasswordException(ex.message, ex.code);
|
3227 | break;
|
3228 |
|
3229 | case "InvalidPDFException":
|
3230 | reason = new _util.InvalidPDFException(ex.message);
|
3231 | break;
|
3232 |
|
3233 | case "MissingPDFException":
|
3234 | reason = new _util.MissingPDFException(ex.message);
|
3235 | break;
|
3236 |
|
3237 | case "UnexpectedResponseException":
|
3238 | reason = new _util.UnexpectedResponseException(ex.message, ex.status);
|
3239 | break;
|
3240 |
|
3241 | case "UnknownErrorException":
|
3242 | reason = new _util.UnknownErrorException(ex.message, ex.details);
|
3243 | break;
|
3244 | }
|
3245 |
|
3246 | loadingTask._capability.reject(reason);
|
3247 | });
|
3248 | messageHandler.on("PasswordRequest", exception => {
|
3249 | this._passwordCapability = (0, _util.createPromiseCapability)();
|
3250 |
|
3251 | if (loadingTask.onPassword) {
|
3252 | const updatePassword = password => {
|
3253 | this._passwordCapability.resolve({
|
3254 | password
|
3255 | });
|
3256 | };
|
3257 |
|
3258 | try {
|
3259 | loadingTask.onPassword(updatePassword, exception.code);
|
3260 | } catch (ex) {
|
3261 | this._passwordCapability.reject(ex);
|
3262 | }
|
3263 | } else {
|
3264 | this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
|
3265 | }
|
3266 |
|
3267 | return this._passwordCapability.promise;
|
3268 | });
|
3269 | messageHandler.on("DataLoaded", data => {
|
3270 | if (loadingTask.onProgress) {
|
3271 | loadingTask.onProgress({
|
3272 | loaded: data.length,
|
3273 | total: data.length
|
3274 | });
|
3275 | }
|
3276 |
|
3277 | this.downloadInfoCapability.resolve(data);
|
3278 | });
|
3279 | messageHandler.on("StartRenderPage", data => {
|
3280 | if (this.destroyed) {
|
3281 | return;
|
3282 | }
|
3283 |
|
3284 | const page = this.pageCache[data.pageIndex];
|
3285 |
|
3286 | page._startRenderPage(data.transparency, data.intent);
|
3287 | });
|
3288 | messageHandler.on("commonobj", data => {
|
3289 | if (this.destroyed) {
|
3290 | return;
|
3291 | }
|
3292 |
|
3293 | const [id, type, exportedData] = data;
|
3294 |
|
3295 | if (this.commonObjs.has(id)) {
|
3296 | return;
|
3297 | }
|
3298 |
|
3299 | switch (type) {
|
3300 | case "Font":
|
3301 | const params = this._params;
|
3302 |
|
3303 | if ("error" in exportedData) {
|
3304 | const exportedError = exportedData.error;
|
3305 | (0, _util.warn)(`Error during font loading: ${exportedError}`);
|
3306 | this.commonObjs.resolve(id, exportedError);
|
3307 | break;
|
3308 | }
|
3309 |
|
3310 | let fontRegistry = null;
|
3311 |
|
3312 | if (params.pdfBug && globalThis.FontInspector && globalThis.FontInspector.enabled) {
|
3313 | fontRegistry = {
|
3314 | registerFont(font, url) {
|
3315 | globalThis.FontInspector.fontAdded(font, url);
|
3316 | }
|
3317 |
|
3318 | };
|
3319 | }
|
3320 |
|
3321 | const font = new _font_loader.FontFaceObject(exportedData, {
|
3322 | isEvalSupported: params.isEvalSupported,
|
3323 | disableFontFace: params.disableFontFace,
|
3324 | ignoreErrors: params.ignoreErrors,
|
3325 | onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
|
3326 | fontRegistry
|
3327 | });
|
3328 | this.fontLoader.bind(font).catch(reason => {
|
3329 | return messageHandler.sendWithPromise("FontFallback", {
|
3330 | id
|
3331 | });
|
3332 | }).finally(() => {
|
3333 | if (!params.fontExtraProperties && font.data) {
|
3334 | font.data = null;
|
3335 | }
|
3336 |
|
3337 | this.commonObjs.resolve(id, font);
|
3338 | });
|
3339 | break;
|
3340 |
|
3341 | case "FontPath":
|
3342 | case "FontType3Res":
|
3343 | case "Image":
|
3344 | this.commonObjs.resolve(id, exportedData);
|
3345 | break;
|
3346 |
|
3347 | default:
|
3348 | throw new Error(`Got unknown common object type ${type}`);
|
3349 | }
|
3350 | });
|
3351 | messageHandler.on("obj", data => {
|
3352 | if (this.destroyed) {
|
3353 | return undefined;
|
3354 | }
|
3355 |
|
3356 | const [id, pageIndex, type, imageData] = data;
|
3357 | const pageProxy = this.pageCache[pageIndex];
|
3358 |
|
3359 | if (pageProxy.objs.has(id)) {
|
3360 | return undefined;
|
3361 | }
|
3362 |
|
3363 | switch (type) {
|
3364 | case "Image":
|
3365 | pageProxy.objs.resolve(id, imageData);
|
3366 | const MAX_IMAGE_SIZE_TO_STORE = 8000000;
|
3367 |
|
3368 | if (imageData && "data" in imageData && imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
|
3369 | pageProxy.cleanupAfterRender = true;
|
3370 | }
|
3371 |
|
3372 | break;
|
3373 |
|
3374 | default:
|
3375 | throw new Error(`Got unknown object type ${type}`);
|
3376 | }
|
3377 |
|
3378 | return undefined;
|
3379 | });
|
3380 | messageHandler.on("DocProgress", data => {
|
3381 | if (this.destroyed) {
|
3382 | return;
|
3383 | }
|
3384 |
|
3385 | if (loadingTask.onProgress) {
|
3386 | loadingTask.onProgress({
|
3387 | loaded: data.loaded,
|
3388 | total: data.total
|
3389 | });
|
3390 | }
|
3391 | });
|
3392 | messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this));
|
3393 | messageHandler.on("FetchBuiltInCMap", (data, sink) => {
|
3394 | if (this.destroyed) {
|
3395 | sink.error(new Error("Worker was destroyed"));
|
3396 | return;
|
3397 | }
|
3398 |
|
3399 | let fetched = false;
|
3400 |
|
3401 | sink.onPull = () => {
|
3402 | if (fetched) {
|
3403 | sink.close();
|
3404 | return;
|
3405 | }
|
3406 |
|
3407 | fetched = true;
|
3408 | this.CMapReaderFactory.fetch(data).then(function (builtInCMap) {
|
3409 | sink.enqueue(builtInCMap, 1, [builtInCMap.cMapData.buffer]);
|
3410 | }).catch(function (reason) {
|
3411 | sink.error(reason);
|
3412 | });
|
3413 | };
|
3414 | });
|
3415 | }
|
3416 |
|
3417 | _onUnsupportedFeature({
|
3418 | featureId
|
3419 | }) {
|
3420 | if (this.destroyed) {
|
3421 | return;
|
3422 | }
|
3423 |
|
3424 | if (this.loadingTask.onUnsupportedFeature) {
|
3425 | this.loadingTask.onUnsupportedFeature(featureId);
|
3426 | }
|
3427 | }
|
3428 |
|
3429 | getData() {
|
3430 | return this.messageHandler.sendWithPromise("GetData", null);
|
3431 | }
|
3432 |
|
3433 | getPage(pageNumber) {
|
3434 | if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
|
3435 | return Promise.reject(new Error("Invalid page request"));
|
3436 | }
|
3437 |
|
3438 | const pageIndex = pageNumber - 1;
|
3439 |
|
3440 | if (pageIndex in this.pagePromises) {
|
3441 | return this.pagePromises[pageIndex];
|
3442 | }
|
3443 |
|
3444 | const promise = this.messageHandler.sendWithPromise("GetPage", {
|
3445 | pageIndex
|
3446 | }).then(pageInfo => {
|
3447 | if (this.destroyed) {
|
3448 | throw new Error("Transport destroyed");
|
3449 | }
|
3450 |
|
3451 | const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.pdfBug);
|
3452 | this.pageCache[pageIndex] = page;
|
3453 | return page;
|
3454 | });
|
3455 | this.pagePromises[pageIndex] = promise;
|
3456 | return promise;
|
3457 | }
|
3458 |
|
3459 | getPageIndex(ref) {
|
3460 | return this.messageHandler.sendWithPromise("GetPageIndex", {
|
3461 | ref
|
3462 | }).catch(function (reason) {
|
3463 | return Promise.reject(new Error(reason));
|
3464 | });
|
3465 | }
|
3466 |
|
3467 | getAnnotations(pageIndex, intent) {
|
3468 | return this.messageHandler.sendWithPromise("GetAnnotations", {
|
3469 | pageIndex,
|
3470 | intent
|
3471 | });
|
3472 | }
|
3473 |
|
3474 | getDestinations() {
|
3475 | return this.messageHandler.sendWithPromise("GetDestinations", null);
|
3476 | }
|
3477 |
|
3478 | getDestination(id) {
|
3479 | if (typeof id !== "string") {
|
3480 | return Promise.reject(new Error("Invalid destination request."));
|
3481 | }
|
3482 |
|
3483 | return this.messageHandler.sendWithPromise("GetDestination", {
|
3484 | id
|
3485 | });
|
3486 | }
|
3487 |
|
3488 | getPageLabels() {
|
3489 | return this.messageHandler.sendWithPromise("GetPageLabels", null);
|
3490 | }
|
3491 |
|
3492 | getPageLayout() {
|
3493 | return this.messageHandler.sendWithPromise("GetPageLayout", null);
|
3494 | }
|
3495 |
|
3496 | getPageMode() {
|
3497 | return this.messageHandler.sendWithPromise("GetPageMode", null);
|
3498 | }
|
3499 |
|
3500 | getViewerPreferences() {
|
3501 | return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
|
3502 | }
|
3503 |
|
3504 | getOpenAction() {
|
3505 | return this.messageHandler.sendWithPromise("GetOpenAction", null);
|
3506 | }
|
3507 |
|
3508 | getAttachments() {
|
3509 | return this.messageHandler.sendWithPromise("GetAttachments", null);
|
3510 | }
|
3511 |
|
3512 | getJavaScript() {
|
3513 | return this.messageHandler.sendWithPromise("GetJavaScript", null);
|
3514 | }
|
3515 |
|
3516 | getOutline() {
|
3517 | return this.messageHandler.sendWithPromise("GetOutline", null);
|
3518 | }
|
3519 |
|
3520 | getPermissions() {
|
3521 | return this.messageHandler.sendWithPromise("GetPermissions", null);
|
3522 | }
|
3523 |
|
3524 | getMetadata() {
|
3525 | return this.messageHandler.sendWithPromise("GetMetadata", null).then(results => {
|
3526 | return {
|
3527 | info: results[0],
|
3528 | metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
|
3529 | contentDispositionFilename: this._fullReader ? this._fullReader.filename : null
|
3530 | };
|
3531 | });
|
3532 | }
|
3533 |
|
3534 | getStats() {
|
3535 | return this.messageHandler.sendWithPromise("GetStats", null);
|
3536 | }
|
3537 |
|
3538 | startCleanup() {
|
3539 | return this.messageHandler.sendWithPromise("Cleanup", null).then(() => {
|
3540 | for (let i = 0, ii = this.pageCache.length; i < ii; i++) {
|
3541 | const page = this.pageCache[i];
|
3542 |
|
3543 | if (page) {
|
3544 | const cleanupSuccessful = page.cleanup();
|
3545 |
|
3546 | if (!cleanupSuccessful) {
|
3547 | throw new Error(`startCleanup: Page ${i + 1} is currently rendering.`);
|
3548 | }
|
3549 | }
|
3550 | }
|
3551 |
|
3552 | this.commonObjs.clear();
|
3553 | this.fontLoader.clear();
|
3554 | });
|
3555 | }
|
3556 |
|
3557 | get loadingParams() {
|
3558 | const params = this._params;
|
3559 | return (0, _util.shadow)(this, "loadingParams", {
|
3560 | disableAutoFetch: params.disableAutoFetch,
|
3561 | disableFontFace: params.disableFontFace
|
3562 | });
|
3563 | }
|
3564 |
|
3565 | }
|
3566 |
|
3567 | class PDFObjects {
|
3568 | constructor() {
|
3569 | this._objs = Object.create(null);
|
3570 | }
|
3571 |
|
3572 | _ensureObj(objId) {
|
3573 | if (this._objs[objId]) {
|
3574 | return this._objs[objId];
|
3575 | }
|
3576 |
|
3577 | return this._objs[objId] = {
|
3578 | capability: (0, _util.createPromiseCapability)(),
|
3579 | data: null,
|
3580 | resolved: false
|
3581 | };
|
3582 | }
|
3583 |
|
3584 | get(objId, callback = null) {
|
3585 | if (callback) {
|
3586 | this._ensureObj(objId).capability.promise.then(callback);
|
3587 |
|
3588 | return null;
|
3589 | }
|
3590 |
|
3591 | const obj = this._objs[objId];
|
3592 |
|
3593 | if (!obj || !obj.resolved) {
|
3594 | throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
|
3595 | }
|
3596 |
|
3597 | return obj.data;
|
3598 | }
|
3599 |
|
3600 | has(objId) {
|
3601 | const obj = this._objs[objId];
|
3602 | return obj ? obj.resolved : false;
|
3603 | }
|
3604 |
|
3605 | resolve(objId, data) {
|
3606 | const obj = this._ensureObj(objId);
|
3607 |
|
3608 | obj.resolved = true;
|
3609 | obj.data = data;
|
3610 | obj.capability.resolve(data);
|
3611 | }
|
3612 |
|
3613 | clear() {
|
3614 | this._objs = Object.create(null);
|
3615 | }
|
3616 |
|
3617 | }
|
3618 |
|
3619 | class RenderTask {
|
3620 | constructor(internalRenderTask) {
|
3621 | this._internalRenderTask = internalRenderTask;
|
3622 | this.onContinue = null;
|
3623 | }
|
3624 |
|
3625 | get promise() {
|
3626 | return this._internalRenderTask.capability.promise;
|
3627 | }
|
3628 |
|
3629 | cancel() {
|
3630 | this._internalRenderTask.cancel();
|
3631 | }
|
3632 |
|
3633 | }
|
3634 |
|
3635 | const InternalRenderTask = function InternalRenderTaskClosure() {
|
3636 | const canvasInRendering = new WeakSet();
|
3637 |
|
3638 | class InternalRenderTask {
|
3639 | constructor({
|
3640 | callback,
|
3641 | params,
|
3642 | objs,
|
3643 | commonObjs,
|
3644 | operatorList,
|
3645 | pageIndex,
|
3646 | canvasFactory,
|
3647 | webGLContext,
|
3648 | useRequestAnimationFrame = false,
|
3649 | pdfBug = false
|
3650 | }) {
|
3651 | this.callback = callback;
|
3652 | this.params = params;
|
3653 | this.objs = objs;
|
3654 | this.commonObjs = commonObjs;
|
3655 | this.operatorListIdx = null;
|
3656 | this.operatorList = operatorList;
|
3657 | this._pageIndex = pageIndex;
|
3658 | this.canvasFactory = canvasFactory;
|
3659 | this.webGLContext = webGLContext;
|
3660 | this._pdfBug = pdfBug;
|
3661 | this.running = false;
|
3662 | this.graphicsReadyCallback = null;
|
3663 | this.graphicsReady = false;
|
3664 | this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
|
3665 | this.cancelled = false;
|
3666 | this.capability = (0, _util.createPromiseCapability)();
|
3667 | this.task = new RenderTask(this);
|
3668 | this._continueBound = this._continue.bind(this);
|
3669 | this._scheduleNextBound = this._scheduleNext.bind(this);
|
3670 | this._nextBound = this._next.bind(this);
|
3671 | this._canvas = params.canvasContext.canvas;
|
3672 | }
|
3673 |
|
3674 | initializeGraphics(transparency = false) {
|
3675 | if (this.cancelled) {
|
3676 | return;
|
3677 | }
|
3678 |
|
3679 | if (this._canvas) {
|
3680 | if (canvasInRendering.has(this._canvas)) {
|
3681 | throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
|
3682 | }
|
3683 |
|
3684 | canvasInRendering.add(this._canvas);
|
3685 | }
|
3686 |
|
3687 | if (this._pdfBug && globalThis.StepperManager && globalThis.StepperManager.enabled) {
|
3688 | this.stepper = globalThis.StepperManager.create(this._pageIndex);
|
3689 | this.stepper.init(this.operatorList);
|
3690 | this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
|
3691 | }
|
3692 |
|
3693 | const {
|
3694 | canvasContext,
|
3695 | viewport,
|
3696 | transform,
|
3697 | imageLayer,
|
3698 | background
|
3699 | } = this.params;
|
3700 | this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext, imageLayer);
|
3701 | this.gfx.beginDrawing({
|
3702 | transform,
|
3703 | viewport,
|
3704 | transparency,
|
3705 | background
|
3706 | });
|
3707 | this.operatorListIdx = 0;
|
3708 | this.graphicsReady = true;
|
3709 |
|
3710 | if (this.graphicsReadyCallback) {
|
3711 | this.graphicsReadyCallback();
|
3712 | }
|
3713 | }
|
3714 |
|
3715 | cancel(error = null) {
|
3716 | this.running = false;
|
3717 | this.cancelled = true;
|
3718 |
|
3719 | if (this.gfx) {
|
3720 | this.gfx.endDrawing();
|
3721 | }
|
3722 |
|
3723 | if (this._canvas) {
|
3724 | canvasInRendering.delete(this._canvas);
|
3725 | }
|
3726 |
|
3727 | this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas"));
|
3728 | }
|
3729 |
|
3730 | operatorListChanged() {
|
3731 | if (!this.graphicsReady) {
|
3732 | if (!this.graphicsReadyCallback) {
|
3733 | this.graphicsReadyCallback = this._continueBound;
|
3734 | }
|
3735 |
|
3736 | return;
|
3737 | }
|
3738 |
|
3739 | if (this.stepper) {
|
3740 | this.stepper.updateOperatorList(this.operatorList);
|
3741 | }
|
3742 |
|
3743 | if (this.running) {
|
3744 | return;
|
3745 | }
|
3746 |
|
3747 | this._continue();
|
3748 | }
|
3749 |
|
3750 | _continue() {
|
3751 | this.running = true;
|
3752 |
|
3753 | if (this.cancelled) {
|
3754 | return;
|
3755 | }
|
3756 |
|
3757 | if (this.task.onContinue) {
|
3758 | this.task.onContinue(this._scheduleNextBound);
|
3759 | } else {
|
3760 | this._scheduleNext();
|
3761 | }
|
3762 | }
|
3763 |
|
3764 | _scheduleNext() {
|
3765 | if (this._useRequestAnimationFrame) {
|
3766 | window.requestAnimationFrame(() => {
|
3767 | this._nextBound().catch(this.cancel.bind(this));
|
3768 | });
|
3769 | } else {
|
3770 | Promise.resolve().then(this._nextBound).catch(this.cancel.bind(this));
|
3771 | }
|
3772 | }
|
3773 |
|
3774 | async _next() {
|
3775 | if (this.cancelled) {
|
3776 | return;
|
3777 | }
|
3778 |
|
3779 | this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
|
3780 |
|
3781 | if (this.operatorListIdx === this.operatorList.argsArray.length) {
|
3782 | this.running = false;
|
3783 |
|
3784 | if (this.operatorList.lastChunk) {
|
3785 | this.gfx.endDrawing();
|
3786 |
|
3787 | if (this._canvas) {
|
3788 | canvasInRendering.delete(this._canvas);
|
3789 | }
|
3790 |
|
3791 | this.callback();
|
3792 | }
|
3793 | }
|
3794 | }
|
3795 |
|
3796 | }
|
3797 |
|
3798 | return InternalRenderTask;
|
3799 | }();
|
3800 |
|
3801 | const version = '2.5.207';
|
3802 | exports.version = version;
|
3803 | const build = '0974d605';
|
3804 | exports.build = build;
|
3805 |
|
3806 | }),
|
3807 |
|
3808 | (function(module, exports, __w_pdfjs_require__) {
|
3809 |
|
3810 | "use strict";
|
3811 |
|
3812 |
|
3813 | Object.defineProperty(exports, "__esModule", {
|
3814 | value: true
|
3815 | });
|
3816 | exports.FontLoader = exports.FontFaceObject = void 0;
|
3817 |
|
3818 | var _util = __w_pdfjs_require__(2);
|
3819 |
|
3820 | class BaseFontLoader {
|
3821 | constructor({
|
3822 | docId,
|
3823 | onUnsupportedFeature
|
3824 | }) {
|
3825 | if (this.constructor === BaseFontLoader) {
|
3826 | (0, _util.unreachable)("Cannot initialize BaseFontLoader.");
|
3827 | }
|
3828 |
|
3829 | this.docId = docId;
|
3830 | this._onUnsupportedFeature = onUnsupportedFeature;
|
3831 | this.nativeFontFaces = [];
|
3832 | this.styleElement = null;
|
3833 | }
|
3834 |
|
3835 | addNativeFontFace(nativeFontFace) {
|
3836 | this.nativeFontFaces.push(nativeFontFace);
|
3837 | document.fonts.add(nativeFontFace);
|
3838 | }
|
3839 |
|
3840 | insertRule(rule) {
|
3841 | let styleElement = this.styleElement;
|
3842 |
|
3843 | if (!styleElement) {
|
3844 | styleElement = this.styleElement = document.createElement("style");
|
3845 | styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
|
3846 | document.documentElement.getElementsByTagName("head")[0].appendChild(styleElement);
|
3847 | }
|
3848 |
|
3849 | const styleSheet = styleElement.sheet;
|
3850 | styleSheet.insertRule(rule, styleSheet.cssRules.length);
|
3851 | }
|
3852 |
|
3853 | clear() {
|
3854 | this.nativeFontFaces.forEach(function (nativeFontFace) {
|
3855 | document.fonts.delete(nativeFontFace);
|
3856 | });
|
3857 | this.nativeFontFaces.length = 0;
|
3858 |
|
3859 | if (this.styleElement) {
|
3860 | this.styleElement.remove();
|
3861 | this.styleElement = null;
|
3862 | }
|
3863 | }
|
3864 |
|
3865 | async bind(font) {
|
3866 | if (font.attached || font.missingFile) {
|
3867 | return;
|
3868 | }
|
3869 |
|
3870 | font.attached = true;
|
3871 |
|
3872 | if (this.isFontLoadingAPISupported) {
|
3873 | const nativeFontFace = font.createNativeFontFace();
|
3874 |
|
3875 | if (nativeFontFace) {
|
3876 | this.addNativeFontFace(nativeFontFace);
|
3877 |
|
3878 | try {
|
3879 | await nativeFontFace.loaded;
|
3880 | } catch (ex) {
|
3881 | this._onUnsupportedFeature({
|
3882 | featureId: _util.UNSUPPORTED_FEATURES.errorFontLoadNative
|
3883 | });
|
3884 |
|
3885 | (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
|
3886 | font.disableFontFace = true;
|
3887 | throw ex;
|
3888 | }
|
3889 | }
|
3890 |
|
3891 | return;
|
3892 | }
|
3893 |
|
3894 | const rule = font.createFontFaceRule();
|
3895 |
|
3896 | if (rule) {
|
3897 | this.insertRule(rule);
|
3898 |
|
3899 | if (this.isSyncFontLoadingSupported) {
|
3900 | return;
|
3901 | }
|
3902 |
|
3903 | await new Promise(resolve => {
|
3904 | const request = this._queueLoadingCallback(resolve);
|
3905 |
|
3906 | this._prepareFontLoadEvent([rule], [font], request);
|
3907 | });
|
3908 | }
|
3909 | }
|
3910 |
|
3911 | _queueLoadingCallback(callback) {
|
3912 | (0, _util.unreachable)("Abstract method `_queueLoadingCallback`.");
|
3913 | }
|
3914 |
|
3915 | get isFontLoadingAPISupported() {
|
3916 | const supported = typeof document !== "undefined" && !!document.fonts;
|
3917 | return (0, _util.shadow)(this, "isFontLoadingAPISupported", supported);
|
3918 | }
|
3919 |
|
3920 | get isSyncFontLoadingSupported() {
|
3921 | (0, _util.unreachable)("Abstract method `isSyncFontLoadingSupported`.");
|
3922 | }
|
3923 |
|
3924 | get _loadTestFont() {
|
3925 | (0, _util.unreachable)("Abstract method `_loadTestFont`.");
|
3926 | }
|
3927 |
|
3928 | _prepareFontLoadEvent(rules, fontsToLoad, request) {
|
3929 | (0, _util.unreachable)("Abstract method `_prepareFontLoadEvent`.");
|
3930 | }
|
3931 |
|
3932 | }
|
3933 |
|
3934 | let FontLoader;
|
3935 | exports.FontLoader = FontLoader;
|
3936 | {
|
3937 | exports.FontLoader = FontLoader = class GenericFontLoader extends BaseFontLoader {
|
3938 | constructor(docId) {
|
3939 | super(docId);
|
3940 | this.loadingContext = {
|
3941 | requests: [],
|
3942 | nextRequestId: 0
|
3943 | };
|
3944 | this.loadTestFontId = 0;
|
3945 | }
|
3946 |
|
3947 | get isSyncFontLoadingSupported() {
|
3948 | let supported = false;
|
3949 |
|
3950 | if (typeof navigator === "undefined") {
|
3951 | supported = true;
|
3952 | } else {
|
3953 | const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
|
3954 |
|
3955 | if (m && m[1] >= 14) {
|
3956 | supported = true;
|
3957 | }
|
3958 | }
|
3959 |
|
3960 | return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
|
3961 | }
|
3962 |
|
3963 | _queueLoadingCallback(callback) {
|
3964 | function completeRequest() {
|
3965 | (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
|
3966 | request.done = true;
|
3967 |
|
3968 | while (context.requests.length > 0 && context.requests[0].done) {
|
3969 | const otherRequest = context.requests.shift();
|
3970 | setTimeout(otherRequest.callback, 0);
|
3971 | }
|
3972 | }
|
3973 |
|
3974 | const context = this.loadingContext;
|
3975 | const request = {
|
3976 | id: `pdfjs-font-loading-${context.nextRequestId++}`,
|
3977 | done: false,
|
3978 | complete: completeRequest,
|
3979 | callback
|
3980 | };
|
3981 | context.requests.push(request);
|
3982 | return request;
|
3983 | }
|
3984 |
|
3985 | get _loadTestFont() {
|
3986 | const getLoadTestFont = function () {
|
3987 | return atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQA" + "FQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAA" + "ALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgA" + "AAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1" + "AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD" + "6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACM" + "AooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4D" + "IP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAA" + "AAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUA" + "AQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgAB" + "AAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABY" + "AAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAA" + "AC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAA" + "AAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQAC" + "AQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3" + "Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTj" + "FQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");
|
3988 | };
|
3989 |
|
3990 | return (0, _util.shadow)(this, "_loadTestFont", getLoadTestFont());
|
3991 | }
|
3992 |
|
3993 | _prepareFontLoadEvent(rules, fonts, request) {
|
3994 | function int32(data, offset) {
|
3995 | return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
|
3996 | }
|
3997 |
|
3998 | function spliceString(s, offset, remove, insert) {
|
3999 | const chunk1 = s.substring(0, offset);
|
4000 | const chunk2 = s.substring(offset + remove);
|
4001 | return chunk1 + insert + chunk2;
|
4002 | }
|
4003 |
|
4004 | let i, ii;
|
4005 | const canvas = document.createElement("canvas");
|
4006 | canvas.width = 1;
|
4007 | canvas.height = 1;
|
4008 | const ctx = canvas.getContext("2d");
|
4009 | let called = 0;
|
4010 |
|
4011 | function isFontReady(name, callback) {
|
4012 | called++;
|
4013 |
|
4014 | if (called > 30) {
|
4015 | (0, _util.warn)("Load test font never loaded.");
|
4016 | callback();
|
4017 | return;
|
4018 | }
|
4019 |
|
4020 | ctx.font = "30px " + name;
|
4021 | ctx.fillText(".", 0, 20);
|
4022 | const imageData = ctx.getImageData(0, 0, 1, 1);
|
4023 |
|
4024 | if (imageData.data[3] > 0) {
|
4025 | callback();
|
4026 | return;
|
4027 | }
|
4028 |
|
4029 | setTimeout(isFontReady.bind(null, name, callback));
|
4030 | }
|
4031 |
|
4032 | const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
|
4033 | let data = this._loadTestFont;
|
4034 | const COMMENT_OFFSET = 976;
|
4035 | data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
|
4036 | const CFF_CHECKSUM_OFFSET = 16;
|
4037 | const XXXX_VALUE = 0x58585858;
|
4038 | let checksum = int32(data, CFF_CHECKSUM_OFFSET);
|
4039 |
|
4040 | for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
|
4041 | checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
|
4042 | }
|
4043 |
|
4044 | if (i < loadTestFontId.length) {
|
4045 | checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
|
4046 | }
|
4047 |
|
4048 | data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
|
4049 | const url = `url(data:font/opentype;base64,${btoa(data)});`;
|
4050 | const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
|
4051 | this.insertRule(rule);
|
4052 | const names = [];
|
4053 |
|
4054 | for (i = 0, ii = fonts.length; i < ii; i++) {
|
4055 | names.push(fonts[i].loadedName);
|
4056 | }
|
4057 |
|
4058 | names.push(loadTestFontId);
|
4059 | const div = document.createElement("div");
|
4060 | div.style.visibility = "hidden";
|
4061 | div.style.width = div.style.height = "10px";
|
4062 | div.style.position = "absolute";
|
4063 | div.style.top = div.style.left = "0px";
|
4064 |
|
4065 | for (i = 0, ii = names.length; i < ii; ++i) {
|
4066 | const span = document.createElement("span");
|
4067 | span.textContent = "Hi";
|
4068 | span.style.fontFamily = names[i];
|
4069 | div.appendChild(span);
|
4070 | }
|
4071 |
|
4072 | document.body.appendChild(div);
|
4073 | isFontReady(loadTestFontId, function () {
|
4074 | document.body.removeChild(div);
|
4075 | request.complete();
|
4076 | });
|
4077 | }
|
4078 |
|
4079 | };
|
4080 | }
|
4081 |
|
4082 | class FontFaceObject {
|
4083 | constructor(translatedData, {
|
4084 | isEvalSupported = true,
|
4085 | disableFontFace = false,
|
4086 | ignoreErrors = false,
|
4087 | onUnsupportedFeature = null,
|
4088 | fontRegistry = null
|
4089 | }) {
|
4090 | this.compiledGlyphs = Object.create(null);
|
4091 |
|
4092 | for (const i in translatedData) {
|
4093 | this[i] = translatedData[i];
|
4094 | }
|
4095 |
|
4096 | this.isEvalSupported = isEvalSupported !== false;
|
4097 | this.disableFontFace = disableFontFace === true;
|
4098 | this.ignoreErrors = ignoreErrors === true;
|
4099 | this._onUnsupportedFeature = onUnsupportedFeature;
|
4100 | this.fontRegistry = fontRegistry;
|
4101 | }
|
4102 |
|
4103 | createNativeFontFace() {
|
4104 | if (!this.data || this.disableFontFace) {
|
4105 | return null;
|
4106 | }
|
4107 |
|
4108 | const nativeFontFace = new FontFace(this.loadedName, this.data, {});
|
4109 |
|
4110 | if (this.fontRegistry) {
|
4111 | this.fontRegistry.registerFont(this);
|
4112 | }
|
4113 |
|
4114 | return nativeFontFace;
|
4115 | }
|
4116 |
|
4117 | createFontFaceRule() {
|
4118 | if (!this.data || this.disableFontFace) {
|
4119 | return null;
|
4120 | }
|
4121 |
|
4122 | const data = (0, _util.bytesToString)(new Uint8Array(this.data));
|
4123 | const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
|
4124 | const rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
|
4125 |
|
4126 | if (this.fontRegistry) {
|
4127 | this.fontRegistry.registerFont(this, url);
|
4128 | }
|
4129 |
|
4130 | return rule;
|
4131 | }
|
4132 |
|
4133 | getPathGenerator(objs, character) {
|
4134 | if (this.compiledGlyphs[character] !== undefined) {
|
4135 | return this.compiledGlyphs[character];
|
4136 | }
|
4137 |
|
4138 | let cmds, current;
|
4139 |
|
4140 | try {
|
4141 | cmds = objs.get(this.loadedName + "_path_" + character);
|
4142 | } catch (ex) {
|
4143 | if (!this.ignoreErrors) {
|
4144 | throw ex;
|
4145 | }
|
4146 |
|
4147 | if (this._onUnsupportedFeature) {
|
4148 | this._onUnsupportedFeature({
|
4149 | featureId: _util.UNSUPPORTED_FEATURES.errorFontGetPath
|
4150 | });
|
4151 | }
|
4152 |
|
4153 | (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
|
4154 | return this.compiledGlyphs[character] = function (c, size) {};
|
4155 | }
|
4156 |
|
4157 | if (this.isEvalSupported && _util.IsEvalSupportedCached.value) {
|
4158 | let args,
|
4159 | js = "";
|
4160 |
|
4161 | for (let i = 0, ii = cmds.length; i < ii; i++) {
|
4162 | current = cmds[i];
|
4163 |
|
4164 | if (current.args !== undefined) {
|
4165 | args = current.args.join(",");
|
4166 | } else {
|
4167 | args = "";
|
4168 | }
|
4169 |
|
4170 | js += "c." + current.cmd + "(" + args + ");\n";
|
4171 | }
|
4172 |
|
4173 | return this.compiledGlyphs[character] = new Function("c", "size", js);
|
4174 | }
|
4175 |
|
4176 | return this.compiledGlyphs[character] = function (c, size) {
|
4177 | for (let i = 0, ii = cmds.length; i < ii; i++) {
|
4178 | current = cmds[i];
|
4179 |
|
4180 | if (current.cmd === "scale") {
|
4181 | current.args = [size, -size];
|
4182 | }
|
4183 |
|
4184 | c[current.cmd].apply(c, current.args);
|
4185 | }
|
4186 | };
|
4187 | }
|
4188 |
|
4189 | }
|
4190 |
|
4191 | exports.FontFaceObject = FontFaceObject;
|
4192 |
|
4193 | }),
|
4194 |
|
4195 | (function(module, exports, __w_pdfjs_require__) {
|
4196 |
|
4197 | "use strict";
|
4198 |
|
4199 |
|
4200 | Object.defineProperty(exports, "__esModule", {
|
4201 | value: true
|
4202 | });
|
4203 | exports.apiCompatibilityParams = void 0;
|
4204 |
|
4205 | var _is_node = __w_pdfjs_require__(4);
|
4206 |
|
4207 | const compatibilityParams = Object.create(null);
|
4208 | {
|
4209 | (function checkFontFace() {
|
4210 | if (_is_node.isNodeJS) {
|
4211 | compatibilityParams.disableFontFace = true;
|
4212 | }
|
4213 | })();
|
4214 | }
|
4215 | const apiCompatibilityParams = Object.freeze(compatibilityParams);
|
4216 | exports.apiCompatibilityParams = apiCompatibilityParams;
|
4217 |
|
4218 | }),
|
4219 |
|
4220 | (function(module, exports, __w_pdfjs_require__) {
|
4221 |
|
4222 | "use strict";
|
4223 |
|
4224 |
|
4225 | Object.defineProperty(exports, "__esModule", {
|
4226 | value: true
|
4227 | });
|
4228 | exports.CanvasGraphics = void 0;
|
4229 |
|
4230 | var _util = __w_pdfjs_require__(2);
|
4231 |
|
4232 | var _pattern_helper = __w_pdfjs_require__(9);
|
4233 |
|
4234 | var MIN_FONT_SIZE = 16;
|
4235 | var MAX_FONT_SIZE = 100;
|
4236 | var MAX_GROUP_SIZE = 4096;
|
4237 | var MIN_WIDTH_FACTOR = 0.65;
|
4238 | var COMPILE_TYPE3_GLYPHS = true;
|
4239 | var MAX_SIZE_TO_COMPILE = 1000;
|
4240 | var FULL_CHUNK_HEIGHT = 16;
|
4241 |
|
4242 | function addContextCurrentTransform(ctx) {
|
4243 | if (!ctx.mozCurrentTransform) {
|
4244 | ctx._originalSave = ctx.save;
|
4245 | ctx._originalRestore = ctx.restore;
|
4246 | ctx._originalRotate = ctx.rotate;
|
4247 | ctx._originalScale = ctx.scale;
|
4248 | ctx._originalTranslate = ctx.translate;
|
4249 | ctx._originalTransform = ctx.transform;
|
4250 | ctx._originalSetTransform = ctx.setTransform;
|
4251 | ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
|
4252 | ctx._transformStack = [];
|
4253 | Object.defineProperty(ctx, "mozCurrentTransform", {
|
4254 | get: function getCurrentTransform() {
|
4255 | return this._transformMatrix;
|
4256 | }
|
4257 | });
|
4258 | Object.defineProperty(ctx, "mozCurrentTransformInverse", {
|
4259 | get: function getCurrentTransformInverse() {
|
4260 | var m = this._transformMatrix;
|
4261 | var a = m[0],
|
4262 | b = m[1],
|
4263 | c = m[2],
|
4264 | d = m[3],
|
4265 | e = m[4],
|
4266 | f = m[5];
|
4267 | var ad_bc = a * d - b * c;
|
4268 | var bc_ad = b * c - a * d;
|
4269 | return [d / ad_bc, b / bc_ad, c / bc_ad, a / ad_bc, (d * e - c * f) / bc_ad, (b * e - a * f) / ad_bc];
|
4270 | }
|
4271 | });
|
4272 |
|
4273 | ctx.save = function ctxSave() {
|
4274 | var old = this._transformMatrix;
|
4275 |
|
4276 | this._transformStack.push(old);
|
4277 |
|
4278 | this._transformMatrix = old.slice(0, 6);
|
4279 |
|
4280 | this._originalSave();
|
4281 | };
|
4282 |
|
4283 | ctx.restore = function ctxRestore() {
|
4284 | var prev = this._transformStack.pop();
|
4285 |
|
4286 | if (prev) {
|
4287 | this._transformMatrix = prev;
|
4288 |
|
4289 | this._originalRestore();
|
4290 | }
|
4291 | };
|
4292 |
|
4293 | ctx.translate = function ctxTranslate(x, y) {
|
4294 | var m = this._transformMatrix;
|
4295 | m[4] = m[0] * x + m[2] * y + m[4];
|
4296 | m[5] = m[1] * x + m[3] * y + m[5];
|
4297 |
|
4298 | this._originalTranslate(x, y);
|
4299 | };
|
4300 |
|
4301 | ctx.scale = function ctxScale(x, y) {
|
4302 | var m = this._transformMatrix;
|
4303 | m[0] = m[0] * x;
|
4304 | m[1] = m[1] * x;
|
4305 | m[2] = m[2] * y;
|
4306 | m[3] = m[3] * y;
|
4307 |
|
4308 | this._originalScale(x, y);
|
4309 | };
|
4310 |
|
4311 | ctx.transform = function ctxTransform(a, b, c, d, e, f) {
|
4312 | var m = this._transformMatrix;
|
4313 | this._transformMatrix = [m[0] * a + m[2] * b, m[1] * a + m[3] * b, m[0] * c + m[2] * d, m[1] * c + m[3] * d, m[0] * e + m[2] * f + m[4], m[1] * e + m[3] * f + m[5]];
|
4314 |
|
4315 | ctx._originalTransform(a, b, c, d, e, f);
|
4316 | };
|
4317 |
|
4318 | ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
|
4319 | this._transformMatrix = [a, b, c, d, e, f];
|
4320 |
|
4321 | ctx._originalSetTransform(a, b, c, d, e, f);
|
4322 | };
|
4323 |
|
4324 | ctx.rotate = function ctxRotate(angle) {
|
4325 | var cosValue = Math.cos(angle);
|
4326 | var sinValue = Math.sin(angle);
|
4327 | var m = this._transformMatrix;
|
4328 | this._transformMatrix = [m[0] * cosValue + m[2] * sinValue, m[1] * cosValue + m[3] * sinValue, m[0] * -sinValue + m[2] * cosValue, m[1] * -sinValue + m[3] * cosValue, m[4], m[5]];
|
4329 |
|
4330 | this._originalRotate(angle);
|
4331 | };
|
4332 | }
|
4333 | }
|
4334 |
|
4335 | var CachedCanvases = function CachedCanvasesClosure() {
|
4336 | function CachedCanvases(canvasFactory) {
|
4337 | this.canvasFactory = canvasFactory;
|
4338 | this.cache = Object.create(null);
|
4339 | }
|
4340 |
|
4341 | CachedCanvases.prototype = {
|
4342 | getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
|
4343 | var canvasEntry;
|
4344 |
|
4345 | if (this.cache[id] !== undefined) {
|
4346 | canvasEntry = this.cache[id];
|
4347 | this.canvasFactory.reset(canvasEntry, width, height);
|
4348 | canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
|
4349 | } else {
|
4350 | canvasEntry = this.canvasFactory.create(width, height);
|
4351 | this.cache[id] = canvasEntry;
|
4352 | }
|
4353 |
|
4354 | if (trackTransform) {
|
4355 | addContextCurrentTransform(canvasEntry.context);
|
4356 | }
|
4357 |
|
4358 | return canvasEntry;
|
4359 | },
|
4360 |
|
4361 | clear() {
|
4362 | for (var id in this.cache) {
|
4363 | var canvasEntry = this.cache[id];
|
4364 | this.canvasFactory.destroy(canvasEntry);
|
4365 | delete this.cache[id];
|
4366 | }
|
4367 | }
|
4368 |
|
4369 | };
|
4370 | return CachedCanvases;
|
4371 | }();
|
4372 |
|
4373 | function compileType3Glyph(imgData) {
|
4374 | var POINT_TO_PROCESS_LIMIT = 1000;
|
4375 | var width = imgData.width,
|
4376 | height = imgData.height;
|
4377 | var i,
|
4378 | j,
|
4379 | j0,
|
4380 | width1 = width + 1;
|
4381 | var points = new Uint8Array(width1 * (height + 1));
|
4382 | var POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
|
4383 | var lineSize = width + 7 & ~7,
|
4384 | data0 = imgData.data;
|
4385 | var data = new Uint8Array(lineSize * height),
|
4386 | pos = 0,
|
4387 | ii;
|
4388 |
|
4389 | for (i = 0, ii = data0.length; i < ii; i++) {
|
4390 | var mask = 128,
|
4391 | elem = data0[i];
|
4392 |
|
4393 | while (mask > 0) {
|
4394 | data[pos++] = elem & mask ? 0 : 255;
|
4395 | mask >>= 1;
|
4396 | }
|
4397 | }
|
4398 |
|
4399 | var count = 0;
|
4400 | pos = 0;
|
4401 |
|
4402 | if (data[pos] !== 0) {
|
4403 | points[0] = 1;
|
4404 | ++count;
|
4405 | }
|
4406 |
|
4407 | for (j = 1; j < width; j++) {
|
4408 | if (data[pos] !== data[pos + 1]) {
|
4409 | points[j] = data[pos] ? 2 : 1;
|
4410 | ++count;
|
4411 | }
|
4412 |
|
4413 | pos++;
|
4414 | }
|
4415 |
|
4416 | if (data[pos] !== 0) {
|
4417 | points[j] = 2;
|
4418 | ++count;
|
4419 | }
|
4420 |
|
4421 | for (i = 1; i < height; i++) {
|
4422 | pos = i * lineSize;
|
4423 | j0 = i * width1;
|
4424 |
|
4425 | if (data[pos - lineSize] !== data[pos]) {
|
4426 | points[j0] = data[pos] ? 1 : 8;
|
4427 | ++count;
|
4428 | }
|
4429 |
|
4430 | var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
|
4431 |
|
4432 | for (j = 1; j < width; j++) {
|
4433 | sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
|
4434 |
|
4435 | if (POINT_TYPES[sum]) {
|
4436 | points[j0 + j] = POINT_TYPES[sum];
|
4437 | ++count;
|
4438 | }
|
4439 |
|
4440 | pos++;
|
4441 | }
|
4442 |
|
4443 | if (data[pos - lineSize] !== data[pos]) {
|
4444 | points[j0 + j] = data[pos] ? 2 : 4;
|
4445 | ++count;
|
4446 | }
|
4447 |
|
4448 | if (count > POINT_TO_PROCESS_LIMIT) {
|
4449 | return null;
|
4450 | }
|
4451 | }
|
4452 |
|
4453 | pos = lineSize * (height - 1);
|
4454 | j0 = i * width1;
|
4455 |
|
4456 | if (data[pos] !== 0) {
|
4457 | points[j0] = 8;
|
4458 | ++count;
|
4459 | }
|
4460 |
|
4461 | for (j = 1; j < width; j++) {
|
4462 | if (data[pos] !== data[pos + 1]) {
|
4463 | points[j0 + j] = data[pos] ? 4 : 8;
|
4464 | ++count;
|
4465 | }
|
4466 |
|
4467 | pos++;
|
4468 | }
|
4469 |
|
4470 | if (data[pos] !== 0) {
|
4471 | points[j0 + j] = 4;
|
4472 | ++count;
|
4473 | }
|
4474 |
|
4475 | if (count > POINT_TO_PROCESS_LIMIT) {
|
4476 | return null;
|
4477 | }
|
4478 |
|
4479 | var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
|
4480 | var outlines = [];
|
4481 |
|
4482 | for (i = 0; count && i <= height; i++) {
|
4483 | var p = i * width1;
|
4484 | var end = p + width;
|
4485 |
|
4486 | while (p < end && !points[p]) {
|
4487 | p++;
|
4488 | }
|
4489 |
|
4490 | if (p === end) {
|
4491 | continue;
|
4492 | }
|
4493 |
|
4494 | var coords = [p % width1, i];
|
4495 | var type = points[p],
|
4496 | p0 = p,
|
4497 | pp;
|
4498 |
|
4499 | do {
|
4500 | var step = steps[type];
|
4501 |
|
4502 | do {
|
4503 | p += step;
|
4504 | } while (!points[p]);
|
4505 |
|
4506 | pp = points[p];
|
4507 |
|
4508 | if (pp !== 5 && pp !== 10) {
|
4509 | type = pp;
|
4510 | points[p] = 0;
|
4511 | } else {
|
4512 | type = pp & 0x33 * type >> 4;
|
4513 | points[p] &= type >> 2 | type << 2;
|
4514 | }
|
4515 |
|
4516 | coords.push(p % width1);
|
4517 | coords.push(p / width1 | 0);
|
4518 |
|
4519 | if (!points[p]) {
|
4520 | --count;
|
4521 | }
|
4522 | } while (p0 !== p);
|
4523 |
|
4524 | outlines.push(coords);
|
4525 | --i;
|
4526 | }
|
4527 |
|
4528 | var drawOutline = function (c) {
|
4529 | c.save();
|
4530 | c.scale(1 / width, -1 / height);
|
4531 | c.translate(0, -height);
|
4532 | c.beginPath();
|
4533 |
|
4534 | for (let k = 0, kk = outlines.length; k < kk; k++) {
|
4535 | var o = outlines[k];
|
4536 | c.moveTo(o[0], o[1]);
|
4537 |
|
4538 | for (let l = 2, ll = o.length; l < ll; l += 2) {
|
4539 | c.lineTo(o[l], o[l + 1]);
|
4540 | }
|
4541 | }
|
4542 |
|
4543 | c.fill();
|
4544 | c.beginPath();
|
4545 | c.restore();
|
4546 | };
|
4547 |
|
4548 | return drawOutline;
|
4549 | }
|
4550 |
|
4551 | var CanvasExtraState = function CanvasExtraStateClosure() {
|
4552 | function CanvasExtraState() {
|
4553 | this.alphaIsShape = false;
|
4554 | this.fontSize = 0;
|
4555 | this.fontSizeScale = 1;
|
4556 | this.textMatrix = _util.IDENTITY_MATRIX;
|
4557 | this.textMatrixScale = 1;
|
4558 | this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
|
4559 | this.leading = 0;
|
4560 | this.x = 0;
|
4561 | this.y = 0;
|
4562 | this.lineX = 0;
|
4563 | this.lineY = 0;
|
4564 | this.charSpacing = 0;
|
4565 | this.wordSpacing = 0;
|
4566 | this.textHScale = 1;
|
4567 | this.textRenderingMode = _util.TextRenderingMode.FILL;
|
4568 | this.textRise = 0;
|
4569 | this.fillColor = "#000000";
|
4570 | this.strokeColor = "#000000";
|
4571 | this.patternFill = false;
|
4572 | this.fillAlpha = 1;
|
4573 | this.strokeAlpha = 1;
|
4574 | this.lineWidth = 1;
|
4575 | this.activeSMask = null;
|
4576 | this.resumeSMaskCtx = null;
|
4577 | }
|
4578 |
|
4579 | CanvasExtraState.prototype = {
|
4580 | clone: function CanvasExtraState_clone() {
|
4581 | return Object.create(this);
|
4582 | },
|
4583 | setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
|
4584 | this.x = x;
|
4585 | this.y = y;
|
4586 | }
|
4587 | };
|
4588 | return CanvasExtraState;
|
4589 | }();
|
4590 |
|
4591 | var CanvasGraphics = function CanvasGraphicsClosure() {
|
4592 | var EXECUTION_TIME = 15;
|
4593 | var EXECUTION_STEPS = 10;
|
4594 |
|
4595 | function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, webGLContext, imageLayer) {
|
4596 | this.ctx = canvasCtx;
|
4597 | this.current = new CanvasExtraState();
|
4598 | this.stateStack = [];
|
4599 | this.pendingClip = null;
|
4600 | this.pendingEOFill = false;
|
4601 | this.res = null;
|
4602 | this.xobjs = null;
|
4603 | this.commonObjs = commonObjs;
|
4604 | this.objs = objs;
|
4605 | this.canvasFactory = canvasFactory;
|
4606 | this.webGLContext = webGLContext;
|
4607 | this.imageLayer = imageLayer;
|
4608 | this.groupStack = [];
|
4609 | this.processingType3 = null;
|
4610 | this.baseTransform = null;
|
4611 | this.baseTransformStack = [];
|
4612 | this.groupLevel = 0;
|
4613 | this.smaskStack = [];
|
4614 | this.smaskCounter = 0;
|
4615 | this.tempSMask = null;
|
4616 | this.cachedCanvases = new CachedCanvases(this.canvasFactory);
|
4617 |
|
4618 | if (canvasCtx) {
|
4619 | addContextCurrentTransform(canvasCtx);
|
4620 | }
|
4621 |
|
4622 | this._cachedGetSinglePixelWidth = null;
|
4623 | }
|
4624 |
|
4625 | function putBinaryImageData(ctx, imgData) {
|
4626 | if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
|
4627 | ctx.putImageData(imgData, 0, 0);
|
4628 | return;
|
4629 | }
|
4630 |
|
4631 | var height = imgData.height,
|
4632 | width = imgData.width;
|
4633 | var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
|
4634 | var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
|
4635 | var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
|
4636 | var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
|
4637 | var srcPos = 0,
|
4638 | destPos;
|
4639 | var src = imgData.data;
|
4640 | var dest = chunkImgData.data;
|
4641 | var i, j, thisChunkHeight, elemsInThisChunk;
|
4642 |
|
4643 | if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
|
4644 | var srcLength = src.byteLength;
|
4645 | var dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
|
4646 | var dest32DataLength = dest32.length;
|
4647 | var fullSrcDiff = width + 7 >> 3;
|
4648 | var white = 0xffffffff;
|
4649 | var black = _util.IsLittleEndianCached.value ? 0xff000000 : 0x000000ff;
|
4650 |
|
4651 | for (i = 0; i < totalChunks; i++) {
|
4652 | thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
|
4653 | destPos = 0;
|
4654 |
|
4655 | for (j = 0; j < thisChunkHeight; j++) {
|
4656 | var srcDiff = srcLength - srcPos;
|
4657 | var k = 0;
|
4658 | var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
|
4659 | var kEndUnrolled = kEnd & ~7;
|
4660 | var mask = 0;
|
4661 | var srcByte = 0;
|
4662 |
|
4663 | for (; k < kEndUnrolled; k += 8) {
|
4664 | srcByte = src[srcPos++];
|
4665 | dest32[destPos++] = srcByte & 128 ? white : black;
|
4666 | dest32[destPos++] = srcByte & 64 ? white : black;
|
4667 | dest32[destPos++] = srcByte & 32 ? white : black;
|
4668 | dest32[destPos++] = srcByte & 16 ? white : black;
|
4669 | dest32[destPos++] = srcByte & 8 ? white : black;
|
4670 | dest32[destPos++] = srcByte & 4 ? white : black;
|
4671 | dest32[destPos++] = srcByte & 2 ? white : black;
|
4672 | dest32[destPos++] = srcByte & 1 ? white : black;
|
4673 | }
|
4674 |
|
4675 | for (; k < kEnd; k++) {
|
4676 | if (mask === 0) {
|
4677 | srcByte = src[srcPos++];
|
4678 | mask = 128;
|
4679 | }
|
4680 |
|
4681 | dest32[destPos++] = srcByte & mask ? white : black;
|
4682 | mask >>= 1;
|
4683 | }
|
4684 | }
|
4685 |
|
4686 | while (destPos < dest32DataLength) {
|
4687 | dest32[destPos++] = 0;
|
4688 | }
|
4689 |
|
4690 | ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
|
4691 | }
|
4692 | } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
|
4693 | j = 0;
|
4694 | elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
|
4695 |
|
4696 | for (i = 0; i < fullChunks; i++) {
|
4697 | dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
|
4698 | srcPos += elemsInThisChunk;
|
4699 | ctx.putImageData(chunkImgData, 0, j);
|
4700 | j += FULL_CHUNK_HEIGHT;
|
4701 | }
|
4702 |
|
4703 | if (i < totalChunks) {
|
4704 | elemsInThisChunk = width * partialChunkHeight * 4;
|
4705 | dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
|
4706 | ctx.putImageData(chunkImgData, 0, j);
|
4707 | }
|
4708 | } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
|
4709 | thisChunkHeight = FULL_CHUNK_HEIGHT;
|
4710 | elemsInThisChunk = width * thisChunkHeight;
|
4711 |
|
4712 | for (i = 0; i < totalChunks; i++) {
|
4713 | if (i >= fullChunks) {
|
4714 | thisChunkHeight = partialChunkHeight;
|
4715 | elemsInThisChunk = width * thisChunkHeight;
|
4716 | }
|
4717 |
|
4718 | destPos = 0;
|
4719 |
|
4720 | for (j = elemsInThisChunk; j--;) {
|
4721 | dest[destPos++] = src[srcPos++];
|
4722 | dest[destPos++] = src[srcPos++];
|
4723 | dest[destPos++] = src[srcPos++];
|
4724 | dest[destPos++] = 255;
|
4725 | }
|
4726 |
|
4727 | ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
|
4728 | }
|
4729 | } else {
|
4730 | throw new Error(`bad image kind: ${imgData.kind}`);
|
4731 | }
|
4732 | }
|
4733 |
|
4734 | function putBinaryImageMask(ctx, imgData) {
|
4735 | var height = imgData.height,
|
4736 | width = imgData.width;
|
4737 | var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
|
4738 | var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
|
4739 | var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
|
4740 | var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
|
4741 | var srcPos = 0;
|
4742 | var src = imgData.data;
|
4743 | var dest = chunkImgData.data;
|
4744 |
|
4745 | for (var i = 0; i < totalChunks; i++) {
|
4746 | var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
|
4747 | var destPos = 3;
|
4748 |
|
4749 | for (var j = 0; j < thisChunkHeight; j++) {
|
4750 | var mask = 0;
|
4751 |
|
4752 | for (var k = 0; k < width; k++) {
|
4753 | if (!mask) {
|
4754 | var elem = src[srcPos++];
|
4755 | mask = 128;
|
4756 | }
|
4757 |
|
4758 | dest[destPos] = elem & mask ? 0 : 255;
|
4759 | destPos += 4;
|
4760 | mask >>= 1;
|
4761 | }
|
4762 | }
|
4763 |
|
4764 | ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
|
4765 | }
|
4766 | }
|
4767 |
|
4768 | function copyCtxState(sourceCtx, destCtx) {
|
4769 | var properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
|
4770 |
|
4771 | for (var i = 0, ii = properties.length; i < ii; i++) {
|
4772 | var property = properties[i];
|
4773 |
|
4774 | if (sourceCtx[property] !== undefined) {
|
4775 | destCtx[property] = sourceCtx[property];
|
4776 | }
|
4777 | }
|
4778 |
|
4779 | if (sourceCtx.setLineDash !== undefined) {
|
4780 | destCtx.setLineDash(sourceCtx.getLineDash());
|
4781 | destCtx.lineDashOffset = sourceCtx.lineDashOffset;
|
4782 | }
|
4783 | }
|
4784 |
|
4785 | function resetCtxToDefault(ctx) {
|
4786 | ctx.strokeStyle = "#000000";
|
4787 | ctx.fillStyle = "#000000";
|
4788 | ctx.fillRule = "nonzero";
|
4789 | ctx.globalAlpha = 1;
|
4790 | ctx.lineWidth = 1;
|
4791 | ctx.lineCap = "butt";
|
4792 | ctx.lineJoin = "miter";
|
4793 | ctx.miterLimit = 10;
|
4794 | ctx.globalCompositeOperation = "source-over";
|
4795 | ctx.font = "10px sans-serif";
|
4796 |
|
4797 | if (ctx.setLineDash !== undefined) {
|
4798 | ctx.setLineDash([]);
|
4799 | ctx.lineDashOffset = 0;
|
4800 | }
|
4801 | }
|
4802 |
|
4803 | function composeSMaskBackdrop(bytes, r0, g0, b0) {
|
4804 | var length = bytes.length;
|
4805 |
|
4806 | for (var i = 3; i < length; i += 4) {
|
4807 | var alpha = bytes[i];
|
4808 |
|
4809 | if (alpha === 0) {
|
4810 | bytes[i - 3] = r0;
|
4811 | bytes[i - 2] = g0;
|
4812 | bytes[i - 1] = b0;
|
4813 | } else if (alpha < 255) {
|
4814 | var alpha_ = 255 - alpha;
|
4815 | bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
|
4816 | bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
|
4817 | bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
|
4818 | }
|
4819 | }
|
4820 | }
|
4821 |
|
4822 | function composeSMaskAlpha(maskData, layerData, transferMap) {
|
4823 | var length = maskData.length;
|
4824 | var scale = 1 / 255;
|
4825 |
|
4826 | for (var i = 3; i < length; i += 4) {
|
4827 | var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
|
4828 | layerData[i] = layerData[i] * alpha * scale | 0;
|
4829 | }
|
4830 | }
|
4831 |
|
4832 | function composeSMaskLuminosity(maskData, layerData, transferMap) {
|
4833 | var length = maskData.length;
|
4834 |
|
4835 | for (var i = 3; i < length; i += 4) {
|
4836 | var y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
|
4837 | layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
|
4838 | }
|
4839 | }
|
4840 |
|
4841 | function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
|
4842 | var hasBackdrop = !!backdrop;
|
4843 | var r0 = hasBackdrop ? backdrop[0] : 0;
|
4844 | var g0 = hasBackdrop ? backdrop[1] : 0;
|
4845 | var b0 = hasBackdrop ? backdrop[2] : 0;
|
4846 | var composeFn;
|
4847 |
|
4848 | if (subtype === "Luminosity") {
|
4849 | composeFn = composeSMaskLuminosity;
|
4850 | } else {
|
4851 | composeFn = composeSMaskAlpha;
|
4852 | }
|
4853 |
|
4854 | var PIXELS_TO_PROCESS = 1048576;
|
4855 | var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
|
4856 |
|
4857 | for (var row = 0; row < height; row += chunkSize) {
|
4858 | var chunkHeight = Math.min(chunkSize, height - row);
|
4859 | var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
|
4860 | var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
|
4861 |
|
4862 | if (hasBackdrop) {
|
4863 | composeSMaskBackdrop(maskData.data, r0, g0, b0);
|
4864 | }
|
4865 |
|
4866 | composeFn(maskData.data, layerData.data, transferMap);
|
4867 | maskCtx.putImageData(layerData, 0, row);
|
4868 | }
|
4869 | }
|
4870 |
|
4871 | function composeSMask(ctx, smask, layerCtx, webGLContext) {
|
4872 | var mask = smask.canvas;
|
4873 | var maskCtx = smask.context;
|
4874 | ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
|
4875 | var backdrop = smask.backdrop || null;
|
4876 |
|
4877 | if (!smask.transferMap && webGLContext.isEnabled) {
|
4878 | const composed = webGLContext.composeSMask({
|
4879 | layer: layerCtx.canvas,
|
4880 | mask,
|
4881 | properties: {
|
4882 | subtype: smask.subtype,
|
4883 | backdrop
|
4884 | }
|
4885 | });
|
4886 | ctx.setTransform(1, 0, 0, 1, 0, 0);
|
4887 | ctx.drawImage(composed, smask.offsetX, smask.offsetY);
|
4888 | return;
|
4889 | }
|
4890 |
|
4891 | genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
|
4892 | ctx.drawImage(mask, 0, 0);
|
4893 | }
|
4894 |
|
4895 | var LINE_CAP_STYLES = ["butt", "round", "square"];
|
4896 | var LINE_JOIN_STYLES = ["miter", "round", "bevel"];
|
4897 | var NORMAL_CLIP = {};
|
4898 | var EO_CLIP = {};
|
4899 | CanvasGraphics.prototype = {
|
4900 | beginDrawing({
|
4901 | transform,
|
4902 | viewport,
|
4903 | transparency = false,
|
4904 | background = null
|
4905 | }) {
|
4906 | var width = this.ctx.canvas.width;
|
4907 | var height = this.ctx.canvas.height;
|
4908 | this.ctx.save();
|
4909 | this.ctx.fillStyle = background || "rgb(255, 255, 255)";
|
4910 | this.ctx.fillRect(0, 0, width, height);
|
4911 | this.ctx.restore();
|
4912 |
|
4913 | if (transparency) {
|
4914 | var transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height, true);
|
4915 | this.compositeCtx = this.ctx;
|
4916 | this.transparentCanvas = transparentCanvas.canvas;
|
4917 | this.ctx = transparentCanvas.context;
|
4918 | this.ctx.save();
|
4919 | this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
|
4920 | }
|
4921 |
|
4922 | this.ctx.save();
|
4923 | resetCtxToDefault(this.ctx);
|
4924 |
|
4925 | if (transform) {
|
4926 | this.ctx.transform.apply(this.ctx, transform);
|
4927 | }
|
4928 |
|
4929 | this.ctx.transform.apply(this.ctx, viewport.transform);
|
4930 | this.baseTransform = this.ctx.mozCurrentTransform.slice();
|
4931 |
|
4932 | if (this.imageLayer) {
|
4933 | this.imageLayer.beginLayout();
|
4934 | }
|
4935 | },
|
4936 |
|
4937 | executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
|
4938 | var argsArray = operatorList.argsArray;
|
4939 | var fnArray = operatorList.fnArray;
|
4940 | var i = executionStartIdx || 0;
|
4941 | var argsArrayLen = argsArray.length;
|
4942 |
|
4943 | if (argsArrayLen === i) {
|
4944 | return i;
|
4945 | }
|
4946 |
|
4947 | var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
|
4948 | var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
|
4949 | var steps = 0;
|
4950 | var commonObjs = this.commonObjs;
|
4951 | var objs = this.objs;
|
4952 | var fnId;
|
4953 |
|
4954 | while (true) {
|
4955 | if (stepper !== undefined && i === stepper.nextBreakPoint) {
|
4956 | stepper.breakIt(i, continueCallback);
|
4957 | return i;
|
4958 | }
|
4959 |
|
4960 | fnId = fnArray[i];
|
4961 |
|
4962 | if (fnId !== _util.OPS.dependency) {
|
4963 | this[fnId].apply(this, argsArray[i]);
|
4964 | } else {
|
4965 | for (const depObjId of argsArray[i]) {
|
4966 | const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
|
4967 |
|
4968 | if (!objsPool.has(depObjId)) {
|
4969 | objsPool.get(depObjId, continueCallback);
|
4970 | return i;
|
4971 | }
|
4972 | }
|
4973 | }
|
4974 |
|
4975 | i++;
|
4976 |
|
4977 | if (i === argsArrayLen) {
|
4978 | return i;
|
4979 | }
|
4980 |
|
4981 | if (chunkOperations && ++steps > EXECUTION_STEPS) {
|
4982 | if (Date.now() > endTime) {
|
4983 | continueCallback();
|
4984 | return i;
|
4985 | }
|
4986 |
|
4987 | steps = 0;
|
4988 | }
|
4989 | }
|
4990 | },
|
4991 | endDrawing: function CanvasGraphics_endDrawing() {
|
4992 | if (this.current.activeSMask !== null) {
|
4993 | this.endSMaskGroup();
|
4994 | }
|
4995 |
|
4996 | this.ctx.restore();
|
4997 |
|
4998 | if (this.transparentCanvas) {
|
4999 | this.ctx = this.compositeCtx;
|
5000 | this.ctx.save();
|
5001 | this.ctx.setTransform(1, 0, 0, 1, 0, 0);
|
5002 | this.ctx.drawImage(this.transparentCanvas, 0, 0);
|
5003 | this.ctx.restore();
|
5004 | this.transparentCanvas = null;
|
5005 | }
|
5006 |
|
5007 | this.cachedCanvases.clear();
|
5008 | this.webGLContext.clear();
|
5009 |
|
5010 | if (this.imageLayer) {
|
5011 | this.imageLayer.endLayout();
|
5012 | }
|
5013 | },
|
5014 | setLineWidth: function CanvasGraphics_setLineWidth(width) {
|
5015 | this.current.lineWidth = width;
|
5016 | this.ctx.lineWidth = width;
|
5017 | },
|
5018 | setLineCap: function CanvasGraphics_setLineCap(style) {
|
5019 | this.ctx.lineCap = LINE_CAP_STYLES[style];
|
5020 | },
|
5021 | setLineJoin: function CanvasGraphics_setLineJoin(style) {
|
5022 | this.ctx.lineJoin = LINE_JOIN_STYLES[style];
|
5023 | },
|
5024 | setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
|
5025 | this.ctx.miterLimit = limit;
|
5026 | },
|
5027 | setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
|
5028 | var ctx = this.ctx;
|
5029 |
|
5030 | if (ctx.setLineDash !== undefined) {
|
5031 | ctx.setLineDash(dashArray);
|
5032 | ctx.lineDashOffset = dashPhase;
|
5033 | }
|
5034 | },
|
5035 |
|
5036 | setRenderingIntent(intent) {},
|
5037 |
|
5038 | setFlatness(flatness) {},
|
5039 |
|
5040 | setGState: function CanvasGraphics_setGState(states) {
|
5041 | for (var i = 0, ii = states.length; i < ii; i++) {
|
5042 | var state = states[i];
|
5043 | var key = state[0];
|
5044 | var value = state[1];
|
5045 |
|
5046 | switch (key) {
|
5047 | case "LW":
|
5048 | this.setLineWidth(value);
|
5049 | break;
|
5050 |
|
5051 | case "LC":
|
5052 | this.setLineCap(value);
|
5053 | break;
|
5054 |
|
5055 | case "LJ":
|
5056 | this.setLineJoin(value);
|
5057 | break;
|
5058 |
|
5059 | case "ML":
|
5060 | this.setMiterLimit(value);
|
5061 | break;
|
5062 |
|
5063 | case "D":
|
5064 | this.setDash(value[0], value[1]);
|
5065 | break;
|
5066 |
|
5067 | case "RI":
|
5068 | this.setRenderingIntent(value);
|
5069 | break;
|
5070 |
|
5071 | case "FL":
|
5072 | this.setFlatness(value);
|
5073 | break;
|
5074 |
|
5075 | case "Font":
|
5076 | this.setFont(value[0], value[1]);
|
5077 | break;
|
5078 |
|
5079 | case "CA":
|
5080 | this.current.strokeAlpha = state[1];
|
5081 | break;
|
5082 |
|
5083 | case "ca":
|
5084 | this.current.fillAlpha = state[1];
|
5085 | this.ctx.globalAlpha = state[1];
|
5086 | break;
|
5087 |
|
5088 | case "BM":
|
5089 | this.ctx.globalCompositeOperation = value;
|
5090 | break;
|
5091 |
|
5092 | case "SMask":
|
5093 | if (this.current.activeSMask) {
|
5094 | if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
|
5095 | this.suspendSMaskGroup();
|
5096 | } else {
|
5097 | this.endSMaskGroup();
|
5098 | }
|
5099 | }
|
5100 |
|
5101 | this.current.activeSMask = value ? this.tempSMask : null;
|
5102 |
|
5103 | if (this.current.activeSMask) {
|
5104 | this.beginSMaskGroup();
|
5105 | }
|
5106 |
|
5107 | this.tempSMask = null;
|
5108 | break;
|
5109 | }
|
5110 | }
|
5111 | },
|
5112 | beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
|
5113 | var activeSMask = this.current.activeSMask;
|
5114 | var drawnWidth = activeSMask.canvas.width;
|
5115 | var drawnHeight = activeSMask.canvas.height;
|
5116 | var cacheId = "smaskGroupAt" + this.groupLevel;
|
5117 | var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
|
5118 | var currentCtx = this.ctx;
|
5119 | var currentTransform = currentCtx.mozCurrentTransform;
|
5120 | this.ctx.save();
|
5121 | var groupCtx = scratchCanvas.context;
|
5122 | groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
|
5123 | groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
|
5124 | groupCtx.transform.apply(groupCtx, currentTransform);
|
5125 | activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
|
5126 | copyCtxState(currentCtx, groupCtx);
|
5127 | this.ctx = groupCtx;
|
5128 | this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
|
5129 | this.groupStack.push(currentCtx);
|
5130 | this.groupLevel++;
|
5131 | },
|
5132 | suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
|
5133 | var groupCtx = this.ctx;
|
5134 | this.groupLevel--;
|
5135 | this.ctx = this.groupStack.pop();
|
5136 | composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
|
5137 | this.ctx.restore();
|
5138 | this.ctx.save();
|
5139 | copyCtxState(groupCtx, this.ctx);
|
5140 | this.current.resumeSMaskCtx = groupCtx;
|
5141 |
|
5142 | var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
|
5143 |
|
5144 | this.ctx.transform.apply(this.ctx, deltaTransform);
|
5145 | groupCtx.save();
|
5146 | groupCtx.setTransform(1, 0, 0, 1, 0, 0);
|
5147 | groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
|
5148 | groupCtx.restore();
|
5149 | },
|
5150 | resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
|
5151 | var groupCtx = this.current.resumeSMaskCtx;
|
5152 | var currentCtx = this.ctx;
|
5153 | this.ctx = groupCtx;
|
5154 | this.groupStack.push(currentCtx);
|
5155 | this.groupLevel++;
|
5156 | },
|
5157 | endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
|
5158 | var groupCtx = this.ctx;
|
5159 | this.groupLevel--;
|
5160 | this.ctx = this.groupStack.pop();
|
5161 | composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
|
5162 | this.ctx.restore();
|
5163 | copyCtxState(groupCtx, this.ctx);
|
5164 |
|
5165 | var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
|
5166 |
|
5167 | this.ctx.transform.apply(this.ctx, deltaTransform);
|
5168 | },
|
5169 | save: function CanvasGraphics_save() {
|
5170 | this.ctx.save();
|
5171 | var old = this.current;
|
5172 | this.stateStack.push(old);
|
5173 | this.current = old.clone();
|
5174 | this.current.resumeSMaskCtx = null;
|
5175 | },
|
5176 | restore: function CanvasGraphics_restore() {
|
5177 | if (this.current.resumeSMaskCtx) {
|
5178 | this.resumeSMaskGroup();
|
5179 | }
|
5180 |
|
5181 | if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
|
5182 | this.endSMaskGroup();
|
5183 | }
|
5184 |
|
5185 | if (this.stateStack.length !== 0) {
|
5186 | this.current = this.stateStack.pop();
|
5187 | this.ctx.restore();
|
5188 | this.pendingClip = null;
|
5189 | this._cachedGetSinglePixelWidth = null;
|
5190 | }
|
5191 | },
|
5192 | transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
|
5193 | this.ctx.transform(a, b, c, d, e, f);
|
5194 | this._cachedGetSinglePixelWidth = null;
|
5195 | },
|
5196 | constructPath: function CanvasGraphics_constructPath(ops, args) {
|
5197 | var ctx = this.ctx;
|
5198 | var current = this.current;
|
5199 | var x = current.x,
|
5200 | y = current.y;
|
5201 |
|
5202 | for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
|
5203 | switch (ops[i] | 0) {
|
5204 | case _util.OPS.rectangle:
|
5205 | x = args[j++];
|
5206 | y = args[j++];
|
5207 | var width = args[j++];
|
5208 | var height = args[j++];
|
5209 |
|
5210 | if (width === 0) {
|
5211 | width = this.getSinglePixelWidth();
|
5212 | }
|
5213 |
|
5214 | if (height === 0) {
|
5215 | height = this.getSinglePixelWidth();
|
5216 | }
|
5217 |
|
5218 | var xw = x + width;
|
5219 | var yh = y + height;
|
5220 | this.ctx.moveTo(x, y);
|
5221 | this.ctx.lineTo(xw, y);
|
5222 | this.ctx.lineTo(xw, yh);
|
5223 | this.ctx.lineTo(x, yh);
|
5224 | this.ctx.lineTo(x, y);
|
5225 | this.ctx.closePath();
|
5226 | break;
|
5227 |
|
5228 | case _util.OPS.moveTo:
|
5229 | x = args[j++];
|
5230 | y = args[j++];
|
5231 | ctx.moveTo(x, y);
|
5232 | break;
|
5233 |
|
5234 | case _util.OPS.lineTo:
|
5235 | x = args[j++];
|
5236 | y = args[j++];
|
5237 | ctx.lineTo(x, y);
|
5238 | break;
|
5239 |
|
5240 | case _util.OPS.curveTo:
|
5241 | x = args[j + 4];
|
5242 | y = args[j + 5];
|
5243 | ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
|
5244 | j += 6;
|
5245 | break;
|
5246 |
|
5247 | case _util.OPS.curveTo2:
|
5248 | ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
|
5249 | x = args[j + 2];
|
5250 | y = args[j + 3];
|
5251 | j += 4;
|
5252 | break;
|
5253 |
|
5254 | case _util.OPS.curveTo3:
|
5255 | x = args[j + 2];
|
5256 | y = args[j + 3];
|
5257 | ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
|
5258 | j += 4;
|
5259 | break;
|
5260 |
|
5261 | case _util.OPS.closePath:
|
5262 | ctx.closePath();
|
5263 | break;
|
5264 | }
|
5265 | }
|
5266 |
|
5267 | current.setCurrentPoint(x, y);
|
5268 | },
|
5269 | closePath: function CanvasGraphics_closePath() {
|
5270 | this.ctx.closePath();
|
5271 | },
|
5272 | stroke: function CanvasGraphics_stroke(consumePath) {
|
5273 | consumePath = typeof consumePath !== "undefined" ? consumePath : true;
|
5274 | var ctx = this.ctx;
|
5275 | var strokeColor = this.current.strokeColor;
|
5276 | ctx.globalAlpha = this.current.strokeAlpha;
|
5277 |
|
5278 | if (strokeColor && strokeColor.hasOwnProperty("type") && strokeColor.type === "Pattern") {
|
5279 | ctx.save();
|
5280 | const transform = ctx.mozCurrentTransform;
|
5281 |
|
5282 | const scale = _util.Util.singularValueDecompose2dScale(transform)[0];
|
5283 |
|
5284 | ctx.strokeStyle = strokeColor.getPattern(ctx, this);
|
5285 | ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth * scale);
|
5286 | ctx.stroke();
|
5287 | ctx.restore();
|
5288 | } else {
|
5289 | ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
|
5290 | ctx.stroke();
|
5291 | }
|
5292 |
|
5293 | if (consumePath) {
|
5294 | this.consumePath();
|
5295 | }
|
5296 |
|
5297 | ctx.globalAlpha = this.current.fillAlpha;
|
5298 | },
|
5299 | closeStroke: function CanvasGraphics_closeStroke() {
|
5300 | this.closePath();
|
5301 | this.stroke();
|
5302 | },
|
5303 | fill: function CanvasGraphics_fill(consumePath) {
|
5304 | consumePath = typeof consumePath !== "undefined" ? consumePath : true;
|
5305 | var ctx = this.ctx;
|
5306 | var fillColor = this.current.fillColor;
|
5307 | var isPatternFill = this.current.patternFill;
|
5308 | var needRestore = false;
|
5309 |
|
5310 | if (isPatternFill) {
|
5311 | ctx.save();
|
5312 |
|
5313 | if (this.baseTransform) {
|
5314 | ctx.setTransform.apply(ctx, this.baseTransform);
|
5315 | }
|
5316 |
|
5317 | ctx.fillStyle = fillColor.getPattern(ctx, this);
|
5318 | needRestore = true;
|
5319 | }
|
5320 |
|
5321 | if (this.pendingEOFill) {
|
5322 | ctx.fill("evenodd");
|
5323 | this.pendingEOFill = false;
|
5324 | } else {
|
5325 | ctx.fill();
|
5326 | }
|
5327 |
|
5328 | if (needRestore) {
|
5329 | ctx.restore();
|
5330 | }
|
5331 |
|
5332 | if (consumePath) {
|
5333 | this.consumePath();
|
5334 | }
|
5335 | },
|
5336 | eoFill: function CanvasGraphics_eoFill() {
|
5337 | this.pendingEOFill = true;
|
5338 | this.fill();
|
5339 | },
|
5340 | fillStroke: function CanvasGraphics_fillStroke() {
|
5341 | this.fill(false);
|
5342 | this.stroke(false);
|
5343 | this.consumePath();
|
5344 | },
|
5345 | eoFillStroke: function CanvasGraphics_eoFillStroke() {
|
5346 | this.pendingEOFill = true;
|
5347 | this.fillStroke();
|
5348 | },
|
5349 | closeFillStroke: function CanvasGraphics_closeFillStroke() {
|
5350 | this.closePath();
|
5351 | this.fillStroke();
|
5352 | },
|
5353 | closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
|
5354 | this.pendingEOFill = true;
|
5355 | this.closePath();
|
5356 | this.fillStroke();
|
5357 | },
|
5358 | endPath: function CanvasGraphics_endPath() {
|
5359 | this.consumePath();
|
5360 | },
|
5361 | clip: function CanvasGraphics_clip() {
|
5362 | this.pendingClip = NORMAL_CLIP;
|
5363 | },
|
5364 | eoClip: function CanvasGraphics_eoClip() {
|
5365 | this.pendingClip = EO_CLIP;
|
5366 | },
|
5367 | beginText: function CanvasGraphics_beginText() {
|
5368 | this.current.textMatrix = _util.IDENTITY_MATRIX;
|
5369 | this.current.textMatrixScale = 1;
|
5370 | this.current.x = this.current.lineX = 0;
|
5371 | this.current.y = this.current.lineY = 0;
|
5372 | },
|
5373 | endText: function CanvasGraphics_endText() {
|
5374 | var paths = this.pendingTextPaths;
|
5375 | var ctx = this.ctx;
|
5376 |
|
5377 | if (paths === undefined) {
|
5378 | ctx.beginPath();
|
5379 | return;
|
5380 | }
|
5381 |
|
5382 | ctx.save();
|
5383 | ctx.beginPath();
|
5384 |
|
5385 | for (var i = 0; i < paths.length; i++) {
|
5386 | var path = paths[i];
|
5387 | ctx.setTransform.apply(ctx, path.transform);
|
5388 | ctx.translate(path.x, path.y);
|
5389 | path.addToPath(ctx, path.fontSize);
|
5390 | }
|
5391 |
|
5392 | ctx.restore();
|
5393 | ctx.clip();
|
5394 | ctx.beginPath();
|
5395 | delete this.pendingTextPaths;
|
5396 | },
|
5397 | setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
|
5398 | this.current.charSpacing = spacing;
|
5399 | },
|
5400 | setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
|
5401 | this.current.wordSpacing = spacing;
|
5402 | },
|
5403 | setHScale: function CanvasGraphics_setHScale(scale) {
|
5404 | this.current.textHScale = scale / 100;
|
5405 | },
|
5406 | setLeading: function CanvasGraphics_setLeading(leading) {
|
5407 | this.current.leading = -leading;
|
5408 | },
|
5409 | setFont: function CanvasGraphics_setFont(fontRefName, size) {
|
5410 | var fontObj = this.commonObjs.get(fontRefName);
|
5411 | var current = this.current;
|
5412 |
|
5413 | if (!fontObj) {
|
5414 | throw new Error(`Can't find font for ${fontRefName}`);
|
5415 | }
|
5416 |
|
5417 | current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
|
5418 |
|
5419 | if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
|
5420 | (0, _util.warn)("Invalid font matrix for font " + fontRefName);
|
5421 | }
|
5422 |
|
5423 | if (size < 0) {
|
5424 | size = -size;
|
5425 | current.fontDirection = -1;
|
5426 | } else {
|
5427 | current.fontDirection = 1;
|
5428 | }
|
5429 |
|
5430 | this.current.font = fontObj;
|
5431 | this.current.fontSize = size;
|
5432 |
|
5433 | if (fontObj.isType3Font) {
|
5434 | return;
|
5435 | }
|
5436 |
|
5437 | var name = fontObj.loadedName || "sans-serif";
|
5438 | let bold = "normal";
|
5439 |
|
5440 | if (fontObj.black) {
|
5441 | bold = "900";
|
5442 | } else if (fontObj.bold) {
|
5443 | bold = "bold";
|
5444 | }
|
5445 |
|
5446 | var italic = fontObj.italic ? "italic" : "normal";
|
5447 | var typeface = `"${name}", ${fontObj.fallbackName}`;
|
5448 | let browserFontSize = size;
|
5449 |
|
5450 | if (size < MIN_FONT_SIZE) {
|
5451 | browserFontSize = MIN_FONT_SIZE;
|
5452 | } else if (size > MAX_FONT_SIZE) {
|
5453 | browserFontSize = MAX_FONT_SIZE;
|
5454 | }
|
5455 |
|
5456 | this.current.fontSizeScale = size / browserFontSize;
|
5457 | this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
|
5458 | },
|
5459 | setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
|
5460 | this.current.textRenderingMode = mode;
|
5461 | },
|
5462 | setTextRise: function CanvasGraphics_setTextRise(rise) {
|
5463 | this.current.textRise = rise;
|
5464 | },
|
5465 | moveText: function CanvasGraphics_moveText(x, y) {
|
5466 | this.current.x = this.current.lineX += x;
|
5467 | this.current.y = this.current.lineY += y;
|
5468 | },
|
5469 | setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
|
5470 | this.setLeading(-y);
|
5471 | this.moveText(x, y);
|
5472 | },
|
5473 | setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
|
5474 | this.current.textMatrix = [a, b, c, d, e, f];
|
5475 | this.current.textMatrixScale = Math.sqrt(a * a + b * b);
|
5476 | this.current.x = this.current.lineX = 0;
|
5477 | this.current.y = this.current.lineY = 0;
|
5478 | },
|
5479 | nextLine: function CanvasGraphics_nextLine() {
|
5480 | this.moveText(0, this.current.leading);
|
5481 | },
|
5482 |
|
5483 | paintChar(character, x, y, patternTransform) {
|
5484 | var ctx = this.ctx;
|
5485 | var current = this.current;
|
5486 | var font = current.font;
|
5487 | var textRenderingMode = current.textRenderingMode;
|
5488 | var fontSize = current.fontSize / current.fontSizeScale;
|
5489 | var fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
|
5490 | var isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
|
5491 | const patternFill = current.patternFill && !font.missingFile;
|
5492 | var addToPath;
|
5493 |
|
5494 | if (font.disableFontFace || isAddToPathSet || patternFill) {
|
5495 | addToPath = font.getPathGenerator(this.commonObjs, character);
|
5496 | }
|
5497 |
|
5498 | if (font.disableFontFace || patternFill) {
|
5499 | ctx.save();
|
5500 | ctx.translate(x, y);
|
5501 | ctx.beginPath();
|
5502 | addToPath(ctx, fontSize);
|
5503 |
|
5504 | if (patternTransform) {
|
5505 | ctx.setTransform.apply(ctx, patternTransform);
|
5506 | }
|
5507 |
|
5508 | if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
5509 | ctx.fill();
|
5510 | }
|
5511 |
|
5512 | if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
5513 | ctx.stroke();
|
5514 | }
|
5515 |
|
5516 | ctx.restore();
|
5517 | } else {
|
5518 | if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
5519 | ctx.fillText(character, x, y);
|
5520 | }
|
5521 |
|
5522 | if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
5523 | ctx.strokeText(character, x, y);
|
5524 | }
|
5525 | }
|
5526 |
|
5527 | if (isAddToPathSet) {
|
5528 | var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
|
5529 | paths.push({
|
5530 | transform: ctx.mozCurrentTransform,
|
5531 | x,
|
5532 | y,
|
5533 | fontSize,
|
5534 | addToPath
|
5535 | });
|
5536 | }
|
5537 | },
|
5538 |
|
5539 | get isFontSubpixelAAEnabled() {
|
5540 | const {
|
5541 | context: ctx
|
5542 | } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
|
5543 | ctx.scale(1.5, 1);
|
5544 | ctx.fillText("I", 0, 10);
|
5545 | var data = ctx.getImageData(0, 0, 10, 10).data;
|
5546 | var enabled = false;
|
5547 |
|
5548 | for (var i = 3; i < data.length; i += 4) {
|
5549 | if (data[i] > 0 && data[i] < 255) {
|
5550 | enabled = true;
|
5551 | break;
|
5552 | }
|
5553 | }
|
5554 |
|
5555 | return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
|
5556 | },
|
5557 |
|
5558 | showText: function CanvasGraphics_showText(glyphs) {
|
5559 | var current = this.current;
|
5560 | var font = current.font;
|
5561 |
|
5562 | if (font.isType3Font) {
|
5563 | return this.showType3Text(glyphs);
|
5564 | }
|
5565 |
|
5566 | var fontSize = current.fontSize;
|
5567 |
|
5568 | if (fontSize === 0) {
|
5569 | return undefined;
|
5570 | }
|
5571 |
|
5572 | var ctx = this.ctx;
|
5573 | var fontSizeScale = current.fontSizeScale;
|
5574 | var charSpacing = current.charSpacing;
|
5575 | var wordSpacing = current.wordSpacing;
|
5576 | var fontDirection = current.fontDirection;
|
5577 | var textHScale = current.textHScale * fontDirection;
|
5578 | var glyphsLength = glyphs.length;
|
5579 | var vertical = font.vertical;
|
5580 | var spacingDir = vertical ? 1 : -1;
|
5581 | var defaultVMetrics = font.defaultVMetrics;
|
5582 | var widthAdvanceScale = fontSize * current.fontMatrix[0];
|
5583 | var simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
|
5584 | ctx.save();
|
5585 | let patternTransform;
|
5586 |
|
5587 | if (current.patternFill) {
|
5588 | ctx.save();
|
5589 | const pattern = current.fillColor.getPattern(ctx, this);
|
5590 | patternTransform = ctx.mozCurrentTransform;
|
5591 | ctx.restore();
|
5592 | ctx.fillStyle = pattern;
|
5593 | }
|
5594 |
|
5595 | ctx.transform.apply(ctx, current.textMatrix);
|
5596 | ctx.translate(current.x, current.y + current.textRise);
|
5597 |
|
5598 | if (fontDirection > 0) {
|
5599 | ctx.scale(textHScale, -1);
|
5600 | } else {
|
5601 | ctx.scale(textHScale, 1);
|
5602 | }
|
5603 |
|
5604 | var lineWidth = current.lineWidth;
|
5605 | var scale = current.textMatrixScale;
|
5606 |
|
5607 | if (scale === 0 || lineWidth === 0) {
|
5608 | var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
|
5609 |
|
5610 | if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
5611 | this._cachedGetSinglePixelWidth = null;
|
5612 | lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
|
5613 | }
|
5614 | } else {
|
5615 | lineWidth /= scale;
|
5616 | }
|
5617 |
|
5618 | if (fontSizeScale !== 1.0) {
|
5619 | ctx.scale(fontSizeScale, fontSizeScale);
|
5620 | lineWidth /= fontSizeScale;
|
5621 | }
|
5622 |
|
5623 | ctx.lineWidth = lineWidth;
|
5624 | var x = 0,
|
5625 | i;
|
5626 |
|
5627 | for (i = 0; i < glyphsLength; ++i) {
|
5628 | var glyph = glyphs[i];
|
5629 |
|
5630 | if ((0, _util.isNum)(glyph)) {
|
5631 | x += spacingDir * glyph * fontSize / 1000;
|
5632 | continue;
|
5633 | }
|
5634 |
|
5635 | var restoreNeeded = false;
|
5636 | var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
|
5637 | var character = glyph.fontChar;
|
5638 | var accent = glyph.accent;
|
5639 | var scaledX, scaledY, scaledAccentX, scaledAccentY;
|
5640 | var width = glyph.width;
|
5641 |
|
5642 | if (vertical) {
|
5643 | var vmetric, vx, vy;
|
5644 | vmetric = glyph.vmetric || defaultVMetrics;
|
5645 | vx = glyph.vmetric ? vmetric[1] : width * 0.5;
|
5646 | vx = -vx * widthAdvanceScale;
|
5647 | vy = vmetric[2] * widthAdvanceScale;
|
5648 | width = vmetric ? -vmetric[0] : width;
|
5649 | scaledX = vx / fontSizeScale;
|
5650 | scaledY = (x + vy) / fontSizeScale;
|
5651 | } else {
|
5652 | scaledX = x / fontSizeScale;
|
5653 | scaledY = 0;
|
5654 | }
|
5655 |
|
5656 | if (font.remeasure && width > 0) {
|
5657 | var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
|
5658 |
|
5659 | if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
|
5660 | var characterScaleX = width / measuredWidth;
|
5661 | restoreNeeded = true;
|
5662 | ctx.save();
|
5663 | ctx.scale(characterScaleX, 1);
|
5664 | scaledX /= characterScaleX;
|
5665 | } else if (width !== measuredWidth) {
|
5666 | scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
|
5667 | }
|
5668 | }
|
5669 |
|
5670 | if (glyph.isInFont || font.missingFile) {
|
5671 | if (simpleFillText && !accent) {
|
5672 | ctx.fillText(character, scaledX, scaledY);
|
5673 | } else {
|
5674 | this.paintChar(character, scaledX, scaledY, patternTransform);
|
5675 |
|
5676 | if (accent) {
|
5677 | scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
|
5678 | scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
|
5679 | this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
|
5680 | }
|
5681 | }
|
5682 | }
|
5683 |
|
5684 | var charWidth;
|
5685 |
|
5686 | if (vertical) {
|
5687 | charWidth = width * widthAdvanceScale - spacing * fontDirection;
|
5688 | } else {
|
5689 | charWidth = width * widthAdvanceScale + spacing * fontDirection;
|
5690 | }
|
5691 |
|
5692 | x += charWidth;
|
5693 |
|
5694 | if (restoreNeeded) {
|
5695 | ctx.restore();
|
5696 | }
|
5697 | }
|
5698 |
|
5699 | if (vertical) {
|
5700 | current.y -= x;
|
5701 | } else {
|
5702 | current.x += x * textHScale;
|
5703 | }
|
5704 |
|
5705 | ctx.restore();
|
5706 | },
|
5707 | showType3Text: function CanvasGraphics_showType3Text(glyphs) {
|
5708 | var ctx = this.ctx;
|
5709 | var current = this.current;
|
5710 | var font = current.font;
|
5711 | var fontSize = current.fontSize;
|
5712 | var fontDirection = current.fontDirection;
|
5713 | var spacingDir = font.vertical ? 1 : -1;
|
5714 | var charSpacing = current.charSpacing;
|
5715 | var wordSpacing = current.wordSpacing;
|
5716 | var textHScale = current.textHScale * fontDirection;
|
5717 | var fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
|
5718 | var glyphsLength = glyphs.length;
|
5719 | var isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
|
5720 | var i, glyph, width, spacingLength;
|
5721 |
|
5722 | if (isTextInvisible || fontSize === 0) {
|
5723 | return;
|
5724 | }
|
5725 |
|
5726 | this._cachedGetSinglePixelWidth = null;
|
5727 | ctx.save();
|
5728 | ctx.transform.apply(ctx, current.textMatrix);
|
5729 | ctx.translate(current.x, current.y);
|
5730 | ctx.scale(textHScale, fontDirection);
|
5731 |
|
5732 | for (i = 0; i < glyphsLength; ++i) {
|
5733 | glyph = glyphs[i];
|
5734 |
|
5735 | if ((0, _util.isNum)(glyph)) {
|
5736 | spacingLength = spacingDir * glyph * fontSize / 1000;
|
5737 | this.ctx.translate(spacingLength, 0);
|
5738 | current.x += spacingLength * textHScale;
|
5739 | continue;
|
5740 | }
|
5741 |
|
5742 | var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
|
5743 | var operatorList = font.charProcOperatorList[glyph.operatorListId];
|
5744 |
|
5745 | if (!operatorList) {
|
5746 | (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
|
5747 | continue;
|
5748 | }
|
5749 |
|
5750 | this.processingType3 = glyph;
|
5751 | this.save();
|
5752 | ctx.scale(fontSize, fontSize);
|
5753 | ctx.transform.apply(ctx, fontMatrix);
|
5754 | this.executeOperatorList(operatorList);
|
5755 | this.restore();
|
5756 |
|
5757 | var transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
|
5758 |
|
5759 | width = transformed[0] * fontSize + spacing;
|
5760 | ctx.translate(width, 0);
|
5761 | current.x += width * textHScale;
|
5762 | }
|
5763 |
|
5764 | ctx.restore();
|
5765 | this.processingType3 = null;
|
5766 | },
|
5767 | setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {},
|
5768 | setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
|
5769 | this.ctx.rect(llx, lly, urx - llx, ury - lly);
|
5770 | this.clip();
|
5771 | this.endPath();
|
5772 | },
|
5773 | getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
|
5774 | var pattern;
|
5775 |
|
5776 | if (IR[0] === "TilingPattern") {
|
5777 | var color = IR[1];
|
5778 | var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
|
5779 | var canvasGraphicsFactory = {
|
5780 | createCanvasGraphics: ctx => {
|
5781 | return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext);
|
5782 | }
|
5783 | };
|
5784 | pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
|
5785 | } else {
|
5786 | pattern = (0, _pattern_helper.getShadingPatternFromIR)(IR);
|
5787 | }
|
5788 |
|
5789 | return pattern;
|
5790 | },
|
5791 | setStrokeColorN: function CanvasGraphics_setStrokeColorN() {
|
5792 | this.current.strokeColor = this.getColorN_Pattern(arguments);
|
5793 | },
|
5794 | setFillColorN: function CanvasGraphics_setFillColorN() {
|
5795 | this.current.fillColor = this.getColorN_Pattern(arguments);
|
5796 | this.current.patternFill = true;
|
5797 | },
|
5798 | setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
|
5799 | var color = _util.Util.makeCssRgb(r, g, b);
|
5800 |
|
5801 | this.ctx.strokeStyle = color;
|
5802 | this.current.strokeColor = color;
|
5803 | },
|
5804 | setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
|
5805 | var color = _util.Util.makeCssRgb(r, g, b);
|
5806 |
|
5807 | this.ctx.fillStyle = color;
|
5808 | this.current.fillColor = color;
|
5809 | this.current.patternFill = false;
|
5810 | },
|
5811 | shadingFill: function CanvasGraphics_shadingFill(patternIR) {
|
5812 | var ctx = this.ctx;
|
5813 | this.save();
|
5814 | var pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
|
5815 | ctx.fillStyle = pattern.getPattern(ctx, this, true);
|
5816 | var inv = ctx.mozCurrentTransformInverse;
|
5817 |
|
5818 | if (inv) {
|
5819 | var canvas = ctx.canvas;
|
5820 | var width = canvas.width;
|
5821 | var height = canvas.height;
|
5822 |
|
5823 | var bl = _util.Util.applyTransform([0, 0], inv);
|
5824 |
|
5825 | var br = _util.Util.applyTransform([0, height], inv);
|
5826 |
|
5827 | var ul = _util.Util.applyTransform([width, 0], inv);
|
5828 |
|
5829 | var ur = _util.Util.applyTransform([width, height], inv);
|
5830 |
|
5831 | var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
|
5832 | var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
|
5833 | var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
|
5834 | var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
|
5835 | this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
|
5836 | } else {
|
5837 | this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
|
5838 | }
|
5839 |
|
5840 | this.restore();
|
5841 | },
|
5842 | beginInlineImage: function CanvasGraphics_beginInlineImage() {
|
5843 | (0, _util.unreachable)("Should not call beginInlineImage");
|
5844 | },
|
5845 | beginImageData: function CanvasGraphics_beginImageData() {
|
5846 | (0, _util.unreachable)("Should not call beginImageData");
|
5847 | },
|
5848 | paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
|
5849 | this.save();
|
5850 | this.baseTransformStack.push(this.baseTransform);
|
5851 |
|
5852 | if (Array.isArray(matrix) && matrix.length === 6) {
|
5853 | this.transform.apply(this, matrix);
|
5854 | }
|
5855 |
|
5856 | this.baseTransform = this.ctx.mozCurrentTransform;
|
5857 |
|
5858 | if (bbox) {
|
5859 | var width = bbox[2] - bbox[0];
|
5860 | var height = bbox[3] - bbox[1];
|
5861 | this.ctx.rect(bbox[0], bbox[1], width, height);
|
5862 | this.clip();
|
5863 | this.endPath();
|
5864 | }
|
5865 | },
|
5866 | paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
|
5867 | this.restore();
|
5868 | this.baseTransform = this.baseTransformStack.pop();
|
5869 | },
|
5870 | beginGroup: function CanvasGraphics_beginGroup(group) {
|
5871 | this.save();
|
5872 | var currentCtx = this.ctx;
|
5873 |
|
5874 | if (!group.isolated) {
|
5875 | (0, _util.info)("TODO: Support non-isolated groups.");
|
5876 | }
|
5877 |
|
5878 | if (group.knockout) {
|
5879 | (0, _util.warn)("Knockout groups not supported.");
|
5880 | }
|
5881 |
|
5882 | var currentTransform = currentCtx.mozCurrentTransform;
|
5883 |
|
5884 | if (group.matrix) {
|
5885 | currentCtx.transform.apply(currentCtx, group.matrix);
|
5886 | }
|
5887 |
|
5888 | if (!group.bbox) {
|
5889 | throw new Error("Bounding box is required.");
|
5890 | }
|
5891 |
|
5892 | var bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
|
5893 |
|
5894 | var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
|
5895 | bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
|
5896 | var offsetX = Math.floor(bounds[0]);
|
5897 | var offsetY = Math.floor(bounds[1]);
|
5898 | var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
|
5899 | var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
|
5900 | var scaleX = 1,
|
5901 | scaleY = 1;
|
5902 |
|
5903 | if (drawnWidth > MAX_GROUP_SIZE) {
|
5904 | scaleX = drawnWidth / MAX_GROUP_SIZE;
|
5905 | drawnWidth = MAX_GROUP_SIZE;
|
5906 | }
|
5907 |
|
5908 | if (drawnHeight > MAX_GROUP_SIZE) {
|
5909 | scaleY = drawnHeight / MAX_GROUP_SIZE;
|
5910 | drawnHeight = MAX_GROUP_SIZE;
|
5911 | }
|
5912 |
|
5913 | var cacheId = "groupAt" + this.groupLevel;
|
5914 |
|
5915 | if (group.smask) {
|
5916 | cacheId += "_smask_" + this.smaskCounter++ % 2;
|
5917 | }
|
5918 |
|
5919 | var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
|
5920 | var groupCtx = scratchCanvas.context;
|
5921 | groupCtx.scale(1 / scaleX, 1 / scaleY);
|
5922 | groupCtx.translate(-offsetX, -offsetY);
|
5923 | groupCtx.transform.apply(groupCtx, currentTransform);
|
5924 |
|
5925 | if (group.smask) {
|
5926 | this.smaskStack.push({
|
5927 | canvas: scratchCanvas.canvas,
|
5928 | context: groupCtx,
|
5929 | offsetX,
|
5930 | offsetY,
|
5931 | scaleX,
|
5932 | scaleY,
|
5933 | subtype: group.smask.subtype,
|
5934 | backdrop: group.smask.backdrop,
|
5935 | transferMap: group.smask.transferMap || null,
|
5936 | startTransformInverse: null
|
5937 | });
|
5938 | } else {
|
5939 | currentCtx.setTransform(1, 0, 0, 1, 0, 0);
|
5940 | currentCtx.translate(offsetX, offsetY);
|
5941 | currentCtx.scale(scaleX, scaleY);
|
5942 | }
|
5943 |
|
5944 | copyCtxState(currentCtx, groupCtx);
|
5945 | this.ctx = groupCtx;
|
5946 | this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
|
5947 | this.groupStack.push(currentCtx);
|
5948 | this.groupLevel++;
|
5949 | this.current.activeSMask = null;
|
5950 | },
|
5951 | endGroup: function CanvasGraphics_endGroup(group) {
|
5952 | this.groupLevel--;
|
5953 | var groupCtx = this.ctx;
|
5954 | this.ctx = this.groupStack.pop();
|
5955 |
|
5956 | if (this.ctx.imageSmoothingEnabled !== undefined) {
|
5957 | this.ctx.imageSmoothingEnabled = false;
|
5958 | } else {
|
5959 | this.ctx.mozImageSmoothingEnabled = false;
|
5960 | }
|
5961 |
|
5962 | if (group.smask) {
|
5963 | this.tempSMask = this.smaskStack.pop();
|
5964 | } else {
|
5965 | this.ctx.drawImage(groupCtx.canvas, 0, 0);
|
5966 | }
|
5967 |
|
5968 | this.restore();
|
5969 | },
|
5970 | beginAnnotations: function CanvasGraphics_beginAnnotations() {
|
5971 | this.save();
|
5972 |
|
5973 | if (this.baseTransform) {
|
5974 | this.ctx.setTransform.apply(this.ctx, this.baseTransform);
|
5975 | }
|
5976 | },
|
5977 | endAnnotations: function CanvasGraphics_endAnnotations() {
|
5978 | this.restore();
|
5979 | },
|
5980 | beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) {
|
5981 | this.save();
|
5982 | resetCtxToDefault(this.ctx);
|
5983 | this.current = new CanvasExtraState();
|
5984 |
|
5985 | if (Array.isArray(rect) && rect.length === 4) {
|
5986 | var width = rect[2] - rect[0];
|
5987 | var height = rect[3] - rect[1];
|
5988 | this.ctx.rect(rect[0], rect[1], width, height);
|
5989 | this.clip();
|
5990 | this.endPath();
|
5991 | }
|
5992 |
|
5993 | this.transform.apply(this, transform);
|
5994 | this.transform.apply(this, matrix);
|
5995 | },
|
5996 | endAnnotation: function CanvasGraphics_endAnnotation() {
|
5997 | this.restore();
|
5998 | },
|
5999 | paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
|
6000 | var ctx = this.ctx;
|
6001 | var width = img.width,
|
6002 | height = img.height;
|
6003 | var fillColor = this.current.fillColor;
|
6004 | var isPatternFill = this.current.patternFill;
|
6005 | var glyph = this.processingType3;
|
6006 |
|
6007 | if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
|
6008 | if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
|
6009 | glyph.compiled = compileType3Glyph({
|
6010 | data: img.data,
|
6011 | width,
|
6012 | height
|
6013 | });
|
6014 | } else {
|
6015 | glyph.compiled = null;
|
6016 | }
|
6017 | }
|
6018 |
|
6019 | if (glyph && glyph.compiled) {
|
6020 | glyph.compiled(ctx);
|
6021 | return;
|
6022 | }
|
6023 |
|
6024 | var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
|
6025 | var maskCtx = maskCanvas.context;
|
6026 | maskCtx.save();
|
6027 | putBinaryImageMask(maskCtx, img);
|
6028 | maskCtx.globalCompositeOperation = "source-in";
|
6029 | maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
|
6030 | maskCtx.fillRect(0, 0, width, height);
|
6031 | maskCtx.restore();
|
6032 | this.paintInlineImageXObject(maskCanvas.canvas);
|
6033 | },
|
6034 | paintImageMaskXObjectRepeat: function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX, scaleY, positions) {
|
6035 | var width = imgData.width;
|
6036 | var height = imgData.height;
|
6037 | var fillColor = this.current.fillColor;
|
6038 | var isPatternFill = this.current.patternFill;
|
6039 | var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
|
6040 | var maskCtx = maskCanvas.context;
|
6041 | maskCtx.save();
|
6042 | putBinaryImageMask(maskCtx, imgData);
|
6043 | maskCtx.globalCompositeOperation = "source-in";
|
6044 | maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
|
6045 | maskCtx.fillRect(0, 0, width, height);
|
6046 | maskCtx.restore();
|
6047 | var ctx = this.ctx;
|
6048 |
|
6049 | for (var i = 0, ii = positions.length; i < ii; i += 2) {
|
6050 | ctx.save();
|
6051 | ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
|
6052 | ctx.scale(1, -1);
|
6053 | ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
|
6054 | ctx.restore();
|
6055 | }
|
6056 | },
|
6057 | paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) {
|
6058 | var ctx = this.ctx;
|
6059 | var fillColor = this.current.fillColor;
|
6060 | var isPatternFill = this.current.patternFill;
|
6061 |
|
6062 | for (var i = 0, ii = images.length; i < ii; i++) {
|
6063 | var image = images[i];
|
6064 | var width = image.width,
|
6065 | height = image.height;
|
6066 | var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
|
6067 | var maskCtx = maskCanvas.context;
|
6068 | maskCtx.save();
|
6069 | putBinaryImageMask(maskCtx, image);
|
6070 | maskCtx.globalCompositeOperation = "source-in";
|
6071 | maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
|
6072 | maskCtx.fillRect(0, 0, width, height);
|
6073 | maskCtx.restore();
|
6074 | ctx.save();
|
6075 | ctx.transform.apply(ctx, image.transform);
|
6076 | ctx.scale(1, -1);
|
6077 | ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
|
6078 | ctx.restore();
|
6079 | }
|
6080 | },
|
6081 | paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
|
6082 | const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
|
6083 |
|
6084 | if (!imgData) {
|
6085 | (0, _util.warn)("Dependent image isn't ready yet");
|
6086 | return;
|
6087 | }
|
6088 |
|
6089 | this.paintInlineImageXObject(imgData);
|
6090 | },
|
6091 | paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
|
6092 | const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
|
6093 |
|
6094 | if (!imgData) {
|
6095 | (0, _util.warn)("Dependent image isn't ready yet");
|
6096 | return;
|
6097 | }
|
6098 |
|
6099 | var width = imgData.width;
|
6100 | var height = imgData.height;
|
6101 | var map = [];
|
6102 |
|
6103 | for (var i = 0, ii = positions.length; i < ii; i += 2) {
|
6104 | map.push({
|
6105 | transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
|
6106 | x: 0,
|
6107 | y: 0,
|
6108 | w: width,
|
6109 | h: height
|
6110 | });
|
6111 | }
|
6112 |
|
6113 | this.paintInlineImageXObjectGroup(imgData, map);
|
6114 | },
|
6115 | paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
|
6116 | var width = imgData.width;
|
6117 | var height = imgData.height;
|
6118 | var ctx = this.ctx;
|
6119 | this.save();
|
6120 | ctx.scale(1 / width, -1 / height);
|
6121 | var currentTransform = ctx.mozCurrentTransformInverse;
|
6122 | var a = currentTransform[0],
|
6123 | b = currentTransform[1];
|
6124 | var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
|
6125 | var c = currentTransform[2],
|
6126 | d = currentTransform[3];
|
6127 | var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
|
6128 | var imgToPaint, tmpCanvas;
|
6129 |
|
6130 | if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
|
6131 | imgToPaint = imgData;
|
6132 | } else {
|
6133 | tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
|
6134 | var tmpCtx = tmpCanvas.context;
|
6135 | putBinaryImageData(tmpCtx, imgData);
|
6136 | imgToPaint = tmpCanvas.canvas;
|
6137 | }
|
6138 |
|
6139 | var paintWidth = width,
|
6140 | paintHeight = height;
|
6141 | var tmpCanvasId = "prescale1";
|
6142 |
|
6143 | while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
|
6144 | var newWidth = paintWidth,
|
6145 | newHeight = paintHeight;
|
6146 |
|
6147 | if (widthScale > 2 && paintWidth > 1) {
|
6148 | newWidth = Math.ceil(paintWidth / 2);
|
6149 | widthScale /= paintWidth / newWidth;
|
6150 | }
|
6151 |
|
6152 | if (heightScale > 2 && paintHeight > 1) {
|
6153 | newHeight = Math.ceil(paintHeight / 2);
|
6154 | heightScale /= paintHeight / newHeight;
|
6155 | }
|
6156 |
|
6157 | tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
|
6158 | tmpCtx = tmpCanvas.context;
|
6159 | tmpCtx.clearRect(0, 0, newWidth, newHeight);
|
6160 | tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
|
6161 | imgToPaint = tmpCanvas.canvas;
|
6162 | paintWidth = newWidth;
|
6163 | paintHeight = newHeight;
|
6164 | tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
|
6165 | }
|
6166 |
|
6167 | ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
|
6168 |
|
6169 | if (this.imageLayer) {
|
6170 | var position = this.getCanvasPosition(0, -height);
|
6171 | this.imageLayer.appendImage({
|
6172 | imgData,
|
6173 | left: position[0],
|
6174 | top: position[1],
|
6175 | width: width / currentTransform[0],
|
6176 | height: height / currentTransform[3]
|
6177 | });
|
6178 | }
|
6179 |
|
6180 | this.restore();
|
6181 | },
|
6182 | paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
|
6183 | var ctx = this.ctx;
|
6184 | var w = imgData.width;
|
6185 | var h = imgData.height;
|
6186 | var tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
|
6187 | var tmpCtx = tmpCanvas.context;
|
6188 | putBinaryImageData(tmpCtx, imgData);
|
6189 |
|
6190 | for (var i = 0, ii = map.length; i < ii; i++) {
|
6191 | var entry = map[i];
|
6192 | ctx.save();
|
6193 | ctx.transform.apply(ctx, entry.transform);
|
6194 | ctx.scale(1, -1);
|
6195 | ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
|
6196 |
|
6197 | if (this.imageLayer) {
|
6198 | var position = this.getCanvasPosition(entry.x, entry.y);
|
6199 | this.imageLayer.appendImage({
|
6200 | imgData,
|
6201 | left: position[0],
|
6202 | top: position[1],
|
6203 | width: w,
|
6204 | height: h
|
6205 | });
|
6206 | }
|
6207 |
|
6208 | ctx.restore();
|
6209 | }
|
6210 | },
|
6211 | paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() {
|
6212 | this.ctx.fillRect(0, 0, 1, 1);
|
6213 | },
|
6214 | paintXObject: function CanvasGraphics_paintXObject() {
|
6215 | (0, _util.warn)("Unsupported 'paintXObject' command.");
|
6216 | },
|
6217 | markPoint: function CanvasGraphics_markPoint(tag) {},
|
6218 | markPointProps: function CanvasGraphics_markPointProps(tag, properties) {},
|
6219 | beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {},
|
6220 | beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {},
|
6221 | endMarkedContent: function CanvasGraphics_endMarkedContent() {},
|
6222 | beginCompat: function CanvasGraphics_beginCompat() {},
|
6223 | endCompat: function CanvasGraphics_endCompat() {},
|
6224 | consumePath: function CanvasGraphics_consumePath() {
|
6225 | var ctx = this.ctx;
|
6226 |
|
6227 | if (this.pendingClip) {
|
6228 | if (this.pendingClip === EO_CLIP) {
|
6229 | ctx.clip("evenodd");
|
6230 | } else {
|
6231 | ctx.clip();
|
6232 | }
|
6233 |
|
6234 | this.pendingClip = null;
|
6235 | }
|
6236 |
|
6237 | ctx.beginPath();
|
6238 | },
|
6239 |
|
6240 | getSinglePixelWidth(scale) {
|
6241 | if (this._cachedGetSinglePixelWidth === null) {
|
6242 | const inverse = this.ctx.mozCurrentTransformInverse;
|
6243 | this._cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
|
6244 | }
|
6245 |
|
6246 | return this._cachedGetSinglePixelWidth;
|
6247 | },
|
6248 |
|
6249 | getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
|
6250 | var transform = this.ctx.mozCurrentTransform;
|
6251 | return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
|
6252 | }
|
6253 | };
|
6254 |
|
6255 | for (var op in _util.OPS) {
|
6256 | CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
|
6257 | }
|
6258 |
|
6259 | return CanvasGraphics;
|
6260 | }();
|
6261 |
|
6262 | exports.CanvasGraphics = CanvasGraphics;
|
6263 |
|
6264 | }),
|
6265 |
|
6266 | (function(module, exports, __w_pdfjs_require__) {
|
6267 |
|
6268 | "use strict";
|
6269 |
|
6270 |
|
6271 | Object.defineProperty(exports, "__esModule", {
|
6272 | value: true
|
6273 | });
|
6274 | exports.getShadingPatternFromIR = getShadingPatternFromIR;
|
6275 | exports.TilingPattern = void 0;
|
6276 |
|
6277 | var _util = __w_pdfjs_require__(2);
|
6278 |
|
6279 | var ShadingIRs = {};
|
6280 |
|
6281 | function applyBoundingBox(ctx, bbox) {
|
6282 | if (!bbox || typeof Path2D === "undefined") {
|
6283 | return;
|
6284 | }
|
6285 |
|
6286 | const width = bbox[2] - bbox[0];
|
6287 | const height = bbox[3] - bbox[1];
|
6288 | const region = new Path2D();
|
6289 | region.rect(bbox[0], bbox[1], width, height);
|
6290 | ctx.clip(region);
|
6291 | }
|
6292 |
|
6293 | ShadingIRs.RadialAxial = {
|
6294 | fromIR: function RadialAxial_fromIR(raw) {
|
6295 | var type = raw[1];
|
6296 | var bbox = raw[2];
|
6297 | var colorStops = raw[3];
|
6298 | var p0 = raw[4];
|
6299 | var p1 = raw[5];
|
6300 | var r0 = raw[6];
|
6301 | var r1 = raw[7];
|
6302 | return {
|
6303 | type: "Pattern",
|
6304 | getPattern: function RadialAxial_getPattern(ctx) {
|
6305 | applyBoundingBox(ctx, bbox);
|
6306 | var grad;
|
6307 |
|
6308 | if (type === "axial") {
|
6309 | grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
|
6310 | } else if (type === "radial") {
|
6311 | grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
|
6312 | }
|
6313 |
|
6314 | for (var i = 0, ii = colorStops.length; i < ii; ++i) {
|
6315 | var c = colorStops[i];
|
6316 | grad.addColorStop(c[0], c[1]);
|
6317 | }
|
6318 |
|
6319 | return grad;
|
6320 | }
|
6321 | };
|
6322 | }
|
6323 | };
|
6324 |
|
6325 | var createMeshCanvas = function createMeshCanvasClosure() {
|
6326 | function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
|
6327 | var coords = context.coords,
|
6328 | colors = context.colors;
|
6329 | var bytes = data.data,
|
6330 | rowSize = data.width * 4;
|
6331 | var tmp;
|
6332 |
|
6333 | if (coords[p1 + 1] > coords[p2 + 1]) {
|
6334 | tmp = p1;
|
6335 | p1 = p2;
|
6336 | p2 = tmp;
|
6337 | tmp = c1;
|
6338 | c1 = c2;
|
6339 | c2 = tmp;
|
6340 | }
|
6341 |
|
6342 | if (coords[p2 + 1] > coords[p3 + 1]) {
|
6343 | tmp = p2;
|
6344 | p2 = p3;
|
6345 | p3 = tmp;
|
6346 | tmp = c2;
|
6347 | c2 = c3;
|
6348 | c3 = tmp;
|
6349 | }
|
6350 |
|
6351 | if (coords[p1 + 1] > coords[p2 + 1]) {
|
6352 | tmp = p1;
|
6353 | p1 = p2;
|
6354 | p2 = tmp;
|
6355 | tmp = c1;
|
6356 | c1 = c2;
|
6357 | c2 = tmp;
|
6358 | }
|
6359 |
|
6360 | var x1 = (coords[p1] + context.offsetX) * context.scaleX;
|
6361 | var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
|
6362 | var x2 = (coords[p2] + context.offsetX) * context.scaleX;
|
6363 | var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
|
6364 | var x3 = (coords[p3] + context.offsetX) * context.scaleX;
|
6365 | var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
|
6366 |
|
6367 | if (y1 >= y3) {
|
6368 | return;
|
6369 | }
|
6370 |
|
6371 | var c1r = colors[c1],
|
6372 | c1g = colors[c1 + 1],
|
6373 | c1b = colors[c1 + 2];
|
6374 | var c2r = colors[c2],
|
6375 | c2g = colors[c2 + 1],
|
6376 | c2b = colors[c2 + 2];
|
6377 | var c3r = colors[c3],
|
6378 | c3g = colors[c3 + 1],
|
6379 | c3b = colors[c3 + 2];
|
6380 | var minY = Math.round(y1),
|
6381 | maxY = Math.round(y3);
|
6382 | var xa, car, cag, cab;
|
6383 | var xb, cbr, cbg, cbb;
|
6384 |
|
6385 | for (var y = minY; y <= maxY; y++) {
|
6386 | if (y < y2) {
|
6387 | let k;
|
6388 |
|
6389 | if (y < y1) {
|
6390 | k = 0;
|
6391 | } else if (y1 === y2) {
|
6392 | k = 1;
|
6393 | } else {
|
6394 | k = (y1 - y) / (y1 - y2);
|
6395 | }
|
6396 |
|
6397 | xa = x1 - (x1 - x2) * k;
|
6398 | car = c1r - (c1r - c2r) * k;
|
6399 | cag = c1g - (c1g - c2g) * k;
|
6400 | cab = c1b - (c1b - c2b) * k;
|
6401 | } else {
|
6402 | let k;
|
6403 |
|
6404 | if (y > y3) {
|
6405 | k = 1;
|
6406 | } else if (y2 === y3) {
|
6407 | k = 0;
|
6408 | } else {
|
6409 | k = (y2 - y) / (y2 - y3);
|
6410 | }
|
6411 |
|
6412 | xa = x2 - (x2 - x3) * k;
|
6413 | car = c2r - (c2r - c3r) * k;
|
6414 | cag = c2g - (c2g - c3g) * k;
|
6415 | cab = c2b - (c2b - c3b) * k;
|
6416 | }
|
6417 |
|
6418 | let k;
|
6419 |
|
6420 | if (y < y1) {
|
6421 | k = 0;
|
6422 | } else if (y > y3) {
|
6423 | k = 1;
|
6424 | } else {
|
6425 | k = (y1 - y) / (y1 - y3);
|
6426 | }
|
6427 |
|
6428 | xb = x1 - (x1 - x3) * k;
|
6429 | cbr = c1r - (c1r - c3r) * k;
|
6430 | cbg = c1g - (c1g - c3g) * k;
|
6431 | cbb = c1b - (c1b - c3b) * k;
|
6432 | var x1_ = Math.round(Math.min(xa, xb));
|
6433 | var x2_ = Math.round(Math.max(xa, xb));
|
6434 | var j = rowSize * y + x1_ * 4;
|
6435 |
|
6436 | for (var x = x1_; x <= x2_; x++) {
|
6437 | k = (xa - x) / (xa - xb);
|
6438 |
|
6439 | if (k < 0) {
|
6440 | k = 0;
|
6441 | } else if (k > 1) {
|
6442 | k = 1;
|
6443 | }
|
6444 |
|
6445 | bytes[j++] = car - (car - cbr) * k | 0;
|
6446 | bytes[j++] = cag - (cag - cbg) * k | 0;
|
6447 | bytes[j++] = cab - (cab - cbb) * k | 0;
|
6448 | bytes[j++] = 255;
|
6449 | }
|
6450 | }
|
6451 | }
|
6452 |
|
6453 | function drawFigure(data, figure, context) {
|
6454 | var ps = figure.coords;
|
6455 | var cs = figure.colors;
|
6456 | var i, ii;
|
6457 |
|
6458 | switch (figure.type) {
|
6459 | case "lattice":
|
6460 | var verticesPerRow = figure.verticesPerRow;
|
6461 | var rows = Math.floor(ps.length / verticesPerRow) - 1;
|
6462 | var cols = verticesPerRow - 1;
|
6463 |
|
6464 | for (i = 0; i < rows; i++) {
|
6465 | var q = i * verticesPerRow;
|
6466 |
|
6467 | for (var j = 0; j < cols; j++, q++) {
|
6468 | drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
|
6469 | drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
|
6470 | }
|
6471 | }
|
6472 |
|
6473 | break;
|
6474 |
|
6475 | case "triangles":
|
6476 | for (i = 0, ii = ps.length; i < ii; i += 3) {
|
6477 | drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
|
6478 | }
|
6479 |
|
6480 | break;
|
6481 |
|
6482 | default:
|
6483 | throw new Error("illegal figure");
|
6484 | }
|
6485 | }
|
6486 |
|
6487 | function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases, webGLContext) {
|
6488 | var EXPECTED_SCALE = 1.1;
|
6489 | var MAX_PATTERN_SIZE = 3000;
|
6490 | var BORDER_SIZE = 2;
|
6491 | var offsetX = Math.floor(bounds[0]);
|
6492 | var offsetY = Math.floor(bounds[1]);
|
6493 | var boundsWidth = Math.ceil(bounds[2]) - offsetX;
|
6494 | var boundsHeight = Math.ceil(bounds[3]) - offsetY;
|
6495 | var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
|
6496 | var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
|
6497 | var scaleX = boundsWidth / width;
|
6498 | var scaleY = boundsHeight / height;
|
6499 | var context = {
|
6500 | coords,
|
6501 | colors,
|
6502 | offsetX: -offsetX,
|
6503 | offsetY: -offsetY,
|
6504 | scaleX: 1 / scaleX,
|
6505 | scaleY: 1 / scaleY
|
6506 | };
|
6507 | var paddedWidth = width + BORDER_SIZE * 2;
|
6508 | var paddedHeight = height + BORDER_SIZE * 2;
|
6509 | var canvas, tmpCanvas, i, ii;
|
6510 |
|
6511 | if (webGLContext.isEnabled) {
|
6512 | canvas = webGLContext.drawFigures({
|
6513 | width,
|
6514 | height,
|
6515 | backgroundColor,
|
6516 | figures,
|
6517 | context
|
6518 | });
|
6519 | tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
|
6520 | tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
|
6521 | canvas = tmpCanvas.canvas;
|
6522 | } else {
|
6523 | tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
|
6524 | var tmpCtx = tmpCanvas.context;
|
6525 | var data = tmpCtx.createImageData(width, height);
|
6526 |
|
6527 | if (backgroundColor) {
|
6528 | var bytes = data.data;
|
6529 |
|
6530 | for (i = 0, ii = bytes.length; i < ii; i += 4) {
|
6531 | bytes[i] = backgroundColor[0];
|
6532 | bytes[i + 1] = backgroundColor[1];
|
6533 | bytes[i + 2] = backgroundColor[2];
|
6534 | bytes[i + 3] = 255;
|
6535 | }
|
6536 | }
|
6537 |
|
6538 | for (i = 0; i < figures.length; i++) {
|
6539 | drawFigure(data, figures[i], context);
|
6540 | }
|
6541 |
|
6542 | tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
|
6543 | canvas = tmpCanvas.canvas;
|
6544 | }
|
6545 |
|
6546 | return {
|
6547 | canvas,
|
6548 | offsetX: offsetX - BORDER_SIZE * scaleX,
|
6549 | offsetY: offsetY - BORDER_SIZE * scaleY,
|
6550 | scaleX,
|
6551 | scaleY
|
6552 | };
|
6553 | }
|
6554 |
|
6555 | return createMeshCanvas;
|
6556 | }();
|
6557 |
|
6558 | ShadingIRs.Mesh = {
|
6559 | fromIR: function Mesh_fromIR(raw) {
|
6560 | var coords = raw[2];
|
6561 | var colors = raw[3];
|
6562 | var figures = raw[4];
|
6563 | var bounds = raw[5];
|
6564 | var matrix = raw[6];
|
6565 | var bbox = raw[7];
|
6566 | var background = raw[8];
|
6567 | return {
|
6568 | type: "Pattern",
|
6569 | getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
|
6570 | applyBoundingBox(ctx, bbox);
|
6571 | var scale;
|
6572 |
|
6573 | if (shadingFill) {
|
6574 | scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
|
6575 | } else {
|
6576 | scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
|
6577 |
|
6578 | if (matrix) {
|
6579 | var matrixScale = _util.Util.singularValueDecompose2dScale(matrix);
|
6580 |
|
6581 | scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
|
6582 | }
|
6583 | }
|
6584 |
|
6585 | var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases, owner.webGLContext);
|
6586 |
|
6587 | if (!shadingFill) {
|
6588 | ctx.setTransform.apply(ctx, owner.baseTransform);
|
6589 |
|
6590 | if (matrix) {
|
6591 | ctx.transform.apply(ctx, matrix);
|
6592 | }
|
6593 | }
|
6594 |
|
6595 | ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
|
6596 | ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
|
6597 | return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
|
6598 | }
|
6599 | };
|
6600 | }
|
6601 | };
|
6602 | ShadingIRs.Dummy = {
|
6603 | fromIR: function Dummy_fromIR() {
|
6604 | return {
|
6605 | type: "Pattern",
|
6606 | getPattern: function Dummy_fromIR_getPattern() {
|
6607 | return "hotpink";
|
6608 | }
|
6609 | };
|
6610 | }
|
6611 | };
|
6612 |
|
6613 | function getShadingPatternFromIR(raw) {
|
6614 | var shadingIR = ShadingIRs[raw[0]];
|
6615 |
|
6616 | if (!shadingIR) {
|
6617 | throw new Error(`Unknown IR type: ${raw[0]}`);
|
6618 | }
|
6619 |
|
6620 | return shadingIR.fromIR(raw);
|
6621 | }
|
6622 |
|
6623 | var TilingPattern = function TilingPatternClosure() {
|
6624 | var PaintType = {
|
6625 | COLORED: 1,
|
6626 | UNCOLORED: 2
|
6627 | };
|
6628 | var MAX_PATTERN_SIZE = 3000;
|
6629 |
|
6630 | function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
|
6631 | this.operatorList = IR[2];
|
6632 | this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
|
6633 | this.bbox = IR[4];
|
6634 | this.xstep = IR[5];
|
6635 | this.ystep = IR[6];
|
6636 | this.paintType = IR[7];
|
6637 | this.tilingType = IR[8];
|
6638 | this.color = color;
|
6639 | this.canvasGraphicsFactory = canvasGraphicsFactory;
|
6640 | this.baseTransform = baseTransform;
|
6641 | this.type = "Pattern";
|
6642 | this.ctx = ctx;
|
6643 | }
|
6644 |
|
6645 | TilingPattern.prototype = {
|
6646 | createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
|
6647 | var operatorList = this.operatorList;
|
6648 | var bbox = this.bbox;
|
6649 | var xstep = this.xstep;
|
6650 | var ystep = this.ystep;
|
6651 | var paintType = this.paintType;
|
6652 | var tilingType = this.tilingType;
|
6653 | var color = this.color;
|
6654 | var canvasGraphicsFactory = this.canvasGraphicsFactory;
|
6655 | (0, _util.info)("TilingType: " + tilingType);
|
6656 | var x0 = bbox[0],
|
6657 | y0 = bbox[1],
|
6658 | x1 = bbox[2],
|
6659 | y1 = bbox[3];
|
6660 |
|
6661 | var matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
|
6662 |
|
6663 | var curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
|
6664 |
|
6665 | var combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
|
6666 | var dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
|
6667 | var dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
|
6668 | var tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
|
6669 | var tmpCtx = tmpCanvas.context;
|
6670 | var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
|
6671 | graphics.groupLevel = owner.groupLevel;
|
6672 | this.setFillAndStrokeStyleToContext(graphics, paintType, color);
|
6673 | graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
|
6674 | graphics.transform(1, 0, 0, 1, -x0, -y0);
|
6675 | this.clipBbox(graphics, bbox, x0, y0, x1, y1);
|
6676 | graphics.executeOperatorList(operatorList);
|
6677 | this.ctx.transform(1, 0, 0, 1, x0, y0);
|
6678 | this.ctx.scale(1 / dimx.scale, 1 / dimy.scale);
|
6679 | return tmpCanvas.canvas;
|
6680 | },
|
6681 | getSizeAndScale: function TilingPattern_getSizeAndScale(step, realOutputSize, scale) {
|
6682 | step = Math.abs(step);
|
6683 | var maxSize = Math.max(MAX_PATTERN_SIZE, realOutputSize);
|
6684 | var size = Math.ceil(step * scale);
|
6685 |
|
6686 | if (size >= maxSize) {
|
6687 | size = maxSize;
|
6688 | } else {
|
6689 | scale = size / step;
|
6690 | }
|
6691 |
|
6692 | return {
|
6693 | scale,
|
6694 | size
|
6695 | };
|
6696 | },
|
6697 | clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
|
6698 | if (Array.isArray(bbox) && bbox.length === 4) {
|
6699 | var bboxWidth = x1 - x0;
|
6700 | var bboxHeight = y1 - y0;
|
6701 | graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
|
6702 | graphics.clip();
|
6703 | graphics.endPath();
|
6704 | }
|
6705 | },
|
6706 | setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(graphics, paintType, color) {
|
6707 | const context = graphics.ctx,
|
6708 | current = graphics.current;
|
6709 |
|
6710 | switch (paintType) {
|
6711 | case PaintType.COLORED:
|
6712 | var ctx = this.ctx;
|
6713 | context.fillStyle = ctx.fillStyle;
|
6714 | context.strokeStyle = ctx.strokeStyle;
|
6715 | current.fillColor = ctx.fillStyle;
|
6716 | current.strokeColor = ctx.strokeStyle;
|
6717 | break;
|
6718 |
|
6719 | case PaintType.UNCOLORED:
|
6720 | var cssColor = _util.Util.makeCssRgb(color[0], color[1], color[2]);
|
6721 |
|
6722 | context.fillStyle = cssColor;
|
6723 | context.strokeStyle = cssColor;
|
6724 | current.fillColor = cssColor;
|
6725 | current.strokeColor = cssColor;
|
6726 | break;
|
6727 |
|
6728 | default:
|
6729 | throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
|
6730 | }
|
6731 | },
|
6732 | getPattern: function TilingPattern_getPattern(ctx, owner) {
|
6733 | ctx = this.ctx;
|
6734 | ctx.setTransform.apply(ctx, this.baseTransform);
|
6735 | ctx.transform.apply(ctx, this.matrix);
|
6736 | var temporaryPatternCanvas = this.createPatternCanvas(owner);
|
6737 | return ctx.createPattern(temporaryPatternCanvas, "repeat");
|
6738 | }
|
6739 | };
|
6740 | return TilingPattern;
|
6741 | }();
|
6742 |
|
6743 | exports.TilingPattern = TilingPattern;
|
6744 |
|
6745 | }),
|
6746 |
|
6747 | (function(module, exports, __w_pdfjs_require__) {
|
6748 |
|
6749 | "use strict";
|
6750 |
|
6751 |
|
6752 | Object.defineProperty(exports, "__esModule", {
|
6753 | value: true
|
6754 | });
|
6755 | exports.GlobalWorkerOptions = void 0;
|
6756 | const GlobalWorkerOptions = Object.create(null);
|
6757 | exports.GlobalWorkerOptions = GlobalWorkerOptions;
|
6758 | GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort;
|
6759 | GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? "" : GlobalWorkerOptions.workerSrc;
|
6760 |
|
6761 | }),
|
6762 |
|
6763 | (function(module, exports, __w_pdfjs_require__) {
|
6764 |
|
6765 | "use strict";
|
6766 |
|
6767 |
|
6768 | Object.defineProperty(exports, "__esModule", {
|
6769 | value: true
|
6770 | });
|
6771 | exports.MessageHandler = void 0;
|
6772 |
|
6773 | var _util = __w_pdfjs_require__(2);
|
6774 |
|
6775 | const CallbackKind = {
|
6776 | UNKNOWN: 0,
|
6777 | DATA: 1,
|
6778 | ERROR: 2
|
6779 | };
|
6780 | const StreamKind = {
|
6781 | UNKNOWN: 0,
|
6782 | CANCEL: 1,
|
6783 | CANCEL_COMPLETE: 2,
|
6784 | CLOSE: 3,
|
6785 | ENQUEUE: 4,
|
6786 | ERROR: 5,
|
6787 | PULL: 6,
|
6788 | PULL_COMPLETE: 7,
|
6789 | START_COMPLETE: 8
|
6790 | };
|
6791 |
|
6792 | function wrapReason(reason) {
|
6793 | if (typeof reason !== "object" || reason === null) {
|
6794 | return reason;
|
6795 | }
|
6796 |
|
6797 | switch (reason.name) {
|
6798 | case "AbortException":
|
6799 | return new _util.AbortException(reason.message);
|
6800 |
|
6801 | case "MissingPDFException":
|
6802 | return new _util.MissingPDFException(reason.message);
|
6803 |
|
6804 | case "UnexpectedResponseException":
|
6805 | return new _util.UnexpectedResponseException(reason.message, reason.status);
|
6806 |
|
6807 | case "UnknownErrorException":
|
6808 | return new _util.UnknownErrorException(reason.message, reason.details);
|
6809 |
|
6810 | default:
|
6811 | return new _util.UnknownErrorException(reason.message, reason.toString());
|
6812 | }
|
6813 | }
|
6814 |
|
6815 | class MessageHandler {
|
6816 | constructor(sourceName, targetName, comObj) {
|
6817 | this.sourceName = sourceName;
|
6818 | this.targetName = targetName;
|
6819 | this.comObj = comObj;
|
6820 | this.callbackId = 1;
|
6821 | this.streamId = 1;
|
6822 | this.postMessageTransfers = true;
|
6823 | this.streamSinks = Object.create(null);
|
6824 | this.streamControllers = Object.create(null);
|
6825 | this.callbackCapabilities = Object.create(null);
|
6826 | this.actionHandler = Object.create(null);
|
6827 |
|
6828 | this._onComObjOnMessage = event => {
|
6829 | const data = event.data;
|
6830 |
|
6831 | if (data.targetName !== this.sourceName) {
|
6832 | return;
|
6833 | }
|
6834 |
|
6835 | if (data.stream) {
|
6836 | this._processStreamMessage(data);
|
6837 |
|
6838 | return;
|
6839 | }
|
6840 |
|
6841 | if (data.callback) {
|
6842 | const callbackId = data.callbackId;
|
6843 | const capability = this.callbackCapabilities[callbackId];
|
6844 |
|
6845 | if (!capability) {
|
6846 | throw new Error(`Cannot resolve callback ${callbackId}`);
|
6847 | }
|
6848 |
|
6849 | delete this.callbackCapabilities[callbackId];
|
6850 |
|
6851 | if (data.callback === CallbackKind.DATA) {
|
6852 | capability.resolve(data.data);
|
6853 | } else if (data.callback === CallbackKind.ERROR) {
|
6854 | capability.reject(wrapReason(data.reason));
|
6855 | } else {
|
6856 | throw new Error("Unexpected callback case");
|
6857 | }
|
6858 |
|
6859 | return;
|
6860 | }
|
6861 |
|
6862 | const action = this.actionHandler[data.action];
|
6863 |
|
6864 | if (!action) {
|
6865 | throw new Error(`Unknown action from worker: ${data.action}`);
|
6866 | }
|
6867 |
|
6868 | if (data.callbackId) {
|
6869 | const cbSourceName = this.sourceName;
|
6870 | const cbTargetName = data.sourceName;
|
6871 | new Promise(function (resolve) {
|
6872 | resolve(action(data.data));
|
6873 | }).then(function (result) {
|
6874 | comObj.postMessage({
|
6875 | sourceName: cbSourceName,
|
6876 | targetName: cbTargetName,
|
6877 | callback: CallbackKind.DATA,
|
6878 | callbackId: data.callbackId,
|
6879 | data: result
|
6880 | });
|
6881 | }, function (reason) {
|
6882 | comObj.postMessage({
|
6883 | sourceName: cbSourceName,
|
6884 | targetName: cbTargetName,
|
6885 | callback: CallbackKind.ERROR,
|
6886 | callbackId: data.callbackId,
|
6887 | reason: wrapReason(reason)
|
6888 | });
|
6889 | });
|
6890 | return;
|
6891 | }
|
6892 |
|
6893 | if (data.streamId) {
|
6894 | this._createStreamSink(data);
|
6895 |
|
6896 | return;
|
6897 | }
|
6898 |
|
6899 | action(data.data);
|
6900 | };
|
6901 |
|
6902 | comObj.addEventListener("message", this._onComObjOnMessage);
|
6903 | }
|
6904 |
|
6905 | on(actionName, handler) {
|
6906 | const ah = this.actionHandler;
|
6907 |
|
6908 | if (ah[actionName]) {
|
6909 | throw new Error(`There is already an actionName called "${actionName}"`);
|
6910 | }
|
6911 |
|
6912 | ah[actionName] = handler;
|
6913 | }
|
6914 |
|
6915 | send(actionName, data, transfers) {
|
6916 | this._postMessage({
|
6917 | sourceName: this.sourceName,
|
6918 | targetName: this.targetName,
|
6919 | action: actionName,
|
6920 | data
|
6921 | }, transfers);
|
6922 | }
|
6923 |
|
6924 | sendWithPromise(actionName, data, transfers) {
|
6925 | const callbackId = this.callbackId++;
|
6926 | const capability = (0, _util.createPromiseCapability)();
|
6927 | this.callbackCapabilities[callbackId] = capability;
|
6928 |
|
6929 | try {
|
6930 | this._postMessage({
|
6931 | sourceName: this.sourceName,
|
6932 | targetName: this.targetName,
|
6933 | action: actionName,
|
6934 | callbackId,
|
6935 | data
|
6936 | }, transfers);
|
6937 | } catch (ex) {
|
6938 | capability.reject(ex);
|
6939 | }
|
6940 |
|
6941 | return capability.promise;
|
6942 | }
|
6943 |
|
6944 | sendWithStream(actionName, data, queueingStrategy, transfers) {
|
6945 | const streamId = this.streamId++;
|
6946 | const sourceName = this.sourceName;
|
6947 | const targetName = this.targetName;
|
6948 | const comObj = this.comObj;
|
6949 | return new ReadableStream({
|
6950 | start: controller => {
|
6951 | const startCapability = (0, _util.createPromiseCapability)();
|
6952 | this.streamControllers[streamId] = {
|
6953 | controller,
|
6954 | startCall: startCapability,
|
6955 | pullCall: null,
|
6956 | cancelCall: null,
|
6957 | isClosed: false
|
6958 | };
|
6959 |
|
6960 | this._postMessage({
|
6961 | sourceName,
|
6962 | targetName,
|
6963 | action: actionName,
|
6964 | streamId,
|
6965 | data,
|
6966 | desiredSize: controller.desiredSize
|
6967 | }, transfers);
|
6968 |
|
6969 | return startCapability.promise;
|
6970 | },
|
6971 | pull: controller => {
|
6972 | const pullCapability = (0, _util.createPromiseCapability)();
|
6973 | this.streamControllers[streamId].pullCall = pullCapability;
|
6974 | comObj.postMessage({
|
6975 | sourceName,
|
6976 | targetName,
|
6977 | stream: StreamKind.PULL,
|
6978 | streamId,
|
6979 | desiredSize: controller.desiredSize
|
6980 | });
|
6981 | return pullCapability.promise;
|
6982 | },
|
6983 | cancel: reason => {
|
6984 | (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
|
6985 | const cancelCapability = (0, _util.createPromiseCapability)();
|
6986 | this.streamControllers[streamId].cancelCall = cancelCapability;
|
6987 | this.streamControllers[streamId].isClosed = true;
|
6988 | comObj.postMessage({
|
6989 | sourceName,
|
6990 | targetName,
|
6991 | stream: StreamKind.CANCEL,
|
6992 | streamId,
|
6993 | reason: wrapReason(reason)
|
6994 | });
|
6995 | return cancelCapability.promise;
|
6996 | }
|
6997 | }, queueingStrategy);
|
6998 | }
|
6999 |
|
7000 | _createStreamSink(data) {
|
7001 | const self = this;
|
7002 | const action = this.actionHandler[data.action];
|
7003 | const streamId = data.streamId;
|
7004 | const sourceName = this.sourceName;
|
7005 | const targetName = data.sourceName;
|
7006 | const comObj = this.comObj;
|
7007 | const streamSink = {
|
7008 | enqueue(chunk, size = 1, transfers) {
|
7009 | if (this.isCancelled) {
|
7010 | return;
|
7011 | }
|
7012 |
|
7013 | const lastDesiredSize = this.desiredSize;
|
7014 | this.desiredSize -= size;
|
7015 |
|
7016 | if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
7017 | this.sinkCapability = (0, _util.createPromiseCapability)();
|
7018 | this.ready = this.sinkCapability.promise;
|
7019 | }
|
7020 |
|
7021 | self._postMessage({
|
7022 | sourceName,
|
7023 | targetName,
|
7024 | stream: StreamKind.ENQUEUE,
|
7025 | streamId,
|
7026 | chunk
|
7027 | }, transfers);
|
7028 | },
|
7029 |
|
7030 | close() {
|
7031 | if (this.isCancelled) {
|
7032 | return;
|
7033 | }
|
7034 |
|
7035 | this.isCancelled = true;
|
7036 | comObj.postMessage({
|
7037 | sourceName,
|
7038 | targetName,
|
7039 | stream: StreamKind.CLOSE,
|
7040 | streamId
|
7041 | });
|
7042 | delete self.streamSinks[streamId];
|
7043 | },
|
7044 |
|
7045 | error(reason) {
|
7046 | (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
|
7047 |
|
7048 | if (this.isCancelled) {
|
7049 | return;
|
7050 | }
|
7051 |
|
7052 | this.isCancelled = true;
|
7053 | comObj.postMessage({
|
7054 | sourceName,
|
7055 | targetName,
|
7056 | stream: StreamKind.ERROR,
|
7057 | streamId,
|
7058 | reason: wrapReason(reason)
|
7059 | });
|
7060 | },
|
7061 |
|
7062 | sinkCapability: (0, _util.createPromiseCapability)(),
|
7063 | onPull: null,
|
7064 | onCancel: null,
|
7065 | isCancelled: false,
|
7066 | desiredSize: data.desiredSize,
|
7067 | ready: null
|
7068 | };
|
7069 | streamSink.sinkCapability.resolve();
|
7070 | streamSink.ready = streamSink.sinkCapability.promise;
|
7071 | this.streamSinks[streamId] = streamSink;
|
7072 | new Promise(function (resolve) {
|
7073 | resolve(action(data.data, streamSink));
|
7074 | }).then(function () {
|
7075 | comObj.postMessage({
|
7076 | sourceName,
|
7077 | targetName,
|
7078 | stream: StreamKind.START_COMPLETE,
|
7079 | streamId,
|
7080 | success: true
|
7081 | });
|
7082 | }, function (reason) {
|
7083 | comObj.postMessage({
|
7084 | sourceName,
|
7085 | targetName,
|
7086 | stream: StreamKind.START_COMPLETE,
|
7087 | streamId,
|
7088 | reason: wrapReason(reason)
|
7089 | });
|
7090 | });
|
7091 | }
|
7092 |
|
7093 | _processStreamMessage(data) {
|
7094 | const streamId = data.streamId;
|
7095 | const sourceName = this.sourceName;
|
7096 | const targetName = data.sourceName;
|
7097 | const comObj = this.comObj;
|
7098 |
|
7099 | switch (data.stream) {
|
7100 | case StreamKind.START_COMPLETE:
|
7101 | if (data.success) {
|
7102 | this.streamControllers[streamId].startCall.resolve();
|
7103 | } else {
|
7104 | this.streamControllers[streamId].startCall.reject(wrapReason(data.reason));
|
7105 | }
|
7106 |
|
7107 | break;
|
7108 |
|
7109 | case StreamKind.PULL_COMPLETE:
|
7110 | if (data.success) {
|
7111 | this.streamControllers[streamId].pullCall.resolve();
|
7112 | } else {
|
7113 | this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason));
|
7114 | }
|
7115 |
|
7116 | break;
|
7117 |
|
7118 | case StreamKind.PULL:
|
7119 | if (!this.streamSinks[streamId]) {
|
7120 | comObj.postMessage({
|
7121 | sourceName,
|
7122 | targetName,
|
7123 | stream: StreamKind.PULL_COMPLETE,
|
7124 | streamId,
|
7125 | success: true
|
7126 | });
|
7127 | break;
|
7128 | }
|
7129 |
|
7130 | if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) {
|
7131 | this.streamSinks[streamId].sinkCapability.resolve();
|
7132 | }
|
7133 |
|
7134 | this.streamSinks[streamId].desiredSize = data.desiredSize;
|
7135 | const {
|
7136 | onPull
|
7137 | } = this.streamSinks[data.streamId];
|
7138 | new Promise(function (resolve) {
|
7139 | resolve(onPull && onPull());
|
7140 | }).then(function () {
|
7141 | comObj.postMessage({
|
7142 | sourceName,
|
7143 | targetName,
|
7144 | stream: StreamKind.PULL_COMPLETE,
|
7145 | streamId,
|
7146 | success: true
|
7147 | });
|
7148 | }, function (reason) {
|
7149 | comObj.postMessage({
|
7150 | sourceName,
|
7151 | targetName,
|
7152 | stream: StreamKind.PULL_COMPLETE,
|
7153 | streamId,
|
7154 | reason: wrapReason(reason)
|
7155 | });
|
7156 | });
|
7157 | break;
|
7158 |
|
7159 | case StreamKind.ENQUEUE:
|
7160 | (0, _util.assert)(this.streamControllers[streamId], "enqueue should have stream controller");
|
7161 |
|
7162 | if (this.streamControllers[streamId].isClosed) {
|
7163 | break;
|
7164 | }
|
7165 |
|
7166 | this.streamControllers[streamId].controller.enqueue(data.chunk);
|
7167 | break;
|
7168 |
|
7169 | case StreamKind.CLOSE:
|
7170 | (0, _util.assert)(this.streamControllers[streamId], "close should have stream controller");
|
7171 |
|
7172 | if (this.streamControllers[streamId].isClosed) {
|
7173 | break;
|
7174 | }
|
7175 |
|
7176 | this.streamControllers[streamId].isClosed = true;
|
7177 | this.streamControllers[streamId].controller.close();
|
7178 |
|
7179 | this._deleteStreamController(streamId);
|
7180 |
|
7181 | break;
|
7182 |
|
7183 | case StreamKind.ERROR:
|
7184 | (0, _util.assert)(this.streamControllers[streamId], "error should have stream controller");
|
7185 | this.streamControllers[streamId].controller.error(wrapReason(data.reason));
|
7186 |
|
7187 | this._deleteStreamController(streamId);
|
7188 |
|
7189 | break;
|
7190 |
|
7191 | case StreamKind.CANCEL_COMPLETE:
|
7192 | if (data.success) {
|
7193 | this.streamControllers[streamId].cancelCall.resolve();
|
7194 | } else {
|
7195 | this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason));
|
7196 | }
|
7197 |
|
7198 | this._deleteStreamController(streamId);
|
7199 |
|
7200 | break;
|
7201 |
|
7202 | case StreamKind.CANCEL:
|
7203 | if (!this.streamSinks[streamId]) {
|
7204 | break;
|
7205 | }
|
7206 |
|
7207 | const {
|
7208 | onCancel
|
7209 | } = this.streamSinks[data.streamId];
|
7210 | new Promise(function (resolve) {
|
7211 | resolve(onCancel && onCancel(wrapReason(data.reason)));
|
7212 | }).then(function () {
|
7213 | comObj.postMessage({
|
7214 | sourceName,
|
7215 | targetName,
|
7216 | stream: StreamKind.CANCEL_COMPLETE,
|
7217 | streamId,
|
7218 | success: true
|
7219 | });
|
7220 | }, function (reason) {
|
7221 | comObj.postMessage({
|
7222 | sourceName,
|
7223 | targetName,
|
7224 | stream: StreamKind.CANCEL_COMPLETE,
|
7225 | streamId,
|
7226 | reason: wrapReason(reason)
|
7227 | });
|
7228 | });
|
7229 | this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason));
|
7230 | this.streamSinks[streamId].isCancelled = true;
|
7231 | delete this.streamSinks[streamId];
|
7232 | break;
|
7233 |
|
7234 | default:
|
7235 | throw new Error("Unexpected stream case");
|
7236 | }
|
7237 | }
|
7238 |
|
7239 | async _deleteStreamController(streamId) {
|
7240 | await Promise.allSettled([this.streamControllers[streamId].startCall, this.streamControllers[streamId].pullCall, this.streamControllers[streamId].cancelCall].map(function (capability) {
|
7241 | return capability && capability.promise;
|
7242 | }));
|
7243 | delete this.streamControllers[streamId];
|
7244 | }
|
7245 |
|
7246 | _postMessage(message, transfers) {
|
7247 | if (transfers && this.postMessageTransfers) {
|
7248 | this.comObj.postMessage(message, transfers);
|
7249 | } else {
|
7250 | this.comObj.postMessage(message);
|
7251 | }
|
7252 | }
|
7253 |
|
7254 | destroy() {
|
7255 | this.comObj.removeEventListener("message", this._onComObjOnMessage);
|
7256 | }
|
7257 |
|
7258 | }
|
7259 |
|
7260 | exports.MessageHandler = MessageHandler;
|
7261 |
|
7262 | }),
|
7263 |
|
7264 | (function(module, exports, __w_pdfjs_require__) {
|
7265 |
|
7266 | "use strict";
|
7267 |
|
7268 |
|
7269 | Object.defineProperty(exports, "__esModule", {
|
7270 | value: true
|
7271 | });
|
7272 | exports.Metadata = void 0;
|
7273 |
|
7274 | var _util = __w_pdfjs_require__(2);
|
7275 |
|
7276 | var _xml_parser = __w_pdfjs_require__(13);
|
7277 |
|
7278 | class Metadata {
|
7279 | constructor(data) {
|
7280 | (0, _util.assert)(typeof data === "string", "Metadata: input is not a string");
|
7281 | data = this._repair(data);
|
7282 | const parser = new _xml_parser.SimpleXMLParser();
|
7283 | const xmlDocument = parser.parseFromString(data);
|
7284 | this._metadataMap = new Map();
|
7285 |
|
7286 | if (xmlDocument) {
|
7287 | this._parse(xmlDocument);
|
7288 | }
|
7289 | }
|
7290 |
|
7291 | _repair(data) {
|
7292 | return data.replace(/^[^<]+/, "").replace(/>\\376\\377([^<]+)/g, function (all, codes) {
|
7293 | const bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
|
7294 | return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
|
7295 | }).replace(/&(amp|apos|gt|lt|quot);/g, function (str, name) {
|
7296 | switch (name) {
|
7297 | case "amp":
|
7298 | return "&";
|
7299 |
|
7300 | case "apos":
|
7301 | return "'";
|
7302 |
|
7303 | case "gt":
|
7304 | return ">";
|
7305 |
|
7306 | case "lt":
|
7307 | return "<";
|
7308 |
|
7309 | case "quot":
|
7310 | return '"';
|
7311 | }
|
7312 |
|
7313 | throw new Error(`_repair: ${name} isn't defined.`);
|
7314 | });
|
7315 | let chars = "";
|
7316 |
|
7317 | for (let i = 0, ii = bytes.length; i < ii; i += 2) {
|
7318 | const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
|
7319 |
|
7320 | if (code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38) {
|
7321 | chars += String.fromCharCode(code);
|
7322 | } else {
|
7323 | chars += "&#x" + (0x10000 + code).toString(16).substring(1) + ";";
|
7324 | }
|
7325 | }
|
7326 |
|
7327 | return ">" + chars;
|
7328 | });
|
7329 | }
|
7330 |
|
7331 | _parse(xmlDocument) {
|
7332 | let rdf = xmlDocument.documentElement;
|
7333 |
|
7334 | if (rdf.nodeName.toLowerCase() !== "rdf:rdf") {
|
7335 | rdf = rdf.firstChild;
|
7336 |
|
7337 | while (rdf && rdf.nodeName.toLowerCase() !== "rdf:rdf") {
|
7338 | rdf = rdf.nextSibling;
|
7339 | }
|
7340 | }
|
7341 |
|
7342 | const nodeName = rdf ? rdf.nodeName.toLowerCase() : null;
|
7343 |
|
7344 | if (!rdf || nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) {
|
7345 | return;
|
7346 | }
|
7347 |
|
7348 | const children = rdf.childNodes;
|
7349 |
|
7350 | for (let i = 0, ii = children.length; i < ii; i++) {
|
7351 | const desc = children[i];
|
7352 |
|
7353 | if (desc.nodeName.toLowerCase() !== "rdf:description") {
|
7354 | continue;
|
7355 | }
|
7356 |
|
7357 | for (let j = 0, jj = desc.childNodes.length; j < jj; j++) {
|
7358 | if (desc.childNodes[j].nodeName.toLowerCase() !== "#text") {
|
7359 | const entry = desc.childNodes[j];
|
7360 | const name = entry.nodeName.toLowerCase();
|
7361 |
|
7362 | this._metadataMap.set(name, entry.textContent.trim());
|
7363 | }
|
7364 | }
|
7365 | }
|
7366 | }
|
7367 |
|
7368 | get(name) {
|
7369 | return this._metadataMap.has(name) ? this._metadataMap.get(name) : null;
|
7370 | }
|
7371 |
|
7372 | getAll() {
|
7373 | const obj = Object.create(null);
|
7374 |
|
7375 | for (const [key, value] of this._metadataMap) {
|
7376 | obj[key] = value;
|
7377 | }
|
7378 |
|
7379 | return obj;
|
7380 | }
|
7381 |
|
7382 | has(name) {
|
7383 | return this._metadataMap.has(name);
|
7384 | }
|
7385 |
|
7386 | }
|
7387 |
|
7388 | exports.Metadata = Metadata;
|
7389 |
|
7390 | }),
|
7391 |
|
7392 | (function(module, exports, __w_pdfjs_require__) {
|
7393 |
|
7394 | "use strict";
|
7395 |
|
7396 |
|
7397 | Object.defineProperty(exports, "__esModule", {
|
7398 | value: true
|
7399 | });
|
7400 | exports.SimpleXMLParser = void 0;
|
7401 | const XMLParserErrorCode = {
|
7402 | NoError: 0,
|
7403 | EndOfDocument: -1,
|
7404 | UnterminatedCdat: -2,
|
7405 | UnterminatedXmlDeclaration: -3,
|
7406 | UnterminatedDoctypeDeclaration: -4,
|
7407 | UnterminatedComment: -5,
|
7408 | MalformedElement: -6,
|
7409 | OutOfMemory: -7,
|
7410 | UnterminatedAttributeValue: -8,
|
7411 | UnterminatedElement: -9,
|
7412 | ElementNeverBegun: -10
|
7413 | };
|
7414 |
|
7415 | function isWhitespace(s, index) {
|
7416 | const ch = s[index];
|
7417 | return ch === " " || ch === "\n" || ch === "\r" || ch === "\t";
|
7418 | }
|
7419 |
|
7420 | function isWhitespaceString(s) {
|
7421 | for (let i = 0, ii = s.length; i < ii; i++) {
|
7422 | if (!isWhitespace(s, i)) {
|
7423 | return false;
|
7424 | }
|
7425 | }
|
7426 |
|
7427 | return true;
|
7428 | }
|
7429 |
|
7430 | class XMLParserBase {
|
7431 | _resolveEntities(s) {
|
7432 | return s.replace(/&([^;]+);/g, (all, entity) => {
|
7433 | if (entity.substring(0, 2) === "#x") {
|
7434 | return String.fromCharCode(parseInt(entity.substring(2), 16));
|
7435 | } else if (entity.substring(0, 1) === "#") {
|
7436 | return String.fromCharCode(parseInt(entity.substring(1), 10));
|
7437 | }
|
7438 |
|
7439 | switch (entity) {
|
7440 | case "lt":
|
7441 | return "<";
|
7442 |
|
7443 | case "gt":
|
7444 | return ">";
|
7445 |
|
7446 | case "amp":
|
7447 | return "&";
|
7448 |
|
7449 | case "quot":
|
7450 | return '"';
|
7451 | }
|
7452 |
|
7453 | return this.onResolveEntity(entity);
|
7454 | });
|
7455 | }
|
7456 |
|
7457 | _parseContent(s, start) {
|
7458 | const attributes = [];
|
7459 | let pos = start;
|
7460 |
|
7461 | function skipWs() {
|
7462 | while (pos < s.length && isWhitespace(s, pos)) {
|
7463 | ++pos;
|
7464 | }
|
7465 | }
|
7466 |
|
7467 | while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
|
7468 | ++pos;
|
7469 | }
|
7470 |
|
7471 | const name = s.substring(start, pos);
|
7472 | skipWs();
|
7473 |
|
7474 | while (pos < s.length && s[pos] !== ">" && s[pos] !== "/" && s[pos] !== "?") {
|
7475 | skipWs();
|
7476 | let attrName = "",
|
7477 | attrValue = "";
|
7478 |
|
7479 | while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== "=") {
|
7480 | attrName += s[pos];
|
7481 | ++pos;
|
7482 | }
|
7483 |
|
7484 | skipWs();
|
7485 |
|
7486 | if (s[pos] !== "=") {
|
7487 | return null;
|
7488 | }
|
7489 |
|
7490 | ++pos;
|
7491 | skipWs();
|
7492 | const attrEndChar = s[pos];
|
7493 |
|
7494 | if (attrEndChar !== '"' && attrEndChar !== "'") {
|
7495 | return null;
|
7496 | }
|
7497 |
|
7498 | const attrEndIndex = s.indexOf(attrEndChar, ++pos);
|
7499 |
|
7500 | if (attrEndIndex < 0) {
|
7501 | return null;
|
7502 | }
|
7503 |
|
7504 | attrValue = s.substring(pos, attrEndIndex);
|
7505 | attributes.push({
|
7506 | name: attrName,
|
7507 | value: this._resolveEntities(attrValue)
|
7508 | });
|
7509 | pos = attrEndIndex + 1;
|
7510 | skipWs();
|
7511 | }
|
7512 |
|
7513 | return {
|
7514 | name,
|
7515 | attributes,
|
7516 | parsed: pos - start
|
7517 | };
|
7518 | }
|
7519 |
|
7520 | _parseProcessingInstruction(s, start) {
|
7521 | let pos = start;
|
7522 |
|
7523 | function skipWs() {
|
7524 | while (pos < s.length && isWhitespace(s, pos)) {
|
7525 | ++pos;
|
7526 | }
|
7527 | }
|
7528 |
|
7529 | while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
|
7530 | ++pos;
|
7531 | }
|
7532 |
|
7533 | const name = s.substring(start, pos);
|
7534 | skipWs();
|
7535 | const attrStart = pos;
|
7536 |
|
7537 | while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
|
7538 | ++pos;
|
7539 | }
|
7540 |
|
7541 | const value = s.substring(attrStart, pos);
|
7542 | return {
|
7543 | name,
|
7544 | value,
|
7545 | parsed: pos - start
|
7546 | };
|
7547 | }
|
7548 |
|
7549 | parseXml(s) {
|
7550 | let i = 0;
|
7551 |
|
7552 | while (i < s.length) {
|
7553 | const ch = s[i];
|
7554 | let j = i;
|
7555 |
|
7556 | if (ch === "<") {
|
7557 | ++j;
|
7558 | const ch2 = s[j];
|
7559 | let q;
|
7560 |
|
7561 | switch (ch2) {
|
7562 | case "/":
|
7563 | ++j;
|
7564 | q = s.indexOf(">", j);
|
7565 |
|
7566 | if (q < 0) {
|
7567 | this.onError(XMLParserErrorCode.UnterminatedElement);
|
7568 | return;
|
7569 | }
|
7570 |
|
7571 | this.onEndElement(s.substring(j, q));
|
7572 | j = q + 1;
|
7573 | break;
|
7574 |
|
7575 | case "?":
|
7576 | ++j;
|
7577 |
|
7578 | const pi = this._parseProcessingInstruction(s, j);
|
7579 |
|
7580 | if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== "?>") {
|
7581 | this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration);
|
7582 | return;
|
7583 | }
|
7584 |
|
7585 | this.onPi(pi.name, pi.value);
|
7586 | j += pi.parsed + 2;
|
7587 | break;
|
7588 |
|
7589 | case "!":
|
7590 | if (s.substring(j + 1, j + 3) === "--") {
|
7591 | q = s.indexOf("-->", j + 3);
|
7592 |
|
7593 | if (q < 0) {
|
7594 | this.onError(XMLParserErrorCode.UnterminatedComment);
|
7595 | return;
|
7596 | }
|
7597 |
|
7598 | this.onComment(s.substring(j + 3, q));
|
7599 | j = q + 3;
|
7600 | } else if (s.substring(j + 1, j + 8) === "[CDATA[") {
|
7601 | q = s.indexOf("]]>", j + 8);
|
7602 |
|
7603 | if (q < 0) {
|
7604 | this.onError(XMLParserErrorCode.UnterminatedCdat);
|
7605 | return;
|
7606 | }
|
7607 |
|
7608 | this.onCdata(s.substring(j + 8, q));
|
7609 | j = q + 3;
|
7610 | } else if (s.substring(j + 1, j + 8) === "DOCTYPE") {
|
7611 | const q2 = s.indexOf("[", j + 8);
|
7612 | let complexDoctype = false;
|
7613 | q = s.indexOf(">", j + 8);
|
7614 |
|
7615 | if (q < 0) {
|
7616 | this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
|
7617 | return;
|
7618 | }
|
7619 |
|
7620 | if (q2 > 0 && q > q2) {
|
7621 | q = s.indexOf("]>", j + 8);
|
7622 |
|
7623 | if (q < 0) {
|
7624 | this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
|
7625 | return;
|
7626 | }
|
7627 |
|
7628 | complexDoctype = true;
|
7629 | }
|
7630 |
|
7631 | const doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0));
|
7632 | this.onDoctype(doctypeContent);
|
7633 | j = q + (complexDoctype ? 2 : 1);
|
7634 | } else {
|
7635 | this.onError(XMLParserErrorCode.MalformedElement);
|
7636 | return;
|
7637 | }
|
7638 |
|
7639 | break;
|
7640 |
|
7641 | default:
|
7642 | const content = this._parseContent(s, j);
|
7643 |
|
7644 | if (content === null) {
|
7645 | this.onError(XMLParserErrorCode.MalformedElement);
|
7646 | return;
|
7647 | }
|
7648 |
|
7649 | let isClosed = false;
|
7650 |
|
7651 | if (s.substring(j + content.parsed, j + content.parsed + 2) === "/>") {
|
7652 | isClosed = true;
|
7653 | } else if (s.substring(j + content.parsed, j + content.parsed + 1) !== ">") {
|
7654 | this.onError(XMLParserErrorCode.UnterminatedElement);
|
7655 | return;
|
7656 | }
|
7657 |
|
7658 | this.onBeginElement(content.name, content.attributes, isClosed);
|
7659 | j += content.parsed + (isClosed ? 2 : 1);
|
7660 | break;
|
7661 | }
|
7662 | } else {
|
7663 | while (j < s.length && s[j] !== "<") {
|
7664 | j++;
|
7665 | }
|
7666 |
|
7667 | const text = s.substring(i, j);
|
7668 | this.onText(this._resolveEntities(text));
|
7669 | }
|
7670 |
|
7671 | i = j;
|
7672 | }
|
7673 | }
|
7674 |
|
7675 | onResolveEntity(name) {
|
7676 | return `&${name};`;
|
7677 | }
|
7678 |
|
7679 | onPi(name, value) {}
|
7680 |
|
7681 | onComment(text) {}
|
7682 |
|
7683 | onCdata(text) {}
|
7684 |
|
7685 | onDoctype(doctypeContent) {}
|
7686 |
|
7687 | onText(text) {}
|
7688 |
|
7689 | onBeginElement(name, attributes, isEmpty) {}
|
7690 |
|
7691 | onEndElement(name) {}
|
7692 |
|
7693 | onError(code) {}
|
7694 |
|
7695 | }
|
7696 |
|
7697 | class SimpleDOMNode {
|
7698 | constructor(nodeName, nodeValue) {
|
7699 | this.nodeName = nodeName;
|
7700 | this.nodeValue = nodeValue;
|
7701 | Object.defineProperty(this, "parentNode", {
|
7702 | value: null,
|
7703 | writable: true
|
7704 | });
|
7705 | }
|
7706 |
|
7707 | get firstChild() {
|
7708 | return this.childNodes && this.childNodes[0];
|
7709 | }
|
7710 |
|
7711 | get nextSibling() {
|
7712 | const childNodes = this.parentNode.childNodes;
|
7713 |
|
7714 | if (!childNodes) {
|
7715 | return undefined;
|
7716 | }
|
7717 |
|
7718 | const index = childNodes.indexOf(this);
|
7719 |
|
7720 | if (index === -1) {
|
7721 | return undefined;
|
7722 | }
|
7723 |
|
7724 | return childNodes[index + 1];
|
7725 | }
|
7726 |
|
7727 | get textContent() {
|
7728 | if (!this.childNodes) {
|
7729 | return this.nodeValue || "";
|
7730 | }
|
7731 |
|
7732 | return this.childNodes.map(function (child) {
|
7733 | return child.textContent;
|
7734 | }).join("");
|
7735 | }
|
7736 |
|
7737 | hasChildNodes() {
|
7738 | return this.childNodes && this.childNodes.length > 0;
|
7739 | }
|
7740 |
|
7741 | }
|
7742 |
|
7743 | class SimpleXMLParser extends XMLParserBase {
|
7744 | constructor() {
|
7745 | super();
|
7746 | this._currentFragment = null;
|
7747 | this._stack = null;
|
7748 | this._errorCode = XMLParserErrorCode.NoError;
|
7749 | }
|
7750 |
|
7751 | parseFromString(data) {
|
7752 | this._currentFragment = [];
|
7753 | this._stack = [];
|
7754 | this._errorCode = XMLParserErrorCode.NoError;
|
7755 | this.parseXml(data);
|
7756 |
|
7757 | if (this._errorCode !== XMLParserErrorCode.NoError) {
|
7758 | return undefined;
|
7759 | }
|
7760 |
|
7761 | const [documentElement] = this._currentFragment;
|
7762 |
|
7763 | if (!documentElement) {
|
7764 | return undefined;
|
7765 | }
|
7766 |
|
7767 | return {
|
7768 | documentElement
|
7769 | };
|
7770 | }
|
7771 |
|
7772 | onResolveEntity(name) {
|
7773 | switch (name) {
|
7774 | case "apos":
|
7775 | return "'";
|
7776 | }
|
7777 |
|
7778 | return super.onResolveEntity(name);
|
7779 | }
|
7780 |
|
7781 | onText(text) {
|
7782 | if (isWhitespaceString(text)) {
|
7783 | return;
|
7784 | }
|
7785 |
|
7786 | const node = new SimpleDOMNode("#text", text);
|
7787 |
|
7788 | this._currentFragment.push(node);
|
7789 | }
|
7790 |
|
7791 | onCdata(text) {
|
7792 | const node = new SimpleDOMNode("#text", text);
|
7793 |
|
7794 | this._currentFragment.push(node);
|
7795 | }
|
7796 |
|
7797 | onBeginElement(name, attributes, isEmpty) {
|
7798 | const node = new SimpleDOMNode(name);
|
7799 | node.childNodes = [];
|
7800 |
|
7801 | this._currentFragment.push(node);
|
7802 |
|
7803 | if (isEmpty) {
|
7804 | return;
|
7805 | }
|
7806 |
|
7807 | this._stack.push(this._currentFragment);
|
7808 |
|
7809 | this._currentFragment = node.childNodes;
|
7810 | }
|
7811 |
|
7812 | onEndElement(name) {
|
7813 | this._currentFragment = this._stack.pop() || [];
|
7814 | const lastElement = this._currentFragment[this._currentFragment.length - 1];
|
7815 |
|
7816 | if (!lastElement) {
|
7817 | return;
|
7818 | }
|
7819 |
|
7820 | for (let i = 0, ii = lastElement.childNodes.length; i < ii; i++) {
|
7821 | lastElement.childNodes[i].parentNode = lastElement;
|
7822 | }
|
7823 | }
|
7824 |
|
7825 | onError(code) {
|
7826 | this._errorCode = code;
|
7827 | }
|
7828 |
|
7829 | }
|
7830 |
|
7831 | exports.SimpleXMLParser = SimpleXMLParser;
|
7832 |
|
7833 | }),
|
7834 |
|
7835 | (function(module, exports, __w_pdfjs_require__) {
|
7836 |
|
7837 | "use strict";
|
7838 |
|
7839 |
|
7840 | Object.defineProperty(exports, "__esModule", {
|
7841 | value: true
|
7842 | });
|
7843 | exports.PDFDataTransportStream = void 0;
|
7844 |
|
7845 | var _util = __w_pdfjs_require__(2);
|
7846 |
|
7847 | class PDFDataTransportStream {
|
7848 | constructor(params, pdfDataRangeTransport) {
|
7849 | (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
|
7850 | this._queuedChunks = [];
|
7851 | this._progressiveDone = params.progressiveDone || false;
|
7852 | const initialData = params.initialData;
|
7853 |
|
7854 | if (initialData && initialData.length > 0) {
|
7855 | const buffer = new Uint8Array(initialData).buffer;
|
7856 |
|
7857 | this._queuedChunks.push(buffer);
|
7858 | }
|
7859 |
|
7860 | this._pdfDataRangeTransport = pdfDataRangeTransport;
|
7861 | this._isStreamingSupported = !params.disableStream;
|
7862 | this._isRangeSupported = !params.disableRange;
|
7863 | this._contentLength = params.length;
|
7864 | this._fullRequestReader = null;
|
7865 | this._rangeReaders = [];
|
7866 |
|
7867 | this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
|
7868 | this._onReceiveData({
|
7869 | begin,
|
7870 | chunk
|
7871 | });
|
7872 | });
|
7873 |
|
7874 | this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
|
7875 | this._onProgress({
|
7876 | loaded,
|
7877 | total
|
7878 | });
|
7879 | });
|
7880 |
|
7881 | this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
|
7882 | this._onReceiveData({
|
7883 | chunk
|
7884 | });
|
7885 | });
|
7886 |
|
7887 | this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
|
7888 | this._onProgressiveDone();
|
7889 | });
|
7890 |
|
7891 | this._pdfDataRangeTransport.transportReady();
|
7892 | }
|
7893 |
|
7894 | _onReceiveData(args) {
|
7895 | const buffer = new Uint8Array(args.chunk).buffer;
|
7896 |
|
7897 | if (args.begin === undefined) {
|
7898 | if (this._fullRequestReader) {
|
7899 | this._fullRequestReader._enqueue(buffer);
|
7900 | } else {
|
7901 | this._queuedChunks.push(buffer);
|
7902 | }
|
7903 | } else {
|
7904 | const found = this._rangeReaders.some(function (rangeReader) {
|
7905 | if (rangeReader._begin !== args.begin) {
|
7906 | return false;
|
7907 | }
|
7908 |
|
7909 | rangeReader._enqueue(buffer);
|
7910 |
|
7911 | return true;
|
7912 | });
|
7913 |
|
7914 | (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
|
7915 | }
|
7916 | }
|
7917 |
|
7918 | get _progressiveDataLength() {
|
7919 | return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
|
7920 | }
|
7921 |
|
7922 | _onProgress(evt) {
|
7923 | if (evt.total === undefined) {
|
7924 | const firstReader = this._rangeReaders[0];
|
7925 |
|
7926 | if (firstReader && firstReader.onProgress) {
|
7927 | firstReader.onProgress({
|
7928 | loaded: evt.loaded
|
7929 | });
|
7930 | }
|
7931 | } else {
|
7932 | const fullReader = this._fullRequestReader;
|
7933 |
|
7934 | if (fullReader && fullReader.onProgress) {
|
7935 | fullReader.onProgress({
|
7936 | loaded: evt.loaded,
|
7937 | total: evt.total
|
7938 | });
|
7939 | }
|
7940 | }
|
7941 | }
|
7942 |
|
7943 | _onProgressiveDone() {
|
7944 | if (this._fullRequestReader) {
|
7945 | this._fullRequestReader.progressiveDone();
|
7946 | }
|
7947 |
|
7948 | this._progressiveDone = true;
|
7949 | }
|
7950 |
|
7951 | _removeRangeReader(reader) {
|
7952 | const i = this._rangeReaders.indexOf(reader);
|
7953 |
|
7954 | if (i >= 0) {
|
7955 | this._rangeReaders.splice(i, 1);
|
7956 | }
|
7957 | }
|
7958 |
|
7959 | getFullReader() {
|
7960 | (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
|
7961 | const queuedChunks = this._queuedChunks;
|
7962 | this._queuedChunks = null;
|
7963 | return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone);
|
7964 | }
|
7965 |
|
7966 | getRangeReader(begin, end) {
|
7967 | if (end <= this._progressiveDataLength) {
|
7968 | return null;
|
7969 | }
|
7970 |
|
7971 | const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
|
7972 |
|
7973 | this._pdfDataRangeTransport.requestDataRange(begin, end);
|
7974 |
|
7975 | this._rangeReaders.push(reader);
|
7976 |
|
7977 | return reader;
|
7978 | }
|
7979 |
|
7980 | cancelAllRequests(reason) {
|
7981 | if (this._fullRequestReader) {
|
7982 | this._fullRequestReader.cancel(reason);
|
7983 | }
|
7984 |
|
7985 | const readers = this._rangeReaders.slice(0);
|
7986 |
|
7987 | readers.forEach(function (rangeReader) {
|
7988 | rangeReader.cancel(reason);
|
7989 | });
|
7990 |
|
7991 | this._pdfDataRangeTransport.abort();
|
7992 | }
|
7993 |
|
7994 | }
|
7995 |
|
7996 | exports.PDFDataTransportStream = PDFDataTransportStream;
|
7997 |
|
7998 | class PDFDataTransportStreamReader {
|
7999 | constructor(stream, queuedChunks, progressiveDone = false) {
|
8000 | this._stream = stream;
|
8001 | this._done = progressiveDone || false;
|
8002 | this._filename = null;
|
8003 | this._queuedChunks = queuedChunks || [];
|
8004 | this._loaded = 0;
|
8005 |
|
8006 | for (const chunk of this._queuedChunks) {
|
8007 | this._loaded += chunk.byteLength;
|
8008 | }
|
8009 |
|
8010 | this._requests = [];
|
8011 | this._headersReady = Promise.resolve();
|
8012 | stream._fullRequestReader = this;
|
8013 | this.onProgress = null;
|
8014 | }
|
8015 |
|
8016 | _enqueue(chunk) {
|
8017 | if (this._done) {
|
8018 | return;
|
8019 | }
|
8020 |
|
8021 | if (this._requests.length > 0) {
|
8022 | const requestCapability = this._requests.shift();
|
8023 |
|
8024 | requestCapability.resolve({
|
8025 | value: chunk,
|
8026 | done: false
|
8027 | });
|
8028 | } else {
|
8029 | this._queuedChunks.push(chunk);
|
8030 | }
|
8031 |
|
8032 | this._loaded += chunk.byteLength;
|
8033 | }
|
8034 |
|
8035 | get headersReady() {
|
8036 | return this._headersReady;
|
8037 | }
|
8038 |
|
8039 | get filename() {
|
8040 | return this._filename;
|
8041 | }
|
8042 |
|
8043 | get isRangeSupported() {
|
8044 | return this._stream._isRangeSupported;
|
8045 | }
|
8046 |
|
8047 | get isStreamingSupported() {
|
8048 | return this._stream._isStreamingSupported;
|
8049 | }
|
8050 |
|
8051 | get contentLength() {
|
8052 | return this._stream._contentLength;
|
8053 | }
|
8054 |
|
8055 | async read() {
|
8056 | if (this._queuedChunks.length > 0) {
|
8057 | const chunk = this._queuedChunks.shift();
|
8058 |
|
8059 | return {
|
8060 | value: chunk,
|
8061 | done: false
|
8062 | };
|
8063 | }
|
8064 |
|
8065 | if (this._done) {
|
8066 | return {
|
8067 | value: undefined,
|
8068 | done: true
|
8069 | };
|
8070 | }
|
8071 |
|
8072 | const requestCapability = (0, _util.createPromiseCapability)();
|
8073 |
|
8074 | this._requests.push(requestCapability);
|
8075 |
|
8076 | return requestCapability.promise;
|
8077 | }
|
8078 |
|
8079 | cancel(reason) {
|
8080 | this._done = true;
|
8081 |
|
8082 | this._requests.forEach(function (requestCapability) {
|
8083 | requestCapability.resolve({
|
8084 | value: undefined,
|
8085 | done: true
|
8086 | });
|
8087 | });
|
8088 |
|
8089 | this._requests = [];
|
8090 | }
|
8091 |
|
8092 | progressiveDone() {
|
8093 | if (this._done) {
|
8094 | return;
|
8095 | }
|
8096 |
|
8097 | this._done = true;
|
8098 | }
|
8099 |
|
8100 | }
|
8101 |
|
8102 | class PDFDataTransportStreamRangeReader {
|
8103 | constructor(stream, begin, end) {
|
8104 | this._stream = stream;
|
8105 | this._begin = begin;
|
8106 | this._end = end;
|
8107 | this._queuedChunk = null;
|
8108 | this._requests = [];
|
8109 | this._done = false;
|
8110 | this.onProgress = null;
|
8111 | }
|
8112 |
|
8113 | _enqueue(chunk) {
|
8114 | if (this._done) {
|
8115 | return;
|
8116 | }
|
8117 |
|
8118 | if (this._requests.length === 0) {
|
8119 | this._queuedChunk = chunk;
|
8120 | } else {
|
8121 | const requestsCapability = this._requests.shift();
|
8122 |
|
8123 | requestsCapability.resolve({
|
8124 | value: chunk,
|
8125 | done: false
|
8126 | });
|
8127 |
|
8128 | this._requests.forEach(function (requestCapability) {
|
8129 | requestCapability.resolve({
|
8130 | value: undefined,
|
8131 | done: true
|
8132 | });
|
8133 | });
|
8134 |
|
8135 | this._requests = [];
|
8136 | }
|
8137 |
|
8138 | this._done = true;
|
8139 |
|
8140 | this._stream._removeRangeReader(this);
|
8141 | }
|
8142 |
|
8143 | get isStreamingSupported() {
|
8144 | return false;
|
8145 | }
|
8146 |
|
8147 | async read() {
|
8148 | if (this._queuedChunk) {
|
8149 | const chunk = this._queuedChunk;
|
8150 | this._queuedChunk = null;
|
8151 | return {
|
8152 | value: chunk,
|
8153 | done: false
|
8154 | };
|
8155 | }
|
8156 |
|
8157 | if (this._done) {
|
8158 | return {
|
8159 | value: undefined,
|
8160 | done: true
|
8161 | };
|
8162 | }
|
8163 |
|
8164 | const requestCapability = (0, _util.createPromiseCapability)();
|
8165 |
|
8166 | this._requests.push(requestCapability);
|
8167 |
|
8168 | return requestCapability.promise;
|
8169 | }
|
8170 |
|
8171 | cancel(reason) {
|
8172 | this._done = true;
|
8173 |
|
8174 | this._requests.forEach(function (requestCapability) {
|
8175 | requestCapability.resolve({
|
8176 | value: undefined,
|
8177 | done: true
|
8178 | });
|
8179 | });
|
8180 |
|
8181 | this._requests = [];
|
8182 |
|
8183 | this._stream._removeRangeReader(this);
|
8184 | }
|
8185 |
|
8186 | }
|
8187 |
|
8188 | }),
|
8189 |
|
8190 | (function(module, exports, __w_pdfjs_require__) {
|
8191 |
|
8192 | "use strict";
|
8193 |
|
8194 |
|
8195 | Object.defineProperty(exports, "__esModule", {
|
8196 | value: true
|
8197 | });
|
8198 | exports.WebGLContext = void 0;
|
8199 |
|
8200 | var _util = __w_pdfjs_require__(2);
|
8201 |
|
8202 | class WebGLContext {
|
8203 | constructor({
|
8204 | enable = false
|
8205 | }) {
|
8206 | this._enabled = enable === true;
|
8207 | }
|
8208 |
|
8209 | get isEnabled() {
|
8210 | let enabled = this._enabled;
|
8211 |
|
8212 | if (enabled) {
|
8213 | enabled = WebGLUtils.tryInitGL();
|
8214 | }
|
8215 |
|
8216 | return (0, _util.shadow)(this, "isEnabled", enabled);
|
8217 | }
|
8218 |
|
8219 | composeSMask({
|
8220 | layer,
|
8221 | mask,
|
8222 | properties
|
8223 | }) {
|
8224 | return WebGLUtils.composeSMask(layer, mask, properties);
|
8225 | }
|
8226 |
|
8227 | drawFigures({
|
8228 | width,
|
8229 | height,
|
8230 | backgroundColor,
|
8231 | figures,
|
8232 | context
|
8233 | }) {
|
8234 | return WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
|
8235 | }
|
8236 |
|
8237 | clear() {
|
8238 | WebGLUtils.cleanup();
|
8239 | }
|
8240 |
|
8241 | }
|
8242 |
|
8243 | exports.WebGLContext = WebGLContext;
|
8244 |
|
8245 | var WebGLUtils = function WebGLUtilsClosure() {
|
8246 | function loadShader(gl, code, shaderType) {
|
8247 | var shader = gl.createShader(shaderType);
|
8248 | gl.shaderSource(shader, code);
|
8249 | gl.compileShader(shader);
|
8250 | var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
8251 |
|
8252 | if (!compiled) {
|
8253 | var errorMsg = gl.getShaderInfoLog(shader);
|
8254 | throw new Error("Error during shader compilation: " + errorMsg);
|
8255 | }
|
8256 |
|
8257 | return shader;
|
8258 | }
|
8259 |
|
8260 | function createVertexShader(gl, code) {
|
8261 | return loadShader(gl, code, gl.VERTEX_SHADER);
|
8262 | }
|
8263 |
|
8264 | function createFragmentShader(gl, code) {
|
8265 | return loadShader(gl, code, gl.FRAGMENT_SHADER);
|
8266 | }
|
8267 |
|
8268 | function createProgram(gl, shaders) {
|
8269 | var program = gl.createProgram();
|
8270 |
|
8271 | for (var i = 0, ii = shaders.length; i < ii; ++i) {
|
8272 | gl.attachShader(program, shaders[i]);
|
8273 | }
|
8274 |
|
8275 | gl.linkProgram(program);
|
8276 | var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
|
8277 |
|
8278 | if (!linked) {
|
8279 | var errorMsg = gl.getProgramInfoLog(program);
|
8280 | throw new Error("Error during program linking: " + errorMsg);
|
8281 | }
|
8282 |
|
8283 | return program;
|
8284 | }
|
8285 |
|
8286 | function createTexture(gl, image, textureId) {
|
8287 | gl.activeTexture(textureId);
|
8288 | var texture = gl.createTexture();
|
8289 | gl.bindTexture(gl.TEXTURE_2D, texture);
|
8290 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
8291 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
8292 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
8293 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
8294 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
8295 | return texture;
|
8296 | }
|
8297 |
|
8298 | var currentGL, currentCanvas;
|
8299 |
|
8300 | function generateGL() {
|
8301 | if (currentGL) {
|
8302 | return;
|
8303 | }
|
8304 |
|
8305 | currentCanvas = document.createElement("canvas");
|
8306 | currentGL = currentCanvas.getContext("webgl", {
|
8307 | premultipliedalpha: false
|
8308 | });
|
8309 | }
|
8310 |
|
8311 | var smaskVertexShaderCode = "\
|
8312 | attribute vec2 a_position; \
|
8313 | attribute vec2 a_texCoord; \
|
8314 | \
|
8315 | uniform vec2 u_resolution; \
|
8316 | \
|
8317 | varying vec2 v_texCoord; \
|
8318 | \
|
8319 | void main() { \
|
8320 | vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
|
8321 | gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
|
8322 | \
|
8323 | v_texCoord = a_texCoord; \
|
8324 | } ";
|
8325 | var smaskFragmentShaderCode = "\
|
8326 | precision mediump float; \
|
8327 | \
|
8328 | uniform vec4 u_backdrop; \
|
8329 | uniform int u_subtype; \
|
8330 | uniform sampler2D u_image; \
|
8331 | uniform sampler2D u_mask; \
|
8332 | \
|
8333 | varying vec2 v_texCoord; \
|
8334 | \
|
8335 | void main() { \
|
8336 | vec4 imageColor = texture2D(u_image, v_texCoord); \
|
8337 | vec4 maskColor = texture2D(u_mask, v_texCoord); \
|
8338 | if (u_backdrop.a > 0.0) { \
|
8339 | maskColor.rgb = maskColor.rgb * maskColor.a + \
|
8340 | u_backdrop.rgb * (1.0 - maskColor.a); \
|
8341 | } \
|
8342 | float lum; \
|
8343 | if (u_subtype == 0) { \
|
8344 | lum = maskColor.a; \
|
8345 | } else { \
|
8346 | lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
|
8347 | maskColor.b * 0.11; \
|
8348 | } \
|
8349 | imageColor.a *= lum; \
|
8350 | imageColor.rgb *= imageColor.a; \
|
8351 | gl_FragColor = imageColor; \
|
8352 | } ";
|
8353 | var smaskCache = null;
|
8354 |
|
8355 | function initSmaskGL() {
|
8356 | var canvas, gl;
|
8357 | generateGL();
|
8358 | canvas = currentCanvas;
|
8359 | currentCanvas = null;
|
8360 | gl = currentGL;
|
8361 | currentGL = null;
|
8362 | var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
|
8363 | var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
|
8364 | var program = createProgram(gl, [vertexShader, fragmentShader]);
|
8365 | gl.useProgram(program);
|
8366 | var cache = {};
|
8367 | cache.gl = gl;
|
8368 | cache.canvas = canvas;
|
8369 | cache.resolutionLocation = gl.getUniformLocation(program, "u_resolution");
|
8370 | cache.positionLocation = gl.getAttribLocation(program, "a_position");
|
8371 | cache.backdropLocation = gl.getUniformLocation(program, "u_backdrop");
|
8372 | cache.subtypeLocation = gl.getUniformLocation(program, "u_subtype");
|
8373 | var texCoordLocation = gl.getAttribLocation(program, "a_texCoord");
|
8374 | var texLayerLocation = gl.getUniformLocation(program, "u_image");
|
8375 | var texMaskLocation = gl.getUniformLocation(program, "u_mask");
|
8376 | var texCoordBuffer = gl.createBuffer();
|
8377 | gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
|
8378 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW);
|
8379 | gl.enableVertexAttribArray(texCoordLocation);
|
8380 | gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
|
8381 | gl.uniform1i(texLayerLocation, 0);
|
8382 | gl.uniform1i(texMaskLocation, 1);
|
8383 | smaskCache = cache;
|
8384 | }
|
8385 |
|
8386 | function composeSMask(layer, mask, properties) {
|
8387 | var width = layer.width,
|
8388 | height = layer.height;
|
8389 |
|
8390 | if (!smaskCache) {
|
8391 | initSmaskGL();
|
8392 | }
|
8393 |
|
8394 | var cache = smaskCache,
|
8395 | canvas = cache.canvas,
|
8396 | gl = cache.gl;
|
8397 | canvas.width = width;
|
8398 | canvas.height = height;
|
8399 | gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
|
8400 | gl.uniform2f(cache.resolutionLocation, width, height);
|
8401 |
|
8402 | if (properties.backdrop) {
|
8403 | gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
|
8404 | } else {
|
8405 | gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
|
8406 | }
|
8407 |
|
8408 | gl.uniform1i(cache.subtypeLocation, properties.subtype === "Luminosity" ? 1 : 0);
|
8409 | var texture = createTexture(gl, layer, gl.TEXTURE0);
|
8410 | var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
|
8411 | var buffer = gl.createBuffer();
|
8412 | gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
8413 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, width, 0, 0, height, 0, height, width, 0, width, height]), gl.STATIC_DRAW);
|
8414 | gl.enableVertexAttribArray(cache.positionLocation);
|
8415 | gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
|
8416 | gl.clearColor(0, 0, 0, 0);
|
8417 | gl.enable(gl.BLEND);
|
8418 | gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
8419 | gl.clear(gl.COLOR_BUFFER_BIT);
|
8420 | gl.drawArrays(gl.TRIANGLES, 0, 6);
|
8421 | gl.flush();
|
8422 | gl.deleteTexture(texture);
|
8423 | gl.deleteTexture(maskTexture);
|
8424 | gl.deleteBuffer(buffer);
|
8425 | return canvas;
|
8426 | }
|
8427 |
|
8428 | var figuresVertexShaderCode = "\
|
8429 | attribute vec2 a_position; \
|
8430 | attribute vec3 a_color; \
|
8431 | \
|
8432 | uniform vec2 u_resolution; \
|
8433 | uniform vec2 u_scale; \
|
8434 | uniform vec2 u_offset; \
|
8435 | \
|
8436 | varying vec4 v_color; \
|
8437 | \
|
8438 | void main() { \
|
8439 | vec2 position = (a_position + u_offset) * u_scale; \
|
8440 | vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
|
8441 | gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
|
8442 | \
|
8443 | v_color = vec4(a_color / 255.0, 1.0); \
|
8444 | } ";
|
8445 | var figuresFragmentShaderCode = "\
|
8446 | precision mediump float; \
|
8447 | \
|
8448 | varying vec4 v_color; \
|
8449 | \
|
8450 | void main() { \
|
8451 | gl_FragColor = v_color; \
|
8452 | } ";
|
8453 | var figuresCache = null;
|
8454 |
|
8455 | function initFiguresGL() {
|
8456 | var canvas, gl;
|
8457 | generateGL();
|
8458 | canvas = currentCanvas;
|
8459 | currentCanvas = null;
|
8460 | gl = currentGL;
|
8461 | currentGL = null;
|
8462 | var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
|
8463 | var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
|
8464 | var program = createProgram(gl, [vertexShader, fragmentShader]);
|
8465 | gl.useProgram(program);
|
8466 | var cache = {};
|
8467 | cache.gl = gl;
|
8468 | cache.canvas = canvas;
|
8469 | cache.resolutionLocation = gl.getUniformLocation(program, "u_resolution");
|
8470 | cache.scaleLocation = gl.getUniformLocation(program, "u_scale");
|
8471 | cache.offsetLocation = gl.getUniformLocation(program, "u_offset");
|
8472 | cache.positionLocation = gl.getAttribLocation(program, "a_position");
|
8473 | cache.colorLocation = gl.getAttribLocation(program, "a_color");
|
8474 | figuresCache = cache;
|
8475 | }
|
8476 |
|
8477 | function drawFigures(width, height, backgroundColor, figures, context) {
|
8478 | if (!figuresCache) {
|
8479 | initFiguresGL();
|
8480 | }
|
8481 |
|
8482 | var cache = figuresCache,
|
8483 | canvas = cache.canvas,
|
8484 | gl = cache.gl;
|
8485 | canvas.width = width;
|
8486 | canvas.height = height;
|
8487 | gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
|
8488 | gl.uniform2f(cache.resolutionLocation, width, height);
|
8489 | var count = 0;
|
8490 | var i, ii, rows;
|
8491 |
|
8492 | for (i = 0, ii = figures.length; i < ii; i++) {
|
8493 | switch (figures[i].type) {
|
8494 | case "lattice":
|
8495 | rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
|
8496 | count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
|
8497 | break;
|
8498 |
|
8499 | case "triangles":
|
8500 | count += figures[i].coords.length;
|
8501 | break;
|
8502 | }
|
8503 | }
|
8504 |
|
8505 | var coords = new Float32Array(count * 2);
|
8506 | var colors = new Uint8Array(count * 3);
|
8507 | var coordsMap = context.coords,
|
8508 | colorsMap = context.colors;
|
8509 | var pIndex = 0,
|
8510 | cIndex = 0;
|
8511 |
|
8512 | for (i = 0, ii = figures.length; i < ii; i++) {
|
8513 | var figure = figures[i],
|
8514 | ps = figure.coords,
|
8515 | cs = figure.colors;
|
8516 |
|
8517 | switch (figure.type) {
|
8518 | case "lattice":
|
8519 | var cols = figure.verticesPerRow;
|
8520 | rows = ps.length / cols | 0;
|
8521 |
|
8522 | for (var row = 1; row < rows; row++) {
|
8523 | var offset = row * cols + 1;
|
8524 |
|
8525 | for (var col = 1; col < cols; col++, offset++) {
|
8526 | coords[pIndex] = coordsMap[ps[offset - cols - 1]];
|
8527 | coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
|
8528 | coords[pIndex + 2] = coordsMap[ps[offset - cols]];
|
8529 | coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
|
8530 | coords[pIndex + 4] = coordsMap[ps[offset - 1]];
|
8531 | coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
|
8532 | colors[cIndex] = colorsMap[cs[offset - cols - 1]];
|
8533 | colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
|
8534 | colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
|
8535 | colors[cIndex + 3] = colorsMap[cs[offset - cols]];
|
8536 | colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
|
8537 | colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
|
8538 | colors[cIndex + 6] = colorsMap[cs[offset - 1]];
|
8539 | colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
|
8540 | colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
|
8541 | coords[pIndex + 6] = coords[pIndex + 2];
|
8542 | coords[pIndex + 7] = coords[pIndex + 3];
|
8543 | coords[pIndex + 8] = coords[pIndex + 4];
|
8544 | coords[pIndex + 9] = coords[pIndex + 5];
|
8545 | coords[pIndex + 10] = coordsMap[ps[offset]];
|
8546 | coords[pIndex + 11] = coordsMap[ps[offset] + 1];
|
8547 | colors[cIndex + 9] = colors[cIndex + 3];
|
8548 | colors[cIndex + 10] = colors[cIndex + 4];
|
8549 | colors[cIndex + 11] = colors[cIndex + 5];
|
8550 | colors[cIndex + 12] = colors[cIndex + 6];
|
8551 | colors[cIndex + 13] = colors[cIndex + 7];
|
8552 | colors[cIndex + 14] = colors[cIndex + 8];
|
8553 | colors[cIndex + 15] = colorsMap[cs[offset]];
|
8554 | colors[cIndex + 16] = colorsMap[cs[offset] + 1];
|
8555 | colors[cIndex + 17] = colorsMap[cs[offset] + 2];
|
8556 | pIndex += 12;
|
8557 | cIndex += 18;
|
8558 | }
|
8559 | }
|
8560 |
|
8561 | break;
|
8562 |
|
8563 | case "triangles":
|
8564 | for (var j = 0, jj = ps.length; j < jj; j++) {
|
8565 | coords[pIndex] = coordsMap[ps[j]];
|
8566 | coords[pIndex + 1] = coordsMap[ps[j] + 1];
|
8567 | colors[cIndex] = colorsMap[cs[j]];
|
8568 | colors[cIndex + 1] = colorsMap[cs[j] + 1];
|
8569 | colors[cIndex + 2] = colorsMap[cs[j] + 2];
|
8570 | pIndex += 2;
|
8571 | cIndex += 3;
|
8572 | }
|
8573 |
|
8574 | break;
|
8575 | }
|
8576 | }
|
8577 |
|
8578 | if (backgroundColor) {
|
8579 | gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
|
8580 | } else {
|
8581 | gl.clearColor(0, 0, 0, 0);
|
8582 | }
|
8583 |
|
8584 | gl.clear(gl.COLOR_BUFFER_BIT);
|
8585 | var coordsBuffer = gl.createBuffer();
|
8586 | gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
|
8587 | gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
|
8588 | gl.enableVertexAttribArray(cache.positionLocation);
|
8589 | gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
|
8590 | var colorsBuffer = gl.createBuffer();
|
8591 | gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
|
8592 | gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
|
8593 | gl.enableVertexAttribArray(cache.colorLocation);
|
8594 | gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0);
|
8595 | gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
|
8596 | gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
|
8597 | gl.drawArrays(gl.TRIANGLES, 0, count);
|
8598 | gl.flush();
|
8599 | gl.deleteBuffer(coordsBuffer);
|
8600 | gl.deleteBuffer(colorsBuffer);
|
8601 | return canvas;
|
8602 | }
|
8603 |
|
8604 | return {
|
8605 | tryInitGL() {
|
8606 | try {
|
8607 | generateGL();
|
8608 | return !!currentGL;
|
8609 | } catch (ex) {}
|
8610 |
|
8611 | return false;
|
8612 | },
|
8613 |
|
8614 | composeSMask,
|
8615 | drawFigures,
|
8616 |
|
8617 | cleanup() {
|
8618 | if (smaskCache && smaskCache.canvas) {
|
8619 | smaskCache.canvas.width = 0;
|
8620 | smaskCache.canvas.height = 0;
|
8621 | }
|
8622 |
|
8623 | if (figuresCache && figuresCache.canvas) {
|
8624 | figuresCache.canvas.width = 0;
|
8625 | figuresCache.canvas.height = 0;
|
8626 | }
|
8627 |
|
8628 | smaskCache = null;
|
8629 | figuresCache = null;
|
8630 | }
|
8631 |
|
8632 | };
|
8633 | }();
|
8634 |
|
8635 | }),
|
8636 |
|
8637 | (function(module, exports, __w_pdfjs_require__) {
|
8638 |
|
8639 | "use strict";
|
8640 |
|
8641 |
|
8642 | Object.defineProperty(exports, "__esModule", {
|
8643 | value: true
|
8644 | });
|
8645 | exports.AnnotationLayer = void 0;
|
8646 |
|
8647 | var _display_utils = __w_pdfjs_require__(1);
|
8648 |
|
8649 | var _util = __w_pdfjs_require__(2);
|
8650 |
|
8651 | class AnnotationElementFactory {
|
8652 | static create(parameters) {
|
8653 | const subtype = parameters.data.annotationType;
|
8654 |
|
8655 | switch (subtype) {
|
8656 | case _util.AnnotationType.LINK:
|
8657 | return new LinkAnnotationElement(parameters);
|
8658 |
|
8659 | case _util.AnnotationType.TEXT:
|
8660 | return new TextAnnotationElement(parameters);
|
8661 |
|
8662 | case _util.AnnotationType.WIDGET:
|
8663 | const fieldType = parameters.data.fieldType;
|
8664 |
|
8665 | switch (fieldType) {
|
8666 | case "Tx":
|
8667 | return new TextWidgetAnnotationElement(parameters);
|
8668 |
|
8669 | case "Btn":
|
8670 | if (parameters.data.radioButton) {
|
8671 | return new RadioButtonWidgetAnnotationElement(parameters);
|
8672 | } else if (parameters.data.checkBox) {
|
8673 | return new CheckboxWidgetAnnotationElement(parameters);
|
8674 | }
|
8675 |
|
8676 | return new PushButtonWidgetAnnotationElement(parameters);
|
8677 |
|
8678 | case "Ch":
|
8679 | return new ChoiceWidgetAnnotationElement(parameters);
|
8680 | }
|
8681 |
|
8682 | return new WidgetAnnotationElement(parameters);
|
8683 |
|
8684 | case _util.AnnotationType.POPUP:
|
8685 | return new PopupAnnotationElement(parameters);
|
8686 |
|
8687 | case _util.AnnotationType.FREETEXT:
|
8688 | return new FreeTextAnnotationElement(parameters);
|
8689 |
|
8690 | case _util.AnnotationType.LINE:
|
8691 | return new LineAnnotationElement(parameters);
|
8692 |
|
8693 | case _util.AnnotationType.SQUARE:
|
8694 | return new SquareAnnotationElement(parameters);
|
8695 |
|
8696 | case _util.AnnotationType.CIRCLE:
|
8697 | return new CircleAnnotationElement(parameters);
|
8698 |
|
8699 | case _util.AnnotationType.POLYLINE:
|
8700 | return new PolylineAnnotationElement(parameters);
|
8701 |
|
8702 | case _util.AnnotationType.CARET:
|
8703 | return new CaretAnnotationElement(parameters);
|
8704 |
|
8705 | case _util.AnnotationType.INK:
|
8706 | return new InkAnnotationElement(parameters);
|
8707 |
|
8708 | case _util.AnnotationType.POLYGON:
|
8709 | return new PolygonAnnotationElement(parameters);
|
8710 |
|
8711 | case _util.AnnotationType.HIGHLIGHT:
|
8712 | return new HighlightAnnotationElement(parameters);
|
8713 |
|
8714 | case _util.AnnotationType.UNDERLINE:
|
8715 | return new UnderlineAnnotationElement(parameters);
|
8716 |
|
8717 | case _util.AnnotationType.SQUIGGLY:
|
8718 | return new SquigglyAnnotationElement(parameters);
|
8719 |
|
8720 | case _util.AnnotationType.STRIKEOUT:
|
8721 | return new StrikeOutAnnotationElement(parameters);
|
8722 |
|
8723 | case _util.AnnotationType.STAMP:
|
8724 | return new StampAnnotationElement(parameters);
|
8725 |
|
8726 | case _util.AnnotationType.FILEATTACHMENT:
|
8727 | return new FileAttachmentAnnotationElement(parameters);
|
8728 |
|
8729 | default:
|
8730 | return new AnnotationElement(parameters);
|
8731 | }
|
8732 | }
|
8733 |
|
8734 | }
|
8735 |
|
8736 | class AnnotationElement {
|
8737 | constructor(parameters, isRenderable = false, ignoreBorder = false) {
|
8738 | this.isRenderable = isRenderable;
|
8739 | this.data = parameters.data;
|
8740 | this.layer = parameters.layer;
|
8741 | this.page = parameters.page;
|
8742 | this.viewport = parameters.viewport;
|
8743 | this.linkService = parameters.linkService;
|
8744 | this.downloadManager = parameters.downloadManager;
|
8745 | this.imageResourcesPath = parameters.imageResourcesPath;
|
8746 | this.renderInteractiveForms = parameters.renderInteractiveForms;
|
8747 | this.svgFactory = parameters.svgFactory;
|
8748 |
|
8749 | if (isRenderable) {
|
8750 | this.container = this._createContainer(ignoreBorder);
|
8751 | }
|
8752 | }
|
8753 |
|
8754 | _createContainer(ignoreBorder = false) {
|
8755 | const data = this.data,
|
8756 | page = this.page,
|
8757 | viewport = this.viewport;
|
8758 | const container = document.createElement("section");
|
8759 | let width = data.rect[2] - data.rect[0];
|
8760 | let height = data.rect[3] - data.rect[1];
|
8761 | container.setAttribute("data-annotation-id", data.id);
|
8762 |
|
8763 | const rect = _util.Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]);
|
8764 |
|
8765 | container.style.transform = `matrix(${viewport.transform.join(",")})`;
|
8766 | container.style.transformOrigin = `-${rect[0]}px -${rect[1]}px`;
|
8767 |
|
8768 | if (!ignoreBorder && data.borderStyle.width > 0) {
|
8769 | container.style.borderWidth = `${data.borderStyle.width}px`;
|
8770 |
|
8771 | if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
|
8772 | width = width - 2 * data.borderStyle.width;
|
8773 | height = height - 2 * data.borderStyle.width;
|
8774 | }
|
8775 |
|
8776 | const horizontalRadius = data.borderStyle.horizontalCornerRadius;
|
8777 | const verticalRadius = data.borderStyle.verticalCornerRadius;
|
8778 |
|
8779 | if (horizontalRadius > 0 || verticalRadius > 0) {
|
8780 | const radius = `${horizontalRadius}px / ${verticalRadius}px`;
|
8781 | container.style.borderRadius = radius;
|
8782 | }
|
8783 |
|
8784 | switch (data.borderStyle.style) {
|
8785 | case _util.AnnotationBorderStyleType.SOLID:
|
8786 | container.style.borderStyle = "solid";
|
8787 | break;
|
8788 |
|
8789 | case _util.AnnotationBorderStyleType.DASHED:
|
8790 | container.style.borderStyle = "dashed";
|
8791 | break;
|
8792 |
|
8793 | case _util.AnnotationBorderStyleType.BEVELED:
|
8794 | (0, _util.warn)("Unimplemented border style: beveled");
|
8795 | break;
|
8796 |
|
8797 | case _util.AnnotationBorderStyleType.INSET:
|
8798 | (0, _util.warn)("Unimplemented border style: inset");
|
8799 | break;
|
8800 |
|
8801 | case _util.AnnotationBorderStyleType.UNDERLINE:
|
8802 | container.style.borderBottomStyle = "solid";
|
8803 | break;
|
8804 |
|
8805 | default:
|
8806 | break;
|
8807 | }
|
8808 |
|
8809 | if (data.color) {
|
8810 | container.style.borderColor = _util.Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
|
8811 | } else {
|
8812 | container.style.borderWidth = 0;
|
8813 | }
|
8814 | }
|
8815 |
|
8816 | container.style.left = `${rect[0]}px`;
|
8817 | container.style.top = `${rect[1]}px`;
|
8818 | container.style.width = `${width}px`;
|
8819 | container.style.height = `${height}px`;
|
8820 | return container;
|
8821 | }
|
8822 |
|
8823 | _createPopup(container, trigger, data) {
|
8824 | if (!trigger) {
|
8825 | trigger = document.createElement("div");
|
8826 | trigger.style.height = container.style.height;
|
8827 | trigger.style.width = container.style.width;
|
8828 | container.appendChild(trigger);
|
8829 | }
|
8830 |
|
8831 | const popupElement = new PopupElement({
|
8832 | container,
|
8833 | trigger,
|
8834 | color: data.color,
|
8835 | title: data.title,
|
8836 | modificationDate: data.modificationDate,
|
8837 | contents: data.contents,
|
8838 | hideWrapper: true
|
8839 | });
|
8840 | const popup = popupElement.render();
|
8841 | popup.style.left = container.style.width;
|
8842 | container.appendChild(popup);
|
8843 | }
|
8844 |
|
8845 | render() {
|
8846 | (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
|
8847 | }
|
8848 |
|
8849 | }
|
8850 |
|
8851 | class LinkAnnotationElement extends AnnotationElement {
|
8852 | constructor(parameters) {
|
8853 | const isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action);
|
8854 | super(parameters, isRenderable);
|
8855 | }
|
8856 |
|
8857 | render() {
|
8858 | this.container.className = "linkAnnotation";
|
8859 | const {
|
8860 | data,
|
8861 | linkService
|
8862 | } = this;
|
8863 | const link = document.createElement("a");
|
8864 |
|
8865 | if (data.url) {
|
8866 | (0, _display_utils.addLinkAttributes)(link, {
|
8867 | url: data.url,
|
8868 | target: data.newWindow ? _display_utils.LinkTarget.BLANK : linkService.externalLinkTarget,
|
8869 | rel: linkService.externalLinkRel,
|
8870 | enabled: linkService.externalLinkEnabled
|
8871 | });
|
8872 | } else if (data.action) {
|
8873 | this._bindNamedAction(link, data.action);
|
8874 | } else {
|
8875 | this._bindLink(link, data.dest);
|
8876 | }
|
8877 |
|
8878 | this.container.appendChild(link);
|
8879 | return this.container;
|
8880 | }
|
8881 |
|
8882 | _bindLink(link, destination) {
|
8883 | link.href = this.linkService.getDestinationHash(destination);
|
8884 |
|
8885 | link.onclick = () => {
|
8886 | if (destination) {
|
8887 | this.linkService.navigateTo(destination);
|
8888 | }
|
8889 |
|
8890 | return false;
|
8891 | };
|
8892 |
|
8893 | if (destination) {
|
8894 | link.className = "internalLink";
|
8895 | }
|
8896 | }
|
8897 |
|
8898 | _bindNamedAction(link, action) {
|
8899 | link.href = this.linkService.getAnchorUrl("");
|
8900 |
|
8901 | link.onclick = () => {
|
8902 | this.linkService.executeNamedAction(action);
|
8903 | return false;
|
8904 | };
|
8905 |
|
8906 | link.className = "internalLink";
|
8907 | }
|
8908 |
|
8909 | }
|
8910 |
|
8911 | class TextAnnotationElement extends AnnotationElement {
|
8912 | constructor(parameters) {
|
8913 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
8914 | super(parameters, isRenderable);
|
8915 | }
|
8916 |
|
8917 | render() {
|
8918 | this.container.className = "textAnnotation";
|
8919 | const image = document.createElement("img");
|
8920 | image.style.height = this.container.style.height;
|
8921 | image.style.width = this.container.style.width;
|
8922 | image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
|
8923 | image.alt = "[{{type}} Annotation]";
|
8924 | image.dataset.l10nId = "text_annotation_type";
|
8925 | image.dataset.l10nArgs = JSON.stringify({
|
8926 | type: this.data.name
|
8927 | });
|
8928 |
|
8929 | if (!this.data.hasPopup) {
|
8930 | this._createPopup(this.container, image, this.data);
|
8931 | }
|
8932 |
|
8933 | this.container.appendChild(image);
|
8934 | return this.container;
|
8935 | }
|
8936 |
|
8937 | }
|
8938 |
|
8939 | class WidgetAnnotationElement extends AnnotationElement {
|
8940 | render() {
|
8941 | return this.container;
|
8942 | }
|
8943 |
|
8944 | }
|
8945 |
|
8946 | class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
8947 | constructor(parameters) {
|
8948 | const isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
|
8949 | super(parameters, isRenderable);
|
8950 | }
|
8951 |
|
8952 | render() {
|
8953 | const TEXT_ALIGNMENT = ["left", "center", "right"];
|
8954 | this.container.className = "textWidgetAnnotation";
|
8955 | let element = null;
|
8956 |
|
8957 | if (this.renderInteractiveForms) {
|
8958 | if (this.data.multiLine) {
|
8959 | element = document.createElement("textarea");
|
8960 | element.textContent = this.data.fieldValue;
|
8961 | } else {
|
8962 | element = document.createElement("input");
|
8963 | element.type = "text";
|
8964 | element.setAttribute("value", this.data.fieldValue);
|
8965 | }
|
8966 |
|
8967 | element.disabled = this.data.readOnly;
|
8968 | element.name = this.data.fieldName;
|
8969 |
|
8970 | if (this.data.maxLen !== null) {
|
8971 | element.maxLength = this.data.maxLen;
|
8972 | }
|
8973 |
|
8974 | if (this.data.comb) {
|
8975 | const fieldWidth = this.data.rect[2] - this.data.rect[0];
|
8976 | const combWidth = fieldWidth / this.data.maxLen;
|
8977 | element.classList.add("comb");
|
8978 | element.style.letterSpacing = `calc(${combWidth}px - 1ch)`;
|
8979 | }
|
8980 | } else {
|
8981 | element = document.createElement("div");
|
8982 | element.textContent = this.data.fieldValue;
|
8983 | element.style.verticalAlign = "middle";
|
8984 | element.style.display = "table-cell";
|
8985 | let font = null;
|
8986 |
|
8987 | if (this.data.fontRefName && this.page.commonObjs.has(this.data.fontRefName)) {
|
8988 | font = this.page.commonObjs.get(this.data.fontRefName);
|
8989 | }
|
8990 |
|
8991 | this._setTextStyle(element, font);
|
8992 | }
|
8993 |
|
8994 | if (this.data.textAlignment !== null) {
|
8995 | element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
|
8996 | }
|
8997 |
|
8998 | this.container.appendChild(element);
|
8999 | return this.container;
|
9000 | }
|
9001 |
|
9002 | _setTextStyle(element, font) {
|
9003 | const style = element.style;
|
9004 | style.fontSize = `${this.data.fontSize}px`;
|
9005 | style.direction = this.data.fontDirection < 0 ? "rtl" : "ltr";
|
9006 |
|
9007 | if (!font) {
|
9008 | return;
|
9009 | }
|
9010 |
|
9011 | let bold = "normal";
|
9012 |
|
9013 | if (font.black) {
|
9014 | bold = "900";
|
9015 | } else if (font.bold) {
|
9016 | bold = "bold";
|
9017 | }
|
9018 |
|
9019 | style.fontWeight = bold;
|
9020 | style.fontStyle = font.italic ? "italic" : "normal";
|
9021 | const fontFamily = font.loadedName ? `"${font.loadedName}", ` : "";
|
9022 | const fallbackName = font.fallbackName || "Helvetica, sans-serif";
|
9023 | style.fontFamily = fontFamily + fallbackName;
|
9024 | }
|
9025 |
|
9026 | }
|
9027 |
|
9028 | class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
|
9029 | constructor(parameters) {
|
9030 | super(parameters, parameters.renderInteractiveForms);
|
9031 | }
|
9032 |
|
9033 | render() {
|
9034 | this.container.className = "buttonWidgetAnnotation checkBox";
|
9035 | const element = document.createElement("input");
|
9036 | element.disabled = this.data.readOnly;
|
9037 | element.type = "checkbox";
|
9038 | element.name = this.data.fieldName;
|
9039 |
|
9040 | if (this.data.fieldValue && this.data.fieldValue !== "Off") {
|
9041 | element.setAttribute("checked", true);
|
9042 | }
|
9043 |
|
9044 | this.container.appendChild(element);
|
9045 | return this.container;
|
9046 | }
|
9047 |
|
9048 | }
|
9049 |
|
9050 | class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
|
9051 | constructor(parameters) {
|
9052 | super(parameters, parameters.renderInteractiveForms);
|
9053 | }
|
9054 |
|
9055 | render() {
|
9056 | this.container.className = "buttonWidgetAnnotation radioButton";
|
9057 | const element = document.createElement("input");
|
9058 | element.disabled = this.data.readOnly;
|
9059 | element.type = "radio";
|
9060 | element.name = this.data.fieldName;
|
9061 |
|
9062 | if (this.data.fieldValue === this.data.buttonValue) {
|
9063 | element.setAttribute("checked", true);
|
9064 | }
|
9065 |
|
9066 | this.container.appendChild(element);
|
9067 | return this.container;
|
9068 | }
|
9069 |
|
9070 | }
|
9071 |
|
9072 | class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
|
9073 | render() {
|
9074 | const container = super.render();
|
9075 | container.className = "buttonWidgetAnnotation pushButton";
|
9076 | return container;
|
9077 | }
|
9078 |
|
9079 | }
|
9080 |
|
9081 | class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
|
9082 | constructor(parameters) {
|
9083 | super(parameters, parameters.renderInteractiveForms);
|
9084 | }
|
9085 |
|
9086 | render() {
|
9087 | this.container.className = "choiceWidgetAnnotation";
|
9088 | const selectElement = document.createElement("select");
|
9089 | selectElement.disabled = this.data.readOnly;
|
9090 | selectElement.name = this.data.fieldName;
|
9091 |
|
9092 | if (!this.data.combo) {
|
9093 | selectElement.size = this.data.options.length;
|
9094 |
|
9095 | if (this.data.multiSelect) {
|
9096 | selectElement.multiple = true;
|
9097 | }
|
9098 | }
|
9099 |
|
9100 | for (const option of this.data.options) {
|
9101 | const optionElement = document.createElement("option");
|
9102 | optionElement.textContent = option.displayValue;
|
9103 | optionElement.value = option.exportValue;
|
9104 |
|
9105 | if (this.data.fieldValue.includes(option.displayValue)) {
|
9106 | optionElement.setAttribute("selected", true);
|
9107 | }
|
9108 |
|
9109 | selectElement.appendChild(optionElement);
|
9110 | }
|
9111 |
|
9112 | this.container.appendChild(selectElement);
|
9113 | return this.container;
|
9114 | }
|
9115 |
|
9116 | }
|
9117 |
|
9118 | class PopupAnnotationElement extends AnnotationElement {
|
9119 | constructor(parameters) {
|
9120 | const isRenderable = !!(parameters.data.title || parameters.data.contents);
|
9121 | super(parameters, isRenderable);
|
9122 | }
|
9123 |
|
9124 | render() {
|
9125 | const IGNORE_TYPES = ["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"];
|
9126 | this.container.className = "popupAnnotation";
|
9127 |
|
9128 | if (IGNORE_TYPES.includes(this.data.parentType)) {
|
9129 | return this.container;
|
9130 | }
|
9131 |
|
9132 | const selector = `[data-annotation-id="${this.data.parentId}"]`;
|
9133 | const parentElement = this.layer.querySelector(selector);
|
9134 |
|
9135 | if (!parentElement) {
|
9136 | return this.container;
|
9137 | }
|
9138 |
|
9139 | const popup = new PopupElement({
|
9140 | container: this.container,
|
9141 | trigger: parentElement,
|
9142 | color: this.data.color,
|
9143 | title: this.data.title,
|
9144 | modificationDate: this.data.modificationDate,
|
9145 | contents: this.data.contents
|
9146 | });
|
9147 | const parentLeft = parseFloat(parentElement.style.left);
|
9148 | const parentWidth = parseFloat(parentElement.style.width);
|
9149 | this.container.style.transformOrigin = `-${parentLeft + parentWidth}px -${parentElement.style.top}`;
|
9150 | this.container.style.left = `${parentLeft + parentWidth}px`;
|
9151 | this.container.appendChild(popup.render());
|
9152 | return this.container;
|
9153 | }
|
9154 |
|
9155 | }
|
9156 |
|
9157 | class PopupElement {
|
9158 | constructor(parameters) {
|
9159 | this.container = parameters.container;
|
9160 | this.trigger = parameters.trigger;
|
9161 | this.color = parameters.color;
|
9162 | this.title = parameters.title;
|
9163 | this.modificationDate = parameters.modificationDate;
|
9164 | this.contents = parameters.contents;
|
9165 | this.hideWrapper = parameters.hideWrapper || false;
|
9166 | this.pinned = false;
|
9167 | }
|
9168 |
|
9169 | render() {
|
9170 | const BACKGROUND_ENLIGHT = 0.7;
|
9171 | const wrapper = document.createElement("div");
|
9172 | wrapper.className = "popupWrapper";
|
9173 | this.hideElement = this.hideWrapper ? wrapper : this.container;
|
9174 | this.hideElement.setAttribute("hidden", true);
|
9175 | const popup = document.createElement("div");
|
9176 | popup.className = "popup";
|
9177 | const color = this.color;
|
9178 |
|
9179 | if (color) {
|
9180 | const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
|
9181 | const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
|
9182 | const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
|
9183 | popup.style.backgroundColor = _util.Util.makeCssRgb(r | 0, g | 0, b | 0);
|
9184 | }
|
9185 |
|
9186 | const title = document.createElement("h1");
|
9187 | title.textContent = this.title;
|
9188 | popup.appendChild(title);
|
9189 |
|
9190 | const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
|
9191 |
|
9192 | if (dateObject) {
|
9193 | const modificationDate = document.createElement("span");
|
9194 | modificationDate.textContent = "{{date}}, {{time}}";
|
9195 | modificationDate.dataset.l10nId = "annotation_date_string";
|
9196 | modificationDate.dataset.l10nArgs = JSON.stringify({
|
9197 | date: dateObject.toLocaleDateString(),
|
9198 | time: dateObject.toLocaleTimeString()
|
9199 | });
|
9200 | popup.appendChild(modificationDate);
|
9201 | }
|
9202 |
|
9203 | const contents = this._formatContents(this.contents);
|
9204 |
|
9205 | popup.appendChild(contents);
|
9206 | this.trigger.addEventListener("click", this._toggle.bind(this));
|
9207 | this.trigger.addEventListener("mouseover", this._show.bind(this, false));
|
9208 | this.trigger.addEventListener("mouseout", this._hide.bind(this, false));
|
9209 | popup.addEventListener("click", this._hide.bind(this, true));
|
9210 | wrapper.appendChild(popup);
|
9211 | return wrapper;
|
9212 | }
|
9213 |
|
9214 | _formatContents(contents) {
|
9215 | const p = document.createElement("p");
|
9216 | const lines = contents.split(/(?:\r\n?|\n)/);
|
9217 |
|
9218 | for (let i = 0, ii = lines.length; i < ii; ++i) {
|
9219 | const line = lines[i];
|
9220 | p.appendChild(document.createTextNode(line));
|
9221 |
|
9222 | if (i < ii - 1) {
|
9223 | p.appendChild(document.createElement("br"));
|
9224 | }
|
9225 | }
|
9226 |
|
9227 | return p;
|
9228 | }
|
9229 |
|
9230 | _toggle() {
|
9231 | if (this.pinned) {
|
9232 | this._hide(true);
|
9233 | } else {
|
9234 | this._show(true);
|
9235 | }
|
9236 | }
|
9237 |
|
9238 | _show(pin = false) {
|
9239 | if (pin) {
|
9240 | this.pinned = true;
|
9241 | }
|
9242 |
|
9243 | if (this.hideElement.hasAttribute("hidden")) {
|
9244 | this.hideElement.removeAttribute("hidden");
|
9245 | this.container.style.zIndex += 1;
|
9246 | }
|
9247 | }
|
9248 |
|
9249 | _hide(unpin = true) {
|
9250 | if (unpin) {
|
9251 | this.pinned = false;
|
9252 | }
|
9253 |
|
9254 | if (!this.hideElement.hasAttribute("hidden") && !this.pinned) {
|
9255 | this.hideElement.setAttribute("hidden", true);
|
9256 | this.container.style.zIndex -= 1;
|
9257 | }
|
9258 | }
|
9259 |
|
9260 | }
|
9261 |
|
9262 | class FreeTextAnnotationElement extends AnnotationElement {
|
9263 | constructor(parameters) {
|
9264 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9265 | super(parameters, isRenderable, true);
|
9266 | }
|
9267 |
|
9268 | render() {
|
9269 | this.container.className = "freeTextAnnotation";
|
9270 |
|
9271 | if (!this.data.hasPopup) {
|
9272 | this._createPopup(this.container, null, this.data);
|
9273 | }
|
9274 |
|
9275 | return this.container;
|
9276 | }
|
9277 |
|
9278 | }
|
9279 |
|
9280 | class LineAnnotationElement extends AnnotationElement {
|
9281 | constructor(parameters) {
|
9282 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9283 | super(parameters, isRenderable, true);
|
9284 | }
|
9285 |
|
9286 | render() {
|
9287 | this.container.className = "lineAnnotation";
|
9288 | const data = this.data;
|
9289 | const width = data.rect[2] - data.rect[0];
|
9290 | const height = data.rect[3] - data.rect[1];
|
9291 | const svg = this.svgFactory.create(width, height);
|
9292 | const line = this.svgFactory.createElement("svg:line");
|
9293 | line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
|
9294 | line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
|
9295 | line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
|
9296 | line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
|
9297 | line.setAttribute("stroke-width", data.borderStyle.width || 1);
|
9298 | line.setAttribute("stroke", "transparent");
|
9299 | svg.appendChild(line);
|
9300 | this.container.append(svg);
|
9301 |
|
9302 | this._createPopup(this.container, line, data);
|
9303 |
|
9304 | return this.container;
|
9305 | }
|
9306 |
|
9307 | }
|
9308 |
|
9309 | class SquareAnnotationElement extends AnnotationElement {
|
9310 | constructor(parameters) {
|
9311 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9312 | super(parameters, isRenderable, true);
|
9313 | }
|
9314 |
|
9315 | render() {
|
9316 | this.container.className = "squareAnnotation";
|
9317 | const data = this.data;
|
9318 | const width = data.rect[2] - data.rect[0];
|
9319 | const height = data.rect[3] - data.rect[1];
|
9320 | const svg = this.svgFactory.create(width, height);
|
9321 | const borderWidth = data.borderStyle.width;
|
9322 | const square = this.svgFactory.createElement("svg:rect");
|
9323 | square.setAttribute("x", borderWidth / 2);
|
9324 | square.setAttribute("y", borderWidth / 2);
|
9325 | square.setAttribute("width", width - borderWidth);
|
9326 | square.setAttribute("height", height - borderWidth);
|
9327 | square.setAttribute("stroke-width", borderWidth || 1);
|
9328 | square.setAttribute("stroke", "transparent");
|
9329 | square.setAttribute("fill", "none");
|
9330 | svg.appendChild(square);
|
9331 | this.container.append(svg);
|
9332 |
|
9333 | this._createPopup(this.container, square, data);
|
9334 |
|
9335 | return this.container;
|
9336 | }
|
9337 |
|
9338 | }
|
9339 |
|
9340 | class CircleAnnotationElement extends AnnotationElement {
|
9341 | constructor(parameters) {
|
9342 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9343 | super(parameters, isRenderable, true);
|
9344 | }
|
9345 |
|
9346 | render() {
|
9347 | this.container.className = "circleAnnotation";
|
9348 | const data = this.data;
|
9349 | const width = data.rect[2] - data.rect[0];
|
9350 | const height = data.rect[3] - data.rect[1];
|
9351 | const svg = this.svgFactory.create(width, height);
|
9352 | const borderWidth = data.borderStyle.width;
|
9353 | const circle = this.svgFactory.createElement("svg:ellipse");
|
9354 | circle.setAttribute("cx", width / 2);
|
9355 | circle.setAttribute("cy", height / 2);
|
9356 | circle.setAttribute("rx", width / 2 - borderWidth / 2);
|
9357 | circle.setAttribute("ry", height / 2 - borderWidth / 2);
|
9358 | circle.setAttribute("stroke-width", borderWidth || 1);
|
9359 | circle.setAttribute("stroke", "transparent");
|
9360 | circle.setAttribute("fill", "none");
|
9361 | svg.appendChild(circle);
|
9362 | this.container.append(svg);
|
9363 |
|
9364 | this._createPopup(this.container, circle, data);
|
9365 |
|
9366 | return this.container;
|
9367 | }
|
9368 |
|
9369 | }
|
9370 |
|
9371 | class PolylineAnnotationElement extends AnnotationElement {
|
9372 | constructor(parameters) {
|
9373 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9374 | super(parameters, isRenderable, true);
|
9375 | this.containerClassName = "polylineAnnotation";
|
9376 | this.svgElementName = "svg:polyline";
|
9377 | }
|
9378 |
|
9379 | render() {
|
9380 | this.container.className = this.containerClassName;
|
9381 | const data = this.data;
|
9382 | const width = data.rect[2] - data.rect[0];
|
9383 | const height = data.rect[3] - data.rect[1];
|
9384 | const svg = this.svgFactory.create(width, height);
|
9385 | let points = [];
|
9386 |
|
9387 | for (const coordinate of data.vertices) {
|
9388 | const x = coordinate.x - data.rect[0];
|
9389 | const y = data.rect[3] - coordinate.y;
|
9390 | points.push(x + "," + y);
|
9391 | }
|
9392 |
|
9393 | points = points.join(" ");
|
9394 | const polyline = this.svgFactory.createElement(this.svgElementName);
|
9395 | polyline.setAttribute("points", points);
|
9396 | polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
|
9397 | polyline.setAttribute("stroke", "transparent");
|
9398 | polyline.setAttribute("fill", "none");
|
9399 | svg.appendChild(polyline);
|
9400 | this.container.append(svg);
|
9401 |
|
9402 | this._createPopup(this.container, polyline, data);
|
9403 |
|
9404 | return this.container;
|
9405 | }
|
9406 |
|
9407 | }
|
9408 |
|
9409 | class PolygonAnnotationElement extends PolylineAnnotationElement {
|
9410 | constructor(parameters) {
|
9411 | super(parameters);
|
9412 | this.containerClassName = "polygonAnnotation";
|
9413 | this.svgElementName = "svg:polygon";
|
9414 | }
|
9415 |
|
9416 | }
|
9417 |
|
9418 | class CaretAnnotationElement extends AnnotationElement {
|
9419 | constructor(parameters) {
|
9420 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9421 | super(parameters, isRenderable, true);
|
9422 | }
|
9423 |
|
9424 | render() {
|
9425 | this.container.className = "caretAnnotation";
|
9426 |
|
9427 | if (!this.data.hasPopup) {
|
9428 | this._createPopup(this.container, null, this.data);
|
9429 | }
|
9430 |
|
9431 | return this.container;
|
9432 | }
|
9433 |
|
9434 | }
|
9435 |
|
9436 | class InkAnnotationElement extends AnnotationElement {
|
9437 | constructor(parameters) {
|
9438 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9439 | super(parameters, isRenderable, true);
|
9440 | this.containerClassName = "inkAnnotation";
|
9441 | this.svgElementName = "svg:polyline";
|
9442 | }
|
9443 |
|
9444 | render() {
|
9445 | this.container.className = this.containerClassName;
|
9446 | const data = this.data;
|
9447 | const width = data.rect[2] - data.rect[0];
|
9448 | const height = data.rect[3] - data.rect[1];
|
9449 | const svg = this.svgFactory.create(width, height);
|
9450 |
|
9451 | for (const inkList of data.inkLists) {
|
9452 | let points = [];
|
9453 |
|
9454 | for (const coordinate of inkList) {
|
9455 | const x = coordinate.x - data.rect[0];
|
9456 | const y = data.rect[3] - coordinate.y;
|
9457 | points.push(`${x},${y}`);
|
9458 | }
|
9459 |
|
9460 | points = points.join(" ");
|
9461 | const polyline = this.svgFactory.createElement(this.svgElementName);
|
9462 | polyline.setAttribute("points", points);
|
9463 | polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
|
9464 | polyline.setAttribute("stroke", "transparent");
|
9465 | polyline.setAttribute("fill", "none");
|
9466 |
|
9467 | this._createPopup(this.container, polyline, data);
|
9468 |
|
9469 | svg.appendChild(polyline);
|
9470 | }
|
9471 |
|
9472 | this.container.append(svg);
|
9473 | return this.container;
|
9474 | }
|
9475 |
|
9476 | }
|
9477 |
|
9478 | class HighlightAnnotationElement extends AnnotationElement {
|
9479 | constructor(parameters) {
|
9480 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9481 | super(parameters, isRenderable, true);
|
9482 | }
|
9483 |
|
9484 | render() {
|
9485 | this.container.className = "highlightAnnotation";
|
9486 |
|
9487 | if (!this.data.hasPopup) {
|
9488 | this._createPopup(this.container, null, this.data);
|
9489 | }
|
9490 |
|
9491 | return this.container;
|
9492 | }
|
9493 |
|
9494 | }
|
9495 |
|
9496 | class UnderlineAnnotationElement extends AnnotationElement {
|
9497 | constructor(parameters) {
|
9498 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9499 | super(parameters, isRenderable, true);
|
9500 | }
|
9501 |
|
9502 | render() {
|
9503 | this.container.className = "underlineAnnotation";
|
9504 |
|
9505 | if (!this.data.hasPopup) {
|
9506 | this._createPopup(this.container, null, this.data);
|
9507 | }
|
9508 |
|
9509 | return this.container;
|
9510 | }
|
9511 |
|
9512 | }
|
9513 |
|
9514 | class SquigglyAnnotationElement extends AnnotationElement {
|
9515 | constructor(parameters) {
|
9516 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9517 | super(parameters, isRenderable, true);
|
9518 | }
|
9519 |
|
9520 | render() {
|
9521 | this.container.className = "squigglyAnnotation";
|
9522 |
|
9523 | if (!this.data.hasPopup) {
|
9524 | this._createPopup(this.container, null, this.data);
|
9525 | }
|
9526 |
|
9527 | return this.container;
|
9528 | }
|
9529 |
|
9530 | }
|
9531 |
|
9532 | class StrikeOutAnnotationElement extends AnnotationElement {
|
9533 | constructor(parameters) {
|
9534 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9535 | super(parameters, isRenderable, true);
|
9536 | }
|
9537 |
|
9538 | render() {
|
9539 | this.container.className = "strikeoutAnnotation";
|
9540 |
|
9541 | if (!this.data.hasPopup) {
|
9542 | this._createPopup(this.container, null, this.data);
|
9543 | }
|
9544 |
|
9545 | return this.container;
|
9546 | }
|
9547 |
|
9548 | }
|
9549 |
|
9550 | class StampAnnotationElement extends AnnotationElement {
|
9551 | constructor(parameters) {
|
9552 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
|
9553 | super(parameters, isRenderable, true);
|
9554 | }
|
9555 |
|
9556 | render() {
|
9557 | this.container.className = "stampAnnotation";
|
9558 |
|
9559 | if (!this.data.hasPopup) {
|
9560 | this._createPopup(this.container, null, this.data);
|
9561 | }
|
9562 |
|
9563 | return this.container;
|
9564 | }
|
9565 |
|
9566 | }
|
9567 |
|
9568 | class FileAttachmentAnnotationElement extends AnnotationElement {
|
9569 | constructor(parameters) {
|
9570 | super(parameters, true);
|
9571 | const {
|
9572 | filename,
|
9573 | content
|
9574 | } = this.data.file;
|
9575 | this.filename = (0, _display_utils.getFilenameFromUrl)(filename);
|
9576 | this.content = content;
|
9577 |
|
9578 | if (this.linkService.eventBus) {
|
9579 | this.linkService.eventBus.dispatch("fileattachmentannotation", {
|
9580 | source: this,
|
9581 | id: (0, _util.stringToPDFString)(filename),
|
9582 | filename,
|
9583 | content
|
9584 | });
|
9585 | }
|
9586 | }
|
9587 |
|
9588 | render() {
|
9589 | this.container.className = "fileAttachmentAnnotation";
|
9590 | const trigger = document.createElement("div");
|
9591 | trigger.style.height = this.container.style.height;
|
9592 | trigger.style.width = this.container.style.width;
|
9593 | trigger.addEventListener("dblclick", this._download.bind(this));
|
9594 |
|
9595 | if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
|
9596 | this._createPopup(this.container, trigger, this.data);
|
9597 | }
|
9598 |
|
9599 | this.container.appendChild(trigger);
|
9600 | return this.container;
|
9601 | }
|
9602 |
|
9603 | _download() {
|
9604 | if (!this.downloadManager) {
|
9605 | (0, _util.warn)("Download cannot be started due to unavailable download manager");
|
9606 | return;
|
9607 | }
|
9608 |
|
9609 | this.downloadManager.downloadData(this.content, this.filename, "");
|
9610 | }
|
9611 |
|
9612 | }
|
9613 |
|
9614 | class AnnotationLayer {
|
9615 | static render(parameters) {
|
9616 | const sortedAnnotations = [],
|
9617 | popupAnnotations = [];
|
9618 |
|
9619 | for (const data of parameters.annotations) {
|
9620 | if (!data) {
|
9621 | continue;
|
9622 | }
|
9623 |
|
9624 | if (data.annotationType === _util.AnnotationType.POPUP) {
|
9625 | popupAnnotations.push(data);
|
9626 | continue;
|
9627 | }
|
9628 |
|
9629 | sortedAnnotations.push(data);
|
9630 | }
|
9631 |
|
9632 | if (popupAnnotations.length) {
|
9633 | sortedAnnotations.push(...popupAnnotations);
|
9634 | }
|
9635 |
|
9636 | for (const data of sortedAnnotations) {
|
9637 | const element = AnnotationElementFactory.create({
|
9638 | data,
|
9639 | layer: parameters.div,
|
9640 | page: parameters.page,
|
9641 | viewport: parameters.viewport,
|
9642 | linkService: parameters.linkService,
|
9643 | downloadManager: parameters.downloadManager,
|
9644 | imageResourcesPath: parameters.imageResourcesPath || "",
|
9645 | renderInteractiveForms: parameters.renderInteractiveForms || false,
|
9646 | svgFactory: new _display_utils.DOMSVGFactory()
|
9647 | });
|
9648 |
|
9649 | if (element.isRenderable) {
|
9650 | parameters.div.appendChild(element.render());
|
9651 | }
|
9652 | }
|
9653 | }
|
9654 |
|
9655 | static update(parameters) {
|
9656 | for (const data of parameters.annotations) {
|
9657 | const element = parameters.div.querySelector(`[data-annotation-id="${data.id}"]`);
|
9658 |
|
9659 | if (element) {
|
9660 | element.style.transform = `matrix(${parameters.viewport.transform.join(",")})`;
|
9661 | }
|
9662 | }
|
9663 |
|
9664 | parameters.div.removeAttribute("hidden");
|
9665 | }
|
9666 |
|
9667 | }
|
9668 |
|
9669 | exports.AnnotationLayer = AnnotationLayer;
|
9670 |
|
9671 | }),
|
9672 |
|
9673 | (function(module, exports, __w_pdfjs_require__) {
|
9674 |
|
9675 | "use strict";
|
9676 |
|
9677 |
|
9678 | Object.defineProperty(exports, "__esModule", {
|
9679 | value: true
|
9680 | });
|
9681 | exports.renderTextLayer = void 0;
|
9682 |
|
9683 | var _util = __w_pdfjs_require__(2);
|
9684 |
|
9685 | var renderTextLayer = function renderTextLayerClosure() {
|
9686 | var MAX_TEXT_DIVS_TO_RENDER = 100000;
|
9687 | var NonWhitespaceRegexp = /\S/;
|
9688 |
|
9689 | function isAllWhitespace(str) {
|
9690 | return !NonWhitespaceRegexp.test(str);
|
9691 | }
|
9692 |
|
9693 | function appendText(task, geom, styles) {
|
9694 | var textDiv = document.createElement("span");
|
9695 | var textDivProperties = {
|
9696 | angle: 0,
|
9697 | canvasWidth: 0,
|
9698 | isWhitespace: false,
|
9699 | originalTransform: null,
|
9700 | paddingBottom: 0,
|
9701 | paddingLeft: 0,
|
9702 | paddingRight: 0,
|
9703 | paddingTop: 0,
|
9704 | scale: 1
|
9705 | };
|
9706 |
|
9707 | task._textDivs.push(textDiv);
|
9708 |
|
9709 | if (isAllWhitespace(geom.str)) {
|
9710 | textDivProperties.isWhitespace = true;
|
9711 |
|
9712 | task._textDivProperties.set(textDiv, textDivProperties);
|
9713 |
|
9714 | return;
|
9715 | }
|
9716 |
|
9717 | var tx = _util.Util.transform(task._viewport.transform, geom.transform);
|
9718 |
|
9719 | var angle = Math.atan2(tx[1], tx[0]);
|
9720 | var style = styles[geom.fontName];
|
9721 |
|
9722 | if (style.vertical) {
|
9723 | angle += Math.PI / 2;
|
9724 | }
|
9725 |
|
9726 | var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
|
9727 | var fontAscent = fontHeight;
|
9728 |
|
9729 | if (style.ascent) {
|
9730 | fontAscent = style.ascent * fontAscent;
|
9731 | } else if (style.descent) {
|
9732 | fontAscent = (1 + style.descent) * fontAscent;
|
9733 | }
|
9734 |
|
9735 | let left, top;
|
9736 |
|
9737 | if (angle === 0) {
|
9738 | left = tx[4];
|
9739 | top = tx[5] - fontAscent;
|
9740 | } else {
|
9741 | left = tx[4] + fontAscent * Math.sin(angle);
|
9742 | top = tx[5] - fontAscent * Math.cos(angle);
|
9743 | }
|
9744 |
|
9745 | textDiv.style.left = `${left}px`;
|
9746 | textDiv.style.top = `${top}px`;
|
9747 | textDiv.style.fontSize = `${fontHeight}px`;
|
9748 | textDiv.style.fontFamily = style.fontFamily;
|
9749 | textDiv.textContent = geom.str;
|
9750 |
|
9751 | if (task._fontInspectorEnabled) {
|
9752 | textDiv.dataset.fontName = geom.fontName;
|
9753 | }
|
9754 |
|
9755 | if (angle !== 0) {
|
9756 | textDivProperties.angle = angle * (180 / Math.PI);
|
9757 | }
|
9758 |
|
9759 | let shouldScaleText = false;
|
9760 |
|
9761 | if (geom.str.length > 1) {
|
9762 | shouldScaleText = true;
|
9763 | } else if (geom.transform[0] !== geom.transform[3]) {
|
9764 | const absScaleX = Math.abs(geom.transform[0]),
|
9765 | absScaleY = Math.abs(geom.transform[3]);
|
9766 |
|
9767 | if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
|
9768 | shouldScaleText = true;
|
9769 | }
|
9770 | }
|
9771 |
|
9772 | if (shouldScaleText) {
|
9773 | if (style.vertical) {
|
9774 | textDivProperties.canvasWidth = geom.height * task._viewport.scale;
|
9775 | } else {
|
9776 | textDivProperties.canvasWidth = geom.width * task._viewport.scale;
|
9777 | }
|
9778 | }
|
9779 |
|
9780 | task._textDivProperties.set(textDiv, textDivProperties);
|
9781 |
|
9782 | if (task._textContentStream) {
|
9783 | task._layoutText(textDiv);
|
9784 | }
|
9785 |
|
9786 | if (task._enhanceTextSelection) {
|
9787 | var angleCos = 1,
|
9788 | angleSin = 0;
|
9789 |
|
9790 | if (angle !== 0) {
|
9791 | angleCos = Math.cos(angle);
|
9792 | angleSin = Math.sin(angle);
|
9793 | }
|
9794 |
|
9795 | var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
|
9796 | var divHeight = fontHeight;
|
9797 | var m, b;
|
9798 |
|
9799 | if (angle !== 0) {
|
9800 | m = [angleCos, angleSin, -angleSin, angleCos, left, top];
|
9801 | b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
|
9802 | } else {
|
9803 | b = [left, top, left + divWidth, top + divHeight];
|
9804 | }
|
9805 |
|
9806 | task._bounds.push({
|
9807 | left: b[0],
|
9808 | top: b[1],
|
9809 | right: b[2],
|
9810 | bottom: b[3],
|
9811 | div: textDiv,
|
9812 | size: [divWidth, divHeight],
|
9813 | m
|
9814 | });
|
9815 | }
|
9816 | }
|
9817 |
|
9818 | function render(task) {
|
9819 | if (task._canceled) {
|
9820 | return;
|
9821 | }
|
9822 |
|
9823 | var textDivs = task._textDivs;
|
9824 | var capability = task._capability;
|
9825 | var textDivsLength = textDivs.length;
|
9826 |
|
9827 | if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
|
9828 | task._renderingDone = true;
|
9829 | capability.resolve();
|
9830 | return;
|
9831 | }
|
9832 |
|
9833 | if (!task._textContentStream) {
|
9834 | for (var i = 0; i < textDivsLength; i++) {
|
9835 | task._layoutText(textDivs[i]);
|
9836 | }
|
9837 | }
|
9838 |
|
9839 | task._renderingDone = true;
|
9840 | capability.resolve();
|
9841 | }
|
9842 |
|
9843 | function findPositiveMin(ts, offset, count) {
|
9844 | let result = 0;
|
9845 |
|
9846 | for (let i = 0; i < count; i++) {
|
9847 | const t = ts[offset++];
|
9848 |
|
9849 | if (t > 0) {
|
9850 | result = result ? Math.min(t, result) : t;
|
9851 | }
|
9852 | }
|
9853 |
|
9854 | return result;
|
9855 | }
|
9856 |
|
9857 | function expand(task) {
|
9858 | var bounds = task._bounds;
|
9859 | var viewport = task._viewport;
|
9860 | var expanded = expandBounds(viewport.width, viewport.height, bounds);
|
9861 |
|
9862 | for (var i = 0; i < expanded.length; i++) {
|
9863 | var div = bounds[i].div;
|
9864 |
|
9865 | var divProperties = task._textDivProperties.get(div);
|
9866 |
|
9867 | if (divProperties.angle === 0) {
|
9868 | divProperties.paddingLeft = bounds[i].left - expanded[i].left;
|
9869 | divProperties.paddingTop = bounds[i].top - expanded[i].top;
|
9870 | divProperties.paddingRight = expanded[i].right - bounds[i].right;
|
9871 | divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
|
9872 |
|
9873 | task._textDivProperties.set(div, divProperties);
|
9874 |
|
9875 | continue;
|
9876 | }
|
9877 |
|
9878 | var e = expanded[i],
|
9879 | b = bounds[i];
|
9880 | var m = b.m,
|
9881 | c = m[0],
|
9882 | s = m[1];
|
9883 | var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
|
9884 | var ts = new Float64Array(64);
|
9885 | points.forEach(function (p, j) {
|
9886 | var t = _util.Util.applyTransform(p, m);
|
9887 |
|
9888 | ts[j + 0] = c && (e.left - t[0]) / c;
|
9889 | ts[j + 4] = s && (e.top - t[1]) / s;
|
9890 | ts[j + 8] = c && (e.right - t[0]) / c;
|
9891 | ts[j + 12] = s && (e.bottom - t[1]) / s;
|
9892 | ts[j + 16] = s && (e.left - t[0]) / -s;
|
9893 | ts[j + 20] = c && (e.top - t[1]) / c;
|
9894 | ts[j + 24] = s && (e.right - t[0]) / -s;
|
9895 | ts[j + 28] = c && (e.bottom - t[1]) / c;
|
9896 | ts[j + 32] = c && (e.left - t[0]) / -c;
|
9897 | ts[j + 36] = s && (e.top - t[1]) / -s;
|
9898 | ts[j + 40] = c && (e.right - t[0]) / -c;
|
9899 | ts[j + 44] = s && (e.bottom - t[1]) / -s;
|
9900 | ts[j + 48] = s && (e.left - t[0]) / s;
|
9901 | ts[j + 52] = c && (e.top - t[1]) / -c;
|
9902 | ts[j + 56] = s && (e.right - t[0]) / s;
|
9903 | ts[j + 60] = c && (e.bottom - t[1]) / -c;
|
9904 | });
|
9905 | var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
|
9906 | divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
|
9907 | divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
|
9908 | divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
|
9909 | divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
|
9910 |
|
9911 | task._textDivProperties.set(div, divProperties);
|
9912 | }
|
9913 | }
|
9914 |
|
9915 | function expandBounds(width, height, boxes) {
|
9916 | var bounds = boxes.map(function (box, i) {
|
9917 | return {
|
9918 | x1: box.left,
|
9919 | y1: box.top,
|
9920 | x2: box.right,
|
9921 | y2: box.bottom,
|
9922 | index: i,
|
9923 | x1New: undefined,
|
9924 | x2New: undefined
|
9925 | };
|
9926 | });
|
9927 | expandBoundsLTR(width, bounds);
|
9928 | var expanded = new Array(boxes.length);
|
9929 | bounds.forEach(function (b) {
|
9930 | var i = b.index;
|
9931 | expanded[i] = {
|
9932 | left: b.x1New,
|
9933 | top: 0,
|
9934 | right: b.x2New,
|
9935 | bottom: 0
|
9936 | };
|
9937 | });
|
9938 | boxes.map(function (box, i) {
|
9939 | var e = expanded[i],
|
9940 | b = bounds[i];
|
9941 | b.x1 = box.top;
|
9942 | b.y1 = width - e.right;
|
9943 | b.x2 = box.bottom;
|
9944 | b.y2 = width - e.left;
|
9945 | b.index = i;
|
9946 | b.x1New = undefined;
|
9947 | b.x2New = undefined;
|
9948 | });
|
9949 | expandBoundsLTR(height, bounds);
|
9950 | bounds.forEach(function (b) {
|
9951 | var i = b.index;
|
9952 | expanded[i].top = b.x1New;
|
9953 | expanded[i].bottom = b.x2New;
|
9954 | });
|
9955 | return expanded;
|
9956 | }
|
9957 |
|
9958 | function expandBoundsLTR(width, bounds) {
|
9959 | bounds.sort(function (a, b) {
|
9960 | return a.x1 - b.x1 || a.index - b.index;
|
9961 | });
|
9962 | var fakeBoundary = {
|
9963 | x1: -Infinity,
|
9964 | y1: -Infinity,
|
9965 | x2: 0,
|
9966 | y2: Infinity,
|
9967 | index: -1,
|
9968 | x1New: 0,
|
9969 | x2New: 0
|
9970 | };
|
9971 | var horizon = [{
|
9972 | start: -Infinity,
|
9973 | end: Infinity,
|
9974 | boundary: fakeBoundary
|
9975 | }];
|
9976 | bounds.forEach(function (boundary) {
|
9977 | var i = 0;
|
9978 |
|
9979 | while (i < horizon.length && horizon[i].end <= boundary.y1) {
|
9980 | i++;
|
9981 | }
|
9982 |
|
9983 | var j = horizon.length - 1;
|
9984 |
|
9985 | while (j >= 0 && horizon[j].start >= boundary.y2) {
|
9986 | j--;
|
9987 | }
|
9988 |
|
9989 | var horizonPart, affectedBoundary;
|
9990 | var q,
|
9991 | k,
|
9992 | maxXNew = -Infinity;
|
9993 |
|
9994 | for (q = i; q <= j; q++) {
|
9995 | horizonPart = horizon[q];
|
9996 | affectedBoundary = horizonPart.boundary;
|
9997 | var xNew;
|
9998 |
|
9999 | if (affectedBoundary.x2 > boundary.x1) {
|
10000 | xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
|
10001 | } else if (affectedBoundary.x2New === undefined) {
|
10002 | xNew = (affectedBoundary.x2 + boundary.x1) / 2;
|
10003 | } else {
|
10004 | xNew = affectedBoundary.x2New;
|
10005 | }
|
10006 |
|
10007 | if (xNew > maxXNew) {
|
10008 | maxXNew = xNew;
|
10009 | }
|
10010 | }
|
10011 |
|
10012 | boundary.x1New = maxXNew;
|
10013 |
|
10014 | for (q = i; q <= j; q++) {
|
10015 | horizonPart = horizon[q];
|
10016 | affectedBoundary = horizonPart.boundary;
|
10017 |
|
10018 | if (affectedBoundary.x2New === undefined) {
|
10019 | if (affectedBoundary.x2 > boundary.x1) {
|
10020 | if (affectedBoundary.index > boundary.index) {
|
10021 | affectedBoundary.x2New = affectedBoundary.x2;
|
10022 | }
|
10023 | } else {
|
10024 | affectedBoundary.x2New = maxXNew;
|
10025 | }
|
10026 | } else if (affectedBoundary.x2New > maxXNew) {
|
10027 | affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
|
10028 | }
|
10029 | }
|
10030 |
|
10031 | var changedHorizon = [],
|
10032 | lastBoundary = null;
|
10033 |
|
10034 | for (q = i; q <= j; q++) {
|
10035 | horizonPart = horizon[q];
|
10036 | affectedBoundary = horizonPart.boundary;
|
10037 | var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
|
10038 |
|
10039 | if (lastBoundary === useBoundary) {
|
10040 | changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
|
10041 | } else {
|
10042 | changedHorizon.push({
|
10043 | start: horizonPart.start,
|
10044 | end: horizonPart.end,
|
10045 | boundary: useBoundary
|
10046 | });
|
10047 | lastBoundary = useBoundary;
|
10048 | }
|
10049 | }
|
10050 |
|
10051 | if (horizon[i].start < boundary.y1) {
|
10052 | changedHorizon[0].start = boundary.y1;
|
10053 | changedHorizon.unshift({
|
10054 | start: horizon[i].start,
|
10055 | end: boundary.y1,
|
10056 | boundary: horizon[i].boundary
|
10057 | });
|
10058 | }
|
10059 |
|
10060 | if (boundary.y2 < horizon[j].end) {
|
10061 | changedHorizon[changedHorizon.length - 1].end = boundary.y2;
|
10062 | changedHorizon.push({
|
10063 | start: boundary.y2,
|
10064 | end: horizon[j].end,
|
10065 | boundary: horizon[j].boundary
|
10066 | });
|
10067 | }
|
10068 |
|
10069 | for (q = i; q <= j; q++) {
|
10070 | horizonPart = horizon[q];
|
10071 | affectedBoundary = horizonPart.boundary;
|
10072 |
|
10073 | if (affectedBoundary.x2New !== undefined) {
|
10074 | continue;
|
10075 | }
|
10076 |
|
10077 | var used = false;
|
10078 |
|
10079 | for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
|
10080 | used = horizon[k].boundary === affectedBoundary;
|
10081 | }
|
10082 |
|
10083 | for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
|
10084 | used = horizon[k].boundary === affectedBoundary;
|
10085 | }
|
10086 |
|
10087 | for (k = 0; !used && k < changedHorizon.length; k++) {
|
10088 | used = changedHorizon[k].boundary === affectedBoundary;
|
10089 | }
|
10090 |
|
10091 | if (!used) {
|
10092 | affectedBoundary.x2New = maxXNew;
|
10093 | }
|
10094 | }
|
10095 |
|
10096 | Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
|
10097 | });
|
10098 | horizon.forEach(function (horizonPart) {
|
10099 | var affectedBoundary = horizonPart.boundary;
|
10100 |
|
10101 | if (affectedBoundary.x2New === undefined) {
|
10102 | affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
|
10103 | }
|
10104 | });
|
10105 | }
|
10106 |
|
10107 | function TextLayerRenderTask({
|
10108 | textContent,
|
10109 | textContentStream,
|
10110 | container,
|
10111 | viewport,
|
10112 | textDivs,
|
10113 | textContentItemsStr,
|
10114 | enhanceTextSelection
|
10115 | }) {
|
10116 | this._textContent = textContent;
|
10117 | this._textContentStream = textContentStream;
|
10118 | this._container = container;
|
10119 | this._viewport = viewport;
|
10120 | this._textDivs = textDivs || [];
|
10121 | this._textContentItemsStr = textContentItemsStr || [];
|
10122 | this._enhanceTextSelection = !!enhanceTextSelection;
|
10123 | this._fontInspectorEnabled = !!(globalThis.FontInspector && globalThis.FontInspector.enabled);
|
10124 | this._reader = null;
|
10125 | this._layoutTextLastFontSize = null;
|
10126 | this._layoutTextLastFontFamily = null;
|
10127 | this._layoutTextCtx = null;
|
10128 | this._textDivProperties = new WeakMap();
|
10129 | this._renderingDone = false;
|
10130 | this._canceled = false;
|
10131 | this._capability = (0, _util.createPromiseCapability)();
|
10132 | this._renderTimer = null;
|
10133 | this._bounds = [];
|
10134 |
|
10135 | this._capability.promise.finally(() => {
|
10136 | if (this._layoutTextCtx) {
|
10137 | this._layoutTextCtx.canvas.width = 0;
|
10138 | this._layoutTextCtx.canvas.height = 0;
|
10139 | this._layoutTextCtx = null;
|
10140 | }
|
10141 | }).catch(() => {});
|
10142 | }
|
10143 |
|
10144 | TextLayerRenderTask.prototype = {
|
10145 | get promise() {
|
10146 | return this._capability.promise;
|
10147 | },
|
10148 |
|
10149 | cancel: function TextLayer_cancel() {
|
10150 | this._canceled = true;
|
10151 |
|
10152 | if (this._reader) {
|
10153 | this._reader.cancel(new _util.AbortException("TextLayer task cancelled."));
|
10154 |
|
10155 | this._reader = null;
|
10156 | }
|
10157 |
|
10158 | if (this._renderTimer !== null) {
|
10159 | clearTimeout(this._renderTimer);
|
10160 | this._renderTimer = null;
|
10161 | }
|
10162 |
|
10163 | this._capability.reject(new Error("TextLayer task cancelled."));
|
10164 | },
|
10165 |
|
10166 | _processItems(items, styleCache) {
|
10167 | for (let i = 0, len = items.length; i < len; i++) {
|
10168 | this._textContentItemsStr.push(items[i].str);
|
10169 |
|
10170 | appendText(this, items[i], styleCache);
|
10171 | }
|
10172 | },
|
10173 |
|
10174 | _layoutText(textDiv) {
|
10175 | const textDivProperties = this._textDivProperties.get(textDiv);
|
10176 |
|
10177 | if (textDivProperties.isWhitespace) {
|
10178 | return;
|
10179 | }
|
10180 |
|
10181 | let transform = "";
|
10182 |
|
10183 | if (textDivProperties.canvasWidth !== 0) {
|
10184 | const {
|
10185 | fontSize,
|
10186 | fontFamily
|
10187 | } = textDiv.style;
|
10188 |
|
10189 | if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
|
10190 | this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
|
10191 | this._layoutTextLastFontSize = fontSize;
|
10192 | this._layoutTextLastFontFamily = fontFamily;
|
10193 | }
|
10194 |
|
10195 | const {
|
10196 | width
|
10197 | } = this._layoutTextCtx.measureText(textDiv.textContent);
|
10198 |
|
10199 | if (width > 0) {
|
10200 | textDivProperties.scale = textDivProperties.canvasWidth / width;
|
10201 | transform = `scaleX(${textDivProperties.scale})`;
|
10202 | }
|
10203 | }
|
10204 |
|
10205 | if (textDivProperties.angle !== 0) {
|
10206 | transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
|
10207 | }
|
10208 |
|
10209 | if (transform.length > 0) {
|
10210 | if (this._enhanceTextSelection) {
|
10211 | textDivProperties.originalTransform = transform;
|
10212 | }
|
10213 |
|
10214 | textDiv.style.transform = transform;
|
10215 | }
|
10216 |
|
10217 | this._textDivProperties.set(textDiv, textDivProperties);
|
10218 |
|
10219 | this._container.appendChild(textDiv);
|
10220 | },
|
10221 |
|
10222 | _render: function TextLayer_render(timeout) {
|
10223 | const capability = (0, _util.createPromiseCapability)();
|
10224 | let styleCache = Object.create(null);
|
10225 | const canvas = document.createElement("canvas");
|
10226 | canvas.mozOpaque = true;
|
10227 | this._layoutTextCtx = canvas.getContext("2d", {
|
10228 | alpha: false
|
10229 | });
|
10230 |
|
10231 | if (this._textContent) {
|
10232 | const textItems = this._textContent.items;
|
10233 | const textStyles = this._textContent.styles;
|
10234 |
|
10235 | this._processItems(textItems, textStyles);
|
10236 |
|
10237 | capability.resolve();
|
10238 | } else if (this._textContentStream) {
|
10239 | const pump = () => {
|
10240 | this._reader.read().then(({
|
10241 | value,
|
10242 | done
|
10243 | }) => {
|
10244 | if (done) {
|
10245 | capability.resolve();
|
10246 | return;
|
10247 | }
|
10248 |
|
10249 | Object.assign(styleCache, value.styles);
|
10250 |
|
10251 | this._processItems(value.items, styleCache);
|
10252 |
|
10253 | pump();
|
10254 | }, capability.reject);
|
10255 | };
|
10256 |
|
10257 | this._reader = this._textContentStream.getReader();
|
10258 | pump();
|
10259 | } else {
|
10260 | throw new Error('Neither "textContent" nor "textContentStream"' + " parameters specified.");
|
10261 | }
|
10262 |
|
10263 | capability.promise.then(() => {
|
10264 | styleCache = null;
|
10265 |
|
10266 | if (!timeout) {
|
10267 | render(this);
|
10268 | } else {
|
10269 | this._renderTimer = setTimeout(() => {
|
10270 | render(this);
|
10271 | this._renderTimer = null;
|
10272 | }, timeout);
|
10273 | }
|
10274 | }, this._capability.reject);
|
10275 | },
|
10276 | expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
|
10277 | if (!this._enhanceTextSelection || !this._renderingDone) {
|
10278 | return;
|
10279 | }
|
10280 |
|
10281 | if (this._bounds !== null) {
|
10282 | expand(this);
|
10283 | this._bounds = null;
|
10284 | }
|
10285 |
|
10286 | const transformBuf = [],
|
10287 | paddingBuf = [];
|
10288 |
|
10289 | for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
|
10290 | const div = this._textDivs[i];
|
10291 |
|
10292 | const divProps = this._textDivProperties.get(div);
|
10293 |
|
10294 | if (divProps.isWhitespace) {
|
10295 | continue;
|
10296 | }
|
10297 |
|
10298 | if (expandDivs) {
|
10299 | transformBuf.length = 0;
|
10300 | paddingBuf.length = 0;
|
10301 |
|
10302 | if (divProps.originalTransform) {
|
10303 | transformBuf.push(divProps.originalTransform);
|
10304 | }
|
10305 |
|
10306 | if (divProps.paddingTop > 0) {
|
10307 | paddingBuf.push(`${divProps.paddingTop}px`);
|
10308 | transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
|
10309 | } else {
|
10310 | paddingBuf.push(0);
|
10311 | }
|
10312 |
|
10313 | if (divProps.paddingRight > 0) {
|
10314 | paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
|
10315 | } else {
|
10316 | paddingBuf.push(0);
|
10317 | }
|
10318 |
|
10319 | if (divProps.paddingBottom > 0) {
|
10320 | paddingBuf.push(`${divProps.paddingBottom}px`);
|
10321 | } else {
|
10322 | paddingBuf.push(0);
|
10323 | }
|
10324 |
|
10325 | if (divProps.paddingLeft > 0) {
|
10326 | paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
|
10327 | transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
|
10328 | } else {
|
10329 | paddingBuf.push(0);
|
10330 | }
|
10331 |
|
10332 | div.style.padding = paddingBuf.join(" ");
|
10333 |
|
10334 | if (transformBuf.length) {
|
10335 | div.style.transform = transformBuf.join(" ");
|
10336 | }
|
10337 | } else {
|
10338 | div.style.padding = null;
|
10339 | div.style.transform = divProps.originalTransform;
|
10340 | }
|
10341 | }
|
10342 | }
|
10343 | };
|
10344 |
|
10345 | function renderTextLayer(renderParameters) {
|
10346 | var task = new TextLayerRenderTask({
|
10347 | textContent: renderParameters.textContent,
|
10348 | textContentStream: renderParameters.textContentStream,
|
10349 | container: renderParameters.container,
|
10350 | viewport: renderParameters.viewport,
|
10351 | textDivs: renderParameters.textDivs,
|
10352 | textContentItemsStr: renderParameters.textContentItemsStr,
|
10353 | enhanceTextSelection: renderParameters.enhanceTextSelection
|
10354 | });
|
10355 |
|
10356 | task._render(renderParameters.timeout);
|
10357 |
|
10358 | return task;
|
10359 | }
|
10360 |
|
10361 | return renderTextLayer;
|
10362 | }();
|
10363 |
|
10364 | exports.renderTextLayer = renderTextLayer;
|
10365 |
|
10366 | }),
|
10367 |
|
10368 | (function(module, exports, __w_pdfjs_require__) {
|
10369 |
|
10370 | "use strict";
|
10371 |
|
10372 |
|
10373 | Object.defineProperty(exports, "__esModule", {
|
10374 | value: true
|
10375 | });
|
10376 | exports.SVGGraphics = void 0;
|
10377 |
|
10378 | var _util = __w_pdfjs_require__(2);
|
10379 |
|
10380 | var _display_utils = __w_pdfjs_require__(1);
|
10381 |
|
10382 | var _is_node = __w_pdfjs_require__(4);
|
10383 |
|
10384 | let SVGGraphics = function () {
|
10385 | throw new Error("Not implemented: SVGGraphics");
|
10386 | };
|
10387 |
|
10388 | exports.SVGGraphics = SVGGraphics;
|
10389 | {
|
10390 | const SVG_DEFAULTS = {
|
10391 | fontStyle: "normal",
|
10392 | fontWeight: "normal",
|
10393 | fillColor: "#000000"
|
10394 | };
|
10395 | const XML_NS = "http://www.w3.org/XML/1998/namespace";
|
10396 | const XLINK_NS = "http://www.w3.org/1999/xlink";
|
10397 | const LINE_CAP_STYLES = ["butt", "round", "square"];
|
10398 | const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
|
10399 |
|
10400 | const convertImgDataToPng = function () {
|
10401 | const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
10402 | const CHUNK_WRAPPER_SIZE = 12;
|
10403 | const crcTable = new Int32Array(256);
|
10404 |
|
10405 | for (let i = 0; i < 256; i++) {
|
10406 | let c = i;
|
10407 |
|
10408 | for (let h = 0; h < 8; h++) {
|
10409 | if (c & 1) {
|
10410 | c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
|
10411 | } else {
|
10412 | c = c >> 1 & 0x7fffffff;
|
10413 | }
|
10414 | }
|
10415 |
|
10416 | crcTable[i] = c;
|
10417 | }
|
10418 |
|
10419 | function crc32(data, start, end) {
|
10420 | let crc = -1;
|
10421 |
|
10422 | for (let i = start; i < end; i++) {
|
10423 | const a = (crc ^ data[i]) & 0xff;
|
10424 | const b = crcTable[a];
|
10425 | crc = crc >>> 8 ^ b;
|
10426 | }
|
10427 |
|
10428 | return crc ^ -1;
|
10429 | }
|
10430 |
|
10431 | function writePngChunk(type, body, data, offset) {
|
10432 | let p = offset;
|
10433 | const len = body.length;
|
10434 | data[p] = len >> 24 & 0xff;
|
10435 | data[p + 1] = len >> 16 & 0xff;
|
10436 | data[p + 2] = len >> 8 & 0xff;
|
10437 | data[p + 3] = len & 0xff;
|
10438 | p += 4;
|
10439 | data[p] = type.charCodeAt(0) & 0xff;
|
10440 | data[p + 1] = type.charCodeAt(1) & 0xff;
|
10441 | data[p + 2] = type.charCodeAt(2) & 0xff;
|
10442 | data[p + 3] = type.charCodeAt(3) & 0xff;
|
10443 | p += 4;
|
10444 | data.set(body, p);
|
10445 | p += body.length;
|
10446 | const crc = crc32(data, offset + 4, p);
|
10447 | data[p] = crc >> 24 & 0xff;
|
10448 | data[p + 1] = crc >> 16 & 0xff;
|
10449 | data[p + 2] = crc >> 8 & 0xff;
|
10450 | data[p + 3] = crc & 0xff;
|
10451 | }
|
10452 |
|
10453 | function adler32(data, start, end) {
|
10454 | let a = 1;
|
10455 | let b = 0;
|
10456 |
|
10457 | for (let i = start; i < end; ++i) {
|
10458 | a = (a + (data[i] & 0xff)) % 65521;
|
10459 | b = (b + a) % 65521;
|
10460 | }
|
10461 |
|
10462 | return b << 16 | a;
|
10463 | }
|
10464 |
|
10465 | function deflateSync(literals) {
|
10466 | if (!_is_node.isNodeJS) {
|
10467 | return deflateSyncUncompressed(literals);
|
10468 | }
|
10469 |
|
10470 | try {
|
10471 | let input;
|
10472 |
|
10473 | if (parseInt(process.versions.node) >= 8) {
|
10474 | input = literals;
|
10475 | } else {
|
10476 | input = Buffer.from(literals);
|
10477 | }
|
10478 |
|
10479 | const output = require("zlib").deflateSync(input, {
|
10480 | level: 9
|
10481 | });
|
10482 |
|
10483 | return output instanceof Uint8Array ? output : new Uint8Array(output);
|
10484 | } catch (e) {
|
10485 | (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
|
10486 | }
|
10487 |
|
10488 | return deflateSyncUncompressed(literals);
|
10489 | }
|
10490 |
|
10491 | function deflateSyncUncompressed(literals) {
|
10492 | let len = literals.length;
|
10493 | const maxBlockLength = 0xffff;
|
10494 | const deflateBlocks = Math.ceil(len / maxBlockLength);
|
10495 | const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
|
10496 | let pi = 0;
|
10497 | idat[pi++] = 0x78;
|
10498 | idat[pi++] = 0x9c;
|
10499 | let pos = 0;
|
10500 |
|
10501 | while (len > maxBlockLength) {
|
10502 | idat[pi++] = 0x00;
|
10503 | idat[pi++] = 0xff;
|
10504 | idat[pi++] = 0xff;
|
10505 | idat[pi++] = 0x00;
|
10506 | idat[pi++] = 0x00;
|
10507 | idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
|
10508 | pi += maxBlockLength;
|
10509 | pos += maxBlockLength;
|
10510 | len -= maxBlockLength;
|
10511 | }
|
10512 |
|
10513 | idat[pi++] = 0x01;
|
10514 | idat[pi++] = len & 0xff;
|
10515 | idat[pi++] = len >> 8 & 0xff;
|
10516 | idat[pi++] = ~len & 0xffff & 0xff;
|
10517 | idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
|
10518 | idat.set(literals.subarray(pos), pi);
|
10519 | pi += literals.length - pos;
|
10520 | const adler = adler32(literals, 0, literals.length);
|
10521 | idat[pi++] = adler >> 24 & 0xff;
|
10522 | idat[pi++] = adler >> 16 & 0xff;
|
10523 | idat[pi++] = adler >> 8 & 0xff;
|
10524 | idat[pi++] = adler & 0xff;
|
10525 | return idat;
|
10526 | }
|
10527 |
|
10528 | function encode(imgData, kind, forceDataSchema, isMask) {
|
10529 | const width = imgData.width;
|
10530 | const height = imgData.height;
|
10531 | let bitDepth, colorType, lineSize;
|
10532 | const bytes = imgData.data;
|
10533 |
|
10534 | switch (kind) {
|
10535 | case _util.ImageKind.GRAYSCALE_1BPP:
|
10536 | colorType = 0;
|
10537 | bitDepth = 1;
|
10538 | lineSize = width + 7 >> 3;
|
10539 | break;
|
10540 |
|
10541 | case _util.ImageKind.RGB_24BPP:
|
10542 | colorType = 2;
|
10543 | bitDepth = 8;
|
10544 | lineSize = width * 3;
|
10545 | break;
|
10546 |
|
10547 | case _util.ImageKind.RGBA_32BPP:
|
10548 | colorType = 6;
|
10549 | bitDepth = 8;
|
10550 | lineSize = width * 4;
|
10551 | break;
|
10552 |
|
10553 | default:
|
10554 | throw new Error("invalid format");
|
10555 | }
|
10556 |
|
10557 | const literals = new Uint8Array((1 + lineSize) * height);
|
10558 | let offsetLiterals = 0,
|
10559 | offsetBytes = 0;
|
10560 |
|
10561 | for (let y = 0; y < height; ++y) {
|
10562 | literals[offsetLiterals++] = 0;
|
10563 | literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
|
10564 | offsetBytes += lineSize;
|
10565 | offsetLiterals += lineSize;
|
10566 | }
|
10567 |
|
10568 | if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
|
10569 | offsetLiterals = 0;
|
10570 |
|
10571 | for (let y = 0; y < height; y++) {
|
10572 | offsetLiterals++;
|
10573 |
|
10574 | for (let i = 0; i < lineSize; i++) {
|
10575 | literals[offsetLiterals++] ^= 0xff;
|
10576 | }
|
10577 | }
|
10578 | }
|
10579 |
|
10580 | 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]);
|
10581 | const idat = deflateSync(literals);
|
10582 | const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
|
10583 | const data = new Uint8Array(pngLength);
|
10584 | let offset = 0;
|
10585 | data.set(PNG_HEADER, offset);
|
10586 | offset += PNG_HEADER.length;
|
10587 | writePngChunk("IHDR", ihdr, data, offset);
|
10588 | offset += CHUNK_WRAPPER_SIZE + ihdr.length;
|
10589 | writePngChunk("IDATA", idat, data, offset);
|
10590 | offset += CHUNK_WRAPPER_SIZE + idat.length;
|
10591 | writePngChunk("IEND", new Uint8Array(0), data, offset);
|
10592 | return (0, _util.createObjectURL)(data, "image/png", forceDataSchema);
|
10593 | }
|
10594 |
|
10595 | return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
|
10596 | const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
|
10597 | return encode(imgData, kind, forceDataSchema, isMask);
|
10598 | };
|
10599 | }();
|
10600 |
|
10601 | class SVGExtraState {
|
10602 | constructor() {
|
10603 | this.fontSizeScale = 1;
|
10604 | this.fontWeight = SVG_DEFAULTS.fontWeight;
|
10605 | this.fontSize = 0;
|
10606 | this.textMatrix = _util.IDENTITY_MATRIX;
|
10607 | this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
|
10608 | this.leading = 0;
|
10609 | this.textRenderingMode = _util.TextRenderingMode.FILL;
|
10610 | this.textMatrixScale = 1;
|
10611 | this.x = 0;
|
10612 | this.y = 0;
|
10613 | this.lineX = 0;
|
10614 | this.lineY = 0;
|
10615 | this.charSpacing = 0;
|
10616 | this.wordSpacing = 0;
|
10617 | this.textHScale = 1;
|
10618 | this.textRise = 0;
|
10619 | this.fillColor = SVG_DEFAULTS.fillColor;
|
10620 | this.strokeColor = "#000000";
|
10621 | this.fillAlpha = 1;
|
10622 | this.strokeAlpha = 1;
|
10623 | this.lineWidth = 1;
|
10624 | this.lineJoin = "";
|
10625 | this.lineCap = "";
|
10626 | this.miterLimit = 0;
|
10627 | this.dashArray = [];
|
10628 | this.dashPhase = 0;
|
10629 | this.dependencies = [];
|
10630 | this.activeClipUrl = null;
|
10631 | this.clipGroup = null;
|
10632 | this.maskId = "";
|
10633 | }
|
10634 |
|
10635 | clone() {
|
10636 | return Object.create(this);
|
10637 | }
|
10638 |
|
10639 | setCurrentPoint(x, y) {
|
10640 | this.x = x;
|
10641 | this.y = y;
|
10642 | }
|
10643 |
|
10644 | }
|
10645 |
|
10646 | function opListToTree(opList) {
|
10647 | let opTree = [];
|
10648 | const tmp = [];
|
10649 |
|
10650 | for (const opListElement of opList) {
|
10651 | if (opListElement.fn === "save") {
|
10652 | opTree.push({
|
10653 | fnId: 92,
|
10654 | fn: "group",
|
10655 | items: []
|
10656 | });
|
10657 | tmp.push(opTree);
|
10658 | opTree = opTree[opTree.length - 1].items;
|
10659 | continue;
|
10660 | }
|
10661 |
|
10662 | if (opListElement.fn === "restore") {
|
10663 | opTree = tmp.pop();
|
10664 | } else {
|
10665 | opTree.push(opListElement);
|
10666 | }
|
10667 | }
|
10668 |
|
10669 | return opTree;
|
10670 | }
|
10671 |
|
10672 | function pf(value) {
|
10673 | if (Number.isInteger(value)) {
|
10674 | return value.toString();
|
10675 | }
|
10676 |
|
10677 | const s = value.toFixed(10);
|
10678 | let i = s.length - 1;
|
10679 |
|
10680 | if (s[i] !== "0") {
|
10681 | return s;
|
10682 | }
|
10683 |
|
10684 | do {
|
10685 | i--;
|
10686 | } while (s[i] === "0");
|
10687 |
|
10688 | return s.substring(0, s[i] === "." ? i : i + 1);
|
10689 | }
|
10690 |
|
10691 | function pm(m) {
|
10692 | if (m[4] === 0 && m[5] === 0) {
|
10693 | if (m[1] === 0 && m[2] === 0) {
|
10694 | if (m[0] === 1 && m[3] === 1) {
|
10695 | return "";
|
10696 | }
|
10697 |
|
10698 | return `scale(${pf(m[0])} ${pf(m[3])})`;
|
10699 | }
|
10700 |
|
10701 | if (m[0] === m[3] && m[1] === -m[2]) {
|
10702 | const a = Math.acos(m[0]) * 180 / Math.PI;
|
10703 | return `rotate(${pf(a)})`;
|
10704 | }
|
10705 | } else {
|
10706 | if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
|
10707 | return `translate(${pf(m[4])} ${pf(m[5])})`;
|
10708 | }
|
10709 | }
|
10710 |
|
10711 | return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
|
10712 | }
|
10713 |
|
10714 | let clipCount = 0;
|
10715 | let maskCount = 0;
|
10716 | let shadingCount = 0;
|
10717 | exports.SVGGraphics = SVGGraphics = class SVGGraphics {
|
10718 | constructor(commonObjs, objs, forceDataSchema = false) {
|
10719 | this.svgFactory = new _display_utils.DOMSVGFactory();
|
10720 | this.current = new SVGExtraState();
|
10721 | this.transformMatrix = _util.IDENTITY_MATRIX;
|
10722 | this.transformStack = [];
|
10723 | this.extraStack = [];
|
10724 | this.commonObjs = commonObjs;
|
10725 | this.objs = objs;
|
10726 | this.pendingClip = null;
|
10727 | this.pendingEOFill = false;
|
10728 | this.embedFonts = false;
|
10729 | this.embeddedFonts = Object.create(null);
|
10730 | this.cssStyle = null;
|
10731 | this.forceDataSchema = !!forceDataSchema;
|
10732 | this._operatorIdMapping = [];
|
10733 |
|
10734 | for (const op in _util.OPS) {
|
10735 | this._operatorIdMapping[_util.OPS[op]] = op;
|
10736 | }
|
10737 | }
|
10738 |
|
10739 | save() {
|
10740 | this.transformStack.push(this.transformMatrix);
|
10741 | const old = this.current;
|
10742 | this.extraStack.push(old);
|
10743 | this.current = old.clone();
|
10744 | }
|
10745 |
|
10746 | restore() {
|
10747 | this.transformMatrix = this.transformStack.pop();
|
10748 | this.current = this.extraStack.pop();
|
10749 | this.pendingClip = null;
|
10750 | this.tgrp = null;
|
10751 | }
|
10752 |
|
10753 | group(items) {
|
10754 | this.save();
|
10755 | this.executeOpTree(items);
|
10756 | this.restore();
|
10757 | }
|
10758 |
|
10759 | loadDependencies(operatorList) {
|
10760 | const fnArray = operatorList.fnArray;
|
10761 | const argsArray = operatorList.argsArray;
|
10762 |
|
10763 | for (let i = 0, ii = fnArray.length; i < ii; i++) {
|
10764 | if (fnArray[i] !== _util.OPS.dependency) {
|
10765 | continue;
|
10766 | }
|
10767 |
|
10768 | for (const obj of argsArray[i]) {
|
10769 | const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
|
10770 | const promise = new Promise(resolve => {
|
10771 | objsPool.get(obj, resolve);
|
10772 | });
|
10773 | this.current.dependencies.push(promise);
|
10774 | }
|
10775 | }
|
10776 |
|
10777 | return Promise.all(this.current.dependencies);
|
10778 | }
|
10779 |
|
10780 | transform(a, b, c, d, e, f) {
|
10781 | const transformMatrix = [a, b, c, d, e, f];
|
10782 | this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
|
10783 | this.tgrp = null;
|
10784 | }
|
10785 |
|
10786 | getSVG(operatorList, viewport) {
|
10787 | this.viewport = viewport;
|
10788 |
|
10789 | const svgElement = this._initialize(viewport);
|
10790 |
|
10791 | return this.loadDependencies(operatorList).then(() => {
|
10792 | this.transformMatrix = _util.IDENTITY_MATRIX;
|
10793 | this.executeOpTree(this.convertOpList(operatorList));
|
10794 | return svgElement;
|
10795 | });
|
10796 | }
|
10797 |
|
10798 | convertOpList(operatorList) {
|
10799 | const operatorIdMapping = this._operatorIdMapping;
|
10800 | const argsArray = operatorList.argsArray;
|
10801 | const fnArray = operatorList.fnArray;
|
10802 | const opList = [];
|
10803 |
|
10804 | for (let i = 0, ii = fnArray.length; i < ii; i++) {
|
10805 | const fnId = fnArray[i];
|
10806 | opList.push({
|
10807 | fnId,
|
10808 | fn: operatorIdMapping[fnId],
|
10809 | args: argsArray[i]
|
10810 | });
|
10811 | }
|
10812 |
|
10813 | return opListToTree(opList);
|
10814 | }
|
10815 |
|
10816 | executeOpTree(opTree) {
|
10817 | for (const opTreeElement of opTree) {
|
10818 | const fn = opTreeElement.fn;
|
10819 | const fnId = opTreeElement.fnId;
|
10820 | const args = opTreeElement.args;
|
10821 |
|
10822 | switch (fnId | 0) {
|
10823 | case _util.OPS.beginText:
|
10824 | this.beginText();
|
10825 | break;
|
10826 |
|
10827 | case _util.OPS.dependency:
|
10828 | break;
|
10829 |
|
10830 | case _util.OPS.setLeading:
|
10831 | this.setLeading(args);
|
10832 | break;
|
10833 |
|
10834 | case _util.OPS.setLeadingMoveText:
|
10835 | this.setLeadingMoveText(args[0], args[1]);
|
10836 | break;
|
10837 |
|
10838 | case _util.OPS.setFont:
|
10839 | this.setFont(args);
|
10840 | break;
|
10841 |
|
10842 | case _util.OPS.showText:
|
10843 | this.showText(args[0]);
|
10844 | break;
|
10845 |
|
10846 | case _util.OPS.showSpacedText:
|
10847 | this.showText(args[0]);
|
10848 | break;
|
10849 |
|
10850 | case _util.OPS.endText:
|
10851 | this.endText();
|
10852 | break;
|
10853 |
|
10854 | case _util.OPS.moveText:
|
10855 | this.moveText(args[0], args[1]);
|
10856 | break;
|
10857 |
|
10858 | case _util.OPS.setCharSpacing:
|
10859 | this.setCharSpacing(args[0]);
|
10860 | break;
|
10861 |
|
10862 | case _util.OPS.setWordSpacing:
|
10863 | this.setWordSpacing(args[0]);
|
10864 | break;
|
10865 |
|
10866 | case _util.OPS.setHScale:
|
10867 | this.setHScale(args[0]);
|
10868 | break;
|
10869 |
|
10870 | case _util.OPS.setTextMatrix:
|
10871 | this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
|
10872 | break;
|
10873 |
|
10874 | case _util.OPS.setTextRise:
|
10875 | this.setTextRise(args[0]);
|
10876 | break;
|
10877 |
|
10878 | case _util.OPS.setTextRenderingMode:
|
10879 | this.setTextRenderingMode(args[0]);
|
10880 | break;
|
10881 |
|
10882 | case _util.OPS.setLineWidth:
|
10883 | this.setLineWidth(args[0]);
|
10884 | break;
|
10885 |
|
10886 | case _util.OPS.setLineJoin:
|
10887 | this.setLineJoin(args[0]);
|
10888 | break;
|
10889 |
|
10890 | case _util.OPS.setLineCap:
|
10891 | this.setLineCap(args[0]);
|
10892 | break;
|
10893 |
|
10894 | case _util.OPS.setMiterLimit:
|
10895 | this.setMiterLimit(args[0]);
|
10896 | break;
|
10897 |
|
10898 | case _util.OPS.setFillRGBColor:
|
10899 | this.setFillRGBColor(args[0], args[1], args[2]);
|
10900 | break;
|
10901 |
|
10902 | case _util.OPS.setStrokeRGBColor:
|
10903 | this.setStrokeRGBColor(args[0], args[1], args[2]);
|
10904 | break;
|
10905 |
|
10906 | case _util.OPS.setStrokeColorN:
|
10907 | this.setStrokeColorN(args);
|
10908 | break;
|
10909 |
|
10910 | case _util.OPS.setFillColorN:
|
10911 | this.setFillColorN(args);
|
10912 | break;
|
10913 |
|
10914 | case _util.OPS.shadingFill:
|
10915 | this.shadingFill(args[0]);
|
10916 | break;
|
10917 |
|
10918 | case _util.OPS.setDash:
|
10919 | this.setDash(args[0], args[1]);
|
10920 | break;
|
10921 |
|
10922 | case _util.OPS.setRenderingIntent:
|
10923 | this.setRenderingIntent(args[0]);
|
10924 | break;
|
10925 |
|
10926 | case _util.OPS.setFlatness:
|
10927 | this.setFlatness(args[0]);
|
10928 | break;
|
10929 |
|
10930 | case _util.OPS.setGState:
|
10931 | this.setGState(args[0]);
|
10932 | break;
|
10933 |
|
10934 | case _util.OPS.fill:
|
10935 | this.fill();
|
10936 | break;
|
10937 |
|
10938 | case _util.OPS.eoFill:
|
10939 | this.eoFill();
|
10940 | break;
|
10941 |
|
10942 | case _util.OPS.stroke:
|
10943 | this.stroke();
|
10944 | break;
|
10945 |
|
10946 | case _util.OPS.fillStroke:
|
10947 | this.fillStroke();
|
10948 | break;
|
10949 |
|
10950 | case _util.OPS.eoFillStroke:
|
10951 | this.eoFillStroke();
|
10952 | break;
|
10953 |
|
10954 | case _util.OPS.clip:
|
10955 | this.clip("nonzero");
|
10956 | break;
|
10957 |
|
10958 | case _util.OPS.eoClip:
|
10959 | this.clip("evenodd");
|
10960 | break;
|
10961 |
|
10962 | case _util.OPS.paintSolidColorImageMask:
|
10963 | this.paintSolidColorImageMask();
|
10964 | break;
|
10965 |
|
10966 | case _util.OPS.paintImageXObject:
|
10967 | this.paintImageXObject(args[0]);
|
10968 | break;
|
10969 |
|
10970 | case _util.OPS.paintInlineImageXObject:
|
10971 | this.paintInlineImageXObject(args[0]);
|
10972 | break;
|
10973 |
|
10974 | case _util.OPS.paintImageMaskXObject:
|
10975 | this.paintImageMaskXObject(args[0]);
|
10976 | break;
|
10977 |
|
10978 | case _util.OPS.paintFormXObjectBegin:
|
10979 | this.paintFormXObjectBegin(args[0], args[1]);
|
10980 | break;
|
10981 |
|
10982 | case _util.OPS.paintFormXObjectEnd:
|
10983 | this.paintFormXObjectEnd();
|
10984 | break;
|
10985 |
|
10986 | case _util.OPS.closePath:
|
10987 | this.closePath();
|
10988 | break;
|
10989 |
|
10990 | case _util.OPS.closeStroke:
|
10991 | this.closeStroke();
|
10992 | break;
|
10993 |
|
10994 | case _util.OPS.closeFillStroke:
|
10995 | this.closeFillStroke();
|
10996 | break;
|
10997 |
|
10998 | case _util.OPS.closeEOFillStroke:
|
10999 | this.closeEOFillStroke();
|
11000 | break;
|
11001 |
|
11002 | case _util.OPS.nextLine:
|
11003 | this.nextLine();
|
11004 | break;
|
11005 |
|
11006 | case _util.OPS.transform:
|
11007 | this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
|
11008 | break;
|
11009 |
|
11010 | case _util.OPS.constructPath:
|
11011 | this.constructPath(args[0], args[1]);
|
11012 | break;
|
11013 |
|
11014 | case _util.OPS.endPath:
|
11015 | this.endPath();
|
11016 | break;
|
11017 |
|
11018 | case 92:
|
11019 | this.group(opTreeElement.items);
|
11020 | break;
|
11021 |
|
11022 | default:
|
11023 | (0, _util.warn)(`Unimplemented operator ${fn}`);
|
11024 | break;
|
11025 | }
|
11026 | }
|
11027 | }
|
11028 |
|
11029 | setWordSpacing(wordSpacing) {
|
11030 | this.current.wordSpacing = wordSpacing;
|
11031 | }
|
11032 |
|
11033 | setCharSpacing(charSpacing) {
|
11034 | this.current.charSpacing = charSpacing;
|
11035 | }
|
11036 |
|
11037 | nextLine() {
|
11038 | this.moveText(0, this.current.leading);
|
11039 | }
|
11040 |
|
11041 | setTextMatrix(a, b, c, d, e, f) {
|
11042 | const current = this.current;
|
11043 | current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
|
11044 | current.textMatrixScale = Math.sqrt(a * a + b * b);
|
11045 | current.x = current.lineX = 0;
|
11046 | current.y = current.lineY = 0;
|
11047 | current.xcoords = [];
|
11048 | current.ycoords = [];
|
11049 | current.tspan = this.svgFactory.createElement("svg:tspan");
|
11050 | current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
|
11051 | current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
|
11052 | current.tspan.setAttributeNS(null, "y", pf(-current.y));
|
11053 | current.txtElement = this.svgFactory.createElement("svg:text");
|
11054 | current.txtElement.appendChild(current.tspan);
|
11055 | }
|
11056 |
|
11057 | beginText() {
|
11058 | const current = this.current;
|
11059 | current.x = current.lineX = 0;
|
11060 | current.y = current.lineY = 0;
|
11061 | current.textMatrix = _util.IDENTITY_MATRIX;
|
11062 | current.lineMatrix = _util.IDENTITY_MATRIX;
|
11063 | current.textMatrixScale = 1;
|
11064 | current.tspan = this.svgFactory.createElement("svg:tspan");
|
11065 | current.txtElement = this.svgFactory.createElement("svg:text");
|
11066 | current.txtgrp = this.svgFactory.createElement("svg:g");
|
11067 | current.xcoords = [];
|
11068 | current.ycoords = [];
|
11069 | }
|
11070 |
|
11071 | moveText(x, y) {
|
11072 | const current = this.current;
|
11073 | current.x = current.lineX += x;
|
11074 | current.y = current.lineY += y;
|
11075 | current.xcoords = [];
|
11076 | current.ycoords = [];
|
11077 | current.tspan = this.svgFactory.createElement("svg:tspan");
|
11078 | current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
|
11079 | current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
|
11080 | current.tspan.setAttributeNS(null, "y", pf(-current.y));
|
11081 | }
|
11082 |
|
11083 | showText(glyphs) {
|
11084 | const current = this.current;
|
11085 | const font = current.font;
|
11086 | const fontSize = current.fontSize;
|
11087 |
|
11088 | if (fontSize === 0) {
|
11089 | return;
|
11090 | }
|
11091 |
|
11092 | const fontSizeScale = current.fontSizeScale;
|
11093 | const charSpacing = current.charSpacing;
|
11094 | const wordSpacing = current.wordSpacing;
|
11095 | const fontDirection = current.fontDirection;
|
11096 | const textHScale = current.textHScale * fontDirection;
|
11097 | const vertical = font.vertical;
|
11098 | const spacingDir = vertical ? 1 : -1;
|
11099 | const defaultVMetrics = font.defaultVMetrics;
|
11100 | const widthAdvanceScale = fontSize * current.fontMatrix[0];
|
11101 | let x = 0;
|
11102 |
|
11103 | for (const glyph of glyphs) {
|
11104 | if (glyph === null) {
|
11105 | x += fontDirection * wordSpacing;
|
11106 | continue;
|
11107 | } else if ((0, _util.isNum)(glyph)) {
|
11108 | x += spacingDir * glyph * fontSize / 1000;
|
11109 | continue;
|
11110 | }
|
11111 |
|
11112 | const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
|
11113 | const character = glyph.fontChar;
|
11114 | let scaledX, scaledY;
|
11115 | let width = glyph.width;
|
11116 |
|
11117 | if (vertical) {
|
11118 | let vx;
|
11119 | const vmetric = glyph.vmetric || defaultVMetrics;
|
11120 | vx = glyph.vmetric ? vmetric[1] : width * 0.5;
|
11121 | vx = -vx * widthAdvanceScale;
|
11122 | const vy = vmetric[2] * widthAdvanceScale;
|
11123 | width = vmetric ? -vmetric[0] : width;
|
11124 | scaledX = vx / fontSizeScale;
|
11125 | scaledY = (x + vy) / fontSizeScale;
|
11126 | } else {
|
11127 | scaledX = x / fontSizeScale;
|
11128 | scaledY = 0;
|
11129 | }
|
11130 |
|
11131 | if (glyph.isInFont || font.missingFile) {
|
11132 | current.xcoords.push(current.x + scaledX);
|
11133 |
|
11134 | if (vertical) {
|
11135 | current.ycoords.push(-current.y + scaledY);
|
11136 | }
|
11137 |
|
11138 | current.tspan.textContent += character;
|
11139 | } else {}
|
11140 |
|
11141 | let charWidth;
|
11142 |
|
11143 | if (vertical) {
|
11144 | charWidth = width * widthAdvanceScale - spacing * fontDirection;
|
11145 | } else {
|
11146 | charWidth = width * widthAdvanceScale + spacing * fontDirection;
|
11147 | }
|
11148 |
|
11149 | x += charWidth;
|
11150 | }
|
11151 |
|
11152 | current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
|
11153 |
|
11154 | if (vertical) {
|
11155 | current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
|
11156 | } else {
|
11157 | current.tspan.setAttributeNS(null, "y", pf(-current.y));
|
11158 | }
|
11159 |
|
11160 | if (vertical) {
|
11161 | current.y -= x;
|
11162 | } else {
|
11163 | current.x += x * textHScale;
|
11164 | }
|
11165 |
|
11166 | current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
|
11167 | current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
|
11168 |
|
11169 | if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
|
11170 | current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
|
11171 | }
|
11172 |
|
11173 | if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
|
11174 | current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
|
11175 | }
|
11176 |
|
11177 | const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
|
11178 |
|
11179 | if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
11180 | if (current.fillColor !== SVG_DEFAULTS.fillColor) {
|
11181 | current.tspan.setAttributeNS(null, "fill", current.fillColor);
|
11182 | }
|
11183 |
|
11184 | if (current.fillAlpha < 1) {
|
11185 | current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
|
11186 | }
|
11187 | } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
|
11188 | current.tspan.setAttributeNS(null, "fill", "transparent");
|
11189 | } else {
|
11190 | current.tspan.setAttributeNS(null, "fill", "none");
|
11191 | }
|
11192 |
|
11193 | if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
11194 | const lineWidthScale = 1 / (current.textMatrixScale || 1);
|
11195 |
|
11196 | this._setStrokeAttributes(current.tspan, lineWidthScale);
|
11197 | }
|
11198 |
|
11199 | let textMatrix = current.textMatrix;
|
11200 |
|
11201 | if (current.textRise !== 0) {
|
11202 | textMatrix = textMatrix.slice();
|
11203 | textMatrix[5] += current.textRise;
|
11204 | }
|
11205 |
|
11206 | current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
|
11207 | current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
|
11208 | current.txtElement.appendChild(current.tspan);
|
11209 | current.txtgrp.appendChild(current.txtElement);
|
11210 |
|
11211 | this._ensureTransformGroup().appendChild(current.txtElement);
|
11212 | }
|
11213 |
|
11214 | setLeadingMoveText(x, y) {
|
11215 | this.setLeading(-y);
|
11216 | this.moveText(x, y);
|
11217 | }
|
11218 |
|
11219 | addFontStyle(fontObj) {
|
11220 | if (!fontObj.data) {
|
11221 | throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
|
11222 | }
|
11223 |
|
11224 | if (!this.cssStyle) {
|
11225 | this.cssStyle = this.svgFactory.createElement("svg:style");
|
11226 | this.cssStyle.setAttributeNS(null, "type", "text/css");
|
11227 | this.defs.appendChild(this.cssStyle);
|
11228 | }
|
11229 |
|
11230 | const url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
|
11231 | this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
|
11232 | }
|
11233 |
|
11234 | setFont(details) {
|
11235 | const current = this.current;
|
11236 | const fontObj = this.commonObjs.get(details[0]);
|
11237 | let size = details[1];
|
11238 | current.font = fontObj;
|
11239 |
|
11240 | if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
|
11241 | this.addFontStyle(fontObj);
|
11242 | this.embeddedFonts[fontObj.loadedName] = fontObj;
|
11243 | }
|
11244 |
|
11245 | current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
|
11246 | let bold = "normal";
|
11247 |
|
11248 | if (fontObj.black) {
|
11249 | bold = "900";
|
11250 | } else if (fontObj.bold) {
|
11251 | bold = "bold";
|
11252 | }
|
11253 |
|
11254 | const italic = fontObj.italic ? "italic" : "normal";
|
11255 |
|
11256 | if (size < 0) {
|
11257 | size = -size;
|
11258 | current.fontDirection = -1;
|
11259 | } else {
|
11260 | current.fontDirection = 1;
|
11261 | }
|
11262 |
|
11263 | current.fontSize = size;
|
11264 | current.fontFamily = fontObj.loadedName;
|
11265 | current.fontWeight = bold;
|
11266 | current.fontStyle = italic;
|
11267 | current.tspan = this.svgFactory.createElement("svg:tspan");
|
11268 | current.tspan.setAttributeNS(null, "y", pf(-current.y));
|
11269 | current.xcoords = [];
|
11270 | current.ycoords = [];
|
11271 | }
|
11272 |
|
11273 | endText() {
|
11274 | const current = this.current;
|
11275 |
|
11276 | if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement && current.txtElement.hasChildNodes()) {
|
11277 | current.element = current.txtElement;
|
11278 | this.clip("nonzero");
|
11279 | this.endPath();
|
11280 | }
|
11281 | }
|
11282 |
|
11283 | setLineWidth(width) {
|
11284 | if (width > 0) {
|
11285 | this.current.lineWidth = width;
|
11286 | }
|
11287 | }
|
11288 |
|
11289 | setLineCap(style) {
|
11290 | this.current.lineCap = LINE_CAP_STYLES[style];
|
11291 | }
|
11292 |
|
11293 | setLineJoin(style) {
|
11294 | this.current.lineJoin = LINE_JOIN_STYLES[style];
|
11295 | }
|
11296 |
|
11297 | setMiterLimit(limit) {
|
11298 | this.current.miterLimit = limit;
|
11299 | }
|
11300 |
|
11301 | setStrokeAlpha(strokeAlpha) {
|
11302 | this.current.strokeAlpha = strokeAlpha;
|
11303 | }
|
11304 |
|
11305 | setStrokeRGBColor(r, g, b) {
|
11306 | this.current.strokeColor = _util.Util.makeCssRgb(r, g, b);
|
11307 | }
|
11308 |
|
11309 | setFillAlpha(fillAlpha) {
|
11310 | this.current.fillAlpha = fillAlpha;
|
11311 | }
|
11312 |
|
11313 | setFillRGBColor(r, g, b) {
|
11314 | this.current.fillColor = _util.Util.makeCssRgb(r, g, b);
|
11315 | this.current.tspan = this.svgFactory.createElement("svg:tspan");
|
11316 | this.current.xcoords = [];
|
11317 | this.current.ycoords = [];
|
11318 | }
|
11319 |
|
11320 | setStrokeColorN(args) {
|
11321 | this.current.strokeColor = this._makeColorN_Pattern(args);
|
11322 | }
|
11323 |
|
11324 | setFillColorN(args) {
|
11325 | this.current.fillColor = this._makeColorN_Pattern(args);
|
11326 | }
|
11327 |
|
11328 | shadingFill(args) {
|
11329 | const width = this.viewport.width;
|
11330 | const height = this.viewport.height;
|
11331 |
|
11332 | const inv = _util.Util.inverseTransform(this.transformMatrix);
|
11333 |
|
11334 | const bl = _util.Util.applyTransform([0, 0], inv);
|
11335 |
|
11336 | const br = _util.Util.applyTransform([0, height], inv);
|
11337 |
|
11338 | const ul = _util.Util.applyTransform([width, 0], inv);
|
11339 |
|
11340 | const ur = _util.Util.applyTransform([width, height], inv);
|
11341 |
|
11342 | const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
|
11343 | const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
|
11344 | const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
|
11345 | const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
|
11346 | const rect = this.svgFactory.createElement("svg:rect");
|
11347 | rect.setAttributeNS(null, "x", x0);
|
11348 | rect.setAttributeNS(null, "y", y0);
|
11349 | rect.setAttributeNS(null, "width", x1 - x0);
|
11350 | rect.setAttributeNS(null, "height", y1 - y0);
|
11351 | rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
|
11352 |
|
11353 | if (this.current.fillAlpha < 1) {
|
11354 | rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
|
11355 | }
|
11356 |
|
11357 | this._ensureTransformGroup().appendChild(rect);
|
11358 | }
|
11359 |
|
11360 | _makeColorN_Pattern(args) {
|
11361 | if (args[0] === "TilingPattern") {
|
11362 | return this._makeTilingPattern(args);
|
11363 | }
|
11364 |
|
11365 | return this._makeShadingPattern(args);
|
11366 | }
|
11367 |
|
11368 | _makeTilingPattern(args) {
|
11369 | const color = args[1];
|
11370 | const operatorList = args[2];
|
11371 | const matrix = args[3] || _util.IDENTITY_MATRIX;
|
11372 | const [x0, y0, x1, y1] = args[4];
|
11373 | const xstep = args[5];
|
11374 | const ystep = args[6];
|
11375 | const paintType = args[7];
|
11376 | const tilingId = `shading${shadingCount++}`;
|
11377 |
|
11378 | const [tx0, ty0] = _util.Util.applyTransform([x0, y0], matrix);
|
11379 |
|
11380 | const [tx1, ty1] = _util.Util.applyTransform([x1, y1], matrix);
|
11381 |
|
11382 | const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
|
11383 |
|
11384 | const txstep = xstep * xscale;
|
11385 | const tystep = ystep * yscale;
|
11386 | const tiling = this.svgFactory.createElement("svg:pattern");
|
11387 | tiling.setAttributeNS(null, "id", tilingId);
|
11388 | tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
|
11389 | tiling.setAttributeNS(null, "width", txstep);
|
11390 | tiling.setAttributeNS(null, "height", tystep);
|
11391 | tiling.setAttributeNS(null, "x", `${tx0}`);
|
11392 | tiling.setAttributeNS(null, "y", `${ty0}`);
|
11393 | const svg = this.svg;
|
11394 | const transformMatrix = this.transformMatrix;
|
11395 | const fillColor = this.current.fillColor;
|
11396 | const strokeColor = this.current.strokeColor;
|
11397 | const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
|
11398 | this.svg = bbox;
|
11399 | this.transformMatrix = matrix;
|
11400 |
|
11401 | if (paintType === 2) {
|
11402 | const cssColor = _util.Util.makeCssRgb(...color);
|
11403 |
|
11404 | this.current.fillColor = cssColor;
|
11405 | this.current.strokeColor = cssColor;
|
11406 | }
|
11407 |
|
11408 | this.executeOpTree(this.convertOpList(operatorList));
|
11409 | this.svg = svg;
|
11410 | this.transformMatrix = transformMatrix;
|
11411 | this.current.fillColor = fillColor;
|
11412 | this.current.strokeColor = strokeColor;
|
11413 | tiling.appendChild(bbox.childNodes[0]);
|
11414 | this.defs.appendChild(tiling);
|
11415 | return `url(#${tilingId})`;
|
11416 | }
|
11417 |
|
11418 | _makeShadingPattern(args) {
|
11419 | switch (args[0]) {
|
11420 | case "RadialAxial":
|
11421 | const shadingId = `shading${shadingCount++}`;
|
11422 | const colorStops = args[3];
|
11423 | let gradient;
|
11424 |
|
11425 | switch (args[1]) {
|
11426 | case "axial":
|
11427 | const point0 = args[4];
|
11428 | const point1 = args[5];
|
11429 | gradient = this.svgFactory.createElement("svg:linearGradient");
|
11430 | gradient.setAttributeNS(null, "id", shadingId);
|
11431 | gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
|
11432 | gradient.setAttributeNS(null, "x1", point0[0]);
|
11433 | gradient.setAttributeNS(null, "y1", point0[1]);
|
11434 | gradient.setAttributeNS(null, "x2", point1[0]);
|
11435 | gradient.setAttributeNS(null, "y2", point1[1]);
|
11436 | break;
|
11437 |
|
11438 | case "radial":
|
11439 | const focalPoint = args[4];
|
11440 | const circlePoint = args[5];
|
11441 | const focalRadius = args[6];
|
11442 | const circleRadius = args[7];
|
11443 | gradient = this.svgFactory.createElement("svg:radialGradient");
|
11444 | gradient.setAttributeNS(null, "id", shadingId);
|
11445 | gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
|
11446 | gradient.setAttributeNS(null, "cx", circlePoint[0]);
|
11447 | gradient.setAttributeNS(null, "cy", circlePoint[1]);
|
11448 | gradient.setAttributeNS(null, "r", circleRadius);
|
11449 | gradient.setAttributeNS(null, "fx", focalPoint[0]);
|
11450 | gradient.setAttributeNS(null, "fy", focalPoint[1]);
|
11451 | gradient.setAttributeNS(null, "fr", focalRadius);
|
11452 | break;
|
11453 |
|
11454 | default:
|
11455 | throw new Error(`Unknown RadialAxial type: ${args[1]}`);
|
11456 | }
|
11457 |
|
11458 | for (const colorStop of colorStops) {
|
11459 | const stop = this.svgFactory.createElement("svg:stop");
|
11460 | stop.setAttributeNS(null, "offset", colorStop[0]);
|
11461 | stop.setAttributeNS(null, "stop-color", colorStop[1]);
|
11462 | gradient.appendChild(stop);
|
11463 | }
|
11464 |
|
11465 | this.defs.appendChild(gradient);
|
11466 | return `url(#${shadingId})`;
|
11467 |
|
11468 | case "Mesh":
|
11469 | (0, _util.warn)("Unimplemented pattern Mesh");
|
11470 | return null;
|
11471 |
|
11472 | case "Dummy":
|
11473 | return "hotpink";
|
11474 |
|
11475 | default:
|
11476 | throw new Error(`Unknown IR type: ${args[0]}`);
|
11477 | }
|
11478 | }
|
11479 |
|
11480 | setDash(dashArray, dashPhase) {
|
11481 | this.current.dashArray = dashArray;
|
11482 | this.current.dashPhase = dashPhase;
|
11483 | }
|
11484 |
|
11485 | constructPath(ops, args) {
|
11486 | const current = this.current;
|
11487 | let x = current.x,
|
11488 | y = current.y;
|
11489 | let d = [];
|
11490 | let j = 0;
|
11491 |
|
11492 | for (const op of ops) {
|
11493 | switch (op | 0) {
|
11494 | case _util.OPS.rectangle:
|
11495 | x = args[j++];
|
11496 | y = args[j++];
|
11497 | const width = args[j++];
|
11498 | const height = args[j++];
|
11499 | const xw = x + width;
|
11500 | const yh = y + height;
|
11501 | d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
|
11502 | break;
|
11503 |
|
11504 | case _util.OPS.moveTo:
|
11505 | x = args[j++];
|
11506 | y = args[j++];
|
11507 | d.push("M", pf(x), pf(y));
|
11508 | break;
|
11509 |
|
11510 | case _util.OPS.lineTo:
|
11511 | x = args[j++];
|
11512 | y = args[j++];
|
11513 | d.push("L", pf(x), pf(y));
|
11514 | break;
|
11515 |
|
11516 | case _util.OPS.curveTo:
|
11517 | x = args[j + 4];
|
11518 | y = args[j + 5];
|
11519 | d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
|
11520 | j += 6;
|
11521 | break;
|
11522 |
|
11523 | case _util.OPS.curveTo2:
|
11524 | d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
|
11525 | x = args[j + 2];
|
11526 | y = args[j + 3];
|
11527 | j += 4;
|
11528 | break;
|
11529 |
|
11530 | case _util.OPS.curveTo3:
|
11531 | x = args[j + 2];
|
11532 | y = args[j + 3];
|
11533 | d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
|
11534 | j += 4;
|
11535 | break;
|
11536 |
|
11537 | case _util.OPS.closePath:
|
11538 | d.push("Z");
|
11539 | break;
|
11540 | }
|
11541 | }
|
11542 |
|
11543 | d = d.join(" ");
|
11544 |
|
11545 | if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
|
11546 | d = current.path.getAttributeNS(null, "d") + d;
|
11547 | } else {
|
11548 | current.path = this.svgFactory.createElement("svg:path");
|
11549 |
|
11550 | this._ensureTransformGroup().appendChild(current.path);
|
11551 | }
|
11552 |
|
11553 | current.path.setAttributeNS(null, "d", d);
|
11554 | current.path.setAttributeNS(null, "fill", "none");
|
11555 | current.element = current.path;
|
11556 | current.setCurrentPoint(x, y);
|
11557 | }
|
11558 |
|
11559 | endPath() {
|
11560 | const current = this.current;
|
11561 | current.path = null;
|
11562 |
|
11563 | if (!this.pendingClip) {
|
11564 | return;
|
11565 | }
|
11566 |
|
11567 | if (!current.element) {
|
11568 | this.pendingClip = null;
|
11569 | return;
|
11570 | }
|
11571 |
|
11572 | const clipId = `clippath${clipCount++}`;
|
11573 | const clipPath = this.svgFactory.createElement("svg:clipPath");
|
11574 | clipPath.setAttributeNS(null, "id", clipId);
|
11575 | clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
|
11576 | const clipElement = current.element.cloneNode(true);
|
11577 |
|
11578 | if (this.pendingClip === "evenodd") {
|
11579 | clipElement.setAttributeNS(null, "clip-rule", "evenodd");
|
11580 | } else {
|
11581 | clipElement.setAttributeNS(null, "clip-rule", "nonzero");
|
11582 | }
|
11583 |
|
11584 | this.pendingClip = null;
|
11585 | clipPath.appendChild(clipElement);
|
11586 | this.defs.appendChild(clipPath);
|
11587 |
|
11588 | if (current.activeClipUrl) {
|
11589 | current.clipGroup = null;
|
11590 | this.extraStack.forEach(function (prev) {
|
11591 | prev.clipGroup = null;
|
11592 | });
|
11593 | clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
|
11594 | }
|
11595 |
|
11596 | current.activeClipUrl = `url(#${clipId})`;
|
11597 | this.tgrp = null;
|
11598 | }
|
11599 |
|
11600 | clip(type) {
|
11601 | this.pendingClip = type;
|
11602 | }
|
11603 |
|
11604 | closePath() {
|
11605 | const current = this.current;
|
11606 |
|
11607 | if (current.path) {
|
11608 | const d = `${current.path.getAttributeNS(null, "d")}Z`;
|
11609 | current.path.setAttributeNS(null, "d", d);
|
11610 | }
|
11611 | }
|
11612 |
|
11613 | setLeading(leading) {
|
11614 | this.current.leading = -leading;
|
11615 | }
|
11616 |
|
11617 | setTextRise(textRise) {
|
11618 | this.current.textRise = textRise;
|
11619 | }
|
11620 |
|
11621 | setTextRenderingMode(textRenderingMode) {
|
11622 | this.current.textRenderingMode = textRenderingMode;
|
11623 | }
|
11624 |
|
11625 | setHScale(scale) {
|
11626 | this.current.textHScale = scale / 100;
|
11627 | }
|
11628 |
|
11629 | setRenderingIntent(intent) {}
|
11630 |
|
11631 | setFlatness(flatness) {}
|
11632 |
|
11633 | setGState(states) {
|
11634 | for (const [key, value] of states) {
|
11635 | switch (key) {
|
11636 | case "LW":
|
11637 | this.setLineWidth(value);
|
11638 | break;
|
11639 |
|
11640 | case "LC":
|
11641 | this.setLineCap(value);
|
11642 | break;
|
11643 |
|
11644 | case "LJ":
|
11645 | this.setLineJoin(value);
|
11646 | break;
|
11647 |
|
11648 | case "ML":
|
11649 | this.setMiterLimit(value);
|
11650 | break;
|
11651 |
|
11652 | case "D":
|
11653 | this.setDash(value[0], value[1]);
|
11654 | break;
|
11655 |
|
11656 | case "RI":
|
11657 | this.setRenderingIntent(value);
|
11658 | break;
|
11659 |
|
11660 | case "FL":
|
11661 | this.setFlatness(value);
|
11662 | break;
|
11663 |
|
11664 | case "Font":
|
11665 | this.setFont(value);
|
11666 | break;
|
11667 |
|
11668 | case "CA":
|
11669 | this.setStrokeAlpha(value);
|
11670 | break;
|
11671 |
|
11672 | case "ca":
|
11673 | this.setFillAlpha(value);
|
11674 | break;
|
11675 |
|
11676 | default:
|
11677 | (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
|
11678 | break;
|
11679 | }
|
11680 | }
|
11681 | }
|
11682 |
|
11683 | fill() {
|
11684 | const current = this.current;
|
11685 |
|
11686 | if (current.element) {
|
11687 | current.element.setAttributeNS(null, "fill", current.fillColor);
|
11688 | current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
|
11689 | this.endPath();
|
11690 | }
|
11691 | }
|
11692 |
|
11693 | stroke() {
|
11694 | const current = this.current;
|
11695 |
|
11696 | if (current.element) {
|
11697 | this._setStrokeAttributes(current.element);
|
11698 |
|
11699 | current.element.setAttributeNS(null, "fill", "none");
|
11700 | this.endPath();
|
11701 | }
|
11702 | }
|
11703 |
|
11704 | _setStrokeAttributes(element, lineWidthScale = 1) {
|
11705 | const current = this.current;
|
11706 | let dashArray = current.dashArray;
|
11707 |
|
11708 | if (lineWidthScale !== 1 && dashArray.length > 0) {
|
11709 | dashArray = dashArray.map(function (value) {
|
11710 | return lineWidthScale * value;
|
11711 | });
|
11712 | }
|
11713 |
|
11714 | element.setAttributeNS(null, "stroke", current.strokeColor);
|
11715 | element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
|
11716 | element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
|
11717 | element.setAttributeNS(null, "stroke-linecap", current.lineCap);
|
11718 | element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
|
11719 | element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
|
11720 | element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
|
11721 | element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
|
11722 | }
|
11723 |
|
11724 | eoFill() {
|
11725 | if (this.current.element) {
|
11726 | this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
|
11727 | }
|
11728 |
|
11729 | this.fill();
|
11730 | }
|
11731 |
|
11732 | fillStroke() {
|
11733 | this.stroke();
|
11734 | this.fill();
|
11735 | }
|
11736 |
|
11737 | eoFillStroke() {
|
11738 | if (this.current.element) {
|
11739 | this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
|
11740 | }
|
11741 |
|
11742 | this.fillStroke();
|
11743 | }
|
11744 |
|
11745 | closeStroke() {
|
11746 | this.closePath();
|
11747 | this.stroke();
|
11748 | }
|
11749 |
|
11750 | closeFillStroke() {
|
11751 | this.closePath();
|
11752 | this.fillStroke();
|
11753 | }
|
11754 |
|
11755 | closeEOFillStroke() {
|
11756 | this.closePath();
|
11757 | this.eoFillStroke();
|
11758 | }
|
11759 |
|
11760 | paintSolidColorImageMask() {
|
11761 | const rect = this.svgFactory.createElement("svg:rect");
|
11762 | rect.setAttributeNS(null, "x", "0");
|
11763 | rect.setAttributeNS(null, "y", "0");
|
11764 | rect.setAttributeNS(null, "width", "1px");
|
11765 | rect.setAttributeNS(null, "height", "1px");
|
11766 | rect.setAttributeNS(null, "fill", this.current.fillColor);
|
11767 |
|
11768 | this._ensureTransformGroup().appendChild(rect);
|
11769 | }
|
11770 |
|
11771 | paintImageXObject(objId) {
|
11772 | const imgData = this.objs.get(objId);
|
11773 |
|
11774 | if (!imgData) {
|
11775 | (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
|
11776 | return;
|
11777 | }
|
11778 |
|
11779 | this.paintInlineImageXObject(imgData);
|
11780 | }
|
11781 |
|
11782 | paintInlineImageXObject(imgData, mask) {
|
11783 | const width = imgData.width;
|
11784 | const height = imgData.height;
|
11785 | const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
|
11786 | const cliprect = this.svgFactory.createElement("svg:rect");
|
11787 | cliprect.setAttributeNS(null, "x", "0");
|
11788 | cliprect.setAttributeNS(null, "y", "0");
|
11789 | cliprect.setAttributeNS(null, "width", pf(width));
|
11790 | cliprect.setAttributeNS(null, "height", pf(height));
|
11791 | this.current.element = cliprect;
|
11792 | this.clip("nonzero");
|
11793 | const imgEl = this.svgFactory.createElement("svg:image");
|
11794 | imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
|
11795 | imgEl.setAttributeNS(null, "x", "0");
|
11796 | imgEl.setAttributeNS(null, "y", pf(-height));
|
11797 | imgEl.setAttributeNS(null, "width", pf(width) + "px");
|
11798 | imgEl.setAttributeNS(null, "height", pf(height) + "px");
|
11799 | imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
|
11800 |
|
11801 | if (mask) {
|
11802 | mask.appendChild(imgEl);
|
11803 | } else {
|
11804 | this._ensureTransformGroup().appendChild(imgEl);
|
11805 | }
|
11806 | }
|
11807 |
|
11808 | paintImageMaskXObject(imgData) {
|
11809 | const current = this.current;
|
11810 | const width = imgData.width;
|
11811 | const height = imgData.height;
|
11812 | const fillColor = current.fillColor;
|
11813 | current.maskId = `mask${maskCount++}`;
|
11814 | const mask = this.svgFactory.createElement("svg:mask");
|
11815 | mask.setAttributeNS(null, "id", current.maskId);
|
11816 | const rect = this.svgFactory.createElement("svg:rect");
|
11817 | rect.setAttributeNS(null, "x", "0");
|
11818 | rect.setAttributeNS(null, "y", "0");
|
11819 | rect.setAttributeNS(null, "width", pf(width));
|
11820 | rect.setAttributeNS(null, "height", pf(height));
|
11821 | rect.setAttributeNS(null, "fill", fillColor);
|
11822 | rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
|
11823 | this.defs.appendChild(mask);
|
11824 |
|
11825 | this._ensureTransformGroup().appendChild(rect);
|
11826 |
|
11827 | this.paintInlineImageXObject(imgData, mask);
|
11828 | }
|
11829 |
|
11830 | paintFormXObjectBegin(matrix, bbox) {
|
11831 | if (Array.isArray(matrix) && matrix.length === 6) {
|
11832 | this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
|
11833 | }
|
11834 |
|
11835 | if (bbox) {
|
11836 | const width = bbox[2] - bbox[0];
|
11837 | const height = bbox[3] - bbox[1];
|
11838 | const cliprect = this.svgFactory.createElement("svg:rect");
|
11839 | cliprect.setAttributeNS(null, "x", bbox[0]);
|
11840 | cliprect.setAttributeNS(null, "y", bbox[1]);
|
11841 | cliprect.setAttributeNS(null, "width", pf(width));
|
11842 | cliprect.setAttributeNS(null, "height", pf(height));
|
11843 | this.current.element = cliprect;
|
11844 | this.clip("nonzero");
|
11845 | this.endPath();
|
11846 | }
|
11847 | }
|
11848 |
|
11849 | paintFormXObjectEnd() {}
|
11850 |
|
11851 | _initialize(viewport) {
|
11852 | const svg = this.svgFactory.create(viewport.width, viewport.height);
|
11853 | const definitions = this.svgFactory.createElement("svg:defs");
|
11854 | svg.appendChild(definitions);
|
11855 | this.defs = definitions;
|
11856 | const rootGroup = this.svgFactory.createElement("svg:g");
|
11857 | rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
|
11858 | svg.appendChild(rootGroup);
|
11859 | this.svg = rootGroup;
|
11860 | return svg;
|
11861 | }
|
11862 |
|
11863 | _ensureClipGroup() {
|
11864 | if (!this.current.clipGroup) {
|
11865 | const clipGroup = this.svgFactory.createElement("svg:g");
|
11866 | clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
|
11867 | this.svg.appendChild(clipGroup);
|
11868 | this.current.clipGroup = clipGroup;
|
11869 | }
|
11870 |
|
11871 | return this.current.clipGroup;
|
11872 | }
|
11873 |
|
11874 | _ensureTransformGroup() {
|
11875 | if (!this.tgrp) {
|
11876 | this.tgrp = this.svgFactory.createElement("svg:g");
|
11877 | this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
|
11878 |
|
11879 | if (this.current.activeClipUrl) {
|
11880 | this._ensureClipGroup().appendChild(this.tgrp);
|
11881 | } else {
|
11882 | this.svg.appendChild(this.tgrp);
|
11883 | }
|
11884 | }
|
11885 |
|
11886 | return this.tgrp;
|
11887 | }
|
11888 |
|
11889 | };
|
11890 | }
|
11891 |
|
11892 | }),
|
11893 |
|
11894 | (function(module, exports, __w_pdfjs_require__) {
|
11895 |
|
11896 | "use strict";
|
11897 |
|
11898 |
|
11899 | Object.defineProperty(exports, "__esModule", {
|
11900 | value: true
|
11901 | });
|
11902 | exports.PDFNodeStream = void 0;
|
11903 |
|
11904 | var _util = __w_pdfjs_require__(2);
|
11905 |
|
11906 | var _network_utils = __w_pdfjs_require__(20);
|
11907 |
|
11908 | ;
|
11909 |
|
11910 | const fs = require("fs");
|
11911 |
|
11912 | const http = require("http");
|
11913 |
|
11914 | const https = require("https");
|
11915 |
|
11916 | const url = require("url");
|
11917 |
|
11918 | const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
|
11919 |
|
11920 | function parseUrl(sourceUrl) {
|
11921 | const parsedUrl = url.parse(sourceUrl);
|
11922 |
|
11923 | if (parsedUrl.protocol === "file:" || parsedUrl.host) {
|
11924 | return parsedUrl;
|
11925 | }
|
11926 |
|
11927 | if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
|
11928 | return url.parse(`file:///${sourceUrl}`);
|
11929 | }
|
11930 |
|
11931 | if (!parsedUrl.host) {
|
11932 | parsedUrl.protocol = "file:";
|
11933 | }
|
11934 |
|
11935 | return parsedUrl;
|
11936 | }
|
11937 |
|
11938 | class PDFNodeStream {
|
11939 | constructor(source) {
|
11940 | this.source = source;
|
11941 | this.url = parseUrl(source.url);
|
11942 | this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
|
11943 | this.isFsUrl = this.url.protocol === "file:";
|
11944 | this.httpHeaders = this.isHttp && source.httpHeaders || {};
|
11945 | this._fullRequestReader = null;
|
11946 | this._rangeRequestReaders = [];
|
11947 | }
|
11948 |
|
11949 | get _progressiveDataLength() {
|
11950 | return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
|
11951 | }
|
11952 |
|
11953 | getFullReader() {
|
11954 | (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
|
11955 | this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
|
11956 | return this._fullRequestReader;
|
11957 | }
|
11958 |
|
11959 | getRangeReader(start, end) {
|
11960 | if (end <= this._progressiveDataLength) {
|
11961 | return null;
|
11962 | }
|
11963 |
|
11964 | const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
|
11965 |
|
11966 | this._rangeRequestReaders.push(rangeReader);
|
11967 |
|
11968 | return rangeReader;
|
11969 | }
|
11970 |
|
11971 | cancelAllRequests(reason) {
|
11972 | if (this._fullRequestReader) {
|
11973 | this._fullRequestReader.cancel(reason);
|
11974 | }
|
11975 |
|
11976 | const readers = this._rangeRequestReaders.slice(0);
|
11977 |
|
11978 | readers.forEach(function (reader) {
|
11979 | reader.cancel(reason);
|
11980 | });
|
11981 | }
|
11982 |
|
11983 | }
|
11984 |
|
11985 | exports.PDFNodeStream = PDFNodeStream;
|
11986 |
|
11987 | class BaseFullReader {
|
11988 | constructor(stream) {
|
11989 | this._url = stream.url;
|
11990 | this._done = false;
|
11991 | this._storedError = null;
|
11992 | this.onProgress = null;
|
11993 | const source = stream.source;
|
11994 | this._contentLength = source.length;
|
11995 | this._loaded = 0;
|
11996 | this._filename = null;
|
11997 | this._disableRange = source.disableRange || false;
|
11998 | this._rangeChunkSize = source.rangeChunkSize;
|
11999 |
|
12000 | if (!this._rangeChunkSize && !this._disableRange) {
|
12001 | this._disableRange = true;
|
12002 | }
|
12003 |
|
12004 | this._isStreamingSupported = !source.disableStream;
|
12005 | this._isRangeSupported = !source.disableRange;
|
12006 | this._readableStream = null;
|
12007 | this._readCapability = (0, _util.createPromiseCapability)();
|
12008 | this._headersCapability = (0, _util.createPromiseCapability)();
|
12009 | }
|
12010 |
|
12011 | get headersReady() {
|
12012 | return this._headersCapability.promise;
|
12013 | }
|
12014 |
|
12015 | get filename() {
|
12016 | return this._filename;
|
12017 | }
|
12018 |
|
12019 | get contentLength() {
|
12020 | return this._contentLength;
|
12021 | }
|
12022 |
|
12023 | get isRangeSupported() {
|
12024 | return this._isRangeSupported;
|
12025 | }
|
12026 |
|
12027 | get isStreamingSupported() {
|
12028 | return this._isStreamingSupported;
|
12029 | }
|
12030 |
|
12031 | async read() {
|
12032 | await this._readCapability.promise;
|
12033 |
|
12034 | if (this._done) {
|
12035 | return {
|
12036 | value: undefined,
|
12037 | done: true
|
12038 | };
|
12039 | }
|
12040 |
|
12041 | if (this._storedError) {
|
12042 | throw this._storedError;
|
12043 | }
|
12044 |
|
12045 | const chunk = this._readableStream.read();
|
12046 |
|
12047 | if (chunk === null) {
|
12048 | this._readCapability = (0, _util.createPromiseCapability)();
|
12049 | return this.read();
|
12050 | }
|
12051 |
|
12052 | this._loaded += chunk.length;
|
12053 |
|
12054 | if (this.onProgress) {
|
12055 | this.onProgress({
|
12056 | loaded: this._loaded,
|
12057 | total: this._contentLength
|
12058 | });
|
12059 | }
|
12060 |
|
12061 | const buffer = new Uint8Array(chunk).buffer;
|
12062 | return {
|
12063 | value: buffer,
|
12064 | done: false
|
12065 | };
|
12066 | }
|
12067 |
|
12068 | cancel(reason) {
|
12069 | if (!this._readableStream) {
|
12070 | this._error(reason);
|
12071 |
|
12072 | return;
|
12073 | }
|
12074 |
|
12075 | this._readableStream.destroy(reason);
|
12076 | }
|
12077 |
|
12078 | _error(reason) {
|
12079 | this._storedError = reason;
|
12080 |
|
12081 | this._readCapability.resolve();
|
12082 | }
|
12083 |
|
12084 | _setReadableStream(readableStream) {
|
12085 | this._readableStream = readableStream;
|
12086 | readableStream.on("readable", () => {
|
12087 | this._readCapability.resolve();
|
12088 | });
|
12089 | readableStream.on("end", () => {
|
12090 | readableStream.destroy();
|
12091 | this._done = true;
|
12092 |
|
12093 | this._readCapability.resolve();
|
12094 | });
|
12095 | readableStream.on("error", reason => {
|
12096 | this._error(reason);
|
12097 | });
|
12098 |
|
12099 | if (!this._isStreamingSupported && this._isRangeSupported) {
|
12100 | this._error(new _util.AbortException("streaming is disabled"));
|
12101 | }
|
12102 |
|
12103 | if (this._storedError) {
|
12104 | this._readableStream.destroy(this._storedError);
|
12105 | }
|
12106 | }
|
12107 |
|
12108 | }
|
12109 |
|
12110 | class BaseRangeReader {
|
12111 | constructor(stream) {
|
12112 | this._url = stream.url;
|
12113 | this._done = false;
|
12114 | this._storedError = null;
|
12115 | this.onProgress = null;
|
12116 | this._loaded = 0;
|
12117 | this._readableStream = null;
|
12118 | this._readCapability = (0, _util.createPromiseCapability)();
|
12119 | const source = stream.source;
|
12120 | this._isStreamingSupported = !source.disableStream;
|
12121 | }
|
12122 |
|
12123 | get isStreamingSupported() {
|
12124 | return this._isStreamingSupported;
|
12125 | }
|
12126 |
|
12127 | async read() {
|
12128 | await this._readCapability.promise;
|
12129 |
|
12130 | if (this._done) {
|
12131 | return {
|
12132 | value: undefined,
|
12133 | done: true
|
12134 | };
|
12135 | }
|
12136 |
|
12137 | if (this._storedError) {
|
12138 | throw this._storedError;
|
12139 | }
|
12140 |
|
12141 | const chunk = this._readableStream.read();
|
12142 |
|
12143 | if (chunk === null) {
|
12144 | this._readCapability = (0, _util.createPromiseCapability)();
|
12145 | return this.read();
|
12146 | }
|
12147 |
|
12148 | this._loaded += chunk.length;
|
12149 |
|
12150 | if (this.onProgress) {
|
12151 | this.onProgress({
|
12152 | loaded: this._loaded
|
12153 | });
|
12154 | }
|
12155 |
|
12156 | const buffer = new Uint8Array(chunk).buffer;
|
12157 | return {
|
12158 | value: buffer,
|
12159 | done: false
|
12160 | };
|
12161 | }
|
12162 |
|
12163 | cancel(reason) {
|
12164 | if (!this._readableStream) {
|
12165 | this._error(reason);
|
12166 |
|
12167 | return;
|
12168 | }
|
12169 |
|
12170 | this._readableStream.destroy(reason);
|
12171 | }
|
12172 |
|
12173 | _error(reason) {
|
12174 | this._storedError = reason;
|
12175 |
|
12176 | this._readCapability.resolve();
|
12177 | }
|
12178 |
|
12179 | _setReadableStream(readableStream) {
|
12180 | this._readableStream = readableStream;
|
12181 | readableStream.on("readable", () => {
|
12182 | this._readCapability.resolve();
|
12183 | });
|
12184 | readableStream.on("end", () => {
|
12185 | readableStream.destroy();
|
12186 | this._done = true;
|
12187 |
|
12188 | this._readCapability.resolve();
|
12189 | });
|
12190 | readableStream.on("error", reason => {
|
12191 | this._error(reason);
|
12192 | });
|
12193 |
|
12194 | if (this._storedError) {
|
12195 | this._readableStream.destroy(this._storedError);
|
12196 | }
|
12197 | }
|
12198 |
|
12199 | }
|
12200 |
|
12201 | function createRequestOptions(parsedUrl, headers) {
|
12202 | return {
|
12203 | protocol: parsedUrl.protocol,
|
12204 | auth: parsedUrl.auth,
|
12205 | host: parsedUrl.hostname,
|
12206 | port: parsedUrl.port,
|
12207 | path: parsedUrl.path,
|
12208 | method: "GET",
|
12209 | headers
|
12210 | };
|
12211 | }
|
12212 |
|
12213 | class PDFNodeStreamFullReader extends BaseFullReader {
|
12214 | constructor(stream) {
|
12215 | super(stream);
|
12216 |
|
12217 | const handleResponse = response => {
|
12218 | if (response.statusCode === 404) {
|
12219 | const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
12220 | this._storedError = error;
|
12221 |
|
12222 | this._headersCapability.reject(error);
|
12223 |
|
12224 | return;
|
12225 | }
|
12226 |
|
12227 | this._headersCapability.resolve();
|
12228 |
|
12229 | this._setReadableStream(response);
|
12230 |
|
12231 | const getResponseHeader = name => {
|
12232 | return this._readableStream.headers[name.toLowerCase()];
|
12233 | };
|
12234 |
|
12235 | const {
|
12236 | allowRangeRequests,
|
12237 | suggestedLength
|
12238 | } = (0, _network_utils.validateRangeRequestCapabilities)({
|
12239 | getResponseHeader,
|
12240 | isHttp: stream.isHttp,
|
12241 | rangeChunkSize: this._rangeChunkSize,
|
12242 | disableRange: this._disableRange
|
12243 | });
|
12244 | this._isRangeSupported = allowRangeRequests;
|
12245 | this._contentLength = suggestedLength || this._contentLength;
|
12246 | this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
12247 | };
|
12248 |
|
12249 | this._request = null;
|
12250 |
|
12251 | if (this._url.protocol === "http:") {
|
12252 | this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
12253 | } else {
|
12254 | this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
12255 | }
|
12256 |
|
12257 | this._request.on("error", reason => {
|
12258 | this._storedError = reason;
|
12259 |
|
12260 | this._headersCapability.reject(reason);
|
12261 | });
|
12262 |
|
12263 | this._request.end();
|
12264 | }
|
12265 |
|
12266 | }
|
12267 |
|
12268 | class PDFNodeStreamRangeReader extends BaseRangeReader {
|
12269 | constructor(stream, start, end) {
|
12270 | super(stream);
|
12271 | this._httpHeaders = {};
|
12272 |
|
12273 | for (const property in stream.httpHeaders) {
|
12274 | const value = stream.httpHeaders[property];
|
12275 |
|
12276 | if (typeof value === "undefined") {
|
12277 | continue;
|
12278 | }
|
12279 |
|
12280 | this._httpHeaders[property] = value;
|
12281 | }
|
12282 |
|
12283 | this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
|
12284 |
|
12285 | const handleResponse = response => {
|
12286 | if (response.statusCode === 404) {
|
12287 | const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
12288 | this._storedError = error;
|
12289 | return;
|
12290 | }
|
12291 |
|
12292 | this._setReadableStream(response);
|
12293 | };
|
12294 |
|
12295 | this._request = null;
|
12296 |
|
12297 | if (this._url.protocol === "http:") {
|
12298 | this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
12299 | } else {
|
12300 | this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
12301 | }
|
12302 |
|
12303 | this._request.on("error", reason => {
|
12304 | this._storedError = reason;
|
12305 | });
|
12306 |
|
12307 | this._request.end();
|
12308 | }
|
12309 |
|
12310 | }
|
12311 |
|
12312 | class PDFNodeStreamFsFullReader extends BaseFullReader {
|
12313 | constructor(stream) {
|
12314 | super(stream);
|
12315 | let path = decodeURIComponent(this._url.path);
|
12316 |
|
12317 | if (fileUriRegex.test(this._url.href)) {
|
12318 | path = path.replace(/^\//, "");
|
12319 | }
|
12320 |
|
12321 | fs.lstat(path, (error, stat) => {
|
12322 | if (error) {
|
12323 | if (error.code === "ENOENT") {
|
12324 | error = new _util.MissingPDFException(`Missing PDF "${path}".`);
|
12325 | }
|
12326 |
|
12327 | this._storedError = error;
|
12328 |
|
12329 | this._headersCapability.reject(error);
|
12330 |
|
12331 | return;
|
12332 | }
|
12333 |
|
12334 | this._contentLength = stat.size;
|
12335 |
|
12336 | this._setReadableStream(fs.createReadStream(path));
|
12337 |
|
12338 | this._headersCapability.resolve();
|
12339 | });
|
12340 | }
|
12341 |
|
12342 | }
|
12343 |
|
12344 | class PDFNodeStreamFsRangeReader extends BaseRangeReader {
|
12345 | constructor(stream, start, end) {
|
12346 | super(stream);
|
12347 | let path = decodeURIComponent(this._url.path);
|
12348 |
|
12349 | if (fileUriRegex.test(this._url.href)) {
|
12350 | path = path.replace(/^\//, "");
|
12351 | }
|
12352 |
|
12353 | this._setReadableStream(fs.createReadStream(path, {
|
12354 | start,
|
12355 | end: end - 1
|
12356 | }));
|
12357 | }
|
12358 |
|
12359 | }
|
12360 |
|
12361 | }),
|
12362 |
|
12363 | (function(module, exports, __w_pdfjs_require__) {
|
12364 |
|
12365 | "use strict";
|
12366 |
|
12367 |
|
12368 | Object.defineProperty(exports, "__esModule", {
|
12369 | value: true
|
12370 | });
|
12371 | exports.createResponseStatusError = createResponseStatusError;
|
12372 | exports.extractFilenameFromHeader = extractFilenameFromHeader;
|
12373 | exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
|
12374 | exports.validateResponseStatus = validateResponseStatus;
|
12375 |
|
12376 | var _util = __w_pdfjs_require__(2);
|
12377 |
|
12378 | var _content_disposition = __w_pdfjs_require__(21);
|
12379 |
|
12380 | function validateRangeRequestCapabilities({
|
12381 | getResponseHeader,
|
12382 | isHttp,
|
12383 | rangeChunkSize,
|
12384 | disableRange
|
12385 | }) {
|
12386 | (0, _util.assert)(rangeChunkSize > 0, "Range chunk size must be larger than zero");
|
12387 | const returnValues = {
|
12388 | allowRangeRequests: false,
|
12389 | suggestedLength: undefined
|
12390 | };
|
12391 | const length = parseInt(getResponseHeader("Content-Length"), 10);
|
12392 |
|
12393 | if (!Number.isInteger(length)) {
|
12394 | return returnValues;
|
12395 | }
|
12396 |
|
12397 | returnValues.suggestedLength = length;
|
12398 |
|
12399 | if (length <= 2 * rangeChunkSize) {
|
12400 | return returnValues;
|
12401 | }
|
12402 |
|
12403 | if (disableRange || !isHttp) {
|
12404 | return returnValues;
|
12405 | }
|
12406 |
|
12407 | if (getResponseHeader("Accept-Ranges") !== "bytes") {
|
12408 | return returnValues;
|
12409 | }
|
12410 |
|
12411 | const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
|
12412 |
|
12413 | if (contentEncoding !== "identity") {
|
12414 | return returnValues;
|
12415 | }
|
12416 |
|
12417 | returnValues.allowRangeRequests = true;
|
12418 | return returnValues;
|
12419 | }
|
12420 |
|
12421 | function extractFilenameFromHeader(getResponseHeader) {
|
12422 | const contentDisposition = getResponseHeader("Content-Disposition");
|
12423 |
|
12424 | if (contentDisposition) {
|
12425 | let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
|
12426 |
|
12427 | if (filename.includes("%")) {
|
12428 | try {
|
12429 | filename = decodeURIComponent(filename);
|
12430 | } catch (ex) {}
|
12431 | }
|
12432 |
|
12433 | if (/\.pdf$/i.test(filename)) {
|
12434 | return filename;
|
12435 | }
|
12436 | }
|
12437 |
|
12438 | return null;
|
12439 | }
|
12440 |
|
12441 | function createResponseStatusError(status, url) {
|
12442 | if (status === 404 || status === 0 && url.startsWith("file:")) {
|
12443 | return new _util.MissingPDFException('Missing PDF "' + url + '".');
|
12444 | }
|
12445 |
|
12446 | return new _util.UnexpectedResponseException("Unexpected server response (" + status + ') while retrieving PDF "' + url + '".', status);
|
12447 | }
|
12448 |
|
12449 | function validateResponseStatus(status) {
|
12450 | return status === 200 || status === 206;
|
12451 | }
|
12452 |
|
12453 | }),
|
12454 |
|
12455 | (function(module, exports, __w_pdfjs_require__) {
|
12456 |
|
12457 | "use strict";
|
12458 |
|
12459 |
|
12460 | Object.defineProperty(exports, "__esModule", {
|
12461 | value: true
|
12462 | });
|
12463 | exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
|
12464 |
|
12465 | function getFilenameFromContentDispositionHeader(contentDisposition) {
|
12466 | let needsEncodingFixup = true;
|
12467 | let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
|
12468 |
|
12469 | if (tmp) {
|
12470 | tmp = tmp[1];
|
12471 | let filename = rfc2616unquote(tmp);
|
12472 | filename = unescape(filename);
|
12473 | filename = rfc5987decode(filename);
|
12474 | filename = rfc2047decode(filename);
|
12475 | return fixupEncoding(filename);
|
12476 | }
|
12477 |
|
12478 | tmp = rfc2231getparam(contentDisposition);
|
12479 |
|
12480 | if (tmp) {
|
12481 | const filename = rfc2047decode(tmp);
|
12482 | return fixupEncoding(filename);
|
12483 | }
|
12484 |
|
12485 | tmp = toParamRegExp("filename", "i").exec(contentDisposition);
|
12486 |
|
12487 | if (tmp) {
|
12488 | tmp = tmp[1];
|
12489 | let filename = rfc2616unquote(tmp);
|
12490 | filename = rfc2047decode(filename);
|
12491 | return fixupEncoding(filename);
|
12492 | }
|
12493 |
|
12494 | function toParamRegExp(attributePattern, flags) {
|
12495 | return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
|
12496 | }
|
12497 |
|
12498 | function textdecode(encoding, value) {
|
12499 | if (encoding) {
|
12500 | if (!/^[\x00-\xFF]+$/.test(value)) {
|
12501 | return value;
|
12502 | }
|
12503 |
|
12504 | try {
|
12505 | const decoder = new TextDecoder(encoding, {
|
12506 | fatal: true
|
12507 | });
|
12508 | const bytes = Array.from(value, function (ch) {
|
12509 | return ch.charCodeAt(0) & 0xff;
|
12510 | });
|
12511 | value = decoder.decode(new Uint8Array(bytes));
|
12512 | needsEncodingFixup = false;
|
12513 | } catch (e) {
|
12514 | if (/^utf-?8$/i.test(encoding)) {
|
12515 | try {
|
12516 | value = decodeURIComponent(escape(value));
|
12517 | needsEncodingFixup = false;
|
12518 | } catch (err) {}
|
12519 | }
|
12520 | }
|
12521 | }
|
12522 |
|
12523 | return value;
|
12524 | }
|
12525 |
|
12526 | function fixupEncoding(value) {
|
12527 | if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
|
12528 | value = textdecode("utf-8", value);
|
12529 |
|
12530 | if (needsEncodingFixup) {
|
12531 | value = textdecode("iso-8859-1", value);
|
12532 | }
|
12533 | }
|
12534 |
|
12535 | return value;
|
12536 | }
|
12537 |
|
12538 | function rfc2231getparam(contentDispositionStr) {
|
12539 | const matches = [];
|
12540 | let match;
|
12541 | const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
|
12542 |
|
12543 | while ((match = iter.exec(contentDispositionStr)) !== null) {
|
12544 | let [, n, quot, part] = match;
|
12545 | n = parseInt(n, 10);
|
12546 |
|
12547 | if (n in matches) {
|
12548 | if (n === 0) {
|
12549 | break;
|
12550 | }
|
12551 |
|
12552 | continue;
|
12553 | }
|
12554 |
|
12555 | matches[n] = [quot, part];
|
12556 | }
|
12557 |
|
12558 | const parts = [];
|
12559 |
|
12560 | for (let n = 0; n < matches.length; ++n) {
|
12561 | if (!(n in matches)) {
|
12562 | break;
|
12563 | }
|
12564 |
|
12565 | let [quot, part] = matches[n];
|
12566 | part = rfc2616unquote(part);
|
12567 |
|
12568 | if (quot) {
|
12569 | part = unescape(part);
|
12570 |
|
12571 | if (n === 0) {
|
12572 | part = rfc5987decode(part);
|
12573 | }
|
12574 | }
|
12575 |
|
12576 | parts.push(part);
|
12577 | }
|
12578 |
|
12579 | return parts.join("");
|
12580 | }
|
12581 |
|
12582 | function rfc2616unquote(value) {
|
12583 | if (value.startsWith('"')) {
|
12584 | const parts = value.slice(1).split('\\"');
|
12585 |
|
12586 | for (let i = 0; i < parts.length; ++i) {
|
12587 | const quotindex = parts[i].indexOf('"');
|
12588 |
|
12589 | if (quotindex !== -1) {
|
12590 | parts[i] = parts[i].slice(0, quotindex);
|
12591 | parts.length = i + 1;
|
12592 | }
|
12593 |
|
12594 | parts[i] = parts[i].replace(/\\(.)/g, "$1");
|
12595 | }
|
12596 |
|
12597 | value = parts.join('"');
|
12598 | }
|
12599 |
|
12600 | return value;
|
12601 | }
|
12602 |
|
12603 | function rfc5987decode(extvalue) {
|
12604 | const encodingend = extvalue.indexOf("'");
|
12605 |
|
12606 | if (encodingend === -1) {
|
12607 | return extvalue;
|
12608 | }
|
12609 |
|
12610 | const encoding = extvalue.slice(0, encodingend);
|
12611 | const langvalue = extvalue.slice(encodingend + 1);
|
12612 | const value = langvalue.replace(/^[^']*'/, "");
|
12613 | return textdecode(encoding, value);
|
12614 | }
|
12615 |
|
12616 | function rfc2047decode(value) {
|
12617 | if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
|
12618 | return value;
|
12619 | }
|
12620 |
|
12621 | return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
|
12622 | if (encoding === "q" || encoding === "Q") {
|
12623 | text = text.replace(/_/g, " ");
|
12624 | text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
|
12625 | return String.fromCharCode(parseInt(hex, 16));
|
12626 | });
|
12627 | return textdecode(charset, text);
|
12628 | }
|
12629 |
|
12630 | try {
|
12631 | text = atob(text);
|
12632 | } catch (e) {}
|
12633 |
|
12634 | return textdecode(charset, text);
|
12635 | });
|
12636 | }
|
12637 |
|
12638 | return "";
|
12639 | }
|
12640 |
|
12641 | }),
|
12642 |
|
12643 | (function(module, exports, __w_pdfjs_require__) {
|
12644 |
|
12645 | "use strict";
|
12646 |
|
12647 |
|
12648 | Object.defineProperty(exports, "__esModule", {
|
12649 | value: true
|
12650 | });
|
12651 | exports.PDFNetworkStream = void 0;
|
12652 |
|
12653 | var _util = __w_pdfjs_require__(2);
|
12654 |
|
12655 | var _network_utils = __w_pdfjs_require__(20);
|
12656 |
|
12657 | ;
|
12658 | const OK_RESPONSE = 200;
|
12659 | const PARTIAL_CONTENT_RESPONSE = 206;
|
12660 |
|
12661 | function getArrayBuffer(xhr) {
|
12662 | const data = xhr.response;
|
12663 |
|
12664 | if (typeof data !== "string") {
|
12665 | return data;
|
12666 | }
|
12667 |
|
12668 | const array = (0, _util.stringToBytes)(data);
|
12669 | return array.buffer;
|
12670 | }
|
12671 |
|
12672 | class NetworkManager {
|
12673 | constructor(url, args) {
|
12674 | this.url = url;
|
12675 | args = args || {};
|
12676 | this.isHttp = /^https?:/i.test(url);
|
12677 | this.httpHeaders = this.isHttp && args.httpHeaders || {};
|
12678 | this.withCredentials = args.withCredentials || false;
|
12679 |
|
12680 | this.getXhr = args.getXhr || function NetworkManager_getXhr() {
|
12681 | return new XMLHttpRequest();
|
12682 | };
|
12683 |
|
12684 | this.currXhrId = 0;
|
12685 | this.pendingRequests = Object.create(null);
|
12686 | }
|
12687 |
|
12688 | requestRange(begin, end, listeners) {
|
12689 | const args = {
|
12690 | begin,
|
12691 | end
|
12692 | };
|
12693 |
|
12694 | for (const prop in listeners) {
|
12695 | args[prop] = listeners[prop];
|
12696 | }
|
12697 |
|
12698 | return this.request(args);
|
12699 | }
|
12700 |
|
12701 | requestFull(listeners) {
|
12702 | return this.request(listeners);
|
12703 | }
|
12704 |
|
12705 | request(args) {
|
12706 | const xhr = this.getXhr();
|
12707 | const xhrId = this.currXhrId++;
|
12708 | const pendingRequest = this.pendingRequests[xhrId] = {
|
12709 | xhr
|
12710 | };
|
12711 | xhr.open("GET", this.url);
|
12712 | xhr.withCredentials = this.withCredentials;
|
12713 |
|
12714 | for (const property in this.httpHeaders) {
|
12715 | const value = this.httpHeaders[property];
|
12716 |
|
12717 | if (typeof value === "undefined") {
|
12718 | continue;
|
12719 | }
|
12720 |
|
12721 | xhr.setRequestHeader(property, value);
|
12722 | }
|
12723 |
|
12724 | if (this.isHttp && "begin" in args && "end" in args) {
|
12725 | xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
|
12726 | pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
|
12727 | } else {
|
12728 | pendingRequest.expectedStatus = OK_RESPONSE;
|
12729 | }
|
12730 |
|
12731 | xhr.responseType = "arraybuffer";
|
12732 |
|
12733 | if (args.onError) {
|
12734 | xhr.onerror = function (evt) {
|
12735 | args.onError(xhr.status);
|
12736 | };
|
12737 | }
|
12738 |
|
12739 | xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
|
12740 | xhr.onprogress = this.onProgress.bind(this, xhrId);
|
12741 | pendingRequest.onHeadersReceived = args.onHeadersReceived;
|
12742 | pendingRequest.onDone = args.onDone;
|
12743 | pendingRequest.onError = args.onError;
|
12744 | pendingRequest.onProgress = args.onProgress;
|
12745 | xhr.send(null);
|
12746 | return xhrId;
|
12747 | }
|
12748 |
|
12749 | onProgress(xhrId, evt) {
|
12750 | const pendingRequest = this.pendingRequests[xhrId];
|
12751 |
|
12752 | if (!pendingRequest) {
|
12753 | return;
|
12754 | }
|
12755 |
|
12756 | if (pendingRequest.onProgress) {
|
12757 | pendingRequest.onProgress(evt);
|
12758 | }
|
12759 | }
|
12760 |
|
12761 | onStateChange(xhrId, evt) {
|
12762 | const pendingRequest = this.pendingRequests[xhrId];
|
12763 |
|
12764 | if (!pendingRequest) {
|
12765 | return;
|
12766 | }
|
12767 |
|
12768 | const xhr = pendingRequest.xhr;
|
12769 |
|
12770 | if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
|
12771 | pendingRequest.onHeadersReceived();
|
12772 | delete pendingRequest.onHeadersReceived;
|
12773 | }
|
12774 |
|
12775 | if (xhr.readyState !== 4) {
|
12776 | return;
|
12777 | }
|
12778 |
|
12779 | if (!(xhrId in this.pendingRequests)) {
|
12780 | return;
|
12781 | }
|
12782 |
|
12783 | delete this.pendingRequests[xhrId];
|
12784 |
|
12785 | if (xhr.status === 0 && this.isHttp) {
|
12786 | if (pendingRequest.onError) {
|
12787 | pendingRequest.onError(xhr.status);
|
12788 | }
|
12789 |
|
12790 | return;
|
12791 | }
|
12792 |
|
12793 | const xhrStatus = xhr.status || OK_RESPONSE;
|
12794 | const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
|
12795 |
|
12796 | if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
|
12797 | if (pendingRequest.onError) {
|
12798 | pendingRequest.onError(xhr.status);
|
12799 | }
|
12800 |
|
12801 | return;
|
12802 | }
|
12803 |
|
12804 | const chunk = getArrayBuffer(xhr);
|
12805 |
|
12806 | if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
|
12807 | const rangeHeader = xhr.getResponseHeader("Content-Range");
|
12808 | const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
|
12809 | pendingRequest.onDone({
|
12810 | begin: parseInt(matches[1], 10),
|
12811 | chunk
|
12812 | });
|
12813 | } else if (chunk) {
|
12814 | pendingRequest.onDone({
|
12815 | begin: 0,
|
12816 | chunk
|
12817 | });
|
12818 | } else if (pendingRequest.onError) {
|
12819 | pendingRequest.onError(xhr.status);
|
12820 | }
|
12821 | }
|
12822 |
|
12823 | hasPendingRequests() {
|
12824 | for (const xhrId in this.pendingRequests) {
|
12825 | return true;
|
12826 | }
|
12827 |
|
12828 | return false;
|
12829 | }
|
12830 |
|
12831 | getRequestXhr(xhrId) {
|
12832 | return this.pendingRequests[xhrId].xhr;
|
12833 | }
|
12834 |
|
12835 | isPendingRequest(xhrId) {
|
12836 | return xhrId in this.pendingRequests;
|
12837 | }
|
12838 |
|
12839 | abortAllRequests() {
|
12840 | for (const xhrId in this.pendingRequests) {
|
12841 | this.abortRequest(xhrId | 0);
|
12842 | }
|
12843 | }
|
12844 |
|
12845 | abortRequest(xhrId) {
|
12846 | const xhr = this.pendingRequests[xhrId].xhr;
|
12847 | delete this.pendingRequests[xhrId];
|
12848 | xhr.abort();
|
12849 | }
|
12850 |
|
12851 | }
|
12852 |
|
12853 | class PDFNetworkStream {
|
12854 | constructor(source) {
|
12855 | this._source = source;
|
12856 | this._manager = new NetworkManager(source.url, {
|
12857 | httpHeaders: source.httpHeaders,
|
12858 | withCredentials: source.withCredentials
|
12859 | });
|
12860 | this._rangeChunkSize = source.rangeChunkSize;
|
12861 | this._fullRequestReader = null;
|
12862 | this._rangeRequestReaders = [];
|
12863 | }
|
12864 |
|
12865 | _onRangeRequestReaderClosed(reader) {
|
12866 | const i = this._rangeRequestReaders.indexOf(reader);
|
12867 |
|
12868 | if (i >= 0) {
|
12869 | this._rangeRequestReaders.splice(i, 1);
|
12870 | }
|
12871 | }
|
12872 |
|
12873 | getFullReader() {
|
12874 | (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
|
12875 | this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
|
12876 | return this._fullRequestReader;
|
12877 | }
|
12878 |
|
12879 | getRangeReader(begin, end) {
|
12880 | const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
|
12881 | reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
|
12882 |
|
12883 | this._rangeRequestReaders.push(reader);
|
12884 |
|
12885 | return reader;
|
12886 | }
|
12887 |
|
12888 | cancelAllRequests(reason) {
|
12889 | if (this._fullRequestReader) {
|
12890 | this._fullRequestReader.cancel(reason);
|
12891 | }
|
12892 |
|
12893 | const readers = this._rangeRequestReaders.slice(0);
|
12894 |
|
12895 | readers.forEach(function (reader) {
|
12896 | reader.cancel(reason);
|
12897 | });
|
12898 | }
|
12899 |
|
12900 | }
|
12901 |
|
12902 | exports.PDFNetworkStream = PDFNetworkStream;
|
12903 |
|
12904 | class PDFNetworkStreamFullRequestReader {
|
12905 | constructor(manager, source) {
|
12906 | this._manager = manager;
|
12907 | const args = {
|
12908 | onHeadersReceived: this._onHeadersReceived.bind(this),
|
12909 | onDone: this._onDone.bind(this),
|
12910 | onError: this._onError.bind(this),
|
12911 | onProgress: this._onProgress.bind(this)
|
12912 | };
|
12913 | this._url = source.url;
|
12914 | this._fullRequestId = manager.requestFull(args);
|
12915 | this._headersReceivedCapability = (0, _util.createPromiseCapability)();
|
12916 | this._disableRange = source.disableRange || false;
|
12917 | this._contentLength = source.length;
|
12918 | this._rangeChunkSize = source.rangeChunkSize;
|
12919 |
|
12920 | if (!this._rangeChunkSize && !this._disableRange) {
|
12921 | this._disableRange = true;
|
12922 | }
|
12923 |
|
12924 | this._isStreamingSupported = false;
|
12925 | this._isRangeSupported = false;
|
12926 | this._cachedChunks = [];
|
12927 | this._requests = [];
|
12928 | this._done = false;
|
12929 | this._storedError = undefined;
|
12930 | this._filename = null;
|
12931 | this.onProgress = null;
|
12932 | }
|
12933 |
|
12934 | _onHeadersReceived() {
|
12935 | const fullRequestXhrId = this._fullRequestId;
|
12936 |
|
12937 | const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
|
12938 |
|
12939 | const getResponseHeader = name => {
|
12940 | return fullRequestXhr.getResponseHeader(name);
|
12941 | };
|
12942 |
|
12943 | const {
|
12944 | allowRangeRequests,
|
12945 | suggestedLength
|
12946 | } = (0, _network_utils.validateRangeRequestCapabilities)({
|
12947 | getResponseHeader,
|
12948 | isHttp: this._manager.isHttp,
|
12949 | rangeChunkSize: this._rangeChunkSize,
|
12950 | disableRange: this._disableRange
|
12951 | });
|
12952 |
|
12953 | if (allowRangeRequests) {
|
12954 | this._isRangeSupported = true;
|
12955 | }
|
12956 |
|
12957 | this._contentLength = suggestedLength || this._contentLength;
|
12958 | this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
12959 |
|
12960 | if (this._isRangeSupported) {
|
12961 | this._manager.abortRequest(fullRequestXhrId);
|
12962 | }
|
12963 |
|
12964 | this._headersReceivedCapability.resolve();
|
12965 | }
|
12966 |
|
12967 | _onDone(args) {
|
12968 | if (args) {
|
12969 | if (this._requests.length > 0) {
|
12970 | const requestCapability = this._requests.shift();
|
12971 |
|
12972 | requestCapability.resolve({
|
12973 | value: args.chunk,
|
12974 | done: false
|
12975 | });
|
12976 | } else {
|
12977 | this._cachedChunks.push(args.chunk);
|
12978 | }
|
12979 | }
|
12980 |
|
12981 | this._done = true;
|
12982 |
|
12983 | if (this._cachedChunks.length > 0) {
|
12984 | return;
|
12985 | }
|
12986 |
|
12987 | this._requests.forEach(function (requestCapability) {
|
12988 | requestCapability.resolve({
|
12989 | value: undefined,
|
12990 | done: true
|
12991 | });
|
12992 | });
|
12993 |
|
12994 | this._requests = [];
|
12995 | }
|
12996 |
|
12997 | _onError(status) {
|
12998 | const url = this._url;
|
12999 | const exception = (0, _network_utils.createResponseStatusError)(status, url);
|
13000 | this._storedError = exception;
|
13001 |
|
13002 | this._headersReceivedCapability.reject(exception);
|
13003 |
|
13004 | this._requests.forEach(function (requestCapability) {
|
13005 | requestCapability.reject(exception);
|
13006 | });
|
13007 |
|
13008 | this._requests = [];
|
13009 | this._cachedChunks = [];
|
13010 | }
|
13011 |
|
13012 | _onProgress(data) {
|
13013 | if (this.onProgress) {
|
13014 | this.onProgress({
|
13015 | loaded: data.loaded,
|
13016 | total: data.lengthComputable ? data.total : this._contentLength
|
13017 | });
|
13018 | }
|
13019 | }
|
13020 |
|
13021 | get filename() {
|
13022 | return this._filename;
|
13023 | }
|
13024 |
|
13025 | get isRangeSupported() {
|
13026 | return this._isRangeSupported;
|
13027 | }
|
13028 |
|
13029 | get isStreamingSupported() {
|
13030 | return this._isStreamingSupported;
|
13031 | }
|
13032 |
|
13033 | get contentLength() {
|
13034 | return this._contentLength;
|
13035 | }
|
13036 |
|
13037 | get headersReady() {
|
13038 | return this._headersReceivedCapability.promise;
|
13039 | }
|
13040 |
|
13041 | async read() {
|
13042 | if (this._storedError) {
|
13043 | throw this._storedError;
|
13044 | }
|
13045 |
|
13046 | if (this._cachedChunks.length > 0) {
|
13047 | const chunk = this._cachedChunks.shift();
|
13048 |
|
13049 | return {
|
13050 | value: chunk,
|
13051 | done: false
|
13052 | };
|
13053 | }
|
13054 |
|
13055 | if (this._done) {
|
13056 | return {
|
13057 | value: undefined,
|
13058 | done: true
|
13059 | };
|
13060 | }
|
13061 |
|
13062 | const requestCapability = (0, _util.createPromiseCapability)();
|
13063 |
|
13064 | this._requests.push(requestCapability);
|
13065 |
|
13066 | return requestCapability.promise;
|
13067 | }
|
13068 |
|
13069 | cancel(reason) {
|
13070 | this._done = true;
|
13071 |
|
13072 | this._headersReceivedCapability.reject(reason);
|
13073 |
|
13074 | this._requests.forEach(function (requestCapability) {
|
13075 | requestCapability.resolve({
|
13076 | value: undefined,
|
13077 | done: true
|
13078 | });
|
13079 | });
|
13080 |
|
13081 | this._requests = [];
|
13082 |
|
13083 | if (this._manager.isPendingRequest(this._fullRequestId)) {
|
13084 | this._manager.abortRequest(this._fullRequestId);
|
13085 | }
|
13086 |
|
13087 | this._fullRequestReader = null;
|
13088 | }
|
13089 |
|
13090 | }
|
13091 |
|
13092 | class PDFNetworkStreamRangeRequestReader {
|
13093 | constructor(manager, begin, end) {
|
13094 | this._manager = manager;
|
13095 | const args = {
|
13096 | onDone: this._onDone.bind(this),
|
13097 | onProgress: this._onProgress.bind(this)
|
13098 | };
|
13099 | this._requestId = manager.requestRange(begin, end, args);
|
13100 | this._requests = [];
|
13101 | this._queuedChunk = null;
|
13102 | this._done = false;
|
13103 | this.onProgress = null;
|
13104 | this.onClosed = null;
|
13105 | }
|
13106 |
|
13107 | _close() {
|
13108 | if (this.onClosed) {
|
13109 | this.onClosed(this);
|
13110 | }
|
13111 | }
|
13112 |
|
13113 | _onDone(data) {
|
13114 | const chunk = data.chunk;
|
13115 |
|
13116 | if (this._requests.length > 0) {
|
13117 | const requestCapability = this._requests.shift();
|
13118 |
|
13119 | requestCapability.resolve({
|
13120 | value: chunk,
|
13121 | done: false
|
13122 | });
|
13123 | } else {
|
13124 | this._queuedChunk = chunk;
|
13125 | }
|
13126 |
|
13127 | this._done = true;
|
13128 |
|
13129 | this._requests.forEach(function (requestCapability) {
|
13130 | requestCapability.resolve({
|
13131 | value: undefined,
|
13132 | done: true
|
13133 | });
|
13134 | });
|
13135 |
|
13136 | this._requests = [];
|
13137 |
|
13138 | this._close();
|
13139 | }
|
13140 |
|
13141 | _onProgress(evt) {
|
13142 | if (!this.isStreamingSupported && this.onProgress) {
|
13143 | this.onProgress({
|
13144 | loaded: evt.loaded
|
13145 | });
|
13146 | }
|
13147 | }
|
13148 |
|
13149 | get isStreamingSupported() {
|
13150 | return false;
|
13151 | }
|
13152 |
|
13153 | async read() {
|
13154 | if (this._queuedChunk !== null) {
|
13155 | const chunk = this._queuedChunk;
|
13156 | this._queuedChunk = null;
|
13157 | return {
|
13158 | value: chunk,
|
13159 | done: false
|
13160 | };
|
13161 | }
|
13162 |
|
13163 | if (this._done) {
|
13164 | return {
|
13165 | value: undefined,
|
13166 | done: true
|
13167 | };
|
13168 | }
|
13169 |
|
13170 | const requestCapability = (0, _util.createPromiseCapability)();
|
13171 |
|
13172 | this._requests.push(requestCapability);
|
13173 |
|
13174 | return requestCapability.promise;
|
13175 | }
|
13176 |
|
13177 | cancel(reason) {
|
13178 | this._done = true;
|
13179 |
|
13180 | this._requests.forEach(function (requestCapability) {
|
13181 | requestCapability.resolve({
|
13182 | value: undefined,
|
13183 | done: true
|
13184 | });
|
13185 | });
|
13186 |
|
13187 | this._requests = [];
|
13188 |
|
13189 | if (this._manager.isPendingRequest(this._requestId)) {
|
13190 | this._manager.abortRequest(this._requestId);
|
13191 | }
|
13192 |
|
13193 | this._close();
|
13194 | }
|
13195 |
|
13196 | }
|
13197 |
|
13198 | }),
|
13199 |
|
13200 | (function(module, exports, __w_pdfjs_require__) {
|
13201 |
|
13202 | "use strict";
|
13203 |
|
13204 |
|
13205 | Object.defineProperty(exports, "__esModule", {
|
13206 | value: true
|
13207 | });
|
13208 | exports.PDFFetchStream = void 0;
|
13209 |
|
13210 | var _util = __w_pdfjs_require__(2);
|
13211 |
|
13212 | var _network_utils = __w_pdfjs_require__(20);
|
13213 |
|
13214 | ;
|
13215 |
|
13216 | function createFetchOptions(headers, withCredentials, abortController) {
|
13217 | return {
|
13218 | method: "GET",
|
13219 | headers,
|
13220 | signal: abortController && abortController.signal,
|
13221 | mode: "cors",
|
13222 | credentials: withCredentials ? "include" : "same-origin",
|
13223 | redirect: "follow"
|
13224 | };
|
13225 | }
|
13226 |
|
13227 | function createHeaders(httpHeaders) {
|
13228 | const headers = new Headers();
|
13229 |
|
13230 | for (const property in httpHeaders) {
|
13231 | const value = httpHeaders[property];
|
13232 |
|
13233 | if (typeof value === "undefined") {
|
13234 | continue;
|
13235 | }
|
13236 |
|
13237 | headers.append(property, value);
|
13238 | }
|
13239 |
|
13240 | return headers;
|
13241 | }
|
13242 |
|
13243 | class PDFFetchStream {
|
13244 | constructor(source) {
|
13245 | this.source = source;
|
13246 | this.isHttp = /^https?:/i.test(source.url);
|
13247 | this.httpHeaders = this.isHttp && source.httpHeaders || {};
|
13248 | this._fullRequestReader = null;
|
13249 | this._rangeRequestReaders = [];
|
13250 | }
|
13251 |
|
13252 | get _progressiveDataLength() {
|
13253 | return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
|
13254 | }
|
13255 |
|
13256 | getFullReader() {
|
13257 | (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
|
13258 | this._fullRequestReader = new PDFFetchStreamReader(this);
|
13259 | return this._fullRequestReader;
|
13260 | }
|
13261 |
|
13262 | getRangeReader(begin, end) {
|
13263 | if (end <= this._progressiveDataLength) {
|
13264 | return null;
|
13265 | }
|
13266 |
|
13267 | const reader = new PDFFetchStreamRangeReader(this, begin, end);
|
13268 |
|
13269 | this._rangeRequestReaders.push(reader);
|
13270 |
|
13271 | return reader;
|
13272 | }
|
13273 |
|
13274 | cancelAllRequests(reason) {
|
13275 | if (this._fullRequestReader) {
|
13276 | this._fullRequestReader.cancel(reason);
|
13277 | }
|
13278 |
|
13279 | const readers = this._rangeRequestReaders.slice(0);
|
13280 |
|
13281 | readers.forEach(function (reader) {
|
13282 | reader.cancel(reason);
|
13283 | });
|
13284 | }
|
13285 |
|
13286 | }
|
13287 |
|
13288 | exports.PDFFetchStream = PDFFetchStream;
|
13289 |
|
13290 | class PDFFetchStreamReader {
|
13291 | constructor(stream) {
|
13292 | this._stream = stream;
|
13293 | this._reader = null;
|
13294 | this._loaded = 0;
|
13295 | this._filename = null;
|
13296 | const source = stream.source;
|
13297 | this._withCredentials = source.withCredentials || false;
|
13298 | this._contentLength = source.length;
|
13299 | this._headersCapability = (0, _util.createPromiseCapability)();
|
13300 | this._disableRange = source.disableRange || false;
|
13301 | this._rangeChunkSize = source.rangeChunkSize;
|
13302 |
|
13303 | if (!this._rangeChunkSize && !this._disableRange) {
|
13304 | this._disableRange = true;
|
13305 | }
|
13306 |
|
13307 | if (typeof AbortController !== "undefined") {
|
13308 | this._abortController = new AbortController();
|
13309 | }
|
13310 |
|
13311 | this._isStreamingSupported = !source.disableStream;
|
13312 | this._isRangeSupported = !source.disableRange;
|
13313 | this._headers = createHeaders(this._stream.httpHeaders);
|
13314 | const url = source.url;
|
13315 | fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
|
13316 | if (!(0, _network_utils.validateResponseStatus)(response.status)) {
|
13317 | throw (0, _network_utils.createResponseStatusError)(response.status, url);
|
13318 | }
|
13319 |
|
13320 | this._reader = response.body.getReader();
|
13321 |
|
13322 | this._headersCapability.resolve();
|
13323 |
|
13324 | const getResponseHeader = name => {
|
13325 | return response.headers.get(name);
|
13326 | };
|
13327 |
|
13328 | const {
|
13329 | allowRangeRequests,
|
13330 | suggestedLength
|
13331 | } = (0, _network_utils.validateRangeRequestCapabilities)({
|
13332 | getResponseHeader,
|
13333 | isHttp: this._stream.isHttp,
|
13334 | rangeChunkSize: this._rangeChunkSize,
|
13335 | disableRange: this._disableRange
|
13336 | });
|
13337 | this._isRangeSupported = allowRangeRequests;
|
13338 | this._contentLength = suggestedLength || this._contentLength;
|
13339 | this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
13340 |
|
13341 | if (!this._isStreamingSupported && this._isRangeSupported) {
|
13342 | this.cancel(new _util.AbortException("Streaming is disabled."));
|
13343 | }
|
13344 | }).catch(this._headersCapability.reject);
|
13345 | this.onProgress = null;
|
13346 | }
|
13347 |
|
13348 | get headersReady() {
|
13349 | return this._headersCapability.promise;
|
13350 | }
|
13351 |
|
13352 | get filename() {
|
13353 | return this._filename;
|
13354 | }
|
13355 |
|
13356 | get contentLength() {
|
13357 | return this._contentLength;
|
13358 | }
|
13359 |
|
13360 | get isRangeSupported() {
|
13361 | return this._isRangeSupported;
|
13362 | }
|
13363 |
|
13364 | get isStreamingSupported() {
|
13365 | return this._isStreamingSupported;
|
13366 | }
|
13367 |
|
13368 | async read() {
|
13369 | await this._headersCapability.promise;
|
13370 | const {
|
13371 | value,
|
13372 | done
|
13373 | } = await this._reader.read();
|
13374 |
|
13375 | if (done) {
|
13376 | return {
|
13377 | value,
|
13378 | done
|
13379 | };
|
13380 | }
|
13381 |
|
13382 | this._loaded += value.byteLength;
|
13383 |
|
13384 | if (this.onProgress) {
|
13385 | this.onProgress({
|
13386 | loaded: this._loaded,
|
13387 | total: this._contentLength
|
13388 | });
|
13389 | }
|
13390 |
|
13391 | const buffer = new Uint8Array(value).buffer;
|
13392 | return {
|
13393 | value: buffer,
|
13394 | done: false
|
13395 | };
|
13396 | }
|
13397 |
|
13398 | cancel(reason) {
|
13399 | if (this._reader) {
|
13400 | this._reader.cancel(reason);
|
13401 | }
|
13402 |
|
13403 | if (this._abortController) {
|
13404 | this._abortController.abort();
|
13405 | }
|
13406 | }
|
13407 |
|
13408 | }
|
13409 |
|
13410 | class PDFFetchStreamRangeReader {
|
13411 | constructor(stream, begin, end) {
|
13412 | this._stream = stream;
|
13413 | this._reader = null;
|
13414 | this._loaded = 0;
|
13415 | const source = stream.source;
|
13416 | this._withCredentials = source.withCredentials || false;
|
13417 | this._readCapability = (0, _util.createPromiseCapability)();
|
13418 | this._isStreamingSupported = !source.disableStream;
|
13419 |
|
13420 | if (typeof AbortController !== "undefined") {
|
13421 | this._abortController = new AbortController();
|
13422 | }
|
13423 |
|
13424 | this._headers = createHeaders(this._stream.httpHeaders);
|
13425 |
|
13426 | this._headers.append("Range", `bytes=${begin}-${end - 1}`);
|
13427 |
|
13428 | const url = source.url;
|
13429 | fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
|
13430 | if (!(0, _network_utils.validateResponseStatus)(response.status)) {
|
13431 | throw (0, _network_utils.createResponseStatusError)(response.status, url);
|
13432 | }
|
13433 |
|
13434 | this._readCapability.resolve();
|
13435 |
|
13436 | this._reader = response.body.getReader();
|
13437 | });
|
13438 | this.onProgress = null;
|
13439 | }
|
13440 |
|
13441 | get isStreamingSupported() {
|
13442 | return this._isStreamingSupported;
|
13443 | }
|
13444 |
|
13445 | async read() {
|
13446 | await this._readCapability.promise;
|
13447 | const {
|
13448 | value,
|
13449 | done
|
13450 | } = await this._reader.read();
|
13451 |
|
13452 | if (done) {
|
13453 | return {
|
13454 | value,
|
13455 | done
|
13456 | };
|
13457 | }
|
13458 |
|
13459 | this._loaded += value.byteLength;
|
13460 |
|
13461 | if (this.onProgress) {
|
13462 | this.onProgress({
|
13463 | loaded: this._loaded
|
13464 | });
|
13465 | }
|
13466 |
|
13467 | const buffer = new Uint8Array(value).buffer;
|
13468 | return {
|
13469 | value: buffer,
|
13470 | done: false
|
13471 | };
|
13472 | }
|
13473 |
|
13474 | cancel(reason) {
|
13475 | if (this._reader) {
|
13476 | this._reader.cancel(reason);
|
13477 | }
|
13478 |
|
13479 | if (this._abortController) {
|
13480 | this._abortController.abort();
|
13481 | }
|
13482 | }
|
13483 |
|
13484 | }
|
13485 |
|
13486 | })
|
13487 | ]);
|
13488 | });
|
13489 |
|
\ | No newline at end of file |