UNPKG

22.8 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2019 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * Javascript code in this page
21 */
22"use strict";
23
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.arrayByteLength = arrayByteLength;
28exports.arraysToBytes = arraysToBytes;
29exports.assert = assert;
30exports.bytesToString = bytesToString;
31exports.createPromiseCapability = createPromiseCapability;
32exports.getVerbosityLevel = getVerbosityLevel;
33exports.info = info;
34exports.isArrayBuffer = isArrayBuffer;
35exports.isArrayEqual = isArrayEqual;
36exports.isBool = isBool;
37exports.isEmptyObj = isEmptyObj;
38exports.isNum = isNum;
39exports.isString = isString;
40exports.isSpace = isSpace;
41exports.isSameOrigin = isSameOrigin;
42exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
43exports.isLittleEndian = isLittleEndian;
44exports.isEvalSupported = isEvalSupported;
45exports.log2 = log2;
46exports.readInt8 = readInt8;
47exports.readUint16 = readUint16;
48exports.readUint32 = readUint32;
49exports.removeNullCharacters = removeNullCharacters;
50exports.setVerbosityLevel = setVerbosityLevel;
51exports.shadow = shadow;
52exports.string32 = string32;
53exports.stringToBytes = stringToBytes;
54exports.stringToPDFString = stringToPDFString;
55exports.stringToUTF8String = stringToUTF8String;
56exports.utf8StringToString = utf8StringToString;
57exports.warn = warn;
58exports.unreachable = unreachable;
59Object.defineProperty(exports, "ReadableStream", {
60 enumerable: true,
61 get: function get() {
62 return _streams_polyfill.ReadableStream;
63 }
64});
65Object.defineProperty(exports, "URL", {
66 enumerable: true,
67 get: function get() {
68 return _url_polyfill.URL;
69 }
70});
71exports.createObjectURL = exports.FormatError = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.NativeImageDecoding = exports.MissingPDFException = 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 = void 0;
72
73require("./compatibility");
74
75var _streams_polyfill = require("./streams_polyfill");
76
77var _url_polyfill = require("./url_polyfill");
78
79function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
80
81var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
82exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
83var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
84exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
85var NativeImageDecoding = {
86 NONE: 'none',
87 DECODE: 'decode',
88 DISPLAY: 'display'
89};
90exports.NativeImageDecoding = NativeImageDecoding;
91var PermissionFlag = {
92 PRINT: 0x04,
93 MODIFY_CONTENTS: 0x08,
94 COPY: 0x10,
95 MODIFY_ANNOTATIONS: 0x20,
96 FILL_INTERACTIVE_FORMS: 0x100,
97 COPY_FOR_ACCESSIBILITY: 0x200,
98 ASSEMBLE: 0x400,
99 PRINT_HIGH_QUALITY: 0x800
100};
101exports.PermissionFlag = PermissionFlag;
102var TextRenderingMode = {
103 FILL: 0,
104 STROKE: 1,
105 FILL_STROKE: 2,
106 INVISIBLE: 3,
107 FILL_ADD_TO_PATH: 4,
108 STROKE_ADD_TO_PATH: 5,
109 FILL_STROKE_ADD_TO_PATH: 6,
110 ADD_TO_PATH: 7,
111 FILL_STROKE_MASK: 3,
112 ADD_TO_PATH_FLAG: 4
113};
114exports.TextRenderingMode = TextRenderingMode;
115var ImageKind = {
116 GRAYSCALE_1BPP: 1,
117 RGB_24BPP: 2,
118 RGBA_32BPP: 3
119};
120exports.ImageKind = ImageKind;
121var AnnotationType = {
122 TEXT: 1,
123 LINK: 2,
124 FREETEXT: 3,
125 LINE: 4,
126 SQUARE: 5,
127 CIRCLE: 6,
128 POLYGON: 7,
129 POLYLINE: 8,
130 HIGHLIGHT: 9,
131 UNDERLINE: 10,
132 SQUIGGLY: 11,
133 STRIKEOUT: 12,
134 STAMP: 13,
135 CARET: 14,
136 INK: 15,
137 POPUP: 16,
138 FILEATTACHMENT: 17,
139 SOUND: 18,
140 MOVIE: 19,
141 WIDGET: 20,
142 SCREEN: 21,
143 PRINTERMARK: 22,
144 TRAPNET: 23,
145 WATERMARK: 24,
146 THREED: 25,
147 REDACT: 26
148};
149exports.AnnotationType = AnnotationType;
150var AnnotationFlag = {
151 INVISIBLE: 0x01,
152 HIDDEN: 0x02,
153 PRINT: 0x04,
154 NOZOOM: 0x08,
155 NOROTATE: 0x10,
156 NOVIEW: 0x20,
157 READONLY: 0x40,
158 LOCKED: 0x80,
159 TOGGLENOVIEW: 0x100,
160 LOCKEDCONTENTS: 0x200
161};
162exports.AnnotationFlag = AnnotationFlag;
163var AnnotationFieldFlag = {
164 READONLY: 0x0000001,
165 REQUIRED: 0x0000002,
166 NOEXPORT: 0x0000004,
167 MULTILINE: 0x0001000,
168 PASSWORD: 0x0002000,
169 NOTOGGLETOOFF: 0x0004000,
170 RADIO: 0x0008000,
171 PUSHBUTTON: 0x0010000,
172 COMBO: 0x0020000,
173 EDIT: 0x0040000,
174 SORT: 0x0080000,
175 FILESELECT: 0x0100000,
176 MULTISELECT: 0x0200000,
177 DONOTSPELLCHECK: 0x0400000,
178 DONOTSCROLL: 0x0800000,
179 COMB: 0x1000000,
180 RICHTEXT: 0x2000000,
181 RADIOSINUNISON: 0x2000000,
182 COMMITONSELCHANGE: 0x4000000
183};
184exports.AnnotationFieldFlag = AnnotationFieldFlag;
185var AnnotationBorderStyleType = {
186 SOLID: 1,
187 DASHED: 2,
188 BEVELED: 3,
189 INSET: 4,
190 UNDERLINE: 5
191};
192exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
193var StreamType = {
194 UNKNOWN: 0,
195 FLATE: 1,
196 LZW: 2,
197 DCT: 3,
198 JPX: 4,
199 JBIG: 5,
200 A85: 6,
201 AHX: 7,
202 CCF: 8,
203 RL: 9
204};
205exports.StreamType = StreamType;
206var FontType = {
207 UNKNOWN: 0,
208 TYPE1: 1,
209 TYPE1C: 2,
210 CIDFONTTYPE0: 3,
211 CIDFONTTYPE0C: 4,
212 TRUETYPE: 5,
213 CIDFONTTYPE2: 6,
214 TYPE3: 7,
215 OPENTYPE: 8,
216 TYPE0: 9,
217 MMTYPE1: 10
218};
219exports.FontType = FontType;
220var VerbosityLevel = {
221 ERRORS: 0,
222 WARNINGS: 1,
223 INFOS: 5
224};
225exports.VerbosityLevel = VerbosityLevel;
226var CMapCompressionType = {
227 NONE: 0,
228 BINARY: 1,
229 STREAM: 2
230};
231exports.CMapCompressionType = CMapCompressionType;
232var OPS = {
233 dependency: 1,
234 setLineWidth: 2,
235 setLineCap: 3,
236 setLineJoin: 4,
237 setMiterLimit: 5,
238 setDash: 6,
239 setRenderingIntent: 7,
240 setFlatness: 8,
241 setGState: 9,
242 save: 10,
243 restore: 11,
244 transform: 12,
245 moveTo: 13,
246 lineTo: 14,
247 curveTo: 15,
248 curveTo2: 16,
249 curveTo3: 17,
250 closePath: 18,
251 rectangle: 19,
252 stroke: 20,
253 closeStroke: 21,
254 fill: 22,
255 eoFill: 23,
256 fillStroke: 24,
257 eoFillStroke: 25,
258 closeFillStroke: 26,
259 closeEOFillStroke: 27,
260 endPath: 28,
261 clip: 29,
262 eoClip: 30,
263 beginText: 31,
264 endText: 32,
265 setCharSpacing: 33,
266 setWordSpacing: 34,
267 setHScale: 35,
268 setLeading: 36,
269 setFont: 37,
270 setTextRenderingMode: 38,
271 setTextRise: 39,
272 moveText: 40,
273 setLeadingMoveText: 41,
274 setTextMatrix: 42,
275 nextLine: 43,
276 showText: 44,
277 showSpacedText: 45,
278 nextLineShowText: 46,
279 nextLineSetSpacingShowText: 47,
280 setCharWidth: 48,
281 setCharWidthAndBounds: 49,
282 setStrokeColorSpace: 50,
283 setFillColorSpace: 51,
284 setStrokeColor: 52,
285 setStrokeColorN: 53,
286 setFillColor: 54,
287 setFillColorN: 55,
288 setStrokeGray: 56,
289 setFillGray: 57,
290 setStrokeRGBColor: 58,
291 setFillRGBColor: 59,
292 setStrokeCMYKColor: 60,
293 setFillCMYKColor: 61,
294 shadingFill: 62,
295 beginInlineImage: 63,
296 beginImageData: 64,
297 endInlineImage: 65,
298 paintXObject: 66,
299 markPoint: 67,
300 markPointProps: 68,
301 beginMarkedContent: 69,
302 beginMarkedContentProps: 70,
303 endMarkedContent: 71,
304 beginCompat: 72,
305 endCompat: 73,
306 paintFormXObjectBegin: 74,
307 paintFormXObjectEnd: 75,
308 beginGroup: 76,
309 endGroup: 77,
310 beginAnnotations: 78,
311 endAnnotations: 79,
312 beginAnnotation: 80,
313 endAnnotation: 81,
314 paintJpegXObject: 82,
315 paintImageMaskXObject: 83,
316 paintImageMaskXObjectGroup: 84,
317 paintImageXObject: 85,
318 paintInlineImageXObject: 86,
319 paintInlineImageXObjectGroup: 87,
320 paintImageXObjectRepeat: 88,
321 paintImageMaskXObjectRepeat: 89,
322 paintSolidColorImageMask: 90,
323 constructPath: 91
324};
325exports.OPS = OPS;
326var UNSUPPORTED_FEATURES = {
327 unknown: 'unknown',
328 forms: 'forms',
329 javaScript: 'javaScript',
330 smask: 'smask',
331 shadingPattern: 'shadingPattern',
332 font: 'font'
333};
334exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
335var PasswordResponses = {
336 NEED_PASSWORD: 1,
337 INCORRECT_PASSWORD: 2
338};
339exports.PasswordResponses = PasswordResponses;
340var verbosity = VerbosityLevel.WARNINGS;
341
342function setVerbosityLevel(level) {
343 if (Number.isInteger(level)) {
344 verbosity = level;
345 }
346}
347
348function getVerbosityLevel() {
349 return verbosity;
350}
351
352function info(msg) {
353 if (verbosity >= VerbosityLevel.INFOS) {
354 console.log('Info: ' + msg);
355 }
356}
357
358function warn(msg) {
359 if (verbosity >= VerbosityLevel.WARNINGS) {
360 console.log('Warning: ' + msg);
361 }
362}
363
364function unreachable(msg) {
365 throw new Error(msg);
366}
367
368function assert(cond, msg) {
369 if (!cond) {
370 unreachable(msg);
371 }
372}
373
374function isSameOrigin(baseUrl, otherUrl) {
375 try {
376 var base = new _url_polyfill.URL(baseUrl);
377
378 if (!base.origin || base.origin === 'null') {
379 return false;
380 }
381 } catch (e) {
382 return false;
383 }
384
385 var other = new _url_polyfill.URL(otherUrl, base);
386 return base.origin === other.origin;
387}
388
389function _isValidProtocol(url) {
390 if (!url) {
391 return false;
392 }
393
394 switch (url.protocol) {
395 case 'http:':
396 case 'https:':
397 case 'ftp:':
398 case 'mailto:':
399 case 'tel:':
400 return true;
401
402 default:
403 return false;
404 }
405}
406
407function createValidAbsoluteUrl(url, baseUrl) {
408 if (!url) {
409 return null;
410 }
411
412 try {
413 var absoluteUrl = baseUrl ? new _url_polyfill.URL(url, baseUrl) : new _url_polyfill.URL(url);
414
415 if (_isValidProtocol(absoluteUrl)) {
416 return absoluteUrl;
417 }
418 } catch (ex) {}
419
420 return null;
421}
422
423function shadow(obj, prop, value) {
424 Object.defineProperty(obj, prop, {
425 value: value,
426 enumerable: true,
427 configurable: true,
428 writable: false
429 });
430 return value;
431}
432
433var PasswordException = function PasswordExceptionClosure() {
434 function PasswordException(msg, code) {
435 this.name = 'PasswordException';
436 this.message = msg;
437 this.code = code;
438 }
439
440 PasswordException.prototype = new Error();
441 PasswordException.constructor = PasswordException;
442 return PasswordException;
443}();
444
445exports.PasswordException = PasswordException;
446
447var UnknownErrorException = function UnknownErrorExceptionClosure() {
448 function UnknownErrorException(msg, details) {
449 this.name = 'UnknownErrorException';
450 this.message = msg;
451 this.details = details;
452 }
453
454 UnknownErrorException.prototype = new Error();
455 UnknownErrorException.constructor = UnknownErrorException;
456 return UnknownErrorException;
457}();
458
459exports.UnknownErrorException = UnknownErrorException;
460
461var InvalidPDFException = function InvalidPDFExceptionClosure() {
462 function InvalidPDFException(msg) {
463 this.name = 'InvalidPDFException';
464 this.message = msg;
465 }
466
467 InvalidPDFException.prototype = new Error();
468 InvalidPDFException.constructor = InvalidPDFException;
469 return InvalidPDFException;
470}();
471
472exports.InvalidPDFException = InvalidPDFException;
473
474var MissingPDFException = function MissingPDFExceptionClosure() {
475 function MissingPDFException(msg) {
476 this.name = 'MissingPDFException';
477 this.message = msg;
478 }
479
480 MissingPDFException.prototype = new Error();
481 MissingPDFException.constructor = MissingPDFException;
482 return MissingPDFException;
483}();
484
485exports.MissingPDFException = MissingPDFException;
486
487var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() {
488 function UnexpectedResponseException(msg, status) {
489 this.name = 'UnexpectedResponseException';
490 this.message = msg;
491 this.status = status;
492 }
493
494 UnexpectedResponseException.prototype = new Error();
495 UnexpectedResponseException.constructor = UnexpectedResponseException;
496 return UnexpectedResponseException;
497}();
498
499exports.UnexpectedResponseException = UnexpectedResponseException;
500
501var FormatError = function FormatErrorClosure() {
502 function FormatError(msg) {
503 this.message = msg;
504 }
505
506 FormatError.prototype = new Error();
507 FormatError.prototype.name = 'FormatError';
508 FormatError.constructor = FormatError;
509 return FormatError;
510}();
511
512exports.FormatError = FormatError;
513
514var AbortException = function AbortExceptionClosure() {
515 function AbortException(msg) {
516 this.name = 'AbortException';
517 this.message = msg;
518 }
519
520 AbortException.prototype = new Error();
521 AbortException.constructor = AbortException;
522 return AbortException;
523}();
524
525exports.AbortException = AbortException;
526var NullCharactersRegExp = /\x00/g;
527
528function removeNullCharacters(str) {
529 if (typeof str !== 'string') {
530 warn('The argument for removeNullCharacters must be a string.');
531 return str;
532 }
533
534 return str.replace(NullCharactersRegExp, '');
535}
536
537function bytesToString(bytes) {
538 assert(bytes !== null && _typeof(bytes) === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString');
539 var length = bytes.length;
540 var MAX_ARGUMENT_COUNT = 8192;
541
542 if (length < MAX_ARGUMENT_COUNT) {
543 return String.fromCharCode.apply(null, bytes);
544 }
545
546 var strBuf = [];
547
548 for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
549 var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
550 var chunk = bytes.subarray(i, chunkEnd);
551 strBuf.push(String.fromCharCode.apply(null, chunk));
552 }
553
554 return strBuf.join('');
555}
556
557function stringToBytes(str) {
558 assert(typeof str === 'string', 'Invalid argument for stringToBytes');
559 var length = str.length;
560 var bytes = new Uint8Array(length);
561
562 for (var i = 0; i < length; ++i) {
563 bytes[i] = str.charCodeAt(i) & 0xFF;
564 }
565
566 return bytes;
567}
568
569function arrayByteLength(arr) {
570 if (arr.length !== undefined) {
571 return arr.length;
572 }
573
574 assert(arr.byteLength !== undefined);
575 return arr.byteLength;
576}
577
578function arraysToBytes(arr) {
579 if (arr.length === 1 && arr[0] instanceof Uint8Array) {
580 return arr[0];
581 }
582
583 var resultLength = 0;
584 var i,
585 ii = arr.length;
586 var item, itemLength;
587
588 for (i = 0; i < ii; i++) {
589 item = arr[i];
590 itemLength = arrayByteLength(item);
591 resultLength += itemLength;
592 }
593
594 var pos = 0;
595 var data = new Uint8Array(resultLength);
596
597 for (i = 0; i < ii; i++) {
598 item = arr[i];
599
600 if (!(item instanceof Uint8Array)) {
601 if (typeof item === 'string') {
602 item = stringToBytes(item);
603 } else {
604 item = new Uint8Array(item);
605 }
606 }
607
608 itemLength = item.byteLength;
609 data.set(item, pos);
610 pos += itemLength;
611 }
612
613 return data;
614}
615
616function string32(value) {
617 return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
618}
619
620function log2(x) {
621 if (x <= 0) {
622 return 0;
623 }
624
625 return Math.ceil(Math.log2(x));
626}
627
628function readInt8(data, start) {
629 return data[start] << 24 >> 24;
630}
631
632function readUint16(data, offset) {
633 return data[offset] << 8 | data[offset + 1];
634}
635
636function readUint32(data, offset) {
637 return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
638}
639
640function isLittleEndian() {
641 var buffer8 = new Uint8Array(4);
642 buffer8[0] = 1;
643 var view32 = new Uint32Array(buffer8.buffer, 0, 1);
644 return view32[0] === 1;
645}
646
647function isEvalSupported() {
648 try {
649 new Function('');
650 return true;
651 } catch (e) {
652 return false;
653 }
654}
655
656var Util = function UtilClosure() {
657 function Util() {}
658
659 var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
660
661 Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
662 rgbBuf[1] = r;
663 rgbBuf[3] = g;
664 rgbBuf[5] = b;
665 return rgbBuf.join('');
666 };
667
668 Util.transform = function Util_transform(m1, m2) {
669 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]];
670 };
671
672 Util.applyTransform = function Util_applyTransform(p, m) {
673 var xt = p[0] * m[0] + p[1] * m[2] + m[4];
674 var yt = p[0] * m[1] + p[1] * m[3] + m[5];
675 return [xt, yt];
676 };
677
678 Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
679 var d = m[0] * m[3] - m[1] * m[2];
680 var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
681 var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
682 return [xt, yt];
683 };
684
685 Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) {
686 var p1 = Util.applyTransform(r, m);
687 var p2 = Util.applyTransform(r.slice(2, 4), m);
688 var p3 = Util.applyTransform([r[0], r[3]], m);
689 var p4 = Util.applyTransform([r[2], r[1]], m);
690 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])];
691 };
692
693 Util.inverseTransform = function Util_inverseTransform(m) {
694 var d = m[0] * m[3] - m[1] * m[2];
695 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];
696 };
697
698 Util.apply3dTransform = function Util_apply3dTransform(m, v) {
699 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]];
700 };
701
702 Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) {
703 var transpose = [m[0], m[2], m[1], m[3]];
704 var a = m[0] * transpose[0] + m[1] * transpose[2];
705 var b = m[0] * transpose[1] + m[1] * transpose[3];
706 var c = m[2] * transpose[0] + m[3] * transpose[2];
707 var d = m[2] * transpose[1] + m[3] * transpose[3];
708 var first = (a + d) / 2;
709 var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
710 var sx = first + second || 1;
711 var sy = first - second || 1;
712 return [Math.sqrt(sx), Math.sqrt(sy)];
713 };
714
715 Util.normalizeRect = function Util_normalizeRect(rect) {
716 var r = rect.slice(0);
717
718 if (rect[0] > rect[2]) {
719 r[0] = rect[2];
720 r[2] = rect[0];
721 }
722
723 if (rect[1] > rect[3]) {
724 r[1] = rect[3];
725 r[3] = rect[1];
726 }
727
728 return r;
729 };
730
731 Util.intersect = function Util_intersect(rect1, rect2) {
732 function compare(a, b) {
733 return a - b;
734 }
735
736 var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
737 orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
738 result = [];
739 rect1 = Util.normalizeRect(rect1);
740 rect2 = Util.normalizeRect(rect2);
741
742 if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
743 result[0] = orderedX[1];
744 result[2] = orderedX[2];
745 } else {
746 return false;
747 }
748
749 if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
750 result[1] = orderedY[1];
751 result[3] = orderedY[2];
752 } else {
753 return false;
754 }
755
756 return result;
757 };
758
759 return Util;
760}();
761
762exports.Util = Util;
763var 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];
764
765function stringToPDFString(str) {
766 var i,
767 n = str.length,
768 strBuf = [];
769
770 if (str[0] === '\xFE' && str[1] === '\xFF') {
771 for (i = 2; i < n; i += 2) {
772 strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
773 }
774 } else {
775 for (i = 0; i < n; ++i) {
776 var code = PDFStringTranslateTable[str.charCodeAt(i)];
777 strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
778 }
779 }
780
781 return strBuf.join('');
782}
783
784function stringToUTF8String(str) {
785 return decodeURIComponent(escape(str));
786}
787
788function utf8StringToString(str) {
789 return unescape(encodeURIComponent(str));
790}
791
792function isEmptyObj(obj) {
793 for (var key in obj) {
794 return false;
795 }
796
797 return true;
798}
799
800function isBool(v) {
801 return typeof v === 'boolean';
802}
803
804function isNum(v) {
805 return typeof v === 'number';
806}
807
808function isString(v) {
809 return typeof v === 'string';
810}
811
812function isArrayBuffer(v) {
813 return _typeof(v) === 'object' && v !== null && v.byteLength !== undefined;
814}
815
816function isArrayEqual(arr1, arr2) {
817 if (arr1.length !== arr2.length) {
818 return false;
819 }
820
821 return arr1.every(function (element, index) {
822 return element === arr2[index];
823 });
824}
825
826function isSpace(ch) {
827 return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A;
828}
829
830function createPromiseCapability() {
831 var capability = Object.create(null);
832 var isSettled = false;
833 Object.defineProperty(capability, 'settled', {
834 get: function get() {
835 return isSettled;
836 }
837 });
838 capability.promise = new Promise(function (resolve, reject) {
839 capability.resolve = function (data) {
840 isSettled = true;
841 resolve(data);
842 };
843
844 capability.reject = function (reason) {
845 isSettled = true;
846 reject(reason);
847 };
848 });
849 return capability;
850}
851
852var createObjectURL = function createObjectURLClosure() {
853 var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
854 return function createObjectURL(data, contentType) {
855 var forceDataSchema = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
856
857 if (!forceDataSchema && _url_polyfill.URL.createObjectURL) {
858 var blob = new Blob([data], {
859 type: contentType
860 });
861 return _url_polyfill.URL.createObjectURL(blob);
862 }
863
864 var buffer = 'data:' + contentType + ';base64,';
865
866 for (var i = 0, ii = data.length; i < ii; i += 3) {
867 var b1 = data[i] & 0xFF;
868 var b2 = data[i + 1] & 0xFF;
869 var b3 = data[i + 2] & 0xFF;
870 var d1 = b1 >> 2,
871 d2 = (b1 & 3) << 4 | b2 >> 4;
872 var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
873 var d4 = i + 2 < ii ? b3 & 0x3F : 64;
874 buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
875 }
876
877 return buffer;
878 };
879}();
880
881exports.createObjectURL = createObjectURL;
\No newline at end of file