util.js 26 KB

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