1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.unreachable = exports.warn = exports.utf8StringToString = exports.stringToUTF8String = exports.stringToPDFString = exports.stringToBytes = exports.string32 = exports.shadow = exports.setVerbosityLevel = exports.ReadableStream = exports.removeNullCharacters = exports.readUint32 = exports.readUint16 = exports.readInt8 = exports.log2 = exports.isEvalSupported = exports.isLittleEndian = exports.createValidAbsoluteUrl = exports.isSameOrigin = exports.isSpace = exports.isString = exports.isNum = exports.isEmptyObj = exports.isBool = exports.isArrayBuffer = exports.info = exports.getVerbosityLevel = exports.getLookupTableFactory = exports.getInheritableProperty = exports.deprecated = exports.createObjectURL = exports.createPromiseCapability = exports.createBlob = exports.bytesToString = exports.assert = exports.arraysToBytes = exports.arrayByteLength = exports.FormatError = exports.XRefParseException = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PasswordResponses = exports.PasswordException = exports.PageViewport = exports.NotImplementedException = exports.NativeImageDecoding = exports.MissingPDFException = exports.MissingDataException = exports.MessageHandler = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = undefined;
|
28 |
|
29 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
30 |
|
31 | require('./compatibility');
|
32 |
|
33 | var _streams_polyfill = require('./streams_polyfill');
|
34 |
|
35 | var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
|
36 | var NativeImageDecoding = {
|
37 | NONE: 'none',
|
38 | DECODE: 'decode',
|
39 | DISPLAY: 'display'
|
40 | };
|
41 | var TextRenderingMode = {
|
42 | FILL: 0,
|
43 | STROKE: 1,
|
44 | FILL_STROKE: 2,
|
45 | INVISIBLE: 3,
|
46 | FILL_ADD_TO_PATH: 4,
|
47 | STROKE_ADD_TO_PATH: 5,
|
48 | FILL_STROKE_ADD_TO_PATH: 6,
|
49 | ADD_TO_PATH: 7,
|
50 | FILL_STROKE_MASK: 3,
|
51 | ADD_TO_PATH_FLAG: 4
|
52 | };
|
53 | var ImageKind = {
|
54 | GRAYSCALE_1BPP: 1,
|
55 | RGB_24BPP: 2,
|
56 | RGBA_32BPP: 3
|
57 | };
|
58 | var AnnotationType = {
|
59 | TEXT: 1,
|
60 | LINK: 2,
|
61 | FREETEXT: 3,
|
62 | LINE: 4,
|
63 | SQUARE: 5,
|
64 | CIRCLE: 6,
|
65 | POLYGON: 7,
|
66 | POLYLINE: 8,
|
67 | HIGHLIGHT: 9,
|
68 | UNDERLINE: 10,
|
69 | SQUIGGLY: 11,
|
70 | STRIKEOUT: 12,
|
71 | STAMP: 13,
|
72 | CARET: 14,
|
73 | INK: 15,
|
74 | POPUP: 16,
|
75 | FILEATTACHMENT: 17,
|
76 | SOUND: 18,
|
77 | MOVIE: 19,
|
78 | WIDGET: 20,
|
79 | SCREEN: 21,
|
80 | PRINTERMARK: 22,
|
81 | TRAPNET: 23,
|
82 | WATERMARK: 24,
|
83 | THREED: 25,
|
84 | REDACT: 26
|
85 | };
|
86 | var AnnotationFlag = {
|
87 | INVISIBLE: 0x01,
|
88 | HIDDEN: 0x02,
|
89 | PRINT: 0x04,
|
90 | NOZOOM: 0x08,
|
91 | NOROTATE: 0x10,
|
92 | NOVIEW: 0x20,
|
93 | READONLY: 0x40,
|
94 | LOCKED: 0x80,
|
95 | TOGGLENOVIEW: 0x100,
|
96 | LOCKEDCONTENTS: 0x200
|
97 | };
|
98 | var AnnotationFieldFlag = {
|
99 | READONLY: 0x0000001,
|
100 | REQUIRED: 0x0000002,
|
101 | NOEXPORT: 0x0000004,
|
102 | MULTILINE: 0x0001000,
|
103 | PASSWORD: 0x0002000,
|
104 | NOTOGGLETOOFF: 0x0004000,
|
105 | RADIO: 0x0008000,
|
106 | PUSHBUTTON: 0x0010000,
|
107 | COMBO: 0x0020000,
|
108 | EDIT: 0x0040000,
|
109 | SORT: 0x0080000,
|
110 | FILESELECT: 0x0100000,
|
111 | MULTISELECT: 0x0200000,
|
112 | DONOTSPELLCHECK: 0x0400000,
|
113 | DONOTSCROLL: 0x0800000,
|
114 | COMB: 0x1000000,
|
115 | RICHTEXT: 0x2000000,
|
116 | RADIOSINUNISON: 0x2000000,
|
117 | COMMITONSELCHANGE: 0x4000000
|
118 | };
|
119 | var AnnotationBorderStyleType = {
|
120 | SOLID: 1,
|
121 | DASHED: 2,
|
122 | BEVELED: 3,
|
123 | INSET: 4,
|
124 | UNDERLINE: 5
|
125 | };
|
126 | var StreamType = {
|
127 | UNKNOWN: 0,
|
128 | FLATE: 1,
|
129 | LZW: 2,
|
130 | DCT: 3,
|
131 | JPX: 4,
|
132 | JBIG: 5,
|
133 | A85: 6,
|
134 | AHX: 7,
|
135 | CCF: 8,
|
136 | RL: 9
|
137 | };
|
138 | var FontType = {
|
139 | UNKNOWN: 0,
|
140 | TYPE1: 1,
|
141 | TYPE1C: 2,
|
142 | CIDFONTTYPE0: 3,
|
143 | CIDFONTTYPE0C: 4,
|
144 | TRUETYPE: 5,
|
145 | CIDFONTTYPE2: 6,
|
146 | TYPE3: 7,
|
147 | OPENTYPE: 8,
|
148 | TYPE0: 9,
|
149 | MMTYPE1: 10
|
150 | };
|
151 | var VerbosityLevel = {
|
152 | ERRORS: 0,
|
153 | WARNINGS: 1,
|
154 | INFOS: 5
|
155 | };
|
156 | var CMapCompressionType = {
|
157 | NONE: 0,
|
158 | BINARY: 1,
|
159 | STREAM: 2
|
160 | };
|
161 | var OPS = {
|
162 | dependency: 1,
|
163 | setLineWidth: 2,
|
164 | setLineCap: 3,
|
165 | setLineJoin: 4,
|
166 | setMiterLimit: 5,
|
167 | setDash: 6,
|
168 | setRenderingIntent: 7,
|
169 | setFlatness: 8,
|
170 | setGState: 9,
|
171 | save: 10,
|
172 | restore: 11,
|
173 | transform: 12,
|
174 | moveTo: 13,
|
175 | lineTo: 14,
|
176 | curveTo: 15,
|
177 | curveTo2: 16,
|
178 | curveTo3: 17,
|
179 | closePath: 18,
|
180 | rectangle: 19,
|
181 | stroke: 20,
|
182 | closeStroke: 21,
|
183 | fill: 22,
|
184 | eoFill: 23,
|
185 | fillStroke: 24,
|
186 | eoFillStroke: 25,
|
187 | closeFillStroke: 26,
|
188 | closeEOFillStroke: 27,
|
189 | endPath: 28,
|
190 | clip: 29,
|
191 | eoClip: 30,
|
192 | beginText: 31,
|
193 | endText: 32,
|
194 | setCharSpacing: 33,
|
195 | setWordSpacing: 34,
|
196 | setHScale: 35,
|
197 | setLeading: 36,
|
198 | setFont: 37,
|
199 | setTextRenderingMode: 38,
|
200 | setTextRise: 39,
|
201 | moveText: 40,
|
202 | setLeadingMoveText: 41,
|
203 | setTextMatrix: 42,
|
204 | nextLine: 43,
|
205 | showText: 44,
|
206 | showSpacedText: 45,
|
207 | nextLineShowText: 46,
|
208 | nextLineSetSpacingShowText: 47,
|
209 | setCharWidth: 48,
|
210 | setCharWidthAndBounds: 49,
|
211 | setStrokeColorSpace: 50,
|
212 | setFillColorSpace: 51,
|
213 | setStrokeColor: 52,
|
214 | setStrokeColorN: 53,
|
215 | setFillColor: 54,
|
216 | setFillColorN: 55,
|
217 | setStrokeGray: 56,
|
218 | setFillGray: 57,
|
219 | setStrokeRGBColor: 58,
|
220 | setFillRGBColor: 59,
|
221 | setStrokeCMYKColor: 60,
|
222 | setFillCMYKColor: 61,
|
223 | shadingFill: 62,
|
224 | beginInlineImage: 63,
|
225 | beginImageData: 64,
|
226 | endInlineImage: 65,
|
227 | paintXObject: 66,
|
228 | markPoint: 67,
|
229 | markPointProps: 68,
|
230 | beginMarkedContent: 69,
|
231 | beginMarkedContentProps: 70,
|
232 | endMarkedContent: 71,
|
233 | beginCompat: 72,
|
234 | endCompat: 73,
|
235 | paintFormXObjectBegin: 74,
|
236 | paintFormXObjectEnd: 75,
|
237 | beginGroup: 76,
|
238 | endGroup: 77,
|
239 | beginAnnotations: 78,
|
240 | endAnnotations: 79,
|
241 | beginAnnotation: 80,
|
242 | endAnnotation: 81,
|
243 | paintJpegXObject: 82,
|
244 | paintImageMaskXObject: 83,
|
245 | paintImageMaskXObjectGroup: 84,
|
246 | paintImageXObject: 85,
|
247 | paintInlineImageXObject: 86,
|
248 | paintInlineImageXObjectGroup: 87,
|
249 | paintImageXObjectRepeat: 88,
|
250 | paintImageMaskXObjectRepeat: 89,
|
251 | paintSolidColorImageMask: 90,
|
252 | constructPath: 91
|
253 | };
|
254 | var verbosity = VerbosityLevel.WARNINGS;
|
255 | function setVerbosityLevel(level) {
|
256 | if (Number.isInteger(level)) {
|
257 | verbosity = level;
|
258 | }
|
259 | }
|
260 | function getVerbosityLevel() {
|
261 | return verbosity;
|
262 | }
|
263 | function info(msg) {
|
264 | if (verbosity >= VerbosityLevel.INFOS) {
|
265 | console.log('Info: ' + msg);
|
266 | }
|
267 | }
|
268 | function warn(msg) {
|
269 | if (verbosity >= VerbosityLevel.WARNINGS) {
|
270 | console.log('Warning: ' + msg);
|
271 | }
|
272 | }
|
273 | function deprecated(details) {
|
274 | console.log('Deprecated API usage: ' + details);
|
275 | }
|
276 | function unreachable(msg) {
|
277 | throw new Error(msg);
|
278 | }
|
279 | function assert(cond, msg) {
|
280 | if (!cond) {
|
281 | unreachable(msg);
|
282 | }
|
283 | }
|
284 | var UNSUPPORTED_FEATURES = {
|
285 | unknown: 'unknown',
|
286 | forms: 'forms',
|
287 | javaScript: 'javaScript',
|
288 | smask: 'smask',
|
289 | shadingPattern: 'shadingPattern',
|
290 | font: 'font'
|
291 | };
|
292 | function isSameOrigin(baseUrl, otherUrl) {
|
293 | try {
|
294 | var base = new URL(baseUrl);
|
295 | if (!base.origin || base.origin === 'null') {
|
296 | return false;
|
297 | }
|
298 | } catch (e) {
|
299 | return false;
|
300 | }
|
301 | var other = new URL(otherUrl, base);
|
302 | return base.origin === other.origin;
|
303 | }
|
304 | function isValidProtocol(url) {
|
305 | if (!url) {
|
306 | return false;
|
307 | }
|
308 | switch (url.protocol) {
|
309 | case 'http:':
|
310 | case 'https:':
|
311 | case 'ftp:':
|
312 | case 'mailto:':
|
313 | case 'tel:':
|
314 | return true;
|
315 | default:
|
316 | return false;
|
317 | }
|
318 | }
|
319 | function createValidAbsoluteUrl(url, baseUrl) {
|
320 | if (!url) {
|
321 | return null;
|
322 | }
|
323 | try {
|
324 | var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
|
325 | if (isValidProtocol(absoluteUrl)) {
|
326 | return absoluteUrl;
|
327 | }
|
328 | } catch (ex) {}
|
329 | return null;
|
330 | }
|
331 | function shadow(obj, prop, value) {
|
332 | Object.defineProperty(obj, prop, {
|
333 | value: value,
|
334 | enumerable: true,
|
335 | configurable: true,
|
336 | writable: false
|
337 | });
|
338 | return value;
|
339 | }
|
340 | function getLookupTableFactory(initializer) {
|
341 | var lookup;
|
342 | return function () {
|
343 | if (initializer) {
|
344 | lookup = Object.create(null);
|
345 | initializer(lookup);
|
346 | initializer = null;
|
347 | }
|
348 | return lookup;
|
349 | };
|
350 | }
|
351 | var PasswordResponses = {
|
352 | NEED_PASSWORD: 1,
|
353 | INCORRECT_PASSWORD: 2
|
354 | };
|
355 | var PasswordException = function PasswordExceptionClosure() {
|
356 | function PasswordException(msg, code) {
|
357 | this.name = 'PasswordException';
|
358 | this.message = msg;
|
359 | this.code = code;
|
360 | }
|
361 | PasswordException.prototype = new Error();
|
362 | PasswordException.constructor = PasswordException;
|
363 | return PasswordException;
|
364 | }();
|
365 | var UnknownErrorException = function UnknownErrorExceptionClosure() {
|
366 | function UnknownErrorException(msg, details) {
|
367 | this.name = 'UnknownErrorException';
|
368 | this.message = msg;
|
369 | this.details = details;
|
370 | }
|
371 | UnknownErrorException.prototype = new Error();
|
372 | UnknownErrorException.constructor = UnknownErrorException;
|
373 | return UnknownErrorException;
|
374 | }();
|
375 | var InvalidPDFException = function InvalidPDFExceptionClosure() {
|
376 | function InvalidPDFException(msg) {
|
377 | this.name = 'InvalidPDFException';
|
378 | this.message = msg;
|
379 | }
|
380 | InvalidPDFException.prototype = new Error();
|
381 | InvalidPDFException.constructor = InvalidPDFException;
|
382 | return InvalidPDFException;
|
383 | }();
|
384 | var MissingPDFException = function MissingPDFExceptionClosure() {
|
385 | function MissingPDFException(msg) {
|
386 | this.name = 'MissingPDFException';
|
387 | this.message = msg;
|
388 | }
|
389 | MissingPDFException.prototype = new Error();
|
390 | MissingPDFException.constructor = MissingPDFException;
|
391 | return MissingPDFException;
|
392 | }();
|
393 | var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() {
|
394 | function UnexpectedResponseException(msg, status) {
|
395 | this.name = 'UnexpectedResponseException';
|
396 | this.message = msg;
|
397 | this.status = status;
|
398 | }
|
399 | UnexpectedResponseException.prototype = new Error();
|
400 | UnexpectedResponseException.constructor = UnexpectedResponseException;
|
401 | return UnexpectedResponseException;
|
402 | }();
|
403 | var NotImplementedException = function NotImplementedExceptionClosure() {
|
404 | function NotImplementedException(msg) {
|
405 | this.message = msg;
|
406 | }
|
407 | NotImplementedException.prototype = new Error();
|
408 | NotImplementedException.prototype.name = 'NotImplementedException';
|
409 | NotImplementedException.constructor = NotImplementedException;
|
410 | return NotImplementedException;
|
411 | }();
|
412 | var MissingDataException = function MissingDataExceptionClosure() {
|
413 | function MissingDataException(begin, end) {
|
414 | this.begin = begin;
|
415 | this.end = end;
|
416 | this.message = 'Missing data [' + begin + ', ' + end + ')';
|
417 | }
|
418 | MissingDataException.prototype = new Error();
|
419 | MissingDataException.prototype.name = 'MissingDataException';
|
420 | MissingDataException.constructor = MissingDataException;
|
421 | return MissingDataException;
|
422 | }();
|
423 | var XRefParseException = function XRefParseExceptionClosure() {
|
424 | function XRefParseException(msg) {
|
425 | this.message = msg;
|
426 | }
|
427 | XRefParseException.prototype = new Error();
|
428 | XRefParseException.prototype.name = 'XRefParseException';
|
429 | XRefParseException.constructor = XRefParseException;
|
430 | return XRefParseException;
|
431 | }();
|
432 | var FormatError = function FormatErrorClosure() {
|
433 | function FormatError(msg) {
|
434 | this.message = msg;
|
435 | }
|
436 | FormatError.prototype = new Error();
|
437 | FormatError.prototype.name = 'FormatError';
|
438 | FormatError.constructor = FormatError;
|
439 | return FormatError;
|
440 | }();
|
441 | var AbortException = function AbortExceptionClosure() {
|
442 | function AbortException(msg) {
|
443 | this.name = 'AbortException';
|
444 | this.message = msg;
|
445 | }
|
446 | AbortException.prototype = new Error();
|
447 | AbortException.constructor = AbortException;
|
448 | return AbortException;
|
449 | }();
|
450 | var NullCharactersRegExp = /\x00/g;
|
451 | function removeNullCharacters(str) {
|
452 | if (typeof str !== 'string') {
|
453 | warn('The argument for removeNullCharacters must be a string.');
|
454 | return str;
|
455 | }
|
456 | return str.replace(NullCharactersRegExp, '');
|
457 | }
|
458 | function bytesToString(bytes) {
|
459 | assert(bytes !== null && (typeof bytes === 'undefined' ? 'undefined' : _typeof(bytes)) === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString');
|
460 | var length = bytes.length;
|
461 | var MAX_ARGUMENT_COUNT = 8192;
|
462 | if (length < MAX_ARGUMENT_COUNT) {
|
463 | return String.fromCharCode.apply(null, bytes);
|
464 | }
|
465 | var strBuf = [];
|
466 | for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
|
467 | var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
|
468 | var chunk = bytes.subarray(i, chunkEnd);
|
469 | strBuf.push(String.fromCharCode.apply(null, chunk));
|
470 | }
|
471 | return strBuf.join('');
|
472 | }
|
473 | function stringToBytes(str) {
|
474 | assert(typeof str === 'string', 'Invalid argument for stringToBytes');
|
475 | var length = str.length;
|
476 | var bytes = new Uint8Array(length);
|
477 | for (var i = 0; i < length; ++i) {
|
478 | bytes[i] = str.charCodeAt(i) & 0xFF;
|
479 | }
|
480 | return bytes;
|
481 | }
|
482 | function arrayByteLength(arr) {
|
483 | if (arr.length !== undefined) {
|
484 | return arr.length;
|
485 | }
|
486 | assert(arr.byteLength !== undefined);
|
487 | return arr.byteLength;
|
488 | }
|
489 | function arraysToBytes(arr) {
|
490 | if (arr.length === 1 && arr[0] instanceof Uint8Array) {
|
491 | return arr[0];
|
492 | }
|
493 | var resultLength = 0;
|
494 | var i,
|
495 | ii = arr.length;
|
496 | var item, itemLength;
|
497 | for (i = 0; i < ii; i++) {
|
498 | item = arr[i];
|
499 | itemLength = arrayByteLength(item);
|
500 | resultLength += itemLength;
|
501 | }
|
502 | var pos = 0;
|
503 | var data = new Uint8Array(resultLength);
|
504 | for (i = 0; i < ii; i++) {
|
505 | item = arr[i];
|
506 | if (!(item instanceof Uint8Array)) {
|
507 | if (typeof item === 'string') {
|
508 | item = stringToBytes(item);
|
509 | } else {
|
510 | item = new Uint8Array(item);
|
511 | }
|
512 | }
|
513 | itemLength = item.byteLength;
|
514 | data.set(item, pos);
|
515 | pos += itemLength;
|
516 | }
|
517 | return data;
|
518 | }
|
519 | function string32(value) {
|
520 | return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
|
521 | }
|
522 | function log2(x) {
|
523 | if (x <= 0) {
|
524 | return 0;
|
525 | }
|
526 | return Math.ceil(Math.log2(x));
|
527 | }
|
528 | function readInt8(data, start) {
|
529 | return data[start] << 24 >> 24;
|
530 | }
|
531 | function readUint16(data, offset) {
|
532 | return data[offset] << 8 | data[offset + 1];
|
533 | }
|
534 | function readUint32(data, offset) {
|
535 | return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
|
536 | }
|
537 | function isLittleEndian() {
|
538 | var buffer8 = new Uint8Array(4);
|
539 | buffer8[0] = 1;
|
540 | var view32 = new Uint32Array(buffer8.buffer, 0, 1);
|
541 | return view32[0] === 1;
|
542 | }
|
543 | function isEvalSupported() {
|
544 | try {
|
545 | new Function('');
|
546 | return true;
|
547 | } catch (e) {
|
548 | return false;
|
549 | }
|
550 | }
|
551 | function getInheritableProperty(_ref) {
|
552 | var dict = _ref.dict,
|
553 | key = _ref.key,
|
554 | _ref$getArray = _ref.getArray,
|
555 | getArray = _ref$getArray === undefined ? false : _ref$getArray,
|
556 | _ref$stopWhenFound = _ref.stopWhenFound,
|
557 | stopWhenFound = _ref$stopWhenFound === undefined ? true : _ref$stopWhenFound;
|
558 |
|
559 | var LOOP_LIMIT = 100;
|
560 | var loopCount = 0;
|
561 | var values = void 0;
|
562 | while (dict) {
|
563 | var value = getArray ? dict.getArray(key) : dict.get(key);
|
564 | if (value !== undefined) {
|
565 | if (stopWhenFound) {
|
566 | return value;
|
567 | }
|
568 | if (!values) {
|
569 | values = [];
|
570 | }
|
571 | values.push(value);
|
572 | }
|
573 | if (++loopCount > LOOP_LIMIT) {
|
574 | warn('getInheritableProperty: maximum loop count exceeded for "' + key + '"');
|
575 | break;
|
576 | }
|
577 | dict = dict.get('Parent');
|
578 | }
|
579 | return values;
|
580 | }
|
581 | var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
|
582 | var Util = function UtilClosure() {
|
583 | function Util() {}
|
584 | var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
|
585 | Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
|
586 | rgbBuf[1] = r;
|
587 | rgbBuf[3] = g;
|
588 | rgbBuf[5] = b;
|
589 | return rgbBuf.join('');
|
590 | };
|
591 | Util.transform = function Util_transform(m1, m2) {
|
592 | 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]];
|
593 | };
|
594 | Util.applyTransform = function Util_applyTransform(p, m) {
|
595 | var xt = p[0] * m[0] + p[1] * m[2] + m[4];
|
596 | var yt = p[0] * m[1] + p[1] * m[3] + m[5];
|
597 | return [xt, yt];
|
598 | };
|
599 | Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
|
600 | var d = m[0] * m[3] - m[1] * m[2];
|
601 | var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
|
602 | var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
|
603 | return [xt, yt];
|
604 | };
|
605 | Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) {
|
606 | var p1 = Util.applyTransform(r, m);
|
607 | var p2 = Util.applyTransform(r.slice(2, 4), m);
|
608 | var p3 = Util.applyTransform([r[0], r[3]], m);
|
609 | var p4 = Util.applyTransform([r[2], r[1]], m);
|
610 | 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])];
|
611 | };
|
612 | Util.inverseTransform = function Util_inverseTransform(m) {
|
613 | var d = m[0] * m[3] - m[1] * m[2];
|
614 | 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];
|
615 | };
|
616 | Util.apply3dTransform = function Util_apply3dTransform(m, v) {
|
617 | 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]];
|
618 | };
|
619 | Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) {
|
620 | var transpose = [m[0], m[2], m[1], m[3]];
|
621 | var a = m[0] * transpose[0] + m[1] * transpose[2];
|
622 | var b = m[0] * transpose[1] + m[1] * transpose[3];
|
623 | var c = m[2] * transpose[0] + m[3] * transpose[2];
|
624 | var d = m[2] * transpose[1] + m[3] * transpose[3];
|
625 | var first = (a + d) / 2;
|
626 | var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
|
627 | var sx = first + second || 1;
|
628 | var sy = first - second || 1;
|
629 | return [Math.sqrt(sx), Math.sqrt(sy)];
|
630 | };
|
631 | Util.normalizeRect = function Util_normalizeRect(rect) {
|
632 | var r = rect.slice(0);
|
633 | if (rect[0] > rect[2]) {
|
634 | r[0] = rect[2];
|
635 | r[2] = rect[0];
|
636 | }
|
637 | if (rect[1] > rect[3]) {
|
638 | r[1] = rect[3];
|
639 | r[3] = rect[1];
|
640 | }
|
641 | return r;
|
642 | };
|
643 | Util.intersect = function Util_intersect(rect1, rect2) {
|
644 | function compare(a, b) {
|
645 | return a - b;
|
646 | }
|
647 | var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
|
648 | orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
|
649 | result = [];
|
650 | rect1 = Util.normalizeRect(rect1);
|
651 | rect2 = Util.normalizeRect(rect2);
|
652 | if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
|
653 | result[0] = orderedX[1];
|
654 | result[2] = orderedX[2];
|
655 | } else {
|
656 | return false;
|
657 | }
|
658 | if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
|
659 | result[1] = orderedY[1];
|
660 | result[3] = orderedY[2];
|
661 | } else {
|
662 | return false;
|
663 | }
|
664 | return result;
|
665 | };
|
666 | var ROMAN_NUMBER_MAP = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'];
|
667 | Util.toRoman = function Util_toRoman(number, lowerCase) {
|
668 | assert(Number.isInteger(number) && number > 0, 'The number should be a positive integer.');
|
669 | var pos,
|
670 | romanBuf = [];
|
671 | while (number >= 1000) {
|
672 | number -= 1000;
|
673 | romanBuf.push('M');
|
674 | }
|
675 | pos = number / 100 | 0;
|
676 | number %= 100;
|
677 | romanBuf.push(ROMAN_NUMBER_MAP[pos]);
|
678 | pos = number / 10 | 0;
|
679 | number %= 10;
|
680 | romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
|
681 | romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
|
682 | var romanStr = romanBuf.join('');
|
683 | return lowerCase ? romanStr.toLowerCase() : romanStr;
|
684 | };
|
685 | Util.appendToArray = function Util_appendToArray(arr1, arr2) {
|
686 | Array.prototype.push.apply(arr1, arr2);
|
687 | };
|
688 | Util.prependToArray = function Util_prependToArray(arr1, arr2) {
|
689 | Array.prototype.unshift.apply(arr1, arr2);
|
690 | };
|
691 | Util.extendObj = function extendObj(obj1, obj2) {
|
692 | for (var key in obj2) {
|
693 | obj1[key] = obj2[key];
|
694 | }
|
695 | };
|
696 | Util.inherit = function Util_inherit(sub, base, prototype) {
|
697 | sub.prototype = Object.create(base.prototype);
|
698 | sub.prototype.constructor = sub;
|
699 | for (var prop in prototype) {
|
700 | sub.prototype[prop] = prototype[prop];
|
701 | }
|
702 | };
|
703 | Util.loadScript = function Util_loadScript(src, callback) {
|
704 | var script = document.createElement('script');
|
705 | var loaded = false;
|
706 | script.setAttribute('src', src);
|
707 | if (callback) {
|
708 | script.onload = function () {
|
709 | if (!loaded) {
|
710 | callback();
|
711 | }
|
712 | loaded = true;
|
713 | };
|
714 | }
|
715 | document.getElementsByTagName('head')[0].appendChild(script);
|
716 | };
|
717 | return Util;
|
718 | }();
|
719 | var PageViewport = function PageViewportClosure() {
|
720 | function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
|
721 | this.viewBox = viewBox;
|
722 | this.scale = scale;
|
723 | this.rotation = rotation;
|
724 | this.offsetX = offsetX;
|
725 | this.offsetY = offsetY;
|
726 | var centerX = (viewBox[2] + viewBox[0]) / 2;
|
727 | var centerY = (viewBox[3] + viewBox[1]) / 2;
|
728 | var rotateA, rotateB, rotateC, rotateD;
|
729 | rotation = rotation % 360;
|
730 | rotation = rotation < 0 ? rotation + 360 : rotation;
|
731 | switch (rotation) {
|
732 | case 180:
|
733 | rotateA = -1;
|
734 | rotateB = 0;
|
735 | rotateC = 0;
|
736 | rotateD = 1;
|
737 | break;
|
738 | case 90:
|
739 | rotateA = 0;
|
740 | rotateB = 1;
|
741 | rotateC = 1;
|
742 | rotateD = 0;
|
743 | break;
|
744 | case 270:
|
745 | rotateA = 0;
|
746 | rotateB = -1;
|
747 | rotateC = -1;
|
748 | rotateD = 0;
|
749 | break;
|
750 | default:
|
751 | rotateA = 1;
|
752 | rotateB = 0;
|
753 | rotateC = 0;
|
754 | rotateD = -1;
|
755 | break;
|
756 | }
|
757 | if (dontFlip) {
|
758 | rotateC = -rotateC;
|
759 | rotateD = -rotateD;
|
760 | }
|
761 | var offsetCanvasX, offsetCanvasY;
|
762 | var width, height;
|
763 | if (rotateA === 0) {
|
764 | offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
|
765 | offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
|
766 | width = Math.abs(viewBox[3] - viewBox[1]) * scale;
|
767 | height = Math.abs(viewBox[2] - viewBox[0]) * scale;
|
768 | } else {
|
769 | offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
|
770 | offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
|
771 | width = Math.abs(viewBox[2] - viewBox[0]) * scale;
|
772 | height = Math.abs(viewBox[3] - viewBox[1]) * scale;
|
773 | }
|
774 | this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
|
775 | this.width = width;
|
776 | this.height = height;
|
777 | this.fontScale = scale;
|
778 | }
|
779 | PageViewport.prototype = {
|
780 | clone: function PageViewPort_clone(args) {
|
781 | args = args || {};
|
782 | var scale = 'scale' in args ? args.scale : this.scale;
|
783 | var rotation = 'rotation' in args ? args.rotation : this.rotation;
|
784 | return new PageViewport(this.viewBox.slice(), scale, rotation, this.offsetX, this.offsetY, args.dontFlip);
|
785 | },
|
786 | convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
|
787 | return Util.applyTransform([x, y], this.transform);
|
788 | },
|
789 | convertToViewportRectangle: function PageViewport_convertToViewportRectangle(rect) {
|
790 | var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
|
791 | var br = Util.applyTransform([rect[2], rect[3]], this.transform);
|
792 | return [tl[0], tl[1], br[0], br[1]];
|
793 | },
|
794 | convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
|
795 | return Util.applyInverseTransform([x, y], this.transform);
|
796 | }
|
797 | };
|
798 | return PageViewport;
|
799 | }();
|
800 | var 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];
|
801 | function stringToPDFString(str) {
|
802 | var i,
|
803 | n = str.length,
|
804 | strBuf = [];
|
805 | if (str[0] === '\xFE' && str[1] === '\xFF') {
|
806 | for (i = 2; i < n; i += 2) {
|
807 | strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
|
808 | }
|
809 | } else {
|
810 | for (i = 0; i < n; ++i) {
|
811 | var code = PDFStringTranslateTable[str.charCodeAt(i)];
|
812 | strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
|
813 | }
|
814 | }
|
815 | return strBuf.join('');
|
816 | }
|
817 | function stringToUTF8String(str) {
|
818 | return decodeURIComponent(escape(str));
|
819 | }
|
820 | function utf8StringToString(str) {
|
821 | return unescape(encodeURIComponent(str));
|
822 | }
|
823 | function isEmptyObj(obj) {
|
824 | for (var key in obj) {
|
825 | return false;
|
826 | }
|
827 | return true;
|
828 | }
|
829 | function isBool(v) {
|
830 | return typeof v === 'boolean';
|
831 | }
|
832 | function isNum(v) {
|
833 | return typeof v === 'number';
|
834 | }
|
835 | function isString(v) {
|
836 | return typeof v === 'string';
|
837 | }
|
838 | function isArrayBuffer(v) {
|
839 | return (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object' && v !== null && v.byteLength !== undefined;
|
840 | }
|
841 | function isSpace(ch) {
|
842 | return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A;
|
843 | }
|
844 | function createPromiseCapability() {
|
845 | var capability = {};
|
846 | capability.promise = new Promise(function (resolve, reject) {
|
847 | capability.resolve = resolve;
|
848 | capability.reject = reject;
|
849 | });
|
850 | return capability;
|
851 | }
|
852 | var createBlob = function createBlob(data, contentType) {
|
853 | if (typeof Blob !== 'undefined') {
|
854 | return new Blob([data], { type: contentType });
|
855 | }
|
856 | throw new Error('The "Blob" constructor is not supported.');
|
857 | };
|
858 | var createObjectURL = function createObjectURLClosure() {
|
859 | var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
860 | return function createObjectURL(data, contentType) {
|
861 | var forceDataSchema = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
862 |
|
863 | if (!forceDataSchema && URL.createObjectURL) {
|
864 | var blob = createBlob(data, contentType);
|
865 | return URL.createObjectURL(blob);
|
866 | }
|
867 | var buffer = 'data:' + contentType + ';base64,';
|
868 | for (var i = 0, ii = data.length; i < ii; i += 3) {
|
869 | var b1 = data[i] & 0xFF;
|
870 | var b2 = data[i + 1] & 0xFF;
|
871 | var b3 = data[i + 2] & 0xFF;
|
872 | var d1 = b1 >> 2,
|
873 | d2 = (b1 & 3) << 4 | b2 >> 4;
|
874 | var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
|
875 | var d4 = i + 2 < ii ? b3 & 0x3F : 64;
|
876 | buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
|
877 | }
|
878 | return buffer;
|
879 | };
|
880 | }();
|
881 | function resolveCall(fn, args) {
|
882 | var thisArg = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
883 |
|
884 | if (!fn) {
|
885 | return Promise.resolve(undefined);
|
886 | }
|
887 | return new Promise(function (resolve, reject) {
|
888 | resolve(fn.apply(thisArg, args));
|
889 | });
|
890 | }
|
891 | function wrapReason(reason) {
|
892 | if ((typeof reason === 'undefined' ? 'undefined' : _typeof(reason)) !== 'object') {
|
893 | return reason;
|
894 | }
|
895 | switch (reason.name) {
|
896 | case 'AbortException':
|
897 | return new AbortException(reason.message);
|
898 | case 'MissingPDFException':
|
899 | return new MissingPDFException(reason.message);
|
900 | case 'UnexpectedResponseException':
|
901 | return new UnexpectedResponseException(reason.message, reason.status);
|
902 | default:
|
903 | return new UnknownErrorException(reason.message, reason.details);
|
904 | }
|
905 | }
|
906 | function makeReasonSerializable(reason) {
|
907 | if (!(reason instanceof Error) || reason instanceof AbortException || reason instanceof MissingPDFException || reason instanceof UnexpectedResponseException || reason instanceof UnknownErrorException) {
|
908 | return reason;
|
909 | }
|
910 | return new UnknownErrorException(reason.message, reason.toString());
|
911 | }
|
912 | function resolveOrReject(capability, success, reason) {
|
913 | if (success) {
|
914 | capability.resolve();
|
915 | } else {
|
916 | capability.reject(reason);
|
917 | }
|
918 | }
|
919 | function finalize(promise) {
|
920 | return Promise.resolve(promise).catch(function () {});
|
921 | }
|
922 | function MessageHandler(sourceName, targetName, comObj) {
|
923 | var _this = this;
|
924 |
|
925 | this.sourceName = sourceName;
|
926 | this.targetName = targetName;
|
927 | this.comObj = comObj;
|
928 | this.callbackId = 1;
|
929 | this.streamId = 1;
|
930 | this.postMessageTransfers = true;
|
931 | this.streamSinks = Object.create(null);
|
932 | this.streamControllers = Object.create(null);
|
933 | var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
|
934 | var ah = this.actionHandler = Object.create(null);
|
935 | this._onComObjOnMessage = function (event) {
|
936 | var data = event.data;
|
937 | if (data.targetName !== _this.sourceName) {
|
938 | return;
|
939 | }
|
940 | if (data.stream) {
|
941 | _this._processStreamMessage(data);
|
942 | } else if (data.isReply) {
|
943 | var callbackId = data.callbackId;
|
944 | if (data.callbackId in callbacksCapabilities) {
|
945 | var callback = callbacksCapabilities[callbackId];
|
946 | delete callbacksCapabilities[callbackId];
|
947 | if ('error' in data) {
|
948 | callback.reject(wrapReason(data.error));
|
949 | } else {
|
950 | callback.resolve(data.data);
|
951 | }
|
952 | } else {
|
953 | throw new Error('Cannot resolve callback ' + callbackId);
|
954 | }
|
955 | } else if (data.action in ah) {
|
956 | var action = ah[data.action];
|
957 | if (data.callbackId) {
|
958 | var _sourceName = _this.sourceName;
|
959 | var _targetName = data.sourceName;
|
960 | Promise.resolve().then(function () {
|
961 | return action[0].call(action[1], data.data);
|
962 | }).then(function (result) {
|
963 | comObj.postMessage({
|
964 | sourceName: _sourceName,
|
965 | targetName: _targetName,
|
966 | isReply: true,
|
967 | callbackId: data.callbackId,
|
968 | data: result
|
969 | });
|
970 | }, function (reason) {
|
971 | comObj.postMessage({
|
972 | sourceName: _sourceName,
|
973 | targetName: _targetName,
|
974 | isReply: true,
|
975 | callbackId: data.callbackId,
|
976 | error: makeReasonSerializable(reason)
|
977 | });
|
978 | });
|
979 | } else if (data.streamId) {
|
980 | _this._createStreamSink(data);
|
981 | } else {
|
982 | action[0].call(action[1], data.data);
|
983 | }
|
984 | } else {
|
985 | throw new Error('Unknown action from worker: ' + data.action);
|
986 | }
|
987 | };
|
988 | comObj.addEventListener('message', this._onComObjOnMessage);
|
989 | }
|
990 | MessageHandler.prototype = {
|
991 | on: function on(actionName, handler, scope) {
|
992 | var ah = this.actionHandler;
|
993 | if (ah[actionName]) {
|
994 | throw new Error('There is already an actionName called "' + actionName + '"');
|
995 | }
|
996 | ah[actionName] = [handler, scope];
|
997 | },
|
998 | send: function send(actionName, data, transfers) {
|
999 | var message = {
|
1000 | sourceName: this.sourceName,
|
1001 | targetName: this.targetName,
|
1002 | action: actionName,
|
1003 | data: data
|
1004 | };
|
1005 | this.postMessage(message, transfers);
|
1006 | },
|
1007 | sendWithPromise: function sendWithPromise(actionName, data, transfers) {
|
1008 | var callbackId = this.callbackId++;
|
1009 | var message = {
|
1010 | sourceName: this.sourceName,
|
1011 | targetName: this.targetName,
|
1012 | action: actionName,
|
1013 | data: data,
|
1014 | callbackId: callbackId
|
1015 | };
|
1016 | var capability = createPromiseCapability();
|
1017 | this.callbacksCapabilities[callbackId] = capability;
|
1018 | try {
|
1019 | this.postMessage(message, transfers);
|
1020 | } catch (e) {
|
1021 | capability.reject(e);
|
1022 | }
|
1023 | return capability.promise;
|
1024 | },
|
1025 | sendWithStream: function sendWithStream(actionName, data, queueingStrategy, transfers) {
|
1026 | var _this2 = this;
|
1027 |
|
1028 | var streamId = this.streamId++;
|
1029 | var sourceName = this.sourceName;
|
1030 | var targetName = this.targetName;
|
1031 | return new _streams_polyfill.ReadableStream({
|
1032 | start: function start(controller) {
|
1033 | var startCapability = createPromiseCapability();
|
1034 | _this2.streamControllers[streamId] = {
|
1035 | controller: controller,
|
1036 | startCall: startCapability,
|
1037 | isClosed: false
|
1038 | };
|
1039 | _this2.postMessage({
|
1040 | sourceName: sourceName,
|
1041 | targetName: targetName,
|
1042 | action: actionName,
|
1043 | streamId: streamId,
|
1044 | data: data,
|
1045 | desiredSize: controller.desiredSize
|
1046 | });
|
1047 | return startCapability.promise;
|
1048 | },
|
1049 | pull: function pull(controller) {
|
1050 | var pullCapability = createPromiseCapability();
|
1051 | _this2.streamControllers[streamId].pullCall = pullCapability;
|
1052 | _this2.postMessage({
|
1053 | sourceName: sourceName,
|
1054 | targetName: targetName,
|
1055 | stream: 'pull',
|
1056 | streamId: streamId,
|
1057 | desiredSize: controller.desiredSize
|
1058 | });
|
1059 | return pullCapability.promise;
|
1060 | },
|
1061 | cancel: function cancel(reason) {
|
1062 | var cancelCapability = createPromiseCapability();
|
1063 | _this2.streamControllers[streamId].cancelCall = cancelCapability;
|
1064 | _this2.streamControllers[streamId].isClosed = true;
|
1065 | _this2.postMessage({
|
1066 | sourceName: sourceName,
|
1067 | targetName: targetName,
|
1068 | stream: 'cancel',
|
1069 | reason: reason,
|
1070 | streamId: streamId
|
1071 | });
|
1072 | return cancelCapability.promise;
|
1073 | }
|
1074 | }, queueingStrategy);
|
1075 | },
|
1076 | _createStreamSink: function _createStreamSink(data) {
|
1077 | var _this3 = this;
|
1078 |
|
1079 | var self = this;
|
1080 | var action = this.actionHandler[data.action];
|
1081 | var streamId = data.streamId;
|
1082 | var desiredSize = data.desiredSize;
|
1083 | var sourceName = this.sourceName;
|
1084 | var targetName = data.sourceName;
|
1085 | var capability = createPromiseCapability();
|
1086 | var sendStreamRequest = function sendStreamRequest(_ref2) {
|
1087 | var stream = _ref2.stream,
|
1088 | chunk = _ref2.chunk,
|
1089 | transfers = _ref2.transfers,
|
1090 | success = _ref2.success,
|
1091 | reason = _ref2.reason;
|
1092 |
|
1093 | _this3.postMessage({
|
1094 | sourceName: sourceName,
|
1095 | targetName: targetName,
|
1096 | stream: stream,
|
1097 | streamId: streamId,
|
1098 | chunk: chunk,
|
1099 | success: success,
|
1100 | reason: reason
|
1101 | }, transfers);
|
1102 | };
|
1103 | var streamSink = {
|
1104 | enqueue: function enqueue(chunk) {
|
1105 | var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
1106 | var transfers = arguments[2];
|
1107 |
|
1108 | if (this.isCancelled) {
|
1109 | return;
|
1110 | }
|
1111 | var lastDesiredSize = this.desiredSize;
|
1112 | this.desiredSize -= size;
|
1113 | if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
1114 | this.sinkCapability = createPromiseCapability();
|
1115 | this.ready = this.sinkCapability.promise;
|
1116 | }
|
1117 | sendStreamRequest({
|
1118 | stream: 'enqueue',
|
1119 | chunk: chunk,
|
1120 | transfers: transfers
|
1121 | });
|
1122 | },
|
1123 | close: function close() {
|
1124 | if (this.isCancelled) {
|
1125 | return;
|
1126 | }
|
1127 | this.isCancelled = true;
|
1128 | sendStreamRequest({ stream: 'close' });
|
1129 | delete self.streamSinks[streamId];
|
1130 | },
|
1131 | error: function error(reason) {
|
1132 | if (this.isCancelled) {
|
1133 | return;
|
1134 | }
|
1135 | this.isCancelled = true;
|
1136 | sendStreamRequest({
|
1137 | stream: 'error',
|
1138 | reason: reason
|
1139 | });
|
1140 | },
|
1141 |
|
1142 | sinkCapability: capability,
|
1143 | onPull: null,
|
1144 | onCancel: null,
|
1145 | isCancelled: false,
|
1146 | desiredSize: desiredSize,
|
1147 | ready: null
|
1148 | };
|
1149 | streamSink.sinkCapability.resolve();
|
1150 | streamSink.ready = streamSink.sinkCapability.promise;
|
1151 | this.streamSinks[streamId] = streamSink;
|
1152 | resolveCall(action[0], [data.data, streamSink], action[1]).then(function () {
|
1153 | sendStreamRequest({
|
1154 | stream: 'start_complete',
|
1155 | success: true
|
1156 | });
|
1157 | }, function (reason) {
|
1158 | sendStreamRequest({
|
1159 | stream: 'start_complete',
|
1160 | success: false,
|
1161 | reason: reason
|
1162 | });
|
1163 | });
|
1164 | },
|
1165 | _processStreamMessage: function _processStreamMessage(data) {
|
1166 | var _this4 = this;
|
1167 |
|
1168 | var sourceName = this.sourceName;
|
1169 | var targetName = data.sourceName;
|
1170 | var streamId = data.streamId;
|
1171 | var sendStreamResponse = function sendStreamResponse(_ref3) {
|
1172 | var stream = _ref3.stream,
|
1173 | success = _ref3.success,
|
1174 | reason = _ref3.reason;
|
1175 |
|
1176 | _this4.comObj.postMessage({
|
1177 | sourceName: sourceName,
|
1178 | targetName: targetName,
|
1179 | stream: stream,
|
1180 | success: success,
|
1181 | streamId: streamId,
|
1182 | reason: reason
|
1183 | });
|
1184 | };
|
1185 | var deleteStreamController = function deleteStreamController() {
|
1186 | Promise.all([_this4.streamControllers[data.streamId].startCall, _this4.streamControllers[data.streamId].pullCall, _this4.streamControllers[data.streamId].cancelCall].map(function (capability) {
|
1187 | return capability && finalize(capability.promise);
|
1188 | })).then(function () {
|
1189 | delete _this4.streamControllers[data.streamId];
|
1190 | });
|
1191 | };
|
1192 | switch (data.stream) {
|
1193 | case 'start_complete':
|
1194 | resolveOrReject(this.streamControllers[data.streamId].startCall, data.success, wrapReason(data.reason));
|
1195 | break;
|
1196 | case 'pull_complete':
|
1197 | resolveOrReject(this.streamControllers[data.streamId].pullCall, data.success, wrapReason(data.reason));
|
1198 | break;
|
1199 | case 'pull':
|
1200 | if (!this.streamSinks[data.streamId]) {
|
1201 | sendStreamResponse({
|
1202 | stream: 'pull_complete',
|
1203 | success: true
|
1204 | });
|
1205 | break;
|
1206 | }
|
1207 | if (this.streamSinks[data.streamId].desiredSize <= 0 && data.desiredSize > 0) {
|
1208 | this.streamSinks[data.streamId].sinkCapability.resolve();
|
1209 | }
|
1210 | this.streamSinks[data.streamId].desiredSize = data.desiredSize;
|
1211 | resolveCall(this.streamSinks[data.streamId].onPull).then(function () {
|
1212 | sendStreamResponse({
|
1213 | stream: 'pull_complete',
|
1214 | success: true
|
1215 | });
|
1216 | }, function (reason) {
|
1217 | sendStreamResponse({
|
1218 | stream: 'pull_complete',
|
1219 | success: false,
|
1220 | reason: reason
|
1221 | });
|
1222 | });
|
1223 | break;
|
1224 | case 'enqueue':
|
1225 | assert(this.streamControllers[data.streamId], 'enqueue should have stream controller');
|
1226 | if (!this.streamControllers[data.streamId].isClosed) {
|
1227 | this.streamControllers[data.streamId].controller.enqueue(data.chunk);
|
1228 | }
|
1229 | break;
|
1230 | case 'close':
|
1231 | assert(this.streamControllers[data.streamId], 'close should have stream controller');
|
1232 | if (this.streamControllers[data.streamId].isClosed) {
|
1233 | break;
|
1234 | }
|
1235 | this.streamControllers[data.streamId].isClosed = true;
|
1236 | this.streamControllers[data.streamId].controller.close();
|
1237 | deleteStreamController();
|
1238 | break;
|
1239 | case 'error':
|
1240 | assert(this.streamControllers[data.streamId], 'error should have stream controller');
|
1241 | this.streamControllers[data.streamId].controller.error(wrapReason(data.reason));
|
1242 | deleteStreamController();
|
1243 | break;
|
1244 | case 'cancel_complete':
|
1245 | resolveOrReject(this.streamControllers[data.streamId].cancelCall, data.success, wrapReason(data.reason));
|
1246 | deleteStreamController();
|
1247 | break;
|
1248 | case 'cancel':
|
1249 | if (!this.streamSinks[data.streamId]) {
|
1250 | break;
|
1251 | }
|
1252 | resolveCall(this.streamSinks[data.streamId].onCancel, [wrapReason(data.reason)]).then(function () {
|
1253 | sendStreamResponse({
|
1254 | stream: 'cancel_complete',
|
1255 | success: true
|
1256 | });
|
1257 | }, function (reason) {
|
1258 | sendStreamResponse({
|
1259 | stream: 'cancel_complete',
|
1260 | success: false,
|
1261 | reason: reason
|
1262 | });
|
1263 | });
|
1264 | this.streamSinks[data.streamId].sinkCapability.reject(wrapReason(data.reason));
|
1265 | this.streamSinks[data.streamId].isCancelled = true;
|
1266 | delete this.streamSinks[data.streamId];
|
1267 | break;
|
1268 | default:
|
1269 | throw new Error('Unexpected stream case');
|
1270 | }
|
1271 | },
|
1272 | postMessage: function postMessage(message, transfers) {
|
1273 | if (transfers && this.postMessageTransfers) {
|
1274 | this.comObj.postMessage(message, transfers);
|
1275 | } else {
|
1276 | this.comObj.postMessage(message);
|
1277 | }
|
1278 | },
|
1279 | destroy: function destroy() {
|
1280 | this.comObj.removeEventListener('message', this._onComObjOnMessage);
|
1281 | }
|
1282 | };
|
1283 | exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
|
1284 | exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
|
1285 | exports.OPS = OPS;
|
1286 | exports.VerbosityLevel = VerbosityLevel;
|
1287 | exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
|
1288 | exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
|
1289 | exports.AnnotationFieldFlag = AnnotationFieldFlag;
|
1290 | exports.AnnotationFlag = AnnotationFlag;
|
1291 | exports.AnnotationType = AnnotationType;
|
1292 | exports.FontType = FontType;
|
1293 | exports.ImageKind = ImageKind;
|
1294 | exports.CMapCompressionType = CMapCompressionType;
|
1295 | exports.AbortException = AbortException;
|
1296 | exports.InvalidPDFException = InvalidPDFException;
|
1297 | exports.MessageHandler = MessageHandler;
|
1298 | exports.MissingDataException = MissingDataException;
|
1299 | exports.MissingPDFException = MissingPDFException;
|
1300 | exports.NativeImageDecoding = NativeImageDecoding;
|
1301 | exports.NotImplementedException = NotImplementedException;
|
1302 | exports.PageViewport = PageViewport;
|
1303 | exports.PasswordException = PasswordException;
|
1304 | exports.PasswordResponses = PasswordResponses;
|
1305 | exports.StreamType = StreamType;
|
1306 | exports.TextRenderingMode = TextRenderingMode;
|
1307 | exports.UnexpectedResponseException = UnexpectedResponseException;
|
1308 | exports.UnknownErrorException = UnknownErrorException;
|
1309 | exports.Util = Util;
|
1310 | exports.XRefParseException = XRefParseException;
|
1311 | exports.FormatError = FormatError;
|
1312 | exports.arrayByteLength = arrayByteLength;
|
1313 | exports.arraysToBytes = arraysToBytes;
|
1314 | exports.assert = assert;
|
1315 | exports.bytesToString = bytesToString;
|
1316 | exports.createBlob = createBlob;
|
1317 | exports.createPromiseCapability = createPromiseCapability;
|
1318 | exports.createObjectURL = createObjectURL;
|
1319 | exports.deprecated = deprecated;
|
1320 | exports.getInheritableProperty = getInheritableProperty;
|
1321 | exports.getLookupTableFactory = getLookupTableFactory;
|
1322 | exports.getVerbosityLevel = getVerbosityLevel;
|
1323 | exports.info = info;
|
1324 | exports.isArrayBuffer = isArrayBuffer;
|
1325 | exports.isBool = isBool;
|
1326 | exports.isEmptyObj = isEmptyObj;
|
1327 | exports.isNum = isNum;
|
1328 | exports.isString = isString;
|
1329 | exports.isSpace = isSpace;
|
1330 | exports.isSameOrigin = isSameOrigin;
|
1331 | exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
|
1332 | exports.isLittleEndian = isLittleEndian;
|
1333 | exports.isEvalSupported = isEvalSupported;
|
1334 | exports.log2 = log2;
|
1335 | exports.readInt8 = readInt8;
|
1336 | exports.readUint16 = readUint16;
|
1337 | exports.readUint32 = readUint32;
|
1338 | exports.removeNullCharacters = removeNullCharacters;
|
1339 | exports.ReadableStream = _streams_polyfill.ReadableStream;
|
1340 | exports.setVerbosityLevel = setVerbosityLevel;
|
1341 | exports.shadow = shadow;
|
1342 | exports.string32 = string32;
|
1343 | exports.stringToBytes = stringToBytes;
|
1344 | exports.stringToPDFString = stringToPDFString;
|
1345 | exports.stringToUTF8String = stringToUTF8String;
|
1346 | exports.utf8StringToString = utf8StringToString;
|
1347 | exports.warn = warn;
|
1348 | exports.unreachable = unreachable; |
\ | No newline at end of file |