1/** 2 * @licstart The following is the entire license notice for the 3 * JavaScript code in this page 4 * 5 * Copyright 2024 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 23/** 24 * pdfjsVersion = 5.4.296 25 * pdfjsBuild = f56dc8601 26 */ 27/******/ // The require scope 28/******/ var __webpack_require__ = {}; 29/******/ 30/************************************************************************/ 31/******/ /* webpack/runtime/define property getters */ 32/******/ (() => { 33/******/ // define getter functions for harmony exports 34/******/ __webpack_require__.d = (exports, definition) => { 35/******/ for(var key in definition) { 36/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 37/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 38/******/ } 39/******/ } 40/******/ }; 41/******/ })(); 42/******/ 43/******/ /* webpack/runtime/hasOwnProperty shorthand */ 44/******/ (() => { 45/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 46/******/ })(); 47/******/ 48/************************************************************************/ 49var __webpack_exports__ = {}; 50 51;// ./src/shared/util.js
vendor: 23,410 bytes, lines 51-906
51 52const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser"); 53const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0]; 54const LINE_FACTOR = 1.35; 55const LINE_DESCENT_FACTOR = 0.35; 56const BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR; 57const RenderingIntentFlag = { 58 ANY: 0x01, 59 DISPLAY: 0x02, 60 PRINT: 0x04, 61 SAVE: 0x08, 62 ANNOTATIONS_FORMS: 0x10, 63 ANNOTATIONS_STORAGE: 0x20, 64 ANNOTATIONS_DISABLE: 0x40, 65 IS_EDITING: 0x80, 66 OPLIST: 0x100 67}; 68const AnnotationMode = { 69 DISABLE: 0, 70 ENABLE: 1, 71 ENABLE_FORMS: 2, 72 ENABLE_STORAGE: 3 73}; 74const AnnotationEditorPrefix = "pdfjs_internal_editor_"; 75const AnnotationEditorType = { 76 DISABLE: -1, 77 NONE: 0, 78 FREETEXT: 3, 79 HIGHLIGHT: 9, 80 STAMP: 13, 81 INK: 15, 82 POPUP: 16, 83 SIGNATURE: 101, 84 COMMENT: 102 85}; 86const AnnotationEditorParamsType = { 87 RESIZE: 1, 88 CREATE: 2, 89 FREETEXT_SIZE: 11, 90 FREETEXT_COLOR: 12, 91 FREETEXT_OPACITY: 13, 92 INK_COLOR: 21, 93 INK_THICKNESS: 22, 94 INK_OPACITY: 23, 95 HIGHLIGHT_COLOR: 31, 96 HIGHLIGHT_THICKNESS: 32, 97 HIGHLIGHT_FREE: 33, 98 HIGHLIGHT_SHOW_ALL: 34, 99 DRAW_STEP: 41 100}; 101const PermissionFlag = { 102 PRINT: 0x04, 103 MODIFY_CONTENTS: 0x08, 104 COPY: 0x10, 105 MODIFY_ANNOTATIONS: 0x20, 106 FILL_INTERACTIVE_FORMS: 0x100, 107 COPY_FOR_ACCESSIBILITY: 0x200, 108 ASSEMBLE: 0x400, 109 PRINT_HIGH_QUALITY: 0x800 110}; 111const TextRenderingMode = { 112 FILL: 0, 113 STROKE: 1, 114 FILL_STROKE: 2, 115 INVISIBLE: 3, 116 FILL_ADD_TO_PATH: 4, 117 STROKE_ADD_TO_PATH: 5, 118 FILL_STROKE_ADD_TO_PATH: 6, 119 ADD_TO_PATH: 7, 120 FILL_STROKE_MASK: 3, 121 ADD_TO_PATH_FLAG: 4 122}; 123const ImageKind = { 124 GRAYSCALE_1BPP: 1, 125 RGB_24BPP: 2, 126 RGBA_32BPP: 3 127}; 128const AnnotationType = { 129 TEXT: 1, 130 LINK: 2, 131 FREETEXT: 3, 132 LINE: 4, 133 SQUARE: 5, 134 CIRCLE: 6, 135 POLYGON: 7, 136 POLYLINE: 8, 137 HIGHLIGHT: 9, 138 UNDERLINE: 10, 139 SQUIGGLY: 11, 140 STRIKEOUT: 12, 141 STAMP: 13, 142 CARET: 14, 143 INK: 15, 144 POPUP: 16, 145 FILEATTACHMENT: 17, 146 SOUND: 18, 147 MOVIE: 19, 148 WIDGET: 20, 149 SCREEN: 21, 150 PRINTERMARK: 22, 151 TRAPNET: 23, 152 WATERMARK: 24, 153 THREED: 25, 154 REDACT: 26 155}; 156const AnnotationReplyType = { 157 GROUP: "Group", 158 REPLY: "R" 159}; 160const AnnotationFlag = { 161 INVISIBLE: 0x01, 162 HIDDEN: 0x02, 163 PRINT: 0x04, 164 NOZOOM: 0x08, 165 NOROTATE: 0x10, 166 NOVIEW: 0x20, 167 READONLY: 0x40, 168 LOCKED: 0x80, 169 TOGGLENOVIEW: 0x100, 170 LOCKEDCONTENTS: 0x200 171}; 172const AnnotationFieldFlag = { 173 READONLY: 0x0000001, 174 REQUIRED: 0x0000002, 175 NOEXPORT: 0x0000004, 176 MULTILINE: 0x0001000, 177 PASSWORD: 0x0002000, 178 NOTOGGLETOOFF: 0x0004000, 179 RADIO: 0x0008000, 180 PUSHBUTTON: 0x0010000, 181 COMBO: 0x0020000, 182 EDIT: 0x0040000, 183 SORT: 0x0080000, 184 FILESELECT: 0x0100000, 185 MULTISELECT: 0x0200000, 186 DONOTSPELLCHECK: 0x0400000, 187 DONOTSCROLL: 0x0800000, 188 COMB: 0x1000000, 189 RICHTEXT: 0x2000000, 190 RADIOSINUNISON: 0x2000000, 191 COMMITONSELCHANGE: 0x4000000 192}; 193const AnnotationBorderStyleType = { 194 SOLID: 1, 195 DASHED: 2, 196 BEVELED: 3, 197 INSET: 4, 198 UNDERLINE: 5 199}; 200const AnnotationActionEventType = { 201 E: "Mouse Enter", 202 X: "Mouse Exit", 203 D: "Mouse Down", 204 U: "Mouse Up", 205 Fo: "Focus", 206 Bl: "Blur", 207 PO: "PageOpen", 208 PC: "PageClose", 209 PV: "PageVisible", 210 PI: "PageInvisible", 211 K: "Keystroke", 212 F: "Format", 213 V: "Validate", 214 C: "Calculate" 215}; 216const DocumentActionEventType = { 217 WC: "WillClose", 218 WS: "WillSave", 219 DS: "DidSave", 220 WP: "WillPrint", 221 DP: "DidPrint" 222}; 223const PageActionEventType = { 224 O: "PageOpen", 225 C: "PageClose" 226}; 227const VerbosityLevel = { 228 ERRORS: 0, 229 WARNINGS: 1, 230 INFOS: 5 231}; 232const 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 beginAnnotation: 80, 311 endAnnotation: 81, 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 setStrokeTransparent: 92, 322 setFillTransparent: 93, 323 rawFillPath: 94 324}; 325const DrawOPS = { 326 moveTo: 0, 327 lineTo: 1, 328 curveTo: 2, 329 closePath: 3 330}; 331const PasswordResponses = { 332 NEED_PASSWORD: 1, 333 INCORRECT_PASSWORD: 2 334}; 335let verbosity = VerbosityLevel.WARNINGS; 336function setVerbosityLevel(level) { 337 if (Number.isInteger(level)) { 338 verbosity = level; 339 } 340} 341function getVerbosityLevel() { 342 return verbosity; 343} 344function info(msg) { 345 if (verbosity >= VerbosityLevel.INFOS) { 346 console.info(`Info: ${msg}`); 347 } 348} 349function warn(msg) { 350 if (verbosity >= VerbosityLevel.WARNINGS) { 351 console.warn(`Warning: ${msg}`); 352 } 353} 354function unreachable(msg) { 355 throw new Error(msg); 356} 357function assert(cond, msg) { 358 if (!cond) { 359 unreachable(msg); 360 } 361} 362function _isValidProtocol(url) { 363 switch (url?.protocol) { 364 case "http:": 365 case "https:": 366 case "ftp:": 367 case "mailto:": 368 case "tel:": 369 return true; 370 default: 371 return false; 372 } 373} 374function createValidAbsoluteUrl(url, baseUrl = null, options = null) { 375 if (!url) { 376 return null; 377 } 378 if (options && typeof url === "string") { 379 if (options.addDefaultProtocol && url.startsWith("www.")) { 380 const dots = url.match(/\./g); 381 if (dots?.length >= 2) { 382 url = `http://${url}`; 383 } 384 } 385 if (options.tryConvertEncoding) { 386 try { 387 url = stringToUTF8String(url); 388 } catch {} 389 } 390 } 391 const absoluteUrl = baseUrl ? URL.parse(url, baseUrl) : URL.parse(url); 392 return _isValidProtocol(absoluteUrl) ? absoluteUrl : null; 393} 394function updateUrlHash(url, hash, allowRel = false) { 395 const res = URL.parse(url); 396 if (res) { 397 res.hash = hash; 398 return res.href; 399 } 400 if (allowRel && createValidAbsoluteUrl(url, "http://example.com")) { 401 return url.split("#", 1)[0] + `${hash ? `#${hash}` : ""}`; 402 } 403 return ""; 404} 405function shadow(obj, prop, value, nonSerializable = false) { 406 Object.defineProperty(obj, prop, { 407 value, 408 enumerable: !nonSerializable, 409 configurable: true, 410 writable: false 411 }); 412 return value; 413} 414const BaseException = function BaseExceptionClosure() { 415 function BaseException(message, name) { 416 this.message = message; 417 this.name = name; 418 } 419 BaseException.prototype = new Error(); 420 BaseException.constructor = BaseException; 421 return BaseException; 422}(); 423class PasswordException extends BaseException { 424 constructor(msg, code) { 425 super(msg, "PasswordException"); 426 this.code = code; 427 } 428} 429class UnknownErrorException extends BaseException { 430 constructor(msg, details) { 431 super(msg, "UnknownErrorException"); 432 this.details = details; 433 } 434} 435class InvalidPDFException extends BaseException { 436 constructor(msg) { 437 super(msg, "InvalidPDFException"); 438 } 439} 440class ResponseException extends BaseException { 441 constructor(msg, status, missing) { 442 super(msg, "ResponseException"); 443 this.status = status; 444 this.missing = missing; 445 } 446} 447class FormatError extends BaseException { 448 constructor(msg) { 449 super(msg, "FormatError"); 450 } 451} 452class AbortException extends BaseException { 453 constructor(msg) { 454 super(msg, "AbortException"); 455 } 456} 457function bytesToString(bytes) { 458 if (typeof bytes !== "object" || bytes?.length === undefined) { 459 unreachable("Invalid argument for bytesToString"); 460 } 461 const length = bytes.length; 462 const MAX_ARGUMENT_COUNT = 8192; 463 if (length < MAX_ARGUMENT_COUNT) { 464 return String.fromCharCode.apply(null, bytes); 465 } 466 const strBuf = []; 467 for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) { 468 const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length); 469 const chunk = bytes.subarray(i, chunkEnd); 470 strBuf.push(String.fromCharCode.apply(null, chunk)); 471 } 472 return strBuf.join(""); 473} 474function stringToBytes(str) { 475 if (typeof str !== "string") { 476 unreachable("Invalid argument for stringToBytes"); 477 } 478 const length = str.length; 479 const bytes = new Uint8Array(length); 480 for (let i = 0; i < length; ++i) { 481 bytes[i] = str.charCodeAt(i) & 0xff; 482 } 483 return bytes; 484} 485function string32(value) { 486 return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff); 487} 488function objectSize(obj) { 489 return Object.keys(obj).length; 490} 491function isLittleEndian() { 492 const buffer8 = new Uint8Array(4); 493 buffer8[0] = 1; 494 const view32 = new Uint32Array(buffer8.buffer, 0, 1); 495 return view32[0] === 1; 496} 497function isEvalSupported() { 498 try { 499 new Function(""); 500 return true; 501 } catch { 502 return false; 503 } 504} 505class FeatureTest { 506 static get isLittleEndian() { 507 return shadow(this, "isLittleEndian", isLittleEndian()); 508 } 509 static get isEvalSupported() { 510 return shadow(this, "isEvalSupported", isEvalSupported()); 511 } 512 static get isOffscreenCanvasSupported() { 513 return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined"); 514 } 515 static get isImageDecoderSupported() { 516 return shadow(this, "isImageDecoderSupported", typeof ImageDecoder !== "undefined"); 517 } 518 static get platform() { 519 const { 520 platform, 521 userAgent 522 } = navigator; 523 return shadow(this, "platform", { 524 isAndroid: userAgent.includes("Android"), 525 isLinux: platform.includes("Linux"), 526 isMac: platform.includes("Mac"), 527 isWindows: platform.includes("Win"), 528 isFirefox: userAgent.includes("Firefox") 529 }); 530 } 531 static get isCSSRoundSupported() { 532 return shadow(this, "isCSSRoundSupported", globalThis.CSS?.supports?.("width: round(1.5px, 1px)")); 533 } 534} 535const hexNumbers = Array.from(Array(256).keys(), n => n.toString(16).padStart(2, "0")); 536class Util { 537 static makeHexColor(r, g, b) { 538 return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`; 539 } 540 static domMatrixToTransform(dm) { 541 return [dm.a, dm.b, dm.c, dm.d, dm.e, dm.f]; 542 } 543 static scaleMinMax(transform, minMax) { 544 let temp; 545 if (transform[0]) { 546 if (transform[0] < 0) { 547 temp = minMax[0]; 548 minMax[0] = minMax[2]; 549 minMax[2] = temp; 550 } 551 minMax[0] *= transform[0]; 552 minMax[2] *= transform[0]; 553 if (transform[3] < 0) { 554 temp = minMax[1]; 555 minMax[1] = minMax[3]; 556 minMax[3] = temp; 557 } 558 minMax[1] *= transform[3]; 559 minMax[3] *= transform[3]; 560 } else { 561 temp = minMax[0]; 562 minMax[0] = minMax[1]; 563 minMax[1] = temp; 564 temp = minMax[2]; 565 minMax[2] = minMax[3]; 566 minMax[3] = temp; 567 if (transform[1] < 0) { 568 temp = minMax[1]; 569 minMax[1] = minMax[3]; 570 minMax[3] = temp; 571 } 572 minMax[1] *= transform[1]; 573 minMax[3] *= transform[1]; 574 if (transform[2] < 0) { 575 temp = minMax[0]; 576 minMax[0] = minMax[2]; 577 minMax[2] = temp; 578 } 579 minMax[0] *= transform[2]; 580 minMax[2] *= transform[2]; 581 } 582 minMax[0] += transform[4]; 583 minMax[1] += transform[5]; 584 minMax[2] += transform[4]; 585 minMax[3] += transform[5]; 586 } 587 static transform(m1, m2) { 588 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]]; 589 } 590 static multiplyByDOMMatrix(m, md) { 591 return [m[0] * md.a + m[2] * md.b, m[1] * md.a + m[3] * md.b, m[0] * md.c + m[2] * md.d, m[1] * md.c + m[3] * md.d, m[0] * md.e + m[2] * md.f + m[4], m[1] * md.e + m[3] * md.f + m[5]]; 592 } 593 static applyTransform(p, m, pos = 0) { 594 const p0 = p[pos]; 595 const p1 = p[pos + 1]; 596 p[pos] = p0 * m[0] + p1 * m[2] + m[4]; 597 p[pos + 1] = p0 * m[1] + p1 * m[3] + m[5]; 598 } 599 static applyTransformToBezier(p, transform, pos = 0) { 600 const m0 = transform[0]; 601 const m1 = transform[1]; 602 const m2 = transform[2]; 603 const m3 = transform[3]; 604 const m4 = transform[4]; 605 const m5 = transform[5]; 606 for (let i = 0; i < 6; i += 2) { 607 const pI = p[pos + i]; 608 const pI1 = p[pos + i + 1]; 609 p[pos + i] = pI * m0 + pI1 * m2 + m4; 610 p[pos + i + 1] = pI * m1 + pI1 * m3 + m5; 611 } 612 } 613 static applyInverseTransform(p, m) { 614 const p0 = p[0]; 615 const p1 = p[1]; 616 const d = m[0] * m[3] - m[1] * m[2]; 617 p[0] = (p0 * m[3] - p1 * m[2] + m[2] * m[5] - m[4] * m[3]) / d; 618 p[1] = (-p0 * m[1] + p1 * m[0] + m[4] * m[1] - m[5] * m[0]) / d; 619 } 620 static axialAlignedBoundingBox(rect, transform, output) { 621 const m0 = transform[0]; 622 const m1 = transform[1]; 623 const m2 = transform[2]; 624 const m3 = transform[3]; 625 const m4 = transform[4]; 626 const m5 = transform[5]; 627 const r0 = rect[0]; 628 const r1 = rect[1]; 629 const r2 = rect[2]; 630 const r3 = rect[3]; 631 let a0 = m0 * r0 + m4; 632 let a2 = a0; 633 let a1 = m0 * r2 + m4; 634 let a3 = a1; 635 let b0 = m3 * r1 + m5; 636 let b2 = b0; 637 let b1 = m3 * r3 + m5; 638 let b3 = b1; 639 if (m1 !== 0 || m2 !== 0) { 640 const m1r0 = m1 * r0; 641 const m1r2 = m1 * r2; 642 const m2r1 = m2 * r1; 643 const m2r3 = m2 * r3; 644 a0 += m2r1; 645 a3 += m2r1; 646 a1 += m2r3; 647 a2 += m2r3; 648 b0 += m1r0; 649 b3 += m1r0; 650 b1 += m1r2; 651 b2 += m1r2; 652 } 653 output[0] = Math.min(output[0], a0, a1, a2, a3); 654 output[1] = Math.min(output[1], b0, b1, b2, b3); 655 output[2] = Math.max(output[2], a0, a1, a2, a3); 656 output[3] = Math.max(output[3], b0, b1, b2, b3); 657 } 658 static inverseTransform(m) { 659 const d = m[0] * m[3] - m[1] * m[2]; 660 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]; 661 } 662 static singularValueDecompose2dScale(matrix, output) { 663 const m0 = matrix[0]; 664 const m1 = matrix[1]; 665 const m2 = matrix[2]; 666 const m3 = matrix[3]; 667 const a = m0 ** 2 + m1 ** 2; 668 const b = m0 * m2 + m1 * m3; 669 const c = m2 ** 2 + m3 ** 2; 670 const first = (a + c) / 2; 671 const second = Math.sqrt(first ** 2 - (a * c - b ** 2)); 672 output[0] = Math.sqrt(first + second || 1); 673 output[1] = Math.sqrt(first - second || 1); 674 } 675 static normalizeRect(rect) { 676 const r = rect.slice(0); 677 if (rect[0] > rect[2]) { 678 r[0] = rect[2]; 679 r[2] = rect[0]; 680 } 681 if (rect[1] > rect[3]) { 682 r[1] = rect[3]; 683 r[3] = rect[1]; 684 } 685 return r; 686 } 687 static intersect(rect1, rect2) { 688 const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2])); 689 const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2])); 690 if (xLow > xHigh) { 691 return null; 692 } 693 const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3])); 694 const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3])); 695 if (yLow > yHigh) { 696 return null; 697 } 698 return [xLow, yLow, xHigh, yHigh]; 699 } 700 static pointBoundingBox(x, y, minMax) { 701 minMax[0] = Math.min(minMax[0], x); 702 minMax[1] = Math.min(minMax[1], y); 703 minMax[2] = Math.max(minMax[2], x); 704 minMax[3] = Math.max(minMax[3], y); 705 } 706 static rectBoundingBox(x0, y0, x1, y1, minMax) { 707 minMax[0] = Math.min(minMax[0], x0, x1); 708 minMax[1] = Math.min(minMax[1], y0, y1); 709 minMax[2] = Math.max(minMax[2], x0, x1); 710 minMax[3] = Math.max(minMax[3], y0, y1); 711 } 712 static #getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, t, minMax) { 713 if (t <= 0 || t >= 1) { 714 return; 715 } 716 const mt = 1 - t; 717 const tt = t * t; 718 const ttt = tt * t; 719 const x = mt * (mt * (mt * x0 + 3 * t * x1) + 3 * tt * x2) + ttt * x3; 720 const y = mt * (mt * (mt * y0 + 3 * t * y1) + 3 * tt * y2) + ttt * y3; 721 minMax[0] = Math.min(minMax[0], x); 722 minMax[1] = Math.min(minMax[1], y); 723 minMax[2] = Math.max(minMax[2], x); 724 minMax[3] = Math.max(minMax[3], y); 725 } 726 static #getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, a, b, c, minMax) { 727 if (Math.abs(a) < 1e-12) { 728 if (Math.abs(b) >= 1e-12) { 729 this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, -c / b, minMax); 730 } 731 return; 732 } 733 const delta = b ** 2 - 4 * c * a; 734 if (delta < 0) { 735 return; 736 } 737 const sqrtDelta = Math.sqrt(delta); 738 const a2 = 2 * a; 739 this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b + sqrtDelta) / a2, minMax); 740 this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b - sqrtDelta) / a2, minMax); 741 } 742 static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax) { 743 minMax[0] = Math.min(minMax[0], x0, x3); 744 minMax[1] = Math.min(minMax[1], y0, y3); 745 minMax[2] = Math.max(minMax[2], x0, x3); 746 minMax[3] = Math.max(minMax[3], y0, y3); 747 this.#getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-x0 + 3 * (x1 - x2) + x3), 6 * (x0 - 2 * x1 + x2), 3 * (x1 - x0), minMax); 748 this.#getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-y0 + 3 * (y1 - y2) + y3), 6 * (y0 - 2 * y1 + y2), 3 * (y1 - y0), minMax); 749 } 750} 751const 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]; 752function stringToPDFString(str, keepEscapeSequence = false) { 753 if (str[0] >= "\xEF") { 754 let encoding; 755 if (str[0] === "\xFE" && str[1] === "\xFF") { 756 encoding = "utf-16be"; 757 if (str.length % 2 === 1) { 758 str = str.slice(0, -1); 759 } 760 } else if (str[0] === "\xFF" && str[1] === "\xFE") { 761 encoding = "utf-16le"; 762 if (str.length % 2 === 1) { 763 str = str.slice(0, -1); 764 } 765 } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") { 766 encoding = "utf-8"; 767 } 768 if (encoding) { 769 try { 770 const decoder = new TextDecoder(encoding, { 771 fatal: true 772 }); 773 const buffer = stringToBytes(str); 774 const decoded = decoder.decode(buffer); 775 if (keepEscapeSequence || !decoded.includes("\x1b")) { 776 return decoded; 777 } 778 return decoded.replaceAll(/\x1b[^\x1b]*(?:\x1b|$)/g, ""); 779 } catch (ex) { 780 warn(`stringToPDFString: "${ex}".`); 781 } 782 } 783 } 784 const strBuf = []; 785 for (let i = 0, ii = str.length; i < ii; i++) { 786 const charCode = str.charCodeAt(i); 787 if (!keepEscapeSequence && charCode === 0x1b) { 788 while (++i < ii && str.charCodeAt(i) !== 0x1b) {} 789 continue; 790 } 791 const code = PDFStringTranslateTable[charCode]; 792 strBuf.push(code ? String.fromCharCode(code) : str.charAt(i)); 793 } 794 return strBuf.join(""); 795} 796function stringToUTF8String(str) { 797 return decodeURIComponent(escape(str)); 798} 799function utf8StringToString(str) { 800 return unescape(encodeURIComponent(str)); 801} 802function isArrayEqual(arr1, arr2) { 803 if (arr1.length !== arr2.length) { 804 return false; 805 } 806 for (let i = 0, ii = arr1.length; i < ii; i++) { 807 if (arr1[i] !== arr2[i]) { 808 return false; 809 } 810 } 811 return true; 812} 813function getModificationDate(date = new Date()) { 814 if (!(date instanceof Date)) { 815 date = new Date(date); 816 } 817 const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")]; 818 return buffer.join(""); 819} 820let NormalizeRegex = null; 821let NormalizationMap = null; 822function normalizeUnicode(str) { 823 if (!NormalizeRegex) { 824 NormalizeRegex = /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu; 825 NormalizationMap = new Map([["ſt", "ſt"]]); 826 } 827 return str.replaceAll(NormalizeRegex, (_, p1, p2) => p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2)); 828} 829function getUuid() { 830 if (typeof crypto.randomUUID === "function") { 831 return crypto.randomUUID(); 832 } 833 const buf = new Uint8Array(32); 834 crypto.getRandomValues(buf); 835 return bytesToString(buf); 836} 837const AnnotationPrefix = "pdfjs_internal_id_"; 838function _isValidExplicitDest(validRef, validName, dest) { 839 if (!Array.isArray(dest) || dest.length < 2) { 840 return false; 841 } 842 const [page, zoom, ...args] = dest; 843 if (!validRef(page) && !Number.isInteger(page)) { 844 return false; 845 } 846 if (!validName(zoom)) { 847 return false; 848 } 849 const argsLen = args.length; 850 let allowNull = true; 851 switch (zoom.name) { 852 case "XYZ": 853 if (argsLen < 2 || argsLen > 3) { 854 return false; 855 } 856 break; 857 case "Fit": 858 case "FitB": 859 return argsLen === 0; 860 case "FitH": 861 case "FitBH": 862 case "FitV": 863 case "FitBV": 864 if (argsLen > 1) { 865 return false; 866 } 867 break; 868 case "FitR": 869 if (argsLen !== 4) { 870 return false; 871 } 872 allowNull = false; 873 break; 874 default: 875 return false; 876 } 877 for (const arg of args) { 878 if (typeof arg === "number" || allowNull && arg === null) { 879 continue; 880 } 881 return false; 882 } 883 return true; 884} 885function MathClamp(v, min, max) { 886 return Math.min(Math.max(v, min), max); 887} 888function toHexUtil(arr) { 889 if (Uint8Array.prototype.toHex) { 890 return arr.toHex(); 891 } 892 return Array.from(arr, num => hexNumbers[num]).join(""); 893} 894function toBase64Util(arr) { 895 if (Uint8Array.prototype.toBase64) { 896 return arr.toBase64(); 897 } 898 return btoa(bytesToString(arr)); 899} 900function fromBase64Util(str) { 901 if (Uint8Array.fromBase64) { 902 return Uint8Array.fromBase64(str); 903 } 904 return stringToBytes(atob(str)); 905} 906if (typeof
906Promise.try !== "function") { 907 Promise.try = function (fn, ...args) { 908 return new Promise(resolve => { 909 resolve(fn(...args)); 910 }); 911 }; 912} 913if (typeof Math.sumPrecise !== "function") { 914 Math.sumPrecise = function (numbers) { 915 return numbers.reduce((a, b) => a + b, 0); 916 }; 917} 918 919;// ./src/core/primitives.js
vendor: 22,270 bytes, lines 919-1759
919 920 921const CIRCULAR_REF = Symbol("CIRCULAR_REF"); 922const EOF = Symbol("EOF"); 923let CmdCache = Object.create(null); 924let NameCache = Object.create(null); 925let RefCache = Object.create(null); 926function clearPrimitiveCaches() { 927 CmdCache = Object.create(null); 928 NameCache = Object.create(null); 929 RefCache = Object.create(null); 930} 931class Name { 932 constructor(name) { 933 this.name = name; 934 } 935 static get(name) { 936 return NameCache[name] ||= new Name(name); 937 } 938} 939class Cmd { 940 constructor(cmd) { 941 this.cmd = cmd; 942 } 943 static get(cmd) { 944 return CmdCache[cmd] ||= new Cmd(cmd); 945 } 946} 947const nonSerializable = function nonSerializableClosure() { 948 return nonSerializable; 949}; 950class Dict { 951 constructor(xref = null) { 952 this._map = new Map(); 953 this.xref = xref; 954 this.objId = null; 955 this.suppressEncryption = false; 956 this.__nonSerializable__ = nonSerializable; 957 } 958 assignXref(newXref) { 959 this.xref = newXref; 960 } 961 get size() { 962 return this._map.size; 963 } 964 get(key1, key2, key3) { 965 let value = this._map.get(key1); 966 if (value === undefined && key2 !== undefined) { 967 value = this._map.get(key2); 968 if (value === undefined && key3 !== undefined) { 969 value = this._map.get(key3); 970 } 971 } 972 if (value instanceof Ref && this.xref) { 973 return this.xref.fetch(value, this.suppressEncryption); 974 } 975 return value; 976 } 977 async getAsync(key1, key2, key3) { 978 let value = this._map.get(key1); 979 if (value === undefined && key2 !== undefined) { 980 value = this._map.get(key2); 981 if (value === undefined && key3 !== undefined) { 982 value = this._map.get(key3); 983 } 984 } 985 if (value instanceof Ref && this.xref) { 986 return this.xref.fetchAsync(value, this.suppressEncryption); 987 } 988 return value; 989 } 990 getArray(key1, key2, key3) { 991 let value = this._map.get(key1); 992 if (value === undefined && key2 !== undefined) { 993 value = this._map.get(key2); 994 if (value === undefined && key3 !== undefined) { 995 value = this._map.get(key3); 996 } 997 } 998 if (value instanceof Ref && this.xref) { 999 value = this.xref.fetch(value, this.suppressEncryption); 1000 } 1001 if (Array.isArray(value)) { 1002 value = value.slice(); 1003 for (let i = 0, ii = value.length; i < ii; i++) { 1004 if (value[i] instanceof Ref && this.xref) { 1005 value[i] = this.xref.fetch(value[i], this.suppressEncryption); 1006 } 1007 } 1008 } 1009 return value; 1010 } 1011 getRaw(key) { 1012 return this._map.get(key); 1013 } 1014 getKeys() { 1015 return [...this._map.keys()]; 1016 } 1017 getRawValues() { 1018 return [...this._map.values()]; 1019 } 1020 set(key, value) { 1021 this._map.set(key, value); 1022 } 1023 setIfNotExists(key, value) { 1024 if (!this.has(key)) { 1025 this.set(key, value); 1026 } 1027 } 1028 setIfNumber(key, value) { 1029 if (typeof value === "number") { 1030 this.set(key, value); 1031 } 1032 } 1033 setIfArray(key, value) { 1034 if (Array.isArray(value) || ArrayBuffer.isView(value)) { 1035 this.set(key, value); 1036 } 1037 } 1038 setIfDefined(key, value) { 1039 if (value !== undefined && value !== null) { 1040 this.set(key, value); 1041 } 1042 } 1043 setIfName(key, value) { 1044 if (typeof value === "string") { 1045 this.set(key, Name.get(value)); 1046 } else if (value instanceof Name) { 1047 this.set(key, value); 1048 } 1049 } 1050 has(key) { 1051 return this._map.has(key); 1052 } 1053 *[Symbol.iterator]() { 1054 for (const [key, value] of this._map) { 1055 yield [key, value instanceof Ref && this.xref ? this.xref.fetch(value, this.suppressEncryption) : value]; 1056 } 1057 } 1058 static get empty() { 1059 const emptyDict = new Dict(null); 1060 emptyDict.set = (key, value) => { 1061 unreachable("Should not call `set` on the empty dictionary."); 1062 }; 1063 return shadow(this, "empty", emptyDict); 1064 } 1065 static merge({ 1066 xref, 1067 dictArray, 1068 mergeSubDicts = false 1069 }) { 1070 const mergedDict = new Dict(xref), 1071 properties = new Map(); 1072 for (const dict of dictArray) { 1073 if (!(dict instanceof Dict)) { 1074 continue; 1075 } 1076 for (const [key, value] of dict._map) { 1077 let property = properties.get(key); 1078 if (property === undefined) { 1079 property = []; 1080 properties.set(key, property); 1081 } else if (!mergeSubDicts || !(value instanceof Dict)) { 1082 continue; 1083 } 1084 property.push(value); 1085 } 1086 } 1087 for (const [name, values] of properties) { 1088 if (values.length === 1 || !(values[0] instanceof Dict)) { 1089 mergedDict._map.set(name, values[0]); 1090 continue; 1091 } 1092 const subDict = new Dict(xref); 1093 for (const dict of values) { 1094 for (const [key, value] of dict._map) { 1095 if (!subDict._map.has(key)) { 1096 subDict._map.set(key, value); 1097 } 1098 } 1099 } 1100 if (subDict.size > 0) { 1101 mergedDict._map.set(name, subDict); 1102 } 1103 } 1104 properties.clear(); 1105 return mergedDict.size > 0 ? mergedDict : Dict.empty; 1106 } 1107 clone() { 1108 const dict = new Dict(this.xref); 1109 for (const key of this.getKeys()) { 1110 dict.set(key, this.getRaw(key)); 1111 } 1112 return dict; 1113 } 1114 delete(key) { 1115 this._map.delete(key); 1116 } 1117} 1118class Ref { 1119 constructor(num, gen) { 1120 this.num = num; 1121 this.gen = gen; 1122 } 1123 toString() { 1124 if (this.gen === 0) { 1125 return `${this.num}R`; 1126 } 1127 return `${this.num}R${this.gen}`; 1128 } 1129 static fromString(str) { 1130 const ref = RefCache[str]; 1131 if (ref) { 1132 return ref; 1133 } 1134 const m = /^(\d+)R(\d*)$/.exec(str); 1135 if (!m || m[1] === "0") { 1136 return null; 1137 } 1138 return RefCache[str] = new Ref(parseInt(m[1]), !m[2] ? 0 : parseInt(m[2])); 1139 } 1140 static get(num, gen) { 1141 const key = gen === 0 ? `${num}R` : `${num}R${gen}`; 1142 return RefCache[key] ||= new Ref(num, gen); 1143 } 1144} 1145class RefSet { 1146 constructor(parent = null) { 1147 this._set = new Set(parent?._set); 1148 } 1149 has(ref) { 1150 return this._set.has(ref.toString()); 1151 } 1152 put(ref) { 1153 this._set.add(ref.toString()); 1154 } 1155 remove(ref) { 1156 this._set.delete(ref.toString()); 1157 } 1158 [Symbol.iterator]() { 1159 return this._set.values(); 1160 } 1161 clear() { 1162 this._set.clear(); 1163 } 1164} 1165class RefSetCache { 1166 constructor() { 1167 this._map = new Map(); 1168 } 1169 get size() { 1170 return this._map.size; 1171 } 1172 get(ref) { 1173 return this._map.get(ref.toString()); 1174 } 1175 has(ref) { 1176 return this._map.has(ref.toString()); 1177 } 1178 put(ref, obj) { 1179 this._map.set(ref.toString(), obj); 1180 } 1181 putAlias(ref, aliasRef) { 1182 this._map.set(ref.toString(), this.get(aliasRef)); 1183 } 1184 [Symbol.iterator]() { 1185 return this._map.values(); 1186 } 1187 clear() { 1188 this._map.clear(); 1189 } 1190 *values() { 1191 yield* this._map.values(); 1192 } 1193 *items() { 1194 for (const [ref, value] of this._map) { 1195 yield [Ref.fromString(ref), value]; 1196 } 1197 } 1198} 1199function isName(v, name) { 1200 return v instanceof Name && (name === undefined || v.name === name); 1201} 1202function isCmd(v, cmd) { 1203 return v instanceof Cmd && (cmd === undefined || v.cmd === cmd); 1204} 1205function isDict(v, type) { 1206 return v instanceof Dict && (type === undefined || isName(v.get("Type"), type)); 1207} 1208function isRefsEqual(v1, v2) { 1209 return v1.num === v2.num && v1.gen === v2.gen; 1210} 1211 1212;// ./src/core/base_stream.js 1213 1214class BaseStream { 1215 get length() { 1216 unreachable("Abstract getter `length` accessed"); 1217 } 1218 get isEmpty() { 1219 unreachable("Abstract getter `isEmpty` accessed"); 1220 } 1221 get isDataLoaded() { 1222 return shadow(this, "isDataLoaded", true); 1223 } 1224 getByte() { 1225 unreachable("Abstract method `getByte` called"); 1226 } 1227 getBytes(length) { 1228 unreachable("Abstract method `getBytes` called"); 1229 } 1230 async getImageData(length, decoderOptions) { 1231 return this.getBytes(length, decoderOptions); 1232 } 1233 async asyncGetBytes() { 1234 unreachable("Abstract method `asyncGetBytes` called"); 1235 } 1236 get isAsync() { 1237 return false; 1238 } 1239 get isAsyncDecoder() { 1240 return false; 1241 } 1242 get canAsyncDecodeImageFromBuffer() { 1243 return false; 1244 } 1245 async getTransferableImage() { 1246 return null; 1247 } 1248 peekByte() { 1249 const peekedByte = this.getByte(); 1250 if (peekedByte !== -1) { 1251 this.pos--; 1252 } 1253 return peekedByte; 1254 } 1255 peekBytes(length) { 1256 const bytes = this.getBytes(length); 1257 this.pos -= bytes.length; 1258 return bytes; 1259 } 1260 getUint16() { 1261 const b0 = this.getByte(); 1262 const b1 = this.getByte(); 1263 if (b0 === -1 || b1 === -1) { 1264 return -1; 1265 } 1266 return (b0 << 8) + b1; 1267 } 1268 getInt32() { 1269 const b0 = this.getByte(); 1270 const b1 = this.getByte(); 1271 const b2 = this.getByte(); 1272 const b3 = this.getByte(); 1273 return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3; 1274 } 1275 getByteRange(begin, end) { 1276 unreachable("Abstract method `getByteRange` called"); 1277 } 1278 getString(length) { 1279 return bytesToString(this.getBytes(length)); 1280 } 1281 skip(n) { 1282 this.pos += n || 1; 1283 } 1284 reset() { 1285 unreachable("Abstract method `reset` called"); 1286 } 1287 moveStart() { 1288 unreachable("Abstract method `moveStart` called"); 1289 } 1290 makeSubStream(start, length, dict = null) { 1291 unreachable("Abstract method `makeSubStream` called"); 1292 } 1293 getBaseStreams() { 1294 return null; 1295 } 1296} 1297 1298;// ./src/core/core_utils.js 1299 1300 1301 1302const PDF_VERSION_REGEXP = /^[1-9]\.\d$/; 1303const MAX_INT_32 = 2 ** 31 - 1; 1304const MIN_INT_32 = -(2 ** 31); 1305const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; 1306const RESOURCES_KEYS_OPERATOR_LIST = ["ColorSpace", "ExtGState", "Font", "Pattern", "Properties", "Shading", "XObject"]; 1307const RESOURCES_KEYS_TEXT_CONTENT = ["ExtGState", "Font", "Properties", "XObject"]; 1308function getLookupTableFactory(initializer) { 1309 let lookup; 1310 return function () { 1311 if (initializer) { 1312 lookup = Object.create(null); 1313 initializer(lookup); 1314 initializer = null; 1315 } 1316 return lookup; 1317 }; 1318} 1319class MissingDataException extends BaseException { 1320 constructor(begin, end) { 1321 super(`Missing data [${begin}, ${end})`, "MissingDataException"); 1322 this.begin = begin; 1323 this.end = end; 1324 } 1325} 1326class ParserEOFException extends BaseException { 1327 constructor(msg) { 1328 super(msg, "ParserEOFException"); 1329 } 1330} 1331class XRefEntryException extends BaseException { 1332 constructor(msg) { 1333 super(msg, "XRefEntryException"); 1334 } 1335} 1336class XRefParseException extends BaseException { 1337 constructor(msg) { 1338 super(msg, "XRefParseException"); 1339 } 1340} 1341function arrayBuffersToBytes(arr) { 1342 const length = arr.length; 1343 if (length === 0) { 1344 return new Uint8Array(0); 1345 } 1346 if (length === 1) { 1347 return new Uint8Array(arr[0]); 1348 } 1349 let dataLength = 0; 1350 for (let i = 0; i < length; i++) { 1351 dataLength += arr[i].byteLength; 1352 } 1353 const data = new Uint8Array(dataLength); 1354 let pos = 0; 1355 for (let i = 0; i < length; i++) { 1356 const item = new Uint8Array(arr[i]); 1357 data.set(item, pos); 1358 pos += item.byteLength; 1359 } 1360 return data; 1361} 1362async function fetchBinaryData(url) { 1363 const response = await fetch(url); 1364 if (!response.ok) { 1365 throw new Error(`Failed to fetch file "${url}" with "${response.statusText}".`); 1366 } 1367 return new Uint8Array(await response.arrayBuffer()); 1368} 1369function getInheritableProperty({ 1370 dict, 1371 key, 1372 getArray = false, 1373 stopWhenFound = true 1374}) { 1375 let values; 1376 const visited = new RefSet(); 1377 while (dict instanceof Dict && !(dict.objId && visited.has(dict.objId))) { 1378 if (dict.objId) { 1379 visited.put(dict.objId); 1380 } 1381 const value = getArray ? dict.getArray(key) : dict.get(key); 1382 if (value !== undefined) { 1383 if (stopWhenFound) { 1384 return value; 1385 } 1386 (values ||= []).push(value); 1387 } 1388 dict = dict.get("Parent"); 1389 } 1390 return values; 1391} 1392function getParentToUpdate(dict, ref, xref) { 1393 const visited = new RefSet(); 1394 const firstDict = dict; 1395 const result = { 1396 dict: null, 1397 ref: null 1398 }; 1399 while (dict instanceof Dict && !visited.has(ref)) { 1400 visited.put(ref); 1401 if (dict.has("T")) { 1402 break; 1403 } 1404 ref = dict.getRaw("Parent"); 1405 if (!(ref instanceof Ref)) { 1406 return result; 1407 } 1408 dict = xref.fetch(ref); 1409 } 1410 if (dict instanceof Dict && dict !== firstDict) { 1411 result.dict = dict; 1412 result.ref = ref; 1413 } 1414 return result; 1415} 1416const 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"]; 1417function toRomanNumerals(number, lowerCase = false) { 1418 assert(Number.isInteger(number) && number > 0, "The number should be a positive integer."); 1419 const roman = "M".repeat(number / 1000 | 0) + ROMAN_NUMBER_MAP[number % 1000 / 100 | 0] + ROMAN_NUMBER_MAP[10 + (number % 100 / 10 | 0)] + ROMAN_NUMBER_MAP[20 + number % 10]; 1420 return lowerCase ? roman.toLowerCase() : roman; 1421} 1422function log2(x) { 1423 return x > 0 ? Math.ceil(Math.log2(x)) : 0; 1424} 1425function readInt8(data, offset) { 1426 return data[offset] << 24 >> 24; 1427} 1428function readInt16(data, offset) { 1429 return (data[offset] << 24 | data[offset + 1] << 16) >> 16; 1430} 1431function readUint16(data, offset) { 1432 return data[offset] << 8 | data[offset + 1]; 1433} 1434function readUint32(data, offset) { 1435 return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0; 1436} 1437function isWhiteSpace(ch) { 1438 return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a; 1439} 1440function isBooleanArray(arr, len) { 1441 return Array.isArray(arr) && (len === null || arr.length === len) && arr.every(x => typeof x === "boolean"); 1442} 1443function isNumberArray(arr, len) { 1444 if (Array.isArray(arr)) { 1445 return (len === null || arr.length === len) && arr.every(x => typeof x === "number"); 1446 } 1447 return ArrayBuffer.isView(arr) && !(arr instanceof BigInt64Array || arr instanceof BigUint64Array) && (len === null || arr.length === len); 1448} 1449function lookupMatrix(arr, fallback) { 1450 return isNumberArray(arr, 6) ? arr : fallback; 1451} 1452function lookupRect(arr, fallback) { 1453 return isNumberArray(arr, 4) ? arr : fallback; 1454} 1455function lookupNormalRect(arr, fallback) { 1456 return isNumberArray(arr, 4) ? Util.normalizeRect(arr) : fallback; 1457} 1458function parseXFAPath(path) { 1459 const positionPattern = /(.+)\[(\d+)\]$/; 1460 return path.split(".").map(component => { 1461 const m = component.match(positionPattern); 1462 if (m) { 1463 return { 1464 name: m[1], 1465 pos: parseInt(m[2], 10) 1466 }; 1467 } 1468 return { 1469 name: component, 1470 pos: 0 1471 }; 1472 }); 1473} 1474function escapePDFName(str) { 1475 const buffer = []; 1476 let start = 0; 1477 for (let i = 0, ii = str.length; i < ii; i++) { 1478 const char = str.charCodeAt(i); 1479 if (char < 0x21 || char > 0x7e || char === 0x23 || char === 0x28 || char === 0x29 || char === 0x3c || char === 0x3e || char === 0x5b || char === 0x5d || char === 0x7b || char === 0x7d || char === 0x2f || char === 0x25) { 1480 if (start < i) { 1481 buffer.push(str.substring(start, i)); 1482 } 1483 buffer.push(`#${char.toString(16)}`); 1484 start = i + 1; 1485 } 1486 } 1487 if (buffer.length === 0) { 1488 return str; 1489 } 1490 if (start < str.length) { 1491 buffer.push(str.substring(start, str.length)); 1492 } 1493 return buffer.join(""); 1494} 1495function escapeString(str) { 1496 return str.replaceAll(/([()\\\n\r])/g, match => { 1497 if (match === "\n") { 1498 return "\\n"; 1499 } else if (match === "\r") { 1500 return "\\r"; 1501 } 1502 return `\\${match}`; 1503 }); 1504} 1505function _collectJS(entry, xref, list, parents) { 1506 if (!entry) { 1507 return; 1508 } 1509 let parent = null; 1510 if (entry instanceof Ref) { 1511 if (parents.has(entry)) { 1512 return; 1513 } 1514 parent = entry; 1515 parents.put(parent); 1516 entry = xref.fetch(entry); 1517 } 1518 if (Array.isArray(entry)) { 1519 for (const element of entry) { 1520 _collectJS(element, xref, list, parents); 1521 } 1522 } else if (entry instanceof Dict) { 1523 if (isName(entry.get("S"), "JavaScript")) { 1524 const js = entry.get("JS"); 1525 let code; 1526 if (js instanceof BaseStream) { 1527 code = js.getString(); 1528 } else if (typeof js === "string") { 1529 code = js; 1530 } 1531 code &&= stringToPDFString(code, true).replaceAll("\x00", ""); 1532 if (code) { 1533 list.push(code.trim()); 1534 } 1535 } 1536 _collectJS(entry.getRaw("Next"), xref, list, parents); 1537 } 1538 if (parent) { 1539 parents.remove(parent); 1540 } 1541} 1542function collectActions(xref, dict, eventType) { 1543 const actions = Object.create(null); 1544 const additionalActionsDicts = getInheritableProperty({ 1545 dict, 1546 key: "AA", 1547 stopWhenFound: false 1548 }); 1549 if (additionalActionsDicts) { 1550 for (let i = additionalActionsDicts.length - 1; i >= 0; i--) { 1551 const additionalActions = additionalActionsDicts[i]; 1552 if (!(additionalActions instanceof Dict)) { 1553 continue; 1554 } 1555 for (const key of additionalActions.getKeys()) { 1556 const action = eventType[key]; 1557 if (!action) { 1558 continue; 1559 } 1560 const actionDict = additionalActions.getRaw(key); 1561 const parents = new RefSet(); 1562 const list = []; 1563 _collectJS(actionDict, xref, list, parents); 1564 if (list.length > 0) { 1565 actions[action] = list; 1566 } 1567 } 1568 } 1569 } 1570 if (dict.has("A")) { 1571 const actionDict = dict.get("A"); 1572 const parents = new RefSet(); 1573 const list = []; 1574 _collectJS(actionDict, xref, list, parents); 1575 if (list.length > 0) { 1576 actions.Action = list; 1577 } 1578 } 1579 return objectSize(actions) > 0 ? actions : null; 1580} 1581const XMLEntities = { 1582 0x3c: "<", 1583 0x3e: ">", 1584 0x26: "&", 1585 0x22: """, 1586 0x27: "'" 1587}; 1588function* codePointIter(str) { 1589 for (let i = 0, ii = str.length; i < ii; i++) { 1590 const char = str.codePointAt(i); 1591 if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) { 1592 i++; 1593 } 1594 yield char; 1595 } 1596} 1597function encodeToXmlString(str) { 1598 const buffer = []; 1599 let start = 0; 1600 for (let i = 0, ii = str.length; i < ii; i++) { 1601 const char = str.codePointAt(i); 1602 if (0x20 <= char && char <= 0x7e) { 1603 const entity = XMLEntities[char]; 1604 if (entity) { 1605 if (start < i) { 1606 buffer.push(str.substring(start, i)); 1607 } 1608 buffer.push(entity); 1609 start = i + 1; 1610 } 1611 } else { 1612 if (start < i) { 1613 buffer.push(str.substring(start, i)); 1614 } 1615 buffer.push(`&#x${char.toString(16).toUpperCase()};`); 1616 if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) { 1617 i++; 1618 } 1619 start = i + 1; 1620 } 1621 } 1622 if (buffer.length === 0) { 1623 return str; 1624 } 1625 if (start < str.length) { 1626 buffer.push(str.substring(start, str.length)); 1627 } 1628 return buffer.join(""); 1629} 1630function validateFontName(fontFamily, mustWarn = false) { 1631 const m = /^("|').*("|')$/.exec(fontFamily); 1632 if (m && m[1] === m[2]) { 1633 const re = new RegExp(`[^\\\\]${m[1]}`); 1634 if (re.test(fontFamily.slice(1, -1))) { 1635 if (mustWarn) { 1636 warn(`FontFamily contains unescaped ${m[1]}: ${fontFamily}.`); 1637 } 1638 return false; 1639 } 1640 } else { 1641 for (const ident of fontFamily.split(/[ \t]+/)) { 1642 if (/^(\d|(-(\d|-)))/.test(ident) || !/^[\w-\\]+$/.test(ident)) { 1643 if (mustWarn) { 1644 warn(`FontFamily contains invalid <custom-ident>: ${fontFamily}.`); 1645 } 1646 return false; 1647 } 1648 } 1649 } 1650 return true; 1651} 1652function validateCSSFont(cssFontInfo) { 1653 const DEFAULT_CSS_FONT_OBLIQUE = "14"; 1654 const DEFAULT_CSS_FONT_WEIGHT = "400"; 1655 const CSS_FONT_WEIGHT_VALUES = new Set(["100", "200", "300", "400", "500", "600", "700", "800", "900", "1000", "normal", "bold", "bolder", "lighter"]); 1656 const { 1657 fontFamily, 1658 fontWeight, 1659 italicAngle 1660 } = cssFontInfo; 1661 if (!validateFontName(fontFamily, true)) { 1662 return false; 1663 } 1664 const weight = fontWeight ? fontWeight.toString() : ""; 1665 cssFontInfo.fontWeight = CSS_FONT_WEIGHT_VALUES.has(weight) ? weight : DEFAULT_CSS_FONT_WEIGHT; 1666 const angle = parseFloat(italicAngle); 1667 cssFontInfo.italicAngle = isNaN(angle) || angle < -90 || angle > 90 ? DEFAULT_CSS_FONT_OBLIQUE : italicAngle.toString(); 1668 return true; 1669} 1670function recoverJsURL(str) { 1671 const URL_OPEN_METHODS = ["app.launchURL", "window.open", "xfa.host.gotoURL"]; 1672 const regex = new RegExp("^\\s*(" + URL_OPEN_METHODS.join("|").replaceAll(".", "\\.") + ")\\((?:'|\")([^'\"]*)(?:'|\")(?:,\\s*(\\w+)\\)|\\))", "i"); 1673 const jsUrl = regex.exec(str); 1674 if (jsUrl?.[2]) { 1675 return { 1676 url: jsUrl[2], 1677 newWindow: jsUrl[1] === "app.launchURL" && jsUrl[3] === "true" 1678 }; 1679 } 1680 return null; 1681} 1682function numberToString(value) { 1683 if (Number.isInteger(value)) { 1684 return value.toString(); 1685 } 1686 const roundedValue = Math.round(value * 100); 1687 if (roundedValue % 100 === 0) { 1688 return (roundedValue / 100).toString(); 1689 } 1690 if (roundedValue % 10 === 0) { 1691 return value.toFixed(1); 1692 } 1693 return value.toFixed(2); 1694} 1695function getNewAnnotationsMap(annotationStorage) { 1696 if (!annotationStorage) { 1697 return null; 1698 } 1699 const newAnnotationsByPage = new Map(); 1700 for (const [key, value] of annotationStorage) { 1701 if (!key.startsWith(AnnotationEditorPrefix)) { 1702 continue; 1703 } 1704 let annotations = newAnnotationsByPage.get(value.pageIndex); 1705 if (!annotations) { 1706 annotations = []; 1707 newAnnotationsByPage.set(value.pageIndex, annotations); 1708 } 1709 annotations.push(value); 1710 } 1711 return newAnnotationsByPage.size > 0 ? newAnnotationsByPage : null; 1712} 1713function stringToAsciiOrUTF16BE(str) { 1714 if (str === null || str === undefined) { 1715 return str; 1716 } 1717 return isAscii(str) ? str : stringToUTF16String(str, true); 1718} 1719function isAscii(str) { 1720 if (typeof str !== "string") { 1721 return false; 1722 } 1723 return !str || /^[\x00-\x7F]*$/.test(str); 1724} 1725function stringToUTF16HexString(str) { 1726 const buf = []; 1727 for (let i = 0, ii = str.length; i < ii; i++) { 1728 const char = str.charCodeAt(i); 1729 buf.push(hexNumbers[char >> 8 & 0xff], hexNumbers[char & 0xff]); 1730 } 1731 return buf.join(""); 1732} 1733function stringToUTF16String(str, bigEndian = false) { 1734 const buf = []; 1735 if (bigEndian) { 1736 buf.push("\xFE\xFF"); 1737 } 1738 for (let i = 0, ii = str.length; i < ii; i++) { 1739 const char = str.charCodeAt(i); 1740 buf.push(String.fromCharCode(char >> 8 & 0xff), String.fromCharCode(char & 0xff)); 1741 } 1742 return buf.join(""); 1743} 1744function getRotationMatrix(rotation, width, height) { 1745 switch (rotation) { 1746 case 90: 1747 return [0, 1, -1, 0, width, 0]; 1748 case 180: 1749 return [-1, 0, 0, -1, width, height]; 1750 case 270: 1751 return [0, -1, 1, 0, 0, height]; 1752 default: 1753 throw new Error("Invalid rotation"); 1754 } 1755} 1756function getSizeInBytes(x) { 1757 return Math.ceil(Math.ceil(Math.log2(1 + x)) / 8); 1758} 1759
1760;// ./external/qcms/qcms_utils.js 1761class QCMS { 1762 static #memoryArray = null; 1763 static _memory = null; 1764 static _mustAddAlpha = false; 1765 static _destBuffer = null; 1766 static _destOffset = 0; 1767 static _destLength = 0; 1768 static _cssColor = ""; 1769 static _makeHexColor = null; 1770 static get _memoryArray() { 1771 const array = this.#memoryArray; 1772 if (array?.byteLength) { 1773 return array; 1774 } 1775 return this.#memoryArray = new Uint8Array(this._memory.buffer); 1776 } 1777} 1778function copy_result(ptr, len) { 1779 const { 1780 _mustAddAlpha, 1781 _destBuffer,
vendor: 7,049 bytes, lines 1782-2006
1782 _destOffset, 1783 _destLength, 1784 _memoryArray 1785 } = QCMS; 1786 if (len === _destLength) { 1787 _destBuffer.set(_memoryArray.subarray(ptr, ptr + len), _destOffset); 1788 return; 1789 } 1790 if (_mustAddAlpha) { 1791 for (let i = ptr, ii = ptr + len, j = _destOffset; i < ii; i += 3, j += 4) { 1792 _destBuffer[j] = _memoryArray[i]; 1793 _destBuffer[j + 1] = _memoryArray[i + 1]; 1794 _destBuffer[j + 2] = _memoryArray[i + 2]; 1795 _destBuffer[j + 3] = 255; 1796 } 1797 } else { 1798 for (let i = ptr, ii = ptr + len, j = _destOffset; i < ii; i += 3, j += 4) { 1799 _destBuffer[j] = _memoryArray[i]; 1800 _destBuffer[j + 1] = _memoryArray[i + 1]; 1801 _destBuffer[j + 2] = _memoryArray[i + 2]; 1802 } 1803 } 1804} 1805function copy_rgb(ptr) { 1806 const { 1807 _destBuffer, 1808 _destOffset, 1809 _memoryArray 1810 } = QCMS; 1811 _destBuffer[_destOffset] = _memoryArray[ptr]; 1812 _destBuffer[_destOffset + 1] = _memoryArray[ptr + 1]; 1813 _destBuffer[_destOffset + 2] = _memoryArray[ptr + 2]; 1814} 1815function make_cssRGB(ptr) { 1816 const { 1817 _memoryArray 1818 } = QCMS; 1819 QCMS._cssColor = QCMS._makeHexColor(_memoryArray[ptr], _memoryArray[ptr + 1], _memoryArray[ptr + 2]); 1820} 1821 1822;// ./external/qcms/qcms.js 1823 1824let wasm; 1825const cachedTextDecoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { 1826 ignoreBOM: true, 1827 fatal: true 1828}) : { 1829 decode: () => { 1830 throw Error('TextDecoder not available'); 1831 } 1832}; 1833if (typeof TextDecoder !== 'undefined') { 1834 cachedTextDecoder.decode(); 1835} 1836; 1837let cachedUint8ArrayMemory0 = null; 1838function getUint8ArrayMemory0() { 1839 if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { 1840 cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); 1841 } 1842 return cachedUint8ArrayMemory0; 1843} 1844function getStringFromWasm0(ptr, len) { 1845 ptr = ptr >>> 0; 1846 return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); 1847} 1848let WASM_VECTOR_LEN = 0; 1849function passArray8ToWasm0(arg, malloc) { 1850 const ptr = malloc(arg.length * 1, 1) >>> 0; 1851 getUint8ArrayMemory0().set(arg, ptr / 1); 1852 WASM_VECTOR_LEN = arg.length; 1853 return ptr; 1854} 1855function qcms_convert_array(transformer, src) { 1856 const ptr0 = passArray8ToWasm0(src, wasm.__wbindgen_malloc); 1857 const len0 = WASM_VECTOR_LEN; 1858 wasm.qcms_convert_array(transformer, ptr0, len0); 1859} 1860function qcms_convert_one(transformer, src, css) { 1861 wasm.qcms_convert_one(transformer, src, css); 1862} 1863function qcms_convert_three(transformer, src1, src2, src3, css) { 1864 wasm.qcms_convert_three(transformer, src1, src2, src3, css); 1865} 1866function qcms_convert_four(transformer, src1, src2, src3, src4, css) { 1867 wasm.qcms_convert_four(transformer, src1, src2, src3, src4, css); 1868} 1869function qcms_transformer_from_memory(mem, in_type, intent) { 1870 const ptr0 = passArray8ToWasm0(mem, wasm.__wbindgen_malloc); 1871 const len0 = WASM_VECTOR_LEN; 1872 const ret = wasm.qcms_transformer_from_memory(ptr0, len0, in_type, intent); 1873 return ret >>> 0; 1874} 1875function qcms_drop_transformer(transformer) { 1876 wasm.qcms_drop_transformer(transformer); 1877} 1878const DataType = Object.freeze({ 1879 RGB8: 0, 1880 "0": "RGB8", 1881 RGBA8: 1, 1882 "1": "RGBA8", 1883 BGRA8: 2, 1884 "2": "BGRA8", 1885 Gray8: 3, 1886 "3": "Gray8", 1887 GrayA8: 4, 1888 "4": "GrayA8", 1889 CMYK: 5, 1890 "5": "CMYK" 1891}); 1892const Intent = Object.freeze({ 1893 Perceptual: 0, 1894 "0": "Perceptual", 1895 RelativeColorimetric: 1, 1896 "1": "RelativeColorimetric", 1897 Saturation: 2, 1898 "2": "Saturation", 1899 AbsoluteColorimetric: 3, 1900 "3": "AbsoluteColorimetric" 1901}); 1902async function __wbg_load(module, imports) { 1903 if (typeof Response === 'function' && module instanceof Response) { 1904 if (typeof WebAssembly.instantiateStreaming === 'function') { 1905 try { 1906 return await WebAssembly.instantiateStreaming(module, imports); 1907 } catch (e) { 1908 if (module.headers.get('Content-Type') != 'application/wasm') { 1909 console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); 1910 } else { 1911 throw e; 1912 } 1913 } 1914 } 1915 const bytes = await module.arrayBuffer(); 1916 return await WebAssembly.instantiate(bytes, imports); 1917 } else { 1918 const instance = await WebAssembly.instantiate(module, imports); 1919 if (instance instanceof WebAssembly.Instance) { 1920 return { 1921 instance, 1922 module 1923 }; 1924 } else { 1925 return instance; 1926 } 1927 } 1928} 1929function __wbg_get_imports() { 1930 const imports = {}; 1931 imports.wbg = {}; 1932 imports.wbg.__wbg_copyresult_b08ee7d273f295dd = function (arg0, arg1) { 1933 copy_result(arg0 >>> 0, arg1 >>> 0); 1934 }; 1935 imports.wbg.__wbg_copyrgb_d60ce17bb05d9b67 = function (arg0) { 1936 copy_rgb(arg0 >>> 0); 1937 }; 1938 imports.wbg.__wbg_makecssRGB_893bf0cd9fdb302d = function (arg0) { 1939 make_cssRGB(arg0 >>> 0); 1940 }; 1941 imports.wbg.__wbindgen_init_externref_table = function () { 1942 const table = wasm.__wbindgen_export_0; 1943 const offset = table.grow(4); 1944 table.set(0, undefined); 1945 table.set(offset + 0, undefined); 1946 table.set(offset + 1, null); 1947 table.set(offset + 2, true); 1948 table.set(offset + 3, false); 1949 }; 1950 imports.wbg.__wbindgen_throw = function (arg0, arg1) { 1951 throw new Error(getStringFromWasm0(arg0, arg1)); 1952 }; 1953 return imports; 1954} 1955function __wbg_init_memory(imports, memory) {} 1956function __wbg_finalize_init(instance, module) { 1957 wasm = instance.exports; 1958 __wbg_init.__wbindgen_wasm_module = module; 1959 cachedUint8ArrayMemory0 = null; 1960 wasm.__wbindgen_start(); 1961 return wasm; 1962} 1963function initSync(module) { 1964 if (wasm !== undefined) return wasm; 1965 if (typeof module !== 'undefined') { 1966 if (Object.getPrototypeOf(module) === Object.prototype) { 1967 ({ 1968 module 1969 } = module); 1970 } else { 1971 console.warn('using deprecated parameters for `initSync()`; pass a single object instead'); 1972 } 1973 } 1974 const imports = __wbg_get_imports(); 1975 __wbg_init_memory(imports); 1976 if (!(module instanceof WebAssembly.Module)) { 1977 module = new WebAssembly.Module(module); 1978 } 1979 const instance = new WebAssembly.Instance(module, imports); 1980 return __wbg_finalize_init(instance, module); 1981} 1982async function __wbg_init(module_or_path) { 1983 if (wasm !== undefined) return wasm; 1984 if (typeof module_or_path !== 'undefined') { 1985 if (Object.getPrototypeOf(module_or_path) === Object.prototype) { 1986 ({ 1987 module_or_path 1988 } = module_or_path); 1989 } else { 1990 console.warn('using deprecated parameters for the initialization function; pass a single object instead'); 1991 } 1992 } 1993 const imports = __wbg_get_imports(); 1994 if (typeof module_or_path === 'string' || typeof Request === 'function' && module_or_path instanceof Request || typeof URL === 'function' && module_or_path instanceof URL) { 1995 module_or_path = fetch(module_or_path); 1996 } 1997 __wbg_init_memory(imports); 1998 const { 1999 instance, 2000 module 2001 } = await __wbg_load(await module_or_path, imports); 2002 return __wbg_finalize_init(instance, module); 2003} 2004 2005/* harmony default export */ const qcms = ((/* unused pure expression or super */ null && (__wbg_init))); 2006;// ./src/core/colorspace.js
vendor: 25,334 bytes, lines 2006-2698
2006 2007 2008 2009function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) { 2010 const COMPONENTS = 3; 2011 alpha01 = alpha01 !== 1 ? 0 : alpha01; 2012 const xRatio = w1 / w2; 2013 const yRatio = h1 / h2; 2014 let newIndex = 0, 2015 oldIndex; 2016 const xScaled = new Uint16Array(w2); 2017 const w1Scanline = w1 * COMPONENTS; 2018 for (let i = 0; i < w2; i++) { 2019 xScaled[i] = Math.floor(i * xRatio) * COMPONENTS; 2020 } 2021 for (let i = 0; i < h2; i++) { 2022 const py = Math.floor(i * yRatio) * w1Scanline; 2023 for (let j = 0; j < w2; j++) { 2024 oldIndex = py + xScaled[j]; 2025 dest[newIndex++] = src[oldIndex++]; 2026 dest[newIndex++] = src[oldIndex++]; 2027 dest[newIndex++] = src[oldIndex++]; 2028 newIndex += alpha01; 2029 } 2030 } 2031} 2032function resizeRgbaImage(src, dest, w1, h1, w2, h2, alpha01) { 2033 const xRatio = w1 / w2; 2034 const yRatio = h1 / h2; 2035 let newIndex = 0; 2036 const xScaled = new Uint16Array(w2); 2037 if (alpha01 === 1) { 2038 for (let i = 0; i < w2; i++) { 2039 xScaled[i] = Math.floor(i * xRatio); 2040 } 2041 const src32 = new Uint32Array(src.buffer); 2042 const dest32 = new Uint32Array(dest.buffer); 2043 const rgbMask = FeatureTest.isLittleEndian ? 0x00ffffff : 0xffffff00; 2044 for (let i = 0; i < h2; i++) { 2045 const buf = src32.subarray(Math.floor(i * yRatio) * w1); 2046 for (let j = 0; j < w2; j++) { 2047 dest32[newIndex++] |= buf[xScaled[j]] & rgbMask; 2048 } 2049 } 2050 } else { 2051 const COMPONENTS = 4; 2052 const w1Scanline = w1 * COMPONENTS; 2053 for (let i = 0; i < w2; i++) { 2054 xScaled[i] = Math.floor(i * xRatio) * COMPONENTS; 2055 } 2056 for (let i = 0; i < h2; i++) { 2057 const buf = src.subarray(Math.floor(i * yRatio) * w1Scanline); 2058 for (let j = 0; j < w2; j++) { 2059 const oldIndex = xScaled[j]; 2060 dest[newIndex++] = buf[oldIndex]; 2061 dest[newIndex++] = buf[oldIndex + 1]; 2062 dest[newIndex++] = buf[oldIndex + 2]; 2063 } 2064 } 2065 } 2066} 2067function copyRgbaImage(src, dest, alpha01) { 2068 if (alpha01 === 1) { 2069 const src32 = new Uint32Array(src.buffer); 2070 const dest32 = new Uint32Array(dest.buffer); 2071 const rgbMask = FeatureTest.isLittleEndian ? 0x00ffffff : 0xffffff00; 2072 for (let i = 0, ii = src32.length; i < ii; i++) { 2073 dest32[i] |= src32[i] & rgbMask; 2074 } 2075 } else { 2076 let j = 0; 2077 for (let i = 0, ii = src.length; i < ii; i += 4) { 2078 dest[j++] = src[i]; 2079 dest[j++] = src[i + 1]; 2080 dest[j++] = src[i + 2]; 2081 } 2082 } 2083} 2084class ColorSpace { 2085 static #rgbBuf = new Uint8ClampedArray(3); 2086 constructor(name, numComps) { 2087 this.name = name; 2088 this.numComps = numComps; 2089 } 2090 getRgb(src, srcOffset, output = new Uint8ClampedArray(3)) { 2091 this.getRgbItem(src, srcOffset, output, 0); 2092 return output; 2093 } 2094 getRgbHex(src, srcOffset) { 2095 const buffer = this.getRgb(src, srcOffset, ColorSpace.#rgbBuf); 2096 return Util.makeHexColor(buffer[0], buffer[1], buffer[2]); 2097 } 2098 getRgbItem(src, srcOffset, dest, destOffset) { 2099 unreachable("Should not call ColorSpace.getRgbItem"); 2100 } 2101 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { 2102 unreachable("Should not call ColorSpace.getRgbBuffer"); 2103 } 2104 getOutputLength(inputLength, alpha01) { 2105 unreachable("Should not call ColorSpace.getOutputLength"); 2106 } 2107 isPassthrough(bits) { 2108 return false; 2109 } 2110 isDefaultDecode(decodeMap, bpc) { 2111 return ColorSpace.isDefaultDecode(decodeMap, this.numComps); 2112 } 2113 fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) { 2114 const count = originalWidth * originalHeight; 2115 let rgbBuf = null; 2116 const numComponentColors = 1 << bpc; 2117 const needsResizing = originalHeight !== height || originalWidth !== width; 2118 if (this.isPassthrough(bpc)) { 2119 rgbBuf = comps; 2120 } else if (this.numComps === 1 && count > numComponentColors && this.name !== "DeviceGray" && this.name !== "DeviceRGB") { 2121 const allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors); 2122 for (let i = 0; i < numComponentColors; i++) { 2123 allColors[i] = i; 2124 } 2125 const colorMap = new Uint8ClampedArray(numComponentColors * 3); 2126 this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, 0); 2127 if (!needsResizing) { 2128 let destPos = 0; 2129 for (let i = 0; i < count; ++i) { 2130 const key = comps[i] * 3; 2131 dest[destPos++] = colorMap[key]; 2132 dest[destPos++] = colorMap[key + 1]; 2133 dest[destPos++] = colorMap[key + 2]; 2134 destPos += alpha01; 2135 } 2136 } else { 2137 rgbBuf = new Uint8Array(count * 3); 2138 let rgbPos = 0; 2139 for (let i = 0; i < count; ++i) { 2140 const key = comps[i] * 3; 2141 rgbBuf[rgbPos++] = colorMap[key]; 2142 rgbBuf[rgbPos++] = colorMap[key + 1]; 2143 rgbBuf[rgbPos++] = colorMap[key + 2]; 2144 } 2145 } 2146 } else if (!needsResizing) { 2147 this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01); 2148 } else { 2149 rgbBuf = new Uint8ClampedArray(count * 3); 2150 this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, 0); 2151 } 2152 if (rgbBuf) { 2153 if (needsResizing) { 2154 resizeRgbImage(rgbBuf, dest, originalWidth, originalHeight, width, height, alpha01); 2155 } else { 2156 let destPos = 0, 2157 rgbPos = 0; 2158 for (let i = 0, ii = width * actualHeight; i < ii; i++) { 2159 dest[destPos++] = rgbBuf[rgbPos++]; 2160 dest[destPos++] = rgbBuf[rgbPos++]; 2161 dest[destPos++] = rgbBuf[rgbPos++]; 2162 destPos += alpha01; 2163 } 2164 } 2165 } 2166 } 2167 get usesZeroToOneRange() { 2168 return shadow(this, "usesZeroToOneRange", true); 2169 } 2170 static isDefaultDecode(decode, numComps) { 2171 if (!Array.isArray(decode)) { 2172 return true; 2173 } 2174 if (numComps * 2 !== decode.length) { 2175 warn("The decode map is not the correct length"); 2176 return true; 2177 } 2178 for (let i = 0, ii = decode.length; i < ii; i += 2) { 2179 if (decode[i] !== 0 || decode[i + 1] !== 1) { 2180 return false; 2181 } 2182 } 2183 return true; 2184 } 2185} 2186class AlternateCS extends ColorSpace { 2187 constructor(numComps, base, tintFn) { 2188 super("Alternate", numComps); 2189 this.base = base; 2190 this.tintFn = tintFn; 2191 this.tmpBuf = new Float32Array(base.numComps); 2192 } 2193 getRgbItem(src, srcOffset, dest, destOffset) { 2194 const tmpBuf = this.tmpBuf; 2195 this.tintFn(src, srcOffset, tmpBuf, 0); 2196 this.base.getRgbItem(tmpBuf, 0, dest, destOffset); 2197 } 2198 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { 2199 const tintFn = this.tintFn; 2200 const base = this.base; 2201 const scale = 1 / ((1 << bits) - 1); 2202 const baseNumComps = base.numComps; 2203 const usesZeroToOneRange = base.usesZeroToOneRange; 2204 const isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0; 2205 let pos = isPassthrough ? destOffset : 0; 2206 const baseBuf = isPassthrough ? dest : new Uint8ClampedArray(baseNumComps * count); 2207 const numComps = this.numComps; 2208 const scaled = new Float32Array(numComps); 2209 const tinted = new Float32Array(baseNumComps); 2210 let i, j; 2211 for (i = 0; i < count; i++) { 2212 for (j = 0; j < numComps; j++) { 2213 scaled[j] = src[srcOffset++] * scale; 2214 } 2215 tintFn(scaled, 0, tinted, 0); 2216 if (usesZeroToOneRange) { 2217 for (j = 0; j < baseNumComps; j++) { 2218 baseBuf[pos++] = tinted[j] * 255; 2219 } 2220 } else { 2221 base.getRgbItem(tinted, 0, baseBuf, pos); 2222 pos += baseNumComps; 2223 } 2224 } 2225 if (!isPassthrough) { 2226 base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01); 2227 } 2228 } 2229 getOutputLength(inputLength, alpha01) { 2230 return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01); 2231 } 2232} 2233class PatternCS extends ColorSpace { 2234 constructor(baseCS) { 2235 super("Pattern", null); 2236 this.base = baseCS; 2237 } 2238 isDefaultDecode(decodeMap, bpc) { 2239 unreachable("Should not call PatternCS.isDefaultDecode"); 2240 } 2241} 2242class IndexedCS extends ColorSpace { 2243 constructor(base, highVal, lookup) { 2244 super("Indexed", 1); 2245 this.base = base; 2246 this.highVal = highVal; 2247 const length = base.numComps * (highVal + 1); 2248 this.lookup = new Uint8Array(length); 2249 if (lookup instanceof BaseStream) { 2250 const bytes = lookup.getBytes(length); 2251 this.lookup.set(bytes); 2252 } else if (typeof lookup === "string") { 2253 for (let i = 0; i < length; ++i) { 2254 this.lookup[i] = lookup.charCodeAt(i) & 0xff; 2255 } 2256 } else { 2257 throw new FormatError(`IndexedCS - unrecognized lookup table: ${lookup}`); 2258 } 2259 } 2260 getRgbItem(src, srcOffset, dest, destOffset) { 2261 const { 2262 base, 2263 highVal, 2264 lookup 2265 } = this; 2266 const start = MathClamp(Math.round(src[srcOffset]), 0, highVal) * base.numComps; 2267 base.getRgbBuffer(lookup, start, 1, dest, destOffset, 8, 0); 2268 } 2269 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { 2270 const { 2271 base, 2272 highVal, 2273 lookup 2274 } = this; 2275 const { 2276 numComps 2277 } = base; 2278 const outputDelta = base.getOutputLength(numComps, alpha01); 2279 for (let i = 0; i < count; ++i) { 2280 const lookupPos = MathClamp(Math.round(src[srcOffset++]), 0, highVal) * numComps; 2281 base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01); 2282 destOffset += outputDelta; 2283 } 2284 } 2285 getOutputLength(inputLength, alpha01) { 2286 return this.base.getOutputLength(inputLength * this.base.numComps, alpha01); 2287 } 2288 isDefaultDecode(decodeMap, bpc) { 2289 if (!Array.isArray(decodeMap)) { 2290 return true; 2291 } 2292 if (decodeMap.length !== 2) { 2293 warn("Decode map length is not correct"); 2294 return true; 2295 } 2296 if (!Number.isInteger(bpc) || bpc < 1) { 2297 warn("Bits per component is not correct"); 2298 return true; 2299 } 2300 return decodeMap[0] === 0 && decodeMap[1] === (1 << bpc) - 1; 2301 } 2302} 2303class DeviceGrayCS extends ColorSpace { 2304 constructor() { 2305 super("DeviceGray", 1); 2306 } 2307 getRgbItem(src, srcOffset, dest, destOffset) { 2308 const c = src[srcOffset] * 255; 2309 dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c; 2310 } 2311 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { 2312 const scale = 255 / ((1 << bits) - 1); 2313 let j = srcOffset, 2314 q = destOffset; 2315 for (let i = 0; i < count; ++i) { 2316 const c = scale * src[j++]; 2317 dest[q++] = c; 2318 dest[q++] = c; 2319 dest[q++] = c; 2320 q += alpha01; 2321 } 2322 } 2323 getOutputLength(inputLength, alpha01) { 2324 return inputLength * (3 + alpha01); 2325 } 2326} 2327class DeviceRgbCS extends ColorSpace { 2328 constructor() { 2329 super("DeviceRGB", 3); 2330 } 2331 getRgbItem(src, srcOffset, dest, destOffset) { 2332 dest[destOffset] = src[srcOffset] * 255; 2333 dest[destOffset + 1] = src[srcOffset + 1] * 255; 2334 dest[destOffset + 2] = src[srcOffset + 2] * 255; 2335 } 2336 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { 2337 if (bits === 8 && alpha01 === 0) { 2338 dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset); 2339 return; 2340 } 2341 const scale = 255 / ((1 << bits) - 1); 2342 let j = srcOffset, 2343 q = destOffset; 2344 for (let i = 0; i < count; ++i) { 2345 dest[q++] = scale * src[j++]; 2346 dest[q++] = scale * src[j++]; 2347 dest[q++] = scale * src[j++]; 2348 q += alpha01; 2349 } 2350 } 2351 getOutputLength(inputLength, alpha01) { 2352 return inputLength * (3 + alpha01) / 3 | 0; 2353 } 2354 isPassthrough(bits) { 2355 return bits === 8; 2356 } 2357} 2358class DeviceRgbaCS extends ColorSpace { 2359 constructor() { 2360 super("DeviceRGBA", 4); 2361 } 2362 getOutputLength(inputLength, _alpha01) { 2363 return inputLength * 4; 2364 } 2365 isPassthrough(bits) { 2366 return bits === 8; 2367 } 2368 fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) { 2369 if (originalHeight !== height || originalWidth !== width) { 2370 resizeRgbaImage(comps, dest, originalWidth, originalHeight, width, height, alpha01); 2371 } else { 2372 copyRgbaImage(comps, dest, alpha01); 2373 } 2374 } 2375} 2376class DeviceCmykCS extends ColorSpace { 2377 constructor() { 2378 super("DeviceCMYK", 4); 2379 } 2380 #toRgb(src, srcOffset, srcScale, dest, destOffset) { 2381 const c = src[srcOffset] * srcScale; 2382 const m = src[srcOffset + 1] * srcScale; 2383 const y = src[srcOffset + 2] * srcScale; 2384 const k = src[srcOffset + 3] * srcScale; 2385 dest[destOffset] = 255 + c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k + -285.2331026137004) + m * (1.7149763477362134 * m - 5.6096736904047315 * y + -17.873870861415444 * k - 5.497006427196366) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) + k * (-21.86122147463605 * k - 189.48180835922747); 2386 dest[destOffset + 1] = 255 + c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k + -79.2970844816548) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + k * (-20.737325471181034 * k - 187.80453709719578); 2387 dest[destOffset + 2] = 255 + c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k + -14.183576799673286) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) + y * (0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) + k * (-22.33816807309886 * k - 180.12613974708367); 2388 } 2389 getRgbItem(src, srcOffset, dest, destOffset) { 2390 this.#toRgb(src, srcOffset, 1, dest, destOffset); 2391 } 2392 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { 2393 const scale = 1 / ((1 << bits) - 1); 2394 for (let i = 0; i < count; i++) { 2395 this.#toRgb(src, srcOffset, scale, dest, destOffset); 2396 srcOffset += 4; 2397 destOffset += 3 + alpha01; 2398 } 2399 } 2400 getOutputLength(inputLength, alpha01) { 2401 return inputLength / 4 * (3 + alpha01) | 0; 2402 } 2403} 2404class CalGrayCS extends ColorSpace { 2405 constructor(whitePoint, blackPoint, gamma) { 2406 super("CalGray", 1); 2407 if (!whitePoint) { 2408 throw new FormatError("WhitePoint missing - required for color space CalGray"); 2409 } 2410 [this.XW, this.YW, this.ZW] = whitePoint; 2411 [this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0]; 2412 this.G = gamma || 1; 2413 if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) { 2414 throw new FormatError(`Invalid WhitePoint components for ${this.name}, no fallback available`); 2415 } 2416 if (this.XB < 0 || this.YB < 0 || this.ZB < 0) { 2417 info(`Invalid BlackPoint for ${this.name}, falling back to default.`); 2418 this.XB = this.YB = this.ZB = 0; 2419 } 2420 if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) { 2421 warn(`${this.name}, BlackPoint: XB: ${this.XB}, YB: ${this.YB}, ` + `ZB: ${this.ZB}, only default values are supported.`); 2422 } 2423 if (this.G < 1) { 2424 info(`Invalid Gamma: ${this.G} for ${this.name}, falling back to default.`); 2425 this.G = 1; 2426 } 2427 } 2428 #toRgb(src, srcOffset, dest, destOffset, scale) { 2429 const A = src[srcOffset] * scale; 2430 const AG = A ** this.G; 2431 const L = this.YW * AG; 2432 const val = Math.max(295.8 * L ** 0.3333333333333333 - 40.8, 0); 2433 dest[destOffset] = val; 2434 dest[destOffset + 1] = val; 2435 dest[destOffset + 2] = val; 2436 } 2437 getRgbItem(src, srcOffset, dest, destOffset) { 2438 this.#toRgb(src, srcOffset, dest, destOffset, 1); 2439 } 2440 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { 2441 const scale = 1 / ((1 << bits) - 1); 2442 for (let i = 0; i < count; ++i) { 2443 this.#toRgb(src, srcOffset, dest, destOffset, scale); 2444 srcOffset += 1; 2445 destOffset += 3 + alpha01; 2446 } 2447 } 2448 getOutputLength(inputLength, alpha01) { 2449 return inputLength * (3 + alpha01); 2450 } 2451} 2452class CalRGBCS extends ColorSpace { 2453 static #BRADFORD_SCALE_MATRIX = new Float32Array([0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296]); 2454 static #BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([0.9869929, -0.1470543, 0.1599627, 0.4323053, 0.5183603, 0.0492912, -0.0085287, 0.0400428, 0.9684867]); 2455 static #SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([3.2404542, -1.5371385, -0.4985314, -0.9692660, 1.8760108, 0.0415560, 0.0556434, -0.2040259, 1.0572252]); 2456 static #FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]); 2457 static #tempNormalizeMatrix = new Float32Array(3); 2458 static #tempConvertMatrix1 = new Float32Array(3); 2459 static #tempConvertMatrix2 = new Float32Array(3); 2460 static #DECODE_L_CONSTANT = ((8 + 16) / 116) ** 3 / 8.0; 2461 constructor(whitePoint, blackPoint, gamma, matrix) { 2462 super("CalRGB", 3); 2463 if (!whitePoint) { 2464 throw new FormatError("WhitePoint missing - required for color space CalRGB"); 2465 } 2466 const [XW, YW, ZW] = this.whitePoint = whitePoint; 2467 const [XB, YB, ZB] = this.blackPoint = blackPoint || new Float32Array(3); 2468 [this.GR, this.GG, this.GB] = gamma || new Float32Array([1, 1, 1]); 2469 [this.MXA, this.MYA, this.MZA, this.MXB, this.MYB, this.MZB, this.MXC, this.MYC, this.MZC] = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]); 2470 if (XW < 0 || ZW < 0 || YW !== 1) { 2471 throw new FormatError(`Invalid WhitePoint components for ${this.name}, no fallback available`); 2472 } 2473 if (XB < 0 || YB < 0 || ZB < 0) { 2474 info(`Invalid BlackPoint for ${this.name} [${XB}, ${YB}, ${ZB}], ` + "falling back to default."); 2475 this.blackPoint = new Float32Array(3); 2476 } 2477 if (this.GR < 0 || this.GG < 0 || this.GB < 0) { 2478 info(`Invalid Gamma [${this.GR}, ${this.GG}, ${this.GB}] for ` + `${this.name}, falling back to default.`); 2479 this.GR = this.GG = this.GB = 1; 2480 } 2481 } 2482 #matrixProduct(a, b, result) { 2483 result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; 2484 result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2]; 2485 result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2]; 2486 } 2487 #toFlat(sourceWhitePoint, LMS, result) { 2488 result[0] = LMS[0] * 1 / sourceWhitePoint[0]; 2489 result[1] = LMS[1] * 1 / sourceWhitePoint[1]; 2490 result[2] = LMS[2] * 1 / sourceWhitePoint[2]; 2491 } 2492 #toD65(sourceWhitePoint, LMS, result) { 2493 const D65X = 0.95047; 2494 const D65Y = 1; 2495 const D65Z = 1.08883; 2496 result[0] = LMS[0] * D65X / sourceWhitePoint[0]; 2497 result[1] = LMS[1] * D65Y / sourceWhitePoint[1]; 2498 result[2] = LMS[2] * D65Z / sourceWhitePoint[2]; 2499 } 2500 #sRGBTransferFunction(color) { 2501 if (color <= 0.0031308) { 2502 return MathClamp(12.92 * color, 0, 1); 2503 } 2504 if (color >= 0.99554525) { 2505 return 1; 2506 } 2507 return MathClamp((1 + 0.055) * color ** (1 / 2.4) - 0.055, 0, 1); 2508 } 2509 #decodeL(L) { 2510 if (L < 0) { 2511 return -this.#decodeL(-L); 2512 } 2513 if (L > 8.0) { 2514 return ((L + 16) / 116) ** 3; 2515 } 2516 return L * CalRGBCS.#DECODE_L_CONSTANT; 2517 } 2518 #compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) { 2519 if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) { 2520 result[0] = XYZ_Flat[0]; 2521 result[1] = XYZ_Flat[1]; 2522 result[2] = XYZ_Flat[2]; 2523 return; 2524 } 2525 const zeroDecodeL = this.#decodeL(0); 2526 const X_DST = zeroDecodeL; 2527 const X_SRC = this.#decodeL(sourceBlackPoint[0]); 2528 const Y_DST = zeroDecodeL; 2529 const Y_SRC = this.#decodeL(sourceBlackPoint[1]); 2530 const Z_DST = zeroDecodeL; 2531 const Z_SRC = this.#decodeL(sourceBlackPoint[2]); 2532 const X_Scale = (1 - X_DST) / (1 - X_SRC); 2533 const X_Offset = 1 - X_Scale; 2534 const Y_Scale = (1 - Y_DST) / (1 - Y_SRC); 2535 const Y_Offset = 1 - Y_Scale; 2536 const Z_Scale = (1 - Z_DST) / (1 - Z_SRC); 2537 const Z_Offset = 1 - Z_Scale; 2538 result[0] = XYZ_Flat[0] * X_Scale + X_Offset; 2539 result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset; 2540 result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset; 2541 } 2542 #normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) { 2543 if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) { 2544 result[0] = XYZ_In[0]; 2545 result[1] = XYZ_In[1]; 2546 result[2] = XYZ_In[2]; 2547 return; 2548 } 2549 const LMS = result; 2550 this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_MATRIX, XYZ_In, LMS); 2551 const LMS_Flat = CalRGBCS.#tempNormalizeMatrix; 2552 this.#toFlat(sourceWhitePoint, LMS, LMS_Flat); 2553 this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result); 2554 } 2555 #normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) { 2556 const LMS = result; 2557 this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_MATRIX, XYZ_In, LMS); 2558 const LMS_D65 = CalRGBCS.#tempNormalizeMatrix; 2559 this.#toD65(sourceWhitePoint, LMS, LMS_D65); 2560 this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result); 2561 } 2562 #toRgb(src, srcOffset, dest, destOffset, scale) { 2563 const A = MathClamp(src[srcOffset] * scale, 0, 1); 2564 const B = MathClamp(src[srcOffset + 1] * scale, 0, 1); 2565 const C = MathClamp(src[srcOffset + 2] * scale, 0, 1); 2566 const AGR = A === 1 ? 1 : A ** this.GR; 2567 const BGG = B === 1 ? 1 : B ** this.GG; 2568 const CGB = C === 1 ? 1 : C ** this.GB; 2569 const X = this.MXA * AGR + this.MXB * BGG + this.MXC * CGB; 2570 const Y = this.MYA * AGR + this.MYB * BGG + this.MYC * CGB; 2571 const Z = this.MZA * AGR + this.MZB * BGG + this.MZC * CGB; 2572 const XYZ = CalRGBCS.#tempConvertMatrix1; 2573 XYZ[0] = X; 2574 XYZ[1] = Y; 2575 XYZ[2] = Z; 2576 const XYZ_Flat = CalRGBCS.#tempConvertMatrix2; 2577 this.#normalizeWhitePointToFlat(this.whitePoint, XYZ, XYZ_Flat); 2578 const XYZ_Black = CalRGBCS.#tempConvertMatrix1; 2579 this.#compensateBlackPoint(this.blackPoint, XYZ_Flat, XYZ_Black); 2580 const XYZ_D65 = CalRGBCS.#tempConvertMatrix2; 2581 this.#normalizeWhitePointToD65(CalRGBCS.#FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65); 2582 const SRGB = CalRGBCS.#tempConvertMatrix1; 2583 this.#matrixProduct(CalRGBCS.#SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB); 2584 dest[destOffset] = this.#sRGBTransferFunction(SRGB[0]) * 255; 2585 dest[destOffset + 1] = this.#sRGBTransferFunction(SRGB[1]) * 255; 2586 dest[destOffset + 2] = this.#sRGBTransferFunction(SRGB[2]) * 255; 2587 } 2588 getRgbItem(src, srcOffset, dest, destOffset) { 2589 this.#toRgb(src, srcOffset, dest, destOffset, 1); 2590 } 2591 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { 2592 const scale = 1 / ((1 << bits) - 1); 2593 for (let i = 0; i < count; ++i) { 2594 this.#toRgb(src, srcOffset, dest, destOffset, scale); 2595 srcOffset += 3; 2596 destOffset += 3 + alpha01; 2597 } 2598 } 2599 getOutputLength(inputLength, alpha01) { 2600 return inputLength * (3 + alpha01) / 3 | 0; 2601 } 2602} 2603class LabCS extends ColorSpace { 2604 constructor(whitePoint, blackPoint, range) { 2605 super("Lab", 3); 2606 if (!whitePoint) { 2607 throw new FormatError("WhitePoint missing - required for color space Lab"); 2608 } 2609 [this.XW, this.YW, this.ZW] = whitePoint; 2610 [this.amin, this.amax, this.bmin, this.bmax] = range || [-100, 100, -100, 100]; 2611 [this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0]; 2612 if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) { 2613 throw new FormatError("Invalid WhitePoint components, no fallback available"); 2614 } 2615 if (this.XB < 0 || this.YB < 0 || this.ZB < 0) { 2616 info("Invalid BlackPoint, falling back to default"); 2617 this.XB = this.YB = this.ZB = 0; 2618 } 2619 if (this.amin > this.amax || this.bmin > this.bmax) { 2620 info("Invalid Range, falling back to defaults"); 2621 this.amin = -100; 2622 this.amax = 100; 2623 this.bmin = -100; 2624 this.bmax = 100; 2625 } 2626 } 2627 #fn_g(x) { 2628 return x >= 6 / 29 ? x ** 3 : 108 / 841 * (x - 4 / 29); 2629 } 2630 #decode(value, high1, low2, high2) { 2631 return low2 + value * (high2 - low2) / high1; 2632 } 2633 #toRgb(src, srcOffset, maxVal, dest, destOffset) { 2634 let Ls = src[srcOffset]; 2635 let as = src[srcOffset + 1]; 2636 let bs = src[srcOffset + 2]; 2637 if (maxVal !== false) { 2638 Ls = this.#decode(Ls, maxVal, 0, 100); 2639 as = this.#decode(as, maxVal, this.amin, this.amax); 2640 bs = this.#decode(bs, maxVal, this.bmin, this.bmax); 2641 } 2642 if (as > this.amax) { 2643 as = this.amax; 2644 } else if (as < this.amin) { 2645 as = this.amin; 2646 } 2647 if (bs > this.bmax) { 2648 bs = this.bmax; 2649 } else if (bs < this.bmin) { 2650 bs = this.bmin; 2651 } 2652 const M = (Ls + 16) / 116; 2653 const L = M + as / 500; 2654 const N = M - bs / 200; 2655 const X = this.XW * this.#fn_g(L); 2656 const Y = this.YW * this.#fn_g(M); 2657 const Z = this.ZW * this.#fn_g(N); 2658 let r, g, b; 2659 if (this.ZW < 1) { 2660 r = X * 3.1339 + Y * -1.617 + Z * -0.4906; 2661 g = X * -0.9785 + Y * 1.916 + Z * 0.0333; 2662 b = X * 0.072 + Y * -0.229 + Z * 1.4057; 2663 } else { 2664 r = X * 3.2406 + Y * -1.5372 + Z * -0.4986; 2665 g = X * -0.9689 + Y * 1.8758 + Z * 0.0415; 2666 b = X * 0.0557 + Y * -0.204 + Z * 1.057; 2667 } 2668 dest[destOffset] = Math.sqrt(r) * 255; 2669 dest[destOffset + 1] = Math.sqrt(g) * 255; 2670 dest[destOffset + 2] = Math.sqrt(b) * 255; 2671 } 2672 getRgbItem(src, srcOffset, dest, destOffset) { 2673 this.#toRgb(src, srcOffset, false, dest, destOffset); 2674 } 2675 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { 2676 const maxVal = (1 << bits) - 1; 2677 for (let i = 0; i < count; i++) { 2678 this.#toRgb(src, srcOffset, maxVal, dest, destOffset); 2679 srcOffset += 3; 2680 destOffset += 3 + alpha01; 2681 } 2682 } 2683 getOutputLength(inputLength, alpha01) { 2684 return inputLength * (3 + alpha01) / 3 | 0; 2685 } 2686 isDefaultDecode(decodeMap, bpc) { 2687 return true; 2688 } 2689 get usesZeroToOneRange() { 2690 return shadow(this, "usesZeroToOneRange", false); 2691 } 2692} 2693 2694;// ./src/core/icc_colorspace.js 2695 2696 2697 2698
vendor: 5,596 bytes, lines 2699-2898
2699function fetchSync(url) { 2700 const xhr = new XMLHttpRequest(); 2701 xhr.open("GET", url, false); 2702 xhr.responseType = "arraybuffer"; 2703 xhr.send(null); 2704 return xhr.response; 2705} 2706class IccColorSpace extends ColorSpace { 2707 #transformer; 2708 #convertPixel; 2709 static #useWasm = true; 2710 static #wasmUrl = null; 2711 static #finalizer = null; 2712 constructor(iccProfile, name, numComps) { 2713 if (!IccColorSpace.isUsable) { 2714 throw new Error("No ICC color space support"); 2715 } 2716 super(name, numComps); 2717 let inType; 2718 switch (numComps) { 2719 case 1: 2720 inType = DataType.Gray8; 2721 this.#convertPixel = (src, srcOffset, css) => qcms_convert_one(this.#transformer, src[srcOffset] * 255, css); 2722 break; 2723 case 3: 2724 inType = DataType.RGB8; 2725 this.#convertPixel = (src, srcOffset, css) => qcms_convert_three(this.#transformer, src[srcOffset] * 255, src[srcOffset + 1] * 255, src[srcOffset + 2] * 255, css); 2726 break; 2727 case 4: 2728 inType = DataType.CMYK; 2729 this.#convertPixel = (src, srcOffset, css) => qcms_convert_four(this.#transformer, src[srcOffset] * 255, src[srcOffset + 1] * 255, src[srcOffset + 2] * 255, src[srcOffset + 3] * 255, css); 2730 break; 2731 default: 2732 throw new Error(`Unsupported number of components: ${numComps}`); 2733 } 2734 this.#transformer = qcms_transformer_from_memory(iccProfile, inType, Intent.Perceptual); 2735 if (!this.#transformer) { 2736 throw new Error("Failed to create ICC color space"); 2737 } 2738 IccColorSpace.#finalizer ||= new FinalizationRegistry(transformer => { 2739 qcms_drop_transformer(transformer); 2740 }); 2741 IccColorSpace.#finalizer.register(this, this.#transformer); 2742 } 2743 getRgbHex(src, srcOffset) { 2744 this.#convertPixel(src, srcOffset, true); 2745 return QCMS._cssColor; 2746 } 2747 getRgbItem(src, srcOffset, dest, destOffset) { 2748 QCMS._destBuffer = dest; 2749 QCMS._destOffset = destOffset; 2750 QCMS._destLength = 3; 2751 this.#convertPixel(src, srcOffset, false); 2752 QCMS._destBuffer = null; 2753 } 2754 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { 2755 src = src.subarray(srcOffset, srcOffset + count * this.numComps); 2756 if (bits !== 8) { 2757 const scale = 255 / ((1 << bits) - 1); 2758 for (let i = 0, ii = src.length; i < ii; i++) { 2759 src[i] *= scale; 2760 } 2761 } 2762 QCMS._mustAddAlpha = alpha01 && dest.buffer === src.buffer; 2763 QCMS._destBuffer = dest; 2764 QCMS._destOffset = destOffset; 2765 QCMS._destLength = count * (3 + alpha01); 2766 qcms_convert_array(this.#transformer, src); 2767 QCMS._mustAddAlpha = false; 2768 QCMS._destBuffer = null; 2769 } 2770 getOutputLength(inputLength, alpha01) { 2771 return inputLength / this.numComps * (3 + alpha01) | 0; 2772 } 2773 static setOptions({ 2774 useWasm, 2775 useWorkerFetch, 2776 wasmUrl 2777 }) { 2778 if (!useWorkerFetch) { 2779 this.#useWasm = false; 2780 return; 2781 } 2782 this.#useWasm = useWasm; 2783 this.#wasmUrl = wasmUrl; 2784 } 2785 static get isUsable() { 2786 let isUsable = false; 2787 if (this.#useWasm) { 2788 if (this.#wasmUrl) { 2789 try { 2790 this._module = initSync({ 2791 module: fetchSync(`${this.#wasmUrl}qcms_bg.wasm`) 2792 }); 2793 isUsable = !!this._module; 2794 QCMS._memory = this._module.memory; 2795 QCMS._makeHexColor = Util.makeHexColor; 2796 } catch (e) { 2797 warn(`ICCBased color space: "${e}".`); 2798 } 2799 } else { 2800 warn("No ICC color space support due to missing `wasmUrl` API option"); 2801 } 2802 } 2803 return shadow(this, "isUsable", isUsable); 2804 } 2805} 2806class CmykICCBasedCS extends IccColorSpace { 2807 static #iccUrl; 2808 constructor() { 2809 const iccProfile = new Uint8Array(fetchSync(`${CmykICCBasedCS.#iccUrl}CGATS001Compat-v2-micro.icc`)); 2810 super(iccProfile, "DeviceCMYK", 4); 2811 } 2812 static setOptions({ 2813 iccUrl 2814 }) { 2815 this.#iccUrl = iccUrl; 2816 } 2817 static get isUsable() { 2818 let isUsable = false; 2819 if (IccColorSpace.isUsable) { 2820 if (this.#iccUrl) { 2821 isUsable = true; 2822 } else { 2823 warn("No CMYK ICC profile support due to missing `iccUrl` API option"); 2824 } 2825 } 2826 return shadow(this, "isUsable", isUsable); 2827 } 2828} 2829 2830;// ./src/core/stream.js 2831 2832 2833class Stream extends BaseStream { 2834 constructor(arrayBuffer, start, length, dict) { 2835 super(); 2836 this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer); 2837 this.start = start || 0; 2838 this.pos = this.start; 2839 this.end = start + length || this.bytes.length; 2840 this.dict = dict; 2841 } 2842 get length() { 2843 return this.end - this.start; 2844 } 2845 get isEmpty() { 2846 return this.length === 0; 2847 } 2848 getByte() { 2849 if (this.pos >= this.end) { 2850 return -1; 2851 } 2852 return this.bytes[this.pos++]; 2853 } 2854 getBytes(length) { 2855 const bytes = this.bytes; 2856 const pos = this.pos; 2857 const strEnd = this.end; 2858 if (!length) { 2859 return bytes.subarray(pos, strEnd); 2860 } 2861 let end = pos + length; 2862 if (end > strEnd) { 2863 end = strEnd; 2864 } 2865 this.pos = end; 2866 return bytes.subarray(pos, end); 2867 } 2868 getByteRange(begin, end) { 2869 if (begin < 0) { 2870 begin = 0; 2871 } 2872 if (end > this.end) { 2873 end = this.end; 2874 } 2875 return this.bytes.subarray(begin, end); 2876 } 2877 reset() { 2878 this.pos = this.start; 2879 } 2880 moveStart() { 2881 this.start = this.pos; 2882 } 2883 makeSubStream(start, length, dict = null) { 2884 return new Stream(this.bytes.buffer, start, length, dict); 2885 } 2886} 2887class StringStream extends Stream { 2888 constructor(str) { 2889 super(stringToBytes(str)); 2890 } 2891} 2892class NullStream extends Stream { 2893 constructor() { 2894 super(new Uint8Array(0)); 2895 } 2896} 2897 2898;// ./src/core/chunked_stream.js
vendor: 12,857 bytes, lines 2898-3324
2898 2899 2900 2901 2902class ChunkedStream extends Stream { 2903 constructor(length, chunkSize, manager) { 2904 super(new Uint8Array(length), 0, length, null); 2905 this.chunkSize = chunkSize; 2906 this._loadedChunks = new Set(); 2907 this.numChunks = Math.ceil(length / chunkSize); 2908 this.manager = manager; 2909 this.progressiveDataLength = 0; 2910 this.lastSuccessfulEnsureByteChunk = -1; 2911 } 2912 getMissingChunks() { 2913 const chunks = []; 2914 for (let chunk = 0, n = this.numChunks; chunk < n; ++chunk) { 2915 if (!this._loadedChunks.has(chunk)) { 2916 chunks.push(chunk); 2917 } 2918 } 2919 return chunks; 2920 } 2921 get numChunksLoaded() { 2922 return this._loadedChunks.size; 2923 } 2924 get isDataLoaded() { 2925 return this.numChunksLoaded === this.numChunks; 2926 } 2927 onReceiveData(begin, chunk) { 2928 const chunkSize = this.chunkSize; 2929 if (begin % chunkSize !== 0) { 2930 throw new Error(`Bad begin offset: ${begin}`); 2931 } 2932 const end = begin + chunk.byteLength; 2933 if (end % chunkSize !== 0 && end !== this.bytes.length) { 2934 throw new Error(`Bad end offset: ${end}`); 2935 } 2936 this.bytes.set(new Uint8Array(chunk), begin); 2937 const beginChunk = Math.floor(begin / chunkSize); 2938 const endChunk = Math.floor((end - 1) / chunkSize) + 1; 2939 for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) { 2940 this._loadedChunks.add(curChunk); 2941 } 2942 } 2943 onReceiveProgressiveData(data) { 2944 let position = this.progressiveDataLength; 2945 const beginChunk = Math.floor(position / this.chunkSize); 2946 this.bytes.set(new Uint8Array(data), position); 2947 position += data.byteLength; 2948 this.progressiveDataLength = position; 2949 const endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize); 2950 for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) { 2951 this._loadedChunks.add(curChunk); 2952 } 2953 } 2954 ensureByte(pos) { 2955 if (pos < this.progressiveDataLength) { 2956 return; 2957 } 2958 const chunk = Math.floor(pos / this.chunkSize); 2959 if (chunk > this.numChunks) { 2960 return; 2961 } 2962 if (chunk === this.lastSuccessfulEnsureByteChunk) { 2963 return; 2964 } 2965 if (!this._loadedChunks.has(chunk)) { 2966 throw new MissingDataException(pos, pos + 1); 2967 } 2968 this.lastSuccessfulEnsureByteChunk = chunk; 2969 } 2970 ensureRange(begin, end) { 2971 if (begin >= end) { 2972 return; 2973 } 2974 if (end <= this.progressiveDataLength) { 2975 return; 2976 } 2977 const beginChunk = Math.floor(begin / this.chunkSize); 2978 if (beginChunk > this.numChunks) { 2979 return; 2980 } 2981 const endChunk = Math.min(Math.floor((end - 1) / this.chunkSize) + 1, this.numChunks); 2982 for (let chunk = beginChunk; chunk < endChunk; ++chunk) { 2983 if (!this._loadedChunks.has(chunk)) { 2984 throw new MissingDataException(begin, end); 2985 } 2986 } 2987 } 2988 nextEmptyChunk(beginChunk) { 2989 const numChunks = this.numChunks; 2990 for (let i = 0; i < numChunks; ++i) { 2991 const chunk = (beginChunk + i) % numChunks; 2992 if (!this._loadedChunks.has(chunk)) { 2993 return chunk; 2994 } 2995 } 2996 return null; 2997 } 2998 hasChunk(chunk) { 2999 return this._loadedChunks.has(chunk); 3000 } 3001 getByte() { 3002 const pos = this.pos; 3003 if (pos >= this.end) { 3004 return -1; 3005 } 3006 if (pos >= this.progressiveDataLength) { 3007 this.ensureByte(pos); 3008 } 3009 return this.bytes[this.pos++]; 3010 } 3011 getBytes(length) { 3012 const bytes = this.bytes; 3013 const pos = this.pos; 3014 const strEnd = this.end; 3015 if (!length) { 3016 if (strEnd > this.progressiveDataLength) { 3017 this.ensureRange(pos, strEnd); 3018 } 3019 return bytes.subarray(pos, strEnd); 3020 } 3021 let end = pos + length; 3022 if (end > strEnd) { 3023 end = strEnd; 3024 } 3025 if (end > this.progressiveDataLength) { 3026 this.ensureRange(pos, end); 3027 } 3028 this.pos = end; 3029 return bytes.subarray(pos, end); 3030 } 3031 getByteRange(begin, end) { 3032 if (begin < 0) { 3033 begin = 0; 3034 } 3035 if (end > this.end) { 3036 end = this.end; 3037 } 3038 if (end > this.progressiveDataLength) { 3039 this.ensureRange(begin, end); 3040 } 3041 return this.bytes.subarray(begin, end); 3042 } 3043 makeSubStream(start, length, dict = null) { 3044 if (length) { 3045 if (start + length > this.progressiveDataLength) { 3046 this.ensureRange(start, start + length); 3047 } 3048 } else if (start >= this.progressiveDataLength) { 3049 this.ensureByte(start); 3050 } 3051 function ChunkedStreamSubstream() {} 3052 ChunkedStreamSubstream.prototype = Object.create(this); 3053 ChunkedStreamSubstream.prototype.getMissingChunks = function () { 3054 const chunkSize = this.chunkSize; 3055 const beginChunk = Math.floor(this.start / chunkSize); 3056 const endChunk = Math.floor((this.end - 1) / chunkSize) + 1; 3057 const missingChunks = []; 3058 for (let chunk = beginChunk; chunk < endChunk; ++chunk) { 3059 if (!this._loadedChunks.has(chunk)) { 3060 missingChunks.push(chunk); 3061 } 3062 } 3063 return missingChunks; 3064 }; 3065 Object.defineProperty(ChunkedStreamSubstream.prototype, "isDataLoaded", { 3066 get() { 3067 if (this.numChunksLoaded === this.numChunks) { 3068 return true; 3069 } 3070 return this.getMissingChunks().length === 0; 3071 }, 3072 configurable: true 3073 }); 3074 const subStream = new ChunkedStreamSubstream(); 3075 subStream.pos = subStream.start = start; 3076 subStream.end = start + length || this.end; 3077 subStream.dict = dict; 3078 return subStream; 3079 } 3080 getBaseStreams() { 3081 return [this]; 3082 } 3083} 3084class ChunkedStreamManager { 3085 constructor(pdfNetworkStream, args) { 3086 this.length = args.length; 3087 this.chunkSize = args.rangeChunkSize; 3088 this.stream = new ChunkedStream(this.length, this.chunkSize, this); 3089 this.pdfNetworkStream = pdfNetworkStream; 3090 this.disableAutoFetch = args.disableAutoFetch; 3091 this.msgHandler = args.msgHandler; 3092 this.currRequestId = 0; 3093 this._chunksNeededByRequest = new Map(); 3094 this._requestsByChunk = new Map(); 3095 this._promisesByRequest = new Map(); 3096 this.progressiveDataLength = 0; 3097 this.aborted = false; 3098 this._loadedStreamCapability = Promise.withResolvers(); 3099 } 3100 sendRequest(begin, end) { 3101 const rangeReader = this.pdfNetworkStream.getRangeReader(begin, end); 3102 if (!rangeReader.isStreamingSupported) { 3103 rangeReader.onProgress = this.onProgress.bind(this); 3104 } 3105 let chunks = [], 3106 loaded = 0; 3107 return new Promise((resolve, reject) => { 3108 const readChunk = ({ 3109 value, 3110 done 3111 }) => { 3112 try { 3113 if (done) { 3114 const chunkData = arrayBuffersToBytes(chunks); 3115 chunks = null; 3116 resolve(chunkData); 3117 return; 3118 } 3119 loaded += value.byteLength; 3120 if (rangeReader.isStreamingSupported) { 3121 this.onProgress({ 3122 loaded 3123 }); 3124 } 3125 chunks.push(value); 3126 rangeReader.read().then(readChunk, reject); 3127 } catch (e) { 3128 reject(e); 3129 } 3130 }; 3131 rangeReader.read().then(readChunk, reject); 3132 }).then(data => { 3133 if (this.aborted) { 3134 return; 3135 } 3136 this.onReceiveData({ 3137 chunk: data, 3138 begin 3139 }); 3140 }); 3141 } 3142 requestAllChunks(noFetch = false) { 3143 if (!noFetch) { 3144 const missingChunks = this.stream.getMissingChunks(); 3145 this._requestChunks(missingChunks); 3146 } 3147 return this._loadedStreamCapability.promise; 3148 } 3149 _requestChunks(chunks) { 3150 const requestId = this.currRequestId++; 3151 const chunksNeeded = new Set(); 3152 this._chunksNeededByRequest.set(requestId, chunksNeeded); 3153 for (const chunk of chunks) { 3154 if (!this.stream.hasChunk(chunk)) { 3155 chunksNeeded.add(chunk); 3156 } 3157 } 3158 if (chunksNeeded.size === 0) { 3159 return Promise.resolve(); 3160 } 3161 const capability = Promise.withResolvers(); 3162 this._promisesByRequest.set(requestId, capability); 3163 const chunksToRequest = []; 3164 for (const chunk of chunksNeeded) { 3165 let requestIds = this._requestsByChunk.get(chunk); 3166 if (!requestIds) { 3167 requestIds = []; 3168 this._requestsByChunk.set(chunk, requestIds); 3169 chunksToRequest.push(chunk); 3170 } 3171 requestIds.push(requestId); 3172 } 3173 if (chunksToRequest.length > 0) { 3174 const groupedChunksToRequest = this.groupChunks(chunksToRequest); 3175 for (const groupedChunk of groupedChunksToRequest) { 3176 const begin = groupedChunk.beginChunk * this.chunkSize; 3177 const end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length); 3178 this.sendRequest(begin, end).catch(capability.reject); 3179 } 3180 } 3181 return capability.promise.catch(reason => { 3182 if (this.aborted) { 3183 return; 3184 } 3185 throw reason; 3186 }); 3187 } 3188 getStream() { 3189 return this.stream; 3190 } 3191 requestRange(begin, end) { 3192 end = Math.min(end, this.length); 3193 const beginChunk = this.getBeginChunk(begin); 3194 const endChunk = this.getEndChunk(end); 3195 const chunks = []; 3196 for (let chunk = beginChunk; chunk < endChunk; ++chunk) { 3197 chunks.push(chunk); 3198 } 3199 return this._requestChunks(chunks); 3200 } 3201 requestRanges(ranges = []) { 3202 const chunksToRequest = []; 3203 for (const range of ranges) { 3204 const beginChunk = this.getBeginChunk(range.begin); 3205 const endChunk = this.getEndChunk(range.end); 3206 for (let chunk = beginChunk; chunk < endChunk; ++chunk) { 3207 if (!chunksToRequest.includes(chunk)) { 3208 chunksToRequest.push(chunk); 3209 } 3210 } 3211 } 3212 chunksToRequest.sort((a, b) => a - b); 3213 return this._requestChunks(chunksToRequest); 3214 } 3215 groupChunks(chunks) { 3216 const groupedChunks = []; 3217 let beginChunk = -1; 3218 let prevChunk = -1; 3219 for (let i = 0, ii = chunks.length; i < ii; ++i) { 3220 const chunk = chunks[i]; 3221 if (beginChunk < 0) { 3222 beginChunk = chunk; 3223 } 3224 if (prevChunk >= 0 && prevChunk + 1 !== chunk) { 3225 groupedChunks.push({ 3226 beginChunk, 3227 endChunk: prevChunk + 1 3228 }); 3229 beginChunk = chunk; 3230 } 3231 if (i + 1 === chunks.length) { 3232 groupedChunks.push({ 3233 beginChunk, 3234 endChunk: chunk + 1 3235 }); 3236 } 3237 prevChunk = chunk; 3238 } 3239 return groupedChunks; 3240 } 3241 onProgress(args) { 3242 this.msgHandler.send("DocProgress", { 3243 loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded, 3244 total: this.length 3245 }); 3246 } 3247 onReceiveData(args) { 3248 const chunk = args.chunk; 3249 const isProgressive = args.begin === undefined; 3250 const begin = isProgressive ? this.progressiveDataLength : args.begin; 3251 const end = begin + chunk.byteLength; 3252 const beginChunk = Math.floor(begin / this.chunkSize); 3253 const endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize); 3254 if (isProgressive) { 3255 this.stream.onReceiveProgressiveData(chunk); 3256 this.progressiveDataLength = end; 3257 } else { 3258 this.stream.onReceiveData(begin, chunk); 3259 } 3260 if (this.stream.isDataLoaded) { 3261 this._loadedStreamCapability.resolve(this.stream); 3262 } 3263 const loadedRequests = []; 3264 for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) { 3265 const requestIds = this._requestsByChunk.get(curChunk); 3266 if (!requestIds) { 3267 continue; 3268 } 3269 this._requestsByChunk.delete(curChunk); 3270 for (const requestId of requestIds) { 3271 const chunksNeeded = this._chunksNeededByRequest.get(requestId); 3272 if (chunksNeeded.has(curChunk)) { 3273 chunksNeeded.delete(curChunk); 3274 } 3275 if (chunksNeeded.size > 0) { 3276 continue; 3277 } 3278 loadedRequests.push(requestId); 3279 } 3280 } 3281 if (!this.disableAutoFetch && this._requestsByChunk.size === 0) { 3282 let nextEmptyChunk; 3283 if (this.stream.numChunksLoaded === 1) { 3284 const lastChunk = this.stream.numChunks - 1; 3285 if (!this.stream.hasChunk(lastChunk)) { 3286 nextEmptyChunk = lastChunk; 3287 } 3288 } else { 3289 nextEmptyChunk = this.stream.nextEmptyChunk(endChunk); 3290 } 3291 if (Number.isInteger(nextEmptyChunk)) { 3292 this._requestChunks([nextEmptyChunk]); 3293 } 3294 } 3295 for (const requestId of loadedRequests) { 3296 const capability = this._promisesByRequest.get(requestId); 3297 this._promisesByRequest.delete(requestId); 3298 capability.resolve(); 3299 } 3300 this.msgHandler.send("DocProgress", { 3301 loaded: this.stream.numChunksLoaded * this.chunkSize, 3302 total: this.length 3303 }); 3304 } 3305 onError(err) { 3306 this._loadedStreamCapability.reject(err); 3307 } 3308 getBeginChunk(begin) { 3309 return Math.floor(begin / this.chunkSize); 3310 } 3311 getEndChunk(end) { 3312 return Math.floor((end - 1) / this.chunkSize) + 1; 3313 } 3314 abort(reason) { 3315 this.aborted = true; 3316 this.pdfNetworkStream?.cancelAllRequests(reason); 3317 for (const capability of this._promisesByRequest.values()) { 3318 capability.reject(reason); 3319 } 3320 } 3321} 3322 3323;// ./src/shared/image_utils.js 3324
vendor: 11,207 bytes, lines 3325-3691
3325function convertToRGBA(params) { 3326 switch (params.kind) { 3327 case ImageKind.GRAYSCALE_1BPP: 3328 return convertBlackAndWhiteToRGBA(params); 3329 case ImageKind.RGB_24BPP: 3330 return convertRGBToRGBA(params); 3331 } 3332 return null; 3333} 3334function convertBlackAndWhiteToRGBA({ 3335 src, 3336 srcPos = 0, 3337 dest, 3338 width, 3339 height, 3340 nonBlackColor = 0xffffffff, 3341 inverseDecode = false 3342}) { 3343 const black = FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff; 3344 const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor]; 3345 const widthInSource = width >> 3; 3346 const widthRemainder = width & 7; 3347 const srcLength = src.length; 3348 dest = new Uint32Array(dest.buffer); 3349 let destPos = 0; 3350 for (let i = 0; i < height; i++) { 3351 for (const max = srcPos + widthInSource; srcPos < max; srcPos++) { 3352 const elem = srcPos < srcLength ? src[srcPos] : 255; 3353 dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping; 3354 dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping; 3355 dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping; 3356 dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping; 3357 dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping; 3358 dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping; 3359 dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping; 3360 dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping; 3361 } 3362 if (widthRemainder === 0) { 3363 continue; 3364 } 3365 const elem = srcPos < srcLength ? src[srcPos++] : 255; 3366 for (let j = 0; j < widthRemainder; j++) { 3367 dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping; 3368 } 3369 } 3370 return { 3371 srcPos, 3372 destPos 3373 }; 3374} 3375function convertRGBToRGBA({ 3376 src, 3377 srcPos = 0, 3378 dest, 3379 destPos = 0, 3380 width, 3381 height 3382}) { 3383 let i = 0; 3384 const len = width * height * 3; 3385 const len32 = len >> 2; 3386 const src32 = new Uint32Array(src.buffer, srcPos, len32); 3387 if (FeatureTest.isLittleEndian) { 3388 for (; i < len32 - 2; i += 3, destPos += 4) { 3389 const s1 = src32[i]; 3390 const s2 = src32[i + 1]; 3391 const s3 = src32[i + 2]; 3392 dest[destPos] = s1 | 0xff000000; 3393 dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 0xff000000; 3394 dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 0xff000000; 3395 dest[destPos + 3] = s3 >>> 8 | 0xff000000; 3396 } 3397 for (let j = i * 4, jj = srcPos + len; j < jj; j += 3) { 3398 dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 0xff000000; 3399 } 3400 } else { 3401 for (; i < len32 - 2; i += 3, destPos += 4) { 3402 const s1 = src32[i]; 3403 const s2 = src32[i + 1]; 3404 const s3 = src32[i + 2]; 3405 dest[destPos] = s1 | 0xff; 3406 dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 0xff; 3407 dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 0xff; 3408 dest[destPos + 3] = s3 << 8 | 0xff; 3409 } 3410 for (let j = i * 4, jj = srcPos + len; j < jj; j += 3) { 3411 dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 0xff; 3412 } 3413 } 3414 return { 3415 srcPos: srcPos + len, 3416 destPos 3417 }; 3418} 3419function grayToRGBA(src, dest) { 3420 if (FeatureTest.isLittleEndian) { 3421 for (let i = 0, ii = src.length; i < ii; i++) { 3422 dest[i] = src[i] * 0x10101 | 0xff000000; 3423 } 3424 } else { 3425 for (let i = 0, ii = src.length; i < ii; i++) { 3426 dest[i] = src[i] * 0x1010100 | 0x000000ff; 3427 } 3428 } 3429} 3430 3431;// ./src/core/image_resizer.js 3432 3433 3434 3435const MIN_IMAGE_DIM = 2048; 3436const MAX_IMAGE_DIM = 65537; 3437const MAX_ERROR = 128; 3438class ImageResizer { 3439 static #goodSquareLength = MIN_IMAGE_DIM; 3440 static #isImageDecoderSupported = FeatureTest.isImageDecoderSupported; 3441 constructor(imgData, isMask) { 3442 this._imgData = imgData; 3443 this._isMask = isMask; 3444 } 3445 static get canUseImageDecoder() { 3446 return shadow(this, "canUseImageDecoder", this.#isImageDecoderSupported ? ImageDecoder.isTypeSupported("image/bmp") : Promise.resolve(false)); 3447 } 3448 static needsToBeResized(width, height) { 3449 if (width <= this.#goodSquareLength && height <= this.#goodSquareLength) { 3450 return false; 3451 } 3452 const { 3453 MAX_DIM 3454 } = this; 3455 if (width > MAX_DIM || height > MAX_DIM) { 3456 return true; 3457 } 3458 const area = width * height; 3459 if (this._hasMaxArea) { 3460 return area > this.MAX_AREA; 3461 } 3462 if (area < this.#goodSquareLength ** 2) { 3463 return false; 3464 } 3465 if (this._areGoodDims(width, height)) { 3466 this.#goodSquareLength = Math.max(this.#goodSquareLength, Math.floor(Math.sqrt(width * height))); 3467 return false; 3468 } 3469 this.#goodSquareLength = this._guessMax(this.#goodSquareLength, MAX_DIM, MAX_ERROR, 0); 3470 const maxArea = this.MAX_AREA = this.#goodSquareLength ** 2; 3471 return area > maxArea; 3472 } 3473 static getReducePowerForJPX(width, height, componentsCount) { 3474 const area = width * height; 3475 const maxJPXArea = 2 ** 30 / (componentsCount * 4); 3476 if (!this.needsToBeResized(width, height)) { 3477 if (area > maxJPXArea) { 3478 return Math.ceil(Math.log2(area / maxJPXArea)); 3479 } 3480 return 0; 3481 } 3482 const { 3483 MAX_DIM, 3484 MAX_AREA 3485 } = this; 3486 const minFactor = Math.max(width / MAX_DIM, height / MAX_DIM, Math.sqrt(area / Math.min(maxJPXArea, MAX_AREA))); 3487 return Math.ceil(Math.log2(minFactor)); 3488 } 3489 static get MAX_DIM() { 3490 return shadow(this, "MAX_DIM", this._guessMax(MIN_IMAGE_DIM, MAX_IMAGE_DIM, 0, 1)); 3491 } 3492 static get MAX_AREA() { 3493 this._hasMaxArea = true; 3494 return shadow(this, "MAX_AREA", this._guessMax(this.#goodSquareLength, this.MAX_DIM, MAX_ERROR, 0) ** 2); 3495 } 3496 static set MAX_AREA(area) { 3497 if (area >= 0) { 3498 this._hasMaxArea = true; 3499 shadow(this, "MAX_AREA", area); 3500 } 3501 } 3502 static setOptions({ 3503 canvasMaxAreaInBytes = -1, 3504 isImageDecoderSupported = false 3505 }) { 3506 if (!this._hasMaxArea) { 3507 this.MAX_AREA = canvasMaxAreaInBytes >> 2; 3508 } 3509 this.#isImageDecoderSupported = isImageDecoderSupported; 3510 } 3511 static _areGoodDims(width, height) { 3512 try { 3513 const canvas = new OffscreenCanvas(width, height); 3514 const ctx = canvas.getContext("2d"); 3515 ctx.fillRect(0, 0, 1, 1); 3516 const opacity = ctx.getImageData(0, 0, 1, 1).data[3]; 3517 canvas.width = canvas.height = 1; 3518 return opacity !== 0; 3519 } catch { 3520 return false; 3521 } 3522 } 3523 static _guessMax(start, end, tolerance, defaultHeight) { 3524 while (start + tolerance + 1 < end) { 3525 const middle = Math.floor((start + end) / 2); 3526 const height = defaultHeight || middle; 3527 if (this._areGoodDims(middle, height)) { 3528 start = middle; 3529 } else { 3530 end = middle; 3531 } 3532 } 3533 return start; 3534 } 3535 static async createImage(imgData, isMask = false) { 3536 return new ImageResizer(imgData, isMask)._createImage(); 3537 } 3538 async _createImage() { 3539 const { 3540 _imgData: imgData 3541 } = this; 3542 const { 3543 width, 3544 height 3545 } = imgData; 3546 if (width * height * 4 > MAX_INT_32) { 3547 const result = this.#rescaleImageData(); 3548 if (result) { 3549 return result; 3550 } 3551 } 3552 const data = this._encodeBMP(); 3553 let decoder, imagePromise; 3554 if (await ImageResizer.canUseImageDecoder) { 3555 decoder = new ImageDecoder({ 3556 data, 3557 type: "image/bmp", 3558 preferAnimation: false, 3559 transfer: [data.buffer] 3560 }); 3561 imagePromise = decoder.decode().catch(reason => { 3562 warn(`BMP image decoding failed: ${reason}`); 3563 return createImageBitmap(new Blob([this._encodeBMP().buffer], { 3564 type: "image/bmp" 3565 })); 3566 }).finally(() => { 3567 decoder.close(); 3568 }); 3569 } else { 3570 imagePromise = createImageBitmap(new Blob([data.buffer], { 3571 type: "image/bmp" 3572 })); 3573 } 3574 const { 3575 MAX_AREA, 3576 MAX_DIM 3577 } = ImageResizer; 3578 const minFactor = Math.max(width / MAX_DIM, height / MAX_DIM, Math.sqrt(width * height / MAX_AREA)); 3579 const firstFactor = Math.max(minFactor, 2); 3580 const factor = Math.round(10 * (minFactor + 1.25)) / 10 / firstFactor; 3581 const N = Math.floor(Math.log2(factor)); 3582 const steps = new Array(N + 2).fill(2); 3583 steps[0] = firstFactor; 3584 steps.splice(-1, 1, factor / (1 << N)); 3585 let newWidth = width; 3586 let newHeight = height; 3587 const result = await imagePromise; 3588 let bitmap = result.image || result; 3589 for (const step of steps) { 3590 const prevWidth = newWidth; 3591 const prevHeight = newHeight; 3592 newWidth = Math.floor(newWidth / step) - 1; 3593 newHeight = Math.floor(newHeight / step) - 1; 3594 const canvas = new OffscreenCanvas(newWidth, newHeight); 3595 const ctx = canvas.getContext("2d"); 3596 ctx.drawImage(bitmap, 0, 0, prevWidth, prevHeight, 0, 0, newWidth, newHeight); 3597 bitmap.close(); 3598 bitmap = canvas.transferToImageBitmap(); 3599 } 3600 imgData.data = null; 3601 imgData.bitmap = bitmap; 3602 imgData.width = newWidth; 3603 imgData.height = newHeight; 3604 return imgData; 3605 } 3606 #rescaleImageData() { 3607 const { 3608 _imgData: imgData 3609 } = this; 3610 const { 3611 data, 3612 width, 3613 height, 3614 kind 3615 } = imgData; 3616 const rgbaSize = width * height * 4; 3617 const K = Math.ceil(Math.log2(rgbaSize / MAX_INT_32)); 3618 const newWidth = width >> K; 3619 const newHeight = height >> K; 3620 let rgbaData; 3621 let maxHeight = height; 3622 try { 3623 rgbaData = new Uint8Array(rgbaSize); 3624 } catch { 3625 let n = Math.floor(Math.log2(rgbaSize + 1)); 3626 while (true) { 3627 try { 3628 rgbaData = new Uint8Array(2 ** n - 1); 3629 break; 3630 } catch { 3631 n -= 1; 3632 } 3633 } 3634 maxHeight = Math.floor((2 ** n - 1) / (width * 4)); 3635 const newSize = width * maxHeight * 4; 3636 if (newSize < rgbaData.length) { 3637 rgbaData = new Uint8Array(newSize); 3638 } 3639 } 3640 const src32 = new Uint32Array(rgbaData.buffer); 3641 const dest32 = new Uint32Array(newWidth * newHeight); 3642 let srcPos = 0; 3643 let newIndex = 0; 3644 const step = Math.ceil(height / maxHeight); 3645 const remainder = height % maxHeight === 0 ? height : height % maxHeight; 3646 for (let k = 0; k < step; k++) { 3647 const h = k < step - 1 ? maxHeight : remainder; 3648 ({ 3649 srcPos 3650 } = convertToRGBA({ 3651 kind, 3652 src: data, 3653 dest: src32, 3654 width, 3655 height: h, 3656 inverseDecode: this._isMask, 3657 srcPos 3658 })); 3659 for (let i = 0, ii = h >> K; i < ii; i++) { 3660 const buf = src32.subarray((i << K) * width); 3661 for (let j = 0; j < newWidth; j++) { 3662 dest32[newIndex++] = buf[j << K]; 3663 } 3664 } 3665 } 3666 if (ImageResizer.needsToBeResized(newWidth, newHeight)) { 3667 imgData.data = dest32; 3668 imgData.width = newWidth; 3669 imgData.height = newHeight; 3670 imgData.kind = ImageKind.RGBA_32BPP; 3671 return null; 3672 } 3673 const canvas = new OffscreenCanvas(newWidth, newHeight); 3674 const ctx = canvas.getContext("2d", { 3675 willReadFrequently: true 3676 }); 3677 ctx.putImageData(new ImageData(new Uint8ClampedArray(dest32.buffer), newWidth, newHeight), 0, 0); 3678 imgData.data = null; 3679 imgData.bitmap = canvas.transferToImageBitmap(); 3680 imgData.width = newWidth; 3681 imgData.height = newHeight; 3682 return imgData; 3683 } 3684 _encodeBMP() { 3685 const { 3686 width, 3687 height, 3688 kind 3689 } = this._imgData; 3690 let data = this._imgData.data; 3691 let bitPerPixel;
vendor: 3,615 bytes, lines 3692-3804
3692 let colorTable = new Uint8Array(0); 3693 let maskTable = colorTable; 3694 let compression = 0; 3695 switch (kind) { 3696 case ImageKind.GRAYSCALE_1BPP: 3697 { 3698 bitPerPixel = 1; 3699 colorTable = new Uint8Array(this._isMask ? [255, 255, 255, 255, 0, 0, 0, 0] : [0, 0, 0, 0, 255, 255, 255, 255]); 3700 const rowLen = width + 7 >> 3; 3701 const rowSize = rowLen + 3 & -4; 3702 if (rowLen !== rowSize) { 3703 const newData = new Uint8Array(rowSize * height); 3704 let k = 0; 3705 for (let i = 0, ii = height * rowLen; i < ii; i += rowLen, k += rowSize) { 3706 newData.set(data.subarray(i, i + rowLen), k); 3707 } 3708 data = newData; 3709 } 3710 break; 3711 } 3712 case ImageKind.RGB_24BPP: 3713 { 3714 bitPerPixel = 24; 3715 if (width & 3) { 3716 const rowLen = 3 * width; 3717 const rowSize = rowLen + 3 & -4; 3718 const extraLen = rowSize - rowLen; 3719 const newData = new Uint8Array(rowSize * height); 3720 let k = 0; 3721 for (let i = 0, ii = height * rowLen; i < ii; i += rowLen) { 3722 const row = data.subarray(i, i + rowLen); 3723 for (let j = 0; j < rowLen; j += 3) { 3724 newData[k++] = row[j + 2]; 3725 newData[k++] = row[j + 1]; 3726 newData[k++] = row[j]; 3727 } 3728 k += extraLen; 3729 } 3730 data = newData; 3731 } else { 3732 for (let i = 0, ii = data.length; i < ii; i += 3) { 3733 const tmp = data[i]; 3734 data[i] = data[i + 2]; 3735 data[i + 2] = tmp; 3736 } 3737 } 3738 break; 3739 } 3740 case ImageKind.RGBA_32BPP: 3741 bitPerPixel = 32; 3742 compression = 3; 3743 maskTable = new Uint8Array(4 + 4 + 4 + 4 + 52); 3744 const view = new DataView(maskTable.buffer); 3745 if (FeatureTest.isLittleEndian) { 3746 view.setUint32(0, 0x000000ff, true); 3747 view.setUint32(4, 0x0000ff00, true); 3748 view.setUint32(8, 0x00ff0000, true); 3749 view.setUint32(12, 0xff000000, true); 3750 } else { 3751 view.setUint32(0, 0xff000000, true); 3752 view.setUint32(4, 0x00ff0000, true); 3753 view.setUint32(8, 0x0000ff00, true); 3754 view.setUint32(12, 0x000000ff, true); 3755 } 3756 break; 3757 default: 3758 throw new Error("invalid format"); 3759 } 3760 let i = 0; 3761 const headerLength = 40 + maskTable.length; 3762 const fileLength = 14 + headerLength + colorTable.length + data.length; 3763 const bmpData = new Uint8Array(fileLength); 3764 const view = new DataView(bmpData.buffer); 3765 view.setUint16(i, 0x4d42, true); 3766 i += 2; 3767 view.setUint32(i, fileLength, true); 3768 i += 4; 3769 view.setUint32(i, 0, true); 3770 i += 4; 3771 view.setUint32(i, 14 + headerLength + colorTable.length, true); 3772 i += 4; 3773 view.setUint32(i, headerLength, true); 3774 i += 4; 3775 view.setInt32(i, width, true); 3776 i += 4; 3777 view.setInt32(i, -height, true); 3778 i += 4; 3779 view.setUint16(i, 1, true); 3780 i += 2; 3781 view.setUint16(i, bitPerPixel, true); 3782 i += 2; 3783 view.setUint32(i, compression, true); 3784 i += 4; 3785 view.setUint32(i, 0, true); 3786 i += 4; 3787 view.setInt32(i, 0, true); 3788 i += 4; 3789 view.setInt32(i, 0, true); 3790 i += 4; 3791 view.setUint32(i, colorTable.length / 4, true); 3792 i += 4; 3793 view.setUint32(i, 0, true); 3794 i += 4; 3795 bmpData.set(maskTable, i); 3796 i += maskTable.length; 3797 bmpData.set(colorTable, i); 3798 i += colorTable.length; 3799 bmpData.set(data, i); 3800 return bmpData; 3801 } 3802} 3803 3804;// ./src/core/decode_stream.js
vendor: 45,446 bytes, lines 3804-5303
3804 3805 3806 3807const emptyBuffer = new Uint8Array(0); 3808class DecodeStream extends BaseStream { 3809 constructor(maybeMinBufferLength) { 3810 super(); 3811 this._rawMinBufferLength = maybeMinBufferLength || 0; 3812 this.pos = 0; 3813 this.bufferLength = 0; 3814 this.eof = false; 3815 this.buffer = emptyBuffer; 3816 this.minBufferLength = 512; 3817 if (maybeMinBufferLength) { 3818 while (this.minBufferLength < maybeMinBufferLength) { 3819 this.minBufferLength *= 2; 3820 } 3821 } 3822 } 3823 get isEmpty() { 3824 while (!this.eof && this.bufferLength === 0) { 3825 this.readBlock(); 3826 } 3827 return this.bufferLength === 0; 3828 } 3829 ensureBuffer(requested) { 3830 const buffer = this.buffer; 3831 if (requested <= buffer.byteLength) { 3832 return buffer; 3833 } 3834 let size = this.minBufferLength; 3835 while (size < requested) { 3836 size *= 2; 3837 } 3838 const buffer2 = new Uint8Array(size); 3839 buffer2.set(buffer); 3840 return this.buffer = buffer2; 3841 } 3842 getByte() { 3843 const pos = this.pos; 3844 while (this.bufferLength <= pos) { 3845 if (this.eof) { 3846 return -1; 3847 } 3848 this.readBlock(); 3849 } 3850 return this.buffer[this.pos++]; 3851 } 3852 getBytes(length, decoderOptions = null) { 3853 const pos = this.pos; 3854 let end; 3855 if (length) { 3856 this.ensureBuffer(pos + length); 3857 end = pos + length; 3858 while (!this.eof && this.bufferLength < end) { 3859 this.readBlock(decoderOptions); 3860 } 3861 const bufEnd = this.bufferLength; 3862 if (end > bufEnd) { 3863 end = bufEnd; 3864 } 3865 } else { 3866 while (!this.eof) { 3867 this.readBlock(decoderOptions); 3868 } 3869 end = this.bufferLength; 3870 } 3871 this.pos = end; 3872 return this.buffer.subarray(pos, end); 3873 } 3874 async getImageData(length, decoderOptions) { 3875 if (!this.canAsyncDecodeImageFromBuffer) { 3876 if (this.isAsyncDecoder) { 3877 return this.decodeImage(null, decoderOptions); 3878 } 3879 return this.getBytes(length, decoderOptions); 3880 } 3881 const data = await this.stream.asyncGetBytes(); 3882 return this.decodeImage(data, decoderOptions); 3883 } 3884 reset() { 3885 this.pos = 0; 3886 } 3887 makeSubStream(start, length, dict = null) { 3888 if (length === undefined) { 3889 while (!this.eof) { 3890 this.readBlock(); 3891 } 3892 } else { 3893 const end = start + length; 3894 while (this.bufferLength <= end && !this.eof) { 3895 this.readBlock(); 3896 } 3897 } 3898 return new Stream(this.buffer, start, length, dict); 3899 } 3900 getBaseStreams() { 3901 return this.str ? this.str.getBaseStreams() : null; 3902 } 3903} 3904class StreamsSequenceStream extends DecodeStream { 3905 constructor(streams, onError = null) { 3906 streams = streams.filter(s => s instanceof BaseStream); 3907 let maybeLength = 0; 3908 for (const stream of streams) { 3909 maybeLength += stream instanceof DecodeStream ? stream._rawMinBufferLength : stream.length; 3910 } 3911 super(maybeLength); 3912 this.streams = streams; 3913 this._onError = onError; 3914 } 3915 readBlock() { 3916 const streams = this.streams; 3917 if (streams.length === 0) { 3918 this.eof = true; 3919 return; 3920 } 3921 const stream = streams.shift(); 3922 let chunk; 3923 try { 3924 chunk = stream.getBytes(); 3925 } catch (reason) { 3926 if (this._onError) { 3927 this._onError(reason, stream.dict?.objId); 3928 return; 3929 } 3930 throw reason; 3931 } 3932 const bufferLength = this.bufferLength; 3933 const newLength = bufferLength + chunk.length; 3934 const buffer = this.ensureBuffer(newLength); 3935 buffer.set(chunk, bufferLength); 3936 this.bufferLength = newLength; 3937 } 3938 getBaseStreams() { 3939 const baseStreamsBuf = []; 3940 for (const stream of this.streams) { 3941 const baseStreams = stream.getBaseStreams(); 3942 if (baseStreams) { 3943 baseStreamsBuf.push(...baseStreams); 3944 } 3945 } 3946 return baseStreamsBuf.length > 0 ? baseStreamsBuf : null; 3947 } 3948} 3949 3950;// ./src/core/colorspace_utils.js 3951 3952 3953 3954 3955 3956class ColorSpaceUtils { 3957 static parse({ 3958 cs, 3959 xref, 3960 resources = null, 3961 pdfFunctionFactory, 3962 globalColorSpaceCache, 3963 localColorSpaceCache, 3964 asyncIfNotCached = false 3965 }) { 3966 const options = { 3967 xref, 3968 resources, 3969 pdfFunctionFactory, 3970 globalColorSpaceCache, 3971 localColorSpaceCache 3972 }; 3973 let csName, csRef, parsedCS; 3974 if (cs instanceof Ref) { 3975 csRef = cs; 3976 const cachedCS = globalColorSpaceCache.getByRef(csRef) || localColorSpaceCache.getByRef(csRef); 3977 if (cachedCS) { 3978 return cachedCS; 3979 } 3980 cs = xref.fetch(cs); 3981 } 3982 if (cs instanceof Name) { 3983 csName = cs.name; 3984 const cachedCS = localColorSpaceCache.getByName(csName); 3985 if (cachedCS) { 3986 return cachedCS; 3987 } 3988 } 3989 try { 3990 parsedCS = this.#parse(cs, options); 3991 } catch (ex) { 3992 if (asyncIfNotCached && !(ex instanceof MissingDataException)) { 3993 return Promise.reject(ex); 3994 } 3995 throw ex; 3996 } 3997 if (csName || csRef) { 3998 localColorSpaceCache.set(csName, csRef, parsedCS); 3999 if (csRef) { 4000 globalColorSpaceCache.set(null, csRef, parsedCS); 4001 } 4002 } 4003 return asyncIfNotCached ? Promise.resolve(parsedCS) : parsedCS; 4004 } 4005 static #subParse(cs, options) { 4006 const { 4007 globalColorSpaceCache 4008 } = options; 4009 let csRef; 4010 if (cs instanceof Ref) { 4011 csRef = cs; 4012 const cachedCS = globalColorSpaceCache.getByRef(csRef); 4013 if (cachedCS) { 4014 return cachedCS; 4015 } 4016 } 4017 const parsedCS = this.#parse(cs, options); 4018 if (csRef) { 4019 globalColorSpaceCache.set(null, csRef, parsedCS); 4020 } 4021 return parsedCS; 4022 } 4023 static #parse(cs, options) { 4024 const { 4025 xref, 4026 resources, 4027 pdfFunctionFactory, 4028 globalColorSpaceCache 4029 } = options; 4030 cs = xref.fetchIfRef(cs); 4031 if (cs instanceof Name) { 4032 switch (cs.name) { 4033 case "G": 4034 case "DeviceGray": 4035 return this.gray; 4036 case "RGB": 4037 case "DeviceRGB": 4038 return this.rgb; 4039 case "DeviceRGBA": 4040 return this.rgba; 4041 case "CMYK": 4042 case "DeviceCMYK": 4043 return this.cmyk; 4044 case "Pattern": 4045 return new PatternCS(null); 4046 default: 4047 if (resources instanceof Dict) { 4048 const colorSpaces = resources.get("ColorSpace"); 4049 if (colorSpaces instanceof Dict) { 4050 const resourcesCS = colorSpaces.get(cs.name); 4051 if (resourcesCS) { 4052 if (resourcesCS instanceof Name) { 4053 return this.#parse(resourcesCS, options); 4054 } 4055 cs = resourcesCS; 4056 break; 4057 } 4058 } 4059 } 4060 warn(`Unrecognized ColorSpace: ${cs.name}`); 4061 return this.gray; 4062 } 4063 } 4064 if (Array.isArray(cs)) { 4065 const mode = xref.fetchIfRef(cs[0]).name; 4066 let params, numComps, baseCS, whitePoint, blackPoint, gamma; 4067 switch (mode) { 4068 case "G": 4069 case "DeviceGray": 4070 return this.gray; 4071 case "RGB": 4072 case "DeviceRGB": 4073 return this.rgb; 4074 case "CMYK": 4075 case "DeviceCMYK": 4076 return this.cmyk; 4077 case "CalGray": 4078 params = xref.fetchIfRef(cs[1]); 4079 whitePoint = params.getArray("WhitePoint"); 4080 blackPoint = params.getArray("BlackPoint"); 4081 gamma = params.get("Gamma"); 4082 return new CalGrayCS(whitePoint, blackPoint, gamma); 4083 case "CalRGB": 4084 params = xref.fetchIfRef(cs[1]); 4085 whitePoint = params.getArray("WhitePoint"); 4086 blackPoint = params.getArray("BlackPoint"); 4087 gamma = params.getArray("Gamma"); 4088 const matrix = params.getArray("Matrix"); 4089 return new CalRGBCS(whitePoint, blackPoint, gamma, matrix); 4090 case "ICCBased": 4091 const isRef = cs[1] instanceof Ref; 4092 if (isRef) { 4093 const cachedCS = globalColorSpaceCache.getByRef(cs[1]); 4094 if (cachedCS) { 4095 return cachedCS; 4096 } 4097 } 4098 const stream = xref.fetchIfRef(cs[1]); 4099 const dict = stream.dict; 4100 numComps = dict.get("N"); 4101 if (IccColorSpace.isUsable) { 4102 try { 4103 const iccCS = new IccColorSpace(stream.getBytes(), "ICCBased", numComps); 4104 if (isRef) { 4105 globalColorSpaceCache.set(null, cs[1], iccCS); 4106 } 4107 return iccCS; 4108 } catch (ex) { 4109 if (ex instanceof MissingDataException) { 4110 throw ex; 4111 } 4112 warn(`ICCBased color space (${cs[1]}): "${ex}".`); 4113 } 4114 } 4115 const altRaw = dict.getRaw("Alternate"); 4116 if (altRaw) { 4117 const altCS = this.#subParse(altRaw, options); 4118 if (altCS.numComps === numComps) { 4119 return altCS; 4120 } 4121 warn("ICCBased color space: Ignoring incorrect /Alternate entry."); 4122 } 4123 if (numComps === 1) { 4124 return this.gray; 4125 } else if (numComps === 3) { 4126 return this.rgb; 4127 } else if (numComps === 4) { 4128 return this.cmyk; 4129 } 4130 break; 4131 case "Pattern": 4132 baseCS = cs[1] || null; 4133 if (baseCS) { 4134 baseCS = this.#subParse(baseCS, options); 4135 } 4136 return new PatternCS(baseCS); 4137 case "I": 4138 case "Indexed": 4139 baseCS = this.#subParse(cs[1], options); 4140 const hiVal = MathClamp(xref.fetchIfRef(cs[2]), 0, 255); 4141 const lookup = xref.fetchIfRef(cs[3]); 4142 return new IndexedCS(baseCS, hiVal, lookup); 4143 case "Separation": 4144 case "DeviceN": 4145 const name = xref.fetchIfRef(cs[1]); 4146 numComps = Array.isArray(name) ? name.length : 1; 4147 baseCS = this.#subParse(cs[2], options); 4148 const tintFn = pdfFunctionFactory.create(cs[3]); 4149 return new AlternateCS(numComps, baseCS, tintFn); 4150 case "Lab": 4151 params = xref.fetchIfRef(cs[1]); 4152 whitePoint = params.getArray("WhitePoint"); 4153 blackPoint = params.getArray("BlackPoint"); 4154 const range = params.getArray("Range"); 4155 return new LabCS(whitePoint, blackPoint, range); 4156 default: 4157 warn(`Unimplemented ColorSpace object: ${mode}`); 4158 return this.gray; 4159 } 4160 } 4161 warn(`Unrecognized ColorSpace object: ${cs}`); 4162 return this.gray; 4163 } 4164 static get gray() { 4165 return shadow(this, "gray", new DeviceGrayCS()); 4166 } 4167 static get rgb() { 4168 return shadow(this, "rgb", new DeviceRgbCS()); 4169 } 4170 static get rgba() { 4171 return shadow(this, "rgba", new DeviceRgbaCS()); 4172 } 4173 static get cmyk() { 4174 if (CmykICCBasedCS.isUsable) { 4175 try { 4176 return shadow(this, "cmyk", new CmykICCBasedCS()); 4177 } catch { 4178 warn("CMYK fallback: DeviceCMYK"); 4179 } 4180 } 4181 return shadow(this, "cmyk", new DeviceCmykCS()); 4182 } 4183} 4184 4185;// ./src/core/jpg.js 4186 4187 4188 4189 4190 4191class JpegError extends BaseException { 4192 constructor(msg) { 4193 super(msg, "JpegError"); 4194 } 4195} 4196class DNLMarkerError extends BaseException { 4197 constructor(message, scanLines) { 4198 super(message, "DNLMarkerError"); 4199 this.scanLines = scanLines; 4200 } 4201} 4202class EOIMarkerError extends BaseException { 4203 constructor(msg) { 4204 super(msg, "EOIMarkerError"); 4205 } 4206} 4207const dctZigZag = new Uint8Array([0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63]); 4208const dctCos1 = 4017; 4209const dctSin1 = 799; 4210const dctCos3 = 3406; 4211const dctSin3 = 2276; 4212const dctCos6 = 1567; 4213const dctSin6 = 3784; 4214const dctSqrt2 = 5793; 4215const dctSqrt1d2 = 2896; 4216function buildHuffmanTable(codeLengths, values) { 4217 let k = 0, 4218 i, 4219 j, 4220 length = 16; 4221 while (length > 0 && !codeLengths[length - 1]) { 4222 length--; 4223 } 4224 const code = [{ 4225 children: [], 4226 index: 0 4227 }]; 4228 let p = code[0], 4229 q; 4230 for (i = 0; i < length; i++) { 4231 for (j = 0; j < codeLengths[i]; j++) { 4232 p = code.pop(); 4233 p.children[p.index] = values[k]; 4234 while (p.index > 0) { 4235 p = code.pop(); 4236 } 4237 p.index++; 4238 code.push(p); 4239 while (code.length <= i) { 4240 code.push(q = { 4241 children: [], 4242 index: 0 4243 }); 4244 p.children[p.index] = q.children; 4245 p = q; 4246 } 4247 k++; 4248 } 4249 if (i + 1 < length) { 4250 code.push(q = { 4251 children: [], 4252 index: 0 4253 }); 4254 p.children[p.index] = q.children; 4255 p = q; 4256 } 4257 } 4258 return code[0].children; 4259} 4260function getBlockBufferOffset(component, row, col) { 4261 return 64 * ((component.blocksPerLine + 1) * row + col); 4262} 4263function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive, parseDNLMarker = false) { 4264 const mcusPerLine = frame.mcusPerLine; 4265 const progressive = frame.progressive; 4266 const startOffset = offset; 4267 let bitsData = 0, 4268 bitsCount = 0; 4269 function readBit() { 4270 if (bitsCount > 0) { 4271 bitsCount--; 4272 return bitsData >> bitsCount & 1; 4273 } 4274 bitsData = data[offset++]; 4275 if (bitsData === 0xff) { 4276 const nextByte = data[offset++]; 4277 if (nextByte) { 4278 if (nextByte === 0xdc && parseDNLMarker) { 4279 offset += 2; 4280 const scanLines = readUint16(data, offset); 4281 offset += 2; 4282 if (scanLines > 0 && scanLines !== frame.scanLines) { 4283 throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data", scanLines); 4284 } 4285 } else if (nextByte === 0xd9) { 4286 if (parseDNLMarker) { 4287 const maybeScanLines = blockRow * (frame.precision === 8 ? 8 : 0); 4288 if (maybeScanLines > 0 && Math.round(frame.scanLines / maybeScanLines) >= 5) { 4289 throw new DNLMarkerError("Found EOI marker (0xFFD9) while parsing scan data, " + "possibly caused by incorrect `scanLines` parameter", maybeScanLines); 4290 } 4291 } 4292 throw new EOIMarkerError("Found EOI marker (0xFFD9) while parsing scan data"); 4293 } 4294 throw new JpegError(`unexpected marker ${(bitsData << 8 | nextByte).toString(16)}`); 4295 } 4296 } 4297 bitsCount = 7; 4298 return bitsData >>> 7; 4299 } 4300 function decodeHuffman(tree) { 4301 let node = tree; 4302 while (true) { 4303 node = node[readBit()]; 4304 switch (typeof node) { 4305 case "number": 4306 return node; 4307 case "object": 4308 continue; 4309 } 4310 throw new JpegError("invalid huffman sequence"); 4311 } 4312 } 4313 function receive(length) { 4314 let n = 0; 4315 while (length > 0) { 4316 n = n << 1 | readBit(); 4317 length--; 4318 } 4319 return n; 4320 } 4321 function receiveAndExtend(length) { 4322 if (length === 1) { 4323 return readBit() === 1 ? 1 : -1; 4324 } 4325 const n = receive(length); 4326 if (n >= 1 << length - 1) { 4327 return n; 4328 } 4329 return n + (-1 << length) + 1; 4330 } 4331 function decodeBaseline(component, blockOffset) { 4332 const t = decodeHuffman(component.huffmanTableDC); 4333 const diff = t === 0 ? 0 : receiveAndExtend(t); 4334 component.blockData[blockOffset] = component.pred += diff; 4335 let k = 1; 4336 while (k < 64) { 4337 const rs = decodeHuffman(component.huffmanTableAC); 4338 const s = rs & 15, 4339 r = rs >> 4; 4340 if (s === 0) { 4341 if (r < 15) { 4342 break; 4343 } 4344 k += 16; 4345 continue; 4346 } 4347 k += r; 4348 const z = dctZigZag[k]; 4349 component.blockData[blockOffset + z] = receiveAndExtend(s); 4350 k++; 4351 } 4352 } 4353 function decodeDCFirst(component, blockOffset) { 4354 const t = decodeHuffman(component.huffmanTableDC); 4355 const diff = t === 0 ? 0 : receiveAndExtend(t) << successive; 4356 component.blockData[blockOffset] = component.pred += diff; 4357 } 4358 function decodeDCSuccessive(component, blockOffset) { 4359 component.blockData[blockOffset] |= readBit() << successive; 4360 } 4361 let eobrun = 0; 4362 function decodeACFirst(component, blockOffset) { 4363 if (eobrun > 0) { 4364 eobrun--; 4365 return; 4366 } 4367 let k = spectralStart; 4368 const e = spectralEnd; 4369 while (k <= e) { 4370 const rs = decodeHuffman(component.huffmanTableAC); 4371 const s = rs & 15, 4372 r = rs >> 4; 4373 if (s === 0) { 4374 if (r < 15) { 4375 eobrun = receive(r) + (1 << r) - 1; 4376 break; 4377 } 4378 k += 16; 4379 continue; 4380 } 4381 k += r; 4382 const z = dctZigZag[k]; 4383 component.blockData[blockOffset + z] = receiveAndExtend(s) * (1 << successive); 4384 k++; 4385 } 4386 } 4387 let successiveACState = 0, 4388 successiveACNextValue; 4389 function decodeACSuccessive(component, blockOffset) { 4390 let k = spectralStart; 4391 const e = spectralEnd; 4392 let r = 0; 4393 let s; 4394 let rs; 4395 while (k <= e) { 4396 const offsetZ = blockOffset + dctZigZag[k]; 4397 const sign = component.blockData[offsetZ] < 0 ? -1 : 1; 4398 switch (successiveACState) { 4399 case 0: 4400 rs = decodeHuffman(component.huffmanTableAC); 4401 s = rs & 15; 4402 r = rs >> 4; 4403 if (s === 0) { 4404 if (r < 15) { 4405 eobrun = receive(r) + (1 << r); 4406 successiveACState = 4; 4407 } else { 4408 r = 16; 4409 successiveACState = 1; 4410 } 4411 } else { 4412 if (s !== 1) { 4413 throw new JpegError("invalid ACn encoding"); 4414 } 4415 successiveACNextValue = receiveAndExtend(s); 4416 successiveACState = r ? 2 : 3; 4417 } 4418 continue; 4419 case 1: 4420 case 2: 4421 if (component.blockData[offsetZ]) { 4422 component.blockData[offsetZ] += sign * (readBit() << successive); 4423 } else { 4424 r--; 4425 if (r === 0) { 4426 successiveACState = successiveACState === 2 ? 3 : 0; 4427 } 4428 } 4429 break; 4430 case 3: 4431 if (component.blockData[offsetZ]) { 4432 component.blockData[offsetZ] += sign * (readBit() << successive); 4433 } else { 4434 component.blockData[offsetZ] = successiveACNextValue << successive; 4435 successiveACState = 0; 4436 } 4437 break; 4438 case 4: 4439 if (component.blockData[offsetZ]) { 4440 component.blockData[offsetZ] += sign * (readBit() << successive); 4441 } 4442 break; 4443 } 4444 k++; 4445 } 4446 if (successiveACState === 4) { 4447 eobrun--; 4448 if (eobrun === 0) { 4449 successiveACState = 0; 4450 } 4451 } 4452 } 4453 let blockRow = 0; 4454 function decodeMcu(component, decode, mcu, row, col) { 4455 const mcuRow = mcu / mcusPerLine | 0; 4456 const mcuCol = mcu % mcusPerLine; 4457 blockRow = mcuRow * component.v + row; 4458 const blockCol = mcuCol * component.h + col; 4459 const blockOffset = getBlockBufferOffset(component, blockRow, blockCol); 4460 decode(component, blockOffset); 4461 } 4462 function decodeBlock(component, decode, mcu) { 4463 blockRow = mcu / component.blocksPerLine | 0; 4464 const blockCol = mcu % component.blocksPerLine; 4465 const blockOffset = getBlockBufferOffset(component, blockRow, blockCol); 4466 decode(component, blockOffset); 4467 } 4468 const componentsLength = components.length; 4469 let component, i, j, k, n; 4470 let decodeFn; 4471 if (progressive) { 4472 if (spectralStart === 0) { 4473 decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive; 4474 } else { 4475 decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive; 4476 } 4477 } else { 4478 decodeFn = decodeBaseline; 4479 } 4480 let mcu = 0, 4481 fileMarker; 4482 const mcuExpected = componentsLength === 1 ? components[0].blocksPerLine * components[0].blocksPerColumn : mcusPerLine * frame.mcusPerColumn; 4483 let h, v; 4484 while (mcu <= mcuExpected) { 4485 const mcuToRead = resetInterval ? Math.min(mcuExpected - mcu, resetInterval) : mcuExpected; 4486 if (mcuToRead > 0) { 4487 for (i = 0; i < componentsLength; i++) { 4488 components[i].pred = 0; 4489 } 4490 eobrun = 0; 4491 if (componentsLength === 1) { 4492 component = components[0]; 4493 for (n = 0; n < mcuToRead; n++) { 4494 decodeBlock(component, decodeFn, mcu); 4495 mcu++; 4496 } 4497 } else { 4498 for (n = 0; n < mcuToRead; n++) { 4499 for (i = 0; i < componentsLength; i++) { 4500 component = components[i]; 4501 h = component.h; 4502 v = component.v; 4503 for (j = 0; j < v; j++) { 4504 for (k = 0; k < h; k++) { 4505 decodeMcu(component, decodeFn, mcu, j, k); 4506 } 4507 } 4508 } 4509 mcu++; 4510 } 4511 } 4512 } 4513 bitsCount = 0; 4514 fileMarker = findNextFileMarker(data, offset); 4515 if (!fileMarker) { 4516 break; 4517 } 4518 if (fileMarker.invalid) { 4519 const partialMsg = mcuToRead > 0 ? "unexpected" : "excessive"; 4520 warn(`decodeScan - ${partialMsg} MCU data, current marker is: ${fileMarker.invalid}`); 4521 offset = fileMarker.offset; 4522 } 4523 if (fileMarker.marker >= 0xffd0 && fileMarker.marker <= 0xffd7) { 4524 offset += 2; 4525 } else { 4526 break; 4527 } 4528 } 4529 return offset - startOffset; 4530} 4531function quantizeAndInverse(component, blockBufferOffset, p) { 4532 const qt = component.quantizationTable, 4533 blockData = component.blockData; 4534 let v0, v1, v2, v3, v4, v5, v6, v7; 4535 let p0, p1, p2, p3, p4, p5, p6, p7; 4536 let t; 4537 if (!qt) { 4538 throw new JpegError("missing required Quantization Table."); 4539 } 4540 for (let row = 0; row < 64; row += 8) { 4541 p0 = blockData[blockBufferOffset + row]; 4542 p1 = blockData[blockBufferOffset + row + 1]; 4543 p2 = blockData[blockBufferOffset + row + 2]; 4544 p3 = blockData[blockBufferOffset + row + 3]; 4545 p4 = blockData[blockBufferOffset + row + 4]; 4546 p5 = blockData[blockBufferOffset + row + 5]; 4547 p6 = blockData[blockBufferOffset + row + 6]; 4548 p7 = blockData[blockBufferOffset + row + 7]; 4549 p0 *= qt[row]; 4550 if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) { 4551 t = dctSqrt2 * p0 + 512 >> 10; 4552 p[row] = t; 4553 p[row + 1] = t; 4554 p[row + 2] = t; 4555 p[row + 3] = t; 4556 p[row + 4] = t; 4557 p[row + 5] = t; 4558 p[row + 6] = t; 4559 p[row + 7] = t; 4560 continue; 4561 } 4562 p1 *= qt[row + 1]; 4563 p2 *= qt[row + 2]; 4564 p3 *= qt[row + 3]; 4565 p4 *= qt[row + 4]; 4566 p5 *= qt[row + 5]; 4567 p6 *= qt[row + 6]; 4568 p7 *= qt[row + 7]; 4569 v0 = dctSqrt2 * p0 + 128 >> 8; 4570 v1 = dctSqrt2 * p4 + 128 >> 8; 4571 v2 = p2; 4572 v3 = p6; 4573 v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8; 4574 v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8; 4575 v5 = p3 << 4; 4576 v6 = p5 << 4; 4577 v0 = v0 + v1 + 1 >> 1; 4578 v1 = v0 - v1; 4579 t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8; 4580 v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8; 4581 v3 = t; 4582 v4 = v4 + v6 + 1 >> 1; 4583 v6 = v4 - v6; 4584 v7 = v7 + v5 + 1 >> 1; 4585 v5 = v7 - v5; 4586 v0 = v0 + v3 + 1 >> 1; 4587 v3 = v0 - v3; 4588 v1 = v1 + v2 + 1 >> 1; 4589 v2 = v1 - v2; 4590 t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12; 4591 v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12; 4592 v7 = t; 4593 t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12; 4594 v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12; 4595 v6 = t; 4596 p[row] = v0 + v7; 4597 p[row + 7] = v0 - v7; 4598 p[row + 1] = v1 + v6; 4599 p[row + 6] = v1 - v6; 4600 p[row + 2] = v2 + v5; 4601 p[row + 5] = v2 - v5; 4602 p[row + 3] = v3 + v4; 4603 p[row + 4] = v3 - v4; 4604 } 4605 for (let col = 0; col < 8; ++col) { 4606 p0 = p[col]; 4607 p1 = p[col + 8]; 4608 p2 = p[col + 16]; 4609 p3 = p[col + 24]; 4610 p4 = p[col + 32]; 4611 p5 = p[col + 40]; 4612 p6 = p[col + 48]; 4613 p7 = p[col + 56]; 4614 if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) { 4615 t = dctSqrt2 * p0 + 8192 >> 14; 4616 if (t < -2040) { 4617 t = 0; 4618 } else if (t >= 2024) { 4619 t = 255; 4620 } else { 4621 t = t + 2056 >> 4; 4622 } 4623 blockData[blockBufferOffset + col] = t; 4624 blockData[blockBufferOffset + col + 8] = t; 4625 blockData[blockBufferOffset + col + 16] = t; 4626 blockData[blockBufferOffset + col + 24] = t; 4627 blockData[blockBufferOffset + col + 32] = t; 4628 blockData[blockBufferOffset + col + 40] = t; 4629 blockData[blockBufferOffset + col + 48] = t; 4630 blockData[blockBufferOffset + col + 56] = t; 4631 continue; 4632 } 4633 v0 = dctSqrt2 * p0 + 2048 >> 12; 4634 v1 = dctSqrt2 * p4 + 2048 >> 12; 4635 v2 = p2; 4636 v3 = p6; 4637 v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12; 4638 v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12; 4639 v5 = p3; 4640 v6 = p5; 4641 v0 = (v0 + v1 + 1 >> 1) + 4112; 4642 v1 = v0 - v1; 4643 t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12; 4644 v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12; 4645 v3 = t; 4646 v4 = v4 + v6 + 1 >> 1; 4647 v6 = v4 - v6; 4648 v7 = v7 + v5 + 1 >> 1; 4649 v5 = v7 - v5; 4650 v0 = v0 + v3 + 1 >> 1; 4651 v3 = v0 - v3; 4652 v1 = v1 + v2 + 1 >> 1; 4653 v2 = v1 - v2; 4654 t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12; 4655 v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12; 4656 v7 = t; 4657 t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12; 4658 v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12; 4659 v6 = t; 4660 p0 = v0 + v7; 4661 p7 = v0 - v7; 4662 p1 = v1 + v6; 4663 p6 = v1 - v6; 4664 p2 = v2 + v5; 4665 p5 = v2 - v5; 4666 p3 = v3 + v4; 4667 p4 = v3 - v4; 4668 if (p0 < 16) { 4669 p0 = 0; 4670 } else if (p0 >= 4080) { 4671 p0 = 255; 4672 } else { 4673 p0 >>= 4; 4674 } 4675 if (p1 < 16) { 4676 p1 = 0; 4677 } else if (p1 >= 4080) { 4678 p1 = 255; 4679 } else { 4680 p1 >>= 4; 4681 } 4682 if (p2 < 16) { 4683 p2 = 0; 4684 } else if (p2 >= 4080) { 4685 p2 = 255; 4686 } else { 4687 p2 >>= 4; 4688 } 4689 if (p3 < 16) { 4690 p3 = 0; 4691 } else if (p3 >= 4080) { 4692 p3 = 255; 4693 } else { 4694 p3 >>= 4; 4695 } 4696 if (p4 < 16) { 4697 p4 = 0; 4698 } else if (p4 >= 4080) { 4699 p4 = 255; 4700 } else { 4701 p4 >>= 4; 4702 } 4703 if (p5 < 16) { 4704 p5 = 0; 4705 } else if (p5 >= 4080) { 4706 p5 = 255; 4707 } else { 4708 p5 >>= 4; 4709 } 4710 if (p6 < 16) { 4711 p6 = 0; 4712 } else if (p6 >= 4080) { 4713 p6 = 255; 4714 } else { 4715 p6 >>= 4; 4716 } 4717 if (p7 < 16) { 4718 p7 = 0; 4719 } else if (p7 >= 4080) { 4720 p7 = 255; 4721 } else { 4722 p7 >>= 4; 4723 } 4724 blockData[blockBufferOffset + col] = p0; 4725 blockData[blockBufferOffset + col + 8] = p1; 4726 blockData[blockBufferOffset + col + 16] = p2; 4727 blockData[blockBufferOffset + col + 24] = p3; 4728 blockData[blockBufferOffset + col + 32] = p4; 4729 blockData[blockBufferOffset + col + 40] = p5; 4730 blockData[blockBufferOffset + col + 48] = p6; 4731 blockData[blockBufferOffset + col + 56] = p7; 4732 } 4733} 4734function buildComponentData(frame, component) { 4735 const blocksPerLine = component.blocksPerLine; 4736 const blocksPerColumn = component.blocksPerColumn; 4737 const computationBuffer = new Int16Array(64); 4738 for (let blockRow = 0; blockRow < blocksPerColumn; blockRow++) { 4739 for (let blockCol = 0; blockCol < blocksPerLine; blockCol++) { 4740 const offset = getBlockBufferOffset(component, blockRow, blockCol); 4741 quantizeAndInverse(component, offset, computationBuffer); 4742 } 4743 } 4744 return component.blockData; 4745} 4746function findNextFileMarker(data, currentPos, startPos = currentPos) { 4747 const maxPos = data.length - 1; 4748 let newPos = startPos < currentPos ? startPos : currentPos; 4749 if (currentPos >= maxPos) { 4750 return null; 4751 } 4752 const currentMarker = readUint16(data, currentPos); 4753 if (currentMarker >= 0xffc0 && currentMarker <= 0xfffe) { 4754 return { 4755 invalid: null, 4756 marker: currentMarker, 4757 offset: currentPos 4758 }; 4759 } 4760 let newMarker = readUint16(data, newPos); 4761 while (!(newMarker >= 0xffc0 && newMarker <= 0xfffe)) { 4762 if (++newPos >= maxPos) { 4763 return null; 4764 } 4765 newMarker = readUint16(data, newPos); 4766 } 4767 return { 4768 invalid: currentMarker.toString(16), 4769 marker: newMarker, 4770 offset: newPos 4771 }; 4772} 4773function prepareComponents(frame) { 4774 const mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH); 4775 const mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV); 4776 for (const component of frame.components) { 4777 const blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH); 4778 const blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV); 4779 const blocksPerLineForMcu = mcusPerLine * component.h; 4780 const blocksPerColumnForMcu = mcusPerColumn * component.v; 4781 const blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1); 4782 component.blockData = new Int16Array(blocksBufferSize); 4783 component.blocksPerLine = blocksPerLine; 4784 component.blocksPerColumn = blocksPerColumn; 4785 } 4786 frame.mcusPerLine = mcusPerLine; 4787 frame.mcusPerColumn = mcusPerColumn; 4788} 4789function readDataBlock(data, offset) { 4790 const length = readUint16(data, offset); 4791 offset += 2; 4792 let endOffset = offset + length - 2; 4793 const fileMarker = findNextFileMarker(data, endOffset, offset); 4794 if (fileMarker?.invalid) { 4795 warn("readDataBlock - incorrect length, current marker is: " + fileMarker.invalid); 4796 endOffset = fileMarker.offset; 4797 } 4798 const array = data.subarray(offset, endOffset); 4799 return { 4800 appData: array, 4801 oldOffset: offset, 4802 newOffset: offset + array.length 4803 }; 4804} 4805function skipData(data, offset) { 4806 const length = readUint16(data, offset); 4807 offset += 2; 4808 const endOffset = offset + length - 2; 4809 const fileMarker = findNextFileMarker(data, endOffset, offset); 4810 if (fileMarker?.invalid) { 4811 return fileMarker.offset; 4812 } 4813 return endOffset; 4814} 4815class JpegImage { 4816 constructor({ 4817 decodeTransform = null, 4818 colorTransform = -1 4819 } = {}) { 4820 this._decodeTransform = decodeTransform; 4821 this._colorTransform = colorTransform; 4822 } 4823 static canUseImageDecoder(data, colorTransform = -1) { 4824 let exifOffsets = null; 4825 let offset = 0; 4826 let numComponents = null; 4827 let fileMarker = readUint16(data, offset); 4828 offset += 2; 4829 if (fileMarker !== 0xffd8) { 4830 throw new JpegError("SOI not found"); 4831 } 4832 fileMarker = readUint16(data, offset); 4833 offset += 2; 4834 markerLoop: while (fileMarker !== 0xffd9) { 4835 switch (fileMarker) { 4836 case 0xffe1: 4837 const { 4838 appData, 4839 oldOffset, 4840 newOffset 4841 } = readDataBlock(data, offset); 4842 offset = newOffset; 4843 if (appData[0] === 0x45 && appData[1] === 0x78 && appData[2] === 0x69 && appData[3] === 0x66 && appData[4] === 0 && appData[5] === 0) { 4844 if (exifOffsets) { 4845 throw new JpegError("Duplicate EXIF-blocks found."); 4846 } 4847 exifOffsets = { 4848 exifStart: oldOffset + 6, 4849 exifEnd: newOffset 4850 }; 4851 } 4852 fileMarker = readUint16(data, offset); 4853 offset += 2; 4854 continue; 4855 case 0xffc0: 4856 case 0xffc1: 4857 case 0xffc2: 4858 numComponents = data[offset + (2 + 1 + 2 + 2)]; 4859 break markerLoop; 4860 case 0xffff: 4861 if (data[offset] !== 0xff) { 4862 offset--; 4863 } 4864 break; 4865 } 4866 offset = skipData(data, offset); 4867 fileMarker = readUint16(data, offset); 4868 offset += 2; 4869 } 4870 if (numComponents === 4) { 4871 return null; 4872 } 4873 if (numComponents === 3 && colorTransform === 0) { 4874 return null; 4875 } 4876 return exifOffsets || {}; 4877 } 4878 parse(data, { 4879 dnlScanLines = null 4880 } = {}) { 4881 let offset = 0; 4882 let jfif = null; 4883 let adobe = null; 4884 let frame, resetInterval; 4885 let numSOSMarkers = 0; 4886 const quantizationTables = []; 4887 const huffmanTablesAC = [], 4888 huffmanTablesDC = []; 4889 let fileMarker = readUint16(data, offset); 4890 offset += 2; 4891 if (fileMarker !== 0xffd8) { 4892 throw new JpegError("SOI not found"); 4893 } 4894 fileMarker = readUint16(data, offset); 4895 offset += 2; 4896 markerLoop: while (fileMarker !== 0xffd9) { 4897 let i, j, l; 4898 switch (fileMarker) { 4899 case 0xffe0: 4900 case 0xffe1: 4901 case 0xffe2: 4902 case 0xffe3: 4903 case 0xffe4: 4904 case 0xffe5: 4905 case 0xffe6: 4906 case 0xffe7: 4907 case 0xffe8: 4908 case 0xffe9: 4909 case 0xffea: 4910 case 0xffeb: 4911 case 0xffec: 4912 case 0xffed: 4913 case 0xffee: 4914 case 0xffef: 4915 case 0xfffe: 4916 const { 4917 appData, 4918 newOffset 4919 } = readDataBlock(data, offset); 4920 offset = newOffset; 4921 if (fileMarker === 0xffe0) { 4922 if (appData[0] === 0x4a && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) { 4923 jfif = { 4924 version: { 4925 major: appData[5], 4926 minor: appData[6] 4927 }, 4928 densityUnits: appData[7], 4929 xDensity: appData[8] << 8 | appData[9], 4930 yDensity: appData[10] << 8 | appData[11], 4931 thumbWidth: appData[12], 4932 thumbHeight: appData[13], 4933 thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13]) 4934 }; 4935 } 4936 } 4937 if (fileMarker === 0xffee) { 4938 if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6f && appData[3] === 0x62 && appData[4] === 0x65) { 4939 adobe = { 4940 version: appData[5] << 8 | appData[6], 4941 flags0: appData[7] << 8 | appData[8], 4942 flags1: appData[9] << 8 | appData[10], 4943 transformCode: appData[11] 4944 }; 4945 } 4946 } 4947 break; 4948 case 0xffdb: 4949 const quantizationTablesLength = readUint16(data, offset); 4950 offset += 2; 4951 const quantizationTablesEnd = quantizationTablesLength + offset - 2; 4952 let z; 4953 while (offset < quantizationTablesEnd) { 4954 const quantizationTableSpec = data[offset++]; 4955 const tableData = new Uint16Array(64); 4956 if (quantizationTableSpec >> 4 === 0) { 4957 for (j = 0; j < 64; j++) { 4958 z = dctZigZag[j]; 4959 tableData[z] = data[offset++]; 4960 } 4961 } else if (quantizationTableSpec >> 4 === 1) { 4962 for (j = 0; j < 64; j++) { 4963 z = dctZigZag[j]; 4964 tableData[z] = readUint16(data, offset); 4965 offset += 2; 4966 } 4967 } else { 4968 throw new JpegError("DQT - invalid table spec"); 4969 } 4970 quantizationTables[quantizationTableSpec & 15] = tableData; 4971 } 4972 break; 4973 case 0xffc0: 4974 case 0xffc1: 4975 case 0xffc2: 4976 if (frame) { 4977 throw new JpegError("Only single frame JPEGs supported"); 4978 } 4979 offset += 2; 4980 frame = {}; 4981 frame.extended = fileMarker === 0xffc1; 4982 frame.progressive = fileMarker === 0xffc2; 4983 frame.precision = data[offset++]; 4984 const sofScanLines = readUint16(data, offset); 4985 offset += 2; 4986 frame.scanLines = dnlScanLines || sofScanLines; 4987 frame.samplesPerLine = readUint16(data, offset); 4988 offset += 2; 4989 frame.components = []; 4990 frame.componentIds = {}; 4991 const componentsCount = data[offset++]; 4992 let maxH = 0, 4993 maxV = 0; 4994 for (i = 0; i < componentsCount; i++) { 4995 const componentId = data[offset]; 4996 const h = data[offset + 1] >> 4; 4997 const v = data[offset + 1] & 15; 4998 if (maxH < h) { 4999 maxH = h; 5000 } 5001 if (maxV < v) { 5002 maxV = v; 5003 } 5004 const qId = data[offset + 2]; 5005 l = frame.components.push({ 5006 h, 5007 v, 5008 quantizationId: qId, 5009 quantizationTable: null 5010 }); 5011 frame.componentIds[componentId] = l - 1; 5012 offset += 3; 5013 } 5014 frame.maxH = maxH; 5015 frame.maxV = maxV; 5016 prepareComponents(frame); 5017 break; 5018 case 0xffc4: 5019 const huffmanLength = readUint16(data, offset); 5020 offset += 2; 5021 for (i = 2; i < huffmanLength;) { 5022 const huffmanTableSpec = data[offset++]; 5023 const codeLengths = new Uint8Array(16); 5024 let codeLengthSum = 0; 5025 for (j = 0; j < 16; j++, offset++) { 5026 codeLengthSum += codeLengths[j] = data[offset]; 5027 } 5028 const huffmanValues = new Uint8Array(codeLengthSum); 5029 for (j = 0; j < codeLengthSum; j++, offset++) { 5030 huffmanValues[j] = data[offset]; 5031 } 5032 i += 17 + codeLengthSum; 5033 (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues); 5034 } 5035 break; 5036 case 0xffdd: 5037 offset += 2; 5038 resetInterval = readUint16(data, offset); 5039 offset += 2; 5040 break; 5041 case 0xffda: 5042 const parseDNLMarker = ++numSOSMarkers === 1 && !dnlScanLines; 5043 offset += 2; 5044 const selectorsCount = data[offset++], 5045 components = []; 5046 for (i = 0; i < selectorsCount; i++) { 5047 const index = data[offset++]; 5048 const componentIndex = frame.componentIds[index]; 5049 const component = frame.components[componentIndex]; 5050 component.index = index; 5051 const tableSpec = data[offset++]; 5052 component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4]; 5053 component.huffmanTableAC = huffmanTablesAC[tableSpec & 15]; 5054 components.push(component); 5055 } 5056 const spectralStart = data[offset++], 5057 spectralEnd = data[offset++], 5058 successiveApproximation = data[offset++]; 5059 try { 5060 const processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15, parseDNLMarker); 5061 offset += processed; 5062 } catch (ex) { 5063 if (ex instanceof DNLMarkerError) { 5064 warn(`${ex.message} -- attempting to re-parse the JPEG image.`); 5065 return this.parse(data, { 5066 dnlScanLines: ex.scanLines 5067 }); 5068 } else if (ex instanceof EOIMarkerError) { 5069 warn(`${ex.message} -- ignoring the rest of the image data.`); 5070 break markerLoop; 5071 } 5072 throw ex; 5073 } 5074 break; 5075 case 0xffdc: 5076 offset += 4; 5077 break; 5078 case 0xffff: 5079 if (data[offset] !== 0xff) { 5080 offset--; 5081 } 5082 break; 5083 default: 5084 const nextFileMarker = findNextFileMarker(data, offset - 2, offset - 3); 5085 if (nextFileMarker?.invalid) { 5086 warn("JpegImage.parse - unexpected data, current marker is: " + nextFileMarker.invalid); 5087 offset = nextFileMarker.offset; 5088 break; 5089 } 5090 if (!nextFileMarker || offset >= data.length - 1) { 5091 warn("JpegImage.parse - reached the end of the image data " + "without finding an EOI marker (0xFFD9)."); 5092 break markerLoop; 5093 } 5094 throw new JpegError("JpegImage.parse - unknown marker: " + fileMarker.toString(16)); 5095 } 5096 fileMarker = readUint16(data, offset); 5097 offset += 2; 5098 } 5099 if (!frame) { 5100 throw new JpegError("JpegImage.parse - no frame data found."); 5101 } 5102 this.width = frame.samplesPerLine; 5103 this.height = frame.scanLines; 5104 this.jfif = jfif; 5105 this.adobe = adobe; 5106 this.components = []; 5107 for (const component of frame.components) { 5108 const quantizationTable = quantizationTables[component.quantizationId]; 5109 if (quantizationTable) { 5110 component.quantizationTable = quantizationTable; 5111 } 5112 this.components.push({ 5113 index: component.index, 5114 output: buildComponentData(frame, component), 5115 scaleX: component.h / frame.maxH, 5116 scaleY: component.v / frame.maxV, 5117 blocksPerLine: component.blocksPerLine, 5118 blocksPerColumn: component.blocksPerColumn 5119 }); 5120 } 5121 this.numComponents = this.components.length; 5122 return undefined; 5123 } 5124 _getLinearizedBlockData(width, height, isSourcePDF = false) { 5125 const scaleX = this.width / width, 5126 scaleY = this.height / height; 5127 let component, componentScaleX, componentScaleY, blocksPerScanline; 5128 let x, y, i, j, k; 5129 let index; 5130 let offset = 0; 5131 let output; 5132 const numComponents = this.components.length; 5133 const dataLength = width * height * numComponents; 5134 const data = new Uint8ClampedArray(dataLength); 5135 const xScaleBlockOffset = new Uint32Array(width); 5136 const mask3LSB = 0xfffffff8; 5137 let lastComponentScaleX; 5138 for (i = 0; i < numComponents; i++) { 5139 component = this.components[i]; 5140 componentScaleX = component.scaleX * scaleX; 5141 componentScaleY = component.scaleY * scaleY; 5142 offset = i; 5143 output = component.output; 5144 blocksPerScanline = component.blocksPerLine + 1 << 3; 5145 if (componentScaleX !== lastComponentScaleX) { 5146 for (x = 0; x < width; x++) { 5147 j = 0 | x * componentScaleX; 5148 xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7; 5149 } 5150 lastComponentScaleX = componentScaleX; 5151 } 5152 for (y = 0; y < height; y++) { 5153 j = 0 | y * componentScaleY; 5154 index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3; 5155 for (x = 0; x < width; x++) { 5156 data[offset] = output[index + xScaleBlockOffset[x]]; 5157 offset += numComponents; 5158 } 5159 } 5160 } 5161 let transform = this._decodeTransform; 5162 if (!isSourcePDF && numComponents === 4 && !transform) { 5163 transform = new Int32Array([-256, 255, -256, 255, -256, 255, -256, 255]); 5164 } 5165 if (transform) { 5166 for (i = 0; i < dataLength;) { 5167 for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) { 5168 data[i] = (data[i] * transform[k] >> 8) + transform[k + 1]; 5169 } 5170 } 5171 } 5172 return data; 5173 } 5174 get _isColorConversionNeeded() { 5175 if (this.adobe) { 5176 return !!this.adobe.transformCode; 5177 } 5178 if (this.numComponents === 3) { 5179 if (this._colorTransform === 0) { 5180 return false; 5181 } else if (this.components[0].index === 0x52 && this.components[1].index === 0x47 && this.components[2].index === 0x42) { 5182 return false; 5183 } 5184 return true; 5185 } 5186 if (this._colorTransform === 1) { 5187 return true; 5188 } 5189 return false; 5190 } 5191 _convertYccToRgb(data) { 5192 let Y, Cb, Cr; 5193 for (let i = 0, length = data.length; i < length; i += 3) { 5194 Y = data[i]; 5195 Cb = data[i + 1]; 5196 Cr = data[i + 2]; 5197 data[i] = Y - 179.456 + 1.402 * Cr; 5198 data[i + 1] = Y + 135.459 - 0.344 * Cb - 0.714 * Cr; 5199 data[i + 2] = Y - 226.816 + 1.772 * Cb; 5200 } 5201 return data; 5202 } 5203 _convertYccToRgba(data, out) { 5204 for (let i = 0, j = 0, length = data.length; i < length; i += 3, j += 4) { 5205 const Y = data[i]; 5206 const Cb = data[i + 1]; 5207 const Cr = data[i + 2]; 5208 out[j] = Y - 179.456 + 1.402 * Cr; 5209 out[j + 1] = Y + 135.459 - 0.344 * Cb - 0.714 * Cr; 5210 out[j + 2] = Y - 226.816 + 1.772 * Cb; 5211 out[j + 3] = 255; 5212 } 5213 return out; 5214 } 5215 _convertYcckToRgb(data) { 5216 this._convertYcckToCmyk(data); 5217 return this._convertCmykToRgb(data); 5218 } 5219 _convertYcckToRgba(data) { 5220 this._convertYcckToCmyk(data); 5221 return this._convertCmykToRgba(data); 5222 } 5223 _convertYcckToCmyk(data) { 5224 let Y, Cb, Cr; 5225 for (let i = 0, length = data.length; i < length; i += 4) { 5226 Y = data[i]; 5227 Cb = data[i + 1]; 5228 Cr = data[i + 2]; 5229 data[i] = 434.456 - Y - 1.402 * Cr; 5230 data[i + 1] = 119.541 - Y + 0.344 * Cb + 0.714 * Cr; 5231 data[i + 2] = 481.816 - Y - 1.772 * Cb; 5232 } 5233 return data; 5234 } 5235 _convertCmykToRgb(data) { 5236 const count = data.length / 4; 5237 ColorSpaceUtils.cmyk.getRgbBuffer(data, 0, count, data, 0, 8, 0); 5238 return data.subarray(0, count * 3); 5239 } 5240 _convertCmykToRgba(data) { 5241 ColorSpaceUtils.cmyk.getRgbBuffer(data, 0, data.length / 4, data, 0, 8, 1); 5242 if (ColorSpaceUtils.cmyk instanceof DeviceCmykCS) { 5243 for (let i = 3, ii = data.length; i < ii; i += 4) { 5244 data[i] = 255; 5245 } 5246 } 5247 return data; 5248 } 5249 getData({ 5250 width, 5251 height, 5252 forceRGBA = false, 5253 forceRGB = false, 5254 isSourcePDF = false 5255 }) { 5256 if (this.numComponents > 4) { 5257 throw new JpegError("Unsupported color mode"); 5258 } 5259 const data = this._getLinearizedBlockData(width, height, isSourcePDF); 5260 if (this.numComponents === 1 && (forceRGBA || forceRGB)) { 5261 const len = data.length * (forceRGBA ? 4 : 3); 5262 const rgbaData = new Uint8ClampedArray(len); 5263 let offset = 0; 5264 if (forceRGBA) { 5265 grayToRGBA(data, new Uint32Array(rgbaData.buffer)); 5266 } else { 5267 for (const grayColor of data) { 5268 rgbaData[offset++] = grayColor; 5269 rgbaData[offset++] = grayColor; 5270 rgbaData[offset++] = grayColor; 5271 } 5272 } 5273 return rgbaData; 5274 } else if (this.numComponents === 3 && this._isColorConversionNeeded) { 5275 if (forceRGBA) { 5276 const rgbaData = new Uint8ClampedArray(data.length / 3 * 4); 5277 return this._convertYccToRgba(data, rgbaData); 5278 } 5279 return this._convertYccToRgb(data); 5280 } else if (this.numComponents === 4) { 5281 if (this._isColorConversionNeeded) { 5282 if (forceRGBA) { 5283 return this._convertYcckToRgba(data); 5284 } 5285 if (forceRGB) { 5286 return this._convertYcckToRgb(data); 5287 } 5288 return this._convertYcckToCmyk(data); 5289 } else if (forceRGBA) { 5290 return this._convertCmykToRgba(data); 5291 } else if (forceRGB) { 5292 return this._convertCmykToRgb(data); 5293 } 5294 } 5295 return data; 5296 } 5297} 5298 5299;// ./src/core/jpeg_stream.js 5300 5301 5302 5303
vendor: 3,919 bytes, lines 5304-5430
5304class JpegStream extends DecodeStream { 5305 static #isImageDecoderSupported = FeatureTest.isImageDecoderSupported; 5306 constructor(stream, maybeLength, params) { 5307 super(maybeLength); 5308 this.stream = stream; 5309 this.dict = stream.dict; 5310 this.maybeLength = maybeLength; 5311 this.params = params; 5312 } 5313 static get canUseImageDecoder() { 5314 return shadow(this, "canUseImageDecoder", this.#isImageDecoderSupported ? ImageDecoder.isTypeSupported("image/jpeg") : Promise.resolve(false)); 5315 } 5316 static setOptions({ 5317 isImageDecoderSupported = false 5318 }) { 5319 this.#isImageDecoderSupported = isImageDecoderSupported; 5320 } 5321 get bytes() { 5322 return shadow(this, "bytes", this.stream.getBytes(this.maybeLength)); 5323 } 5324 ensureBuffer(requested) {} 5325 readBlock() { 5326 this.decodeImage(); 5327 } 5328 get jpegOptions() { 5329 const jpegOptions = { 5330 decodeTransform: undefined, 5331 colorTransform: undefined 5332 }; 5333 const decodeArr = this.dict.getArray("D", "Decode"); 5334 if ((this.forceRGBA || this.forceRGB) && Array.isArray(decodeArr)) { 5335 const bitsPerComponent = this.dict.get("BPC", "BitsPerComponent") || 8; 5336 const decodeArrLength = decodeArr.length; 5337 const transform = new Int32Array(decodeArrLength); 5338 let transformNeeded = false; 5339 const maxValue = (1 << bitsPerComponent) - 1; 5340 for (let i = 0; i < decodeArrLength; i += 2) { 5341 transform[i] = (decodeArr[i + 1] - decodeArr[i]) * 256 | 0; 5342 transform[i + 1] = decodeArr[i] * maxValue | 0; 5343 if (transform[i] !== 256 || transform[i + 1] !== 0) { 5344 transformNeeded = true; 5345 } 5346 } 5347 if (transformNeeded) { 5348 jpegOptions.decodeTransform = transform; 5349 } 5350 } 5351 if (this.params instanceof Dict) { 5352 const colorTransform = this.params.get("ColorTransform"); 5353 if (Number.isInteger(colorTransform)) { 5354 jpegOptions.colorTransform = colorTransform; 5355 } 5356 } 5357 return shadow(this, "jpegOptions", jpegOptions); 5358 } 5359 #skipUselessBytes(data) { 5360 for (let i = 0, ii = data.length - 1; i < ii; i++) { 5361 if (data[i] === 0xff && data[i + 1] === 0xd8) { 5362 if (i > 0) { 5363 data = data.subarray(i); 5364 } 5365 break; 5366 } 5367 } 5368 return data; 5369 } 5370 decodeImage(bytes) { 5371 if (this.eof) { 5372 return this.buffer; 5373 } 5374 bytes = this.#skipUselessBytes(bytes || this.bytes); 5375 const jpegImage = new JpegImage(this.jpegOptions); 5376 jpegImage.parse(bytes); 5377 const data = jpegImage.getData({ 5378 width: this.drawWidth, 5379 height: this.drawHeight, 5380 forceRGBA: this.forceRGBA, 5381 forceRGB: this.forceRGB, 5382 isSourcePDF: true 5383 }); 5384 this.buffer = data; 5385 this.bufferLength = data.length; 5386 this.eof = true; 5387 return this.buffer; 5388 } 5389 get canAsyncDecodeImageFromBuffer() { 5390 return this.stream.isAsync; 5391 } 5392 async getTransferableImage() { 5393 if (!(await JpegStream.canUseImageDecoder)) { 5394 return null; 5395 } 5396 const jpegOptions = this.jpegOptions; 5397 if (jpegOptions.decodeTransform) { 5398 return null; 5399 } 5400 let decoder; 5401 try { 5402 const bytes = this.canAsyncDecodeImageFromBuffer && (await this.stream.asyncGetBytes()) || this.bytes; 5403 if (!bytes) { 5404 return null; 5405 } 5406 let data = this.#skipUselessBytes(bytes); 5407 const useImageDecoder = JpegImage.canUseImageDecoder(data, jpegOptions.colorTransform); 5408 if (!useImageDecoder) { 5409 return null; 5410 } 5411 if (useImageDecoder.exifStart) { 5412 data = data.slice(); 5413 data.fill(0x00, useImageDecoder.exifStart, useImageDecoder.exifEnd); 5414 } 5415 decoder = new ImageDecoder({ 5416 data, 5417 type: "image/jpeg", 5418 preferAnimation: false 5419 }); 5420 return (await decoder.decode()).image; 5421 } catch (reason) { 5422 warn(`getTransferableImage - failed: "${reason}".`); 5423 return null; 5424 } finally { 5425 decoder?.close(); 5426 } 5427 } 5428} 5429 5430;// ./external/openjpeg/openjpeg.js
vendor: 16,954 bytes, lines 5430-5973
5430 5431async function OpenJPEG(moduleArg = {}) { 5432 var moduleRtn; 5433 var Module = moduleArg; 5434 var ENVIRONMENT_IS_WEB = true; 5435 var ENVIRONMENT_IS_WORKER = false; 5436 var arguments_ = []; 5437 var thisProgram = "./this.program"; 5438 var quit_ = (status, toThrow) => { 5439 throw toThrow; 5440 }; 5441 var _scriptName = import.meta.url; 5442 var scriptDirectory = ""; 5443 var readAsync, readBinary; 5444 if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { 5445 try { 5446 scriptDirectory = new URL(".", _scriptName).href; 5447 } catch {} 5448 readAsync = async url => { 5449 var response = await fetch(url, { 5450 credentials: "same-origin" 5451 }); 5452 if (response.ok) { 5453 return response.arrayBuffer(); 5454 } 5455 throw new Error(response.status + " : " + response.url); 5456 }; 5457 } else {} 5458 var out = console.log.bind(console); 5459 var err = console.error.bind(console); 5460 var wasmBinary; 5461 var ABORT = false; 5462 var EXITSTATUS; 5463 var readyPromiseResolve, readyPromiseReject; 5464 var wasmMemory; 5465 var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64; 5466 var HEAP64, HEAPU64; 5467 var runtimeInitialized = false; 5468 function updateMemoryViews() { 5469 var b = wasmMemory.buffer; 5470 HEAP8 = new Int8Array(b); 5471 HEAP16 = new Int16Array(b); 5472 HEAPU8 = new Uint8Array(b); 5473 HEAPU16 = new Uint16Array(b); 5474 HEAP32 = new Int32Array(b); 5475 HEAPU32 = new Uint32Array(b); 5476 HEAPF32 = new Float32Array(b); 5477 HEAPF64 = new Float64Array(b); 5478 HEAP64 = new BigInt64Array(b); 5479 HEAPU64 = new BigUint64Array(b); 5480 } 5481 function preRun() { 5482 if (Module["preRun"]) { 5483 if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]]; 5484 while (Module["preRun"].length) { 5485 addOnPreRun(Module["preRun"].shift()); 5486 } 5487 } 5488 callRuntimeCallbacks(onPreRuns); 5489 } 5490 function initRuntime() { 5491 runtimeInitialized = true; 5492 wasmExports["s"](); 5493 } 5494 function postRun() { 5495 if (Module["postRun"]) { 5496 if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]]; 5497 while (Module["postRun"].length) { 5498 addOnPostRun(Module["postRun"].shift()); 5499 } 5500 } 5501 callRuntimeCallbacks(onPostRuns); 5502 } 5503 function abort(what) { 5504 Module["onAbort"]?.(what); 5505 what = "Aborted(" + what + ")"; 5506 err(what); 5507 ABORT = true; 5508 what += ". Build with -sASSERTIONS for more info."; 5509 var e = new WebAssembly.RuntimeError(what); 5510 readyPromiseReject?.(e); 5511 throw e; 5512 } 5513 var wasmBinaryFile; 5514 function getWasmImports() { 5515 return { 5516 a: wasmImports 5517 }; 5518 } 5519 async function createWasm() { 5520 function receiveInstance(instance, module) { 5521 wasmExports = instance.exports; 5522 wasmMemory = wasmExports["r"]; 5523 updateMemoryViews(); 5524 assignWasmExports(wasmExports); 5525 return wasmExports; 5526 } 5527 var info = getWasmImports(); 5528 return new Promise((resolve, reject) => { 5529 Module["instantiateWasm"](info, (mod, inst) => { 5530 resolve(receiveInstance(mod, inst)); 5531 }); 5532 }); 5533 } 5534 class ExitStatus { 5535 name = "ExitStatus"; 5536 constructor(status) { 5537 this.message = `Program terminated with exit(${status})`; 5538 this.status = status; 5539 } 5540 } 5541 var callRuntimeCallbacks = callbacks => { 5542 while (callbacks.length > 0) { 5543 callbacks.shift()(Module); 5544 } 5545 }; 5546 var onPostRuns = []; 5547 var addOnPostRun = cb => onPostRuns.push(cb); 5548 var onPreRuns = []; 5549 var addOnPreRun = cb => onPreRuns.push(cb); 5550 var noExitRuntime = true; 5551 var __abort_js = () => abort(""); 5552 var runtimeKeepaliveCounter = 0; 5553 var __emscripten_runtime_keepalive_clear = () => { 5554 noExitRuntime = false; 5555 runtimeKeepaliveCounter = 0; 5556 }; 5557 var timers = {}; 5558 var handleException = e => { 5559 if (e instanceof ExitStatus || e == "unwind") { 5560 return EXITSTATUS; 5561 } 5562 quit_(1, e); 5563 }; 5564 var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0; 5565 var _proc_exit = code => { 5566 EXITSTATUS = code; 5567 if (!keepRuntimeAlive()) { 5568 Module["onExit"]?.(code); 5569 ABORT = true; 5570 } 5571 quit_(code, new ExitStatus(code)); 5572 }; 5573 var exitJS = (status, implicit) => { 5574 EXITSTATUS = status; 5575 _proc_exit(status); 5576 }; 5577 var _exit = exitJS; 5578 var maybeExit = () => { 5579 if (!keepRuntimeAlive()) { 5580 try { 5581 _exit(EXITSTATUS); 5582 } catch (e) { 5583 handleException(e); 5584 } 5585 } 5586 }; 5587 var callUserCallback = func => { 5588 if (ABORT) { 5589 return; 5590 } 5591 try { 5592 func(); 5593 maybeExit(); 5594 } catch (e) { 5595 handleException(e); 5596 } 5597 }; 5598 var _emscripten_get_now = () => performance.now(); 5599 var __setitimer_js = (which, timeout_ms) => { 5600 if (timers[which]) { 5601 clearTimeout(timers[which].id); 5602 delete timers[which]; 5603 } 5604 if (!timeout_ms) return 0; 5605 var id = setTimeout(() => { 5606 delete timers[which]; 5607 callUserCallback(() => __emscripten_timeout(which, _emscripten_get_now())); 5608 }, timeout_ms); 5609 timers[which] = { 5610 id, 5611 timeout_ms 5612 }; 5613 return 0; 5614 }; 5615 function _copy_pixels_1(compG_ptr, nb_pixels) { 5616 compG_ptr >>= 2; 5617 const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels); 5618 const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels); 5619 imageData.set(compG); 5620 } 5621 function _copy_pixels_3(compR_ptr, compG_ptr, compB_ptr, nb_pixels) { 5622 compR_ptr >>= 2; 5623 compG_ptr >>= 2; 5624 compB_ptr >>= 2; 5625 const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels * 3); 5626 const compR = HEAP32.subarray(compR_ptr, compR_ptr + nb_pixels); 5627 const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels); 5628 const compB = HEAP32.subarray(compB_ptr, compB_ptr + nb_pixels); 5629 for (let i = 0; i < nb_pixels; i++) { 5630 imageData[3 * i] = compR[i]; 5631 imageData[3 * i + 1] = compG[i]; 5632 imageData[3 * i + 2] = compB[i]; 5633 } 5634 } 5635 function _copy_pixels_4(compR_ptr, compG_ptr, compB_ptr, compA_ptr, nb_pixels) { 5636 compR_ptr >>= 2; 5637 compG_ptr >>= 2; 5638 compB_ptr >>= 2; 5639 compA_ptr >>= 2; 5640 const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels * 4); 5641 const compR = HEAP32.subarray(compR_ptr, compR_ptr + nb_pixels); 5642 const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels); 5643 const compB = HEAP32.subarray(compB_ptr, compB_ptr + nb_pixels); 5644 const compA = HEAP32.subarray(compA_ptr, compA_ptr + nb_pixels); 5645 for (let i = 0; i < nb_pixels; i++) { 5646 imageData[4 * i] = compR[i]; 5647 imageData[4 * i + 1] = compG[i]; 5648 imageData[4 * i + 2] = compB[i]; 5649 imageData[4 * i + 3] = compA[i]; 5650 } 5651 } 5652 var getHeapMax = () => 2147483648; 5653 var alignMemory = (size, alignment) => Math.ceil(size / alignment) * alignment; 5654 var growMemory = size => { 5655 var oldHeapSize = wasmMemory.buffer.byteLength; 5656 var pages = (size - oldHeapSize + 65535) / 65536 | 0; 5657 try { 5658 wasmMemory.grow(pages); 5659 updateMemoryViews(); 5660 return 1; 5661 } catch (e) {} 5662 }; 5663 var _emscripten_resize_heap = requestedSize => { 5664 var oldSize = HEAPU8.length; 5665 requestedSize >>>= 0; 5666 var maxHeapSize = getHeapMax(); 5667 if (requestedSize > maxHeapSize) { 5668 return false; 5669 } 5670 for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { 5671 var overGrownHeapSize = oldSize * (1 + .2 / cutDown); 5672 overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296); 5673 var newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536)); 5674 var replacement = growMemory(newSize); 5675 if (replacement) { 5676 return true; 5677 } 5678 } 5679 return false; 5680 }; 5681 var ENV = {}; 5682 var getExecutableName = () => thisProgram || "./this.program"; 5683 var getEnvStrings = () => { 5684 if (!getEnvStrings.strings) { 5685 var lang = (typeof navigator == "object" && navigator.language || "C").replace("-", "_") + ".UTF-8"; 5686 var env = { 5687 USER: "web_user", 5688 LOGNAME: "web_user", 5689 PATH: "/", 5690 PWD: "/", 5691 HOME: "/home/web_user", 5692 LANG: lang, 5693 _: getExecutableName() 5694 }; 5695 for (var x in ENV) { 5696 if (ENV[x] === undefined) delete env[x];else env[x] = ENV[x]; 5697 } 5698 var strings = []; 5699 for (var x in env) { 5700 strings.push(`${x}=${env[x]}`); 5701 } 5702 getEnvStrings.strings = strings; 5703 } 5704 return getEnvStrings.strings; 5705 }; 5706 var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => { 5707 if (!(maxBytesToWrite > 0)) return 0; 5708 var startIdx = outIdx; 5709 var endIdx = outIdx + maxBytesToWrite - 1; 5710 for (var i = 0; i < str.length; ++i) { 5711 var u = str.codePointAt(i); 5712 if (u <= 127) { 5713 if (outIdx >= endIdx) break; 5714 heap[outIdx++] = u; 5715 } else if (u <= 2047) { 5716 if (outIdx + 1 >= endIdx) break; 5717 heap[outIdx++] = 192 | u >> 6; 5718 heap[outIdx++] = 128 | u & 63; 5719 } else if (u <= 65535) { 5720 if (outIdx + 2 >= endIdx) break; 5721 heap[outIdx++] = 224 | u >> 12; 5722 heap[outIdx++] = 128 | u >> 6 & 63; 5723 heap[outIdx++] = 128 | u & 63; 5724 } else { 5725 if (outIdx + 3 >= endIdx) break; 5726 heap[outIdx++] = 240 | u >> 18; 5727 heap[outIdx++] = 128 | u >> 12 & 63; 5728 heap[outIdx++] = 128 | u >> 6 & 63; 5729 heap[outIdx++] = 128 | u & 63; 5730 i++; 5731 } 5732 } 5733 heap[outIdx] = 0; 5734 return outIdx - startIdx; 5735 }; 5736 var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite); 5737 var _environ_get = (__environ, environ_buf) => { 5738 var bufSize = 0; 5739 var envp = 0; 5740 for (var string of getEnvStrings()) { 5741 var ptr = environ_buf + bufSize; 5742 HEAPU32[__environ + envp >> 2] = ptr; 5743 bufSize += stringToUTF8(string, ptr, Infinity) + 1; 5744 envp += 4; 5745 } 5746 return 0; 5747 }; 5748 var lengthBytesUTF8 = str => { 5749 var len = 0; 5750 for (var i = 0; i < str.length; ++i) { 5751 var c = str.charCodeAt(i); 5752 if (c <= 127) { 5753 len++; 5754 } else if (c <= 2047) { 5755 len += 2; 5756 } else if (c >= 55296 && c <= 57343) { 5757 len += 4; 5758 ++i; 5759 } else { 5760 len += 3; 5761 } 5762 } 5763 return len; 5764 }; 5765 var _environ_sizes_get = (penviron_count, penviron_buf_size) => { 5766 var strings = getEnvStrings(); 5767 HEAPU32[penviron_count >> 2] = strings.length; 5768 var bufSize = 0; 5769 for (var string of strings) { 5770 bufSize += lengthBytesUTF8(string) + 1; 5771 } 5772 HEAPU32[penviron_buf_size >> 2] = bufSize; 5773 return 0; 5774 }; 5775 var INT53_MAX = 9007199254740992; 5776 var INT53_MIN = -9007199254740992; 5777 var bigintToI53Checked = num => num < INT53_MIN || num > INT53_MAX ? NaN : Number(num); 5778 function _fd_seek(fd, offset, whence, newOffset) { 5779 offset = bigintToI53Checked(offset); 5780 return 70; 5781 } 5782 var printCharBuffers = [null, [], []]; 5783 var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder() : undefined; 5784 var findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => { 5785 var maxIdx = idx + maxBytesToRead; 5786 if (ignoreNul) return maxIdx; 5787 while (heapOrArray[idx] && !(idx >= maxIdx)) ++idx; 5788 return idx; 5789 }; 5790 var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => { 5791 var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul); 5792 if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) { 5793 return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr)); 5794 } 5795 var str = ""; 5796 while (idx < endPtr) { 5797 var u0 = heapOrArray[idx++]; 5798 if (!(u0 & 128)) { 5799 str += String.fromCharCode(u0); 5800 continue; 5801 } 5802 var u1 = heapOrArray[idx++] & 63; 5803 if ((u0 & 224) == 192) { 5804 str += String.fromCharCode((u0 & 31) << 6 | u1); 5805 continue; 5806 } 5807 var u2 = heapOrArray[idx++] & 63; 5808 if ((u0 & 240) == 224) { 5809 u0 = (u0 & 15) << 12 | u1 << 6 | u2; 5810 } else { 5811 u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63; 5812 } 5813 if (u0 < 65536) { 5814 str += String.fromCharCode(u0); 5815 } else { 5816 var ch = u0 - 65536; 5817 str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023); 5818 } 5819 } 5820 return str; 5821 }; 5822 var printChar = (stream, curr) => { 5823 var buffer = printCharBuffers[stream]; 5824 if (curr === 0 || curr === 10) { 5825 (stream === 1 ? out : err)(UTF8ArrayToString(buffer)); 5826 buffer.length = 0; 5827 } else { 5828 buffer.push(curr); 5829 } 5830 }; 5831 var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : ""; 5832 var _fd_write = (fd, iov, iovcnt, pnum) => { 5833 var num = 0; 5834 for (var i = 0; i < iovcnt; i++) { 5835 var ptr = HEAPU32[iov >> 2]; 5836 var len = HEAPU32[iov + 4 >> 2]; 5837 iov += 8; 5838 for (var j = 0; j < len; j++) { 5839 printChar(fd, HEAPU8[ptr + j]); 5840 } 5841 num += len; 5842 } 5843 HEAPU32[pnum >> 2] = num; 5844 return 0; 5845 }; 5846 function _gray_to_rgba(compG_ptr, nb_pixels) { 5847 compG_ptr >>= 2; 5848 const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels * 4); 5849 const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels); 5850 for (let i = 0; i < nb_pixels; i++) { 5851 imageData[4 * i] = imageData[4 * i + 1] = imageData[4 * i + 2] = compG[i]; 5852 imageData[4 * i + 3] = 255; 5853 } 5854 } 5855 function _graya_to_rgba(compG_ptr, compA_ptr, nb_pixels) { 5856 compG_ptr >>= 2; 5857 compA_ptr >>= 2; 5858 const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels * 4); 5859 const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels); 5860 const compA = HEAP32.subarray(compA_ptr, compA_ptr + nb_pixels); 5861 for (let i = 0; i < nb_pixels; i++) { 5862 imageData[4 * i] = imageData[4 * i + 1] = imageData[4 * i + 2] = compG[i]; 5863 imageData[4 * i + 3] = compA[i]; 5864 } 5865 } 5866 function _jsPrintWarning(message_ptr) { 5867 const message = UTF8ToString(message_ptr); 5868 (Module.warn || console.warn)(`OpenJPEG: ${message}`); 5869 } 5870 function _rgb_to_rgba(compR_ptr, compG_ptr, compB_ptr, nb_pixels) { 5871 compR_ptr >>= 2; 5872 compG_ptr >>= 2; 5873 compB_ptr >>= 2; 5874 const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels * 4); 5875 const compR = HEAP32.subarray(compR_ptr, compR_ptr + nb_pixels); 5876 const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels); 5877 const compB = HEAP32.subarray(compB_ptr, compB_ptr + nb_pixels); 5878 for (let i = 0; i < nb_pixels; i++) { 5879 imageData[4 * i] = compR[i]; 5880 imageData[4 * i + 1] = compG[i]; 5881 imageData[4 * i + 2] = compB[i]; 5882 imageData[4 * i + 3] = 255; 5883 } 5884 } 5885 function _storeErrorMessage(message_ptr) { 5886 const message = UTF8ToString(message_ptr); 5887 if (!Module.errorMessages) { 5888 Module.errorMessages = message; 5889 } else { 5890 Module.errorMessages += "\n" + message; 5891 } 5892 } 5893 var writeArrayToMemory = (array, buffer) => { 5894 HEAP8.set(array, buffer); 5895 }; 5896 if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"]; 5897 if (Module["print"]) out = Module["print"]; 5898 if (Module["printErr"]) err = Module["printErr"]; 5899 if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"]; 5900 if (Module["arguments"]) arguments_ = Module["arguments"]; 5901 if (Module["thisProgram"]) thisProgram = Module["thisProgram"]; 5902 if (Module["preInit"]) { 5903 if (typeof Module["preInit"] == "function") Module["preInit"] = [Module["preInit"]]; 5904 while (Module["preInit"].length > 0) { 5905 Module["preInit"].shift()(); 5906 } 5907 } 5908 Module["writeArrayToMemory"] = writeArrayToMemory; 5909 var _malloc, _free, _jp2_decode, __emscripten_timeout; 5910 function assignWasmExports(wasmExports) { 5911 Module["_malloc"] = _malloc = wasmExports["t"]; 5912 Module["_free"] = _free = wasmExports["u"]; 5913 Module["_jp2_decode"] = _jp2_decode = wasmExports["v"]; 5914 __emscripten_timeout = wasmExports["w"]; 5915 } 5916 var wasmImports = { 5917 k: __abort_js, 5918 j: __emscripten_runtime_keepalive_clear, 5919 l: __setitimer_js, 5920 f: _copy_pixels_1, 5921 e: _copy_pixels_3, 5922 d: _copy_pixels_4, 5923 m: _emscripten_resize_heap, 5924 o: _environ_get, 5925 p: _environ_sizes_get, 5926 n: _fd_seek, 5927 b: _fd_write, 5928 q: _gray_to_rgba, 5929 h: _graya_to_rgba, 5930 c: _jsPrintWarning, 5931 i: _proc_exit, 5932 g: _rgb_to_rgba, 5933 a: _storeErrorMessage 5934 }; 5935 function run() { 5936 preRun(); 5937 function doRun() { 5938 Module["calledRun"] = true; 5939 if (ABORT) return; 5940 initRuntime(); 5941 readyPromiseResolve?.(Module); 5942 Module["onRuntimeInitialized"]?.(); 5943 postRun(); 5944 } 5945 if (Module["setStatus"]) { 5946 Module["setStatus"]("Running..."); 5947 setTimeout(() => { 5948 setTimeout(() => Module["setStatus"](""), 1); 5949 doRun(); 5950 }, 1); 5951 } else { 5952 doRun(); 5953 } 5954 } 5955 var wasmExports; 5956 wasmExports = await createWasm(); 5957 run(); 5958 if (runtimeInitialized) { 5959 moduleRtn = Module; 5960 } else { 5961 moduleRtn = new Promise((resolve, reject) => { 5962 readyPromiseResolve = resolve; 5963 readyPromiseReject = reject; 5964 }); 5965 } 5966 return moduleRtn; 5967} 5968/* harmony default export */ const openjpeg = (OpenJPEG); 5969;// ./src/core/jpx.js 5970 5971 5972 5973
vendor: 3,892 bytes, lines 5974-6114
5974class JpxError extends BaseException { 5975 constructor(msg) { 5976 super(msg, "JpxError"); 5977 } 5978} 5979class JpxImage { 5980 static #buffer = null; 5981 static #handler = null; 5982 static #modulePromise = null; 5983 static #useWasm = true; 5984 static #useWorkerFetch = true; 5985 static #wasmUrl = null; 5986 static setOptions({ 5987 handler, 5988 useWasm, 5989 useWorkerFetch, 5990 wasmUrl 5991 }) { 5992 this.#useWasm = useWasm; 5993 this.#useWorkerFetch = useWorkerFetch; 5994 this.#wasmUrl = wasmUrl; 5995 if (!useWorkerFetch) { 5996 this.#handler = handler; 5997 } 5998 } 5999 static async #getJsModule(fallbackCallback) { 6000 const path = `${this.#wasmUrl}openjpeg_nowasm_fallback.js`; 6001 let instance = null; 6002 try { 6003 const mod = await import( 6004 /*webpackIgnore: true*/ 6005 /*@vite-ignore*/ 6006 path); 6007 instance = mod.default(); 6008 } catch (e) { 6009 warn(`JpxImage#getJsModule: ${e}`); 6010 } 6011 fallbackCallback(instance); 6012 } 6013 static async #instantiateWasm(fallbackCallback, imports, successCallback) { 6014 const filename = "openjpeg.wasm"; 6015 try { 6016 if (!this.#buffer) { 6017 if (this.#useWorkerFetch) { 6018 this.#buffer = await fetchBinaryData(`${this.#wasmUrl}${filename}`); 6019 } else { 6020 this.#buffer = await this.#handler.sendWithPromise("FetchBinaryData", { 6021 type: "wasmFactory", 6022 filename 6023 }); 6024 } 6025 } 6026 const results = await WebAssembly.instantiate(this.#buffer, imports); 6027 return successCallback(results.instance); 6028 } catch (reason) { 6029 warn(`JpxImage#instantiateWasm: ${reason}`); 6030 this.#getJsModule(fallbackCallback); 6031 return null; 6032 } finally { 6033 this.#handler = null; 6034 } 6035 } 6036 static async decode(bytes, { 6037 numComponents = 4, 6038 isIndexedColormap = false, 6039 smaskInData = false, 6040 reducePower = 0 6041 } = {}) { 6042 if (!this.#modulePromise) { 6043 const { 6044 promise, 6045 resolve 6046 } = Promise.withResolvers(); 6047 const promises = [promise]; 6048 if (!this.#useWasm) { 6049 this.#getJsModule(resolve); 6050 } else { 6051 promises.push(openjpeg({ 6052 warn: warn, 6053 instantiateWasm: this.#instantiateWasm.bind(this, resolve) 6054 })); 6055 } 6056 this.#modulePromise = Promise.race(promises); 6057 } 6058 const module = await this.#modulePromise; 6059 if (!module) { 6060 throw new JpxError("OpenJPEG failed to initialize"); 6061 } 6062 let ptr; 6063 try { 6064 const size = bytes.length; 6065 ptr = module._malloc(size); 6066 module.writeArrayToMemory(bytes, ptr); 6067 const ret = module._jp2_decode(ptr, size, numComponents > 0 ? numComponents : 0, !!isIndexedColormap, !!smaskInData, reducePower); 6068 if (ret) { 6069 const { 6070 errorMessages 6071 } = module; 6072 if (errorMessages) { 6073 delete module.errorMessages; 6074 throw new JpxError(errorMessages); 6075 } 6076 throw new JpxError("Unknown error"); 6077 } 6078 const { 6079 imageData 6080 } = module; 6081 module.imageData = null; 6082 return imageData; 6083 } finally { 6084 if (ptr) { 6085 module._free(ptr); 6086 } 6087 } 6088 } 6089 static cleanup() { 6090 this.#modulePromise = null; 6091 } 6092 static parseImageProperties(stream) { 6093 let newByte = stream.getByte(); 6094 while (newByte >= 0) { 6095 const oldByte = newByte; 6096 newByte = stream.getByte(); 6097 const code = oldByte << 8 | newByte; 6098 if (code === 0xff51) { 6099 stream.skip(4); 6100 const Xsiz = stream.getInt32() >>> 0; 6101 const Ysiz = stream.getInt32() >>> 0; 6102 const XOsiz = stream.getInt32() >>> 0; 6103 const YOsiz = stream.getInt32() >>> 0; 6104 stream.skip(16); 6105 const Csiz = stream.getUint16(); 6106 return { 6107 width: Xsiz - XOsiz, 6108 height: Ysiz - YOsiz, 6109 bitsPerComponent: 8, 6110 componentsCount: Csiz 6111 }; 6112 } 6113 } 6114 throw new JpxError("No size marker found in JPX stream")
vendor: 12,591 bytes, lines 6114-6444
6114; 6115 } 6116} 6117 6118;// ./src/core/operator_list.js 6119 6120function addState(parentState, pattern, checkFn, iterateFn, processFn) { 6121 let state = parentState; 6122 for (let i = 0, ii = pattern.length - 1; i < ii; i++) { 6123 const item = pattern[i]; 6124 state = state[item] ||= []; 6125 } 6126 state[pattern.at(-1)] = { 6127 checkFn, 6128 iterateFn, 6129 processFn 6130 }; 6131} 6132const InitialState = []; 6133addState(InitialState, [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore], null, function iterateInlineImageGroup(context, i) { 6134 const fnArray = context.fnArray; 6135 const iFirstSave = context.iCurr - 3; 6136 const pos = (i - iFirstSave) % 4; 6137 switch (pos) { 6138 case 0: 6139 return fnArray[i] === OPS.save; 6140 case 1: 6141 return fnArray[i] === OPS.transform; 6142 case 2: 6143 return fnArray[i] === OPS.paintInlineImageXObject; 6144 case 3: 6145 return fnArray[i] === OPS.restore; 6146 } 6147 throw new Error(`iterateInlineImageGroup - invalid pos: ${pos}`); 6148}, function foundInlineImageGroup(context, i) { 6149 const MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10; 6150 const MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200; 6151 const MAX_WIDTH = 1000; 6152 const IMAGE_PADDING = 1; 6153 const fnArray = context.fnArray, 6154 argsArray = context.argsArray; 6155 const curr = context.iCurr; 6156 const iFirstSave = curr - 3; 6157 const iFirstTransform = curr - 2; 6158 const iFirstPIIXO = curr - 1; 6159 const count = Math.min(Math.floor((i - iFirstSave) / 4), MAX_IMAGES_IN_INLINE_IMAGES_BLOCK); 6160 if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) { 6161 return i - (i - iFirstSave) % 4; 6162 } 6163 let maxX = 0; 6164 const map = []; 6165 let maxLineHeight = 0; 6166 let currentX = IMAGE_PADDING, 6167 currentY = IMAGE_PADDING; 6168 for (let q = 0; q < count; q++) { 6169 const transform = argsArray[iFirstTransform + (q << 2)]; 6170 const img = argsArray[iFirstPIIXO + (q << 2)][0]; 6171 if (currentX + img.width > MAX_WIDTH) { 6172 maxX = Math.max(maxX, currentX); 6173 currentY += maxLineHeight + 2 * IMAGE_PADDING; 6174 currentX = 0; 6175 maxLineHeight = 0; 6176 } 6177 map.push({ 6178 transform, 6179 x: currentX, 6180 y: currentY, 6181 w: img.width, 6182 h: img.height 6183 }); 6184 currentX += img.width + 2 * IMAGE_PADDING; 6185 maxLineHeight = Math.max(maxLineHeight, img.height); 6186 } 6187 const imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING; 6188 const imgHeight = currentY + maxLineHeight + IMAGE_PADDING; 6189 const imgData = new Uint8Array(imgWidth * imgHeight * 4); 6190 const imgRowSize = imgWidth << 2; 6191 for (let q = 0; q < count; q++) { 6192 const data = argsArray[iFirstPIIXO + (q << 2)][0].data; 6193 const rowSize = map[q].w << 2; 6194 let dataOffset = 0; 6195 let offset = map[q].x + map[q].y * imgWidth << 2; 6196 imgData.set(data.subarray(0, rowSize), offset - imgRowSize); 6197 for (let k = 0, kk = map[q].h; k < kk; k++) { 6198 imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset); 6199 dataOffset += rowSize; 6200 offset += imgRowSize; 6201 } 6202 imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset); 6203 while (offset >= 0) { 6204 data[offset - 4] = data[offset]; 6205 data[offset - 3] = data[offset + 1]; 6206 data[offset - 2] = data[offset + 2]; 6207 data[offset - 1] = data[offset + 3]; 6208 data[offset + rowSize] = data[offset + rowSize - 4]; 6209 data[offset + rowSize + 1] = data[offset + rowSize - 3]; 6210 data[offset + rowSize + 2] = data[offset + rowSize - 2]; 6211 data[offset + rowSize + 3] = data[offset + rowSize - 1]; 6212 offset -= imgRowSize; 6213 } 6214 } 6215 const img = { 6216 width: imgWidth, 6217 height: imgHeight 6218 }; 6219 if (context.isOffscreenCanvasSupported) { 6220 const canvas = new OffscreenCanvas(imgWidth, imgHeight); 6221 const ctx = canvas.getContext("2d"); 6222 ctx.putImageData(new ImageData(new Uint8ClampedArray(imgData.buffer), imgWidth, imgHeight), 0, 0); 6223 img.bitmap = canvas.transferToImageBitmap(); 6224 img.data = null; 6225 } else { 6226 img.kind = ImageKind.RGBA_32BPP; 6227 img.data = imgData; 6228 } 6229 fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup); 6230 argsArray.splice(iFirstSave, count * 4, [img, map]); 6231 return iFirstSave + 1; 6232}); 6233addState(InitialState, [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore], null, function iterateImageMaskGroup(context, i) { 6234 const fnArray = context.fnArray; 6235 const iFirstSave = context.iCurr - 3; 6236 const pos = (i - iFirstSave) % 4; 6237 switch (pos) { 6238 case 0: 6239 return fnArray[i] === OPS.save; 6240 case 1: 6241 return fnArray[i] === OPS.transform; 6242 case 2: 6243 return fnArray[i] === OPS.paintImageMaskXObject; 6244 case 3: 6245 return fnArray[i] === OPS.restore; 6246 } 6247 throw new Error(`iterateImageMaskGroup - invalid pos: ${pos}`); 6248}, function foundImageMaskGroup(context, i) { 6249 const MIN_IMAGES_IN_MASKS_BLOCK = 10; 6250 const MAX_IMAGES_IN_MASKS_BLOCK = 100; 6251 const MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000; 6252 const fnArray = context.fnArray, 6253 argsArray = context.argsArray; 6254 const curr = context.iCurr; 6255 const iFirstSave = curr - 3; 6256 const iFirstTransform = curr - 2; 6257 const iFirstPIMXO = curr - 1; 6258 let count = Math.floor((i - iFirstSave) / 4); 6259 if (count < MIN_IMAGES_IN_MASKS_BLOCK) { 6260 return i - (i - iFirstSave) % 4; 6261 } 6262 let isSameImage = false; 6263 let iTransform, transformArgs; 6264 const firstPIMXOArg0 = argsArray[iFirstPIMXO][0]; 6265 const firstTransformArg0 = argsArray[iFirstTransform][0], 6266 firstTransformArg1 = argsArray[iFirstTransform][1], 6267 firstTransformArg2 = argsArray[iFirstTransform][2], 6268 firstTransformArg3 = argsArray[iFirstTransform][3]; 6269 if (firstTransformArg1 === firstTransformArg2) { 6270 isSameImage = true; 6271 iTransform = iFirstTransform + 4; 6272 let iPIMXO = iFirstPIMXO + 4; 6273 for (let q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) { 6274 transformArgs = argsArray[iTransform]; 6275 if (argsArray[iPIMXO][0] !== firstPIMXOArg0 || transformArgs[0] !== firstTransformArg0 || transformArgs[1] !== firstTransformArg1 || transformArgs[2] !== firstTransformArg2 || transformArgs[3] !== firstTransformArg3) { 6276 if (q < MIN_IMAGES_IN_MASKS_BLOCK) { 6277 isSameImage = false; 6278 } else { 6279 count = q; 6280 } 6281 break; 6282 } 6283 } 6284 } 6285 if (isSameImage) { 6286 count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK); 6287 const positions = new Float32Array(count * 2); 6288 iTransform = iFirstTransform; 6289 for (let q = 0; q < count; q++, iTransform += 4) { 6290 transformArgs = argsArray[iTransform]; 6291 positions[q << 1] = transformArgs[4]; 6292 positions[(q << 1) + 1] = transformArgs[5]; 6293 } 6294 fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat); 6295 argsArray.splice(iFirstSave, count * 4, [firstPIMXOArg0, firstTransformArg0, firstTransformArg1, firstTransformArg2, firstTransformArg3, positions]); 6296 } else { 6297 count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK); 6298 const images = []; 6299 for (let q = 0; q < count; q++) { 6300 transformArgs = argsArray[iFirstTransform + (q << 2)]; 6301 const maskParams = argsArray[iFirstPIMXO + (q << 2)][0]; 6302 images.push({ 6303 data: maskParams.data, 6304 width: maskParams.width, 6305 height: maskParams.height, 6306 interpolate: maskParams.interpolate, 6307 count: maskParams.count, 6308 transform: transformArgs 6309 }); 6310 } 6311 fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup); 6312 argsArray.splice(iFirstSave, count * 4, [images]); 6313 } 6314 return iFirstSave + 1; 6315}); 6316addState(InitialState, [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore], function (context) { 6317 const argsArray = context.argsArray; 6318 const iFirstTransform = context.iCurr - 2; 6319 return argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0; 6320}, function iterateImageGroup(context, i) { 6321 const fnArray = context.fnArray, 6322 argsArray = context.argsArray; 6323 const iFirstSave = context.iCurr - 3; 6324 const pos = (i - iFirstSave) % 4; 6325 switch (pos) { 6326 case 0: 6327 return fnArray[i] === OPS.save; 6328 case 1: 6329 if (fnArray[i] !== OPS.transform) { 6330 return false; 6331 } 6332 const iFirstTransform = context.iCurr - 2; 6333 const firstTransformArg0 = argsArray[iFirstTransform][0]; 6334 const firstTransformArg3 = argsArray[iFirstTransform][3]; 6335 if (argsArray[i][0] !== firstTransformArg0 || argsArray[i][1] !== 0 || argsArray[i][2] !== 0 || argsArray[i][3] !== firstTransformArg3) { 6336 return false; 6337 } 6338 return true; 6339 case 2: 6340 if (fnArray[i] !== OPS.paintImageXObject) { 6341 return false; 6342 } 6343 const iFirstPIXO = context.iCurr - 1; 6344 const firstPIXOArg0 = argsArray[iFirstPIXO][0]; 6345 if (argsArray[i][0] !== firstPIXOArg0) { 6346 return false; 6347 } 6348 return true; 6349 case 3: 6350 return fnArray[i] === OPS.restore; 6351 } 6352 throw new Error(`iterateImageGroup - invalid pos: ${pos}`); 6353}, function (context, i) { 6354 const MIN_IMAGES_IN_BLOCK = 3; 6355 const MAX_IMAGES_IN_BLOCK = 1000; 6356 const fnArray = context.fnArray, 6357 argsArray = context.argsArray; 6358 const curr = context.iCurr; 6359 const iFirstSave = curr - 3; 6360 const iFirstTransform = curr - 2; 6361 const iFirstPIXO = curr - 1; 6362 const firstPIXOArg0 = argsArray[iFirstPIXO][0]; 6363 const firstTransformArg0 = argsArray[iFirstTransform][0]; 6364 const firstTransformArg3 = argsArray[iFirstTransform][3]; 6365 const count = Math.min(Math.floor((i - iFirstSave) / 4), MAX_IMAGES_IN_BLOCK); 6366 if (count < MIN_IMAGES_IN_BLOCK) { 6367 return i - (i - iFirstSave) % 4; 6368 } 6369 const positions = new Float32Array(count * 2); 6370 let iTransform = iFirstTransform; 6371 for (let q = 0; q < count; q++, iTransform += 4) { 6372 const transformArgs = argsArray[iTransform]; 6373 positions[q << 1] = transformArgs[4]; 6374 positions[(q << 1) + 1] = transformArgs[5]; 6375 } 6376 const args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3, positions]; 6377 fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat); 6378 argsArray.splice(iFirstSave, count * 4, args); 6379 return iFirstSave + 1; 6380}); 6381addState(InitialState, [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText], null, function iterateShowTextGroup(context, i) { 6382 const fnArray = context.fnArray, 6383 argsArray = context.argsArray; 6384 const iFirstSave = context.iCurr - 4; 6385 const pos = (i - iFirstSave) % 5; 6386 switch (pos) { 6387 case 0: 6388 return fnArray[i] === OPS.beginText; 6389 case 1: 6390 return fnArray[i] === OPS.setFont; 6391 case 2: 6392 return fnArray[i] === OPS.setTextMatrix; 6393 case 3: 6394 if (fnArray[i] !== OPS.showText) { 6395 return false; 6396 } 6397 const iFirstSetFont = context.iCurr - 3; 6398 const firstSetFontArg0 = argsArray[iFirstSetFont][0]; 6399 const firstSetFontArg1 = argsArray[iFirstSetFont][1]; 6400 if (argsArray[i][0] !== firstSetFontArg0 || argsArray[i][1] !== firstSetFontArg1) { 6401 return false; 6402 } 6403 return true; 6404 case 4: 6405 return fnArray[i] === OPS.endText; 6406 } 6407 throw new Error(`iterateShowTextGroup - invalid pos: ${pos}`); 6408}, function (context, i) { 6409 const MIN_CHARS_IN_BLOCK = 3; 6410 const MAX_CHARS_IN_BLOCK = 1000; 6411 const fnArray = context.fnArray, 6412 argsArray = context.argsArray; 6413 const curr = context.iCurr; 6414 const iFirstBeginText = curr - 4; 6415 const iFirstSetFont = curr - 3; 6416 const iFirstSetTextMatrix = curr - 2; 6417 const iFirstShowText = curr - 1; 6418 const iFirstEndText = curr; 6419 const firstSetFontArg0 = argsArray[iFirstSetFont][0]; 6420 const firstSetFontArg1 = argsArray[iFirstSetFont][1]; 6421 let count = Math.min(Math.floor((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK); 6422 if (count < MIN_CHARS_IN_BLOCK) { 6423 return i - (i - iFirstBeginText) % 5; 6424 } 6425 let iFirst = iFirstBeginText; 6426 if (iFirstBeginText >= 4 && fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] && fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] && fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] && fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] && argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 && argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) { 6427 count++; 6428 iFirst -= 5; 6429 } 6430 let iEndText = iFirst + 4; 6431 for (let q = 1; q < count; q++) { 6432 fnArray.splice(iEndText, 3); 6433 argsArray.splice(iEndText, 3); 6434 iEndText += 2; 6435 } 6436 return iEndText + 1; 6437}); 6438addState(InitialState, [OPS.save, OPS.transform, OPS.constructPath, OPS.restore], context => { 6439 const argsArray = context.argsArray; 6440 const iFirstConstructPath = context.iCurr - 1; 6441 const op = argsArray[iFirstConstructPath][0]; 6442 if (op !== OPS.stroke && op !== OPS.closeStroke && op !== OPS.fillStroke && op !== OPS.eoFillStroke && op !== OPS.closeFillStroke && op !== OPS.closeEOFillStroke) { 6443 return true; 6444 }
vendor: 7,202 bytes, lines 6445-6715
6445 const iFirstTransform = context.iCurr - 2; 6446 const transform = argsArray[iFirstTransform]; 6447 return transform[0] === 1 && transform[1] === 0 && transform[2] === 0 && transform[3] === 1; 6448}, () => false, (context, i) => { 6449 const { 6450 fnArray, 6451 argsArray 6452 } = context; 6453 const curr = context.iCurr; 6454 const iFirstSave = curr - 3; 6455 const iFirstTransform = curr - 2; 6456 const iFirstConstructPath = curr - 1; 6457 const args = argsArray[iFirstConstructPath]; 6458 const transform = argsArray[iFirstTransform]; 6459 const [, [buffer], minMax] = args; 6460 if (minMax) { 6461 Util.scaleMinMax(transform, minMax); 6462 for (let k = 0, kk = buffer.length; k < kk;) { 6463 switch (buffer[k++]) { 6464 case DrawOPS.moveTo: 6465 case DrawOPS.lineTo: 6466 Util.applyTransform(buffer, transform, k); 6467 k += 2; 6468 break; 6469 case DrawOPS.curveTo: 6470 Util.applyTransformToBezier(buffer, transform, k); 6471 k += 6; 6472 break; 6473 } 6474 } 6475 } 6476 fnArray.splice(iFirstSave, 4, OPS.constructPath); 6477 argsArray.splice(iFirstSave, 4, args); 6478 return iFirstSave + 1; 6479}); 6480class NullOptimizer { 6481 constructor(queue) { 6482 this.queue = queue; 6483 } 6484 _optimize() {} 6485 push(fn, args) { 6486 this.queue.fnArray.push(fn); 6487 this.queue.argsArray.push(args); 6488 this._optimize(); 6489 } 6490 flush() {} 6491 reset() {} 6492} 6493class QueueOptimizer extends NullOptimizer { 6494 constructor(queue) { 6495 super(queue); 6496 this.state = null; 6497 this.context = { 6498 iCurr: 0, 6499 fnArray: queue.fnArray, 6500 argsArray: queue.argsArray, 6501 isOffscreenCanvasSupported: OperatorList.isOffscreenCanvasSupported 6502 }; 6503 this.match = null; 6504 this.lastProcessed = 0; 6505 } 6506 _optimize() { 6507 const fnArray = this.queue.fnArray; 6508 let i = this.lastProcessed, 6509 ii = fnArray.length; 6510 let state = this.state; 6511 let match = this.match; 6512 if (!state && !match && i + 1 === ii && !InitialState[fnArray[i]]) { 6513 this.lastProcessed = ii; 6514 return; 6515 } 6516 const context = this.context; 6517 while (i < ii) { 6518 if (match) { 6519 const iterate = (0, match.iterateFn)(context, i); 6520 if (iterate) { 6521 i++; 6522 continue; 6523 } 6524 i = (0, match.processFn)(context, i + 1); 6525 ii = fnArray.length; 6526 match = null; 6527 state = null; 6528 if (i >= ii) { 6529 break; 6530 } 6531 } 6532 state = (state || InitialState)[fnArray[i]]; 6533 if (!state || Array.isArray(state)) { 6534 i++; 6535 continue; 6536 } 6537 context.iCurr = i; 6538 i++; 6539 if (state.checkFn && !(0, state.checkFn)(context)) { 6540 state = null; 6541 continue; 6542 } 6543 match = state; 6544 state = null; 6545 } 6546 this.state = state; 6547 this.match = match; 6548 this.lastProcessed = i; 6549 } 6550 flush() { 6551 while (this.match) { 6552 const length = this.queue.fnArray.length; 6553 this.lastProcessed = (0, this.match.processFn)(this.context, length); 6554 this.match = null; 6555 this.state = null; 6556 this._optimize(); 6557 } 6558 } 6559 reset() { 6560 this.state = null; 6561 this.match = null; 6562 this.lastProcessed = 0; 6563 } 6564} 6565class OperatorList { 6566 static CHUNK_SIZE = 1000; 6567 static CHUNK_SIZE_ABOUT = this.CHUNK_SIZE - 5; 6568 static isOffscreenCanvasSupported = false; 6569 constructor(intent = 0, streamSink) { 6570 this._streamSink = streamSink; 6571 this.fnArray = []; 6572 this.argsArray = []; 6573 this.optimizer = streamSink && !(intent & RenderingIntentFlag.OPLIST) ? new QueueOptimizer(this) : new NullOptimizer(this); 6574 this.dependencies = new Set(); 6575 this._totalLength = 0; 6576 this.weight = 0; 6577 this._resolved = streamSink ? null : Promise.resolve(); 6578 } 6579 static setOptions({ 6580 isOffscreenCanvasSupported 6581 }) { 6582 this.isOffscreenCanvasSupported = isOffscreenCanvasSupported; 6583 } 6584 get length() { 6585 return this.argsArray.length; 6586 } 6587 get ready() { 6588 return this._resolved || this._streamSink.ready; 6589 } 6590 get totalLength() { 6591 return this._totalLength + this.length; 6592 } 6593 addOp(fn, args) { 6594 this.optimizer.push(fn, args); 6595 this.weight++; 6596 if (this._streamSink) { 6597 if (this.weight >= OperatorList.CHUNK_SIZE) { 6598 this.flush(); 6599 } else if (this.weight >= OperatorList.CHUNK_SIZE_ABOUT && (fn === OPS.restore || fn === OPS.endText)) { 6600 this.flush(); 6601 } 6602 } 6603 } 6604 addImageOps(fn, args, optionalContent, hasMask = false) { 6605 if (hasMask) { 6606 this.addOp(OPS.save); 6607 this.addOp(OPS.setGState, [[["SMask", false]]]); 6608 } 6609 if (optionalContent !== undefined) { 6610 this.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]); 6611 } 6612 this.addOp(fn, args); 6613 if (optionalContent !== undefined) { 6614 this.addOp(OPS.endMarkedContent, []); 6615 } 6616 if (hasMask) { 6617 this.addOp(OPS.restore); 6618 } 6619 } 6620 addDependency(dependency) { 6621 if (this.dependencies.has(dependency)) { 6622 return; 6623 } 6624 this.dependencies.add(dependency); 6625 this.addOp(OPS.dependency, [dependency]); 6626 } 6627 addDependencies(dependencies) { 6628 for (const dependency of dependencies) { 6629 this.addDependency(dependency); 6630 } 6631 } 6632 addOpList(opList) { 6633 if (!(opList instanceof OperatorList)) { 6634 warn('addOpList - ignoring invalid "opList" parameter.'); 6635 return; 6636 } 6637 for (const dependency of opList.dependencies) { 6638 this.dependencies.add(dependency); 6639 } 6640 for (let i = 0, ii = opList.length; i < ii; i++) { 6641 this.addOp(opList.fnArray[i], opList.argsArray[i]); 6642 } 6643 } 6644 getIR() { 6645 return { 6646 fnArray: this.fnArray, 6647 argsArray: this.argsArray, 6648 length: this.length 6649 }; 6650 } 6651 get _transfers() { 6652 const transfers = []; 6653 const { 6654 fnArray, 6655 argsArray, 6656 length 6657 } = this; 6658 for (let i = 0; i < length; i++) { 6659 switch (fnArray[i]) { 6660 case OPS.paintInlineImageXObject: 6661 case OPS.paintInlineImageXObjectGroup: 6662 case OPS.paintImageMaskXObject: 6663 { 6664 const { 6665 bitmap, 6666 data 6667 } = argsArray[i][0]; 6668 if (bitmap || data?.buffer) { 6669 transfers.push(bitmap || data.buffer); 6670 } 6671 break; 6672 } 6673 case OPS.constructPath: 6674 { 6675 const [, [data], minMax] = argsArray[i]; 6676 if (data) { 6677 transfers.push(data.buffer, minMax.buffer); 6678 } 6679 break; 6680 } 6681 case OPS.paintFormXObjectBegin: 6682 const [matrix, bbox] = argsArray[i]; 6683 if (matrix) { 6684 transfers.push(matrix.buffer); 6685 } 6686 if (bbox) { 6687 transfers.push(bbox.buffer); 6688 } 6689 break; 6690 case OPS.setTextMatrix: 6691 transfers.push(argsArray[i][0].buffer); 6692 break; 6693 } 6694 } 6695 return transfers; 6696 } 6697 flush(lastChunk = false, separateAnnots = null) { 6698 this.optimizer.flush(); 6699 const length = this.length; 6700 this._totalLength += length; 6701 this._streamSink.enqueue({ 6702 fnArray: this.fnArray, 6703 argsArray: this.argsArray, 6704 lastChunk, 6705 separateAnnots, 6706 length 6707 }, 1, this._transfers); 6708 this.dependencies.clear(); 6709 this.fnArray.length = 0; 6710 this.argsArray.length = 0; 6711 this.weight = 0; 6712 this.optimizer.reset(); 6713 } 6714} 6715
vendor: 10,758 bytes, lines 6716-7091
6716;// ./src/core/binary_cmap.js 6717 6718function hexToInt(a, size) { 6719 let n = 0; 6720 for (let i = 0; i <= size; i++) { 6721 n = n << 8 | a[i]; 6722 } 6723 return n >>> 0; 6724} 6725function hexToStr(a, size) { 6726 if (size === 1) { 6727 return String.fromCharCode(a[0], a[1]); 6728 } 6729 if (size === 3) { 6730 return String.fromCharCode(a[0], a[1], a[2], a[3]); 6731 } 6732 return String.fromCharCode(...a.subarray(0, size + 1)); 6733} 6734function addHex(a, b, size) { 6735 let c = 0; 6736 for (let i = size; i >= 0; i--) { 6737 c += a[i] + b[i]; 6738 a[i] = c & 255; 6739 c >>= 8; 6740 } 6741} 6742function incHex(a, size) { 6743 let c = 1; 6744 for (let i = size; i >= 0 && c > 0; i--) { 6745 c += a[i]; 6746 a[i] = c & 255; 6747 c >>= 8; 6748 } 6749} 6750const MAX_NUM_SIZE = 16; 6751const MAX_ENCODED_NUM_SIZE = 19; 6752class BinaryCMapStream { 6753 constructor(data) { 6754 this.buffer = data; 6755 this.pos = 0; 6756 this.end = data.length; 6757 this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE); 6758 } 6759 readByte() { 6760 if (this.pos >= this.end) { 6761 return -1; 6762 } 6763 return this.buffer[this.pos++]; 6764 } 6765 readNumber() { 6766 let n = 0; 6767 let last; 6768 do { 6769 const b = this.readByte(); 6770 if (b < 0) { 6771 throw new FormatError("unexpected EOF in bcmap"); 6772 } 6773 last = !(b & 0x80); 6774 n = n << 7 | b & 0x7f; 6775 } while (!last); 6776 return n; 6777 } 6778 readSigned() { 6779 const n = this.readNumber(); 6780 return n & 1 ? ~(n >>> 1) : n >>> 1; 6781 } 6782 readHex(num, size) { 6783 num.set(this.buffer.subarray(this.pos, this.pos + size + 1)); 6784 this.pos += size + 1; 6785 } 6786 readHexNumber(num, size) { 6787 let last; 6788 const stack = this.tmpBuf; 6789 let sp = 0; 6790 do { 6791 const b = this.readByte(); 6792 if (b < 0) { 6793 throw new FormatError("unexpected EOF in bcmap"); 6794 } 6795 last = !(b & 0x80); 6796 stack[sp++] = b & 0x7f; 6797 } while (!last); 6798 let i = size, 6799 buffer = 0, 6800 bufferSize = 0; 6801 while (i >= 0) { 6802 while (bufferSize < 8 && stack.length > 0) { 6803 buffer |= stack[--sp] << bufferSize; 6804 bufferSize += 7; 6805 } 6806 num[i] = buffer & 255; 6807 i--; 6808 buffer >>= 8; 6809 bufferSize -= 8; 6810 } 6811 } 6812 readHexSigned(num, size) { 6813 this.readHexNumber(num, size); 6814 const sign = num[size] & 1 ? 255 : 0; 6815 let c = 0; 6816 for (let i = 0; i <= size; i++) { 6817 c = (c & 1) << 8 | num[i]; 6818 num[i] = c >> 1 ^ sign; 6819 } 6820 } 6821 readString() { 6822 const len = this.readNumber(), 6823 buf = new Array(len); 6824 for (let i = 0; i < len; i++) { 6825 buf[i] = this.readNumber(); 6826 } 6827 return String.fromCharCode(...buf); 6828 } 6829} 6830class BinaryCMapReader { 6831 async process(data, cMap, extend) { 6832 const stream = new BinaryCMapStream(data); 6833 const header = stream.readByte(); 6834 cMap.vertical = !!(header & 1); 6835 let useCMap = null; 6836 const start = new Uint8Array(MAX_NUM_SIZE); 6837 const end = new Uint8Array(MAX_NUM_SIZE); 6838 const char = new Uint8Array(MAX_NUM_SIZE); 6839 const charCode = new Uint8Array(MAX_NUM_SIZE); 6840 const tmp = new Uint8Array(MAX_NUM_SIZE); 6841 let code; 6842 let b; 6843 while ((b = stream.readByte()) >= 0) { 6844 const type = b >> 5; 6845 if (type === 7) { 6846 switch (b & 0x1f) { 6847 case 0: 6848 stream.readString(); 6849 break; 6850 case 1: 6851 useCMap = stream.readString(); 6852 break; 6853 } 6854 continue; 6855 } 6856 const sequence = !!(b & 0x10); 6857 const dataSize = b & 15; 6858 if (dataSize + 1 > MAX_NUM_SIZE) { 6859 throw new Error("BinaryCMapReader.process: Invalid dataSize."); 6860 } 6861 const ucs2DataSize = 1; 6862 const subitemsCount = stream.readNumber(); 6863 switch (type) { 6864 case 0: 6865 stream.readHex(start, dataSize); 6866 stream.readHexNumber(end, dataSize); 6867 addHex(end, start, dataSize); 6868 cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize)); 6869 for (let i = 1; i < subitemsCount; i++) { 6870 incHex(end, dataSize); 6871 stream.readHexNumber(start, dataSize); 6872 addHex(start, end, dataSize); 6873 stream.readHexNumber(end, dataSize); 6874 addHex(end, start, dataSize); 6875 cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize)); 6876 } 6877 break; 6878 case 1: 6879 stream.readHex(start, dataSize); 6880 stream.readHexNumber(end, dataSize); 6881 addHex(end, start, dataSize); 6882 stream.readNumber(); 6883 for (let i = 1; i < subitemsCount; i++) { 6884 incHex(end, dataSize); 6885 stream.readHexNumber(start, dataSize); 6886 addHex(start, end, dataSize); 6887 stream.readHexNumber(end, dataSize); 6888 addHex(end, start, dataSize); 6889 stream.readNumber(); 6890 } 6891 break; 6892 case 2: 6893 stream.readHex(char, dataSize); 6894 code = stream.readNumber(); 6895 cMap.mapOne(hexToInt(char, dataSize), code); 6896 for (let i = 1; i < subitemsCount; i++) { 6897 incHex(char, dataSize); 6898 if (!sequence) { 6899 stream.readHexNumber(tmp, dataSize); 6900 addHex(char, tmp, dataSize); 6901 } 6902 code = stream.readSigned() + (code + 1); 6903 cMap.mapOne(hexToInt(char, dataSize), code); 6904 } 6905 break; 6906 case 3: 6907 stream.readHex(start, dataSize); 6908 stream.readHexNumber(end, dataSize); 6909 addHex(end, start, dataSize); 6910 code = stream.readNumber(); 6911 cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code); 6912 for (let i = 1; i < subitemsCount; i++) { 6913 incHex(end, dataSize); 6914 if (!sequence) { 6915 stream.readHexNumber(start, dataSize); 6916 addHex(start, end, dataSize); 6917 } else { 6918 start.set(end); 6919 } 6920 stream.readHexNumber(end, dataSize); 6921 addHex(end, start, dataSize); 6922 code = stream.readNumber(); 6923 cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code); 6924 } 6925 break; 6926 case 4: 6927 stream.readHex(char, ucs2DataSize); 6928 stream.readHex(charCode, dataSize); 6929 cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize)); 6930 for (let i = 1; i < subitemsCount; i++) { 6931 incHex(char, ucs2DataSize); 6932 if (!sequence) { 6933 stream.readHexNumber(tmp, ucs2DataSize); 6934 addHex(char, tmp, ucs2DataSize); 6935 } 6936 incHex(charCode, dataSize); 6937 stream.readHexSigned(tmp, dataSize); 6938 addHex(charCode, tmp, dataSize); 6939 cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize)); 6940 } 6941 break; 6942 case 5: 6943 stream.readHex(start, ucs2DataSize); 6944 stream.readHexNumber(end, ucs2DataSize); 6945 addHex(end, start, ucs2DataSize); 6946 stream.readHex(charCode, dataSize); 6947 cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize)); 6948 for (let i = 1; i < subitemsCount; i++) { 6949 incHex(end, ucs2DataSize); 6950 if (!sequence) { 6951 stream.readHexNumber(start, ucs2DataSize); 6952 addHex(start, end, ucs2DataSize); 6953 } else { 6954 start.set(end); 6955 } 6956 stream.readHexNumber(end, ucs2DataSize); 6957 addHex(end, start, ucs2DataSize); 6958 stream.readHex(charCode, dataSize); 6959 cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize)); 6960 } 6961 break; 6962 default: 6963 throw new Error(`BinaryCMapReader.process - unknown type: ${type}`); 6964 } 6965 } 6966 if (useCMap) { 6967 return extend(useCMap); 6968 } 6969 return cMap; 6970 } 6971} 6972 6973;// ./src/core/ascii_85_stream.js 6974 6975 6976class Ascii85Stream extends DecodeStream { 6977 constructor(str, maybeLength) { 6978 if (maybeLength) { 6979 maybeLength *= 0.8; 6980 } 6981 super(maybeLength); 6982 this.str = str; 6983 this.dict = str.dict; 6984 this.input = new Uint8Array(5); 6985 } 6986 readBlock() { 6987 const TILDA_CHAR = 0x7e; 6988 const Z_LOWER_CHAR = 0x7a; 6989 const EOF = -1; 6990 const str = this.str; 6991 let c = str.getByte(); 6992 while (isWhiteSpace(c)) { 6993 c = str.getByte(); 6994 } 6995 if (c === EOF || c === TILDA_CHAR) { 6996 this.eof = true; 6997 return; 6998 } 6999 const bufferLength = this.bufferLength; 7000 let buffer, i; 7001 if (c === Z_LOWER_CHAR) { 7002 buffer = this.ensureBuffer(bufferLength + 4); 7003 for (i = 0; i < 4; ++i) { 7004 buffer[bufferLength + i] = 0; 7005 } 7006 this.bufferLength += 4; 7007 } else { 7008 const input = this.input; 7009 input[0] = c; 7010 for (i = 1; i < 5; ++i) { 7011 c = str.getByte(); 7012 while (isWhiteSpace(c)) { 7013 c = str.getByte(); 7014 } 7015 input[i] = c; 7016 if (c === EOF || c === TILDA_CHAR) { 7017 break; 7018 } 7019 } 7020 buffer = this.ensureBuffer(bufferLength + i - 1); 7021 this.bufferLength += i - 1; 7022 if (i < 5) { 7023 for (; i < 5; ++i) { 7024 input[i] = 0x21 + 84; 7025 } 7026 this.eof = true; 7027 } 7028 let t = 0; 7029 for (i = 0; i < 5; ++i) { 7030 t = t * 85 + (input[i] - 0x21); 7031 } 7032 for (i = 3; i >= 0; --i) { 7033 buffer[bufferLength + i] = t & 0xff; 7034 t >>= 8; 7035 } 7036 } 7037 } 7038} 7039 7040;// ./src/core/ascii_hex_stream.js 7041 7042class AsciiHexStream extends DecodeStream { 7043 constructor(str, maybeLength) { 7044 if (maybeLength) { 7045 maybeLength *= 0.5; 7046 } 7047 super(maybeLength); 7048 this.str = str; 7049 this.dict = str.dict; 7050 this.firstDigit = -1; 7051 } 7052 readBlock() { 7053 const UPSTREAM_BLOCK_SIZE = 8000; 7054 const bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE); 7055 if (!bytes.length) { 7056 this.eof = true; 7057 return; 7058 } 7059 const maxDecodeLength = bytes.length + 1 >> 1; 7060 const buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength); 7061 let bufferLength = this.bufferLength; 7062 let firstDigit = this.firstDigit; 7063 for (const ch of bytes) { 7064 let digit; 7065 if (ch >= 0x30 && ch <= 0x39) { 7066 digit = ch & 0x0f; 7067 } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) { 7068 digit = (ch & 0x0f) + 9; 7069 } else if (ch === 0x3e) { 7070 this.eof = true; 7071 break; 7072 } else { 7073 continue; 7074 } 7075 if (firstDigit < 0) { 7076 firstDigit = digit; 7077 } else { 7078 buffer[bufferLength++] = firstDigit << 4 | digit; 7079 firstDigit = -1; 7080 } 7081 } 7082 if (firstDigit >= 0 && this.eof) { 7083 buffer[bufferLength++] = firstDigit << 4; 7084 firstDigit = -1; 7085 } 7086 this.firstDigit = firstDigit; 7087 this.bufferLength = bufferLength; 7088 } 7089} 7090 7091;// ./src/core/ccitt.js
vendor: 104,039 bytes, lines 7091-10010
7091 7092 7093const ccittEOL = -2; 7094const ccittEOF = -1; 7095const twoDimPass = 0; 7096const twoDimHoriz = 1; 7097const twoDimVert0 = 2; 7098const twoDimVertR1 = 3; 7099const twoDimVertL1 = 4; 7100const twoDimVertR2 = 5; 7101const twoDimVertL2 = 6; 7102const twoDimVertR3 = 7; 7103const twoDimVertL3 = 8; 7104const twoDimTable = [[-1, -1], [-1, -1], [7, twoDimVertL3], [7, twoDimVertR3], [6, twoDimVertL2], [6, twoDimVertL2], [6, twoDimVertR2], [6, twoDimVertR2], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0]]; 7105const whiteTable1 = [[-1, -1], [12, ccittEOL], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [11, 1792], [11, 1792], [12, 1984], [12, 2048], [12, 2112], [12, 2176], [12, 2240], [12, 2304], [11, 1856], [11, 1856], [11, 1920], [11, 1920], [12, 2368], [12, 2432], [12, 2496], [12, 2560]]; 7106const whiteTable2 = [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [8, 29], [8, 29], [8, 30], [8, 30], [8, 45], [8, 45], [8, 46], [8, 46], [7, 22], [7, 22], [7, 22], [7, 22], [7, 23], [7, 23], [7, 23], [7, 23], [8, 47], [8, 47], [8, 48], [8, 48], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [7, 20], [7, 20], [7, 20], [7, 20], [8, 33], [8, 33], [8, 34], [8, 34], [8, 35], [8, 35], [8, 36], [8, 36], [8, 37], [8, 37], [8, 38], [8, 38], [7, 19], [7, 19], [7, 19], [7, 19], [8, 31], [8, 31], [8, 32], [8, 32], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [8, 53], [8, 53], [8, 54], [8, 54], [7, 26], [7, 26], [7, 26], [7, 26], [8, 39], [8, 39], [8, 40], [8, 40], [8, 41], [8, 41], [8, 42], [8, 42], [8, 43], [8, 43], [8, 44], [8, 44], [7, 21], [7, 21], [7, 21], [7, 21], [7, 28], [7, 28], [7, 28], [7, 28], [8, 61], [8, 61], [8, 62], [8, 62], [8, 63], [8, 63], [8, 0], [8, 0], [8, 320], [8, 320], [8, 384], [8, 384], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [7, 27], [7, 27], [7, 27], [7, 27], [8, 59], [8, 59], [8, 60], [8, 60], [9, 1472], [9, 1536], [9, 1600], [9, 1728], [7, 18], [7, 18], [7, 18], [7, 18], [7, 24], [7, 24], [7, 24], [7, 24], [8, 49], [8, 49], [8, 50], [8, 50], [8, 51], [8, 51], [8, 52], [8, 52], [7, 25], [7, 25], [7, 25], [7, 25], [8, 55], [8, 55], [8, 56], [8, 56], [8, 57], [8, 57], [8, 58], [8, 58], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [8, 448], [8, 448], [8, 512], [8, 512], [9, 704], [9, 768], [8, 640], [8, 640], [8, 576], [8, 576], [9, 832], [9, 896], [9, 960], [9, 1024], [9, 1088], [9, 1152], [9, 1216], [9, 1280], [9, 1344], [9, 1408], [7, 256], [7, 256], [7, 256], [7, 256], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7]]; 7107const blackTable1 = [[-1, -1], [-1, -1], [12, ccittEOL], [12, ccittEOL], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [11, 1792], [11, 1792], [11, 1792], [11, 1792], [12, 1984], [12, 1984], [12, 2048], [12, 2048], [12, 2112], [12, 2112], [12, 2176], [12, 2176], [12, 2240], [12, 2240], [12, 2304], [12, 2304], [11, 1856], [11, 1856], [11, 1856], [11, 1856], [11, 1920], [11, 1920], [11, 1920], [11, 1920], [12, 2368], [12, 2368], [12, 2432], [12, 2432], [12, 2496], [12, 2496], [12, 2560], [12, 2560], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [12, 52], [12, 52], [13, 640], [13, 704], [13, 768], [13, 832], [12, 55], [12, 55], [12, 56], [12, 56], [13, 1280], [13, 1344], [13, 1408], [13, 1472], [12, 59], [12, 59], [12, 60], [12, 60], [13, 1536], [13, 1600], [11, 24], [11, 24], [11, 24], [11, 24], [11, 25], [11, 25], [11, 25], [11, 25], [13, 1664], [13, 1728], [12, 320], [12, 320], [12, 384], [12, 384], [12, 448], [12, 448], [13, 512], [13, 576], [12, 53], [12, 53], [12, 54], [12, 54], [13, 896], [13, 960], [13, 1024], [13, 1088], [13, 1152], [13, 1216], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64]]; 7108const blackTable2 = [[8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [11, 23], [11, 23], [12, 50], [12, 51], [12, 44], [12, 45], [12, 46], [12, 47], [12, 57], [12, 58], [12, 61], [12, 256], [10, 16], [10, 16], [10, 16], [10, 16], [10, 17], [10, 17], [10, 17], [10, 17], [12, 48], [12, 49], [12, 62], [12, 63], [12, 30], [12, 31], [12, 32], [12, 33], [12, 40], [12, 41], [11, 22], [11, 22], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [12, 128], [12, 192], [12, 26], [12, 27], [12, 28], [12, 29], [11, 19], [11, 19], [11, 20], [11, 20], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [11, 21], [11, 21], [12, 42], [12, 43], [10, 0], [10, 0], [10, 0], [10, 0], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12]]; 7109const blackTable3 = [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [6, 9], [6, 8], [5, 7], [5, 7], [4, 6], [4, 6], [4, 6], [4, 6], [4, 5], [4, 5], [4, 5], [4, 5], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2]]; 7110class CCITTFaxDecoder { 7111 constructor(source, options = {}) { 7112 if (typeof source?.next !== "function") { 7113 throw new Error('CCITTFaxDecoder - invalid "source" parameter.'); 7114 } 7115 this.source = source; 7116 this.eof = false; 7117 this.encoding = options.K || 0; 7118 this.eoline = options.EndOfLine || false; 7119 this.byteAlign = options.EncodedByteAlign || false; 7120 this.columns = options.Columns || 1728; 7121 this.rows = options.Rows || 0; 7122 this.eoblock = options.EndOfBlock ?? true; 7123 this.black = options.BlackIs1 || false; 7124 this.codingLine = new Uint32Array(this.columns + 1); 7125 this.refLine = new Uint32Array(this.columns + 2); 7126 this.codingLine[0] = this.columns; 7127 this.codingPos = 0; 7128 this.row = 0; 7129 this.nextLine2D = this.encoding < 0; 7130 this.inputBits = 0; 7131 this.inputBuf = 0; 7132 this.outputBits = 0; 7133 this.rowsDone = false; 7134 let code1; 7135 while ((code1 = this._lookBits(12)) === 0) { 7136 this._eatBits(1); 7137 } 7138 if (code1 === 1) { 7139 this._eatBits(12); 7140 } 7141 if (this.encoding > 0) { 7142 this.nextLine2D = !this._lookBits(1); 7143 this._eatBits(1); 7144 } 7145 } 7146 readNextChar() { 7147 if (this.eof) { 7148 return -1; 7149 } 7150 const refLine = this.refLine; 7151 const codingLine = this.codingLine; 7152 const columns = this.columns; 7153 let refPos, blackPixels, bits, i; 7154 if (this.outputBits === 0) { 7155 if (this.rowsDone) { 7156 this.eof = true; 7157 } 7158 if (this.eof) { 7159 return -1; 7160 } 7161 this.err = false; 7162 let code1, code2, code3; 7163 if (this.nextLine2D) { 7164 for (i = 0; codingLine[i] < columns; ++i) { 7165 refLine[i] = codingLine[i]; 7166 } 7167 refLine[i++] = columns; 7168 refLine[i] = columns; 7169 codingLine[0] = 0; 7170 this.codingPos = 0; 7171 refPos = 0; 7172 blackPixels = 0; 7173 while (codingLine[this.codingPos] < columns) { 7174 code1 = this._getTwoDimCode(); 7175 switch (code1) { 7176 case twoDimPass: 7177 this._addPixels(refLine[refPos + 1], blackPixels); 7178 if (refLine[refPos + 1] < columns) { 7179 refPos += 2; 7180 } 7181 break; 7182 case twoDimHoriz: 7183 code1 = code2 = 0; 7184 if (blackPixels) { 7185 do { 7186 code1 += code3 = this._getBlackCode(); 7187 } while (code3 >= 64); 7188 do { 7189 code2 += code3 = this._getWhiteCode(); 7190 } while (code3 >= 64); 7191 } else { 7192 do { 7193 code1 += code3 = this._getWhiteCode(); 7194 } while (code3 >= 64); 7195 do { 7196 code2 += code3 = this._getBlackCode(); 7197 } while (code3 >= 64); 7198 } 7199 this._addPixels(codingLine[this.codingPos] + code1, blackPixels); 7200 if (codingLine[this.codingPos] < columns) { 7201 this._addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1); 7202 } 7203 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) { 7204 refPos += 2; 7205 } 7206 break; 7207 case twoDimVertR3: 7208 this._addPixels(refLine[refPos] + 3, blackPixels); 7209 blackPixels ^= 1; 7210 if (codingLine[this.codingPos] < columns) { 7211 ++refPos; 7212 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) { 7213 refPos += 2; 7214 } 7215 } 7216 break; 7217 case twoDimVertR2: 7218 this._addPixels(refLine[refPos] + 2, blackPixels); 7219 blackPixels ^= 1; 7220 if (codingLine[this.codingPos] < columns) { 7221 ++refPos; 7222 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) { 7223 refPos += 2; 7224 } 7225 } 7226 break; 7227 case twoDimVertR1: 7228 this._addPixels(refLine[refPos] + 1, blackPixels); 7229 blackPixels ^= 1; 7230 if (codingLine[this.codingPos] < columns) { 7231 ++refPos; 7232 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) { 7233 refPos += 2; 7234 } 7235 } 7236 break; 7237 case twoDimVert0: 7238 this._addPixels(refLine[refPos], blackPixels); 7239 blackPixels ^= 1; 7240 if (codingLine[this.codingPos] < columns) { 7241 ++refPos; 7242 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) { 7243 refPos += 2; 7244 } 7245 } 7246 break; 7247 case twoDimVertL3: 7248 this._addPixelsNeg(refLine[refPos] - 3, blackPixels); 7249 blackPixels ^= 1; 7250 if (codingLine[this.codingPos] < columns) { 7251 if (refPos > 0) { 7252 --refPos; 7253 } else { 7254 ++refPos; 7255 } 7256 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) { 7257 refPos += 2; 7258 } 7259 } 7260 break; 7261 case twoDimVertL2: 7262 this._addPixelsNeg(refLine[refPos] - 2, blackPixels); 7263 blackPixels ^= 1; 7264 if (codingLine[this.codingPos] < columns) { 7265 if (refPos > 0) { 7266 --refPos; 7267 } else { 7268 ++refPos; 7269 } 7270 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) { 7271 refPos += 2; 7272 } 7273 } 7274 break; 7275 case twoDimVertL1: 7276 this._addPixelsNeg(refLine[refPos] - 1, blackPixels); 7277 blackPixels ^= 1; 7278 if (codingLine[this.codingPos] < columns) { 7279 if (refPos > 0) { 7280 --refPos; 7281 } else { 7282 ++refPos; 7283 } 7284 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) { 7285 refPos += 2; 7286 } 7287 } 7288 break; 7289 case ccittEOF: 7290 this._addPixels(columns, 0); 7291 this.eof = true; 7292 break; 7293 default: 7294 info("bad 2d code"); 7295 this._addPixels(columns, 0); 7296 this.err = true; 7297 } 7298 } 7299 } else { 7300 codingLine[0] = 0; 7301 this.codingPos = 0; 7302 blackPixels = 0; 7303 while (codingLine[this.codingPos] < columns) { 7304 code1 = 0; 7305 if (blackPixels) { 7306 do { 7307 code1 += code3 = this._getBlackCode(); 7308 } while (code3 >= 64); 7309 } else { 7310 do { 7311 code1 += code3 = this._getWhiteCode(); 7312 } while (code3 >= 64); 7313 } 7314 this._addPixels(codingLine[this.codingPos] + code1, blackPixels); 7315 blackPixels ^= 1; 7316 } 7317 } 7318 let gotEOL = false; 7319 if (this.byteAlign) { 7320 this.inputBits &= ~7; 7321 } 7322 if (!this.eoblock && this.row === this.rows - 1) { 7323 this.rowsDone = true; 7324 } else { 7325 code1 = this._lookBits(12); 7326 if (this.eoline) { 7327 while (code1 !== ccittEOF && code1 !== 1) { 7328 this._eatBits(1); 7329 code1 = this._lookBits(12); 7330 } 7331 } else { 7332 while (code1 === 0) { 7333 this._eatBits(1); 7334 code1 = this._lookBits(12); 7335 } 7336 } 7337 if (code1 === 1) { 7338 this._eatBits(12); 7339 gotEOL = true; 7340 } else if (code1 === ccittEOF) { 7341 this.eof = true; 7342 } 7343 } 7344 if (!this.eof && this.encoding > 0 && !this.rowsDone) { 7345 this.nextLine2D = !this._lookBits(1); 7346 this._eatBits(1); 7347 } 7348 if (this.eoblock && gotEOL && this.byteAlign) { 7349 code1 = this._lookBits(12); 7350 if (code1 === 1) { 7351 this._eatBits(12); 7352 if (this.encoding > 0) { 7353 this._lookBits(1); 7354 this._eatBits(1); 7355 } 7356 if (this.encoding >= 0) { 7357 for (i = 0; i < 4; ++i) { 7358 code1 = this._lookBits(12); 7359 if (code1 !== 1) { 7360 info("bad rtc code: " + code1); 7361 } 7362 this._eatBits(12); 7363 if (this.encoding > 0) { 7364 this._lookBits(1); 7365 this._eatBits(1); 7366 } 7367 } 7368 } 7369 this.eof = true; 7370 } 7371 } else if (this.err && this.eoline) { 7372 while (true) { 7373 code1 = this._lookBits(13); 7374 if (code1 === ccittEOF) { 7375 this.eof = true; 7376 return -1; 7377 } 7378 if (code1 >> 1 === 1) { 7379 break; 7380 } 7381 this._eatBits(1); 7382 } 7383 this._eatBits(12); 7384 if (this.encoding > 0) { 7385 this._eatBits(1); 7386 this.nextLine2D = !(code1 & 1); 7387 } 7388 } 7389 this.outputBits = codingLine[0] > 0 ? codingLine[this.codingPos = 0] : codingLine[this.codingPos = 1]; 7390 this.row++; 7391 } 7392 let c; 7393 if (this.outputBits >= 8) { 7394 c = this.codingPos & 1 ? 0 : 0xff; 7395 this.outputBits -= 8; 7396 if (this.outputBits === 0 && codingLine[this.codingPos] < columns) { 7397 this.codingPos++; 7398 this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1]; 7399 } 7400 } else { 7401 bits = 8; 7402 c = 0; 7403 do { 7404 if (typeof this.outputBits !== "number") { 7405 throw new FormatError('Invalid /CCITTFaxDecode data, "outputBits" must be a number.'); 7406 } 7407 if (this.outputBits > bits) { 7408 c <<= bits; 7409 if (!(this.codingPos & 1)) { 7410 c |= 0xff >> 8 - bits; 7411 } 7412 this.outputBits -= bits; 7413 bits = 0; 7414 } else { 7415 c <<= this.outputBits; 7416 if (!(this.codingPos & 1)) { 7417 c |= 0xff >> 8 - this.outputBits; 7418 } 7419 bits -= this.outputBits; 7420 this.outputBits = 0; 7421 if (codingLine[this.codingPos] < columns) { 7422 this.codingPos++; 7423 this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1]; 7424 } else if (bits > 0) { 7425 c <<= bits; 7426 bits = 0; 7427 } 7428 } 7429 } while (bits); 7430 } 7431 if (this.black) { 7432 c ^= 0xff; 7433 } 7434 return c; 7435 } 7436 _addPixels(a1, blackPixels) { 7437 const codingLine = this.codingLine; 7438 let codingPos = this.codingPos; 7439 if (a1 > codingLine[codingPos]) { 7440 if (a1 > this.columns) { 7441 info("row is wrong length"); 7442 this.err = true; 7443 a1 = this.columns; 7444 } 7445 if (codingPos & 1 ^ blackPixels) { 7446 ++codingPos; 7447 } 7448 codingLine[codingPos] = a1; 7449 } 7450 this.codingPos = codingPos; 7451 } 7452 _addPixelsNeg(a1, blackPixels) { 7453 const codingLine = this.codingLine; 7454 let codingPos = this.codingPos; 7455 if (a1 > codingLine[codingPos]) { 7456 if (a1 > this.columns) { 7457 info("row is wrong length"); 7458 this.err = true; 7459 a1 = this.columns; 7460 } 7461 if (codingPos & 1 ^ blackPixels) { 7462 ++codingPos; 7463 } 7464 codingLine[codingPos] = a1; 7465 } else if (a1 < codingLine[codingPos]) { 7466 if (a1 < 0) { 7467 info("invalid code"); 7468 this.err = true; 7469 a1 = 0; 7470 } 7471 while (codingPos > 0 && a1 < codingLine[codingPos - 1]) { 7472 --codingPos; 7473 } 7474 codingLine[codingPos] = a1; 7475 } 7476 this.codingPos = codingPos; 7477 } 7478 _findTableCode(start, end, table, limit) { 7479 const limitValue = limit || 0; 7480 for (let i = start; i <= end; ++i) { 7481 let code = this._lookBits(i); 7482 if (code === ccittEOF) { 7483 return [true, 1, false]; 7484 } 7485 if (i < end) { 7486 code <<= end - i; 7487 } 7488 if (!limitValue || code >= limitValue) { 7489 const p = table[code - limitValue]; 7490 if (p[0] === i) { 7491 this._eatBits(i); 7492 return [true, p[1], true]; 7493 } 7494 } 7495 } 7496 return [false, 0, false]; 7497 } 7498 _getTwoDimCode() { 7499 let code = 0; 7500 let p; 7501 if (this.eoblock) { 7502 code = this._lookBits(7); 7503 p = twoDimTable[code]; 7504 if (p?.[0] > 0) { 7505 this._eatBits(p[0]); 7506 return p[1]; 7507 } 7508 } else { 7509 const result = this._findTableCode(1, 7, twoDimTable); 7510 if (result[0] && result[2]) { 7511 return result[1]; 7512 } 7513 } 7514 info("Bad two dim code"); 7515 return ccittEOF; 7516 } 7517 _getWhiteCode() { 7518 let code = 0; 7519 let p; 7520 if (this.eoblock) { 7521 code = this._lookBits(12); 7522 if (code === ccittEOF) { 7523 return 1; 7524 } 7525 p = code >> 5 === 0 ? whiteTable1[code] : whiteTable2[code >> 3]; 7526 if (p[0] > 0) { 7527 this._eatBits(p[0]); 7528 return p[1]; 7529 } 7530 } else { 7531 let result = this._findTableCode(1, 9, whiteTable2); 7532 if (result[0]) { 7533 return result[1]; 7534 } 7535 result = this._findTableCode(11, 12, whiteTable1); 7536 if (result[0]) { 7537 return result[1]; 7538 } 7539 } 7540 info("bad white code"); 7541 this._eatBits(1); 7542 return 1; 7543 } 7544 _getBlackCode() { 7545 let code, p; 7546 if (this.eoblock) { 7547 code = this._lookBits(13); 7548 if (code === ccittEOF) { 7549 return 1; 7550 } 7551 if (code >> 7 === 0) { 7552 p = blackTable1[code]; 7553 } else if (code >> 9 === 0 && code >> 7 !== 0) { 7554 p = blackTable2[(code >> 1) - 64]; 7555 } else { 7556 p = blackTable3[code >> 7]; 7557 } 7558 if (p[0] > 0) { 7559 this._eatBits(p[0]); 7560 return p[1]; 7561 } 7562 } else { 7563 let result = this._findTableCode(2, 6, blackTable3); 7564 if (result[0]) { 7565 return result[1]; 7566 } 7567 result = this._findTableCode(7, 12, blackTable2, 64); 7568 if (result[0]) { 7569 return result[1]; 7570 } 7571 result = this._findTableCode(10, 13, blackTable1); 7572 if (result[0]) { 7573 return result[1]; 7574 } 7575 } 7576 info("bad black code"); 7577 this._eatBits(1); 7578 return 1; 7579 } 7580 _lookBits(n) { 7581 let c; 7582 while (this.inputBits < n) { 7583 if ((c = this.source.next()) === -1) { 7584 if (this.inputBits === 0) { 7585 return ccittEOF; 7586 } 7587 return this.inputBuf << n - this.inputBits & 0xffff >> 16 - n; 7588 } 7589 this.inputBuf = this.inputBuf << 8 | c; 7590 this.inputBits += 8; 7591 } 7592 return this.inputBuf >> this.inputBits - n & 0xffff >> 16 - n; 7593 } 7594 _eatBits(n) { 7595 if ((this.inputBits -= n) < 0) { 7596 this.inputBits = 0; 7597 } 7598 } 7599} 7600 7601;// ./src/core/ccitt_stream.js 7602 7603 7604 7605class CCITTFaxStream extends DecodeStream { 7606 constructor(str, maybeLength, params) { 7607 super(maybeLength); 7608 this.str = str; 7609 this.dict = str.dict; 7610 if (!(params instanceof Dict)) { 7611 params = Dict.empty; 7612 } 7613 const source = { 7614 next() { 7615 return str.getByte(); 7616 } 7617 }; 7618 this.ccittFaxDecoder = new CCITTFaxDecoder(source, { 7619 K: params.get("K"), 7620 EndOfLine: params.get("EndOfLine"), 7621 EncodedByteAlign: params.get("EncodedByteAlign"), 7622 Columns: params.get("Columns"), 7623 Rows: params.get("Rows"), 7624 EndOfBlock: params.get("EndOfBlock"), 7625 BlackIs1: params.get("BlackIs1") 7626 }); 7627 } 7628 readBlock() { 7629 while (!this.eof) { 7630 const c = this.ccittFaxDecoder.readNextChar(); 7631 if (c === -1) { 7632 this.eof = true; 7633 return; 7634 } 7635 this.ensureBuffer(this.bufferLength + 1); 7636 this.buffer[this.bufferLength++] = c; 7637 } 7638 } 7639} 7640 7641;// ./src/core/flate_stream.js 7642 7643 7644 7645const codeLenCodeMap = new Int32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); 7646const lengthDecode = new Int32Array([0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f, 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073, 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102]); 7647const distDecode = new Int32Array([0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d, 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1, 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01, 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001]); 7648const fixedLitCodeTab = [new Int32Array([0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0, 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0, 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0, 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8, 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8, 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8, 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4, 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4, 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4, 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc, 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec, 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc, 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2, 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2, 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2, 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca, 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea, 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da, 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6, 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6, 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6, 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce, 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee, 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de, 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe, 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1, 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1, 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1, 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9, 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9, 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9, 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5, 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5, 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5, 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd, 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed, 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd, 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3, 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3, 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3, 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb, 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb, 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db, 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7, 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7, 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7, 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf, 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef, 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df, 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff]), 9]; 7649const fixedDistCodeTab = [new Int32Array([0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c, 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000, 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d, 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000]), 5]; 7650class FlateStream extends DecodeStream { 7651 constructor(str, maybeLength) { 7652 super(maybeLength); 7653 this.str = str; 7654 this.dict = str.dict; 7655 const cmf = str.getByte(); 7656 const flg = str.getByte(); 7657 if (cmf === -1 || flg === -1) { 7658 throw new FormatError(`Invalid header in flate stream: ${cmf}, ${flg}`); 7659 } 7660 if ((cmf & 0x0f) !== 0x08) { 7661 throw new FormatError(`Unknown compression method in flate stream: ${cmf}, ${flg}`); 7662 } 7663 if (((cmf << 8) + flg) % 31 !== 0) { 7664 throw new FormatError(`Bad FCHECK in flate stream: ${cmf}, ${flg}`); 7665 } 7666 if (flg & 0x20) { 7667 throw new FormatError(`FDICT bit set in flate stream: ${cmf}, ${flg}`); 7668 } 7669 this.codeSize = 0; 7670 this.codeBuf = 0; 7671 } 7672 async getImageData(length, _decoderOptions) { 7673 const data = await this.asyncGetBytes(); 7674 if (!data) { 7675 return this.getBytes(length); 7676 } 7677 if (data.length <= length) { 7678 return data; 7679 } 7680 return data.subarray(0, length); 7681 } 7682 async asyncGetBytes() { 7683 this.str.reset(); 7684 const bytes = this.str.getBytes(); 7685 try { 7686 const { 7687 readable, 7688 writable 7689 } = new DecompressionStream("deflate"); 7690 const writer = writable.getWriter(); 7691 await writer.ready; 7692 writer.write(bytes).then(async () => { 7693 await writer.ready; 7694 await writer.close(); 7695 }).catch(() => {}); 7696 const chunks = []; 7697 let totalLength = 0; 7698 for await (const chunk of readable) { 7699 chunks.push(chunk); 7700 totalLength += chunk.byteLength; 7701 } 7702 const data = new Uint8Array(totalLength); 7703 let offset = 0; 7704 for (const chunk of chunks) { 7705 data.set(chunk, offset); 7706 offset += chunk.byteLength; 7707 } 7708 return data; 7709 } catch { 7710 this.str = new Stream(bytes, 2, bytes.length, this.str.dict); 7711 this.reset(); 7712 return null; 7713 } 7714 } 7715 get isAsync() { 7716 return true; 7717 } 7718 getBits(bits) { 7719 const str = this.str; 7720 let codeSize = this.codeSize; 7721 let codeBuf = this.codeBuf; 7722 let b; 7723 while (codeSize < bits) { 7724 if ((b = str.getByte()) === -1) { 7725 throw new FormatError("Bad encoding in flate stream"); 7726 } 7727 codeBuf |= b << codeSize; 7728 codeSize += 8; 7729 } 7730 b = codeBuf & (1 << bits) - 1; 7731 this.codeBuf = codeBuf >> bits; 7732 this.codeSize = codeSize -= bits; 7733 return b; 7734 } 7735 getCode(table) { 7736 const str = this.str; 7737 const codes = table[0]; 7738 const maxLen = table[1]; 7739 let codeSize = this.codeSize; 7740 let codeBuf = this.codeBuf; 7741 let b; 7742 while (codeSize < maxLen) { 7743 if ((b = str.getByte()) === -1) { 7744 break; 7745 } 7746 codeBuf |= b << codeSize; 7747 codeSize += 8; 7748 } 7749 const code = codes[codeBuf & (1 << maxLen) - 1]; 7750 const codeLen = code >> 16; 7751 const codeVal = code & 0xffff; 7752 if (codeLen < 1 || codeSize < codeLen) { 7753 throw new FormatError("Bad encoding in flate stream"); 7754 } 7755 this.codeBuf = codeBuf >> codeLen; 7756 this.codeSize = codeSize - codeLen; 7757 return codeVal; 7758 } 7759 generateHuffmanTable(lengths) { 7760 const n = lengths.length; 7761 let maxLen = 0; 7762 let i; 7763 for (i = 0; i < n; ++i) { 7764 if (lengths[i] > maxLen) { 7765 maxLen = lengths[i]; 7766 } 7767 } 7768 const size = 1 << maxLen; 7769 const codes = new Int32Array(size); 7770 for (let len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) { 7771 for (let val = 0; val < n; ++val) { 7772 if (lengths[val] === len) { 7773 let code2 = 0; 7774 let t = code; 7775 for (i = 0; i < len; ++i) { 7776 code2 = code2 << 1 | t & 1; 7777 t >>= 1; 7778 } 7779 for (i = code2; i < size; i += skip) { 7780 codes[i] = len << 16 | val; 7781 } 7782 ++code; 7783 } 7784 } 7785 } 7786 return [codes, maxLen]; 7787 } 7788 #endsStreamOnError(err) { 7789 info(err); 7790 this.eof = true; 7791 } 7792 readBlock() { 7793 let buffer, hdr, len; 7794 const str = this.str; 7795 try { 7796 hdr = this.getBits(3); 7797 } catch (ex) { 7798 this.#endsStreamOnError(ex.message); 7799 return; 7800 } 7801 if (hdr & 1) { 7802 this.eof = true; 7803 } 7804 hdr >>= 1; 7805 if (hdr === 0) { 7806 let b; 7807 if ((b = str.getByte()) === -1) { 7808 this.#endsStreamOnError("Bad block header in flate stream"); 7809 return; 7810 } 7811 let blockLen = b; 7812 if ((b = str.getByte()) === -1) { 7813 this.#endsStreamOnError("Bad block header in flate stream"); 7814 return; 7815 } 7816 blockLen |= b << 8; 7817 if ((b = str.getByte()) === -1) { 7818 this.#endsStreamOnError("Bad block header in flate stream"); 7819 return; 7820 } 7821 let check = b; 7822 if ((b = str.getByte()) === -1) { 7823 this.#endsStreamOnError("Bad block header in flate stream"); 7824 return; 7825 } 7826 check |= b << 8; 7827 if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) { 7828 throw new FormatError("Bad uncompressed block length in flate stream"); 7829 } 7830 this.codeBuf = 0; 7831 this.codeSize = 0; 7832 const bufferLength = this.bufferLength, 7833 end = bufferLength + blockLen; 7834 buffer = this.ensureBuffer(end); 7835 this.bufferLength = end; 7836 if (blockLen === 0) { 7837 if (str.peekByte() === -1) { 7838 this.eof = true; 7839 } 7840 } else { 7841 const block = str.getBytes(blockLen); 7842 buffer.set(block, bufferLength); 7843 if (block.length < blockLen) { 7844 this.eof = true; 7845 } 7846 } 7847 return; 7848 } 7849 let litCodeTable; 7850 let distCodeTable; 7851 if (hdr === 1) { 7852 litCodeTable = fixedLitCodeTab; 7853 distCodeTable = fixedDistCodeTab; 7854 } else if (hdr === 2) { 7855 const numLitCodes = this.getBits(5) + 257; 7856 const numDistCodes = this.getBits(5) + 1; 7857 const numCodeLenCodes = this.getBits(4) + 4; 7858 const codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length); 7859 let i; 7860 for (i = 0; i < numCodeLenCodes; ++i) { 7861 codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3); 7862 } 7863 const codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths); 7864 len = 0; 7865 i = 0; 7866 const codes = numLitCodes + numDistCodes; 7867 const codeLengths = new Uint8Array(codes); 7868 let bitsLength, bitsOffset, what; 7869 while (i < codes) { 7870 const code = this.getCode(codeLenCodeTab); 7871 if (code === 16) { 7872 bitsLength = 2; 7873 bitsOffset = 3; 7874 what = len; 7875 } else if (code === 17) { 7876 bitsLength = 3; 7877 bitsOffset = 3; 7878 what = len = 0; 7879 } else if (code === 18) { 7880 bitsLength = 7; 7881 bitsOffset = 11; 7882 what = len = 0; 7883 } else { 7884 codeLengths[i++] = len = code; 7885 continue; 7886 } 7887 let repeatLength = this.getBits(bitsLength) + bitsOffset; 7888 while (repeatLength-- > 0) { 7889 codeLengths[i++] = what; 7890 } 7891 } 7892 litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes)); 7893 distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes)); 7894 } else { 7895 throw new FormatError("Unknown block type in flate stream"); 7896 } 7897 buffer = this.buffer; 7898 let limit = buffer ? buffer.length : 0; 7899 let pos = this.bufferLength; 7900 while (true) { 7901 let code1 = this.getCode(litCodeTable); 7902 if (code1 < 256) { 7903 if (pos + 1 >= limit) { 7904 buffer = this.ensureBuffer(pos + 1); 7905 limit = buffer.length; 7906 } 7907 buffer[pos++] = code1; 7908 continue; 7909 } 7910 if (code1 === 256) { 7911 this.bufferLength = pos; 7912 return; 7913 } 7914 code1 -= 257; 7915 code1 = lengthDecode[code1]; 7916 let code2 = code1 >> 16; 7917 if (code2 > 0) { 7918 code2 = this.getBits(code2); 7919 } 7920 len = (code1 & 0xffff) + code2; 7921 code1 = this.getCode(distCodeTable); 7922 code1 = distDecode[code1]; 7923 code2 = code1 >> 16; 7924 if (code2 > 0) { 7925 code2 = this.getBits(code2); 7926 } 7927 const dist = (code1 & 0xffff) + code2; 7928 if (pos + len >= limit) { 7929 buffer = this.ensureBuffer(pos + len); 7930 limit = buffer.length; 7931 } 7932 for (let k = 0; k < len; ++k, ++pos) { 7933 buffer[pos] = buffer[pos - dist]; 7934 } 7935 } 7936 } 7937} 7938 7939;// ./src/core/arithmetic_decoder.js 7940const QeTable = [{ 7941 qe: 0x5601, 7942 nmps: 1, 7943 nlps: 1, 7944 switchFlag: 1 7945}, { 7946 qe: 0x3401, 7947 nmps: 2, 7948 nlps: 6, 7949 switchFlag: 0 7950}, { 7951 qe: 0x1801, 7952 nmps: 3, 7953 nlps: 9, 7954 switchFlag: 0 7955}, { 7956 qe: 0x0ac1, 7957 nmps: 4, 7958 nlps: 12, 7959 switchFlag: 0 7960}, { 7961 qe: 0x0521, 7962 nmps: 5, 7963 nlps: 29, 7964 switchFlag: 0 7965}, { 7966 qe: 0x0221, 7967 nmps: 38, 7968 nlps: 33, 7969 switchFlag: 0 7970}, { 7971 qe: 0x5601, 7972 nmps: 7, 7973 nlps: 6, 7974 switchFlag: 1 7975}, { 7976 qe: 0x5401, 7977 nmps: 8, 7978 nlps: 14, 7979 switchFlag: 0 7980}, { 7981 qe: 0x4801, 7982 nmps: 9, 7983 nlps: 14, 7984 switchFlag: 0 7985}, { 7986 qe: 0x3801, 7987 nmps: 10, 7988 nlps: 14, 7989 switchFlag: 0 7990}, { 7991 qe: 0x3001, 7992 nmps: 11, 7993 nlps: 17, 7994 switchFlag: 0 7995}, { 7996 qe: 0x2401, 7997 nmps: 12, 7998 nlps: 18, 7999 switchFlag: 0 8000}, { 8001 qe: 0x1c01, 8002 nmps: 13, 8003 nlps: 20, 8004 switchFlag: 0 8005}, { 8006 qe: 0x1601, 8007 nmps: 29, 8008 nlps: 21, 8009 switchFlag: 0 8010}, { 8011 qe: 0x5601, 8012 nmps: 15, 8013 nlps: 14, 8014 switchFlag: 1 8015}, { 8016 qe: 0x5401, 8017 nmps: 16, 8018 nlps: 14, 8019 switchFlag: 0 8020}, { 8021 qe: 0x5101, 8022 nmps: 17, 8023 nlps: 15, 8024 switchFlag: 0 8025}, { 8026 qe: 0x4801, 8027 nmps: 18, 8028 nlps: 16, 8029 switchFlag: 0 8030}, { 8031 qe: 0x3801, 8032 nmps: 19, 8033 nlps: 17, 8034 switchFlag: 0 8035}, { 8036 qe: 0x3401, 8037 nmps: 20, 8038 nlps: 18, 8039 switchFlag: 0 8040}, { 8041 qe: 0x3001, 8042 nmps: 21, 8043 nlps: 19, 8044 switchFlag: 0 8045}, { 8046 qe: 0x2801, 8047 nmps: 22, 8048 nlps: 19, 8049 switchFlag: 0 8050}, { 8051 qe: 0x2401, 8052 nmps: 23, 8053 nlps: 20, 8054 switchFlag: 0 8055}, { 8056 qe: 0x2201, 8057 nmps: 24, 8058 nlps: 21, 8059 switchFlag: 0 8060}, { 8061 qe: 0x1c01, 8062 nmps: 25, 8063 nlps: 22, 8064 switchFlag: 0 8065}, { 8066 qe: 0x1801, 8067 nmps: 26, 8068 nlps: 23, 8069 switchFlag: 0 8070}, { 8071 qe: 0x1601, 8072 nmps: 27, 8073 nlps: 24, 8074 switchFlag: 0 8075}, { 8076 qe: 0x1401, 8077 nmps: 28, 8078 nlps: 25, 8079 switchFlag: 0 8080}, { 8081 qe: 0x1201, 8082 nmps: 29, 8083 nlps: 26, 8084 switchFlag: 0 8085}, { 8086 qe: 0x1101, 8087 nmps: 30, 8088 nlps: 27, 8089 switchFlag: 0 8090}, { 8091 qe: 0x0ac1, 8092 nmps: 31, 8093 nlps: 28, 8094 switchFlag: 0 8095}, { 8096 qe: 0x09c1, 8097 nmps: 32, 8098 nlps: 29, 8099 switchFlag: 0 8100}, { 8101 qe: 0x08a1, 8102 nmps: 33, 8103 nlps: 30, 8104 switchFlag: 0 8105}, { 8106 qe: 0x0521, 8107 nmps: 34, 8108 nlps: 31, 8109 switchFlag: 0 8110}, { 8111 qe: 0x0441, 8112 nmps: 35, 8113 nlps: 32, 8114 switchFlag: 0 8115}, { 8116 qe: 0x02a1, 8117 nmps: 36, 8118 nlps: 33, 8119 switchFlag: 0 8120}, { 8121 qe: 0x0221, 8122 nmps: 37, 8123 nlps: 34, 8124 switchFlag: 0 8125}, { 8126 qe: 0x0141, 8127 nmps: 38, 8128 nlps: 35, 8129 switchFlag: 0 8130}, { 8131 qe: 0x0111, 8132 nmps: 39, 8133 nlps: 36, 8134 switchFlag: 0 8135}, { 8136 qe: 0x0085, 8137 nmps: 40, 8138 nlps: 37, 8139 switchFlag: 0 8140}, { 8141 qe: 0x0049, 8142 nmps: 41, 8143 nlps: 38, 8144 switchFlag: 0 8145}, { 8146 qe: 0x0025, 8147 nmps: 42, 8148 nlps: 39, 8149 switchFlag: 0 8150}, { 8151 qe: 0x0015, 8152 nmps: 43, 8153 nlps: 40, 8154 switchFlag: 0 8155}, { 8156 qe: 0x0009, 8157 nmps: 44, 8158 nlps: 41, 8159 switchFlag: 0 8160}, { 8161 qe: 0x0005, 8162 nmps: 45, 8163 nlps: 42, 8164 switchFlag: 0 8165}, { 8166 qe: 0x0001, 8167 nmps: 45, 8168 nlps: 43, 8169 switchFlag: 0 8170}, { 8171 qe: 0x5601, 8172 nmps: 46, 8173 nlps: 46, 8174 switchFlag: 0 8175}]; 8176class ArithmeticDecoder { 8177 constructor(data, start, end) { 8178 this.data = data; 8179 this.bp = start; 8180 this.dataEnd = end; 8181 this.chigh = data[start]; 8182 this.clow = 0; 8183 this.byteIn(); 8184 this.chigh = this.chigh << 7 & 0xffff | this.clow >> 9 & 0x7f; 8185 this.clow = this.clow << 7 & 0xffff; 8186 this.ct -= 7; 8187 this.a = 0x8000; 8188 } 8189 byteIn() { 8190 const data = this.data; 8191 let bp = this.bp; 8192 if (data[bp] === 0xff) { 8193 if (data[bp + 1] > 0x8f) { 8194 this.clow += 0xff00; 8195 this.ct = 8; 8196 } else { 8197 bp++; 8198 this.clow += data[bp] << 9; 8199 this.ct = 7; 8200 this.bp = bp; 8201 } 8202 } else { 8203 bp++; 8204 this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xff00; 8205 this.ct = 8; 8206 this.bp = bp; 8207 } 8208 if (this.clow > 0xffff) { 8209 this.chigh += this.clow >> 16; 8210 this.clow &= 0xffff; 8211 } 8212 } 8213 readBit(contexts, pos) { 8214 let cx_index = contexts[pos] >> 1, 8215 cx_mps = contexts[pos] & 1; 8216 const qeTableIcx = QeTable[cx_index]; 8217 const qeIcx = qeTableIcx.qe; 8218 let d; 8219 let a = this.a - qeIcx; 8220 if (this.chigh < qeIcx) { 8221 if (a < qeIcx) { 8222 a = qeIcx; 8223 d = cx_mps; 8224 cx_index = qeTableIcx.nmps; 8225 } else { 8226 a = qeIcx; 8227 d = 1 ^ cx_mps; 8228 if (qeTableIcx.switchFlag === 1) { 8229 cx_mps = d; 8230 } 8231 cx_index = qeTableIcx.nlps; 8232 } 8233 } else { 8234 this.chigh -= qeIcx; 8235 if ((a & 0x8000) !== 0) { 8236 this.a = a; 8237 return cx_mps; 8238 } 8239 if (a < qeIcx) { 8240 d = 1 ^ cx_mps; 8241 if (qeTableIcx.switchFlag === 1) { 8242 cx_mps = d; 8243 } 8244 cx_index = qeTableIcx.nlps; 8245 } else { 8246 d = cx_mps; 8247 cx_index = qeTableIcx.nmps; 8248 } 8249 } 8250 do { 8251 if (this.ct === 0) { 8252 this.byteIn(); 8253 } 8254 a <<= 1; 8255 this.chigh = this.chigh << 1 & 0xffff | this.clow >> 15 & 1; 8256 this.clow = this.clow << 1 & 0xffff; 8257 this.ct--; 8258 } while ((a & 0x8000) === 0); 8259 this.a = a; 8260 contexts[pos] = cx_index << 1 | cx_mps; 8261 return d; 8262 } 8263} 8264 8265;// ./src/core/jbig2.js 8266 8267 8268 8269 8270class Jbig2Error extends BaseException { 8271 constructor(msg) { 8272 super(msg, "Jbig2Error"); 8273 } 8274} 8275class ContextCache { 8276 getContexts(id) { 8277 if (id in this) { 8278 return this[id]; 8279 } 8280 return this[id] = new Int8Array(1 << 16); 8281 } 8282} 8283class DecodingContext { 8284 constructor(data, start, end) { 8285 this.data = data; 8286 this.start = start; 8287 this.end = end; 8288 } 8289 get decoder() { 8290 const decoder = new ArithmeticDecoder(this.data, this.start, this.end); 8291 return shadow(this, "decoder", decoder); 8292 } 8293 get contextCache() { 8294 const cache = new ContextCache(); 8295 return shadow(this, "contextCache", cache); 8296 } 8297} 8298function decodeInteger(contextCache, procedure, decoder) { 8299 const contexts = contextCache.getContexts(procedure); 8300 let prev = 1; 8301 function readBits(length) { 8302 let v = 0; 8303 for (let i = 0; i < length; i++) { 8304 const bit = decoder.readBit(contexts, prev); 8305 prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256; 8306 v = v << 1 | bit; 8307 } 8308 return v >>> 0; 8309 } 8310 const sign = readBits(1); 8311 const value = readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(32) + 4436 : readBits(12) + 340 : readBits(8) + 84 : readBits(6) + 20 : readBits(4) + 4 : readBits(2); 8312 let signedValue; 8313 if (sign === 0) { 8314 signedValue = value; 8315 } else if (value > 0) { 8316 signedValue = -value; 8317 } 8318 if (signedValue >= MIN_INT_32 && signedValue <= MAX_INT_32) { 8319 return signedValue; 8320 } 8321 return null; 8322} 8323function decodeIAID(contextCache, decoder, codeLength) { 8324 const contexts = contextCache.getContexts("IAID"); 8325 let prev = 1; 8326 for (let i = 0; i < codeLength; i++) { 8327 const bit = decoder.readBit(contexts, prev); 8328 prev = prev << 1 | bit; 8329 } 8330 if (codeLength < 31) { 8331 return prev & (1 << codeLength) - 1; 8332 } 8333 return prev & 0x7fffffff; 8334} 8335const SegmentTypes = ["SymbolDictionary", null, null, null, "IntermediateTextRegion", null, "ImmediateTextRegion", "ImmediateLosslessTextRegion", null, null, null, null, null, null, null, null, "PatternDictionary", null, null, null, "IntermediateHalftoneRegion", null, "ImmediateHalftoneRegion", "ImmediateLosslessHalftoneRegion", null, null, null, null, null, null, null, null, null, null, null, null, "IntermediateGenericRegion", null, "ImmediateGenericRegion", "ImmediateLosslessGenericRegion", "IntermediateGenericRefinementRegion", null, "ImmediateGenericRefinementRegion", "ImmediateLosslessGenericRefinementRegion", null, null, null, null, "PageInformation", "EndOfPage", "EndOfStripe", "EndOfFile", "Profiles", "Tables", null, null, null, null, null, null, null, null, "Extension"]; 8336const CodingTemplates = [[{ 8337 x: -1, 8338 y: -2 8339}, { 8340 x: 0, 8341 y: -2 8342}, { 8343 x: 1, 8344 y: -2 8345}, { 8346 x: -2, 8347 y: -1 8348}, { 8349 x: -1, 8350 y: -1 8351}, { 8352 x: 0, 8353 y: -1 8354}, { 8355 x: 1, 8356 y: -1 8357}, { 8358 x: 2, 8359 y: -1 8360}, { 8361 x: -4, 8362 y: 0 8363}, { 8364 x: -3, 8365 y: 0 8366}, { 8367 x: -2, 8368 y: 0 8369}, { 8370 x: -1, 8371 y: 0 8372}], [{ 8373 x: -1, 8374 y: -2 8375}, { 8376 x: 0, 8377 y: -2 8378}, { 8379 x: 1, 8380 y: -2 8381}, { 8382 x: 2, 8383 y: -2 8384}, { 8385 x: -2, 8386 y: -1 8387}, { 8388 x: -1, 8389 y: -1 8390}, { 8391 x: 0, 8392 y: -1 8393}, { 8394 x: 1, 8395 y: -1 8396}, { 8397 x: 2, 8398 y: -1 8399}, { 8400 x: -3, 8401 y: 0 8402}, { 8403 x: -2, 8404 y: 0 8405}, { 8406 x: -1, 8407 y: 0 8408}], [{ 8409 x: -1, 8410 y: -2 8411}, { 8412 x: 0, 8413 y: -2 8414}, { 8415 x: 1, 8416 y: -2 8417}, { 8418 x: -2, 8419 y: -1 8420}, { 8421 x: -1, 8422 y: -1 8423}, { 8424 x: 0, 8425 y: -1 8426}, { 8427 x: 1, 8428 y: -1 8429}, { 8430 x: -2, 8431 y: 0 8432}, { 8433 x: -1, 8434 y: 0 8435}], [{ 8436 x: -3, 8437 y: -1 8438}, { 8439 x: -2, 8440 y: -1 8441}, { 8442 x: -1, 8443 y: -1 8444}, { 8445 x: 0, 8446 y: -1 8447}, { 8448 x: 1, 8449 y: -1 8450}, { 8451 x: -4, 8452 y: 0 8453}, { 8454 x: -3, 8455 y: 0 8456}, { 8457 x: -2, 8458 y: 0 8459}, { 8460 x: -1, 8461 y: 0 8462}]]; 8463const RefinementTemplates = [{ 8464 coding: [{ 8465 x: 0, 8466 y: -1 8467 }, { 8468 x: 1, 8469 y: -1 8470 }, { 8471 x: -1, 8472 y: 0 8473 }], 8474 reference: [{ 8475 x: 0, 8476 y: -1 8477 }, { 8478 x: 1, 8479 y: -1 8480 }, { 8481 x: -1, 8482 y: 0 8483 }, { 8484 x: 0, 8485 y: 0 8486 }, { 8487 x: 1, 8488 y: 0 8489 }, { 8490 x: -1, 8491 y: 1 8492 }, { 8493 x: 0, 8494 y: 1 8495 }, { 8496 x: 1, 8497 y: 1 8498 }] 8499}, { 8500 coding: [{ 8501 x: -1, 8502 y: -1 8503 }, { 8504 x: 0, 8505 y: -1 8506 }, { 8507 x: 1, 8508 y: -1 8509 }, { 8510 x: -1, 8511 y: 0 8512 }], 8513 reference: [{ 8514 x: 0, 8515 y: -1 8516 }, { 8517 x: -1, 8518 y: 0 8519 }, { 8520 x: 0, 8521 y: 0 8522 }, { 8523 x: 1, 8524 y: 0 8525 }, { 8526 x: 0, 8527 y: 1 8528 }, { 8529 x: 1, 8530 y: 1 8531 }] 8532}]; 8533const ReusedContexts = [0x9b25, 0x0795, 0x00e5, 0x0195]; 8534const RefinementReusedContexts = [0x0020, 0x0008]; 8535function decodeBitmapTemplate0(width, height, decodingContext) { 8536 const decoder = decodingContext.decoder; 8537 const contexts = decodingContext.contextCache.getContexts("GB"); 8538 const bitmap = []; 8539 let contextLabel, i, j, pixel, row, row1, row2; 8540 const OLD_PIXEL_MASK = 0x7bf7; 8541 for (i = 0; i < height; i++) { 8542 row = bitmap[i] = new Uint8Array(width); 8543 row1 = i < 1 ? row : bitmap[i - 1]; 8544 row2 = i < 2 ? row : bitmap[i - 2]; 8545 contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4; 8546 for (j = 0; j < width; j++) { 8547 row[j] = pixel = decoder.readBit(contexts, contextLabel); 8548 contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel; 8549 } 8550 } 8551 return bitmap; 8552} 8553function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) { 8554 if (mmr) { 8555 const input = new Reader(decodingContext.data, decodingContext.start, decodingContext.end); 8556 return decodeMMRBitmap(input, width, height, false); 8557 } 8558 if (templateIndex === 0 && !skip && !prediction && at.length === 4 && at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 && at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) { 8559 return decodeBitmapTemplate0(width, height, decodingContext); 8560 } 8561 const useskip = !!skip; 8562 const template = CodingTemplates[templateIndex].concat(at); 8563 template.sort((a, b) => a.y - b.y || a.x - b.x); 8564 const templateLength = template.length; 8565 const templateX = new Int8Array(templateLength); 8566 const templateY = new Int8Array(templateLength); 8567 const changingTemplateEntries = []; 8568 let reuseMask = 0, 8569 minX = 0, 8570 maxX = 0, 8571 minY = 0; 8572 let c, k; 8573 for (k = 0; k < templateLength; k++) { 8574 templateX[k] = template[k].x; 8575 templateY[k] = template[k].y; 8576 minX = Math.min(minX, template[k].x); 8577 maxX = Math.max(maxX, template[k].x); 8578 minY = Math.min(minY, template[k].y); 8579 if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) { 8580 reuseMask |= 1 << templateLength - 1 - k; 8581 } else { 8582 changingTemplateEntries.push(k); 8583 } 8584 } 8585 const changingEntriesLength = changingTemplateEntries.length; 8586 const changingTemplateX = new Int8Array(changingEntriesLength); 8587 const changingTemplateY = new Int8Array(changingEntriesLength); 8588 const changingTemplateBit = new Uint16Array(changingEntriesLength); 8589 for (c = 0; c < changingEntriesLength; c++) { 8590 k = changingTemplateEntries[c]; 8591 changingTemplateX[c] = template[k].x; 8592 changingTemplateY[c] = template[k].y; 8593 changingTemplateBit[c] = 1 << templateLength - 1 - k; 8594 } 8595 const sbb_left = -minX; 8596 const sbb_top = -minY; 8597 const sbb_right = width - maxX; 8598 const pseudoPixelContext = ReusedContexts[templateIndex]; 8599 let row = new Uint8Array(width); 8600 const bitmap = []; 8601 const decoder = decodingContext.decoder; 8602 const contexts = decodingContext.contextCache.getContexts("GB"); 8603 let ltp = 0, 8604 j, 8605 i0, 8606 j0, 8607 contextLabel = 0, 8608 bit, 8609 shift; 8610 for (let i = 0; i < height; i++) { 8611 if (prediction) { 8612 const sltp = decoder.readBit(contexts, pseudoPixelContext); 8613 ltp ^= sltp; 8614 if (ltp) { 8615 bitmap.push(row); 8616 continue; 8617 } 8618 } 8619 row = new Uint8Array(row); 8620 bitmap.push(row); 8621 for (j = 0; j < width; j++) { 8622 if (useskip && skip[i][j]) { 8623 row[j] = 0; 8624 continue; 8625 } 8626 if (j >= sbb_left && j < sbb_right && i >= sbb_top) { 8627 contextLabel = contextLabel << 1 & reuseMask; 8628 for (k = 0; k < changingEntriesLength; k++) { 8629 i0 = i + changingTemplateY[k]; 8630 j0 = j + changingTemplateX[k]; 8631 bit = bitmap[i0][j0]; 8632 if (bit) { 8633 bit = changingTemplateBit[k]; 8634 contextLabel |= bit; 8635 } 8636 } 8637 } else { 8638 contextLabel = 0; 8639 shift = templateLength - 1; 8640 for (k = 0; k < templateLength; k++, shift--) { 8641 j0 = j + templateX[k]; 8642 if (j0 >= 0 && j0 < width) { 8643 i0 = i + templateY[k]; 8644 if (i0 >= 0) { 8645 bit = bitmap[i0][j0]; 8646 if (bit) { 8647 contextLabel |= bit << shift; 8648 } 8649 } 8650 } 8651 } 8652 } 8653 const pixel = decoder.readBit(contexts, contextLabel); 8654 row[j] = pixel; 8655 } 8656 } 8657 return bitmap; 8658} 8659function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) { 8660 let codingTemplate = RefinementTemplates[templateIndex].coding; 8661 if (templateIndex === 0) { 8662 codingTemplate = codingTemplate.concat([at[0]]); 8663 } 8664 const codingTemplateLength = codingTemplate.length; 8665 const codingTemplateX = new Int32Array(codingTemplateLength); 8666 const codingTemplateY = new Int32Array(codingTemplateLength); 8667 let k; 8668 for (k = 0; k < codingTemplateLength; k++) { 8669 codingTemplateX[k] = codingTemplate[k].x; 8670 codingTemplateY[k] = codingTemplate[k].y; 8671 } 8672 let referenceTemplate = RefinementTemplates[templateIndex].reference; 8673 if (templateIndex === 0) { 8674 referenceTemplate = referenceTemplate.concat([at[1]]); 8675 } 8676 const referenceTemplateLength = referenceTemplate.length; 8677 const referenceTemplateX = new Int32Array(referenceTemplateLength); 8678 const referenceTemplateY = new Int32Array(referenceTemplateLength); 8679 for (k = 0; k < referenceTemplateLength; k++) { 8680 referenceTemplateX[k] = referenceTemplate[k].x; 8681 referenceTemplateY[k] = referenceTemplate[k].y; 8682 } 8683 const referenceWidth = referenceBitmap[0].length; 8684 const referenceHeight = referenceBitmap.length; 8685 const pseudoPixelContext = RefinementReusedContexts[templateIndex]; 8686 const bitmap = []; 8687 const decoder = decodingContext.decoder; 8688 const contexts = decodingContext.contextCache.getContexts("GR"); 8689 let ltp = 0; 8690 for (let i = 0; i < height; i++) { 8691 if (prediction) { 8692 const sltp = decoder.readBit(contexts, pseudoPixelContext); 8693 ltp ^= sltp; 8694 if (ltp) { 8695 throw new Jbig2Error("prediction is not supported"); 8696 } 8697 } 8698 const row = new Uint8Array(width); 8699 bitmap.push(row); 8700 for (let j = 0; j < width; j++) { 8701 let i0, j0; 8702 let contextLabel = 0; 8703 for (k = 0; k < codingTemplateLength; k++) { 8704 i0 = i + codingTemplateY[k]; 8705 j0 = j + codingTemplateX[k]; 8706 if (i0 < 0 || j0 < 0 || j0 >= width) { 8707 contextLabel <<= 1; 8708 } else { 8709 contextLabel = contextLabel << 1 | bitmap[i0][j0]; 8710 } 8711 } 8712 for (k = 0; k < referenceTemplateLength; k++) { 8713 i0 = i + referenceTemplateY[k] - offsetY; 8714 j0 = j + referenceTemplateX[k] - offsetX; 8715 if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) { 8716 contextLabel <<= 1; 8717 } else { 8718 contextLabel = contextLabel << 1 | referenceBitmap[i0][j0]; 8719 } 8720 } 8721 const pixel = decoder.readBit(contexts, contextLabel); 8722 row[j] = pixel; 8723 } 8724 } 8725 return bitmap; 8726} 8727function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext, huffmanInput) { 8728 if (huffman && refinement) { 8729 throw new Jbig2Error("symbol refinement with Huffman is not supported"); 8730 } 8731 const newSymbols = []; 8732 let currentHeight = 0; 8733 let symbolCodeLength = log2(symbols.length + numberOfNewSymbols); 8734 const decoder = decodingContext.decoder; 8735 const contextCache = decodingContext.contextCache; 8736 let tableB1, symbolWidths; 8737 if (huffman) { 8738 tableB1 = getStandardTable(1); 8739 symbolWidths = []; 8740 symbolCodeLength = Math.max(symbolCodeLength, 1); 8741 } 8742 while (newSymbols.length < numberOfNewSymbols) { 8743 const deltaHeight = huffman ? huffmanTables.tableDeltaHeight.decode(huffmanInput) : decodeInteger(contextCache, "IADH", decoder); 8744 currentHeight += deltaHeight; 8745 let currentWidth = 0, 8746 totalWidth = 0; 8747 const firstSymbol = huffman ? symbolWidths.length : 0; 8748 while (true) { 8749 const deltaWidth = huffman ? huffmanTables.tableDeltaWidth.decode(huffmanInput) : decodeInteger(contextCache, "IADW", decoder); 8750 if (deltaWidth === null) { 8751 break; 8752 } 8753 currentWidth += deltaWidth; 8754 totalWidth += currentWidth; 8755 let bitmap; 8756 if (refinement) { 8757 const numberOfInstances = decodeInteger(contextCache, "IAAI", decoder); 8758 if (numberOfInstances > 1) { 8759 bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, symbols.concat(newSymbols), symbolCodeLength, 0, 0, 1, 0, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, 0, huffmanInput); 8760 } else { 8761 const symbolId = decodeIAID(contextCache, decoder, symbolCodeLength); 8762 const rdx = decodeInteger(contextCache, "IARDX", decoder); 8763 const rdy = decodeInteger(contextCache, "IARDY", decoder); 8764 const symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length]; 8765 bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext); 8766 } 8767 newSymbols.push(bitmap); 8768 } else if (huffman) { 8769 symbolWidths.push(currentWidth); 8770 } else { 8771 bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext); 8772 newSymbols.push(bitmap); 8773 } 8774 } 8775 if (huffman && !refinement) { 8776 const bitmapSize = huffmanTables.tableBitmapSize.decode(huffmanInput); 8777 huffmanInput.byteAlign(); 8778 let collectiveBitmap; 8779 if (bitmapSize === 0) { 8780 collectiveBitmap = readUncompressedBitmap(huffmanInput, totalWidth, currentHeight); 8781 } else { 8782 const originalEnd = huffmanInput.end; 8783 const bitmapEnd = huffmanInput.position + bitmapSize; 8784 huffmanInput.end = bitmapEnd; 8785 collectiveBitmap = decodeMMRBitmap(huffmanInput, totalWidth, currentHeight, false); 8786 huffmanInput.end = originalEnd; 8787 huffmanInput.position = bitmapEnd; 8788 } 8789 const numberOfSymbolsDecoded = symbolWidths.length; 8790 if (firstSymbol === numberOfSymbolsDecoded - 1) { 8791 newSymbols.push(collectiveBitmap); 8792 } else { 8793 let i, 8794 y, 8795 xMin = 0, 8796 xMax, 8797 bitmapWidth, 8798 symbolBitmap; 8799 for (i = firstSymbol; i < numberOfSymbolsDecoded; i++) { 8800 bitmapWidth = symbolWidths[i]; 8801 xMax = xMin + bitmapWidth; 8802 symbolBitmap = []; 8803 for (y = 0; y < currentHeight; y++) { 8804 symbolBitmap.push(collectiveBitmap[y].subarray(xMin, xMax)); 8805 } 8806 newSymbols.push(symbolBitmap); 8807 xMin = xMax; 8808 } 8809 } 8810 } 8811 } 8812 const exportedSymbols = [], 8813 flags = []; 8814 let currentFlag = false, 8815 i, 8816 ii; 8817 const totalSymbolsLength = symbols.length + numberOfNewSymbols; 8818 while (flags.length < totalSymbolsLength) { 8819 let runLength = huffman ? tableB1.decode(huffmanInput) : decodeInteger(contextCache, "IAEX", decoder); 8820 while (runLength--) { 8821 flags.push(currentFlag); 8822 } 8823 currentFlag = !currentFlag; 8824 } 8825 for (i = 0, ii = symbols.length; i < ii; i++) { 8826 if (flags[i]) { 8827 exportedSymbols.push(symbols[i]); 8828 } 8829 } 8830 for (let j = 0; j < numberOfNewSymbols; i++, j++) { 8831 if (flags[i]) { 8832 exportedSymbols.push(newSymbols[j]); 8833 } 8834 } 8835 return exportedSymbols; 8836} 8837function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, logStripSize, huffmanInput) { 8838 if (huffman && refinement) { 8839 throw new Jbig2Error("refinement with Huffman is not supported"); 8840 } 8841 const bitmap = []; 8842 let i, row; 8843 for (i = 0; i < height; i++) { 8844 row = new Uint8Array(width); 8845 if (defaultPixelValue) { 8846 row.fill(defaultPixelValue); 8847 } 8848 bitmap.push(row); 8849 } 8850 const decoder = decodingContext.decoder; 8851 const contextCache = decodingContext.contextCache; 8852 let stripT = huffman ? -huffmanTables.tableDeltaT.decode(huffmanInput) : -decodeInteger(contextCache, "IADT", decoder); 8853 let firstS = 0; 8854 i = 0; 8855 while (i < numberOfSymbolInstances) { 8856 const deltaT = huffman ? huffmanTables.tableDeltaT.decode(huffmanInput) : decodeInteger(contextCache, "IADT", decoder); 8857 stripT += deltaT; 8858 const deltaFirstS = huffman ? huffmanTables.tableFirstS.decode(huffmanInput) : decodeInteger(contextCache, "IAFS", decoder); 8859 firstS += deltaFirstS; 8860 let currentS = firstS; 8861 do { 8862 let currentT = 0; 8863 if (stripSize > 1) { 8864 currentT = huffman ? huffmanInput.readBits(logStripSize) : decodeInteger(contextCache, "IAIT", decoder); 8865 } 8866 const t = stripSize * stripT + currentT; 8867 const symbolId = huffman ? huffmanTables.symbolIDTable.decode(huffmanInput) : decodeIAID(contextCache, decoder, symbolCodeLength); 8868 const applyRefinement = refinement && (huffman ? huffmanInput.readBit() : decodeInteger(contextCache, "IARI", decoder)); 8869 let symbolBitmap = inputSymbols[symbolId]; 8870 let symbolWidth = symbolBitmap[0].length; 8871 let symbolHeight = symbolBitmap.length; 8872 if (applyRefinement) { 8873 const rdw = decodeInteger(contextCache, "IARDW", decoder); 8874 const rdh = decodeInteger(contextCache, "IARDH", decoder); 8875 const rdx = decodeInteger(contextCache, "IARDX", decoder); 8876 const rdy = decodeInteger(contextCache, "IARDY", decoder); 8877 symbolWidth += rdw; 8878 symbolHeight += rdh; 8879 symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext); 8880 } 8881 let increment = 0; 8882 if (!transposed) { 8883 if (referenceCorner > 1) { 8884 currentS += symbolWidth - 1; 8885 } else { 8886 increment = symbolWidth - 1; 8887 } 8888 } else if (!(referenceCorner & 1)) { 8889 currentS += symbolHeight - 1; 8890 } else { 8891 increment = symbolHeight - 1; 8892 } 8893 const offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1); 8894 const offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0); 8895 let s2, t2, symbolRow; 8896 if (transposed) { 8897 for (s2 = 0; s2 < symbolHeight; s2++) { 8898 row = bitmap[offsetS + s2]; 8899 if (!row) { 8900 continue; 8901 } 8902 symbolRow = symbolBitmap[s2]; 8903 const maxWidth = Math.min(width - offsetT, symbolWidth); 8904 switch (combinationOperator) { 8905 case 0: 8906 for (t2 = 0; t2 < maxWidth; t2++) { 8907 row[offsetT + t2] |= symbolRow[t2]; 8908 } 8909 break; 8910 case 2: 8911 for (t2 = 0; t2 < maxWidth; t2++) { 8912 row[offsetT + t2] ^= symbolRow[t2]; 8913 } 8914 break; 8915 default: 8916 throw new Jbig2Error(`operator ${combinationOperator} is not supported`); 8917 } 8918 } 8919 } else { 8920 for (t2 = 0; t2 < symbolHeight; t2++) { 8921 row = bitmap[offsetT + t2]; 8922 if (!row) { 8923 continue; 8924 } 8925 symbolRow = symbolBitmap[t2]; 8926 switch (combinationOperator) { 8927 case 0: 8928 for (s2 = 0; s2 < symbolWidth; s2++) { 8929 row[offsetS + s2] |= symbolRow[s2]; 8930 } 8931 break; 8932 case 2: 8933 for (s2 = 0; s2 < symbolWidth; s2++) { 8934 row[offsetS + s2] ^= symbolRow[s2]; 8935 } 8936 break; 8937 default: 8938 throw new Jbig2Error(`operator ${combinationOperator} is not supported`); 8939 } 8940 } 8941 } 8942 i++; 8943 const deltaS = huffman ? huffmanTables.tableDeltaS.decode(huffmanInput) : decodeInteger(contextCache, "IADS", decoder); 8944 if (deltaS === null) { 8945 break; 8946 } 8947 currentS += increment + deltaS + dsOffset; 8948 } while (true); 8949 } 8950 return bitmap; 8951} 8952function decodePatternDictionary(mmr, patternWidth, patternHeight, maxPatternIndex, template, decodingContext) { 8953 const at = []; 8954 if (!mmr) { 8955 at.push({ 8956 x: -patternWidth, 8957 y: 0 8958 }); 8959 if (template === 0) { 8960 at.push({ 8961 x: -3, 8962 y: -1 8963 }, { 8964 x: 2, 8965 y: -2 8966 }, { 8967 x: -2, 8968 y: -2 8969 }); 8970 } 8971 } 8972 const collectiveWidth = (maxPatternIndex + 1) * patternWidth; 8973 const collectiveBitmap = decodeBitmap(mmr, collectiveWidth, patternHeight, template, false, null, at, decodingContext); 8974 const patterns = []; 8975 for (let i = 0; i <= maxPatternIndex; i++) { 8976 const patternBitmap = []; 8977 const xMin = patternWidth * i; 8978 const xMax = xMin + patternWidth; 8979 for (let y = 0; y < patternHeight; y++) { 8980 patternBitmap.push(collectiveBitmap[y].subarray(xMin, xMax)); 8981 } 8982 patterns.push(patternBitmap); 8983 } 8984 return patterns; 8985} 8986function decodeHalftoneRegion(mmr, patterns, template, regionWidth, regionHeight, defaultPixelValue, enableSkip, combinationOperator, gridWidth, gridHeight, gridOffsetX, gridOffsetY, gridVectorX, gridVectorY, decodingContext) { 8987 const skip = null; 8988 if (enableSkip) { 8989 throw new Jbig2Error("skip is not supported"); 8990 } 8991 if (combinationOperator !== 0) { 8992 throw new Jbig2Error(`operator "${combinationOperator}" is not supported in halftone region`); 8993 } 8994 const regionBitmap = []; 8995 let i, j, row; 8996 for (i = 0; i < regionHeight; i++) { 8997 row = new Uint8Array(regionWidth); 8998 if (defaultPixelValue) { 8999 row.fill(defaultPixelValue); 9000 } 9001 regionBitmap.push(row); 9002 } 9003 const numberOfPatterns = patterns.length; 9004 const pattern0 = patterns[0]; 9005 const patternWidth = pattern0[0].length, 9006 patternHeight = pattern0.length; 9007 const bitsPerValue = log2(numberOfPatterns); 9008 const at = []; 9009 if (!mmr) { 9010 at.push({ 9011 x: template <= 1 ? 3 : 2, 9012 y: -1 9013 }); 9014 if (template === 0) { 9015 at.push({ 9016 x: -3, 9017 y: -1 9018 }, { 9019 x: 2, 9020 y: -2 9021 }, { 9022 x: -2, 9023 y: -2 9024 }); 9025 } 9026 } 9027 const grayScaleBitPlanes = []; 9028 let mmrInput, bitmap; 9029 if (mmr) { 9030 mmrInput = new Reader(decodingContext.data, decodingContext.start, decodingContext.end); 9031 } 9032 for (i = bitsPerValue - 1; i >= 0; i--) { 9033 if (mmr) { 9034 bitmap = decodeMMRBitmap(mmrInput, gridWidth, gridHeight, true); 9035 } else { 9036 bitmap = decodeBitmap(false, gridWidth, gridHeight, template, false, skip, at, decodingContext); 9037 } 9038 grayScaleBitPlanes[i] = bitmap; 9039 } 9040 let mg, ng, bit, patternIndex, patternBitmap, x, y, patternRow, regionRow; 9041 for (mg = 0; mg < gridHeight; mg++) { 9042 for (ng = 0; ng < gridWidth; ng++) { 9043 bit = 0; 9044 patternIndex = 0; 9045 for (j = bitsPerValue - 1; j >= 0; j--) { 9046 bit ^= grayScaleBitPlanes[j][mg][ng]; 9047 patternIndex |= bit << j; 9048 } 9049 patternBitmap = patterns[patternIndex]; 9050 x = gridOffsetX + mg * gridVectorY + ng * gridVectorX >> 8; 9051 y = gridOffsetY + mg * gridVectorX - ng * gridVectorY >> 8; 9052 if (x >= 0 && x + patternWidth <= regionWidth && y >= 0 && y + patternHeight <= regionHeight) { 9053 for (i = 0; i < patternHeight; i++) { 9054 regionRow = regionBitmap[y + i]; 9055 patternRow = patternBitmap[i]; 9056 for (j = 0; j < patternWidth; j++) { 9057 regionRow[x + j] |= patternRow[j]; 9058 } 9059 } 9060 } else { 9061 let regionX, regionY; 9062 for (i = 0; i < patternHeight; i++) { 9063 regionY = y + i; 9064 if (regionY < 0 || regionY >= regionHeight) { 9065 continue; 9066 } 9067 regionRow = regionBitmap[regionY]; 9068 patternRow = patternBitmap[i]; 9069 for (j = 0; j < patternWidth; j++) { 9070 regionX = x + j; 9071 if (regionX >= 0 && regionX < regionWidth) { 9072 regionRow[regionX] |= patternRow[j]; 9073 } 9074 } 9075 } 9076 } 9077 } 9078 } 9079 return regionBitmap; 9080} 9081function readSegmentHeader(data, start) { 9082 const segmentHeader = {}; 9083 segmentHeader.number = readUint32(data, start); 9084 const flags = data[start + 4]; 9085 const segmentType = flags & 0x3f; 9086 if (!SegmentTypes[segmentType]) { 9087 throw new Jbig2Error("invalid segment type: " + segmentType); 9088 } 9089 segmentHeader.type = segmentType; 9090 segmentHeader.typeName = SegmentTypes[segmentType]; 9091 segmentHeader.deferredNonRetain = !!(flags & 0x80); 9092 const pageAssociationFieldSize = !!(flags & 0x40); 9093 const referredFlags = data[start + 5]; 9094 let referredToCount = referredFlags >> 5 & 7; 9095 const retainBits = [referredFlags & 31]; 9096 let position = start + 6; 9097 if (referredFlags === 7) { 9098 referredToCount = readUint32(data, position - 1) & 0x1fffffff; 9099 position += 3; 9100 let bytes = referredToCount + 7 >> 3; 9101 retainBits[0] = data[position++]; 9102 while (--bytes > 0) { 9103 retainBits.push(data[position++]); 9104 } 9105 } else if (referredFlags === 5 || referredFlags === 6) { 9106 throw new Jbig2Error("invalid referred-to flags"); 9107 } 9108 segmentHeader.retainBits = retainBits; 9109 let referredToSegmentNumberSize = 4; 9110 if (segmentHeader.number <= 256) { 9111 referredToSegmentNumberSize = 1; 9112 } else if (segmentHeader.number <= 65536) { 9113 referredToSegmentNumberSize = 2; 9114 } 9115 const referredTo = []; 9116 let i, ii; 9117 for (i = 0; i < referredToCount; i++) { 9118 let number; 9119 if (referredToSegmentNumberSize === 1) { 9120 number = data[position]; 9121 } else if (referredToSegmentNumberSize === 2) { 9122 number = readUint16(data, position); 9123 } else { 9124 number = readUint32(data, position); 9125 } 9126 referredTo.push(number); 9127 position += referredToSegmentNumberSize; 9128 } 9129 segmentHeader.referredTo = referredTo; 9130 if (!pageAssociationFieldSize) { 9131 segmentHeader.pageAssociation = data[position++]; 9132 } else { 9133 segmentHeader.pageAssociation = readUint32(data, position); 9134 position += 4; 9135 } 9136 segmentHeader.length = readUint32(data, position); 9137 position += 4; 9138 if (segmentHeader.length === 0xffffffff) { 9139 if (segmentType === 38) { 9140 const genericRegionInfo = readRegionSegmentInformation(data, position); 9141 const genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength]; 9142 const genericRegionMmr = !!(genericRegionSegmentFlags & 1); 9143 const searchPatternLength = 6; 9144 const searchPattern = new Uint8Array(searchPatternLength); 9145 if (!genericRegionMmr) { 9146 searchPattern[0] = 0xff; 9147 searchPattern[1] = 0xac; 9148 } 9149 searchPattern[2] = genericRegionInfo.height >>> 24 & 0xff; 9150 searchPattern[3] = genericRegionInfo.height >> 16 & 0xff; 9151 searchPattern[4] = genericRegionInfo.height >> 8 & 0xff; 9152 searchPattern[5] = genericRegionInfo.height & 0xff; 9153 for (i = position, ii = data.length; i < ii; i++) { 9154 let j = 0; 9155 while (j < searchPatternLength && searchPattern[j] === data[i + j]) { 9156 j++; 9157 } 9158 if (j === searchPatternLength) { 9159 segmentHeader.length = i + searchPatternLength; 9160 break; 9161 } 9162 } 9163 if (segmentHeader.length === 0xffffffff) { 9164 throw new Jbig2Error("segment end was not found"); 9165 } 9166 } else { 9167 throw new Jbig2Error("invalid unknown segment length"); 9168 } 9169 } 9170 segmentHeader.headerEnd = position; 9171 return segmentHeader; 9172} 9173function readSegments(header, data, start, end) { 9174 const segments = []; 9175 let position = start; 9176 while (position < end) { 9177 const segmentHeader = readSegmentHeader(data, position); 9178 position = segmentHeader.headerEnd; 9179 const segment = { 9180 header: segmentHeader, 9181 data 9182 }; 9183 if (!header.randomAccess) { 9184 segment.start = position; 9185 position += segmentHeader.length; 9186 segment.end = position; 9187 } 9188 segments.push(segment); 9189 if (segmentHeader.type === 51) { 9190 break; 9191 } 9192 } 9193 if (header.randomAccess) { 9194 for (let i = 0, ii = segments.length; i < ii; i++) { 9195 segments[i].start = position; 9196 position += segments[i].header.length; 9197 segments[i].end = position; 9198 } 9199 } 9200 return segments; 9201} 9202function readRegionSegmentInformation(data, start) { 9203 return { 9204 width: readUint32(data, start), 9205 height: readUint32(data, start + 4), 9206 x: readUint32(data, start + 8), 9207 y: readUint32(data, start + 12), 9208 combinationOperator: data[start + 16] & 7 9209 }; 9210} 9211const RegionSegmentInformationFieldLength = 17; 9212function processSegment(segment, visitor) { 9213 const header = segment.header; 9214 const data = segment.data, 9215 end = segment.end; 9216 let position = segment.start; 9217 let args, at, i, atLength; 9218 switch (header.type) { 9219 case 0: 9220 const dictionary = {}; 9221 const dictionaryFlags = readUint16(data, position); 9222 dictionary.huffman = !!(dictionaryFlags & 1); 9223 dictionary.refinement = !!(dictionaryFlags & 2); 9224 dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3; 9225 dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3; 9226 dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1; 9227 dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1; 9228 dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256); 9229 dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512); 9230 dictionary.template = dictionaryFlags >> 10 & 3; 9231 dictionary.refinementTemplate = dictionaryFlags >> 12 & 1; 9232 position += 2; 9233 if (!dictionary.huffman) { 9234 atLength = dictionary.template === 0 ? 4 : 1; 9235 at = []; 9236 for (i = 0; i < atLength; i++) { 9237 at.push({ 9238 x: readInt8(data, position), 9239 y: readInt8(data, position + 1) 9240 }); 9241 position += 2; 9242 } 9243 dictionary.at = at; 9244 } 9245 if (dictionary.refinement && !dictionary.refinementTemplate) { 9246 at = []; 9247 for (i = 0; i < 2; i++) { 9248 at.push({ 9249 x: readInt8(data, position), 9250 y: readInt8(data, position + 1) 9251 }); 9252 position += 2; 9253 } 9254 dictionary.refinementAt = at; 9255 } 9256 dictionary.numberOfExportedSymbols = readUint32(data, position); 9257 position += 4; 9258 dictionary.numberOfNewSymbols = readUint32(data, position); 9259 position += 4; 9260 args = [dictionary, header.number, header.referredTo, data, position, end]; 9261 break; 9262 case 6: 9263 case 7: 9264 const textRegion = {}; 9265 textRegion.info = readRegionSegmentInformation(data, position); 9266 position += RegionSegmentInformationFieldLength; 9267 const textRegionSegmentFlags = readUint16(data, position); 9268 position += 2; 9269 textRegion.huffman = !!(textRegionSegmentFlags & 1); 9270 textRegion.refinement = !!(textRegionSegmentFlags & 2); 9271 textRegion.logStripSize = textRegionSegmentFlags >> 2 & 3; 9272 textRegion.stripSize = 1 << textRegion.logStripSize; 9273 textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3; 9274 textRegion.transposed = !!(textRegionSegmentFlags & 64); 9275 textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3; 9276 textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1; 9277 textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27; 9278 textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1; 9279 if (textRegion.huffman) { 9280 const textRegionHuffmanFlags = readUint16(data, position); 9281 position += 2; 9282 textRegion.huffmanFS = textRegionHuffmanFlags & 3; 9283 textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3; 9284 textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3; 9285 textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3; 9286 textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3; 9287 textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3; 9288 textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3; 9289 textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 0x4000); 9290 } 9291 if (textRegion.refinement && !textRegion.refinementTemplate) { 9292 at = []; 9293 for (i = 0; i < 2; i++) { 9294 at.push({ 9295 x: readInt8(data, position), 9296 y: readInt8(data, position + 1) 9297 }); 9298 position += 2; 9299 } 9300 textRegion.refinementAt = at; 9301 } 9302 textRegion.numberOfSymbolInstances = readUint32(data, position); 9303 position += 4; 9304 args = [textRegion, header.referredTo, data, position, end]; 9305 break; 9306 case 16: 9307 const patternDictionary = {}; 9308 const patternDictionaryFlags = data[position++]; 9309 patternDictionary.mmr = !!(patternDictionaryFlags & 1); 9310 patternDictionary.template = patternDictionaryFlags >> 1 & 3; 9311 patternDictionary.patternWidth = data[position++]; 9312 patternDictionary.patternHeight = data[position++]; 9313 patternDictionary.maxPatternIndex = readUint32(data, position); 9314 position += 4; 9315 args = [patternDictionary, header.number, data, position, end]; 9316 break; 9317 case 22: 9318 case 23: 9319 const halftoneRegion = {}; 9320 halftoneRegion.info = readRegionSegmentInformation(data, position); 9321 position += RegionSegmentInformationFieldLength; 9322 const halftoneRegionFlags = data[position++]; 9323 halftoneRegion.mmr = !!(halftoneRegionFlags & 1); 9324 halftoneRegion.template = halftoneRegionFlags >> 1 & 3; 9325 halftoneRegion.enableSkip = !!(halftoneRegionFlags & 8); 9326 halftoneRegion.combinationOperator = halftoneRegionFlags >> 4 & 7; 9327 halftoneRegion.defaultPixelValue = halftoneRegionFlags >> 7 & 1; 9328 halftoneRegion.gridWidth = readUint32(data, position); 9329 position += 4; 9330 halftoneRegion.gridHeight = readUint32(data, position); 9331 position += 4; 9332 halftoneRegion.gridOffsetX = readUint32(data, position) & 0xffffffff; 9333 position += 4; 9334 halftoneRegion.gridOffsetY = readUint32(data, position) & 0xffffffff; 9335 position += 4; 9336 halftoneRegion.gridVectorX = readUint16(data, position); 9337 position += 2; 9338 halftoneRegion.gridVectorY = readUint16(data, position); 9339 position += 2; 9340 args = [halftoneRegion, header.referredTo, data, position, end]; 9341 break; 9342 case 38: 9343 case 39: 9344 const genericRegion = {}; 9345 genericRegion.info = readRegionSegmentInformation(data, position); 9346 position += RegionSegmentInformationFieldLength; 9347 const genericRegionSegmentFlags = data[position++]; 9348 genericRegion.mmr = !!(genericRegionSegmentFlags & 1); 9349 genericRegion.template = genericRegionSegmentFlags >> 1 & 3; 9350 genericRegion.prediction = !!(genericRegionSegmentFlags & 8); 9351 if (!genericRegion.mmr) { 9352 atLength = genericRegion.template === 0 ? 4 : 1; 9353 at = []; 9354 for (i = 0; i < atLength; i++) { 9355 at.push({ 9356 x: readInt8(data, position), 9357 y: readInt8(data, position + 1) 9358 }); 9359 position += 2; 9360 } 9361 genericRegion.at = at; 9362 } 9363 args = [genericRegion, data, position, end]; 9364 break; 9365 case 48: 9366 const pageInfo = { 9367 width: readUint32(data, position), 9368 height: readUint32(data, position + 4), 9369 resolutionX: readUint32(data, position + 8), 9370 resolutionY: readUint32(data, position + 12) 9371 }; 9372 if (pageInfo.height === 0xffffffff) { 9373 delete pageInfo.height; 9374 } 9375 const pageSegmentFlags = data[position + 16]; 9376 readUint16(data, position + 17); 9377 pageInfo.lossless = !!(pageSegmentFlags & 1); 9378 pageInfo.refinement = !!(pageSegmentFlags & 2); 9379 pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1; 9380 pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3; 9381 pageInfo.requiresBuffer = !!(pageSegmentFlags & 32); 9382 pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64); 9383 args = [pageInfo]; 9384 break; 9385 case 49: 9386 break; 9387 case 50: 9388 break; 9389 case 51: 9390 break; 9391 case 53: 9392 args = [header.number, data, position, end]; 9393 break; 9394 case 62: 9395 break; 9396 default: 9397 throw new Jbig2Error(`segment type ${header.typeName}(${header.type}) is not implemented`); 9398 } 9399 const callbackName = "on" + header.typeName; 9400 if (callbackName in visitor) { 9401 visitor[callbackName].apply(visitor, args); 9402 } 9403} 9404function processSegments(segments, visitor) { 9405 for (let i = 0, ii = segments.length; i < ii; i++) { 9406 processSegment(segments[i], visitor); 9407 } 9408} 9409function parseJbig2Chunks(chunks) { 9410 const visitor = new SimpleSegmentVisitor(); 9411 for (let i = 0, ii = chunks.length; i < ii; i++) { 9412 const chunk = chunks[i]; 9413 const segments = readSegments({}, chunk.data, chunk.start, chunk.end); 9414 processSegments(segments, visitor); 9415 } 9416 return visitor.buffer; 9417} 9418class SimpleSegmentVisitor { 9419 onPageInformation(info) { 9420 this.currentPageInfo = info; 9421 const rowSize = info.width + 7 >> 3; 9422 const buffer = new Uint8ClampedArray(rowSize * info.height); 9423 if (info.defaultPixelValue) { 9424 buffer.fill(0xff); 9425 } 9426 this.buffer = buffer; 9427 } 9428 drawBitmap(regionInfo, bitmap) { 9429 const pageInfo = this.currentPageInfo; 9430 const width = regionInfo.width, 9431 height = regionInfo.height; 9432 const rowSize = pageInfo.width + 7 >> 3; 9433 const combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator; 9434 const buffer = this.buffer; 9435 const mask0 = 128 >> (regionInfo.x & 7); 9436 let offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3); 9437 let i, j, mask, offset; 9438 switch (combinationOperator) { 9439 case 0: 9440 for (i = 0; i < height; i++) { 9441 mask = mask0; 9442 offset = offset0; 9443 for (j = 0; j < width; j++) { 9444 if (bitmap[i][j]) { 9445 buffer[offset] |= mask; 9446 } 9447 mask >>= 1; 9448 if (!mask) { 9449 mask = 128; 9450 offset++; 9451 } 9452 } 9453 offset0 += rowSize; 9454 } 9455 break; 9456 case 2: 9457 for (i = 0; i < height; i++) { 9458 mask = mask0; 9459 offset = offset0; 9460 for (j = 0; j < width; j++) { 9461 if (bitmap[i][j]) { 9462 buffer[offset] ^= mask; 9463 } 9464 mask >>= 1; 9465 if (!mask) { 9466 mask = 128; 9467 offset++; 9468 } 9469 } 9470 offset0 += rowSize; 9471 } 9472 break; 9473 default: 9474 throw new Jbig2Error(`operator ${combinationOperator} is not supported`); 9475 } 9476 } 9477 onImmediateGenericRegion(region, data, start, end) { 9478 const regionInfo = region.info; 9479 const decodingContext = new DecodingContext(data, start, end); 9480 const bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext); 9481 this.drawBitmap(regionInfo, bitmap); 9482 } 9483 onImmediateLosslessGenericRegion() { 9484 this.onImmediateGenericRegion(...arguments); 9485 } 9486 onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) { 9487 let huffmanTables, huffmanInput; 9488 if (dictionary.huffman) { 9489 huffmanTables = getSymbolDictionaryHuffmanTables(dictionary, referredSegments, this.customTables); 9490 huffmanInput = new Reader(data, start, end); 9491 } 9492 let symbols = this.symbols; 9493 if (!symbols) { 9494 this.symbols = symbols = {}; 9495 } 9496 const inputSymbols = []; 9497 for (const referredSegment of referredSegments) { 9498 const referredSymbols = symbols[referredSegment]; 9499 if (referredSymbols) { 9500 inputSymbols.push(...referredSymbols); 9501 } 9502 } 9503 const decodingContext = new DecodingContext(data, start, end); 9504 symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext, huffmanInput); 9505 } 9506 onImmediateTextRegion(region, referredSegments, data, start, end) { 9507 const regionInfo = region.info; 9508 let huffmanTables, huffmanInput; 9509 const symbols = this.symbols; 9510 const inputSymbols = []; 9511 for (const referredSegment of referredSegments) { 9512 const referredSymbols = symbols[referredSegment]; 9513 if (referredSymbols) { 9514 inputSymbols.push(...referredSymbols); 9515 } 9516 } 9517 const symbolCodeLength = log2(inputSymbols.length); 9518 if (region.huffman) { 9519 huffmanInput = new Reader(data, start, end); 9520 huffmanTables = getTextRegionHuffmanTables(region, referredSegments, this.customTables, inputSymbols.length, huffmanInput); 9521 } 9522 const decodingContext = new DecodingContext(data, start, end); 9523 const bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext, region.logStripSize, huffmanInput); 9524 this.drawBitmap(regionInfo, bitmap); 9525 } 9526 onImmediateLosslessTextRegion() { 9527 this.onImmediateTextRegion(...arguments); 9528 } 9529 onPatternDictionary(dictionary, currentSegment, data, start, end) { 9530 let patterns = this.patterns; 9531 if (!patterns) { 9532 this.patterns = patterns = {}; 9533 } 9534 const decodingContext = new DecodingContext(data, start, end); 9535 patterns[currentSegment] = decodePatternDictionary(dictionary.mmr, dictionary.patternWidth, dictionary.patternHeight, dictionary.maxPatternIndex, dictionary.template, decodingContext); 9536 } 9537 onImmediateHalftoneRegion(region, referredSegments, data, start, end) { 9538 const patterns = this.patterns[referredSegments[0]]; 9539 const regionInfo = region.info; 9540 const decodingContext = new DecodingContext(data, start, end); 9541 const bitmap = decodeHalftoneRegion(region.mmr, patterns, region.template, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.enableSkip, region.combinationOperator, region.gridWidth, region.gridHeight, region.gridOffsetX, region.gridOffsetY, region.gridVectorX, region.gridVectorY, decodingContext); 9542 this.drawBitmap(regionInfo, bitmap); 9543 } 9544 onImmediateLosslessHalftoneRegion() { 9545 this.onImmediateHalftoneRegion(...arguments); 9546 } 9547 onTables(currentSegment, data, start, end) { 9548 let customTables = this.customTables; 9549 if (!customTables) { 9550 this.customTables = customTables = {}; 9551 } 9552 customTables[currentSegment] = decodeTablesSegment(data, start, end); 9553 } 9554} 9555class HuffmanLine { 9556 constructor(lineData) { 9557 if (lineData.length === 2) { 9558 this.isOOB = true; 9559 this.rangeLow = 0; 9560 this.prefixLength = lineData[0]; 9561 this.rangeLength = 0; 9562 this.prefixCode = lineData[1]; 9563 this.isLowerRange = false; 9564 } else { 9565 this.isOOB = false; 9566 this.rangeLow = lineData[0]; 9567 this.prefixLength = lineData[1]; 9568 this.rangeLength = lineData[2]; 9569 this.prefixCode = lineData[3]; 9570 this.isLowerRange = lineData[4] === "lower"; 9571 } 9572 } 9573} 9574class HuffmanTreeNode { 9575 constructor(line) { 9576 this.children = []; 9577 if (line) { 9578 this.isLeaf = true; 9579 this.rangeLength = line.rangeLength; 9580 this.rangeLow = line.rangeLow; 9581 this.isLowerRange = line.isLowerRange; 9582 this.isOOB = line.isOOB; 9583 } else { 9584 this.isLeaf = false; 9585 } 9586 } 9587 buildTree(line, shift) { 9588 const bit = line.prefixCode >> shift & 1; 9589 if (shift <= 0) { 9590 this.children[bit] = new HuffmanTreeNode(line); 9591 } else { 9592 let node = this.children[bit]; 9593 if (!node) { 9594 this.children[bit] = node = new HuffmanTreeNode(null); 9595 } 9596 node.buildTree(line, shift - 1); 9597 } 9598 } 9599 decodeNode(reader) { 9600 if (this.isLeaf) { 9601 if (this.isOOB) { 9602 return null; 9603 } 9604 const htOffset = reader.readBits(this.rangeLength); 9605 return this.rangeLow + (this.isLowerRange ? -htOffset : htOffset); 9606 } 9607 const node = this.children[reader.readBit()]; 9608 if (!node) { 9609 throw new Jbig2Error("invalid Huffman data"); 9610 } 9611 return node.decodeNode(reader); 9612 } 9613} 9614class HuffmanTable { 9615 constructor(lines, prefixCodesDone) { 9616 if (!prefixCodesDone) { 9617 this.assignPrefixCodes(lines); 9618 } 9619 this.rootNode = new HuffmanTreeNode(null); 9620 for (let i = 0, ii = lines.length; i < ii; i++) { 9621 const line = lines[i]; 9622 if (line.prefixLength > 0) { 9623 this.rootNode.buildTree(line, line.prefixLength - 1); 9624 } 9625 } 9626 } 9627 decode(reader) { 9628 return this.rootNode.decodeNode(reader); 9629 } 9630 assignPrefixCodes(lines) { 9631 const linesLength = lines.length; 9632 let prefixLengthMax = 0; 9633 for (let i = 0; i < linesLength; i++) { 9634 prefixLengthMax = Math.max(prefixLengthMax, lines[i].prefixLength); 9635 } 9636 const histogram = new Uint32Array(prefixLengthMax + 1); 9637 for (let i = 0; i < linesLength; i++) { 9638 histogram[lines[i].prefixLength]++; 9639 } 9640 let currentLength = 1, 9641 firstCode = 0, 9642 currentCode, 9643 currentTemp, 9644 line; 9645 histogram[0] = 0; 9646 while (currentLength <= prefixLengthMax) { 9647 firstCode = firstCode + histogram[currentLength - 1] << 1; 9648 currentCode = firstCode; 9649 currentTemp = 0; 9650 while (currentTemp < linesLength) { 9651 line = lines[currentTemp]; 9652 if (line.prefixLength === currentLength) { 9653 line.prefixCode = currentCode; 9654 currentCode++; 9655 } 9656 currentTemp++; 9657 } 9658 currentLength++; 9659 } 9660 } 9661} 9662function decodeTablesSegment(data, start, end) { 9663 const flags = data[start]; 9664 const lowestValue = readUint32(data, start + 1) & 0xffffffff; 9665 const highestValue = readUint32(data, start + 5) & 0xffffffff; 9666 const reader = new Reader(data, start + 9, end); 9667 const prefixSizeBits = (flags >> 1 & 7) + 1; 9668 const rangeSizeBits = (flags >> 4 & 7) + 1; 9669 const lines = []; 9670 let prefixLength, 9671 rangeLength, 9672 currentRangeLow = lowestValue; 9673 do { 9674 prefixLength = reader.readBits(prefixSizeBits); 9675 rangeLength = reader.readBits(rangeSizeBits); 9676 lines.push(new HuffmanLine([currentRangeLow, prefixLength, rangeLength, 0])); 9677 currentRangeLow += 1 << rangeLength; 9678 } while (currentRangeLow < highestValue); 9679 prefixLength = reader.readBits(prefixSizeBits); 9680 lines.push(new HuffmanLine([lowestValue - 1, prefixLength, 32, 0, "lower"])); 9681 prefixLength = reader.readBits(prefixSizeBits); 9682 lines.push(new HuffmanLine([highestValue, prefixLength, 32, 0])); 9683 if (flags & 1) { 9684 prefixLength = reader.readBits(prefixSizeBits); 9685 lines.push(new HuffmanLine([prefixLength, 0])); 9686 } 9687 return new HuffmanTable(lines, false); 9688} 9689const standardTablesCache = {}; 9690function getStandardTable(number) { 9691 let table = standardTablesCache[number]; 9692 if (table) { 9693 return table; 9694 } 9695 let lines; 9696 switch (number) { 9697 case 1: 9698 lines = [[0, 1, 4, 0x0], [16, 2, 8, 0x2], [272, 3, 16, 0x6], [65808, 3, 32, 0x7]]; 9699 break; 9700 case 2: 9701 lines = [[0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xe], [11, 5, 6, 0x1e], [75, 6, 32, 0x3e], [6, 0x3f]]; 9702 break; 9703 case 3: 9704 lines = [[-256, 8, 8, 0xfe], [0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xe], [11, 5, 6, 0x1e], [-257, 8, 32, 0xff, "lower"], [75, 7, 32, 0x7e], [6, 0x3e]]; 9705 break; 9706 case 4: 9707 lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xe], [12, 5, 6, 0x1e], [76, 5, 32, 0x1f]]; 9708 break; 9709 case 5: 9710 lines = [[-255, 7, 8, 0x7e], [1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xe], [12, 5, 6, 0x1e], [-256, 7, 32, 0x7f, "lower"], [76, 6, 32, 0x3e]]; 9711 break; 9712 case 6: 9713 lines = [[-2048, 5, 10, 0x1c], [-1024, 4, 9, 0x8], [-512, 4, 8, 0x9], [-256, 4, 7, 0xa], [-128, 5, 6, 0x1d], [-64, 5, 5, 0x1e], [-32, 4, 5, 0xb], [0, 2, 7, 0x0], [128, 3, 7, 0x2], [256, 3, 8, 0x3], [512, 4, 9, 0xc], [1024, 4, 10, 0xd], [-2049, 6, 32, 0x3e, "lower"], [2048, 6, 32, 0x3f]]; 9714 break; 9715 case 7: 9716 lines = [[-1024, 4, 9, 0x8], [-512, 3, 8, 0x0], [-256, 4, 7, 0x9], [-128, 5, 6, 0x1a], [-64, 5, 5, 0x1b], [-32, 4, 5, 0xa], [0, 4, 5, 0xb], [32, 5, 5, 0x1c], [64, 5, 6, 0x1d], [128, 4, 7, 0xc], [256, 3, 8, 0x1], [512, 3, 9, 0x2], [1024, 3, 10, 0x3], [-1025, 5, 32, 0x1e, "lower"], [2048, 5, 32, 0x1f]]; 9717 break; 9718 case 8: 9719 lines = [[-15, 8, 3, 0xfc], [-7, 9, 1, 0x1fc], [-5, 8, 1, 0xfd], [-3, 9, 0, 0x1fd], [-2, 7, 0, 0x7c], [-1, 4, 0, 0xa], [0, 2, 1, 0x0], [2, 5, 0, 0x1a], [3, 6, 0, 0x3a], [4, 3, 4, 0x4], [20, 6, 1, 0x3b], [22, 4, 4, 0xb], [38, 4, 5, 0xc], [70, 5, 6, 0x1b], [134, 5, 7, 0x1c], [262, 6, 7, 0x3c], [390, 7, 8, 0x7d], [646, 6, 10, 0x3d], [-16, 9, 32, 0x1fe, "lower"], [1670, 9, 32, 0x1ff], [2, 0x1]]; 9720 break; 9721 case 9: 9722 lines = [[-31, 8, 4, 0xfc], [-15, 9, 2, 0x1fc], [-11, 8, 2, 0xfd], [-7, 9, 1, 0x1fd], [-5, 7, 1, 0x7c], [-3, 4, 1, 0xa], [-1, 3, 1, 0x2], [1, 3, 1, 0x3], [3, 5, 1, 0x1a], [5, 6, 1, 0x3a], [7, 3, 5, 0x4], [39, 6, 2, 0x3b], [43, 4, 5, 0xb], [75, 4, 6, 0xc], [139, 5, 7, 0x1b], [267, 5, 8, 0x1c], [523, 6, 8, 0x3c], [779, 7, 9, 0x7d], [1291, 6, 11, 0x3d], [-32, 9, 32, 0x1fe, "lower"], [3339, 9, 32, 0x1ff], [2, 0x0]]; 9723 break; 9724 case 10: 9725 lines = [[-21, 7, 4, 0x7a], [-5, 8, 0, 0xfc], [-4, 7, 0, 0x7b], [-3, 5, 0, 0x18], [-2, 2, 2, 0x0], [2, 5, 0, 0x19], [3, 6, 0, 0x36], [4, 7, 0, 0x7c], [5, 8, 0, 0xfd], [6, 2, 6, 0x1], [70, 5, 5, 0x1a], [102, 6, 5, 0x37], [134, 6, 6, 0x38], [198, 6, 7, 0x39], [326, 6, 8, 0x3a], [582, 6, 9, 0x3b], [1094, 6, 10, 0x3c], [2118, 7, 11, 0x7d], [-22, 8, 32, 0xfe, "lower"], [4166, 8, 32, 0xff], [2, 0x2]]; 9726 break; 9727 case 11: 9728 lines = [[1, 1, 0, 0x0], [2, 2, 1, 0x2], [4, 4, 0, 0xc], [5, 4, 1, 0xd], [7, 5, 1, 0x1c], [9, 5, 2, 0x1d], [13, 6, 2, 0x3c], [17, 7, 2, 0x7a], [21, 7, 3, 0x7b], [29, 7, 4, 0x7c], [45, 7, 5, 0x7d], [77, 7, 6, 0x7e], [141, 7, 32, 0x7f]]; 9729 break; 9730 case 12: 9731 lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 1, 0x6], [5, 5, 0, 0x1c], [6, 5, 1, 0x1d], [8, 6, 1, 0x3c], [10, 7, 0, 0x7a], [11, 7, 1, 0x7b], [13, 7, 2, 0x7c], [17, 7, 3, 0x7d], [25, 7, 4, 0x7e], [41, 8, 5, 0xfe], [73, 8, 32, 0xff]]; 9732 break; 9733 case 13: 9734 lines = [[1, 1, 0, 0x0], [2, 3, 0, 0x4], [3, 4, 0, 0xc], [4, 5, 0, 0x1c], [5, 4, 1, 0xd], [7, 3, 3, 0x5], [15, 6, 1, 0x3a], [17, 6, 2, 0x3b], [21, 6, 3, 0x3c], [29, 6, 4, 0x3d], [45, 6, 5, 0x3e], [77, 7, 6, 0x7e], [141, 7, 32, 0x7f]]; 9735 break; 9736 case 14: 9737 lines = [[-2, 3, 0, 0x4], [-1, 3, 0, 0x5], [0, 1, 0, 0x0], [1, 3, 0, 0x6], [2, 3, 0, 0x7]]; 9738 break; 9739 case 15: 9740 lines = [[-24, 7, 4, 0x7c], [-8, 6, 2, 0x3c], [-4, 5, 1, 0x1c], [-2, 4, 0, 0xc], [-1, 3, 0, 0x4], [0, 1, 0, 0x0], [1, 3, 0, 0x5], [2, 4, 0, 0xd], [3, 5, 1, 0x1d], [5, 6, 2, 0x3d], [9, 7, 4, 0x7d], [-25, 7, 32, 0x7e, "lower"], [25, 7, 32, 0x7f]]; 9741 break; 9742 default: 9743 throw new Jbig2Error(`standard table B.${number} does not exist`); 9744 } 9745 for (let i = 0, ii = lines.length; i < ii; i++) { 9746 lines[i] = new HuffmanLine(lines[i]); 9747 } 9748 table = new HuffmanTable(lines, true); 9749 standardTablesCache[number] = table; 9750 return table; 9751} 9752class Reader { 9753 constructor(data, start, end) { 9754 this.data = data; 9755 this.start = start; 9756 this.end = end; 9757 this.position = start; 9758 this.shift = -1; 9759 this.currentByte = 0; 9760 } 9761 readBit() { 9762 if (this.shift < 0) { 9763 if (this.position >= this.end) { 9764 throw new Jbig2Error("end of data while reading bit"); 9765 } 9766 this.currentByte = this.data[this.position++]; 9767 this.shift = 7; 9768 } 9769 const bit = this.currentByte >> this.shift & 1; 9770 this.shift--; 9771 return bit; 9772 } 9773 readBits(numBits) { 9774 let result = 0, 9775 i; 9776 for (i = numBits - 1; i >= 0; i--) { 9777 result |= this.readBit() << i; 9778 } 9779 return result; 9780 } 9781 byteAlign() { 9782 this.shift = -1; 9783 } 9784 next() { 9785 if (this.position >= this.end) { 9786 return -1; 9787 } 9788 return this.data[this.position++]; 9789 } 9790} 9791function getCustomHuffmanTable(index, referredTo, customTables) { 9792 let currentIndex = 0; 9793 for (let i = 0, ii = referredTo.length; i < ii; i++) { 9794 const table = customTables[referredTo[i]]; 9795 if (table) { 9796 if (index === currentIndex) { 9797 return table; 9798 } 9799 currentIndex++; 9800 } 9801 } 9802 throw new Jbig2Error("can't find custom Huffman table"); 9803} 9804function getTextRegionHuffmanTables(textRegion, referredTo, customTables, numberOfSymbols, reader) { 9805 const codes = []; 9806 for (let i = 0; i <= 34; i++) { 9807 const codeLength = reader.readBits(4); 9808 codes.push(new HuffmanLine([i, codeLength, 0, 0])); 9809 } 9810 const runCodesTable = new HuffmanTable(codes, false); 9811 codes.length = 0; 9812 for (let i = 0; i < numberOfSymbols;) { 9813 const codeLength = runCodesTable.decode(reader); 9814 if (codeLength >= 32) { 9815 let repeatedLength, numberOfRepeats, j; 9816 switch (codeLength) { 9817 case 32: 9818 if (i === 0) { 9819 throw new Jbig2Error("no previous value in symbol ID table"); 9820 } 9821 numberOfRepeats = reader.readBits(2) + 3; 9822 repeatedLength = codes[i - 1].prefixLength; 9823 break; 9824 case 33: 9825 numberOfRepeats = reader.readBits(3) + 3; 9826 repeatedLength = 0; 9827 break; 9828 case 34: 9829 numberOfRepeats = reader.readBits(7) + 11; 9830 repeatedLength = 0; 9831 break; 9832 default: 9833 throw new Jbig2Error("invalid code length in symbol ID table"); 9834 } 9835 for (j = 0; j < numberOfRepeats; j++) { 9836 codes.push(new HuffmanLine([i, repeatedLength, 0, 0])); 9837 i++; 9838 } 9839 } else { 9840 codes.push(new HuffmanLine([i, codeLength, 0, 0])); 9841 i++; 9842 } 9843 } 9844 reader.byteAlign(); 9845 const symbolIDTable = new HuffmanTable(codes, false); 9846 let customIndex = 0, 9847 tableFirstS, 9848 tableDeltaS, 9849 tableDeltaT; 9850 switch (textRegion.huffmanFS) { 9851 case 0: 9852 case 1: 9853 tableFirstS = getStandardTable(textRegion.huffmanFS + 6); 9854 break; 9855 case 3: 9856 tableFirstS = getCustomHuffmanTable(customIndex, referredTo, customTables); 9857 customIndex++; 9858 break; 9859 default: 9860 throw new Jbig2Error("invalid Huffman FS selector"); 9861 } 9862 switch (textRegion.huffmanDS) { 9863 case 0: 9864 case 1: 9865 case 2: 9866 tableDeltaS = getStandardTable(textRegion.huffmanDS + 8); 9867 break; 9868 case 3: 9869 tableDeltaS = getCustomHuffmanTable(customIndex, referredTo, customTables); 9870 customIndex++; 9871 break; 9872 default: 9873 throw new Jbig2Error("invalid Huffman DS selector"); 9874 } 9875 switch (textRegion.huffmanDT) { 9876 case 0: 9877 case 1: 9878 case 2: 9879 tableDeltaT = getStandardTable(textRegion.huffmanDT + 11); 9880 break; 9881 case 3: 9882 tableDeltaT = getCustomHuffmanTable(customIndex, referredTo, customTables); 9883 customIndex++; 9884 break; 9885 default: 9886 throw new Jbig2Error("invalid Huffman DT selector"); 9887 } 9888 if (textRegion.refinement) { 9889 throw new Jbig2Error("refinement with Huffman is not supported"); 9890 } 9891 return { 9892 symbolIDTable, 9893 tableFirstS, 9894 tableDeltaS, 9895 tableDeltaT 9896 }; 9897} 9898function getSymbolDictionaryHuffmanTables(dictionary, referredTo, customTables) { 9899 let customIndex = 0, 9900 tableDeltaHeight, 9901 tableDeltaWidth; 9902 switch (dictionary.huffmanDHSelector) { 9903 case 0: 9904 case 1: 9905 tableDeltaHeight = getStandardTable(dictionary.huffmanDHSelector + 4); 9906 break; 9907 case 3: 9908 tableDeltaHeight = getCustomHuffmanTable(customIndex, referredTo, customTables); 9909 customIndex++; 9910 break; 9911 default: 9912 throw new Jbig2Error("invalid Huffman DH selector"); 9913 } 9914 switch (dictionary.huffmanDWSelector) { 9915 case 0: 9916 case 1: 9917 tableDeltaWidth = getStandardTable(dictionary.huffmanDWSelector + 2); 9918 break; 9919 case 3: 9920 tableDeltaWidth = getCustomHuffmanTable(customIndex, referredTo, customTables); 9921 customIndex++; 9922 break; 9923 default: 9924 throw new Jbig2Error("invalid Huffman DW selector"); 9925 } 9926 let tableBitmapSize, tableAggregateInstances; 9927 if (dictionary.bitmapSizeSelector) { 9928 tableBitmapSize = getCustomHuffmanTable(customIndex, referredTo, customTables); 9929 customIndex++; 9930 } else { 9931 tableBitmapSize = getStandardTable(1); 9932 } 9933 if (dictionary.aggregationInstancesSelector) { 9934 tableAggregateInstances = getCustomHuffmanTable(customIndex, referredTo, customTables); 9935 } else { 9936 tableAggregateInstances = getStandardTable(1); 9937 } 9938 return { 9939 tableDeltaHeight, 9940 tableDeltaWidth, 9941 tableBitmapSize, 9942 tableAggregateInstances 9943 }; 9944} 9945function readUncompressedBitmap(reader, width, height) { 9946 const bitmap = []; 9947 for (let y = 0; y < height; y++) { 9948 const row = new Uint8Array(width); 9949 bitmap.push(row); 9950 for (let x = 0; x < width; x++) { 9951 row[x] = reader.readBit(); 9952 } 9953 reader.byteAlign(); 9954 } 9955 return bitmap; 9956} 9957function decodeMMRBitmap(input, width, height, endOfBlock) { 9958 const params = { 9959 K: -1, 9960 Columns: width, 9961 Rows: height, 9962 BlackIs1: true, 9963 EndOfBlock: endOfBlock 9964 }; 9965 const decoder = new CCITTFaxDecoder(input, params); 9966 const bitmap = []; 9967 let currentByte, 9968 eof = false; 9969 for (let y = 0; y < height; y++) { 9970 const row = new Uint8Array(width); 9971 bitmap.push(row); 9972 let shift = -1; 9973 for (let x = 0; x < width; x++) { 9974 if (shift < 0) { 9975 currentByte = decoder.readNextChar(); 9976 if (currentByte === -1) { 9977 currentByte = 0; 9978 eof = true; 9979 } 9980 shift = 7; 9981 } 9982 row[x] = currentByte >> shift & 1; 9983 shift--; 9984 } 9985 } 9986 if (endOfBlock && !eof) { 9987 const lookForEOFLimit = 5; 9988 for (let i = 0; i < lookForEOFLimit; i++) { 9989 if (decoder.readNextChar() === -1) { 9990 break; 9991 } 9992 } 9993 } 9994 return bitmap; 9995} 9996class Jbig2Image { 9997 parseChunks(chunks) { 9998 return parseJbig2Chunks(chunks); 9999 } 10000 parse(data) { 10001 throw new Error("Not implemented: Jbig2Image.parse"); 10002 } 10003} 10004 10005;// ./src/core/jbig2_stream.js 10006 10007 10008 10009 10010
vendor: 2,206 bytes, lines 10011-10101
10011class Jbig2Stream extends DecodeStream { 10012 constructor(stream, maybeLength, params) { 10013 super(maybeLength); 10014 this.stream = stream; 10015 this.dict = stream.dict; 10016 this.maybeLength = maybeLength; 10017 this.params = params; 10018 } 10019 get bytes() { 10020 return shadow(this, "bytes", this.stream.getBytes(this.maybeLength)); 10021 } 10022 ensureBuffer(requested) {} 10023 readBlock() { 10024 this.decodeImage(); 10025 } 10026 decodeImage(bytes) { 10027 if (this.eof) { 10028 return this.buffer; 10029 } 10030 bytes ||= this.bytes; 10031 const jbig2Image = new Jbig2Image(); 10032 const chunks = []; 10033 if (this.params instanceof Dict) { 10034 const globalsStream = this.params.get("JBIG2Globals"); 10035 if (globalsStream instanceof BaseStream) { 10036 const globals = globalsStream.getBytes(); 10037 chunks.push({ 10038 data: globals, 10039 start: 0, 10040 end: globals.length 10041 }); 10042 } 10043 } 10044 chunks.push({ 10045 data: bytes, 10046 start: 0, 10047 end: bytes.length 10048 }); 10049 const data = jbig2Image.parseChunks(chunks); 10050 const dataLength = data.length; 10051 for (let i = 0; i < dataLength; i++) { 10052 data[i] ^= 0xff; 10053 } 10054 this.buffer = data; 10055 this.bufferLength = dataLength; 10056 this.eof = true; 10057 return this.buffer; 10058 } 10059 get canAsyncDecodeImageFromBuffer() { 10060 return this.stream.isAsync; 10061 } 10062} 10063 10064;// ./src/core/jpx_stream.js 10065 10066 10067 10068class JpxStream extends DecodeStream { 10069 constructor(stream, maybeLength, params) { 10070 super(maybeLength); 10071 this.stream = stream; 10072 this.dict = stream.dict; 10073 this.maybeLength = maybeLength; 10074 this.params = params; 10075 } 10076 get bytes() { 10077 return shadow(this, "bytes", this.stream.getBytes(this.maybeLength)); 10078 } 10079 ensureBuffer(requested) {} 10080 readBlock(decoderOptions) { 10081 unreachable("JpxStream.readBlock"); 10082 } 10083 get isAsyncDecoder() { 10084 return true; 10085 } 10086 async decodeImage(bytes, decoderOptions) { 10087 if (this.eof) { 10088 return this.buffer; 10089 } 10090 bytes ||= this.bytes; 10091 this.buffer = await JpxImage.decode(bytes, decoderOptions); 10092 this.bufferLength = this.buffer.length; 10093 this.eof = true; 10094 return this.buffer; 10095 } 10096 get canAsyncDecodeImageFromBuffer() { 10097 return this.stream.isAsync; 10098 } 10099} 10100 10101;// ./src/core/lzw_stream.js
vendor: 4,021 bytes, lines 10101-10221
10101 10102 10103class LZWStream extends DecodeStream { 10104 constructor(str, maybeLength, earlyChange) { 10105 super(maybeLength); 10106 this.str = str; 10107 this.dict = str.dict; 10108 this.cachedData = 0; 10109 this.bitsCached = 0; 10110 const maxLzwDictionarySize = 4096; 10111 const lzwState = { 10112 earlyChange, 10113 codeLength: 9, 10114 nextCode: 258, 10115 dictionaryValues: new Uint8Array(maxLzwDictionarySize), 10116 dictionaryLengths: new Uint16Array(maxLzwDictionarySize), 10117 dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize), 10118 currentSequence: new Uint8Array(maxLzwDictionarySize), 10119 currentSequenceLength: 0 10120 }; 10121 for (let i = 0; i < 256; ++i) { 10122 lzwState.dictionaryValues[i] = i; 10123 lzwState.dictionaryLengths[i] = 1; 10124 } 10125 this.lzwState = lzwState; 10126 } 10127 readBits(n) { 10128 let bitsCached = this.bitsCached; 10129 let cachedData = this.cachedData; 10130 while (bitsCached < n) { 10131 const c = this.str.getByte(); 10132 if (c === -1) { 10133 this.eof = true; 10134 return null; 10135 } 10136 cachedData = cachedData << 8 | c; 10137 bitsCached += 8; 10138 } 10139 this.bitsCached = bitsCached -= n; 10140 this.cachedData = cachedData; 10141 this.lastCode = null; 10142 return cachedData >>> bitsCached & (1 << n) - 1; 10143 } 10144 readBlock() { 10145 const blockSize = 512, 10146 decodedSizeDelta = blockSize; 10147 let estimatedDecodedSize = blockSize * 2; 10148 let i, j, q; 10149 const lzwState = this.lzwState; 10150 if (!lzwState) { 10151 return; 10152 } 10153 const earlyChange = lzwState.earlyChange; 10154 let nextCode = lzwState.nextCode; 10155 const dictionaryValues = lzwState.dictionaryValues; 10156 const dictionaryLengths = lzwState.dictionaryLengths; 10157 const dictionaryPrevCodes = lzwState.dictionaryPrevCodes; 10158 let codeLength = lzwState.codeLength; 10159 let prevCode = lzwState.prevCode; 10160 const currentSequence = lzwState.currentSequence; 10161 let currentSequenceLength = lzwState.currentSequenceLength; 10162 let decodedLength = 0; 10163 let currentBufferLength = this.bufferLength; 10164 let buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize); 10165 for (i = 0; i < blockSize; i++) { 10166 const code = this.readBits(codeLength); 10167 const hasPrev = currentSequenceLength > 0; 10168 if (code < 256) { 10169 currentSequence[0] = code; 10170 currentSequenceLength = 1; 10171 } else if (code >= 258) { 10172 if (code < nextCode) { 10173 currentSequenceLength = dictionaryLengths[code]; 10174 for (j = currentSequenceLength - 1, q = code; j >= 0; j--) { 10175 currentSequence[j] = dictionaryValues[q]; 10176 q = dictionaryPrevCodes[q]; 10177 } 10178 } else { 10179 currentSequence[currentSequenceLength++] = currentSequence[0]; 10180 } 10181 } else if (code === 256) { 10182 codeLength = 9; 10183 nextCode = 258; 10184 currentSequenceLength = 0; 10185 continue; 10186 } else { 10187 this.eof = true; 10188 delete this.lzwState; 10189 break; 10190 } 10191 if (hasPrev) { 10192 dictionaryPrevCodes[nextCode] = prevCode; 10193 dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1; 10194 dictionaryValues[nextCode] = currentSequence[0]; 10195 nextCode++; 10196 codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0; 10197 } 10198 prevCode = code; 10199 decodedLength += currentSequenceLength; 10200 if (estimatedDecodedSize < decodedLength) { 10201 do { 10202 estimatedDecodedSize += decodedSizeDelta; 10203 } while (estimatedDecodedSize < decodedLength); 10204 buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize); 10205 } 10206 for (j = 0; j < currentSequenceLength; j++) { 10207 buffer[currentBufferLength++] = currentSequence[j]; 10208 } 10209 } 10210 lzwState.nextCode = nextCode; 10211 lzwState.codeLength = codeLength; 10212 lzwState.prevCode = prevCode; 10213 lzwState.currentSequenceLength = currentSequenceLength; 10214 this.bufferLength = currentBufferLength; 10215 } 10216} 10217 10218;// ./src/core/predictor_stream.js 10219 10220 10221
vendor: 2,598 bytes, lines 10222-10298
10222class PredictorStream extends DecodeStream { 10223 constructor(str, maybeLength, params) { 10224 super(maybeLength); 10225 if (!(params instanceof Dict)) { 10226 return str; 10227 } 10228 const predictor = this.predictor = params.get("Predictor") || 1; 10229 if (predictor <= 1) { 10230 return str; 10231 } 10232 if (predictor !== 2 && (predictor < 10 || predictor > 15)) { 10233 throw new FormatError(`Unsupported predictor: ${predictor}`); 10234 } 10235 this.readBlock = predictor === 2 ? this.readBlockTiff : this.readBlockPng; 10236 this.str = str; 10237 this.dict = str.dict; 10238 const colors = this.colors = params.get("Colors") || 1; 10239 const bits = this.bits = params.get("BPC", "BitsPerComponent") || 8; 10240 const columns = this.columns = params.get("Columns") || 1; 10241 this.pixBytes = colors * bits + 7 >> 3; 10242 this.rowBytes = columns * colors * bits + 7 >> 3; 10243 return this; 10244 } 10245 readBlockTiff() { 10246 const rowBytes = this.rowBytes; 10247 const bufferLength = this.bufferLength; 10248 const buffer = this.ensureBuffer(bufferLength + rowBytes); 10249 const bits = this.bits; 10250 const colors = this.colors; 10251 const rawBytes = this.str.getBytes(rowBytes); 10252 this.eof = !rawBytes.length; 10253 if (this.eof) { 10254 return; 10255 } 10256 let inbuf = 0, 10257 outbuf = 0; 10258 let inbits = 0, 10259 outbits = 0; 10260 let pos = bufferLength; 10261 let i; 10262 if (bits === 1 && colors === 1) { 10263 for (i = 0; i < rowBytes; ++i) { 10264 let c = rawBytes[i] ^ inbuf; 10265 c ^= c >> 1; 10266 c ^= c >> 2; 10267 c ^= c >> 4; 10268 inbuf = (c & 1) << 7; 10269 buffer[pos++] = c; 10270 } 10271 } else if (bits === 8) { 10272 for (i = 0; i < colors; ++i) { 10273 buffer[pos++] = rawBytes[i]; 10274 } 10275 for (; i < rowBytes; ++i) { 10276 buffer[pos] = buffer[pos - colors] + rawBytes[i]; 10277 pos++; 10278 } 10279 } else if (bits === 16) { 10280 const bytesPerPixel = colors * 2; 10281 for (i = 0; i < bytesPerPixel; ++i) { 10282 buffer[pos++] = rawBytes[i]; 10283 } 10284 for (; i < rowBytes; i += 2) { 10285 const sum = ((rawBytes[i] & 0xff) << 8) + (rawBytes[i + 1] & 0xff) + ((buffer[pos - bytesPerPixel] & 0xff) << 8) + (buffer[pos - bytesPerPixel + 1] & 0xff); 10286 buffer[pos++] = sum >> 8 & 0xff; 10287 buffer[pos++] = sum & 0xff; 10288 } 10289 } else { 10290 const compArray = new Uint8Array(colors + 1); 10291 const bitMask = (1 << bits) - 1; 10292 let j = 0, 10293 k = bufferLength; 10294 const columns = this.columns; 10295 for (i = 0; i < columns; ++i) { 10296 for (let kk = 0; kk < colors; ++kk) { 10297 if (inbits < bits) { 10298 inbuf = inbuf << 8 | rawBytes[j++] & 0xff;
vendor: 3,882 bytes, lines 10299-10440
10299 inbits += 8; 10300 } 10301 compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask; 10302 inbits -= bits; 10303 outbuf = outbuf << bits | compArray[kk]; 10304 outbits += bits; 10305 if (outbits >= 8) { 10306 buffer[k++] = outbuf >> outbits - 8 & 0xff; 10307 outbits -= 8; 10308 } 10309 } 10310 } 10311 if (outbits > 0) { 10312 buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1); 10313 } 10314 } 10315 this.bufferLength += rowBytes; 10316 } 10317 readBlockPng() { 10318 const rowBytes = this.rowBytes; 10319 const pixBytes = this.pixBytes; 10320 const predictor = this.str.getByte(); 10321 const rawBytes = this.str.getBytes(rowBytes); 10322 this.eof = !rawBytes.length; 10323 if (this.eof) { 10324 return; 10325 } 10326 const bufferLength = this.bufferLength; 10327 const buffer = this.ensureBuffer(bufferLength + rowBytes); 10328 let prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength); 10329 if (prevRow.length === 0) { 10330 prevRow = new Uint8Array(rowBytes); 10331 } 10332 let i, 10333 j = bufferLength, 10334 up, 10335 c; 10336 switch (predictor) { 10337 case 0: 10338 for (i = 0; i < rowBytes; ++i) { 10339 buffer[j++] = rawBytes[i]; 10340 } 10341 break; 10342 case 1: 10343 for (i = 0; i < pixBytes; ++i) { 10344 buffer[j++] = rawBytes[i]; 10345 } 10346 for (; i < rowBytes; ++i) { 10347 buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xff; 10348 j++; 10349 } 10350 break; 10351 case 2: 10352 for (i = 0; i < rowBytes; ++i) { 10353 buffer[j++] = prevRow[i] + rawBytes[i] & 0xff; 10354 } 10355 break; 10356 case 3: 10357 for (i = 0; i < pixBytes; ++i) { 10358 buffer[j++] = (prevRow[i] >> 1) + rawBytes[i]; 10359 } 10360 for (; i < rowBytes; ++i) { 10361 buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xff; 10362 j++; 10363 } 10364 break; 10365 case 4: 10366 for (i = 0; i < pixBytes; ++i) { 10367 up = prevRow[i]; 10368 c = rawBytes[i]; 10369 buffer[j++] = up + c; 10370 } 10371 for (; i < rowBytes; ++i) { 10372 up = prevRow[i]; 10373 const upLeft = prevRow[i - pixBytes]; 10374 const left = buffer[j - pixBytes]; 10375 const p = left + up - upLeft; 10376 let pa = p - left; 10377 if (pa < 0) { 10378 pa = -pa; 10379 } 10380 let pb = p - up; 10381 if (pb < 0) { 10382 pb = -pb; 10383 } 10384 let pc = p - upLeft; 10385 if (pc < 0) { 10386 pc = -pc; 10387 } 10388 c = rawBytes[i]; 10389 if (pa <= pb && pa <= pc) { 10390 buffer[j++] = left + c; 10391 } else if (pb <= pc) { 10392 buffer[j++] = up + c; 10393 } else { 10394 buffer[j++] = upLeft + c; 10395 } 10396 } 10397 break; 10398 default: 10399 throw new FormatError(`Unsupported predictor: ${predictor}`); 10400 } 10401 this.bufferLength += rowBytes; 10402 } 10403} 10404 10405;// ./src/core/run_length_stream.js 10406 10407class RunLengthStream extends DecodeStream { 10408 constructor(str, maybeLength) { 10409 super(maybeLength); 10410 this.str = str; 10411 this.dict = str.dict; 10412 } 10413 readBlock() { 10414 const repeatHeader = this.str.getBytes(2); 10415 if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) { 10416 this.eof = true; 10417 return; 10418 } 10419 let buffer; 10420 let bufferLength = this.bufferLength; 10421 let n = repeatHeader[0]; 10422 if (n < 128) { 10423 buffer = this.ensureBuffer(bufferLength + n + 1); 10424 buffer[bufferLength++] = repeatHeader[1]; 10425 if (n > 0) { 10426 const source = this.str.getBytes(n); 10427 buffer.set(source, bufferLength); 10428 bufferLength += n; 10429 } 10430 } else { 10431 n = 257 - n; 10432 buffer = this.ensureBuffer(bufferLength + n + 1); 10433 buffer.fill(repeatHeader[1], bufferLength, bufferLength + n); 10434 bufferLength += n; 10435 } 10436 this.bufferLength = bufferLength; 10437 } 10438} 10439 10440;// ./src/core/parser.js
vendor: 23,422 bytes, lines 10440-11255
10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455const MAX_LENGTH_TO_CACHE = 1000; 10456function getInlineImageCacheKey(bytes) { 10457 const strBuf = [], 10458 ii = bytes.length; 10459 let i = 0; 10460 while (i < ii - 1) { 10461 strBuf.push(bytes[i++] << 8 | bytes[i++]); 10462 } 10463 if (i < ii) { 10464 strBuf.push(bytes[i]); 10465 } 10466 return ii + "_" + String.fromCharCode.apply(null, strBuf); 10467} 10468class Parser { 10469 constructor({ 10470 lexer, 10471 xref, 10472 allowStreams = false, 10473 recoveryMode = false 10474 }) { 10475 this.lexer = lexer; 10476 this.xref = xref; 10477 this.allowStreams = allowStreams; 10478 this.recoveryMode = recoveryMode; 10479 this.imageCache = Object.create(null); 10480 this._imageId = 0; 10481 this.refill(); 10482 } 10483 refill() { 10484 this.buf1 = this.lexer.getObj(); 10485 this.buf2 = this.lexer.getObj(); 10486 } 10487 shift() { 10488 if (this.buf2 instanceof Cmd && this.buf2.cmd === "ID") { 10489 this.buf1 = this.buf2; 10490 this.buf2 = null; 10491 } else { 10492 this.buf1 = this.buf2; 10493 this.buf2 = this.lexer.getObj(); 10494 } 10495 } 10496 tryShift() { 10497 try { 10498 this.shift(); 10499 return true; 10500 } catch (e) { 10501 if (e instanceof MissingDataException) { 10502 throw e; 10503 } 10504 return false; 10505 } 10506 } 10507 getObj(cipherTransform = null) { 10508 const buf1 = this.buf1; 10509 this.shift(); 10510 if (buf1 instanceof Cmd) { 10511 switch (buf1.cmd) { 10512 case "BI": 10513 return this.makeInlineImage(cipherTransform); 10514 case "[": 10515 const array = []; 10516 while (!isCmd(this.buf1, "]") && this.buf1 !== EOF) { 10517 array.push(this.getObj(cipherTransform)); 10518 } 10519 if (this.buf1 === EOF) { 10520 if (this.recoveryMode) { 10521 return array; 10522 } 10523 throw new ParserEOFException("End of file inside array."); 10524 } 10525 this.shift(); 10526 return array; 10527 case "<<": 10528 const dict = new Dict(this.xref); 10529 while (!isCmd(this.buf1, ">>") && this.buf1 !== EOF) { 10530 if (!(this.buf1 instanceof Name)) { 10531 info("Malformed dictionary: key must be a name object"); 10532 this.shift(); 10533 continue; 10534 } 10535 const key = this.buf1.name; 10536 this.shift(); 10537 if (this.buf1 === EOF) { 10538 break; 10539 } 10540 dict.set(key, this.getObj(cipherTransform)); 10541 } 10542 if (this.buf1 === EOF) { 10543 if (this.recoveryMode) { 10544 return dict; 10545 } 10546 throw new ParserEOFException("End of file inside dictionary."); 10547 } 10548 if (isCmd(this.buf2, "stream")) { 10549 return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict; 10550 } 10551 this.shift(); 10552 return dict; 10553 default: 10554 return buf1; 10555 } 10556 } 10557 if (Number.isInteger(buf1)) { 10558 if (Number.isInteger(this.buf1) && isCmd(this.buf2, "R")) { 10559 const ref = Ref.get(buf1, this.buf1); 10560 this.shift(); 10561 this.shift(); 10562 return ref; 10563 } 10564 return buf1; 10565 } 10566 if (typeof buf1 === "string") { 10567 if (cipherTransform) { 10568 return cipherTransform.decryptString(buf1); 10569 } 10570 return buf1; 10571 } 10572 return buf1; 10573 } 10574 findDefaultInlineStreamEnd(stream) { 10575 const E = 0x45, 10576 I = 0x49, 10577 SPACE = 0x20, 10578 LF = 0xa, 10579 CR = 0xd, 10580 NUL = 0x0; 10581 const { 10582 knownCommands 10583 } = this.lexer, 10584 startPos = stream.pos, 10585 n = 15; 10586 let state = 0, 10587 ch, 10588 maybeEIPos; 10589 while ((ch = stream.getByte()) !== -1) { 10590 if (state === 0) { 10591 state = ch === E ? 1 : 0; 10592 } else if (state === 1) { 10593 state = ch === I ? 2 : 0; 10594 } else { 10595 if (ch === SPACE || ch === LF || ch === CR) { 10596 maybeEIPos = stream.pos; 10597 const followingBytes = stream.peekBytes(n); 10598 const ii = followingBytes.length; 10599 if (ii === 0) { 10600 break; 10601 } 10602 for (let i = 0; i < ii; i++) { 10603 ch = followingBytes[i]; 10604 if (ch === NUL && followingBytes[i + 1] !== NUL) { 10605 continue; 10606 } 10607 if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7f)) { 10608 state = 0; 10609 break; 10610 } 10611 } 10612 if (state !== 2) { 10613 continue; 10614 } 10615 if (!knownCommands) { 10616 warn("findDefaultInlineStreamEnd - `lexer.knownCommands` is undefined."); 10617 continue; 10618 } 10619 const tmpLexer = new Lexer(new Stream(stream.peekBytes(5 * n)), knownCommands); 10620 tmpLexer._hexStringWarn = () => {}; 10621 let numArgs = 0; 10622 while (true) { 10623 const nextObj = tmpLexer.getObj(); 10624 if (nextObj === EOF) { 10625 state = 0; 10626 break; 10627 } 10628 if (nextObj instanceof Cmd) { 10629 const knownCommand = knownCommands[nextObj.cmd]; 10630 if (!knownCommand) { 10631 state = 0; 10632 break; 10633 } else if (knownCommand.variableArgs ? numArgs <= knownCommand.numArgs : numArgs === knownCommand.numArgs) { 10634 break; 10635 } 10636 numArgs = 0; 10637 continue; 10638 } 10639 numArgs++; 10640 } 10641 if (state === 2) { 10642 break; 10643 } 10644 } else { 10645 state = 0; 10646 } 10647 } 10648 } 10649 if (ch === -1) { 10650 warn("findDefaultInlineStreamEnd: " + "Reached the end of the stream without finding a valid EI marker"); 10651 if (maybeEIPos) { 10652 warn('... trying to recover by using the last "EI" occurrence.'); 10653 stream.skip(-(stream.pos - maybeEIPos)); 10654 } 10655 } 10656 let endOffset = 4; 10657 stream.skip(-endOffset); 10658 ch = stream.peekByte(); 10659 stream.skip(endOffset); 10660 if (!isWhiteSpace(ch)) { 10661 endOffset--; 10662 } 10663 return stream.pos - endOffset - startPos; 10664 } 10665 findDCTDecodeInlineStreamEnd(stream) { 10666 const startPos = stream.pos; 10667 let foundEOI = false, 10668 b, 10669 markerLength; 10670 while ((b = stream.getByte()) !== -1) { 10671 if (b !== 0xff) { 10672 continue; 10673 } 10674 switch (stream.getByte()) { 10675 case 0x00: 10676 break; 10677 case 0xff: 10678 stream.skip(-1); 10679 break; 10680 case 0xd9: 10681 foundEOI = true; 10682 break; 10683 case 0xc0: 10684 case 0xc1: 10685 case 0xc2: 10686 case 0xc3: 10687 case 0xc5: 10688 case 0xc6: 10689 case 0xc7: 10690 case 0xc9: 10691 case 0xca: 10692 case 0xcb: 10693 case 0xcd: 10694 case 0xce: 10695 case 0xcf: 10696 case 0xc4: 10697 case 0xcc: 10698 case 0xda: 10699 case 0xdb: 10700 case 0xdc: 10701 case 0xdd: 10702 case 0xde: 10703 case 0xdf: 10704 case 0xe0: 10705 case 0xe1: 10706 case 0xe2: 10707 case 0xe3: 10708 case 0xe4: 10709 case 0xe5: 10710 case 0xe6: 10711 case 0xe7: 10712 case 0xe8: 10713 case 0xe9: 10714 case 0xea: 10715 case 0xeb: 10716 case 0xec: 10717 case 0xed: 10718 case 0xee: 10719 case 0xef: 10720 case 0xfe: 10721 markerLength = stream.getUint16(); 10722 if (markerLength > 2) { 10723 stream.skip(markerLength - 2); 10724 } else { 10725 stream.skip(-2); 10726 } 10727 break; 10728 } 10729 if (foundEOI) { 10730 break; 10731 } 10732 } 10733 const length = stream.pos - startPos; 10734 if (b === -1) { 10735 warn("Inline DCTDecode image stream: " + "EOI marker not found, searching for /EI/ instead."); 10736 stream.skip(-length); 10737 return this.findDefaultInlineStreamEnd(stream); 10738 } 10739 this.inlineStreamSkipEI(stream); 10740 return length; 10741 } 10742 findASCII85DecodeInlineStreamEnd(stream) { 10743 const TILDE = 0x7e, 10744 GT = 0x3e; 10745 const startPos = stream.pos; 10746 let ch; 10747 while ((ch = stream.getByte()) !== -1) { 10748 if (ch === TILDE) { 10749 const tildePos = stream.pos; 10750 ch = stream.peekByte(); 10751 while (isWhiteSpace(ch)) { 10752 stream.skip(); 10753 ch = stream.peekByte(); 10754 } 10755 if (ch === GT) { 10756 stream.skip(); 10757 break; 10758 } 10759 if (stream.pos > tildePos) { 10760 const maybeEI = stream.peekBytes(2); 10761 if (maybeEI[0] === 0x45 && maybeEI[1] === 0x49) { 10762 break; 10763 } 10764 } 10765 } 10766 } 10767 const length = stream.pos - startPos; 10768 if (ch === -1) { 10769 warn("Inline ASCII85Decode image stream: " + "EOD marker not found, searching for /EI/ instead."); 10770 stream.skip(-length); 10771 return this.findDefaultInlineStreamEnd(stream); 10772 } 10773 this.inlineStreamSkipEI(stream); 10774 return length; 10775 } 10776 findASCIIHexDecodeInlineStreamEnd(stream) { 10777 const GT = 0x3e; 10778 const startPos = stream.pos; 10779 let ch; 10780 while ((ch = stream.getByte()) !== -1) { 10781 if (ch === GT) { 10782 break; 10783 } 10784 } 10785 const length = stream.pos - startPos; 10786 if (ch === -1) { 10787 warn("Inline ASCIIHexDecode image stream: " + "EOD marker not found, searching for /EI/ instead."); 10788 stream.skip(-length); 10789 return this.findDefaultInlineStreamEnd(stream); 10790 } 10791 this.inlineStreamSkipEI(stream); 10792 return length; 10793 } 10794 inlineStreamSkipEI(stream) { 10795 const E = 0x45, 10796 I = 0x49; 10797 let state = 0, 10798 ch; 10799 while ((ch = stream.getByte()) !== -1) { 10800 if (state === 0) { 10801 state = ch === E ? 1 : 0; 10802 } else if (state === 1) { 10803 state = ch === I ? 2 : 0; 10804 } else if (state === 2) { 10805 break; 10806 } 10807 } 10808 } 10809 makeInlineImage(cipherTransform) { 10810 const lexer = this.lexer; 10811 const stream = lexer.stream; 10812 const dictMap = Object.create(null); 10813 let dictLength; 10814 while (!isCmd(this.buf1, "ID") && this.buf1 !== EOF) { 10815 if (!(this.buf1 instanceof Name)) { 10816 throw new FormatError("Dictionary key must be a name object"); 10817 } 10818 const key = this.buf1.name; 10819 this.shift(); 10820 if (this.buf1 === EOF) { 10821 break; 10822 } 10823 dictMap[key] = this.getObj(cipherTransform); 10824 } 10825 if (lexer.beginInlineImagePos !== -1) { 10826 dictLength = stream.pos - lexer.beginInlineImagePos; 10827 } 10828 const filter = this.xref.fetchIfRef(dictMap.F || dictMap.Filter); 10829 let filterName; 10830 if (filter instanceof Name) { 10831 filterName = filter.name; 10832 } else if (Array.isArray(filter)) { 10833 const filterZero = this.xref.fetchIfRef(filter[0]); 10834 if (filterZero instanceof Name) { 10835 filterName = filterZero.name; 10836 } 10837 } 10838 const startPos = stream.pos; 10839 let length; 10840 switch (filterName) { 10841 case "DCT": 10842 case "DCTDecode": 10843 length = this.findDCTDecodeInlineStreamEnd(stream); 10844 break; 10845 case "A85": 10846 case "ASCII85Decode": 10847 length = this.findASCII85DecodeInlineStreamEnd(stream); 10848 break; 10849 case "AHx": 10850 case "ASCIIHexDecode": 10851 length = this.findASCIIHexDecodeInlineStreamEnd(stream); 10852 break; 10853 default: 10854 length = this.findDefaultInlineStreamEnd(stream); 10855 } 10856 let cacheKey; 10857 if (length < MAX_LENGTH_TO_CACHE && dictLength > 0) { 10858 const initialStreamPos = stream.pos; 10859 stream.pos = lexer.beginInlineImagePos; 10860 cacheKey = getInlineImageCacheKey(stream.getBytes(dictLength + length)); 10861 stream.pos = initialStreamPos; 10862 const cacheEntry = this.imageCache[cacheKey]; 10863 if (cacheEntry !== undefined) { 10864 this.buf2 = Cmd.get("EI"); 10865 this.shift(); 10866 cacheEntry.reset(); 10867 return cacheEntry; 10868 } 10869 } 10870 const dict = new Dict(this.xref); 10871 for (const key in dictMap) { 10872 dict.set(key, dictMap[key]); 10873 } 10874 let imageStream = stream.makeSubStream(startPos, length, dict); 10875 if (cipherTransform) { 10876 imageStream = cipherTransform.createStream(imageStream, length); 10877 } 10878 imageStream = this.filter(imageStream, dict, length); 10879 imageStream.dict = dict; 10880 if (cacheKey !== undefined) { 10881 imageStream.cacheKey = `inline_img_${++this._imageId}`; 10882 this.imageCache[cacheKey] = imageStream; 10883 } 10884 this.buf2 = Cmd.get("EI"); 10885 this.shift(); 10886 return imageStream; 10887 } 10888 #findStreamLength(startPos) { 10889 const { 10890 stream 10891 } = this.lexer; 10892 stream.pos = startPos; 10893 const SCAN_BLOCK_LENGTH = 2048; 10894 const signatureLength = "endstream".length; 10895 const END_SIGNATURE = new Uint8Array([0x65, 0x6e, 0x64]); 10896 const endLength = END_SIGNATURE.length; 10897 const PARTIAL_SIGNATURE = [new Uint8Array([0x73, 0x74, 0x72, 0x65, 0x61, 0x6d]), new Uint8Array([0x73, 0x74, 0x65, 0x61, 0x6d]), new Uint8Array([0x73, 0x74, 0x72, 0x65, 0x61])]; 10898 const normalLength = signatureLength - endLength; 10899 while (stream.pos < stream.end) { 10900 const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH); 10901 const scanLength = scanBytes.length - signatureLength; 10902 if (scanLength <= 0) { 10903 break; 10904 } 10905 let pos = 0; 10906 while (pos < scanLength) { 10907 let j = 0; 10908 while (j < endLength && scanBytes[pos + j] === END_SIGNATURE[j]) { 10909 j++; 10910 } 10911 if (j >= endLength) { 10912 let found = false; 10913 for (const part of PARTIAL_SIGNATURE) { 10914 const partLen = part.length; 10915 let k = 0; 10916 while (k < partLen && scanBytes[pos + j + k] === part[k]) { 10917 k++; 10918 } 10919 if (k >= normalLength) { 10920 found = true; 10921 break; 10922 } 10923 if (k >= partLen) { 10924 const lastByte = scanBytes[pos + j + k]; 10925 if (isWhiteSpace(lastByte)) { 10926 info(`Found "${bytesToString([...END_SIGNATURE, ...part])}" when ` + "searching for endstream command."); 10927 found = true; 10928 } 10929 break; 10930 } 10931 } 10932 if (found) { 10933 stream.pos += pos; 10934 return stream.pos - startPos; 10935 } 10936 } 10937 pos++; 10938 } 10939 stream.pos += scanLength; 10940 } 10941 return -1; 10942 } 10943 makeStream(dict, cipherTransform) { 10944 const lexer = this.lexer; 10945 let stream = lexer.stream; 10946 lexer.skipToNextLine(); 10947 const startPos = stream.pos - 1; 10948 let length = dict.get("Length"); 10949 if (!Number.isInteger(length)) { 10950 info(`Bad length "${length && length.toString()}" in stream.`); 10951 length = 0; 10952 } 10953 stream.pos = startPos + length; 10954 lexer.nextChar(); 10955 if (this.tryShift() && isCmd(this.buf2, "endstream")) { 10956 this.shift(); 10957 } else { 10958 length = this.#findStreamLength(startPos); 10959 if (length < 0) { 10960 throw new FormatError("Missing endstream command."); 10961 } 10962 lexer.nextChar(); 10963 this.shift(); 10964 this.shift(); 10965 } 10966 this.shift(); 10967 stream = stream.makeSubStream(startPos, length, dict); 10968 if (cipherTransform) { 10969 stream = cipherTransform.createStream(stream, length); 10970 } 10971 stream = this.filter(stream, dict, length); 10972 stream.dict = dict; 10973 return stream; 10974 } 10975 filter(stream, dict, length) { 10976 let filter = dict.get("F", "Filter"); 10977 let params = dict.get("DP", "DecodeParms"); 10978 if (filter instanceof Name) { 10979 if (Array.isArray(params)) { 10980 warn("/DecodeParms should not be an Array, when /Filter is a Name."); 10981 } 10982 return this.makeFilter(stream, filter.name, length, params); 10983 } 10984 let maybeLength = length; 10985 if (Array.isArray(filter)) { 10986 const filterArray = filter; 10987 const paramsArray = params; 10988 for (let i = 0, ii = filterArray.length; i < ii; ++i) { 10989 filter = this.xref.fetchIfRef(filterArray[i]); 10990 if (!(filter instanceof Name)) { 10991 throw new FormatError(`Bad filter name "${filter}"`); 10992 } 10993 params = null; 10994 if (Array.isArray(paramsArray) && i in paramsArray) { 10995 params = this.xref.fetchIfRef(paramsArray[i]); 10996 } 10997 stream = this.makeFilter(stream, filter.name, maybeLength, params); 10998 maybeLength = null; 10999 } 11000 } 11001 return stream; 11002 } 11003 makeFilter(stream, name, maybeLength, params) { 11004 if (maybeLength === 0) { 11005 warn(`Empty "${name}" stream.`); 11006 return new NullStream(); 11007 } 11008 try { 11009 switch (name) { 11010 case "Fl": 11011 case "FlateDecode": 11012 if (params) { 11013 return new PredictorStream(new FlateStream(stream, maybeLength), maybeLength, params); 11014 } 11015 return new FlateStream(stream, maybeLength); 11016 case "LZW": 11017 case "LZWDecode": 11018 let earlyChange = 1; 11019 if (params) { 11020 if (params.has("EarlyChange")) { 11021 earlyChange = params.get("EarlyChange"); 11022 } 11023 return new PredictorStream(new LZWStream(stream, maybeLength, earlyChange), maybeLength, params); 11024 } 11025 return new LZWStream(stream, maybeLength, earlyChange); 11026 case "DCT": 11027 case "DCTDecode": 11028 return new JpegStream(stream, maybeLength, params); 11029 case "JPX": 11030 case "JPXDecode": 11031 return new JpxStream(stream, maybeLength, params); 11032 case "A85": 11033 case "ASCII85Decode": 11034 return new Ascii85Stream(stream, maybeLength); 11035 case "AHx": 11036 case "ASCIIHexDecode": 11037 return new AsciiHexStream(stream, maybeLength); 11038 case "CCF": 11039 case "CCITTFaxDecode": 11040 return new CCITTFaxStream(stream, maybeLength, params); 11041 case "RL": 11042 case "RunLengthDecode": 11043 return new RunLengthStream(stream, maybeLength); 11044 case "JBIG2Decode": 11045 return new Jbig2Stream(stream, maybeLength, params); 11046 } 11047 warn(`Filter "${name}" is not supported.`); 11048 return stream; 11049 } catch (ex) { 11050 if (ex instanceof MissingDataException) { 11051 throw ex; 11052 } 11053 warn(`Invalid stream: "${ex}"`); 11054 return new NullStream(); 11055 } 11056 } 11057} 11058const specialChars = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; 11059function toHexDigit(ch) { 11060 if (ch >= 0x30 && ch <= 0x39) { 11061 return ch & 0x0f; 11062 } 11063 if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) { 11064 return (ch & 0x0f) + 9; 11065 } 11066 return -1; 11067} 11068class Lexer { 11069 constructor(stream, knownCommands = null) { 11070 this.stream = stream; 11071 this.nextChar(); 11072 this.strBuf = []; 11073 this.knownCommands = knownCommands; 11074 this._hexStringNumWarn = 0; 11075 this.beginInlineImagePos = -1; 11076 } 11077 nextChar() { 11078 return this.currentChar = this.stream.getByte(); 11079 } 11080 peekChar() { 11081 return this.stream.peekByte(); 11082 } 11083 getNumber() { 11084 let ch = this.currentChar; 11085 let eNotation = false; 11086 let divideBy = 0; 11087 let sign = 1; 11088 if (ch === 0x2d) { 11089 sign = -1; 11090 ch = this.nextChar(); 11091 if (ch === 0x2d) { 11092 ch = this.nextChar(); 11093 } 11094 } else if (ch === 0x2b) { 11095 ch = this.nextChar(); 11096 } 11097 if (ch === 0x0a || ch === 0x0d) { 11098 do { 11099 ch = this.nextChar(); 11100 } while (ch === 0x0a || ch === 0x0d); 11101 } 11102 if (ch === 0x2e) { 11103 divideBy = 10; 11104 ch = this.nextChar(); 11105 } 11106 if (ch < 0x30 || ch > 0x39) { 11107 const msg = `Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`; 11108 if (isWhiteSpace(ch) || ch === 0x28 || ch === 0x3c || ch === -1) { 11109 info(`Lexer.getNumber - "${msg}".`); 11110 return 0; 11111 } 11112 throw new FormatError(msg); 11113 } 11114 let baseValue = ch - 0x30; 11115 let powerValue = 0; 11116 let powerValueSign = 1; 11117 while ((ch = this.nextChar()) >= 0) { 11118 if (ch >= 0x30 && ch <= 0x39) { 11119 const currentDigit = ch - 0x30; 11120 if (eNotation) { 11121 powerValue = powerValue * 10 + currentDigit; 11122 } else { 11123 if (divideBy !== 0) { 11124 divideBy *= 10; 11125 } 11126 baseValue = baseValue * 10 + currentDigit; 11127 } 11128 } else if (ch === 0x2e) { 11129 if (divideBy === 0) { 11130 divideBy = 1; 11131 } else { 11132 break; 11133 } 11134 } else if (ch === 0x2d) { 11135 warn("Badly formatted number: minus sign in the middle"); 11136 } else if (ch === 0x45 || ch === 0x65) { 11137 ch = this.peekChar(); 11138 if (ch === 0x2b || ch === 0x2d) { 11139 powerValueSign = ch === 0x2d ? -1 : 1; 11140 this.nextChar(); 11141 } else if (ch < 0x30 || ch > 0x39) { 11142 break; 11143 } 11144 eNotation = true; 11145 } else { 11146 break; 11147 } 11148 } 11149 if (divideBy !== 0) { 11150 baseValue /= divideBy; 11151 } 11152 if (eNotation) { 11153 baseValue *= 10 ** (powerValueSign * powerValue); 11154 } 11155 return sign * baseValue; 11156 } 11157 getString() { 11158 let numParen = 1; 11159 let done = false; 11160 const strBuf = this.strBuf; 11161 strBuf.length = 0; 11162 let ch = this.nextChar(); 11163 while (true) { 11164 let charBuffered = false; 11165 switch (ch | 0) { 11166 case -1: 11167 warn("Unterminated string"); 11168 done = true; 11169 break; 11170 case 0x28: 11171 ++numParen; 11172 strBuf.push("("); 11173 break; 11174 case 0x29: 11175 if (--numParen === 0) { 11176 this.nextChar(); 11177 done = true; 11178 } else { 11179 strBuf.push(")"); 11180 } 11181 break; 11182 case 0x5c: 11183 ch = this.nextChar(); 11184 switch (ch) { 11185 case -1: 11186 warn("Unterminated string"); 11187 done = true; 11188 break; 11189 case 0x6e: 11190 strBuf.push("\n"); 11191 break; 11192 case 0x72: 11193 strBuf.push("\r"); 11194 break; 11195 case 0x74: 11196 strBuf.push("\t"); 11197 break; 11198 case 0x62: 11199 strBuf.push("\b"); 11200 break; 11201 case 0x66: 11202 strBuf.push("\f"); 11203 break; 11204 case 0x5c: 11205 case 0x28: 11206 case 0x29: 11207 strBuf.push(String.fromCharCode(ch)); 11208 break; 11209 case 0x30: 11210 case 0x31: 11211 case 0x32: 11212 case 0x33: 11213 case 0x34: 11214 case 0x35: 11215 case 0x36: 11216 case 0x37: 11217 let x = ch & 0x0f; 11218 ch = this.nextChar(); 11219 charBuffered = true; 11220 if (ch >= 0x30 && ch <= 0x37) { 11221 x = (x << 3) + (ch & 0x0f); 11222 ch = this.nextChar(); 11223 if (ch >= 0x30 && ch <= 0x37) { 11224 charBuffered = false; 11225 x = (x << 3) + (ch & 0x0f); 11226 } 11227 } 11228 strBuf.push(String.fromCharCode(x)); 11229 break; 11230 case 0x0d: 11231 if (this.peekChar() === 0x0a) { 11232 this.nextChar(); 11233 } 11234 break; 11235 case 0x0a: 11236 break; 11237 default: 11238 strBuf.push(String.fromCharCode(ch)); 11239 break; 11240 } 11241 break; 11242 default: 11243 strBuf.push(String.fromCharCode(ch)); 11244 break; 11245 } 11246 if (done) { 11247 break; 11248 } 11249 if (!charBuffered) { 11250 ch = this.nextChar(); 11251 } 11252 } 11253 return strBuf.join(""); 11254 } 11255 getName() {
vendor: 10,065 bytes, lines 11256-11524
11256 let ch, previousCh; 11257 const strBuf = this.strBuf; 11258 strBuf.length = 0; 11259 while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) { 11260 if (ch === 0x23) { 11261 ch = this.nextChar(); 11262 if (specialChars[ch]) { 11263 warn("Lexer_getName: " + "NUMBER SIGN (#) should be followed by a hexadecimal number."); 11264 strBuf.push("#"); 11265 break; 11266 } 11267 const x = toHexDigit(ch); 11268 if (x !== -1) { 11269 previousCh = ch; 11270 ch = this.nextChar(); 11271 const x2 = toHexDigit(ch); 11272 if (x2 === -1) { 11273 warn(`Lexer_getName: Illegal digit (${String.fromCharCode(ch)}) ` + "in hexadecimal number."); 11274 strBuf.push("#", String.fromCharCode(previousCh)); 11275 if (specialChars[ch]) { 11276 break; 11277 } 11278 strBuf.push(String.fromCharCode(ch)); 11279 continue; 11280 } 11281 strBuf.push(String.fromCharCode(x << 4 | x2)); 11282 } else { 11283 strBuf.push("#", String.fromCharCode(ch)); 11284 } 11285 } else { 11286 strBuf.push(String.fromCharCode(ch)); 11287 } 11288 } 11289 if (strBuf.length > 127) { 11290 warn(`Name token is longer than allowed by the spec: ${strBuf.length}`); 11291 } 11292 return Name.get(strBuf.join("")); 11293 } 11294 _hexStringWarn(ch) { 11295 const MAX_HEX_STRING_NUM_WARN = 5; 11296 if (this._hexStringNumWarn++ === MAX_HEX_STRING_NUM_WARN) { 11297 warn("getHexString - ignoring additional invalid characters."); 11298 return; 11299 } 11300 if (this._hexStringNumWarn > MAX_HEX_STRING_NUM_WARN) { 11301 return; 11302 } 11303 warn(`getHexString - ignoring invalid character: ${ch}`); 11304 } 11305 getHexString() { 11306 const strBuf = this.strBuf; 11307 strBuf.length = 0; 11308 let ch = this.currentChar; 11309 let firstDigit = -1, 11310 digit = -1; 11311 this._hexStringNumWarn = 0; 11312 while (true) { 11313 if (ch < 0) { 11314 warn("Unterminated hex string"); 11315 break; 11316 } else if (ch === 0x3e) { 11317 this.nextChar(); 11318 break; 11319 } else if (specialChars[ch] === 1) { 11320 ch = this.nextChar(); 11321 continue; 11322 } else { 11323 digit = toHexDigit(ch); 11324 if (digit === -1) { 11325 this._hexStringWarn(ch); 11326 } else if (firstDigit === -1) { 11327 firstDigit = digit; 11328 } else { 11329 strBuf.push(String.fromCharCode(firstDigit << 4 | digit)); 11330 firstDigit = -1; 11331 } 11332 ch = this.nextChar(); 11333 } 11334 } 11335 if (firstDigit !== -1) { 11336 strBuf.push(String.fromCharCode(firstDigit << 4)); 11337 } 11338 return strBuf.join(""); 11339 } 11340 getObj() { 11341 let comment = false; 11342 let ch = this.currentChar; 11343 while (true) { 11344 if (ch < 0) { 11345 return EOF; 11346 } 11347 if (comment) { 11348 if (ch === 0x0a || ch === 0x0d) { 11349 comment = false; 11350 } 11351 } else if (ch === 0x25) { 11352 comment = true; 11353 } else if (specialChars[ch] !== 1) { 11354 break; 11355 } 11356 ch = this.nextChar(); 11357 } 11358 switch (ch | 0) { 11359 case 0x30: 11360 case 0x31: 11361 case 0x32: 11362 case 0x33: 11363 case 0x34: 11364 case 0x35: 11365 case 0x36: 11366 case 0x37: 11367 case 0x38: 11368 case 0x39: 11369 case 0x2b: 11370 case 0x2d: 11371 case 0x2e: 11372 return this.getNumber(); 11373 case 0x28: 11374 return this.getString(); 11375 case 0x2f: 11376 return this.getName(); 11377 case 0x5b: 11378 this.nextChar(); 11379 return Cmd.get("["); 11380 case 0x5d: 11381 this.nextChar(); 11382 return Cmd.get("]"); 11383 case 0x3c: 11384 ch = this.nextChar(); 11385 if (ch === 0x3c) { 11386 this.nextChar(); 11387 return Cmd.get("<<"); 11388 } 11389 return this.getHexString(); 11390 case 0x3e: 11391 ch = this.nextChar(); 11392 if (ch === 0x3e) { 11393 this.nextChar(); 11394 return Cmd.get(">>"); 11395 } 11396 return Cmd.get(">"); 11397 case 0x7b: 11398 this.nextChar(); 11399 return Cmd.get("{"); 11400 case 0x7d: 11401 this.nextChar(); 11402 return Cmd.get("}"); 11403 case 0x29: 11404 this.nextChar(); 11405 throw new FormatError(`Illegal character: ${ch}`); 11406 } 11407 let str = String.fromCharCode(ch); 11408 if (ch < 0x20 || ch > 0x7f) { 11409 const nextCh = this.peekChar(); 11410 if (nextCh >= 0x20 && nextCh <= 0x7f) { 11411 this.nextChar(); 11412 return Cmd.get(str); 11413 } 11414 } 11415 const knownCommands = this.knownCommands; 11416 let knownCommandFound = knownCommands?.[str] !== undefined; 11417 while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) { 11418 const possibleCommand = str + String.fromCharCode(ch); 11419 if (knownCommandFound && knownCommands[possibleCommand] === undefined) { 11420 break; 11421 } 11422 if (str.length === 128) { 11423 throw new FormatError(`Command token too long: ${str.length}`); 11424 } 11425 str = possibleCommand; 11426 knownCommandFound = knownCommands?.[str] !== undefined; 11427 } 11428 if (str === "true") { 11429 return true; 11430 } 11431 if (str === "false") { 11432 return false; 11433 } 11434 if (str === "null") { 11435 return null; 11436 } 11437 if (str === "BI") { 11438 this.beginInlineImagePos = this.stream.pos; 11439 } 11440 return Cmd.get(str); 11441 } 11442 skipToNextLine() { 11443 let ch = this.currentChar; 11444 while (ch >= 0) { 11445 if (ch === 0x0d) { 11446 ch = this.nextChar(); 11447 if (ch === 0x0a) { 11448 this.nextChar(); 11449 } 11450 break; 11451 } else if (ch === 0x0a) { 11452 this.nextChar(); 11453 break; 11454 } 11455 ch = this.nextChar(); 11456 } 11457 } 11458} 11459class Linearization { 11460 static create(stream) { 11461 function getInt(linDict, name, allowZeroValue = false) { 11462 const obj = linDict.get(name); 11463 if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) { 11464 return obj; 11465 } 11466 throw new Error(`The "${name}" parameter in the linearization ` + "dictionary is invalid."); 11467 } 11468 function getHints(linDict) { 11469 const hints = linDict.get("H"); 11470 let hintsLength; 11471 if (Array.isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) { 11472 for (let index = 0; index < hintsLength; index++) { 11473 const hint = hints[index]; 11474 if (!(Number.isInteger(hint) && hint > 0)) { 11475 throw new Error(`Hint (${index}) in the linearization dictionary is invalid.`); 11476 } 11477 } 11478 return hints; 11479 } 11480 throw new Error("Hint array in the linearization dictionary is invalid."); 11481 } 11482 const parser = new Parser({ 11483 lexer: new Lexer(stream), 11484 xref: null 11485 }); 11486 const obj1 = parser.getObj(); 11487 const obj2 = parser.getObj(); 11488 const obj3 = parser.getObj(); 11489 const linDict = parser.getObj(); 11490 let obj, length; 11491 if (!(Number.isInteger(obj1) && Number.isInteger(obj2) && isCmd(obj3, "obj") && linDict instanceof Dict && typeof (obj = linDict.get("Linearized")) === "number" && obj > 0)) { 11492 return null; 11493 } else if ((length = getInt(linDict, "L")) !== stream.length) { 11494 throw new Error('The "L" parameter in the linearization dictionary ' + "does not equal the stream length."); 11495 } 11496 return { 11497 length, 11498 hints: getHints(linDict), 11499 objectNumberFirst: getInt(linDict, "O"), 11500 endFirst: getInt(linDict, "E"), 11501 numPages: getInt(linDict, "N"), 11502 mainXRefEntriesOffset: getInt(linDict, "T"), 11503 pageFirst: linDict.has("P") ? getInt(linDict, "P", true) : 0 11504 }; 11505 } 11506} 11507 11508;// ./src/core/cmap.js 11509 11510 11511 11512 11513 11514 11515 11516const BUILT_IN_CMAPS = ["Adobe-GB1-UCS2", "Adobe-CNS1-UCS2", "Adobe-Japan1-UCS2", "Adobe-Korea1-UCS2", "78-EUC-H", "78-EUC-V", "78-H", "78-RKSJ-H", "78-RKSJ-V", "78-V", "78ms-RKSJ-H", "78ms-RKSJ-V", "83pv-RKSJ-H", "90ms-RKSJ-H", "90ms-RKSJ-V", "90msp-RKSJ-H", "90msp-RKSJ-V", "90pv-RKSJ-H", "90pv-RKSJ-V", "Add-H", "Add-RKSJ-H", "Add-RKSJ-V", "Add-V", "Adobe-CNS1-0", "Adobe-CNS1-1", "Adobe-CNS1-2", "Adobe-CNS1-3", "Adobe-CNS1-4", "Adobe-CNS1-5", "Adobe-CNS1-6", "Adobe-GB1-0", "Adobe-GB1-1", "Adobe-GB1-2", "Adobe-GB1-3", "Adobe-GB1-4", "Adobe-GB1-5", "Adobe-Japan1-0", "Adobe-Japan1-1", "Adobe-Japan1-2", "Adobe-Japan1-3", "Adobe-Japan1-4", "Adobe-Japan1-5", "Adobe-Japan1-6", "Adobe-Korea1-0", "Adobe-Korea1-1", "Adobe-Korea1-2", "B5-H", "B5-V", "B5pc-H", "B5pc-V", "CNS-EUC-H", "CNS-EUC-V", "CNS1-H", "CNS1-V", "CNS2-H", "CNS2-V", "ETHK-B5-H", "ETHK-B5-V", "ETen-B5-H", "ETen-B5-V", "ETenms-B5-H", "ETenms-B5-V", "EUC-H", "EUC-V", "Ext-H", "Ext-RKSJ-H", "Ext-RKSJ-V", "Ext-V", "GB-EUC-H", "GB-EUC-V", "GB-H", "GB-V", "GBK-EUC-H", "GBK-EUC-V", "GBK2K-H", "GBK2K-V", "GBKp-EUC-H", "GBKp-EUC-V", "GBT-EUC-H", "GBT-EUC-V", "GBT-H", "GBT-V", "GBTpc-EUC-H", "GBTpc-EUC-V", "GBpc-EUC-H", "GBpc-EUC-V", "H", "HKdla-B5-H", "HKdla-B5-V", "HKdlb-B5-H", "HKdlb-B5-V", "HKgccs-B5-H", "HKgccs-B5-V", "HKm314-B5-H", "HKm314-B5-V", "HKm471-B5-H", "HKm471-B5-V", "HKscs-B5-H", "HKscs-B5-V", "Hankaku", "Hiragana", "KSC-EUC-H", "KSC-EUC-V", "KSC-H", "KSC-Johab-H", "KSC-Johab-V", "KSC-V", "KSCms-UHC-H", "KSCms-UHC-HW-H", "KSCms-UHC-HW-V", "KSCms-UHC-V", "KSCpc-EUC-H", "KSCpc-EUC-V", "Katakana", "NWP-H", "NWP-V", "RKSJ-H", "RKSJ-V", "Roman", "UniCNS-UCS2-H", "UniCNS-UCS2-V", "UniCNS-UTF16-H", "UniCNS-UTF16-V", "UniCNS-UTF32-H", "UniCNS-UTF32-V", "UniCNS-UTF8-H", "UniCNS-UTF8-V", "UniGB-UCS2-H", "UniGB-UCS2-V", "UniGB-UTF16-H", "UniGB-UTF16-V", "UniGB-UTF32-H", "UniGB-UTF32-V", "UniGB-UTF8-H", "UniGB-UTF8-V", "UniJIS-UCS2-H", "UniJIS-UCS2-HW-H", "UniJIS-UCS2-HW-V", "UniJIS-UCS2-V", "UniJIS-UTF16-H", "UniJIS-UTF16-V", "UniJIS-UTF32-H", "UniJIS-UTF32-V", "UniJIS-UTF8-H", "UniJIS-UTF8-V", "UniJIS2004-UTF16-H", "UniJIS2004-UTF16-V", "UniJIS2004-UTF32-H", "UniJIS2004-UTF32-V", "UniJIS2004-UTF8-H", "UniJIS2004-UTF8-V", "UniJISPro-UCS2-HW-V", "UniJISPro-UCS2-V", "UniJISPro-UTF8-V", "UniJISX0213-UTF32-H", "UniJISX0213-UTF32-V", "UniJISX02132004-UTF32-H", "UniJISX02132004-UTF32-V", "UniKS-UCS2-H", "UniKS-UCS2-V", "UniKS-UTF16-H", "UniKS-UTF16-V", "UniKS-UTF32-H", "UniKS-UTF32-V", "UniKS-UTF8-H", "UniKS-UTF8-V", "V", "WP-Symbol"]; 11517const MAX_MAP_RANGE = 2 ** 24 - 1; 11518class CMap { 11519 constructor(builtInCMap = false) { 11520 this.codespaceRanges = [[], [], [], []]; 11521 this.numCodespaceRanges = 0; 11522 this._map = []; 11523 this.name = ""; 11524 this.vertical = false;
vendor: 2,526 bytes, lines 11525-11614
11525 this.useCMap = null; 11526 this.builtInCMap = builtInCMap; 11527 } 11528 addCodespaceRange(n, low, high) { 11529 this.codespaceRanges[n - 1].push(low, high); 11530 this.numCodespaceRanges++; 11531 } 11532 mapCidRange(low, high, dstLow) { 11533 if (high - low > MAX_MAP_RANGE) { 11534 throw new Error("mapCidRange - ignoring data above MAX_MAP_RANGE."); 11535 } 11536 while (low <= high) { 11537 this._map[low++] = dstLow++; 11538 } 11539 } 11540 mapBfRange(low, high, dstLow) { 11541 if (high - low > MAX_MAP_RANGE) { 11542 throw new Error("mapBfRange - ignoring data above MAX_MAP_RANGE."); 11543 } 11544 const lastByte = dstLow.length - 1; 11545 while (low <= high) { 11546 this._map[low++] = dstLow; 11547 const nextCharCode = dstLow.charCodeAt(lastByte) + 1; 11548 if (nextCharCode > 0xff) { 11549 dstLow = dstLow.substring(0, lastByte - 1) + String.fromCharCode(dstLow.charCodeAt(lastByte - 1) + 1) + "\x00"; 11550 continue; 11551 } 11552 dstLow = dstLow.substring(0, lastByte) + String.fromCharCode(nextCharCode); 11553 } 11554 } 11555 mapBfRangeToArray(low, high, array) { 11556 if (high - low > MAX_MAP_RANGE) { 11557 throw new Error("mapBfRangeToArray - ignoring data above MAX_MAP_RANGE."); 11558 } 11559 const ii = array.length; 11560 let i = 0; 11561 while (low <= high && i < ii) { 11562 this._map[low] = array[i++]; 11563 ++low; 11564 } 11565 } 11566 mapOne(src, dst) { 11567 this._map[src] = dst; 11568 } 11569 lookup(code) { 11570 return this._map[code]; 11571 } 11572 contains(code) { 11573 return this._map[code] !== undefined; 11574 } 11575 forEach(callback) { 11576 const map = this._map; 11577 const length = map.length; 11578 if (length <= 0x10000) { 11579 for (let i = 0; i < length; i++) { 11580 if (map[i] !== undefined) { 11581 callback(i, map[i]); 11582 } 11583 } 11584 } else { 11585 for (const i in map) { 11586 callback(i, map[i]); 11587 } 11588 } 11589 } 11590 charCodeOf(value) { 11591 const map = this._map; 11592 if (map.length <= 0x10000) { 11593 return map.indexOf(value); 11594 } 11595 for (const charCode in map) { 11596 if (map[charCode] === value) { 11597 return charCode | 0; 11598 } 11599 } 11600 return -1; 11601 } 11602 getMap() { 11603 return this._map; 11604 } 11605 readCharCode(str, offset, out) { 11606 let c = 0; 11607 const codespaceRanges = this.codespaceRanges; 11608 for (let n = 0, nn = codespaceRanges.length; n < nn; n++) { 11609 c = (c << 8 | str.charCodeAt(offset + n)) >>> 0; 11610 const codespaceRange = codespaceRanges[n]; 11611 for (let k = 0, kk = codespaceRange.length; k < kk;) { 11612 const low = codespaceRange[k++]; 11613 const high = codespaceRange[k++]; 11614 if (c >= low && c <= high) {
vendor: 5,562 bytes, lines 11615-11849
11615 out.charcode = c; 11616 out.length = n + 1; 11617 return; 11618 } 11619 } 11620 } 11621 out.charcode = 0; 11622 out.length = 1; 11623 } 11624 getCharCodeLength(charCode) { 11625 const codespaceRanges = this.codespaceRanges; 11626 for (let n = 0, nn = codespaceRanges.length; n < nn; n++) { 11627 const codespaceRange = codespaceRanges[n]; 11628 for (let k = 0, kk = codespaceRange.length; k < kk;) { 11629 const low = codespaceRange[k++]; 11630 const high = codespaceRange[k++]; 11631 if (charCode >= low && charCode <= high) { 11632 return n + 1; 11633 } 11634 } 11635 } 11636 return 1; 11637 } 11638 get length() { 11639 return this._map.length; 11640 } 11641 get isIdentityCMap() { 11642 if (!(this.name === "Identity-H" || this.name === "Identity-V")) { 11643 return false; 11644 } 11645 if (this._map.length !== 0x10000) { 11646 return false; 11647 } 11648 for (let i = 0; i < 0x10000; i++) { 11649 if (this._map[i] !== i) { 11650 return false; 11651 } 11652 } 11653 return true; 11654 } 11655} 11656class IdentityCMap extends CMap { 11657 constructor(vertical, n) { 11658 super(); 11659 this.vertical = vertical; 11660 this.addCodespaceRange(n, 0, 0xffff); 11661 } 11662 mapCidRange(low, high, dstLow) { 11663 unreachable("should not call mapCidRange"); 11664 } 11665 mapBfRange(low, high, dstLow) { 11666 unreachable("should not call mapBfRange"); 11667 } 11668 mapBfRangeToArray(low, high, array) { 11669 unreachable("should not call mapBfRangeToArray"); 11670 } 11671 mapOne(src, dst) { 11672 unreachable("should not call mapCidOne"); 11673 } 11674 lookup(code) { 11675 return Number.isInteger(code) && code <= 0xffff ? code : undefined; 11676 } 11677 contains(code) { 11678 return Number.isInteger(code) && code <= 0xffff; 11679 } 11680 forEach(callback) { 11681 for (let i = 0; i <= 0xffff; i++) { 11682 callback(i, i); 11683 } 11684 } 11685 charCodeOf(value) { 11686 return Number.isInteger(value) && value <= 0xffff ? value : -1; 11687 } 11688 getMap() { 11689 const map = new Array(0x10000); 11690 for (let i = 0; i <= 0xffff; i++) { 11691 map[i] = i; 11692 } 11693 return map; 11694 } 11695 get length() { 11696 return 0x10000; 11697 } 11698 get isIdentityCMap() { 11699 unreachable("should not access .isIdentityCMap"); 11700 } 11701} 11702function strToInt(str) { 11703 let a = 0; 11704 for (let i = 0; i < str.length; i++) { 11705 a = a << 8 | str.charCodeAt(i); 11706 } 11707 return a >>> 0; 11708} 11709function expectString(obj) { 11710 if (typeof obj !== "string") { 11711 throw new FormatError("Malformed CMap: expected string."); 11712 } 11713} 11714function expectInt(obj) { 11715 if (!Number.isInteger(obj)) { 11716 throw new FormatError("Malformed CMap: expected int."); 11717 } 11718} 11719function parseBfChar(cMap, lexer) { 11720 while (true) { 11721 let obj = lexer.getObj(); 11722 if (obj === EOF) { 11723 break; 11724 } 11725 if (isCmd(obj, "endbfchar")) { 11726 return; 11727 } 11728 expectString(obj); 11729 const src = strToInt(obj); 11730 obj = lexer.getObj(); 11731 expectString(obj); 11732 const dst = obj; 11733 cMap.mapOne(src, dst); 11734 } 11735} 11736function parseBfRange(cMap, lexer) { 11737 while (true) { 11738 let obj = lexer.getObj(); 11739 if (obj === EOF) { 11740 break; 11741 } 11742 if (isCmd(obj, "endbfrange")) { 11743 return; 11744 } 11745 expectString(obj); 11746 const low = strToInt(obj); 11747 obj = lexer.getObj(); 11748 expectString(obj); 11749 const high = strToInt(obj); 11750 obj = lexer.getObj(); 11751 if (Number.isInteger(obj) || typeof obj === "string") { 11752 const dstLow = Number.isInteger(obj) ? String.fromCharCode(obj) : obj; 11753 cMap.mapBfRange(low, high, dstLow); 11754 } else if (isCmd(obj, "[")) { 11755 obj = lexer.getObj(); 11756 const array = []; 11757 while (!isCmd(obj, "]") && obj !== EOF) { 11758 array.push(obj); 11759 obj = lexer.getObj(); 11760 } 11761 cMap.mapBfRangeToArray(low, high, array); 11762 } else { 11763 break; 11764 } 11765 } 11766 throw new FormatError("Invalid bf range."); 11767} 11768function parseCidChar(cMap, lexer) { 11769 while (true) { 11770 let obj = lexer.getObj(); 11771 if (obj === EOF) { 11772 break; 11773 } 11774 if (isCmd(obj, "endcidchar")) { 11775 return; 11776 } 11777 expectString(obj); 11778 const src = strToInt(obj); 11779 obj = lexer.getObj(); 11780 expectInt(obj); 11781 const dst = obj; 11782 cMap.mapOne(src, dst); 11783 } 11784} 11785function parseCidRange(cMap, lexer) { 11786 while (true) { 11787 let obj = lexer.getObj(); 11788 if (obj === EOF) { 11789 break; 11790 } 11791 if (isCmd(obj, "endcidrange")) { 11792 return; 11793 } 11794 expectString(obj); 11795 const low = strToInt(obj); 11796 obj = lexer.getObj(); 11797 expectString(obj); 11798 const high = strToInt(obj); 11799 obj = lexer.getObj(); 11800 expectInt(obj); 11801 const dstLow = obj; 11802 cMap.mapCidRange(low, high, dstLow); 11803 } 11804} 11805function parseCodespaceRange(cMap, lexer) { 11806 while (true) { 11807 let obj = lexer.getObj(); 11808 if (obj === EOF) { 11809 break; 11810 } 11811 if (isCmd(obj, "endcodespacerange")) { 11812 return; 11813 } 11814 if (typeof obj !== "string") { 11815 break; 11816 } 11817 const low = strToInt(obj); 11818 obj = lexer.getObj(); 11819 if (typeof obj !== "string") { 11820 break; 11821 } 11822 const high = strToInt(obj); 11823 cMap.addCodespaceRange(obj.length, low, high); 11824 } 11825 throw new FormatError("Invalid codespace range."); 11826} 11827function parseWMode(cMap, lexer) { 11828 const obj = lexer.getObj(); 11829 if (Number.isInteger(obj)) { 11830 cMap.vertical = !!obj; 11831 } 11832} 11833function parseCMapName(cMap, lexer) { 11834 const obj = lexer.getObj(); 11835 if (obj instanceof Name) { 11836 cMap.name = obj.name; 11837 } 11838} 11839async function parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap) { 11840 let previous, embeddedUseCMap; 11841 objLoop: while (true) { 11842 try { 11843 const obj = lexer.getObj(); 11844 if (obj === EOF) { 11845 break; 11846 } else if (obj instanceof Name) { 11847 if (obj.name === "WMode") { 11848 parseWMode(cMap, lexer); 11849 } else if (obj.name === "CMapName") {
vendor: 10,601 bytes, lines 11850-11956
11850 parseCMapName(cMap, lexer); 11851 } 11852 previous = obj; 11853 } else if (obj instanceof Cmd) { 11854 switch (obj.cmd) { 11855 case "endcmap": 11856 break objLoop; 11857 case "usecmap": 11858 if (previous instanceof Name) { 11859 embeddedUseCMap = previous.name; 11860 } 11861 break; 11862 case "begincodespacerange": 11863 parseCodespaceRange(cMap, lexer); 11864 break; 11865 case "beginbfchar": 11866 parseBfChar(cMap, lexer); 11867 break; 11868 case "begincidchar": 11869 parseCidChar(cMap, lexer); 11870 break; 11871 case "beginbfrange": 11872 parseBfRange(cMap, lexer); 11873 break; 11874 case "begincidrange": 11875 parseCidRange(cMap, lexer); 11876 break; 11877 } 11878 } 11879 } catch (ex) { 11880 if (ex instanceof MissingDataException) { 11881 throw ex; 11882 } 11883 warn("Invalid cMap data: " + ex); 11884 continue; 11885 } 11886 } 11887 if (!useCMap && embeddedUseCMap) { 11888 useCMap = embeddedUseCMap; 11889 } 11890 if (useCMap) { 11891 return extendCMap(cMap, fetchBuiltInCMap, useCMap); 11892 } 11893 return cMap; 11894} 11895async function extendCMap(cMap, fetchBuiltInCMap, useCMap) { 11896 cMap.useCMap = await createBuiltInCMap(useCMap, fetchBuiltInCMap); 11897 if (cMap.numCodespaceRanges === 0) { 11898 const useCodespaceRanges = cMap.useCMap.codespaceRanges; 11899 for (let i = 0; i < useCodespaceRanges.length; i++) { 11900 cMap.codespaceRanges[i] = useCodespaceRanges[i].slice(); 11901 } 11902 cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges; 11903 } 11904 cMap.useCMap.forEach(function (key, value) { 11905 if (!cMap.contains(key)) { 11906 cMap.mapOne(key, value); 11907 } 11908 }); 11909 return cMap; 11910} 11911async function createBuiltInCMap(name, fetchBuiltInCMap) { 11912 if (name === "Identity-H") { 11913 return new IdentityCMap(false, 2); 11914 } else if (name === "Identity-V") { 11915 return new IdentityCMap(true, 2); 11916 } 11917 if (!BUILT_IN_CMAPS.includes(name)) { 11918 throw new Error("Unknown CMap name: " + name); 11919 } 11920 if (!fetchBuiltInCMap) { 11921 throw new Error("Built-in CMap parameters are not provided."); 11922 } 11923 const { 11924 cMapData, 11925 isCompressed 11926 } = await fetchBuiltInCMap(name); 11927 const cMap = new CMap(true); 11928 if (isCompressed) { 11929 return new BinaryCMapReader().process(cMapData, cMap, useCMap => extendCMap(cMap, fetchBuiltInCMap, useCMap)); 11930 } 11931 const lexer = new Lexer(new Stream(cMapData)); 11932 return parseCMap(cMap, lexer, fetchBuiltInCMap, null); 11933} 11934class CMapFactory { 11935 static async create({ 11936 encoding, 11937 fetchBuiltInCMap, 11938 useCMap 11939 }) { 11940 if (encoding instanceof Name) { 11941 return createBuiltInCMap(encoding.name, fetchBuiltInCMap); 11942 } else if (encoding instanceof BaseStream) { 11943 const parsedCMap = await parseCMap(new CMap(), new Lexer(encoding), fetchBuiltInCMap, useCMap); 11944 if (parsedCMap.isIdentityCMap) { 11945 return createBuiltInCMap(parsedCMap.name, fetchBuiltInCMap); 11946 } 11947 return parsedCMap; 11948 } 11949 throw new Error("Encoding required."); 11950 } 11951} 11952 11953;// ./src/core/encodings.js 11954const ExpertEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclamsmall", "Hungarumlautsmall", "", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "commasuperior", "threequartersemdash", "periodsuperior", "questionsmall", "", "asuperior", "bsuperior", "centsuperior", "dsuperior", "esuperior", "", "", "", "isuperior", "", "", "lsuperior", "msuperior", "nsuperior", "osuperior", "", "", "rsuperior", "ssuperior", "tsuperior", "", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "", "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "exclamdownsmall", "centoldstyle", "Lslashsmall", "", "", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall", "Caronsmall", "", "Dotaccentsmall", "", "", "Macronsmall", "", "", "figuredash", "hypheninferior", "", "", "Ogoneksmall", "Ringsmall", "Cedillasmall", "", "", "", "onequarter", "onehalf", "threequarters", "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "", "", "zerosuperior", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", "threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior", "dollarinferior", "periodinferior", "commainferior", "Agravesmall", "Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall", "Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall", "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall", "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall", "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall", "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall", "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall", "Ydieresissmall"]; 11955const MacExpertEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclamsmall", "Hungarumlautsmall", "centoldstyle", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "", "threequartersemdash", "", "questionsmall", "", "", "", "", "Ethsmall", "", "", "onequarter", "onehalf", "threequarters", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "", "", "", "", "", "", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "", "parenrightinferior", "Circumflexsmall", "hypheninferior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "", "", "asuperior", "centsuperior", "", "", "", "", "Aacutesmall", "Agravesmall", "Acircumflexsmall", "Adieresissmall", "Atildesmall", "Aringsmall", "Ccedillasmall", "Eacutesmall", "Egravesmall", "Ecircumflexsmall", "Edieresissmall", "Iacutesmall", "Igravesmall", "Icircumflexsmall", "Idieresissmall", "Ntildesmall", "Oacutesmall", "Ogravesmall", "Ocircumflexsmall", "Odieresissmall", "Otildesmall", "Uacutesmall", "Ugravesmall", "Ucircumflexsmall", "Udieresissmall", "", "eightsuperior", "fourinferior", "threeinferior", "sixinferior", "eightinferior", "seveninferior", "Scaronsmall", "", "centinferior", "twoinferior", "", "Dieresissmall", "", "Caronsmall", "osuperior", "fiveinferior", "", "commainferior", "periodinferior", "Yacutesmall", "", "dollarinferior", "", "", "Thornsmall", "", "nineinferior", "zeroinferior", "Zcaronsmall", "AEsmall", "Oslashsmall", "questiondownsmall", "oneinferior", "Lslashsmall", "", "", "", "", "", "", "Cedillasmall", "", "", "", "", "", "OEsmall", "figuredash", "hyphensuperior", "", "", "", "", "exclamdownsmall", "", "Ydieresissmall", "", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "ninesuperior", "zerosuperior", "", "esuperior", "rsuperior", "tsuperior", "", "", "isuperior", "ssuperior", "dsuperior", "", "", "", "", "", "lsuperior", "Ogoneksmall", "Brevesmall", "Macronsmall", "bsuperior", "nsuperior", "msuperior", "commasuperior", "periodsuperior", "Dotaccentsmall", "Ringsmall", "", "", "", ""]; 11956const MacRomanEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "", "Adieresis", "Aring", "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute", "agrave", "acircumflex", "adieresis", "atilde", "aring", "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute", "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling", "section", "bullet", "paragraph", "germandbls", "registered", "copyright", "trademark", "acute", "dieresis", "notequal", "AE", "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", "yen", "mu", "partialdiff", "summation", "product", "pi", "integral", "ordfeminine", "ordmasculine", "Omega", "ae", "oslash", "questiondown", "exclamdown", "logicalnot", "radical", "florin", "approxequal", "Delta", "guillemotleft", "guillemotright", "ellipsis", "space", "Agrave", "Atilde", "Otilde", "OE", "oe", "endash", "emdash", "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide", "lozenge", "ydieresis", "Ydieresis", "fraction", "currency", "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl", "periodce
vendor: 128,913 bytes, lines 11956-16529
11956ntered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex", "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", "circumflex", "tilde", "macron", "breve", "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek", "caron"]; 11957const StandardEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "exclamdown", "cent", "sterling", "fraction", "yen", "florin", "section", "currency", "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl", "", "endash", "dagger", "daggerdbl", "periodcentered", "", "paragraph", "bullet", "quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", "ellipsis", "perthousand", "", "questiondown", "", "grave", "acute", "circumflex", "tilde", "macron", "breve", "dotaccent", "dieresis", "", "ring", "cedilla", "", "hungarumlaut", "ogonek", "caron", "emdash", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "AE", "", "ordfeminine", "", "", "", "", "Lslash", "Oslash", "OE", "ordmasculine", "", "", "", "", "", "ae", "", "", "", "dotlessi", "", "", "lslash", "oslash", "oe", "germandbls", "", "", "", ""]; 11958const WinAnsiEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "bullet", "Euro", "bullet", "quotesinglbase", "florin", "quotedblbase", "ellipsis", "dagger", "daggerdbl", "circumflex", "perthousand", "Scaron", "guilsinglleft", "OE", "bullet", "Zcaron", "bullet", "bullet", "quoteleft", "quoteright", "quotedblleft", "quotedblright", "bullet", "endash", "emdash", "tilde", "trademark", "scaron", "guilsinglright", "oe", "bullet", "zcaron", "Ydieresis", "space", "exclamdown", "cent", "sterling", "currency", "yen", "brokenbar", "section", "dieresis", "copyright", "ordfeminine", "guillemotleft", "logicalnot", "hyphen", "registered", "macron", "degree", "plusminus", "twosuperior", "threesuperior", "acute", "mu", "paragraph", "periodcentered", "cedilla", "onesuperior", "ordmasculine", "guillemotright", "onequarter", "onehalf", "threequarters", "questiondown", "Agrave", "Aacute", "Acircumflex", "Atilde", "Adieresis", "Aring", "AE", "Ccedilla", "Egrave", "Eacute", "Ecircumflex", "Edieresis", "Igrave", "Iacute", "Icircumflex", "Idieresis", "Eth", "Ntilde", "Ograve", "Oacute", "Ocircumflex", "Otilde", "Odieresis", "multiply", "Oslash", "Ugrave", "Uacute", "Ucircumflex", "Udieresis", "Yacute", "Thorn", "germandbls", "agrave", "aacute", "acircumflex", "atilde", "adieresis", "aring", "ae", "ccedilla", "egrave", "eacute", "ecircumflex", "edieresis", "igrave", "iacute", "icircumflex", "idieresis", "eth", "ntilde", "ograve", "oacute", "ocircumflex", "otilde", "odieresis", "divide", "oslash", "ugrave", "uacute", "ucircumflex", "udieresis", "yacute", "thorn", "ydieresis"]; 11959const SymbolSetEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclam", "universal", "numbersign", "existential", "percent", "ampersand", "suchthat", "parenleft", "parenright", "asteriskmath", "plus", "comma", "minus", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "congruent", "Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi", "Gamma", "Eta", "Iota", "theta1", "Kappa", "Lambda", "Mu", "Nu", "Omicron", "Pi", "Theta", "Rho", "Sigma", "Tau", "Upsilon", "sigma1", "Omega", "Xi", "Psi", "Zeta", "bracketleft", "therefore", "bracketright", "perpendicular", "underscore", "radicalex", "alpha", "beta", "chi", "delta", "epsilon", "phi", "gamma", "eta", "iota", "phi1", "kappa", "lambda", "mu", "nu", "omicron", "pi", "theta", "rho", "sigma", "tau", "upsilon", "omega1", "omega", "xi", "psi", "zeta", "braceleft", "bar", "braceright", "similar", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Euro", "Upsilon1", "minute", "lessequal", "fraction", "infinity", "florin", "club", "diamond", "heart", "spade", "arrowboth", "arrowleft", "arrowup", "arrowright", "arrowdown", "degree", "plusminus", "second", "greaterequal", "multiply", "proportional", "partialdiff", "bullet", "divide", "notequal", "equivalence", "approxequal", "ellipsis", "arrowvertex", "arrowhorizex", "carriagereturn", "aleph", "Ifraktur", "Rfraktur", "weierstrass", "circlemultiply", "circleplus", "emptyset", "intersection", "union", "propersuperset", "reflexsuperset", "notsubset", "propersubset", "reflexsubset", "element", "notelement", "angle", "gradient", "registerserif", "copyrightserif", "trademarkserif", "product", "radical", "dotmath", "logicalnot", "logicaland", "logicalor", "arrowdblboth", "arrowdblleft", "arrowdblup", "arrowdblright", "arrowdbldown", "lozenge", "angleleft", "registersans", "copyrightsans", "trademarksans", "summation", "parenlefttp", "parenleftex", "parenleftbt", "bracketlefttp", "bracketleftex", "bracketleftbt", "bracelefttp", "braceleftmid", "braceleftbt", "braceex", "", "angleright", "integral", "integraltp", "integralex", "integralbt", "parenrighttp", "parenrightex", "parenrightbt", "bracketrighttp", "bracketrightex", "bracketrightbt", "bracerighttp", "bracerightmid", "bracerightbt", ""]; 11960const ZapfDingbatsEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "a1", "a2", "a202", "a3", "a4", "a5", "a119", "a118", "a117", "a11", "a12", "a13", "a14", "a15", "a16", "a105", "a17", "a18", "a19", "a20", "a21", "a22", "a23", "a24", "a25", "a26", "a27", "a28", "a6", "a7", "a8", "a9", "a10", "a29", "a30", "a31", "a32", "a33", "a34", "a35", "a36", "a37", "a38", "a39", "a40", "a41", "a42", "a43", "a44", "a45", "a46", "a47", "a48", "a49", "a50", "a51", "a52", "a53", "a54", "a55", "a56", "a57", "a58", "a59", "a60", "a61", "a62", "a63", "a64", "a65", "a66", "a67", "a68", "a69", "a70", "a71", "a72", "a73", "a74", "a203", "a75", "a204", "a76", "a77", "a78", "a79", "a81", "a82", "a83", "a84", "a97", "a98", "a99", "a100", "", "a89", "a90", "a93", "a94", "a91", "a92", "a205", "a85", "a206", "a86", "a87", "a88", "a95", "a96", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "a101", "a102", "a103", "a104", "a106", "a107", "a108", "a112", "a111", "a110", "a109", "a120", "a121", "a122", "a123", "a124", "a125", "a126", "a127", "a128", "a129", "a130", "a131", "a132", "a133", "a134", "a135", "a136", "a137", "a138", "a139", "a140", "a141", "a142", "a143", "a144", "a145", "a146", "a147", "a148", "a149", "a150", "a151", "a152", "a153", "a154", "a155", "a156", "a157", "a158", "a159", "a160", "a161", "a163", "a164", "a196", "a165", "a192", "a166", "a167", "a168", "a169", "a170", "a171", "a172", "a173", "a162", "a174", "a175", "a176", "a177", "a178", "a179", "a193", "a180", "a199", "a181", "a200", "a182", "", "a201", "a183", "a184", "a197", "a185", "a194", "a198", "a186", "a195", "a187", "a188", "a189", "a190", "a191", ""]; 11961function getEncoding(encodingName) { 11962 switch (encodingName) { 11963 case "WinAnsiEncoding": 11964 return WinAnsiEncoding; 11965 case "StandardEncoding": 11966 return StandardEncoding; 11967 case "MacRomanEncoding": 11968 return MacRomanEncoding; 11969 case "SymbolSetEncoding": 11970 return SymbolSetEncoding; 11971 case "ZapfDingbatsEncoding": 11972 return ZapfDingbatsEncoding; 11973 case "ExpertEncoding": 11974 return ExpertEncoding; 11975 case "MacExpertEncoding": 11976 return MacExpertEncoding; 11977 default: 11978 return null; 11979 } 11980} 11981 11982;// ./src/core/glyphlist.js 11983 11984const getGlyphsUnicode = getLookupTableFactory(function (t) { 11985 t.A = 0x0041; 11986 t.AE = 0x00c6; 11987 t.AEacute = 0x01fc; 11988 t.AEmacron = 0x01e2; 11989 t.AEsmall = 0xf7e6; 11990 t.Aacute = 0x00c1; 11991 t.Aacutesmall = 0xf7e1; 11992 t.Abreve = 0x0102; 11993 t.Abreveacute = 0x1eae; 11994 t.Abrevecyrillic = 0x04d0; 11995 t.Abrevedotbelow = 0x1eb6; 11996 t.Abrevegrave = 0x1eb0; 11997 t.Abrevehookabove = 0x1eb2; 11998 t.Abrevetilde = 0x1eb4; 11999 t.Acaron = 0x01cd; 12000 t.Acircle = 0x24b6; 12001 t.Acircumflex = 0x00c2; 12002 t.Acircumflexacute = 0x1ea4; 12003 t.Acircumflexdotbelow = 0x1eac; 12004 t.Acircumflexgrave = 0x1ea6; 12005 t.Acircumflexhookabove = 0x1ea8; 12006 t.Acircumflexsmall = 0xf7e2; 12007 t.Acircumflextilde = 0x1eaa; 12008 t.Acute = 0xf6c9; 12009 t.Acutesmall = 0xf7b4; 12010 t.Acyrillic = 0x0410; 12011 t.Adblgrave = 0x0200; 12012 t.Adieresis = 0x00c4; 12013 t.Adieresiscyrillic = 0x04d2; 12014 t.Adieresismacron = 0x01de; 12015 t.Adieresissmall = 0xf7e4; 12016 t.Adotbelow = 0x1ea0; 12017 t.Adotmacron = 0x01e0; 12018 t.Agrave = 0x00c0; 12019 t.Agravesmall = 0xf7e0; 12020 t.Ahookabove = 0x1ea2; 12021 t.Aiecyrillic = 0x04d4; 12022 t.Ainvertedbreve = 0x0202; 12023 t.Alpha = 0x0391; 12024 t.Alphatonos = 0x0386; 12025 t.Amacron = 0x0100; 12026 t.Amonospace = 0xff21; 12027 t.Aogonek = 0x0104; 12028 t.Aring = 0x00c5; 12029 t.Aringacute = 0x01fa; 12030 t.Aringbelow = 0x1e00; 12031 t.Aringsmall = 0xf7e5; 12032 t.Asmall = 0xf761; 12033 t.Atilde = 0x00c3; 12034 t.Atildesmall = 0xf7e3; 12035 t.Aybarmenian = 0x0531; 12036 t.B = 0x0042; 12037 t.Bcircle = 0x24b7; 12038 t.Bdotaccent = 0x1e02; 12039 t.Bdotbelow = 0x1e04; 12040 t.Becyrillic = 0x0411; 12041 t.Benarmenian = 0x0532; 12042 t.Beta = 0x0392; 12043 t.Bhook = 0x0181; 12044 t.Blinebelow = 0x1e06; 12045 t.Bmonospace = 0xff22; 12046 t.Brevesmall = 0xf6f4; 12047 t.Bsmall = 0xf762; 12048 t.Btopbar = 0x0182; 12049 t.C = 0x0043; 12050 t.Caarmenian = 0x053e; 12051 t.Cacute = 0x0106; 12052 t.Caron = 0xf6ca; 12053 t.Caronsmall = 0xf6f5; 12054 t.Ccaron = 0x010c; 12055 t.Ccedilla = 0x00c7; 12056 t.Ccedillaacute = 0x1e08; 12057 t.Ccedillasmall = 0xf7e7; 12058 t.Ccircle = 0x24b8; 12059 t.Ccircumflex = 0x0108; 12060 t.Cdot = 0x010a; 12061 t.Cdotaccent = 0x010a; 12062 t.Cedillasmall = 0xf7b8; 12063 t.Chaarmenian = 0x0549; 12064 t.Cheabkhasiancyrillic = 0x04bc; 12065 t.Checyrillic = 0x0427; 12066 t.Chedescenderabkhasiancyrillic = 0x04be; 12067 t.Chedescendercyrillic = 0x04b6; 12068 t.Chedieresiscyrillic = 0x04f4; 12069 t.Cheharmenian = 0x0543; 12070 t.Chekhakassiancyrillic = 0x04cb; 12071 t.Cheverticalstrokecyrillic = 0x04b8; 12072 t.Chi = 0x03a7; 12073 t.Chook = 0x0187; 12074 t.Circumflexsmall = 0xf6f6; 12075 t.Cmonospace = 0xff23; 12076 t.Coarmenian = 0x0551; 12077 t.Csmall = 0xf763; 12078 t.D = 0x0044; 12079 t.DZ = 0x01f1; 12080 t.DZcaron = 0x01c4; 12081 t.Daarmenian = 0x0534; 12082 t.Dafrican = 0x0189; 12083 t.Dcaron = 0x010e; 12084 t.Dcedilla = 0x1e10; 12085 t.Dcircle = 0x24b9; 12086 t.Dcircumflexbelow = 0x1e12; 12087 t.Dcroat = 0x0110; 12088 t.Ddotaccent = 0x1e0a; 12089 t.Ddotbelow = 0x1e0c; 12090 t.Decyrillic = 0x0414; 12091 t.Deicoptic = 0x03ee; 12092 t.Delta = 0x2206; 12093 t.Deltagreek = 0x0394; 12094 t.Dhook = 0x018a; 12095 t.Dieresis = 0xf6cb; 12096 t.DieresisAcute = 0xf6cc; 12097 t.DieresisGrave = 0xf6cd; 12098 t.Dieresissmall = 0xf7a8; 12099 t.Digammagreek = 0x03dc; 12100 t.Djecyrillic = 0x0402; 12101 t.Dlinebelow = 0x1e0e; 12102 t.Dmonospace = 0xff24; 12103 t.Dotaccentsmall = 0xf6f7; 12104 t.Dslash = 0x0110; 12105 t.Dsmall = 0xf764; 12106 t.Dtopbar = 0x018b; 12107 t.Dz = 0x01f2; 12108 t.Dzcaron = 0x01c5; 12109 t.Dzeabkhasiancyrillic = 0x04e0; 12110 t.Dzecyrillic = 0x0405; 12111 t.Dzhecyrillic = 0x040f; 12112 t.E = 0x0045; 12113 t.Eacute = 0x00c9; 12114 t.Eacutesmall = 0xf7e9; 12115 t.Ebreve = 0x0114; 12116 t.Ecaron = 0x011a; 12117 t.Ecedillabreve = 0x1e1c; 12118 t.Echarmenian = 0x0535; 12119 t.Ecircle = 0x24ba; 12120 t.Ecircumflex = 0x00ca; 12121 t.Ecircumflexacute = 0x1ebe; 12122 t.Ecircumflexbelow = 0x1e18; 12123 t.Ecircumflexdotbelow = 0x1ec6; 12124 t.Ecircumflexgrave = 0x1ec0; 12125 t.Ecircumflexhookabove = 0x1ec2; 12126 t.Ecircumflexsmall = 0xf7ea; 12127 t.Ecircumflextilde = 0x1ec4; 12128 t.Ecyrillic = 0x0404; 12129 t.Edblgrave = 0x0204; 12130 t.Edieresis = 0x00cb; 12131 t.Edieresissmall = 0xf7eb; 12132 t.Edot = 0x0116; 12133 t.Edotaccent = 0x0116; 12134 t.Edotbelow = 0x1eb8; 12135 t.Efcyrillic = 0x0424; 12136 t.Egrave = 0x00c8; 12137 t.Egravesmall = 0xf7e8; 12138 t.Eharmenian = 0x0537; 12139 t.Ehookabove = 0x1eba; 12140 t.Eightroman = 0x2167; 12141 t.Einvertedbreve = 0x0206; 12142 t.Eiotifiedcyrillic = 0x0464; 12143 t.Elcyrillic = 0x041b; 12144 t.Elevenroman = 0x216a; 12145 t.Emacron = 0x0112; 12146 t.Emacronacute = 0x1e16; 12147 t.Emacrongrave = 0x1e14; 12148 t.Emcyrillic = 0x041c; 12149 t.Emonospace = 0xff25; 12150 t.Encyrillic = 0x041d; 12151 t.Endescendercyrillic = 0x04a2; 12152 t.Eng = 0x014a; 12153 t.Enghecyrillic = 0x04a4; 12154 t.Enhookcyrillic = 0x04c7; 12155 t.Eogonek = 0x0118; 12156 t.Eopen = 0x0190; 12157 t.Epsilon = 0x0395; 12158 t.Epsilontonos = 0x0388; 12159 t.Ercyrillic = 0x0420; 12160 t.Ereversed = 0x018e; 12161 t.Ereversedcyrillic = 0x042d; 12162 t.Escyrillic = 0x0421; 12163 t.Esdescendercyrillic = 0x04aa; 12164 t.Esh = 0x01a9; 12165 t.Esmall = 0xf765; 12166 t.Eta = 0x0397; 12167 t.Etarmenian = 0x0538; 12168 t.Etatonos = 0x0389; 12169 t.Eth = 0x00d0; 12170 t.Ethsmall = 0xf7f0; 12171 t.Etilde = 0x1ebc; 12172 t.Etildebelow = 0x1e1a; 12173 t.Euro = 0x20ac; 12174 t.Ezh = 0x01b7; 12175 t.Ezhcaron = 0x01ee; 12176 t.Ezhreversed = 0x01b8; 12177 t.F = 0x0046; 12178 t.Fcircle = 0x24bb; 12179 t.Fdotaccent = 0x1e1e; 12180 t.Feharmenian = 0x0556; 12181 t.Feicoptic = 0x03e4; 12182 t.Fhook = 0x0191; 12183 t.Fitacyrillic = 0x0472; 12184 t.Fiveroman = 0x2164; 12185 t.Fmonospace = 0xff26; 12186 t.Fourroman = 0x2163; 12187 t.Fsmall = 0xf766; 12188 t.G = 0x0047; 12189 t.GBsquare = 0x3387; 12190 t.Gacute = 0x01f4; 12191 t.Gamma = 0x0393; 12192 t.Gammaafrican = 0x0194; 12193 t.Gangiacoptic = 0x03ea; 12194 t.Gbreve = 0x011e; 12195 t.Gcaron = 0x01e6; 12196 t.Gcedilla = 0x0122; 12197 t.Gcircle = 0x24bc; 12198 t.Gcircumflex = 0x011c; 12199 t.Gcommaaccent = 0x0122; 12200 t.Gdot = 0x0120; 12201 t.Gdotaccent = 0x0120; 12202 t.Gecyrillic = 0x0413; 12203 t.Ghadarmenian = 0x0542; 12204 t.Ghemiddlehookcyrillic = 0x0494; 12205 t.Ghestrokecyrillic = 0x0492; 12206 t.Gheupturncyrillic = 0x0490; 12207 t.Ghook = 0x0193; 12208 t.Gimarmenian = 0x0533; 12209 t.Gjecyrillic = 0x0403; 12210 t.Gmacron = 0x1e20; 12211 t.Gmonospace = 0xff27; 12212 t.Grave = 0xf6ce; 12213 t.Gravesmall = 0xf760; 12214 t.Gsmall = 0xf767; 12215 t.Gsmallhook = 0x029b; 12216 t.Gstroke = 0x01e4; 12217 t.H = 0x0048; 12218 t.H18533 = 0x25cf; 12219 t.H18543 = 0x25aa; 12220 t.H18551 = 0x25ab; 12221 t.H22073 = 0x25a1; 12222 t.HPsquare = 0x33cb; 12223 t.Haabkhasiancyrillic = 0x04a8; 12224 t.Hadescendercyrillic = 0x04b2; 12225 t.Hardsigncyrillic = 0x042a; 12226 t.Hbar = 0x0126; 12227 t.Hbrevebelow = 0x1e2a; 12228 t.Hcedilla = 0x1e28; 12229 t.Hcircle = 0x24bd; 12230 t.Hcircumflex = 0x0124; 12231 t.Hdieresis = 0x1e26; 12232 t.Hdotaccent = 0x1e22; 12233 t.Hdotbelow = 0x1e24; 12234 t.Hmonospace = 0xff28; 12235 t.Hoarmenian = 0x0540; 12236 t.Horicoptic = 0x03e8; 12237 t.Hsmall = 0xf768; 12238 t.Hungarumlaut = 0xf6cf; 12239 t.Hungarumlautsmall = 0xf6f8; 12240 t.Hzsquare = 0x3390; 12241 t.I = 0x0049; 12242 t.IAcyrillic = 0x042f; 12243 t.IJ = 0x0132; 12244 t.IUcyrillic = 0x042e; 12245 t.Iacute = 0x00cd; 12246 t.Iacutesmall = 0xf7ed; 12247 t.Ibreve = 0x012c; 12248 t.Icaron = 0x01cf; 12249 t.Icircle = 0x24be; 12250 t.Icircumflex = 0x00ce; 12251 t.Icircumflexsmall = 0xf7ee; 12252 t.Icyrillic = 0x0406; 12253 t.Idblgrave = 0x0208; 12254 t.Idieresis = 0x00cf; 12255 t.Idieresisacute = 0x1e2e; 12256 t.Idieresiscyrillic = 0x04e4; 12257 t.Idieresissmall = 0xf7ef; 12258 t.Idot = 0x0130; 12259 t.Idotaccent = 0x0130; 12260 t.Idotbelow = 0x1eca; 12261 t.Iebrevecyrillic = 0x04d6; 12262 t.Iecyrillic = 0x0415; 12263 t.Ifraktur = 0x2111; 12264 t.Igrave = 0x00cc; 12265 t.Igravesmall = 0xf7ec; 12266 t.Ihookabove = 0x1ec8; 12267 t.Iicyrillic = 0x0418; 12268 t.Iinvertedbreve = 0x020a; 12269 t.Iishortcyrillic = 0x0419; 12270 t.Imacron = 0x012a; 12271 t.Imacroncyrillic = 0x04e2; 12272 t.Imonospace = 0xff29; 12273 t.Iniarmenian = 0x053b; 12274 t.Iocyrillic = 0x0401; 12275 t.Iogonek = 0x012e; 12276 t.Iota = 0x0399; 12277 t.Iotaafrican = 0x0196; 12278 t.Iotadieresis = 0x03aa; 12279 t.Iotatonos = 0x038a; 12280 t.Ismall = 0xf769; 12281 t.Istroke = 0x0197; 12282 t.Itilde = 0x0128; 12283 t.Itildebelow = 0x1e2c; 12284 t.Izhitsacyrillic = 0x0474; 12285 t.Izhitsadblgravecyrillic = 0x0476; 12286 t.J = 0x004a; 12287 t.Jaarmenian = 0x0541; 12288 t.Jcircle = 0x24bf; 12289 t.Jcircumflex = 0x0134; 12290 t.Jecyrillic = 0x0408; 12291 t.Jheharmenian = 0x054b; 12292 t.Jmonospace = 0xff2a; 12293 t.Jsmall = 0xf76a; 12294 t.K = 0x004b; 12295 t.KBsquare = 0x3385; 12296 t.KKsquare = 0x33cd; 12297 t.Kabashkircyrillic = 0x04a0; 12298 t.Kacute = 0x1e30; 12299 t.Kacyrillic = 0x041a; 12300 t.Kadescendercyrillic = 0x049a; 12301 t.Kahookcyrillic = 0x04c3; 12302 t.Kappa = 0x039a; 12303 t.Kastrokecyrillic = 0x049e; 12304 t.Kaverticalstrokecyrillic = 0x049c; 12305 t.Kcaron = 0x01e8; 12306 t.Kcedilla = 0x0136; 12307 t.Kcircle = 0x24c0; 12308 t.Kcommaaccent = 0x0136; 12309 t.Kdotbelow = 0x1e32; 12310 t.Keharmenian = 0x0554; 12311 t.Kenarmenian = 0x053f; 12312 t.Khacyrillic = 0x0425; 12313 t.Kheicoptic = 0x03e6; 12314 t.Khook = 0x0198; 12315 t.Kjecyrillic = 0x040c; 12316 t.Klinebelow = 0x1e34; 12317 t.Kmonospace = 0xff2b; 12318 t.Koppacyrillic = 0x0480; 12319 t.Koppagreek = 0x03de; 12320 t.Ksicyrillic = 0x046e; 12321 t.Ksmall = 0xf76b; 12322 t.L = 0x004c; 12323 t.LJ = 0x01c7; 12324 t.LL = 0xf6bf; 12325 t.Lacute = 0x0139; 12326 t.Lambda = 0x039b; 12327 t.Lcaron = 0x013d; 12328 t.Lcedilla = 0x013b; 12329 t.Lcircle = 0x24c1; 12330 t.Lcircumflexbelow = 0x1e3c; 12331 t.Lcommaaccent = 0x013b; 12332 t.Ldot = 0x013f; 12333 t.Ldotaccent = 0x013f; 12334 t.Ldotbelow = 0x1e36; 12335 t.Ldotbelowmacron = 0x1e38; 12336 t.Liwnarmenian = 0x053c; 12337 t.Lj = 0x01c8; 12338 t.Ljecyrillic = 0x0409; 12339 t.Llinebelow = 0x1e3a; 12340 t.Lmonospace = 0xff2c; 12341 t.Lslash = 0x0141; 12342 t.Lslashsmall = 0xf6f9; 12343 t.Lsmall = 0xf76c; 12344 t.M = 0x004d; 12345 t.MBsquare = 0x3386; 12346 t.Macron = 0xf6d0; 12347 t.Macronsmall = 0xf7af; 12348 t.Macute = 0x1e3e; 12349 t.Mcircle = 0x24c2; 12350 t.Mdotaccent = 0x1e40; 12351 t.Mdotbelow = 0x1e42; 12352 t.Menarmenian = 0x0544; 12353 t.Mmonospace = 0xff2d; 12354 t.Msmall = 0xf76d; 12355 t.Mturned = 0x019c; 12356 t.Mu = 0x039c; 12357 t.N = 0x004e; 12358 t.NJ = 0x01ca; 12359 t.Nacute = 0x0143; 12360 t.Ncaron = 0x0147; 12361 t.Ncedilla = 0x0145; 12362 t.Ncircle = 0x24c3; 12363 t.Ncircumflexbelow = 0x1e4a; 12364 t.Ncommaaccent = 0x0145; 12365 t.Ndotaccent = 0x1e44; 12366 t.Ndotbelow = 0x1e46; 12367 t.Nhookleft = 0x019d; 12368 t.Nineroman = 0x2168; 12369 t.Nj = 0x01cb; 12370 t.Njecyrillic = 0x040a; 12371 t.Nlinebelow = 0x1e48; 12372 t.Nmonospace = 0xff2e; 12373 t.Nowarmenian = 0x0546; 12374 t.Nsmall = 0xf76e; 12375 t.Ntilde = 0x00d1; 12376 t.Ntildesmall = 0xf7f1; 12377 t.Nu = 0x039d; 12378 t.O = 0x004f; 12379 t.OE = 0x0152; 12380 t.OEsmall = 0xf6fa; 12381 t.Oacute = 0x00d3; 12382 t.Oacutesmall = 0xf7f3; 12383 t.Obarredcyrillic = 0x04e8; 12384 t.Obarreddieresiscyrillic = 0x04ea; 12385 t.Obreve = 0x014e; 12386 t.Ocaron = 0x01d1; 12387 t.Ocenteredtilde = 0x019f; 12388 t.Ocircle = 0x24c4; 12389 t.Ocircumflex = 0x00d4; 12390 t.Ocircumflexacute = 0x1ed0; 12391 t.Ocircumflexdotbelow = 0x1ed8; 12392 t.Ocircumflexgrave = 0x1ed2; 12393 t.Ocircumflexhookabove = 0x1ed4; 12394 t.Ocircumflexsmall = 0xf7f4; 12395 t.Ocircumflextilde = 0x1ed6; 12396 t.Ocyrillic = 0x041e; 12397 t.Odblacute = 0x0150; 12398 t.Odblgrave = 0x020c; 12399 t.Odieresis = 0x00d6; 12400 t.Odieresiscyrillic = 0x04e6; 12401 t.Odieresissmall = 0xf7f6; 12402 t.Odotbelow = 0x1ecc; 12403 t.Ogoneksmall = 0xf6fb; 12404 t.Ograve = 0x00d2; 12405 t.Ogravesmall = 0xf7f2; 12406 t.Oharmenian = 0x0555; 12407 t.Ohm = 0x2126; 12408 t.Ohookabove = 0x1ece; 12409 t.Ohorn = 0x01a0; 12410 t.Ohornacute = 0x1eda; 12411 t.Ohorndotbelow = 0x1ee2; 12412 t.Ohorngrave = 0x1edc; 12413 t.Ohornhookabove = 0x1ede; 12414 t.Ohorntilde = 0x1ee0; 12415 t.Ohungarumlaut = 0x0150; 12416 t.Oi = 0x01a2; 12417 t.Oinvertedbreve = 0x020e; 12418 t.Omacron = 0x014c; 12419 t.Omacronacute = 0x1e52; 12420 t.Omacrongrave = 0x1e50; 12421 t.Omega = 0x2126; 12422 t.Omegacyrillic = 0x0460; 12423 t.Omegagreek = 0x03a9; 12424 t.Omegaroundcyrillic = 0x047a; 12425 t.Omegatitlocyrillic = 0x047c; 12426 t.Omegatonos = 0x038f; 12427 t.Omicron = 0x039f; 12428 t.Omicrontonos = 0x038c; 12429 t.Omonospace = 0xff2f; 12430 t.Oneroman = 0x2160; 12431 t.Oogonek = 0x01ea; 12432 t.Oogonekmacron = 0x01ec; 12433 t.Oopen = 0x0186; 12434 t.Oslash = 0x00d8; 12435 t.Oslashacute = 0x01fe; 12436 t.Oslashsmall = 0xf7f8; 12437 t.Osmall = 0xf76f; 12438 t.Ostrokeacute = 0x01fe; 12439 t.Otcyrillic = 0x047e; 12440 t.Otilde = 0x00d5; 12441 t.Otildeacute = 0x1e4c; 12442 t.Otildedieresis = 0x1e4e; 12443 t.Otildesmall = 0xf7f5; 12444 t.P = 0x0050; 12445 t.Pacute = 0x1e54; 12446 t.Pcircle = 0x24c5; 12447 t.Pdotaccent = 0x1e56; 12448 t.Pecyrillic = 0x041f; 12449 t.Peharmenian = 0x054a; 12450 t.Pemiddlehookcyrillic = 0x04a6; 12451 t.Phi = 0x03a6; 12452 t.Phook = 0x01a4; 12453 t.Pi = 0x03a0; 12454 t.Piwrarmenian = 0x0553; 12455 t.Pmonospace = 0xff30; 12456 t.Psi = 0x03a8; 12457 t.Psicyrillic = 0x0470; 12458 t.Psmall = 0xf770; 12459 t.Q = 0x0051; 12460 t.Qcircle = 0x24c6; 12461 t.Qmonospace = 0xff31; 12462 t.Qsmall = 0xf771; 12463 t.R = 0x0052; 12464 t.Raarmenian = 0x054c; 12465 t.Racute = 0x0154; 12466 t.Rcaron = 0x0158; 12467 t.Rcedilla = 0x0156; 12468 t.Rcircle = 0x24c7; 12469 t.Rcommaaccent = 0x0156; 12470 t.Rdblgrave = 0x0210; 12471 t.Rdotaccent = 0x1e58; 12472 t.Rdotbelow = 0x1e5a; 12473 t.Rdotbelowmacron = 0x1e5c; 12474 t.Reharmenian = 0x0550; 12475 t.Rfraktur = 0x211c; 12476 t.Rho = 0x03a1; 12477 t.Ringsmall = 0xf6fc; 12478 t.Rinvertedbreve = 0x0212; 12479 t.Rlinebelow = 0x1e5e; 12480 t.Rmonospace = 0xff32; 12481 t.Rsmall = 0xf772; 12482 t.Rsmallinverted = 0x0281; 12483 t.Rsmallinvertedsuperior = 0x02b6; 12484 t.S = 0x0053; 12485 t.SF010000 = 0x250c; 12486 t.SF020000 = 0x2514; 12487 t.SF030000 = 0x2510; 12488 t.SF040000 = 0x2518; 12489 t.SF050000 = 0x253c; 12490 t.SF060000 = 0x252c; 12491 t.SF070000 = 0x2534; 12492 t.SF080000 = 0x251c; 12493 t.SF090000 = 0x2524; 12494 t.SF100000 = 0x2500; 12495 t.SF110000 = 0x2502; 12496 t.SF190000 = 0x2561; 12497 t.SF200000 = 0x2562; 12498 t.SF210000 = 0x2556; 12499 t.SF220000 = 0x2555; 12500 t.SF230000 = 0x2563; 12501 t.SF240000 = 0x2551; 12502 t.SF250000 = 0x2557; 12503 t.SF260000 = 0x255d; 12504 t.SF270000 = 0x255c; 12505 t.SF280000 = 0x255b; 12506 t.SF360000 = 0x255e; 12507 t.SF370000 = 0x255f; 12508 t.SF380000 = 0x255a; 12509 t.SF390000 = 0x2554; 12510 t.SF400000 = 0x2569; 12511 t.SF410000 = 0x2566; 12512 t.SF420000 = 0x2560; 12513 t.SF430000 = 0x2550; 12514 t.SF440000 = 0x256c; 12515 t.SF450000 = 0x2567; 12516 t.SF460000 = 0x2568; 12517 t.SF470000 = 0x2564; 12518 t.SF480000 = 0x2565; 12519 t.SF490000 = 0x2559; 12520 t.SF500000 = 0x2558; 12521 t.SF510000 = 0x2552; 12522 t.SF520000 = 0x2553; 12523 t.SF530000 = 0x256b; 12524 t.SF540000 = 0x256a; 12525 t.Sacute = 0x015a; 12526 t.Sacutedotaccent = 0x1e64; 12527 t.Sampigreek = 0x03e0; 12528 t.Scaron = 0x0160; 12529 t.Scarondotaccent = 0x1e66; 12530 t.Scaronsmall = 0xf6fd; 12531 t.Scedilla = 0x015e; 12532 t.Schwa = 0x018f; 12533 t.Schwacyrillic = 0x04d8; 12534 t.Schwadieresiscyrillic = 0x04da; 12535 t.Scircle = 0x24c8; 12536 t.Scircumflex = 0x015c; 12537 t.Scommaaccent = 0x0218; 12538 t.Sdotaccent = 0x1e60; 12539 t.Sdotbelow = 0x1e62; 12540 t.Sdotbelowdotaccent = 0x1e68; 12541 t.Seharmenian = 0x054d; 12542 t.Sevenroman = 0x2166; 12543 t.Shaarmenian = 0x0547; 12544 t.Shacyrillic = 0x0428; 12545 t.Shchacyrillic = 0x0429; 12546 t.Sheicoptic = 0x03e2; 12547 t.Shhacyrillic = 0x04ba; 12548 t.Shimacoptic = 0x03ec; 12549 t.Sigma = 0x03a3; 12550 t.Sixroman = 0x2165; 12551 t.Smonospace = 0xff33; 12552 t.Softsigncyrillic = 0x042c; 12553 t.Ssmall = 0xf773; 12554 t.Stigmagreek = 0x03da; 12555 t.T = 0x0054; 12556 t.Tau = 0x03a4; 12557 t.Tbar = 0x0166; 12558 t.Tcaron = 0x0164; 12559 t.Tcedilla = 0x0162; 12560 t.Tcircle = 0x24c9; 12561 t.Tcircumflexbelow = 0x1e70; 12562 t.Tcommaaccent = 0x0162; 12563 t.Tdotaccent = 0x1e6a; 12564 t.Tdotbelow = 0x1e6c; 12565 t.Tecyrillic = 0x0422; 12566 t.Tedescendercyrillic = 0x04ac; 12567 t.Tenroman = 0x2169; 12568 t.Tetsecyrillic = 0x04b4; 12569 t.Theta = 0x0398; 12570 t.Thook = 0x01ac; 12571 t.Thorn = 0x00de; 12572 t.Thornsmall = 0xf7fe; 12573 t.Threeroman = 0x2162; 12574 t.Tildesmall = 0xf6fe; 12575 t.Tiwnarmenian = 0x054f; 12576 t.Tlinebelow = 0x1e6e; 12577 t.Tmonospace = 0xff34; 12578 t.Toarmenian = 0x0539; 12579 t.Tonefive = 0x01bc; 12580 t.Tonesix = 0x0184; 12581 t.Tonetwo = 0x01a7; 12582 t.Tretroflexhook = 0x01ae; 12583 t.Tsecyrillic = 0x0426; 12584 t.Tshecyrillic = 0x040b; 12585 t.Tsmall = 0xf774; 12586 t.Twelveroman = 0x216b; 12587 t.Tworoman = 0x2161; 12588 t.U = 0x0055; 12589 t.Uacute = 0x00da; 12590 t.Uacutesmall = 0xf7fa; 12591 t.Ubreve = 0x016c; 12592 t.Ucaron = 0x01d3; 12593 t.Ucircle = 0x24ca; 12594 t.Ucircumflex = 0x00db; 12595 t.Ucircumflexbelow = 0x1e76; 12596 t.Ucircumflexsmall = 0xf7fb; 12597 t.Ucyrillic = 0x0423; 12598 t.Udblacute = 0x0170; 12599 t.Udblgrave = 0x0214; 12600 t.Udieresis = 0x00dc; 12601 t.Udieresisacute = 0x01d7; 12602 t.Udieresisbelow = 0x1e72; 12603 t.Udieresiscaron = 0x01d9; 12604 t.Udieresiscyrillic = 0x04f0; 12605 t.Udieresisgrave = 0x01db; 12606 t.Udieresismacron = 0x01d5; 12607 t.Udieresissmall = 0xf7fc; 12608 t.Udotbelow = 0x1ee4; 12609 t.Ugrave = 0x00d9; 12610 t.Ugravesmall = 0xf7f9; 12611 t.Uhookabove = 0x1ee6; 12612 t.Uhorn = 0x01af; 12613 t.Uhornacute = 0x1ee8; 12614 t.Uhorndotbelow = 0x1ef0; 12615 t.Uhorngrave = 0x1eea; 12616 t.Uhornhookabove = 0x1eec; 12617 t.Uhorntilde = 0x1eee; 12618 t.Uhungarumlaut = 0x0170; 12619 t.Uhungarumlautcyrillic = 0x04f2; 12620 t.Uinvertedbreve = 0x0216; 12621 t.Ukcyrillic = 0x0478; 12622 t.Umacron = 0x016a; 12623 t.Umacroncyrillic = 0x04ee; 12624 t.Umacrondieresis = 0x1e7a; 12625 t.Umonospace = 0xff35; 12626 t.Uogonek = 0x0172; 12627 t.Upsilon = 0x03a5; 12628 t.Upsilon1 = 0x03d2; 12629 t.Upsilonacutehooksymbolgreek = 0x03d3; 12630 t.Upsilonafrican = 0x01b1; 12631 t.Upsilondieresis = 0x03ab; 12632 t.Upsilondieresishooksymbolgreek = 0x03d4; 12633 t.Upsilonhooksymbol = 0x03d2; 12634 t.Upsilontonos = 0x038e; 12635 t.Uring = 0x016e; 12636 t.Ushortcyrillic = 0x040e; 12637 t.Usmall = 0xf775; 12638 t.Ustraightcyrillic = 0x04ae; 12639 t.Ustraightstrokecyrillic = 0x04b0; 12640 t.Utilde = 0x0168; 12641 t.Utildeacute = 0x1e78; 12642 t.Utildebelow = 0x1e74; 12643 t.V = 0x0056; 12644 t.Vcircle = 0x24cb; 12645 t.Vdotbelow = 0x1e7e; 12646 t.Vecyrillic = 0x0412; 12647 t.Vewarmenian = 0x054e; 12648 t.Vhook = 0x01b2; 12649 t.Vmonospace = 0xff36; 12650 t.Voarmenian = 0x0548; 12651 t.Vsmall = 0xf776; 12652 t.Vtilde = 0x1e7c; 12653 t.W = 0x0057; 12654 t.Wacute = 0x1e82; 12655 t.Wcircle = 0x24cc; 12656 t.Wcircumflex = 0x0174; 12657 t.Wdieresis = 0x1e84; 12658 t.Wdotaccent = 0x1e86; 12659 t.Wdotbelow = 0x1e88; 12660 t.Wgrave = 0x1e80; 12661 t.Wmonospace = 0xff37; 12662 t.Wsmall = 0xf777; 12663 t.X = 0x0058; 12664 t.Xcircle = 0x24cd; 12665 t.Xdieresis = 0x1e8c; 12666 t.Xdotaccent = 0x1e8a; 12667 t.Xeharmenian = 0x053d; 12668 t.Xi = 0x039e; 12669 t.Xmonospace = 0xff38; 12670 t.Xsmall = 0xf778; 12671 t.Y = 0x0059; 12672 t.Yacute = 0x00dd; 12673 t.Yacutesmall = 0xf7fd; 12674 t.Yatcyrillic = 0x0462; 12675 t.Ycircle = 0x24ce; 12676 t.Ycircumflex = 0x0176; 12677 t.Ydieresis = 0x0178; 12678 t.Ydieresissmall = 0xf7ff; 12679 t.Ydotaccent = 0x1e8e; 12680 t.Ydotbelow = 0x1ef4; 12681 t.Yericyrillic = 0x042b; 12682 t.Yerudieresiscyrillic = 0x04f8; 12683 t.Ygrave = 0x1ef2; 12684 t.Yhook = 0x01b3; 12685 t.Yhookabove = 0x1ef6; 12686 t.Yiarmenian = 0x0545; 12687 t.Yicyrillic = 0x0407; 12688 t.Yiwnarmenian = 0x0552; 12689 t.Ymonospace = 0xff39; 12690 t.Ysmall = 0xf779; 12691 t.Ytilde = 0x1ef8; 12692 t.Yusbigcyrillic = 0x046a; 12693 t.Yusbigiotifiedcyrillic = 0x046c; 12694 t.Yuslittlecyrillic = 0x0466; 12695 t.Yuslittleiotifiedcyrillic = 0x0468; 12696 t.Z = 0x005a; 12697 t.Zaarmenian = 0x0536; 12698 t.Zacute = 0x0179; 12699 t.Zcaron = 0x017d; 12700 t.Zcaronsmall = 0xf6ff; 12701 t.Zcircle = 0x24cf; 12702 t.Zcircumflex = 0x1e90; 12703 t.Zdot = 0x017b; 12704 t.Zdotaccent = 0x017b; 12705 t.Zdotbelow = 0x1e92; 12706 t.Zecyrillic = 0x0417; 12707 t.Zedescendercyrillic = 0x0498; 12708 t.Zedieresiscyrillic = 0x04de; 12709 t.Zeta = 0x0396; 12710 t.Zhearmenian = 0x053a; 12711 t.Zhebrevecyrillic = 0x04c1; 12712 t.Zhecyrillic = 0x0416; 12713 t.Zhedescendercyrillic = 0x0496; 12714 t.Zhedieresiscyrillic = 0x04dc; 12715 t.Zlinebelow = 0x1e94; 12716 t.Zmonospace = 0xff3a; 12717 t.Zsmall = 0xf77a; 12718 t.Zstroke = 0x01b5; 12719 t.a = 0x0061; 12720 t.aabengali = 0x0986; 12721 t.aacute = 0x00e1; 12722 t.aadeva = 0x0906; 12723 t.aagujarati = 0x0a86; 12724 t.aagurmukhi = 0x0a06; 12725 t.aamatragurmukhi = 0x0a3e; 12726 t.aarusquare = 0x3303; 12727 t.aavowelsignbengali = 0x09be; 12728 t.aavowelsigndeva = 0x093e; 12729 t.aavowelsigngujarati = 0x0abe; 12730 t.abbreviationmarkarmenian = 0x055f; 12731 t.abbreviationsigndeva = 0x0970; 12732 t.abengali = 0x0985; 12733 t.abopomofo = 0x311a; 12734 t.abreve = 0x0103; 12735 t.abreveacute = 0x1eaf; 12736 t.abrevecyrillic = 0x04d1; 12737 t.abrevedotbelow = 0x1eb7; 12738 t.abrevegrave = 0x1eb1; 12739 t.abrevehookabove = 0x1eb3; 12740 t.abrevetilde = 0x1eb5; 12741 t.acaron = 0x01ce; 12742 t.acircle = 0x24d0; 12743 t.acircumflex = 0x00e2; 12744 t.acircumflexacute = 0x1ea5; 12745 t.acircumflexdotbelow = 0x1ead; 12746 t.acircumflexgrave = 0x1ea7; 12747 t.acircumflexhookabove = 0x1ea9; 12748 t.acircumflextilde = 0x1eab; 12749 t.acute = 0x00b4; 12750 t.acutebelowcmb = 0x0317; 12751 t.acutecmb = 0x0301; 12752 t.acutecomb = 0x0301; 12753 t.acutedeva = 0x0954; 12754 t.acutelowmod = 0x02cf; 12755 t.acutetonecmb = 0x0341; 12756 t.acyrillic = 0x0430; 12757 t.adblgrave = 0x0201; 12758 t.addakgurmukhi = 0x0a71; 12759 t.adeva = 0x0905; 12760 t.adieresis = 0x00e4; 12761 t.adieresiscyrillic = 0x04d3; 12762 t.adieresismacron = 0x01df; 12763 t.adotbelow = 0x1ea1; 12764 t.adotmacron = 0x01e1; 12765 t.ae = 0x00e6; 12766 t.aeacute = 0x01fd; 12767 t.aekorean = 0x3150; 12768 t.aemacron = 0x01e3; 12769 t.afii00208 = 0x2015; 12770 t.afii08941 = 0x20a4; 12771 t.afii10017 = 0x0410; 12772 t.afii10018 = 0x0411; 12773 t.afii10019 = 0x0412; 12774 t.afii10020 = 0x0413; 12775 t.afii10021 = 0x0414; 12776 t.afii10022 = 0x0415; 12777 t.afii10023 = 0x0401; 12778 t.afii10024 = 0x0416; 12779 t.afii10025 = 0x0417; 12780 t.afii10026 = 0x0418; 12781 t.afii10027 = 0x0419; 12782 t.afii10028 = 0x041a; 12783 t.afii10029 = 0x041b; 12784 t.afii10030 = 0x041c; 12785 t.afii10031 = 0x041d; 12786 t.afii10032 = 0x041e; 12787 t.afii10033 = 0x041f; 12788 t.afii10034 = 0x0420; 12789 t.afii10035 = 0x0421; 12790 t.afii10036 = 0x0422; 12791 t.afii10037 = 0x0423; 12792 t.afii10038 = 0x0424; 12793 t.afii10039 = 0x0425; 12794 t.afii10040 = 0x0426; 12795 t.afii10041 = 0x0427; 12796 t.afii10042 = 0x0428; 12797 t.afii10043 = 0x0429; 12798 t.afii10044 = 0x042a; 12799 t.afii10045 = 0x042b; 12800 t.afii10046 = 0x042c; 12801 t.afii10047 = 0x042d; 12802 t.afii10048 = 0x042e; 12803 t.afii10049 = 0x042f; 12804 t.afii10050 = 0x0490; 12805 t.afii10051 = 0x0402; 12806 t.afii10052 = 0x0403; 12807 t.afii10053 = 0x0404; 12808 t.afii10054 = 0x0405; 12809 t.afii10055 = 0x0406; 12810 t.afii10056 = 0x0407; 12811 t.afii10057 = 0x0408; 12812 t.afii10058 = 0x0409; 12813 t.afii10059 = 0x040a; 12814 t.afii10060 = 0x040b; 12815 t.afii10061 = 0x040c; 12816 t.afii10062 = 0x040e; 12817 t.afii10063 = 0xf6c4; 12818 t.afii10064 = 0xf6c5; 12819 t.afii10065 = 0x0430; 12820 t.afii10066 = 0x0431; 12821 t.afii10067 = 0x0432; 12822 t.afii10068 = 0x0433; 12823 t.afii10069 = 0x0434; 12824 t.afii10070 = 0x0435; 12825 t.afii10071 = 0x0451; 12826 t.afii10072 = 0x0436; 12827 t.afii10073 = 0x0437; 12828 t.afii10074 = 0x0438; 12829 t.afii10075 = 0x0439; 12830 t.afii10076 = 0x043a; 12831 t.afii10077 = 0x043b; 12832 t.afii10078 = 0x043c; 12833 t.afii10079 = 0x043d; 12834 t.afii10080 = 0x043e; 12835 t.afii10081 = 0x043f; 12836 t.afii10082 = 0x0440; 12837 t.afii10083 = 0x0441; 12838 t.afii10084 = 0x0442; 12839 t.afii10085 = 0x0443; 12840 t.afii10086 = 0x0444; 12841 t.afii10087 = 0x0445; 12842 t.afii10088 = 0x0446; 12843 t.afii10089 = 0x0447; 12844 t.afii10090 = 0x0448; 12845 t.afii10091 = 0x0449; 12846 t.afii10092 = 0x044a; 12847 t.afii10093 = 0x044b; 12848 t.afii10094 = 0x044c; 12849 t.afii10095 = 0x044d; 12850 t.afii10096 = 0x044e; 12851 t.afii10097 = 0x044f; 12852 t.afii10098 = 0x0491; 12853 t.afii10099 = 0x0452; 12854 t.afii10100 = 0x0453; 12855 t.afii10101 = 0x0454; 12856 t.afii10102 = 0x0455; 12857 t.afii10103 = 0x0456; 12858 t.afii10104 = 0x0457; 12859 t.afii10105 = 0x0458; 12860 t.afii10106 = 0x0459; 12861 t.afii10107 = 0x045a; 12862 t.afii10108 = 0x045b; 12863 t.afii10109 = 0x045c; 12864 t.afii10110 = 0x045e; 12865 t.afii10145 = 0x040f; 12866 t.afii10146 = 0x0462; 12867 t.afii10147 = 0x0472; 12868 t.afii10148 = 0x0474; 12869 t.afii10192 = 0xf6c6; 12870 t.afii10193 = 0x045f; 12871 t.afii10194 = 0x0463; 12872 t.afii10195 = 0x0473; 12873 t.afii10196 = 0x0475; 12874 t.afii10831 = 0xf6c7; 12875 t.afii10832 = 0xf6c8; 12876 t.afii10846 = 0x04d9; 12877 t.afii299 = 0x200e; 12878 t.afii300 = 0x200f; 12879 t.afii301 = 0x200d; 12880 t.afii57381 = 0x066a; 12881 t.afii57388 = 0x060c; 12882 t.afii57392 = 0x0660; 12883 t.afii57393 = 0x0661; 12884 t.afii57394 = 0x0662; 12885 t.afii57395 = 0x0663; 12886 t.afii57396 = 0x0664; 12887 t.afii57397 = 0x0665; 12888 t.afii57398 = 0x0666; 12889 t.afii57399 = 0x0667; 12890 t.afii57400 = 0x0668; 12891 t.afii57401 = 0x0669; 12892 t.afii57403 = 0x061b; 12893 t.afii57407 = 0x061f; 12894 t.afii57409 = 0x0621; 12895 t.afii57410 = 0x0622; 12896 t.afii57411 = 0x0623; 12897 t.afii57412 = 0x0624; 12898 t.afii57413 = 0x0625; 12899 t.afii57414 = 0x0626; 12900 t.afii57415 = 0x0627; 12901 t.afii57416 = 0x0628; 12902 t.afii57417 = 0x0629; 12903 t.afii57418 = 0x062a; 12904 t.afii57419 = 0x062b; 12905 t.afii57420 = 0x062c; 12906 t.afii57421 = 0x062d; 12907 t.afii57422 = 0x062e; 12908 t.afii57423 = 0x062f; 12909 t.afii57424 = 0x0630; 12910 t.afii57425 = 0x0631; 12911 t.afii57426 = 0x0632; 12912 t.afii57427 = 0x0633; 12913 t.afii57428 = 0x0634; 12914 t.afii57429 = 0x0635; 12915 t.afii57430 = 0x0636; 12916 t.afii57431 = 0x0637; 12917 t.afii57432 = 0x0638; 12918 t.afii57433 = 0x0639; 12919 t.afii57434 = 0x063a; 12920 t.afii57440 = 0x0640; 12921 t.afii57441 = 0x0641; 12922 t.afii57442 = 0x0642; 12923 t.afii57443 = 0x0643; 12924 t.afii57444 = 0x0644; 12925 t.afii57445 = 0x0645; 12926 t.afii57446 = 0x0646; 12927 t.afii57448 = 0x0648; 12928 t.afii57449 = 0x0649; 12929 t.afii57450 = 0x064a; 12930 t.afii57451 = 0x064b; 12931 t.afii57452 = 0x064c; 12932 t.afii57453 = 0x064d; 12933 t.afii57454 = 0x064e; 12934 t.afii57455 = 0x064f; 12935 t.afii57456 = 0x0650; 12936 t.afii57457 = 0x0651; 12937 t.afii57458 = 0x0652; 12938 t.afii57470 = 0x0647; 12939 t.afii57505 = 0x06a4; 12940 t.afii57506 = 0x067e; 12941 t.afii57507 = 0x0686; 12942 t.afii57508 = 0x0698; 12943 t.afii57509 = 0x06af; 12944 t.afii57511 = 0x0679; 12945 t.afii57512 = 0x0688; 12946 t.afii57513 = 0x0691; 12947 t.afii57514 = 0x06ba; 12948 t.afii57519 = 0x06d2; 12949 t.afii57534 = 0x06d5; 12950 t.afii57636 = 0x20aa; 12951 t.afii57645 = 0x05be; 12952 t.afii57658 = 0x05c3; 12953 t.afii57664 = 0x05d0; 12954 t.afii57665 = 0x05d1; 12955 t.afii57666 = 0x05d2; 12956 t.afii57667 = 0x05d3; 12957 t.afii57668 = 0x05d4; 12958 t.afii57669 = 0x05d5; 12959 t.afii57670 = 0x05d6; 12960 t.afii57671 = 0x05d7; 12961 t.afii57672 = 0x05d8; 12962 t.afii57673 = 0x05d9; 12963 t.afii57674 = 0x05da; 12964 t.afii57675 = 0x05db; 12965 t.afii57676 = 0x05dc; 12966 t.afii57677 = 0x05dd; 12967 t.afii57678 = 0x05de; 12968 t.afii57679 = 0x05df; 12969 t.afii57680 = 0x05e0; 12970 t.afii57681 = 0x05e1; 12971 t.afii57682 = 0x05e2; 12972 t.afii57683 = 0x05e3; 12973 t.afii57684 = 0x05e4; 12974 t.afii57685 = 0x05e5; 12975 t.afii57686 = 0x05e6; 12976 t.afii57687 = 0x05e7; 12977 t.afii57688 = 0x05e8; 12978 t.afii57689 = 0x05e9; 12979 t.afii57690 = 0x05ea; 12980 t.afii57694 = 0xfb2a; 12981 t.afii57695 = 0xfb2b; 12982 t.afii57700 = 0xfb4b; 12983 t.afii57705 = 0xfb1f; 12984 t.afii57716 = 0x05f0; 12985 t.afii57717 = 0x05f1; 12986 t.afii57718 = 0x05f2; 12987 t.afii57723 = 0xfb35; 12988 t.afii57793 = 0x05b4; 12989 t.afii57794 = 0x05b5; 12990 t.afii57795 = 0x05b6; 12991 t.afii57796 = 0x05bb; 12992 t.afii57797 = 0x05b8; 12993 t.afii57798 = 0x05b7; 12994 t.afii57799 = 0x05b0; 12995 t.afii57800 = 0x05b2; 12996 t.afii57801 = 0x05b1; 12997 t.afii57802 = 0x05b3; 12998 t.afii57803 = 0x05c2; 12999 t.afii57804 = 0x05c1; 13000 t.afii57806 = 0x05b9; 13001 t.afii57807 = 0x05bc; 13002 t.afii57839 = 0x05bd; 13003 t.afii57841 = 0x05bf; 13004 t.afii57842 = 0x05c0; 13005 t.afii57929 = 0x02bc; 13006 t.afii61248 = 0x2105; 13007 t.afii61289 = 0x2113; 13008 t.afii61352 = 0x2116; 13009 t.afii61573 = 0x202c; 13010 t.afii61574 = 0x202d; 13011 t.afii61575 = 0x202e; 13012 t.afii61664 = 0x200c; 13013 t.afii63167 = 0x066d; 13014 t.afii64937 = 0x02bd; 13015 t.agrave = 0x00e0; 13016 t.agujarati = 0x0a85; 13017 t.agurmukhi = 0x0a05; 13018 t.ahiragana = 0x3042; 13019 t.ahookabove = 0x1ea3; 13020 t.aibengali = 0x0990; 13021 t.aibopomofo = 0x311e; 13022 t.aideva = 0x0910; 13023 t.aiecyrillic = 0x04d5; 13024 t.aigujarati = 0x0a90; 13025 t.aigurmukhi = 0x0a10; 13026 t.aimatragurmukhi = 0x0a48; 13027 t.ainarabic = 0x0639; 13028 t.ainfinalarabic = 0xfeca; 13029 t.aininitialarabic = 0xfecb; 13030 t.ainmedialarabic = 0xfecc; 13031 t.ainvertedbreve = 0x0203; 13032 t.aivowelsignbengali = 0x09c8; 13033 t.aivowelsigndeva = 0x0948; 13034 t.aivowelsigngujarati = 0x0ac8; 13035 t.akatakana = 0x30a2; 13036 t.akatakanahalfwidth = 0xff71; 13037 t.akorean = 0x314f; 13038 t.alef = 0x05d0; 13039 t.alefarabic = 0x0627; 13040 t.alefdageshhebrew = 0xfb30; 13041 t.aleffinalarabic = 0xfe8e; 13042 t.alefhamzaabovearabic = 0x0623; 13043 t.alefhamzaabovefinalarabic = 0xfe84; 13044 t.alefhamzabelowarabic = 0x0625; 13045 t.alefhamzabelowfinalarabic = 0xfe88; 13046 t.alefhebrew = 0x05d0; 13047 t.aleflamedhebrew = 0xfb4f; 13048 t.alefmaddaabovearabic = 0x0622; 13049 t.alefmaddaabovefinalarabic = 0xfe82; 13050 t.alefmaksuraarabic = 0x0649; 13051 t.alefmaksurafinalarabic = 0xfef0; 13052 t.alefmaksurainitialarabic = 0xfef3; 13053 t.alefmaksuramedialarabic = 0xfef4; 13054 t.alefpatahhebrew = 0xfb2e; 13055 t.alefqamatshebrew = 0xfb2f; 13056 t.aleph = 0x2135; 13057 t.allequal = 0x224c; 13058 t.alpha = 0x03b1; 13059 t.alphatonos = 0x03ac; 13060 t.amacron = 0x0101; 13061 t.amonospace = 0xff41; 13062 t.ampersand = 0x0026; 13063 t.ampersandmonospace = 0xff06; 13064 t.ampersandsmall = 0xf726; 13065 t.amsquare = 0x33c2; 13066 t.anbopomofo = 0x3122; 13067 t.angbopomofo = 0x3124; 13068 t.angbracketleft = 0x3008; 13069 t.angbracketright = 0x3009; 13070 t.angkhankhuthai = 0x0e5a; 13071 t.angle = 0x2220; 13072 t.anglebracketleft = 0x3008; 13073 t.anglebracketleftvertical = 0xfe3f; 13074 t.anglebracketright = 0x3009; 13075 t.anglebracketrightvertical = 0xfe40; 13076 t.angleleft = 0x2329; 13077 t.angleright = 0x232a; 13078 t.angstrom = 0x212b; 13079 t.anoteleia = 0x0387; 13080 t.anudattadeva = 0x0952; 13081 t.anusvarabengali = 0x0982; 13082 t.anusvaradeva = 0x0902; 13083 t.anusvaragujarati = 0x0a82; 13084 t.aogonek = 0x0105; 13085 t.apaatosquare = 0x3300; 13086 t.aparen = 0x249c; 13087 t.apostrophearmenian = 0x055a; 13088 t.apostrophemod = 0x02bc; 13089 t.apple = 0xf8ff; 13090 t.approaches = 0x2250; 13091 t.approxequal = 0x2248; 13092 t.approxequalorimage = 0x2252; 13093 t.approximatelyequal = 0x2245; 13094 t.araeaekorean = 0x318e; 13095 t.araeakorean = 0x318d; 13096 t.arc = 0x2312; 13097 t.arighthalfring = 0x1e9a; 13098 t.aring = 0x00e5; 13099 t.aringacute = 0x01fb; 13100 t.aringbelow = 0x1e01; 13101 t.arrowboth = 0x2194; 13102 t.arrowdashdown = 0x21e3; 13103 t.arrowdashleft = 0x21e0; 13104 t.arrowdashright = 0x21e2; 13105 t.arrowdashup = 0x21e1; 13106 t.arrowdblboth = 0x21d4; 13107 t.arrowdbldown = 0x21d3; 13108 t.arrowdblleft = 0x21d0; 13109 t.arrowdblright = 0x21d2; 13110 t.arrowdblup = 0x21d1; 13111 t.arrowdown = 0x2193; 13112 t.arrowdownleft = 0x2199; 13113 t.arrowdownright = 0x2198; 13114 t.arrowdownwhite = 0x21e9; 13115 t.arrowheaddownmod = 0x02c5; 13116 t.arrowheadleftmod = 0x02c2; 13117 t.arrowheadrightmod = 0x02c3; 13118 t.arrowheadupmod = 0x02c4; 13119 t.arrowhorizex = 0xf8e7; 13120 t.arrowleft = 0x2190; 13121 t.arrowleftdbl = 0x21d0; 13122 t.arrowleftdblstroke = 0x21cd; 13123 t.arrowleftoverright = 0x21c6; 13124 t.arrowleftwhite = 0x21e6; 13125 t.arrowright = 0x2192; 13126 t.arrowrightdblstroke = 0x21cf; 13127 t.arrowrightheavy = 0x279e; 13128 t.arrowrightoverleft = 0x21c4; 13129 t.arrowrightwhite = 0x21e8; 13130 t.arrowtableft = 0x21e4; 13131 t.arrowtabright = 0x21e5; 13132 t.arrowup = 0x2191; 13133 t.arrowupdn = 0x2195; 13134 t.arrowupdnbse = 0x21a8; 13135 t.arrowupdownbase = 0x21a8; 13136 t.arrowupleft = 0x2196; 13137 t.arrowupleftofdown = 0x21c5; 13138 t.arrowupright = 0x2197; 13139 t.arrowupwhite = 0x21e7; 13140 t.arrowvertex = 0xf8e6; 13141 t.asciicircum = 0x005e; 13142 t.asciicircummonospace = 0xff3e; 13143 t.asciitilde = 0x007e; 13144 t.asciitildemonospace = 0xff5e; 13145 t.ascript = 0x0251; 13146 t.ascriptturned = 0x0252; 13147 t.asmallhiragana = 0x3041; 13148 t.asmallkatakana = 0x30a1; 13149 t.asmallkatakanahalfwidth = 0xff67; 13150 t.asterisk = 0x002a; 13151 t.asteriskaltonearabic = 0x066d; 13152 t.asteriskarabic = 0x066d; 13153 t.asteriskmath = 0x2217; 13154 t.asteriskmonospace = 0xff0a; 13155 t.asterisksmall = 0xfe61; 13156 t.asterism = 0x2042; 13157 t.asuperior = 0xf6e9; 13158 t.asymptoticallyequal = 0x2243; 13159 t.at = 0x0040; 13160 t.atilde = 0x00e3; 13161 t.atmonospace = 0xff20; 13162 t.atsmall = 0xfe6b; 13163 t.aturned = 0x0250; 13164 t.aubengali = 0x0994; 13165 t.aubopomofo = 0x3120; 13166 t.audeva = 0x0914; 13167 t.augujarati = 0x0a94; 13168 t.augurmukhi = 0x0a14; 13169 t.aulengthmarkbengali = 0x09d7; 13170 t.aumatragurmukhi = 0x0a4c; 13171 t.auvowelsignbengali = 0x09cc; 13172 t.auvowelsigndeva = 0x094c; 13173 t.auvowelsigngujarati = 0x0acc; 13174 t.avagrahadeva = 0x093d; 13175 t.aybarmenian = 0x0561; 13176 t.ayin = 0x05e2; 13177 t.ayinaltonehebrew = 0xfb20; 13178 t.ayinhebrew = 0x05e2; 13179 t.b = 0x0062; 13180 t.babengali = 0x09ac; 13181 t.backslash = 0x005c; 13182 t.backslashmonospace = 0xff3c; 13183 t.badeva = 0x092c; 13184 t.bagujarati = 0x0aac; 13185 t.bagurmukhi = 0x0a2c; 13186 t.bahiragana = 0x3070; 13187 t.bahtthai = 0x0e3f; 13188 t.bakatakana = 0x30d0; 13189 t.bar = 0x007c; 13190 t.barmonospace = 0xff5c; 13191 t.bbopomofo = 0x3105; 13192 t.bcircle = 0x24d1; 13193 t.bdotaccent = 0x1e03; 13194 t.bdotbelow = 0x1e05; 13195 t.beamedsixteenthnotes = 0x266c; 13196 t.because = 0x2235; 13197 t.becyrillic = 0x0431; 13198 t.beharabic = 0x0628; 13199 t.behfinalarabic = 0xfe90; 13200 t.behinitialarabic = 0xfe91; 13201 t.behiragana = 0x3079; 13202 t.behmedialarabic = 0xfe92; 13203 t.behmeeminitialarabic = 0xfc9f; 13204 t.behmeemisolatedarabic = 0xfc08; 13205 t.behnoonfinalarabic = 0xfc6d; 13206 t.bekatakana = 0x30d9; 13207 t.benarmenian = 0x0562; 13208 t.bet = 0x05d1; 13209 t.beta = 0x03b2; 13210 t.betasymbolgreek = 0x03d0; 13211 t.betdagesh = 0xfb31; 13212 t.betdageshhebrew = 0xfb31; 13213 t.bethebrew = 0x05d1; 13214 t.betrafehebrew = 0xfb4c; 13215 t.bhabengali = 0x09ad; 13216 t.bhadeva = 0x092d; 13217 t.bhagujarati = 0x0aad; 13218 t.bhagurmukhi = 0x0a2d; 13219 t.bhook = 0x0253; 13220 t.bihiragana = 0x3073; 13221 t.bikatakana = 0x30d3; 13222 t.bilabialclick = 0x0298; 13223 t.bindigurmukhi = 0x0a02; 13224 t.birusquare = 0x3331; 13225 t.blackcircle = 0x25cf; 13226 t.blackdiamond = 0x25c6; 13227 t.blackdownpointingtriangle = 0x25bc; 13228 t.blackleftpointingpointer = 0x25c4; 13229 t.blackleftpointingtriangle = 0x25c0; 13230 t.blacklenticularbracketleft = 0x3010; 13231 t.blacklenticularbracketleftvertical = 0xfe3b; 13232 t.blacklenticularbracketright = 0x3011; 13233 t.blacklenticularbracketrightvertical = 0xfe3c; 13234 t.blacklowerlefttriangle = 0x25e3; 13235 t.blacklowerrighttriangle = 0x25e2; 13236 t.blackrectangle = 0x25ac; 13237 t.blackrightpointingpointer = 0x25ba; 13238 t.blackrightpointingtriangle = 0x25b6; 13239 t.blacksmallsquare = 0x25aa; 13240 t.blacksmilingface = 0x263b; 13241 t.blacksquare = 0x25a0; 13242 t.blackstar = 0x2605; 13243 t.blackupperlefttriangle = 0x25e4; 13244 t.blackupperrighttriangle = 0x25e5; 13245 t.blackuppointingsmalltriangle = 0x25b4; 13246 t.blackuppointingtriangle = 0x25b2; 13247 t.blank = 0x2423; 13248 t.blinebelow = 0x1e07; 13249 t.block = 0x2588; 13250 t.bmonospace = 0xff42; 13251 t.bobaimaithai = 0x0e1a; 13252 t.bohiragana = 0x307c; 13253 t.bokatakana = 0x30dc; 13254 t.bparen = 0x249d; 13255 t.bqsquare = 0x33c3; 13256 t.braceex = 0xf8f4; 13257 t.braceleft = 0x007b; 13258 t.braceleftbt = 0xf8f3; 13259 t.braceleftmid = 0xf8f2; 13260 t.braceleftmonospace = 0xff5b; 13261 t.braceleftsmall = 0xfe5b; 13262 t.bracelefttp = 0xf8f1; 13263 t.braceleftvertical = 0xfe37; 13264 t.braceright = 0x007d; 13265 t.bracerightbt = 0xf8fe; 13266 t.bracerightmid = 0xf8fd; 13267 t.bracerightmonospace = 0xff5d; 13268 t.bracerightsmall = 0xfe5c; 13269 t.bracerighttp = 0xf8fc; 13270 t.bracerightvertical = 0xfe38; 13271 t.bracketleft = 0x005b; 13272 t.bracketleftbt = 0xf8f0; 13273 t.bracketleftex = 0xf8ef; 13274 t.bracketleftmonospace = 0xff3b; 13275 t.bracketlefttp = 0xf8ee; 13276 t.bracketright = 0x005d; 13277 t.bracketrightbt = 0xf8fb; 13278 t.bracketrightex = 0xf8fa; 13279 t.bracketrightmonospace = 0xff3d; 13280 t.bracketrighttp = 0xf8f9; 13281 t.breve = 0x02d8; 13282 t.brevebelowcmb = 0x032e; 13283 t.brevecmb = 0x0306; 13284 t.breveinvertedbelowcmb = 0x032f; 13285 t.breveinvertedcmb = 0x0311; 13286 t.breveinverteddoublecmb = 0x0361; 13287 t.bridgebelowcmb = 0x032a; 13288 t.bridgeinvertedbelowcmb = 0x033a; 13289 t.brokenbar = 0x00a6; 13290 t.bstroke = 0x0180; 13291 t.bsuperior = 0xf6ea; 13292 t.btopbar = 0x0183; 13293 t.buhiragana = 0x3076; 13294 t.bukatakana = 0x30d6; 13295 t.bullet = 0x2022; 13296 t.bulletinverse = 0x25d8; 13297 t.bulletoperator = 0x2219; 13298 t.bullseye = 0x25ce; 13299 t.c = 0x0063; 13300 t.caarmenian = 0x056e; 13301 t.cabengali = 0x099a; 13302 t.cacute = 0x0107; 13303 t.cadeva = 0x091a; 13304 t.cagujarati = 0x0a9a; 13305 t.cagurmukhi = 0x0a1a; 13306 t.calsquare = 0x3388; 13307 t.candrabindubengali = 0x0981; 13308 t.candrabinducmb = 0x0310; 13309 t.candrabindudeva = 0x0901; 13310 t.candrabindugujarati = 0x0a81; 13311 t.capslock = 0x21ea; 13312 t.careof = 0x2105; 13313 t.caron = 0x02c7; 13314 t.caronbelowcmb = 0x032c; 13315 t.caroncmb = 0x030c; 13316 t.carriagereturn = 0x21b5; 13317 t.cbopomofo = 0x3118; 13318 t.ccaron = 0x010d; 13319 t.ccedilla = 0x00e7; 13320 t.ccedillaacute = 0x1e09; 13321 t.ccircle = 0x24d2; 13322 t.ccircumflex = 0x0109; 13323 t.ccurl = 0x0255; 13324 t.cdot = 0x010b; 13325 t.cdotaccent = 0x010b; 13326 t.cdsquare = 0x33c5; 13327 t.cedilla = 0x00b8; 13328 t.cedillacmb = 0x0327; 13329 t.cent = 0x00a2; 13330 t.centigrade = 0x2103; 13331 t.centinferior = 0xf6df; 13332 t.centmonospace = 0xffe0; 13333 t.centoldstyle = 0xf7a2; 13334 t.centsuperior = 0xf6e0; 13335 t.chaarmenian = 0x0579; 13336 t.chabengali = 0x099b; 13337 t.chadeva = 0x091b; 13338 t.chagujarati = 0x0a9b; 13339 t.chagurmukhi = 0x0a1b; 13340 t.chbopomofo = 0x3114; 13341 t.cheabkhasiancyrillic = 0x04bd; 13342 t.checkmark = 0x2713; 13343 t.checyrillic = 0x0447; 13344 t.chedescenderabkhasiancyrillic = 0x04bf; 13345 t.chedescendercyrillic = 0x04b7; 13346 t.chedieresiscyrillic = 0x04f5; 13347 t.cheharmenian = 0x0573; 13348 t.chekhakassiancyrillic = 0x04cc; 13349 t.cheverticalstrokecyrillic = 0x04b9; 13350 t.chi = 0x03c7; 13351 t.chieuchacirclekorean = 0x3277; 13352 t.chieuchaparenkorean = 0x3217; 13353 t.chieuchcirclekorean = 0x3269; 13354 t.chieuchkorean = 0x314a; 13355 t.chieuchparenkorean = 0x3209; 13356 t.chochangthai = 0x0e0a; 13357 t.chochanthai = 0x0e08; 13358 t.chochingthai = 0x0e09; 13359 t.chochoethai = 0x0e0c; 13360 t.chook = 0x0188; 13361 t.cieucacirclekorean = 0x3276; 13362 t.cieucaparenkorean = 0x3216; 13363 t.cieuccirclekorean = 0x3268; 13364 t.cieuckorean = 0x3148; 13365 t.cieucparenkorean = 0x3208; 13366 t.cieucuparenkorean = 0x321c; 13367 t.circle = 0x25cb; 13368 t.circlecopyrt = 0x00a9; 13369 t.circlemultiply = 0x2297; 13370 t.circleot = 0x2299; 13371 t.circleplus = 0x2295; 13372 t.circlepostalmark = 0x3036; 13373 t.circlewithlefthalfblack = 0x25d0; 13374 t.circlewithrighthalfblack = 0x25d1; 13375 t.circumflex = 0x02c6; 13376 t.circumflexbelowcmb = 0x032d; 13377 t.circumflexcmb = 0x0302; 13378 t.clear = 0x2327; 13379 t.clickalveolar = 0x01c2; 13380 t.clickdental = 0x01c0; 13381 t.clicklateral = 0x01c1; 13382 t.clickretroflex = 0x01c3; 13383 t.club = 0x2663; 13384 t.clubsuitblack = 0x2663; 13385 t.clubsuitwhite = 0x2667; 13386 t.cmcubedsquare = 0x33a4; 13387 t.cmonospace = 0xff43; 13388 t.cmsquaredsquare = 0x33a0; 13389 t.coarmenian = 0x0581; 13390 t.colon = 0x003a; 13391 t.colonmonetary = 0x20a1; 13392 t.colonmonospace = 0xff1a; 13393 t.colonsign = 0x20a1; 13394 t.colonsmall = 0xfe55; 13395 t.colontriangularhalfmod = 0x02d1; 13396 t.colontriangularmod = 0x02d0; 13397 t.comma = 0x002c; 13398 t.commaabovecmb = 0x0313; 13399 t.commaaboverightcmb = 0x0315; 13400 t.commaaccent = 0xf6c3; 13401 t.commaarabic = 0x060c; 13402 t.commaarmenian = 0x055d; 13403 t.commainferior = 0xf6e1; 13404 t.commamonospace = 0xff0c; 13405 t.commareversedabovecmb = 0x0314; 13406 t.commareversedmod = 0x02bd; 13407 t.commasmall = 0xfe50; 13408 t.commasuperior = 0xf6e2; 13409 t.commaturnedabovecmb = 0x0312; 13410 t.commaturnedmod = 0x02bb; 13411 t.compass = 0x263c; 13412 t.congruent = 0x2245; 13413 t.contourintegral = 0x222e; 13414 t.control = 0x2303; 13415 t.controlACK = 0x0006; 13416 t.controlBEL = 0x0007; 13417 t.controlBS = 0x0008; 13418 t.controlCAN = 0x0018; 13419 t.controlCR = 0x000d; 13420 t.controlDC1 = 0x0011; 13421 t.controlDC2 = 0x0012; 13422 t.controlDC3 = 0x0013; 13423 t.controlDC4 = 0x0014; 13424 t.controlDEL = 0x007f; 13425 t.controlDLE = 0x0010; 13426 t.controlEM = 0x0019; 13427 t.controlENQ = 0x0005; 13428 t.controlEOT = 0x0004; 13429 t.controlESC = 0x001b; 13430 t.controlETB = 0x0017; 13431 t.controlETX = 0x0003; 13432 t.controlFF = 0x000c; 13433 t.controlFS = 0x001c; 13434 t.controlGS = 0x001d; 13435 t.controlHT = 0x0009; 13436 t.controlLF = 0x000a; 13437 t.controlNAK = 0x0015; 13438 t.controlNULL = 0x0000; 13439 t.controlRS = 0x001e; 13440 t.controlSI = 0x000f; 13441 t.controlSO = 0x000e; 13442 t.controlSOT = 0x0002; 13443 t.controlSTX = 0x0001; 13444 t.controlSUB = 0x001a; 13445 t.controlSYN = 0x0016; 13446 t.controlUS = 0x001f; 13447 t.controlVT = 0x000b; 13448 t.copyright = 0x00a9; 13449 t.copyrightsans = 0xf8e9; 13450 t.copyrightserif = 0xf6d9; 13451 t.cornerbracketleft = 0x300c; 13452 t.cornerbracketlefthalfwidth = 0xff62; 13453 t.cornerbracketleftvertical = 0xfe41; 13454 t.cornerbracketright = 0x300d; 13455 t.cornerbracketrighthalfwidth = 0xff63; 13456 t.cornerbracketrightvertical = 0xfe42; 13457 t.corporationsquare = 0x337f; 13458 t.cosquare = 0x33c7; 13459 t.coverkgsquare = 0x33c6; 13460 t.cparen = 0x249e; 13461 t.cruzeiro = 0x20a2; 13462 t.cstretched = 0x0297; 13463 t.curlyand = 0x22cf; 13464 t.curlyor = 0x22ce; 13465 t.currency = 0x00a4; 13466 t.cyrBreve = 0xf6d1; 13467 t.cyrFlex = 0xf6d2; 13468 t.cyrbreve = 0xf6d4; 13469 t.cyrflex = 0xf6d5; 13470 t.d = 0x0064; 13471 t.daarmenian = 0x0564; 13472 t.dabengali = 0x09a6; 13473 t.dadarabic = 0x0636; 13474 t.dadeva = 0x0926; 13475 t.dadfinalarabic = 0xfebe; 13476 t.dadinitialarabic = 0xfebf; 13477 t.dadmedialarabic = 0xfec0; 13478 t.dagesh = 0x05bc; 13479 t.dageshhebrew = 0x05bc; 13480 t.dagger = 0x2020; 13481 t.daggerdbl = 0x2021; 13482 t.dagujarati = 0x0aa6; 13483 t.dagurmukhi = 0x0a26; 13484 t.dahiragana = 0x3060; 13485 t.dakatakana = 0x30c0; 13486 t.dalarabic = 0x062f; 13487 t.dalet = 0x05d3; 13488 t.daletdagesh = 0xfb33; 13489 t.daletdageshhebrew = 0xfb33; 13490 t.dalethebrew = 0x05d3; 13491 t.dalfinalarabic = 0xfeaa; 13492 t.dammaarabic = 0x064f; 13493 t.dammalowarabic = 0x064f; 13494 t.dammatanaltonearabic = 0x064c; 13495 t.dammatanarabic = 0x064c; 13496 t.danda = 0x0964; 13497 t.dargahebrew = 0x05a7; 13498 t.dargalefthebrew = 0x05a7; 13499 t.dasiapneumatacyrilliccmb = 0x0485; 13500 t.dblGrave = 0xf6d3; 13501 t.dblanglebracketleft = 0x300a; 13502 t.dblanglebracketleftvertical = 0xfe3d; 13503 t.dblanglebracketright = 0x300b; 13504 t.dblanglebracketrightvertical = 0xfe3e; 13505 t.dblarchinvertedbelowcmb = 0x032b; 13506 t.dblarrowleft = 0x21d4; 13507 t.dblarrowright = 0x21d2; 13508 t.dbldanda = 0x0965; 13509 t.dblgrave = 0xf6d6; 13510 t.dblgravecmb = 0x030f; 13511 t.dblintegral = 0x222c; 13512 t.dbllowline = 0x2017; 13513 t.dbllowlinecmb = 0x0333; 13514 t.dbloverlinecmb = 0x033f; 13515 t.dblprimemod = 0x02ba; 13516 t.dblverticalbar = 0x2016; 13517 t.dblverticallineabovecmb = 0x030e; 13518 t.dbopomofo = 0x3109; 13519 t.dbsquare = 0x33c8; 13520 t.dcaron = 0x010f; 13521 t.dcedilla = 0x1e11; 13522 t.dcircle = 0x24d3; 13523 t.dcircumflexbelow = 0x1e13; 13524 t.dcroat = 0x0111; 13525 t.ddabengali = 0x09a1; 13526 t.ddadeva = 0x0921; 13527 t.ddagujarati = 0x0aa1; 13528 t.ddagurmukhi = 0x0a21; 13529 t.ddalarabic = 0x0688; 13530 t.ddalfinalarabic = 0xfb89; 13531 t.dddhadeva = 0x095c; 13532 t.ddhabengali = 0x09a2; 13533 t.ddhadeva = 0x0922; 13534 t.ddhagujarati = 0x0aa2; 13535 t.ddhagurmukhi = 0x0a22; 13536 t.ddotaccent = 0x1e0b; 13537 t.ddotbelow = 0x1e0d; 13538 t.decimalseparatorarabic = 0x066b; 13539 t.decimalseparatorpersian = 0x066b; 13540 t.decyrillic = 0x0434; 13541 t.degree = 0x00b0; 13542 t.dehihebrew = 0x05ad; 13543 t.dehiragana = 0x3067; 13544 t.deicoptic = 0x03ef; 13545 t.dekatakana = 0x30c7; 13546 t.deleteleft = 0x232b; 13547 t.deleteright = 0x2326; 13548 t.delta = 0x03b4; 13549 t.deltaturned = 0x018d; 13550 t.denominatorminusonenumeratorbengali = 0x09f8; 13551 t.dezh = 0x02a4; 13552 t.dhabengali = 0x09a7; 13553 t.dhadeva = 0x0927; 13554 t.dhagujarati = 0x0aa7; 13555 t.dhagurmukhi = 0x0a27; 13556 t.dhook = 0x0257; 13557 t.dialytikatonos = 0x0385; 13558 t.dialytikatonoscmb = 0x0344; 13559 t.diamond = 0x2666; 13560 t.diamondsuitwhite = 0x2662; 13561 t.dieresis = 0x00a8; 13562 t.dieresisacute = 0xf6d7; 13563 t.dieresisbelowcmb = 0x0324; 13564 t.dieresiscmb = 0x0308; 13565 t.dieresisgrave = 0xf6d8; 13566 t.dieresistonos = 0x0385; 13567 t.dihiragana = 0x3062; 13568 t.dikatakana = 0x30c2; 13569 t.dittomark = 0x3003; 13570 t.divide = 0x00f7; 13571 t.divides = 0x2223; 13572 t.divisionslash = 0x2215; 13573 t.djecyrillic = 0x0452; 13574 t.dkshade = 0x2593; 13575 t.dlinebelow = 0x1e0f; 13576 t.dlsquare = 0x3397; 13577 t.dmacron = 0x0111; 13578 t.dmonospace = 0xff44; 13579 t.dnblock = 0x2584; 13580 t.dochadathai = 0x0e0e; 13581 t.dodekthai = 0x0e14; 13582 t.dohiragana = 0x3069; 13583 t.dokatakana = 0x30c9; 13584 t.dollar = 0x0024; 13585 t.dollarinferior = 0xf6e3; 13586 t.dollarmonospace = 0xff04; 13587 t.dollaroldstyle = 0xf724; 13588 t.dollarsmall = 0xfe69; 13589 t.dollarsuperior = 0xf6e4; 13590 t.dong = 0x20ab; 13591 t.dorusquare = 0x3326; 13592 t.dotaccent = 0x02d9; 13593 t.dotaccentcmb = 0x0307; 13594 t.dotbelowcmb = 0x0323; 13595 t.dotbelowcomb = 0x0323; 13596 t.dotkatakana = 0x30fb; 13597 t.dotlessi = 0x0131; 13598 t.dotlessj = 0xf6be; 13599 t.dotlessjstrokehook = 0x0284; 13600 t.dotmath = 0x22c5; 13601 t.dottedcircle = 0x25cc; 13602 t.doubleyodpatah = 0xfb1f; 13603 t.doubleyodpatahhebrew = 0xfb1f; 13604 t.downtackbelowcmb = 0x031e; 13605 t.downtackmod = 0x02d5; 13606 t.dparen = 0x249f; 13607 t.dsuperior = 0xf6eb; 13608 t.dtail = 0x0256; 13609 t.dtopbar = 0x018c; 13610 t.duhiragana = 0x3065; 13611 t.dukatakana = 0x30c5; 13612 t.dz = 0x01f3; 13613 t.dzaltone = 0x02a3; 13614 t.dzcaron = 0x01c6; 13615 t.dzcurl = 0x02a5; 13616 t.dzeabkhasiancyrillic = 0x04e1; 13617 t.dzecyrillic = 0x0455; 13618 t.dzhecyrillic = 0x045f; 13619 t.e = 0x0065; 13620 t.eacute = 0x00e9; 13621 t.earth = 0x2641; 13622 t.ebengali = 0x098f; 13623 t.ebopomofo = 0x311c; 13624 t.ebreve = 0x0115; 13625 t.ecandradeva = 0x090d; 13626 t.ecandragujarati = 0x0a8d; 13627 t.ecandravowelsigndeva = 0x0945; 13628 t.ecandravowelsigngujarati = 0x0ac5; 13629 t.ecaron = 0x011b; 13630 t.ecedillabreve = 0x1e1d; 13631 t.echarmenian = 0x0565; 13632 t.echyiwnarmenian = 0x0587; 13633 t.ecircle = 0x24d4; 13634 t.ecircumflex = 0x00ea; 13635 t.ecircumflexacute = 0x1ebf; 13636 t.ecircumflexbelow = 0x1e19; 13637 t.ecircumflexdotbelow = 0x1ec7; 13638 t.ecircumflexgrave = 0x1ec1; 13639 t.ecircumflexhookabove = 0x1ec3; 13640 t.ecircumflextilde = 0x1ec5; 13641 t.ecyrillic = 0x0454; 13642 t.edblgrave = 0x0205; 13643 t.edeva = 0x090f; 13644 t.edieresis = 0x00eb; 13645 t.edot = 0x0117; 13646 t.edotaccent = 0x0117; 13647 t.edotbelow = 0x1eb9; 13648 t.eegurmukhi = 0x0a0f; 13649 t.eematragurmukhi = 0x0a47; 13650 t.efcyrillic = 0x0444; 13651 t.egrave = 0x00e8; 13652 t.egujarati = 0x0a8f; 13653 t.eharmenian = 0x0567; 13654 t.ehbopomofo = 0x311d; 13655 t.ehiragana = 0x3048; 13656 t.ehookabove = 0x1ebb; 13657 t.eibopomofo = 0x311f; 13658 t.eight = 0x0038; 13659 t.eightarabic = 0x0668; 13660 t.eightbengali = 0x09ee; 13661 t.eightcircle = 0x2467; 13662 t.eightcircleinversesansserif = 0x2791; 13663 t.eightdeva = 0x096e; 13664 t.eighteencircle = 0x2471; 13665 t.eighteenparen = 0x2485; 13666 t.eighteenperiod = 0x2499; 13667 t.eightgujarati = 0x0aee; 13668 t.eightgurmukhi = 0x0a6e; 13669 t.eighthackarabic = 0x0668; 13670 t.eighthangzhou = 0x3028; 13671 t.eighthnotebeamed = 0x266b; 13672 t.eightideographicparen = 0x3227; 13673 t.eightinferior = 0x2088; 13674 t.eightmonospace = 0xff18; 13675 t.eightoldstyle = 0xf738; 13676 t.eightparen = 0x247b; 13677 t.eightperiod = 0x248f; 13678 t.eightpersian = 0x06f8; 13679 t.eightroman = 0x2177; 13680 t.eightsuperior = 0x2078; 13681 t.eightthai = 0x0e58; 13682 t.einvertedbreve = 0x0207; 13683 t.eiotifiedcyrillic = 0x0465; 13684 t.ekatakana = 0x30a8; 13685 t.ekatakanahalfwidth = 0xff74; 13686 t.ekonkargurmukhi = 0x0a74; 13687 t.ekorean = 0x3154; 13688 t.elcyrillic = 0x043b; 13689 t.element = 0x2208; 13690 t.elevencircle = 0x246a; 13691 t.elevenparen = 0x247e; 13692 t.elevenperiod = 0x2492; 13693 t.elevenroman = 0x217a; 13694 t.ellipsis = 0x2026; 13695 t.ellipsisvertical = 0x22ee; 13696 t.emacron = 0x0113; 13697 t.emacronacute = 0x1e17; 13698 t.emacrongrave = 0x1e15; 13699 t.emcyrillic = 0x043c; 13700 t.emdash = 0x2014; 13701 t.emdashvertical = 0xfe31; 13702 t.emonospace = 0xff45; 13703 t.emphasismarkarmenian = 0x055b; 13704 t.emptyset = 0x2205; 13705 t.enbopomofo = 0x3123; 13706 t.encyrillic = 0x043d; 13707 t.endash = 0x2013; 13708 t.endashvertical = 0xfe32; 13709 t.endescendercyrillic = 0x04a3; 13710 t.eng = 0x014b; 13711 t.engbopomofo = 0x3125; 13712 t.enghecyrillic = 0x04a5; 13713 t.enhookcyrillic = 0x04c8; 13714 t.enspace = 0x2002; 13715 t.eogonek = 0x0119; 13716 t.eokorean = 0x3153; 13717 t.eopen = 0x025b; 13718 t.eopenclosed = 0x029a; 13719 t.eopenreversed = 0x025c; 13720 t.eopenreversedclosed = 0x025e; 13721 t.eopenreversedhook = 0x025d; 13722 t.eparen = 0x24a0; 13723 t.epsilon = 0x03b5; 13724 t.epsilontonos = 0x03ad; 13725 t.equal = 0x003d; 13726 t.equalmonospace = 0xff1d; 13727 t.equalsmall = 0xfe66; 13728 t.equalsuperior = 0x207c; 13729 t.equivalence = 0x2261; 13730 t.erbopomofo = 0x3126; 13731 t.ercyrillic = 0x0440; 13732 t.ereversed = 0x0258; 13733 t.ereversedcyrillic = 0x044d; 13734 t.escyrillic = 0x0441; 13735 t.esdescendercyrillic = 0x04ab; 13736 t.esh = 0x0283; 13737 t.eshcurl = 0x0286; 13738 t.eshortdeva = 0x090e; 13739 t.eshortvowelsigndeva = 0x0946; 13740 t.eshreversedloop = 0x01aa; 13741 t.eshsquatreversed = 0x0285; 13742 t.esmallhiragana = 0x3047; 13743 t.esmallkatakana = 0x30a7; 13744 t.esmallkatakanahalfwidth = 0xff6a; 13745 t.estimated = 0x212e; 13746 t.esuperior = 0xf6ec; 13747 t.eta = 0x03b7; 13748 t.etarmenian = 0x0568; 13749 t.etatonos = 0x03ae; 13750 t.eth = 0x00f0; 13751 t.etilde = 0x1ebd; 13752 t.etildebelow = 0x1e1b; 13753 t.etnahtafoukhhebrew = 0x0591; 13754 t.etnahtafoukhlefthebrew = 0x0591; 13755 t.etnahtahebrew = 0x0591; 13756 t.etnahtalefthebrew = 0x0591; 13757 t.eturned = 0x01dd; 13758 t.eukorean = 0x3161; 13759 t.euro = 0x20ac; 13760 t.evowelsignbengali = 0x09c7; 13761 t.evowelsigndeva = 0x0947; 13762 t.evowelsigngujarati = 0x0ac7; 13763 t.exclam = 0x0021; 13764 t.exclamarmenian = 0x055c; 13765 t.exclamdbl = 0x203c; 13766 t.exclamdown = 0x00a1; 13767 t.exclamdownsmall = 0xf7a1; 13768 t.exclammonospace = 0xff01; 13769 t.exclamsmall = 0xf721; 13770 t.existential = 0x2203; 13771 t.ezh = 0x0292; 13772 t.ezhcaron = 0x01ef; 13773 t.ezhcurl = 0x0293; 13774 t.ezhreversed = 0x01b9; 13775 t.ezhtail = 0x01ba; 13776 t.f = 0x0066; 13777 t.fadeva = 0x095e; 13778 t.fagurmukhi = 0x0a5e; 13779 t.fahrenheit = 0x2109; 13780 t.fathaarabic = 0x064e; 13781 t.fathalowarabic = 0x064e; 13782 t.fathatanarabic = 0x064b; 13783 t.fbopomofo = 0x3108; 13784 t.fcircle = 0x24d5; 13785 t.fdotaccent = 0x1e1f; 13786 t.feharabic = 0x0641; 13787 t.feharmenian = 0x0586; 13788 t.fehfinalarabic = 0xfed2; 13789 t.fehinitialarabic = 0xfed3; 13790 t.fehmedialarabic = 0xfed4; 13791 t.feicoptic = 0x03e5; 13792 t.female = 0x2640; 13793 t.ff = 0xfb00; 13794 t.f_f = 0xfb00; 13795 t.ffi = 0xfb03; 13796 t.f_f_i = 0xfb03; 13797 t.ffl = 0xfb04; 13798 t.f_f_l = 0xfb04; 13799 t.fi = 0xfb01; 13800 t.f_i = 0xfb01; 13801 t.fifteencircle = 0x246e; 13802 t.fifteenparen = 0x2482; 13803 t.fifteenperiod = 0x2496; 13804 t.figuredash = 0x2012; 13805 t.filledbox = 0x25a0; 13806 t.filledrect = 0x25ac; 13807 t.finalkaf = 0x05da; 13808 t.finalkafdagesh = 0xfb3a; 13809 t.finalkafdageshhebrew = 0xfb3a; 13810 t.finalkafhebrew = 0x05da; 13811 t.finalmem = 0x05dd; 13812 t.finalmemhebrew = 0x05dd; 13813 t.finalnun = 0x05df; 13814 t.finalnunhebrew = 0x05df; 13815 t.finalpe = 0x05e3; 13816 t.finalpehebrew = 0x05e3; 13817 t.finaltsadi = 0x05e5; 13818 t.finaltsadihebrew = 0x05e5; 13819 t.firsttonechinese = 0x02c9; 13820 t.fisheye = 0x25c9; 13821 t.fitacyrillic = 0x0473; 13822 t.five = 0x0035; 13823 t.fivearabic = 0x0665; 13824 t.fivebengali = 0x09eb; 13825 t.fivecircle = 0x2464; 13826 t.fivecircleinversesansserif = 0x278e; 13827 t.fivedeva = 0x096b; 13828 t.fiveeighths = 0x215d; 13829 t.fivegujarati = 0x0aeb; 13830 t.fivegurmukhi = 0x0a6b; 13831 t.fivehackarabic = 0x0665; 13832 t.fivehangzhou = 0x3025; 13833 t.fiveideographicparen = 0x3224; 13834 t.fiveinferior = 0x2085; 13835 t.fivemonospace = 0xff15; 13836 t.fiveoldstyle = 0xf735; 13837 t.fiveparen = 0x2478; 13838 t.fiveperiod = 0x248c; 13839 t.fivepersian = 0x06f5; 13840 t.fiveroman = 0x2174; 13841 t.fivesuperior = 0x2075; 13842 t.fivethai = 0x0e55; 13843 t.fl = 0xfb02; 13844 t.f_l = 0xfb02; 13845 t.florin = 0x0192; 13846 t.fmonospace = 0xff46; 13847 t.fmsquare = 0x3399; 13848 t.fofanthai = 0x0e1f; 13849 t.fofathai = 0x0e1d; 13850 t.fongmanthai = 0x0e4f; 13851 t.forall = 0x2200; 13852 t.four = 0x0034; 13853 t.fourarabic = 0x0664; 13854 t.fourbengali = 0x09ea; 13855 t.fourcircle = 0x2463; 13856 t.fourcircleinversesansserif = 0x278d; 13857 t.fourdeva = 0x096a; 13858 t.fourgujarati = 0x0aea; 13859 t.fourgurmukhi = 0x0a6a; 13860 t.fourhackarabic = 0x0664; 13861 t.fourhangzhou = 0x3024; 13862 t.fourideographicparen = 0x3223; 13863 t.fourinferior = 0x2084; 13864 t.fourmonospace = 0xff14; 13865 t.fournumeratorbengali = 0x09f7; 13866 t.fouroldstyle = 0xf734; 13867 t.fourparen = 0x2477; 13868 t.fourperiod = 0x248b; 13869 t.fourpersian = 0x06f4; 13870 t.fourroman = 0x2173; 13871 t.foursuperior = 0x2074; 13872 t.fourteencircle = 0x246d; 13873 t.fourteenparen = 0x2481; 13874 t.fourteenperiod = 0x2495; 13875 t.fourthai = 0x0e54; 13876 t.fourthtonechinese = 0x02cb; 13877 t.fparen = 0x24a1; 13878 t.fraction = 0x2044; 13879 t.franc = 0x20a3; 13880 t.g = 0x0067; 13881 t.gabengali = 0x0997; 13882 t.gacute = 0x01f5; 13883 t.gadeva = 0x0917; 13884 t.gafarabic = 0x06af; 13885 t.gaffinalarabic = 0xfb93; 13886 t.gafinitialarabic = 0xfb94; 13887 t.gafmedialarabic = 0xfb95; 13888 t.gagujarati = 0x0a97; 13889 t.gagurmukhi = 0x0a17; 13890 t.gahiragana = 0x304c; 13891 t.gakatakana = 0x30ac; 13892 t.gamma = 0x03b3; 13893 t.gammalatinsmall = 0x0263; 13894 t.gammasuperior = 0x02e0; 13895 t.gangiacoptic = 0x03eb; 13896 t.gbopomofo = 0x310d; 13897 t.gbreve = 0x011f; 13898 t.gcaron = 0x01e7; 13899 t.gcedilla = 0x0123; 13900 t.gcircle = 0x24d6; 13901 t.gcircumflex = 0x011d; 13902 t.gcommaaccent = 0x0123; 13903 t.gdot = 0x0121; 13904 t.gdotaccent = 0x0121; 13905 t.gecyrillic = 0x0433; 13906 t.gehiragana = 0x3052; 13907 t.gekatakana = 0x30b2; 13908 t.geometricallyequal = 0x2251; 13909 t.gereshaccenthebrew = 0x059c; 13910 t.gereshhebrew = 0x05f3; 13911 t.gereshmuqdamhebrew = 0x059d; 13912 t.germandbls = 0x00df; 13913 t.gershayimaccenthebrew = 0x059e; 13914 t.gershayimhebrew = 0x05f4; 13915 t.getamark = 0x3013; 13916 t.ghabengali = 0x0998; 13917 t.ghadarmenian = 0x0572; 13918 t.ghadeva = 0x0918; 13919 t.ghagujarati = 0x0a98; 13920 t.ghagurmukhi = 0x0a18; 13921 t.ghainarabic = 0x063a; 13922 t.ghainfinalarabic = 0xfece; 13923 t.ghaininitialarabic = 0xfecf; 13924 t.ghainmedialarabic = 0xfed0; 13925 t.ghemiddlehookcyrillic = 0x0495; 13926 t.ghestrokecyrillic = 0x0493; 13927 t.gheupturncyrillic = 0x0491; 13928 t.ghhadeva = 0x095a; 13929 t.ghhagurmukhi = 0x0a5a; 13930 t.ghook = 0x0260; 13931 t.ghzsquare = 0x3393; 13932 t.gihiragana = 0x304e; 13933 t.gikatakana = 0x30ae; 13934 t.gimarmenian = 0x0563; 13935 t.gimel = 0x05d2; 13936 t.gimeldagesh = 0xfb32; 13937 t.gimeldageshhebrew = 0xfb32; 13938 t.gimelhebrew = 0x05d2; 13939 t.gjecyrillic = 0x0453; 13940 t.glottalinvertedstroke = 0x01be; 13941 t.glottalstop = 0x0294; 13942 t.glottalstopinverted = 0x0296; 13943 t.glottalstopmod = 0x02c0; 13944 t.glottalstopreversed = 0x0295; 13945 t.glottalstopreversedmod = 0x02c1; 13946 t.glottalstopreversedsuperior = 0x02e4; 13947 t.glottalstopstroke = 0x02a1; 13948 t.glottalstopstrokereversed = 0x02a2; 13949 t.gmacron = 0x1e21; 13950 t.gmonospace = 0xff47; 13951 t.gohiragana = 0x3054; 13952 t.gokatakana = 0x30b4; 13953 t.gparen = 0x24a2; 13954 t.gpasquare = 0x33ac; 13955 t.gradient = 0x2207; 13956 t.grave = 0x0060; 13957 t.gravebelowcmb = 0x0316; 13958 t.gravecmb = 0x0300; 13959 t.gravecomb = 0x0300; 13960 t.gravedeva = 0x0953; 13961 t.gravelowmod = 0x02ce; 13962 t.gravemonospace = 0xff40; 13963 t.gravetonecmb = 0x0340; 13964 t.greater = 0x003e; 13965 t.greaterequal = 0x2265; 13966 t.greaterequalorless = 0x22db; 13967 t.greatermonospace = 0xff1e; 13968 t.greaterorequivalent = 0x2273; 13969 t.greaterorless = 0x2277; 13970 t.greateroverequal = 0x2267; 13971 t.greatersmall = 0xfe65; 13972 t.gscript = 0x0261; 13973 t.gstroke = 0x01e5; 13974 t.guhiragana = 0x3050; 13975 t.guillemotleft = 0x00ab; 13976 t.guillemotright = 0x00bb; 13977 t.guilsinglleft = 0x2039; 13978 t.guilsinglright = 0x203a; 13979 t.gukatakana = 0x30b0; 13980 t.guramusquare = 0x3318; 13981 t.gysquare = 0x33c9; 13982 t.h = 0x0068; 13983 t.haabkhasiancyrillic = 0x04a9; 13984 t.haaltonearabic = 0x06c1; 13985 t.habengali = 0x09b9; 13986 t.hadescendercyrillic = 0x04b3; 13987 t.hadeva = 0x0939; 13988 t.hagujarati = 0x0ab9; 13989 t.hagurmukhi = 0x0a39; 13990 t.haharabic = 0x062d; 13991 t.hahfinalarabic = 0xfea2; 13992 t.hahinitialarabic = 0xfea3; 13993 t.hahiragana = 0x306f; 13994 t.hahmedialarabic = 0xfea4; 13995 t.haitusquare = 0x332a; 13996 t.hakatakana = 0x30cf; 13997 t.hakatakanahalfwidth = 0xff8a; 13998 t.halantgurmukhi = 0x0a4d; 13999 t.hamzaarabic = 0x0621; 14000 t.hamzalowarabic = 0x0621; 14001 t.hangulfiller = 0x3164; 14002 t.hardsigncyrillic = 0x044a; 14003 t.harpoonleftbarbup = 0x21bc; 14004 t.harpoonrightbarbup = 0x21c0; 14005 t.hasquare = 0x33ca; 14006 t.hatafpatah = 0x05b2; 14007 t.hatafpatah16 = 0x05b2; 14008 t.hatafpatah23 = 0x05b2; 14009 t.hatafpatah2f = 0x05b2; 14010 t.hatafpatahhebrew = 0x05b2; 14011 t.hatafpatahnarrowhebrew = 0x05b2; 14012 t.hatafpatahquarterhebrew = 0x05b2; 14013 t.hatafpatahwidehebrew = 0x05b2; 14014 t.hatafqamats = 0x05b3; 14015 t.hatafqamats1b = 0x05b3; 14016 t.hatafqamats28 = 0x05b3; 14017 t.hatafqamats34 = 0x05b3; 14018 t.hatafqamatshebrew = 0x05b3; 14019 t.hatafqamatsnarrowhebrew = 0x05b3; 14020 t.hatafqamatsquarterhebrew = 0x05b3; 14021 t.hatafqamatswidehebrew = 0x05b3; 14022 t.hatafsegol = 0x05b1; 14023 t.hatafsegol17 = 0x05b1; 14024 t.hatafsegol24 = 0x05b1; 14025 t.hatafsegol30 = 0x05b1; 14026 t.hatafsegolhebrew = 0x05b1; 14027 t.hatafsegolnarrowhebrew = 0x05b1; 14028 t.hatafsegolquarterhebrew = 0x05b1; 14029 t.hatafsegolwidehebrew = 0x05b1; 14030 t.hbar = 0x0127; 14031 t.hbopomofo = 0x310f; 14032 t.hbrevebelow = 0x1e2b; 14033 t.hcedilla = 0x1e29; 14034 t.hcircle = 0x24d7; 14035 t.hcircumflex = 0x0125; 14036 t.hdieresis = 0x1e27; 14037 t.hdotaccent = 0x1e23; 14038 t.hdotbelow = 0x1e25; 14039 t.he = 0x05d4; 14040 t.heart = 0x2665; 14041 t.heartsuitblack = 0x2665; 14042 t.heartsuitwhite = 0x2661; 14043 t.hedagesh = 0xfb34; 14044 t.hedageshhebrew = 0xfb34; 14045 t.hehaltonearabic = 0x06c1; 14046 t.heharabic = 0x0647; 14047 t.hehebrew = 0x05d4; 14048 t.hehfinalaltonearabic = 0xfba7; 14049 t.hehfinalalttwoarabic = 0xfeea; 14050 t.hehfinalarabic = 0xfeea; 14051 t.hehhamzaabovefinalarabic = 0xfba5; 14052 t.hehhamzaaboveisolatedarabic = 0xfba4; 14053 t.hehinitialaltonearabic = 0xfba8; 14054 t.hehinitialarabic = 0xfeeb; 14055 t.hehiragana = 0x3078; 14056 t.hehmedialaltonearabic = 0xfba9; 14057 t.hehmedialarabic = 0xfeec; 14058 t.heiseierasquare = 0x337b; 14059 t.hekatakana = 0x30d8; 14060 t.hekatakanahalfwidth = 0xff8d; 14061 t.hekutaarusquare = 0x3336; 14062 t.henghook = 0x0267; 14063 t.herutusquare = 0x3339; 14064 t.het = 0x05d7; 14065 t.hethebrew = 0x05d7; 14066 t.hhook = 0x0266; 14067 t.hhooksuperior = 0x02b1; 14068 t.hieuhacirclekorean = 0x327b; 14069 t.hieuhaparenkorean = 0x321b; 14070 t.hieuhcirclekorean = 0x326d; 14071 t.hieuhkorean = 0x314e; 14072 t.hieuhparenkorean = 0x320d; 14073 t.hihiragana = 0x3072; 14074 t.hikatakana = 0x30d2; 14075 t.hikatakanahalfwidth = 0xff8b; 14076 t.hiriq = 0x05b4; 14077 t.hiriq14 = 0x05b4; 14078 t.hiriq21 = 0x05b4; 14079 t.hiriq2d = 0x05b4; 14080 t.hiriqhebrew = 0x05b4; 14081 t.hiriqnarrowhebrew = 0x05b4; 14082 t.hiriqquarterhebrew = 0x05b4; 14083 t.hiriqwidehebrew = 0x05b4; 14084 t.hlinebelow = 0x1e96; 14085 t.hmonospace = 0xff48; 14086 t.hoarmenian = 0x0570; 14087 t.hohipthai = 0x0e2b; 14088 t.hohiragana = 0x307b; 14089 t.hokatakana = 0x30db; 14090 t.hokatakanahalfwidth = 0xff8e; 14091 t.holam = 0x05b9; 14092 t.holam19 = 0x05b9; 14093 t.holam26 = 0x05b9; 14094 t.holam32 = 0x05b9; 14095 t.holamhebrew = 0x05b9; 14096 t.holamnarrowhebrew = 0x05b9; 14097 t.holamquarterhebrew = 0x05b9; 14098 t.holamwidehebrew = 0x05b9; 14099 t.honokhukthai = 0x0e2e; 14100 t.hookabovecomb = 0x0309; 14101 t.hookcmb = 0x0309; 14102 t.hookpalatalizedbelowcmb = 0x0321; 14103 t.hookretroflexbelowcmb = 0x0322; 14104 t.hoonsquare = 0x3342; 14105 t.horicoptic = 0x03e9; 14106 t.horizontalbar = 0x2015; 14107 t.horncmb = 0x031b; 14108 t.hotsprings = 0x2668; 14109 t.house = 0x2302; 14110 t.hparen = 0x24a3; 14111 t.hsuperior = 0x02b0; 14112 t.hturned = 0x0265; 14113 t.huhiragana = 0x3075; 14114 t.huiitosquare = 0x3333; 14115 t.hukatakana = 0x30d5; 14116 t.hukatakanahalfwidth = 0xff8c; 14117 t.hungarumlaut = 0x02dd; 14118 t.hungarumlautcmb = 0x030b; 14119 t.hv = 0x0195; 14120 t.hyphen = 0x002d; 14121 t.hypheninferior = 0xf6e5; 14122 t.hyphenmonospace = 0xff0d; 14123 t.hyphensmall = 0xfe63; 14124 t.hyphensuperior = 0xf6e6; 14125 t.hyphentwo = 0x2010; 14126 t.i = 0x0069; 14127 t.iacute = 0x00ed; 14128 t.iacyrillic = 0x044f; 14129 t.ibengali = 0x0987; 14130 t.ibopomofo = 0x3127; 14131 t.ibreve = 0x012d; 14132 t.icaron = 0x01d0; 14133 t.icircle = 0x24d8; 14134 t.icircumflex = 0x00ee; 14135 t.icyrillic = 0x0456; 14136 t.idblgrave = 0x0209; 14137 t.ideographearthcircle = 0x328f; 14138 t.ideographfirecircle = 0x328b; 14139 t.ideographicallianceparen = 0x323f; 14140 t.ideographiccallparen = 0x323a; 14141 t.ideographiccentrecircle = 0x32a5; 14142 t.ideographicclose = 0x3006; 14143 t.ideographiccomma = 0x3001; 14144 t.ideographiccommaleft = 0xff64; 14145 t.ideographiccongratulationparen = 0x3237; 14146 t.ideographiccorrectcircle = 0x32a3; 14147 t.ideographicearthparen = 0x322f; 14148 t.ideographicenterpriseparen = 0x323d; 14149 t.ideographicexcellentcircle = 0x329d; 14150 t.ideographicfestivalparen = 0x3240; 14151 t.ideographicfinancialcircle = 0x3296; 14152 t.ideographicfinancialparen = 0x3236; 14153 t.ideographicfireparen = 0x322b; 14154 t.ideographichaveparen = 0x3232; 14155 t.ideographichighcircle = 0x32a4; 14156 t.ideographiciterationmark = 0x3005; 14157 t.ideographiclaborcircle = 0x3298; 14158 t.ideographiclaborparen = 0x3238; 14159 t.ideographicleftcircle = 0x32a7; 14160 t.ideographiclowcircle = 0x32a6; 14161 t.ideographicmedicinecircle = 0x32a9; 14162 t.ideographicmetalparen = 0x322e; 14163 t.ideographicmoonparen = 0x322a; 14164 t.ideographicnameparen = 0x3234; 14165 t.ideographicperiod = 0x3002; 14166 t.ideographicprintcircle = 0x329e; 14167 t.ideographicreachparen = 0x3243; 14168 t.ideographicrepresentparen = 0x3239; 14169 t.ideographicresourceparen = 0x323e; 14170 t.ideographicrightcircle = 0x32a8; 14171 t.ideographicsecretcircle = 0x3299; 14172 t.ideographicselfparen = 0x3242; 14173 t.ideographicsocietyparen = 0x3233; 14174 t.ideographicspace = 0x3000; 14175 t.ideographicspecialparen = 0x3235; 14176 t.ideographicstockparen = 0x3231; 14177 t.ideographicstudyparen = 0x323b; 14178 t.ideographicsunparen = 0x3230; 14179 t.ideographicsuperviseparen = 0x323c; 14180 t.ideographicwaterparen = 0x322c; 14181 t.ideographicwoodparen = 0x322d; 14182 t.ideographiczero = 0x3007; 14183 t.ideographmetalcircle = 0x328e; 14184 t.ideographmooncircle = 0x328a; 14185 t.ideographnamecircle = 0x3294; 14186 t.ideographsuncircle = 0x3290; 14187 t.ideographwatercircle = 0x328c; 14188 t.ideographwoodcircle = 0x328d; 14189 t.ideva = 0x0907; 14190 t.idieresis = 0x00ef; 14191 t.idieresisacute = 0x1e2f; 14192 t.idieresiscyrillic = 0x04e5; 14193 t.idotbelow = 0x1ecb; 14194 t.iebrevecyrillic = 0x04d7; 14195 t.iecyrillic = 0x0435; 14196 t.ieungacirclekorean = 0x3275; 14197 t.ieungaparenkorean = 0x3215; 14198 t.ieungcirclekorean = 0x3267; 14199 t.ieungkorean = 0x3147; 14200 t.ieungparenkorean = 0x3207; 14201 t.igrave = 0x00ec; 14202 t.igujarati = 0x0a87; 14203 t.igurmukhi = 0x0a07; 14204 t.ihiragana = 0x3044; 14205 t.ihookabove = 0x1ec9; 14206 t.iibengali = 0x0988; 14207 t.iicyrillic = 0x0438; 14208 t.iideva = 0x0908; 14209 t.iigujarati = 0x0a88; 14210 t.iigurmukhi = 0x0a08; 14211 t.iimatragurmukhi = 0x0a40; 14212 t.iinvertedbreve = 0x020b; 14213 t.iishortcyrillic = 0x0439; 14214 t.iivowelsignbengali = 0x09c0; 14215 t.iivowelsigndeva = 0x0940; 14216 t.iivowelsigngujarati = 0x0ac0; 14217 t.ij = 0x0133; 14218 t.ikatakana = 0x30a4; 14219 t.ikatakanahalfwidth = 0xff72; 14220 t.ikorean = 0x3163; 14221 t.ilde = 0x02dc; 14222 t.iluyhebrew = 0x05ac; 14223 t.imacron = 0x012b; 14224 t.imacroncyrillic = 0x04e3; 14225 t.imageorapproximatelyequal = 0x2253; 14226 t.imatragurmukhi = 0x0a3f; 14227 t.imonospace = 0xff49; 14228 t.increment = 0x2206; 14229 t.infinity = 0x221e; 14230 t.iniarmenian = 0x056b; 14231 t.integral = 0x222b; 14232 t.integralbottom = 0x2321; 14233 t.integralbt = 0x2321; 14234 t.integralex = 0xf8f5; 14235 t.integraltop = 0x2320; 14236 t.integraltp = 0x2320; 14237 t.intersection = 0x2229; 14238 t.intisquare = 0x3305; 14239 t.invbullet = 0x25d8; 14240 t.invcircle = 0x25d9; 14241 t.invsmileface = 0x263b; 14242 t.iocyrillic = 0x0451; 14243 t.iogonek = 0x012f; 14244 t.iota = 0x03b9; 14245 t.iotadieresis = 0x03ca; 14246 t.iotadieresistonos = 0x0390; 14247 t.iotalatin = 0x0269; 14248 t.iotatonos = 0x03af; 14249 t.iparen = 0x24a4; 14250 t.irigurmukhi = 0x0a72; 14251 t.ismallhiragana = 0x3043; 14252 t.ismallkatakana = 0x30a3; 14253 t.ismallkatakanahalfwidth = 0xff68; 14254 t.issharbengali = 0x09fa; 14255 t.istroke = 0x0268; 14256 t.isuperior = 0xf6ed; 14257 t.iterationhiragana = 0x309d; 14258 t.iterationkatakana = 0x30fd; 14259 t.itilde = 0x0129; 14260 t.itildebelow = 0x1e2d; 14261 t.iubopomofo = 0x3129; 14262 t.iucyrillic = 0x044e; 14263 t.ivowelsignbengali = 0x09bf; 14264 t.ivowelsigndeva = 0x093f; 14265 t.ivowelsigngujarati = 0x0abf; 14266 t.izhitsacyrillic = 0x0475; 14267 t.izhitsadblgravecyrillic = 0x0477; 14268 t.j = 0x006a; 14269 t.jaarmenian = 0x0571; 14270 t.jabengali = 0x099c; 14271 t.jadeva = 0x091c; 14272 t.jagujarati = 0x0a9c; 14273 t.jagurmukhi = 0x0a1c; 14274 t.jbopomofo = 0x3110; 14275 t.jcaron = 0x01f0; 14276 t.jcircle = 0x24d9; 14277 t.jcircumflex = 0x0135; 14278 t.jcrossedtail = 0x029d; 14279 t.jdotlessstroke = 0x025f; 14280 t.jecyrillic = 0x0458; 14281 t.jeemarabic = 0x062c; 14282 t.jeemfinalarabic = 0xfe9e; 14283 t.jeeminitialarabic = 0xfe9f; 14284 t.jeemmedialarabic = 0xfea0; 14285 t.jeharabic = 0x0698; 14286 t.jehfinalarabic = 0xfb8b; 14287 t.jhabengali = 0x099d; 14288 t.jhadeva = 0x091d; 14289 t.jhagujarati = 0x0a9d; 14290 t.jhagurmukhi = 0x0a1d; 14291 t.jheharmenian = 0x057b; 14292 t.jis = 0x3004; 14293 t.jmonospace = 0xff4a; 14294 t.jparen = 0x24a5; 14295 t.jsuperior = 0x02b2; 14296 t.k = 0x006b; 14297 t.kabashkircyrillic = 0x04a1; 14298 t.kabengali = 0x0995; 14299 t.kacute = 0x1e31; 14300 t.kacyrillic = 0x043a; 14301 t.kadescendercyrillic = 0x049b; 14302 t.kadeva = 0x0915; 14303 t.kaf = 0x05db; 14304 t.kafarabic = 0x0643; 14305 t.kafdagesh = 0xfb3b; 14306 t.kafdageshhebrew = 0xfb3b; 14307 t.kaffinalarabic = 0xfeda; 14308 t.kafhebrew = 0x05db; 14309 t.kafinitialarabic = 0xfedb; 14310 t.kafmedialarabic = 0xfedc; 14311 t.kafrafehebrew = 0xfb4d; 14312 t.kagujarati = 0x0a95; 14313 t.kagurmukhi = 0x0a15; 14314 t.kahiragana = 0x304b; 14315 t.kahookcyrillic = 0x04c4; 14316 t.kakatakana = 0x30ab; 14317 t.kakatakanahalfwidth = 0xff76; 14318 t.kappa = 0x03ba; 14319 t.kappasymbolgreek = 0x03f0; 14320 t.kapyeounmieumkorean = 0x3171; 14321 t.kapyeounphieuphkorean = 0x3184; 14322 t.kapyeounpieupkorean = 0x3178; 14323 t.kapyeounssangpieupkorean = 0x3179; 14324 t.karoriisquare = 0x330d; 14325 t.kashidaautoarabic = 0x0640; 14326 t.kashidaautonosidebearingarabic = 0x0640; 14327 t.kasmallkatakana = 0x30f5; 14328 t.kasquare = 0x3384; 14329 t.kasraarabic = 0x0650; 14330 t.kasratanarabic = 0x064d; 14331 t.kastrokecyrillic = 0x049f; 14332 t.katahiraprolongmarkhalfwidth = 0xff70; 14333 t.kaverticalstrokecyrillic = 0x049d; 14334 t.kbopomofo = 0x310e; 14335 t.kcalsquare = 0x3389; 14336 t.kcaron = 0x01e9; 14337 t.kcedilla = 0x0137; 14338 t.kcircle = 0x24da; 14339 t.kcommaaccent = 0x0137; 14340 t.kdotbelow = 0x1e33; 14341 t.keharmenian = 0x0584; 14342 t.kehiragana = 0x3051; 14343 t.kekatakana = 0x30b1; 14344 t.kekatakanahalfwidth = 0xff79; 14345 t.kenarmenian = 0x056f; 14346 t.kesmallkatakana = 0x30f6; 14347 t.kgreenlandic = 0x0138; 14348 t.khabengali = 0x0996; 14349 t.khacyrillic = 0x0445; 14350 t.khadeva = 0x0916; 14351 t.khagujarati = 0x0a96; 14352 t.khagurmukhi = 0x0a16; 14353 t.khaharabic = 0x062e; 14354 t.khahfinalarabic = 0xfea6; 14355 t.khahinitialarabic = 0xfea7; 14356 t.khahmedialarabic = 0xfea8; 14357 t.kheicoptic = 0x03e7; 14358 t.khhadeva = 0x0959; 14359 t.khhagurmukhi = 0x0a59; 14360 t.khieukhacirclekorean = 0x3278; 14361 t.khieukhaparenkorean = 0x3218; 14362 t.khieukhcirclekorean = 0x326a; 14363 t.khieukhkorean = 0x314b; 14364 t.khieukhparenkorean = 0x320a; 14365 t.khokhaithai = 0x0e02; 14366 t.khokhonthai = 0x0e05; 14367 t.khokhuatthai = 0x0e03; 14368 t.khokhwaithai = 0x0e04; 14369 t.khomutthai = 0x0e5b; 14370 t.khook = 0x0199; 14371 t.khorakhangthai = 0x0e06; 14372 t.khzsquare = 0x3391; 14373 t.kihiragana = 0x304d; 14374 t.kikatakana = 0x30ad; 14375 t.kikatakanahalfwidth = 0xff77; 14376 t.kiroguramusquare = 0x3315; 14377 t.kiromeetorusquare = 0x3316; 14378 t.kirosquare = 0x3314; 14379 t.kiyeokacirclekorean = 0x326e; 14380 t.kiyeokaparenkorean = 0x320e; 14381 t.kiyeokcirclekorean = 0x3260; 14382 t.kiyeokkorean = 0x3131; 14383 t.kiyeokparenkorean = 0x3200; 14384 t.kiyeoksioskorean = 0x3133; 14385 t.kjecyrillic = 0x045c; 14386 t.klinebelow = 0x1e35; 14387 t.klsquare = 0x3398; 14388 t.kmcubedsquare = 0x33a6; 14389 t.kmonospace = 0xff4b; 14390 t.kmsquaredsquare = 0x33a2; 14391 t.kohiragana = 0x3053; 14392 t.kohmsquare = 0x33c0; 14393 t.kokaithai = 0x0e01; 14394 t.kokatakana = 0x30b3; 14395 t.kokatakanahalfwidth = 0xff7a; 14396 t.kooposquare = 0x331e; 14397 t.koppacyrillic = 0x0481; 14398 t.koreanstandardsymbol = 0x327f; 14399 t.koroniscmb = 0x0343; 14400 t.kparen = 0x24a6; 14401 t.kpasquare = 0x33aa; 14402 t.ksicyrillic = 0x046f; 14403 t.ktsquare = 0x33cf; 14404 t.kturned = 0x029e; 14405 t.kuhiragana = 0x304f; 14406 t.kukatakana = 0x30af; 14407 t.kukatakanahalfwidth = 0xff78; 14408 t.kvsquare = 0x33b8; 14409 t.kwsquare = 0x33be; 14410 t.l = 0x006c; 14411 t.labengali = 0x09b2; 14412 t.lacute = 0x013a; 14413 t.ladeva = 0x0932; 14414 t.lagujarati = 0x0ab2; 14415 t.lagurmukhi = 0x0a32; 14416 t.lakkhangyaothai = 0x0e45; 14417 t.lamaleffinalarabic = 0xfefc; 14418 t.lamalefhamzaabovefinalarabic = 0xfef8; 14419 t.lamalefhamzaaboveisolatedarabic = 0xfef7; 14420 t.lamalefhamzabelowfinalarabic = 0xfefa; 14421 t.lamalefhamzabelowisolatedarabic = 0xfef9; 14422 t.lamalefisolatedarabic = 0xfefb; 14423 t.lamalefmaddaabovefinalarabic = 0xfef6; 14424 t.lamalefmaddaaboveisolatedarabic = 0xfef5; 14425 t.lamarabic = 0x0644; 14426 t.lambda = 0x03bb; 14427 t.lambdastroke = 0x019b; 14428 t.lamed = 0x05dc; 14429 t.lameddagesh = 0xfb3c; 14430 t.lameddageshhebrew = 0xfb3c; 14431 t.lamedhebrew = 0x05dc; 14432 t.lamfinalarabic = 0xfede; 14433 t.lamhahinitialarabic = 0xfcca; 14434 t.laminitialarabic = 0xfedf; 14435 t.lamjeeminitialarabic = 0xfcc9; 14436 t.lamkhahinitialarabic = 0xfccb; 14437 t.lamlamhehisolatedarabic = 0xfdf2; 14438 t.lammedialarabic = 0xfee0; 14439 t.lammeemhahinitialarabic = 0xfd88; 14440 t.lammeeminitialarabic = 0xfccc; 14441 t.largecircle = 0x25ef; 14442 t.lbar = 0x019a; 14443 t.lbelt = 0x026c; 14444 t.lbopomofo = 0x310c; 14445 t.lcaron = 0x013e; 14446 t.lcedilla = 0x013c; 14447 t.lcircle = 0x24db; 14448 t.lcircumflexbelow = 0x1e3d; 14449 t.lcommaaccent = 0x013c; 14450 t.ldot = 0x0140; 14451 t.ldotaccent = 0x0140; 14452 t.ldotbelow = 0x1e37; 14453 t.ldotbelowmacron = 0x1e39; 14454 t.leftangleabovecmb = 0x031a; 14455 t.lefttackbelowcmb = 0x0318; 14456 t.less = 0x003c; 14457 t.lessequal = 0x2264; 14458 t.lessequalorgreater = 0x22da; 14459 t.lessmonospace = 0xff1c; 14460 t.lessorequivalent = 0x2272; 14461 t.lessorgreater = 0x2276; 14462 t.lessoverequal = 0x2266; 14463 t.lesssmall = 0xfe64; 14464 t.lezh = 0x026e; 14465 t.lfblock = 0x258c; 14466 t.lhookretroflex = 0x026d; 14467 t.lira = 0x20a4; 14468 t.liwnarmenian = 0x056c; 14469 t.lj = 0x01c9; 14470 t.ljecyrillic = 0x0459; 14471 t.ll = 0xf6c0; 14472 t.lladeva = 0x0933; 14473 t.llagujarati = 0x0ab3; 14474 t.llinebelow = 0x1e3b; 14475 t.llladeva = 0x0934; 14476 t.llvocalicbengali = 0x09e1; 14477 t.llvocalicdeva = 0x0961; 14478 t.llvocalicvowelsignbengali = 0x09e3; 14479 t.llvocalicvowelsigndeva = 0x0963; 14480 t.lmiddletilde = 0x026b; 14481 t.lmonospace = 0xff4c; 14482 t.lmsquare = 0x33d0; 14483 t.lochulathai = 0x0e2c; 14484 t.logicaland = 0x2227; 14485 t.logicalnot = 0x00ac; 14486 t.logicalnotreversed = 0x2310; 14487 t.logicalor = 0x2228; 14488 t.lolingthai = 0x0e25; 14489 t.longs = 0x017f; 14490 t.lowlinecenterline = 0xfe4e; 14491 t.lowlinecmb = 0x0332; 14492 t.lowlinedashed = 0xfe4d; 14493 t.lozenge = 0x25ca; 14494 t.lparen = 0x24a7; 14495 t.lslash = 0x0142; 14496 t.lsquare = 0x2113; 14497 t.lsuperior = 0xf6ee; 14498 t.ltshade = 0x2591; 14499 t.luthai = 0x0e26; 14500 t.lvocalicbengali = 0x098c; 14501 t.lvocalicdeva = 0x090c; 14502 t.lvocalicvowelsignbengali = 0x09e2; 14503 t.lvocalicvowelsigndeva = 0x0962; 14504 t.lxsquare = 0x33d3; 14505 t.m = 0x006d; 14506 t.mabengali = 0x09ae; 14507 t.macron = 0x00af; 14508 t.macronbelowcmb = 0x0331; 14509 t.macroncmb = 0x0304; 14510 t.macronlowmod = 0x02cd; 14511 t.macronmonospace = 0xffe3; 14512 t.macute = 0x1e3f; 14513 t.madeva = 0x092e; 14514 t.magujarati = 0x0aae; 14515 t.magurmukhi = 0x0a2e; 14516 t.mahapakhhebrew = 0x05a4; 14517 t.mahapakhlefthebrew = 0x05a4; 14518 t.mahiragana = 0x307e; 14519 t.maichattawalowleftthai = 0xf895; 14520 t.maichattawalowrightthai = 0xf894; 14521 t.maichattawathai = 0x0e4b; 14522 t.maichattawaupperleftthai = 0xf893; 14523 t.maieklowleftthai = 0xf88c; 14524 t.maieklowrightthai = 0xf88b; 14525 t.maiekthai = 0x0e48; 14526 t.maiekupperleftthai = 0xf88a; 14527 t.maihanakatleftthai = 0xf884; 14528 t.maihanakatthai = 0x0e31; 14529 t.maitaikhuleftthai = 0xf889; 14530 t.maitaikhuthai = 0x0e47; 14531 t.maitholowleftthai = 0xf88f; 14532 t.maitholowrightthai = 0xf88e; 14533 t.maithothai = 0x0e49; 14534 t.maithoupperleftthai = 0xf88d; 14535 t.maitrilowleftthai = 0xf892; 14536 t.maitrilowrightthai = 0xf891; 14537 t.maitrithai = 0x0e4a; 14538 t.maitriupperleftthai = 0xf890; 14539 t.maiyamokthai = 0x0e46; 14540 t.makatakana = 0x30de; 14541 t.makatakanahalfwidth = 0xff8f; 14542 t.male = 0x2642; 14543 t.mansyonsquare = 0x3347; 14544 t.maqafhebrew = 0x05be; 14545 t.mars = 0x2642; 14546 t.masoracirclehebrew = 0x05af; 14547 t.masquare = 0x3383; 14548 t.mbopomofo = 0x3107; 14549 t.mbsquare = 0x33d4; 14550 t.mcircle = 0x24dc; 14551 t.mcubedsquare = 0x33a5; 14552 t.mdotaccent = 0x1e41; 14553 t.mdotbelow = 0x1e43; 14554 t.meemarabic = 0x0645; 14555 t.meemfinalarabic = 0xfee2; 14556 t.meeminitialarabic = 0xfee3; 14557 t.meemmedialarabic = 0xfee4; 14558 t.meemmeeminitialarabic = 0xfcd1; 14559 t.meemmeemisolatedarabic = 0xfc48; 14560 t.meetorusquare = 0x334d; 14561 t.mehiragana = 0x3081; 14562 t.meizierasquare = 0x337e; 14563 t.mekatakana = 0x30e1; 14564 t.mekatakanahalfwidth = 0xff92; 14565 t.mem = 0x05de; 14566 t.memdagesh = 0xfb3e; 14567 t.memdageshhebrew = 0xfb3e; 14568 t.memhebrew = 0x05de; 14569 t.menarmenian = 0x0574; 14570 t.merkhahebrew = 0x05a5; 14571 t.merkhakefulahebrew = 0x05a6; 14572 t.merkhakefulalefthebrew = 0x05a6; 14573 t.merkhalefthebrew = 0x05a5; 14574 t.mhook = 0x0271; 14575 t.mhzsquare = 0x3392; 14576 t.middledotkatakanahalfwidth = 0xff65; 14577 t.middot = 0x00b7; 14578 t.mieumacirclekorean = 0x3272; 14579 t.mieumaparenkorean = 0x3212; 14580 t.mieumcirclekorean = 0x3264; 14581 t.mieumkorean = 0x3141; 14582 t.mieumpansioskorean = 0x3170; 14583 t.mieumparenkorean = 0x3204; 14584 t.mieumpieupkorean = 0x316e; 14585 t.mieumsioskorean = 0x316f; 14586 t.mihiragana = 0x307f; 14587 t.mikatakana = 0x30df; 14588 t.mikatakanahalfwidth = 0xff90; 14589 t.minus = 0x2212; 14590 t.minusbelowcmb = 0x0320; 14591 t.minuscircle = 0x2296; 14592 t.minusmod = 0x02d7; 14593 t.minusplus = 0x2213; 14594 t.minute = 0x2032; 14595 t.miribaarusquare = 0x334a; 14596 t.mirisquare = 0x3349; 14597 t.mlonglegturned = 0x0270; 14598 t.mlsquare = 0x3396; 14599 t.mmcubedsquare = 0x33a3; 14600 t.mmonospace = 0xff4d; 14601 t.mmsquaredsquare = 0x339f; 14602 t.mohiragana = 0x3082; 14603 t.mohmsquare = 0x33c1; 14604 t.mokatakana = 0x30e2; 14605 t.mokatakanahalfwidth = 0xff93; 14606 t.molsquare = 0x33d6; 14607 t.momathai = 0x0e21; 14608 t.moverssquare = 0x33a7; 14609 t.moverssquaredsquare = 0x33a8; 14610 t.mparen = 0x24a8; 14611 t.mpasquare = 0x33ab; 14612 t.mssquare = 0x33b3; 14613 t.msuperior = 0xf6ef; 14614 t.mturned = 0x026f; 14615 t.mu = 0x00b5; 14616 t.mu1 = 0x00b5; 14617 t.muasquare = 0x3382; 14618 t.muchgreater = 0x226b; 14619 t.muchless = 0x226a; 14620 t.mufsquare = 0x338c; 14621 t.mugreek = 0x03bc; 14622 t.mugsquare = 0x338d; 14623 t.muhiragana = 0x3080; 14624 t.mukatakana = 0x30e0; 14625 t.mukatakanahalfwidth = 0xff91; 14626 t.mulsquare = 0x3395; 14627 t.multiply = 0x00d7; 14628 t.mumsquare = 0x339b; 14629 t.munahhebrew = 0x05a3; 14630 t.munahlefthebrew = 0x05a3; 14631 t.musicalnote = 0x266a; 14632 t.musicalnotedbl = 0x266b; 14633 t.musicflatsign = 0x266d; 14634 t.musicsharpsign = 0x266f; 14635 t.mussquare = 0x33b2; 14636 t.muvsquare = 0x33b6; 14637 t.muwsquare = 0x33bc; 14638 t.mvmegasquare = 0x33b9; 14639 t.mvsquare = 0x33b7; 14640 t.mwmegasquare = 0x33bf; 14641 t.mwsquare = 0x33bd; 14642 t.n = 0x006e; 14643 t.nabengali = 0x09a8; 14644 t.nabla = 0x2207; 14645 t.nacute = 0x0144; 14646 t.nadeva = 0x0928; 14647 t.nagujarati = 0x0aa8; 14648 t.nagurmukhi = 0x0a28; 14649 t.nahiragana = 0x306a; 14650 t.nakatakana = 0x30ca; 14651 t.nakatakanahalfwidth = 0xff85; 14652 t.napostrophe = 0x0149; 14653 t.nasquare = 0x3381; 14654 t.nbopomofo = 0x310b; 14655 t.nbspace = 0x00a0; 14656 t.ncaron = 0x0148; 14657 t.ncedilla = 0x0146; 14658 t.ncircle = 0x24dd; 14659 t.ncircumflexbelow = 0x1e4b; 14660 t.ncommaaccent = 0x0146; 14661 t.ndotaccent = 0x1e45; 14662 t.ndotbelow = 0x1e47; 14663 t.nehiragana = 0x306d; 14664 t.nekatakana = 0x30cd; 14665 t.nekatakanahalfwidth = 0xff88; 14666 t.newsheqelsign = 0x20aa; 14667 t.nfsquare = 0x338b; 14668 t.ngabengali = 0x0999; 14669 t.ngadeva = 0x0919; 14670 t.ngagujarati = 0x0a99; 14671 t.ngagurmukhi = 0x0a19; 14672 t.ngonguthai = 0x0e07; 14673 t.nhiragana = 0x3093; 14674 t.nhookleft = 0x0272; 14675 t.nhookretroflex = 0x0273; 14676 t.nieunacirclekorean = 0x326f; 14677 t.nieunaparenkorean = 0x320f; 14678 t.nieuncieuckorean = 0x3135; 14679 t.nieuncirclekorean = 0x3261; 14680 t.nieunhieuhkorean = 0x3136; 14681 t.nieunkorean = 0x3134; 14682 t.nieunpansioskorean = 0x3168; 14683 t.nieunparenkorean = 0x3201; 14684 t.nieunsioskorean = 0x3167; 14685 t.nieuntikeutkorean = 0x3166; 14686 t.nihiragana = 0x306b; 14687 t.nikatakana = 0x30cb; 14688 t.nikatakanahalfwidth = 0xff86; 14689 t.nikhahitleftthai = 0xf899; 14690 t.nikhahitthai = 0x0e4d; 14691 t.nine = 0x0039; 14692 t.ninearabic = 0x0669; 14693 t.ninebengali = 0x09ef; 14694 t.ninecircle = 0x2468; 14695 t.ninecircleinversesansserif = 0x2792; 14696 t.ninedeva = 0x096f; 14697 t.ninegujarati = 0x0aef; 14698 t.ninegurmukhi = 0x0a6f; 14699 t.ninehackarabic = 0x0669; 14700 t.ninehangzhou = 0x3029; 14701 t.nineideographicparen = 0x3228; 14702 t.nineinferior = 0x2089; 14703 t.ninemonospace = 0xff19; 14704 t.nineoldstyle = 0xf739; 14705 t.nineparen = 0x247c; 14706 t.nineperiod = 0x2490; 14707 t.ninepersian = 0x06f9; 14708 t.nineroman = 0x2178; 14709 t.ninesuperior = 0x2079; 14710 t.nineteencircle = 0x2472; 14711 t.nineteenparen = 0x2486; 14712 t.nineteenperiod = 0x249a; 14713 t.ninethai = 0x0e59; 14714 t.nj = 0x01cc; 14715 t.njecyrillic = 0x045a; 14716 t.nkatakana = 0x30f3; 14717 t.nkatakanahalfwidth = 0xff9d; 14718 t.nlegrightlong = 0x019e; 14719 t.nlinebelow = 0x1e49; 14720 t.nmonospace = 0xff4e; 14721 t.nmsquare = 0x339a; 14722 t.nnabengali = 0x09a3; 14723 t.nnadeva = 0x0923; 14724 t.nnagujarati = 0x0aa3; 14725 t.nnagurmukhi = 0x0a23; 14726 t.nnnadeva = 0x0929; 14727 t.nohiragana = 0x306e; 14728 t.nokatakana = 0x30ce; 14729 t.nokatakanahalfwidth = 0xff89; 14730 t.nonbreakingspace = 0x00a0; 14731 t.nonenthai = 0x0e13; 14732 t.nonuthai = 0x0e19; 14733 t.noonarabic = 0x0646; 14734 t.noonfinalarabic = 0xfee6; 14735 t.noonghunnaarabic = 0x06ba; 14736 t.noonghunnafinalarabic = 0xfb9f; 14737 t.nooninitialarabic = 0xfee7; 14738 t.noonjeeminitialarabic = 0xfcd2; 14739 t.noonjeemisolatedarabic = 0xfc4b; 14740 t.noonmedialarabic = 0xfee8; 14741 t.noonmeeminitialarabic = 0xfcd5; 14742 t.noonmeemisolatedarabic = 0xfc4e; 14743 t.noonnoonfinalarabic = 0xfc8d; 14744 t.notcontains = 0x220c; 14745 t.notelement = 0x2209; 14746 t.notelementof = 0x2209; 14747 t.notequal = 0x2260; 14748 t.notgreater = 0x226f; 14749 t.notgreaternorequal = 0x2271; 14750 t.notgreaternorless = 0x2279; 14751 t.notidentical = 0x2262; 14752 t.notless = 0x226e; 14753 t.notlessnorequal = 0x2270; 14754 t.notparallel = 0x2226; 14755 t.notprecedes = 0x2280; 14756 t.notsubset = 0x2284; 14757 t.notsucceeds = 0x2281; 14758 t.notsuperset = 0x2285; 14759 t.nowarmenian = 0x0576; 14760 t.nparen = 0x24a9; 14761 t.nssquare = 0x33b1; 14762 t.nsuperior = 0x207f; 14763 t.ntilde = 0x00f1; 14764 t.nu = 0x03bd; 14765 t.nuhiragana = 0x306c; 14766 t.nukatakana = 0x30cc; 14767 t.nukatakanahalfwidth = 0xff87; 14768 t.nuktabengali = 0x09bc; 14769 t.nuktadeva = 0x093c; 14770 t.nuktagujarati = 0x0abc; 14771 t.nuktagurmukhi = 0x0a3c; 14772 t.numbersign = 0x0023; 14773 t.numbersignmonospace = 0xff03; 14774 t.numbersignsmall = 0xfe5f; 14775 t.numeralsigngreek = 0x0374; 14776 t.numeralsignlowergreek = 0x0375; 14777 t.numero = 0x2116; 14778 t.nun = 0x05e0; 14779 t.nundagesh = 0xfb40; 14780 t.nundageshhebrew = 0xfb40; 14781 t.nunhebrew = 0x05e0; 14782 t.nvsquare = 0x33b5; 14783 t.nwsquare = 0x33bb; 14784 t.nyabengali = 0x099e; 14785 t.nyadeva = 0x091e; 14786 t.nyagujarati = 0x0a9e; 14787 t.nyagurmukhi = 0x0a1e; 14788 t.o = 0x006f; 14789 t.oacute = 0x00f3; 14790 t.oangthai = 0x0e2d; 14791 t.obarred = 0x0275; 14792 t.obarredcyrillic = 0x04e9; 14793 t.obarreddieresiscyrillic = 0x04eb; 14794 t.obengali = 0x0993; 14795 t.obopomofo = 0x311b; 14796 t.obreve = 0x014f; 14797 t.ocandradeva = 0x0911; 14798 t.ocandragujarati = 0x0a91; 14799 t.ocandravowelsigndeva = 0x0949; 14800 t.ocandravowelsigngujarati = 0x0ac9; 14801 t.ocaron = 0x01d2; 14802 t.ocircle = 0x24de; 14803 t.ocircumflex = 0x00f4; 14804 t.ocircumflexacute = 0x1ed1; 14805 t.ocircumflexdotbelow = 0x1ed9; 14806 t.ocircumflexgrave = 0x1ed3; 14807 t.ocircumflexhookabove = 0x1ed5; 14808 t.ocircumflextilde = 0x1ed7; 14809 t.ocyrillic = 0x043e; 14810 t.odblacute = 0x0151; 14811 t.odblgrave = 0x020d; 14812 t.odeva = 0x0913; 14813 t.odieresis = 0x00f6; 14814 t.odieresiscyrillic = 0x04e7; 14815 t.odotbelow = 0x1ecd; 14816 t.oe = 0x0153; 14817 t.oekorean = 0x315a; 14818 t.ogonek = 0x02db; 14819 t.ogonekcmb = 0x0328; 14820 t.ograve = 0x00f2; 14821 t.ogujarati = 0x0a93; 14822 t.oharmenian = 0x0585; 14823 t.ohiragana = 0x304a; 14824 t.ohookabove = 0x1ecf; 14825 t.ohorn = 0x01a1; 14826 t.ohornacute = 0x1edb; 14827 t.ohorndotbelow = 0x1ee3; 14828 t.ohorngrave = 0x1edd; 14829 t.ohornhookabove = 0x1edf; 14830 t.ohorntilde = 0x1ee1; 14831 t.ohungarumlaut = 0x0151; 14832 t.oi = 0x01a3; 14833 t.oinvertedbreve = 0x020f; 14834 t.okatakana = 0x30aa; 14835 t.okatakanahalfwidth = 0xff75; 14836 t.okorean = 0x3157; 14837 t.olehebrew = 0x05ab; 14838 t.omacron = 0x014d; 14839 t.omacronacute = 0x1e53; 14840 t.omacrongrave = 0x1e51; 14841 t.omdeva = 0x0950; 14842 t.omega = 0x03c9; 14843 t.omega1 = 0x03d6; 14844 t.omegacyrillic = 0x0461; 14845 t.omegalatinclosed = 0x0277; 14846 t.omegaroundcyrillic = 0x047b; 14847 t.omegatitlocyrillic = 0x047d; 14848 t.omegatonos = 0x03ce; 14849 t.omgujarati = 0x0ad0; 14850 t.omicron = 0x03bf; 14851 t.omicrontonos = 0x03cc; 14852 t.omonospace = 0xff4f; 14853 t.one = 0x0031; 14854 t.onearabic = 0x0661; 14855 t.onebengali = 0x09e7; 14856 t.onecircle = 0x2460; 14857 t.onecircleinversesansserif = 0x278a; 14858 t.onedeva = 0x0967; 14859 t.onedotenleader = 0x2024; 14860 t.oneeighth = 0x215b; 14861 t.onefitted = 0xf6dc; 14862 t.onegujarati = 0x0ae7; 14863 t.onegurmukhi = 0x0a67; 14864 t.onehackarabic = 0x0661; 14865 t.onehalf = 0x00bd; 14866 t.onehangzhou = 0x3021; 14867 t.oneideographicparen = 0x3220; 14868 t.oneinferior = 0x2081; 14869 t.onemonospace = 0xff11; 14870 t.onenumeratorbengali = 0x09f4; 14871 t.oneoldstyle = 0xf731; 14872 t.oneparen = 0x2474; 14873 t.oneperiod = 0x2488; 14874 t.onepersian = 0x06f1; 14875 t.onequarter = 0x00bc; 14876 t.oneroman = 0x2170; 14877 t.onesuperior = 0x00b9; 14878 t.onethai = 0x0e51; 14879 t.onethird = 0x2153; 14880 t.oogonek = 0x01eb; 14881 t.oogonekmacron = 0x01ed; 14882 t.oogurmukhi = 0x0a13; 14883 t.oomatragurmukhi = 0x0a4b; 14884 t.oopen = 0x0254; 14885 t.oparen = 0x24aa; 14886 t.openbullet = 0x25e6; 14887 t.option = 0x2325; 14888 t.ordfeminine = 0x00aa; 14889 t.ordmasculine = 0x00ba; 14890 t.orthogonal = 0x221f; 14891 t.oshortdeva = 0x0912; 14892 t.oshortvowelsigndeva = 0x094a; 14893 t.oslash = 0x00f8; 14894 t.oslashacute = 0x01ff; 14895 t.osmallhiragana = 0x3049; 14896 t.osmallkatakana = 0x30a9; 14897 t.osmallkatakanahalfwidth = 0xff6b; 14898 t.ostrokeacute = 0x01ff; 14899 t.osuperior = 0xf6f0; 14900 t.otcyrillic = 0x047f; 14901 t.otilde = 0x00f5; 14902 t.otildeacute = 0x1e4d; 14903 t.otildedieresis = 0x1e4f; 14904 t.oubopomofo = 0x3121; 14905 t.overline = 0x203e; 14906 t.overlinecenterline = 0xfe4a; 14907 t.overlinecmb = 0x0305; 14908 t.overlinedashed = 0xfe49; 14909 t.overlinedblwavy = 0xfe4c; 14910 t.overlinewavy = 0xfe4b; 14911 t.overscore = 0x00af; 14912 t.ovowelsignbengali = 0x09cb; 14913 t.ovowelsigndeva = 0x094b; 14914 t.ovowelsigngujarati = 0x0acb; 14915 t.p = 0x0070; 14916 t.paampssquare = 0x3380; 14917 t.paasentosquare = 0x332b; 14918 t.pabengali = 0x09aa; 14919 t.pacute = 0x1e55; 14920 t.padeva = 0x092a; 14921 t.pagedown = 0x21df; 14922 t.pageup = 0x21de; 14923 t.pagujarati = 0x0aaa; 14924 t.pagurmukhi = 0x0a2a; 14925 t.pahiragana = 0x3071; 14926 t.paiyannoithai = 0x0e2f; 14927 t.pakatakana = 0x30d1; 14928 t.palatalizationcyrilliccmb = 0x0484; 14929 t.palochkacyrillic = 0x04c0; 14930 t.pansioskorean = 0x317f; 14931 t.paragraph = 0x00b6; 14932 t.parallel = 0x2225; 14933 t.parenleft = 0x0028; 14934 t.parenleftaltonearabic = 0xfd3e; 14935 t.parenleftbt = 0xf8ed; 14936 t.parenleftex = 0xf8ec; 14937 t.parenleftinferior = 0x208d; 14938 t.parenleftmonospace = 0xff08; 14939 t.parenleftsmall = 0xfe59; 14940 t.parenleftsuperior = 0x207d; 14941 t.parenlefttp = 0xf8eb; 14942 t.parenleftvertical = 0xfe35; 14943 t.parenright = 0x0029; 14944 t.parenrightaltonearabic = 0xfd3f; 14945 t.parenrightbt = 0xf8f8; 14946 t.parenrightex = 0xf8f7; 14947 t.parenrightinferior = 0x208e; 14948 t.parenrightmonospace = 0xff09; 14949 t.parenrightsmall = 0xfe5a; 14950 t.parenrightsuperior = 0x207e; 14951 t.parenrighttp = 0xf8f6; 14952 t.parenrightvertical = 0xfe36; 14953 t.partialdiff = 0x2202; 14954 t.paseqhebrew = 0x05c0; 14955 t.pashtahebrew = 0x0599; 14956 t.pasquare = 0x33a9; 14957 t.patah = 0x05b7; 14958 t.patah11 = 0x05b7; 14959 t.patah1d = 0x05b7; 14960 t.patah2a = 0x05b7; 14961 t.patahhebrew = 0x05b7; 14962 t.patahnarrowhebrew = 0x05b7; 14963 t.patahquarterhebrew = 0x05b7; 14964 t.patahwidehebrew = 0x05b7; 14965 t.pazerhebrew = 0x05a1; 14966 t.pbopomofo = 0x3106; 14967 t.pcircle = 0x24df; 14968 t.pdotaccent = 0x1e57; 14969 t.pe = 0x05e4; 14970 t.pecyrillic = 0x043f; 14971 t.pedagesh = 0xfb44; 14972 t.pedageshhebrew = 0xfb44; 14973 t.peezisquare = 0x333b; 14974 t.pefinaldageshhebrew = 0xfb43; 14975 t.peharabic = 0x067e; 14976 t.peharmenian = 0x057a; 14977 t.pehebrew = 0x05e4; 14978 t.pehfinalarabic = 0xfb57; 14979 t.pehinitialarabic = 0xfb58; 14980 t.pehiragana = 0x307a; 14981 t.pehmedialarabic = 0xfb59; 14982 t.pekatakana = 0x30da; 14983 t.pemiddlehookcyrillic = 0x04a7; 14984 t.perafehebrew = 0xfb4e; 14985 t.percent = 0x0025; 14986 t.percentarabic = 0x066a; 14987 t.percentmonospace = 0xff05; 14988 t.percentsmall = 0xfe6a; 14989 t.period = 0x002e; 14990 t.periodarmenian = 0x0589; 14991 t.periodcentered = 0x00b7; 14992 t.periodhalfwidth = 0xff61; 14993 t.periodinferior = 0xf6e7; 14994 t.periodmonospace = 0xff0e; 14995 t.periodsmall = 0xfe52; 14996 t.periodsuperior = 0xf6e8; 14997 t.perispomenigreekcmb = 0x0342; 14998 t.perpendicular = 0x22a5; 14999 t.perthousand = 0x2030; 15000 t.peseta = 0x20a7; 15001 t.pfsquare = 0x338a; 15002 t.phabengali = 0x09ab; 15003 t.phadeva = 0x092b; 15004 t.phagujarati = 0x0aab; 15005 t.phagurmukhi = 0x0a2b; 15006 t.phi = 0x03c6; 15007 t.phi1 = 0x03d5; 15008 t.phieuphacirclekorean = 0x327a; 15009 t.phieuphaparenkorean = 0x321a; 15010 t.phieuphcirclekorean = 0x326c; 15011 t.phieuphkorean = 0x314d; 15012 t.phieuphparenkorean = 0x320c; 15013 t.philatin = 0x0278; 15014 t.phinthuthai = 0x0e3a; 15015 t.phisymbolgreek = 0x03d5; 15016 t.phook = 0x01a5; 15017 t.phophanthai = 0x0e1e; 15018 t.phophungthai = 0x0e1c; 15019 t.phosamphaothai = 0x0e20; 15020 t.pi = 0x03c0; 15021 t.pieupacirclekorean = 0x3273; 15022 t.pieupaparenkorean = 0x3213; 15023 t.pieupcieuckorean = 0x3176; 15024 t.pieupcirclekorean = 0x3265; 15025 t.pieupkiyeokkorean = 0x3172; 15026 t.pieupkorean = 0x3142; 15027 t.pieupparenkorean = 0x3205; 15028 t.pieupsioskiyeokkorean = 0x3174; 15029 t.pieupsioskorean = 0x3144; 15030 t.pieupsiostikeutkorean = 0x3175; 15031 t.pieupthieuthkorean = 0x3177; 15032 t.pieuptikeutkorean = 0x3173; 15033 t.pihiragana = 0x3074; 15034 t.pikatakana = 0x30d4; 15035 t.pisymbolgreek = 0x03d6; 15036 t.piwrarmenian = 0x0583; 15037 t.planckover2pi = 0x210f; 15038 t.planckover2pi1 = 0x210f; 15039 t.plus = 0x002b; 15040 t.plusbelowcmb = 0x031f; 15041 t.pluscircle = 0x2295; 15042 t.plusminus = 0x00b1; 15043 t.plusmod = 0x02d6; 15044 t.plusmonospace = 0xff0b; 15045 t.plussmall = 0xfe62; 15046 t.plussuperior = 0x207a; 15047 t.pmonospace = 0xff50; 15048 t.pmsquare = 0x33d8; 15049 t.pohiragana = 0x307d; 15050 t.pointingindexdownwhite = 0x261f; 15051 t.pointingindexleftwhite = 0x261c; 15052 t.pointingindexrightwhite = 0x261e; 15053 t.pointingindexupwhite = 0x261d; 15054 t.pokatakana = 0x30dd; 15055 t.poplathai = 0x0e1b; 15056 t.postalmark = 0x3012; 15057 t.postalmarkface = 0x3020; 15058 t.pparen = 0x24ab; 15059 t.precedes = 0x227a; 15060 t.prescription = 0x211e; 15061 t.primemod = 0x02b9; 15062 t.primereversed = 0x2035; 15063 t.product = 0x220f; 15064 t.projective = 0x2305; 15065 t.prolongedkana = 0x30fc; 15066 t.propellor = 0x2318; 15067 t.propersubset = 0x2282; 15068 t.propersuperset = 0x2283; 15069 t.proportion = 0x2237; 15070 t.proportional = 0x221d; 15071 t.psi = 0x03c8; 15072 t.psicyrillic = 0x0471; 15073 t.psilipneumatacyrilliccmb = 0x0486; 15074 t.pssquare = 0x33b0; 15075 t.puhiragana = 0x3077; 15076 t.pukatakana = 0x30d7; 15077 t.pvsquare = 0x33b4; 15078 t.pwsquare = 0x33ba; 15079 t.q = 0x0071; 15080 t.qadeva = 0x0958; 15081 t.qadmahebrew = 0x05a8; 15082 t.qafarabic = 0x0642; 15083 t.qaffinalarabic = 0xfed6; 15084 t.qafinitialarabic = 0xfed7; 15085 t.qafmedialarabic = 0xfed8; 15086 t.qamats = 0x05b8; 15087 t.qamats10 = 0x05b8; 15088 t.qamats1a = 0x05b8; 15089 t.qamats1c = 0x05b8; 15090 t.qamats27 = 0x05b8; 15091 t.qamats29 = 0x05b8; 15092 t.qamats33 = 0x05b8; 15093 t.qamatsde = 0x05b8; 15094 t.qamatshebrew = 0x05b8; 15095 t.qamatsnarrowhebrew = 0x05b8; 15096 t.qamatsqatanhebrew = 0x05b8; 15097 t.qamatsqatannarrowhebrew = 0x05b8; 15098 t.qamatsqatanquarterhebrew = 0x05b8; 15099 t.qamatsqatanwidehebrew = 0x05b8; 15100 t.qamatsquarterhebrew = 0x05b8; 15101 t.qamatswidehebrew = 0x05b8; 15102 t.qarneyparahebrew = 0x059f; 15103 t.qbopomofo = 0x3111; 15104 t.qcircle = 0x24e0; 15105 t.qhook = 0x02a0; 15106 t.qmonospace = 0xff51; 15107 t.qof = 0x05e7; 15108 t.qofdagesh = 0xfb47; 15109 t.qofdageshhebrew = 0xfb47; 15110 t.qofhebrew = 0x05e7; 15111 t.qparen = 0x24ac; 15112 t.quarternote = 0x2669; 15113 t.qubuts = 0x05bb; 15114 t.qubuts18 = 0x05bb; 15115 t.qubuts25 = 0x05bb; 15116 t.qubuts31 = 0x05bb; 15117 t.qubutshebrew = 0x05bb; 15118 t.qubutsnarrowhebrew = 0x05bb; 15119 t.qubutsquarterhebrew = 0x05bb; 15120 t.qubutswidehebrew = 0x05bb; 15121 t.question = 0x003f; 15122 t.questionarabic = 0x061f; 15123 t.questionarmenian = 0x055e; 15124 t.questiondown = 0x00bf; 15125 t.questiondownsmall = 0xf7bf; 15126 t.questiongreek = 0x037e; 15127 t.questionmonospace = 0xff1f; 15128 t.questionsmall = 0xf73f; 15129 t.quotedbl = 0x0022; 15130 t.quotedblbase = 0x201e; 15131 t.quotedblleft = 0x201c; 15132 t.quotedblmonospace = 0xff02; 15133 t.quotedblprime = 0x301e; 15134 t.quotedblprimereversed = 0x301d; 15135 t.quotedblright = 0x201d; 15136 t.quoteleft = 0x2018; 15137 t.quoteleftreversed = 0x201b; 15138 t.quotereversed = 0x201b; 15139 t.quoteright = 0x2019; 15140 t.quoterightn = 0x0149; 15141 t.quotesinglbase = 0x201a; 15142 t.quotesingle = 0x0027; 15143 t.quotesinglemonospace = 0xff07; 15144 t.r = 0x0072; 15145 t.raarmenian = 0x057c; 15146 t.rabengali = 0x09b0; 15147 t.racute = 0x0155; 15148 t.radeva = 0x0930; 15149 t.radical = 0x221a; 15150 t.radicalex = 0xf8e5; 15151 t.radoverssquare = 0x33ae; 15152 t.radoverssquaredsquare = 0x33af; 15153 t.radsquare = 0x33ad; 15154 t.rafe = 0x05bf; 15155 t.rafehebrew = 0x05bf; 15156 t.ragujarati = 0x0ab0; 15157 t.ragurmukhi = 0x0a30; 15158 t.rahiragana = 0x3089; 15159 t.rakatakana = 0x30e9; 15160 t.rakatakanahalfwidth = 0xff97; 15161 t.ralowerdiagonalbengali = 0x09f1; 15162 t.ramiddlediagonalbengali = 0x09f0; 15163 t.ramshorn = 0x0264; 15164 t.ratio = 0x2236; 15165 t.rbopomofo = 0x3116; 15166 t.rcaron = 0x0159; 15167 t.rcedilla = 0x0157; 15168 t.rcircle = 0x24e1; 15169 t.rcommaaccent = 0x0157; 15170 t.rdblgrave = 0x0211; 15171 t.rdotaccent = 0x1e59; 15172 t.rdotbelow = 0x1e5b; 15173 t.rdotbelowmacron = 0x1e5d; 15174 t.referencemark = 0x203b; 15175 t.reflexsubset = 0x2286; 15176 t.reflexsuperset = 0x2287; 15177 t.registered = 0x00ae; 15178 t.registersans = 0xf8e8; 15179 t.registerserif = 0xf6da; 15180 t.reharabic = 0x0631; 15181 t.reharmenian = 0x0580; 15182 t.rehfinalarabic = 0xfeae; 15183 t.rehiragana = 0x308c; 15184 t.rekatakana = 0x30ec; 15185 t.rekatakanahalfwidth = 0xff9a; 15186 t.resh = 0x05e8; 15187 t.reshdageshhebrew = 0xfb48; 15188 t.reshhebrew = 0x05e8; 15189 t.reversedtilde = 0x223d; 15190 t.reviahebrew = 0x0597; 15191 t.reviamugrashhebrew = 0x0597; 15192 t.revlogicalnot = 0x2310; 15193 t.rfishhook = 0x027e; 15194 t.rfishhookreversed = 0x027f; 15195 t.rhabengali = 0x09dd; 15196 t.rhadeva = 0x095d; 15197 t.rho = 0x03c1; 15198 t.rhook = 0x027d; 15199 t.rhookturned = 0x027b; 15200 t.rhookturnedsuperior = 0x02b5; 15201 t.rhosymbolgreek = 0x03f1; 15202 t.rhotichookmod = 0x02de; 15203 t.rieulacirclekorean = 0x3271; 15204 t.rieulaparenkorean = 0x3211; 15205 t.rieulcirclekorean = 0x3263; 15206 t.rieulhieuhkorean = 0x3140; 15207 t.rieulkiyeokkorean = 0x313a; 15208 t.rieulkiyeoksioskorean = 0x3169; 15209 t.rieulkorean = 0x3139; 15210 t.rieulmieumkorean = 0x313b; 15211 t.rieulpansioskorean = 0x316c; 15212 t.rieulparenkorean = 0x3203; 15213 t.rieulphieuphkorean = 0x313f; 15214 t.rieulpieupkorean = 0x313c; 15215 t.rieulpieupsioskorean = 0x316b; 15216 t.rieulsioskorean = 0x313d; 15217 t.rieulthieuthkorean = 0x313e; 15218 t.rieultikeutkorean = 0x316a; 15219 t.rieulyeorinhieuhkorean = 0x316d; 15220 t.rightangle = 0x221f; 15221 t.righttackbelowcmb = 0x0319; 15222 t.righttriangle = 0x22bf; 15223 t.rihiragana = 0x308a; 15224 t.rikatakana = 0x30ea; 15225 t.rikatakanahalfwidth = 0xff98; 15226 t.ring = 0x02da; 15227 t.ringbelowcmb = 0x0325; 15228 t.ringcmb = 0x030a; 15229 t.ringhalfleft = 0x02bf; 15230 t.ringhalfleftarmenian = 0x0559; 15231 t.ringhalfleftbelowcmb = 0x031c; 15232 t.ringhalfleftcentered = 0x02d3; 15233 t.ringhalfright = 0x02be; 15234 t.ringhalfrightbelowcmb = 0x0339; 15235 t.ringhalfrightcentered = 0x02d2; 15236 t.rinvertedbreve = 0x0213; 15237 t.rittorusquare = 0x3351; 15238 t.rlinebelow = 0x1e5f; 15239 t.rlongleg = 0x027c; 15240 t.rlonglegturned = 0x027a; 15241 t.rmonospace = 0xff52; 15242 t.rohiragana = 0x308d; 15243 t.rokatakana = 0x30ed; 15244 t.rokatakanahalfwidth = 0xff9b; 15245 t.roruathai = 0x0e23; 15246 t.rparen = 0x24ad; 15247 t.rrabengali = 0x09dc; 15248 t.rradeva = 0x0931; 15249 t.rragurmukhi = 0x0a5c; 15250 t.rreharabic = 0x0691; 15251 t.rrehfinalarabic = 0xfb8d; 15252 t.rrvocalicbengali = 0x09e0; 15253 t.rrvocalicdeva = 0x0960; 15254 t.rrvocalicgujarati = 0x0ae0; 15255 t.rrvocalicvowelsignbengali = 0x09c4; 15256 t.rrvocalicvowelsigndeva = 0x0944; 15257 t.rrvocalicvowelsigngujarati = 0x0ac4; 15258 t.rsuperior = 0xf6f1; 15259 t.rtblock = 0x2590; 15260 t.rturned = 0x0279; 15261 t.rturnedsuperior = 0x02b4; 15262 t.ruhiragana = 0x308b; 15263 t.rukatakana = 0x30eb; 15264 t.rukatakanahalfwidth = 0xff99; 15265 t.rupeemarkbengali = 0x09f2; 15266 t.rupeesignbengali = 0x09f3; 15267 t.rupiah = 0xf6dd; 15268 t.ruthai = 0x0e24; 15269 t.rvocalicbengali = 0x098b; 15270 t.rvocalicdeva = 0x090b; 15271 t.rvocalicgujarati = 0x0a8b; 15272 t.rvocalicvowelsignbengali = 0x09c3; 15273 t.rvocalicvowelsigndeva = 0x0943; 15274 t.rvocalicvowelsigngujarati = 0x0ac3; 15275 t.s = 0x0073; 15276 t.sabengali = 0x09b8; 15277 t.sacute = 0x015b; 15278 t.sacutedotaccent = 0x1e65; 15279 t.sadarabic = 0x0635; 15280 t.sadeva = 0x0938; 15281 t.sadfinalarabic = 0xfeba; 15282 t.sadinitialarabic = 0xfebb; 15283 t.sadmedialarabic = 0xfebc; 15284 t.sagujarati = 0x0ab8; 15285 t.sagurmukhi = 0x0a38; 15286 t.sahiragana = 0x3055; 15287 t.sakatakana = 0x30b5; 15288 t.sakatakanahalfwidth = 0xff7b; 15289 t.sallallahoualayhewasallamarabic = 0xfdfa; 15290 t.samekh = 0x05e1; 15291 t.samekhdagesh = 0xfb41; 15292 t.samekhdageshhebrew = 0xfb41; 15293 t.samekhhebrew = 0x05e1; 15294 t.saraaathai = 0x0e32; 15295 t.saraaethai = 0x0e41; 15296 t.saraaimaimalaithai = 0x0e44; 15297 t.saraaimaimuanthai = 0x0e43; 15298 t.saraamthai = 0x0e33; 15299 t.saraathai = 0x0e30; 15300 t.saraethai = 0x0e40; 15301 t.saraiileftthai = 0xf886; 15302 t.saraiithai = 0x0e35; 15303 t.saraileftthai = 0xf885; 15304 t.saraithai = 0x0e34; 15305 t.saraothai = 0x0e42; 15306 t.saraueeleftthai = 0xf888; 15307 t.saraueethai = 0x0e37; 15308 t.saraueleftthai = 0xf887; 15309 t.sarauethai = 0x0e36; 15310 t.sarauthai = 0x0e38; 15311 t.sarauuthai = 0x0e39; 15312 t.sbopomofo = 0x3119; 15313 t.scaron = 0x0161; 15314 t.scarondotaccent = 0x1e67; 15315 t.scedilla = 0x015f; 15316 t.schwa = 0x0259; 15317 t.schwacyrillic = 0x04d9; 15318 t.schwadieresiscyrillic = 0x04db; 15319 t.schwahook = 0x025a; 15320 t.scircle = 0x24e2; 15321 t.scircumflex = 0x015d; 15322 t.scommaaccent = 0x0219; 15323 t.sdotaccent = 0x1e61; 15324 t.sdotbelow = 0x1e63; 15325 t.sdotbelowdotaccent = 0x1e69; 15326 t.seagullbelowcmb = 0x033c; 15327 t.second = 0x2033; 15328 t.secondtonechinese = 0x02ca; 15329 t.section = 0x00a7; 15330 t.seenarabic = 0x0633; 15331 t.seenfinalarabic = 0xfeb2; 15332 t.seeninitialarabic = 0xfeb3; 15333 t.seenmedialarabic = 0xfeb4; 15334 t.segol = 0x05b6; 15335 t.segol13 = 0x05b6; 15336 t.segol1f = 0x05b6; 15337 t.segol2c = 0x05b6; 15338 t.segolhebrew = 0x05b6; 15339 t.segolnarrowhebrew = 0x05b6; 15340 t.segolquarterhebrew = 0x05b6; 15341 t.segoltahebrew = 0x0592; 15342 t.segolwidehebrew = 0x05b6; 15343 t.seharmenian = 0x057d; 15344 t.sehiragana = 0x305b; 15345 t.sekatakana = 0x30bb; 15346 t.sekatakanahalfwidth = 0xff7e; 15347 t.semicolon = 0x003b; 15348 t.semicolonarabic = 0x061b; 15349 t.semicolonmonospace = 0xff1b; 15350 t.semicolonsmall = 0xfe54; 15351 t.semivoicedmarkkana = 0x309c; 15352 t.semivoicedmarkkanahalfwidth = 0xff9f; 15353 t.sentisquare = 0x3322; 15354 t.sentosquare = 0x3323; 15355 t.seven = 0x0037; 15356 t.sevenarabic = 0x0667; 15357 t.sevenbengali = 0x09ed; 15358 t.sevencircle = 0x2466; 15359 t.sevencircleinversesansserif = 0x2790; 15360 t.sevendeva = 0x096d; 15361 t.seveneighths = 0x215e; 15362 t.sevengujarati = 0x0aed; 15363 t.sevengurmukhi = 0x0a6d; 15364 t.sevenhackarabic = 0x0667; 15365 t.sevenhangzhou = 0x3027; 15366 t.sevenideographicparen = 0x3226; 15367 t.seveninferior = 0x2087; 15368 t.sevenmonospace = 0xff17; 15369 t.sevenoldstyle = 0xf737; 15370 t.sevenparen = 0x247a; 15371 t.sevenperiod = 0x248e; 15372 t.sevenpersian = 0x06f7; 15373 t.sevenroman = 0x2176; 15374 t.sevensuperior = 0x2077; 15375 t.seventeencircle = 0x2470; 15376 t.seventeenparen = 0x2484; 15377 t.seventeenperiod = 0x2498; 15378 t.seventhai = 0x0e57; 15379 t.sfthyphen = 0x00ad; 15380 t.shaarmenian = 0x0577; 15381 t.shabengali = 0x09b6; 15382 t.shacyrillic = 0x0448; 15383 t.shaddaarabic = 0x0651; 15384 t.shaddadammaarabic = 0xfc61; 15385 t.shaddadammatanarabic = 0xfc5e; 15386 t.shaddafathaarabic = 0xfc60; 15387 t.shaddakasraarabic = 0xfc62; 15388 t.shaddakasratanarabic = 0xfc5f; 15389 t.shade = 0x2592; 15390 t.shadedark = 0x2593; 15391 t.shadelight = 0x2591; 15392 t.shademedium = 0x2592; 15393 t.shadeva = 0x0936; 15394 t.shagujarati = 0x0ab6; 15395 t.shagurmukhi = 0x0a36; 15396 t.shalshelethebrew = 0x0593; 15397 t.shbopomofo = 0x3115; 15398 t.shchacyrillic = 0x0449; 15399 t.sheenarabic = 0x0634; 15400 t.sheenfinalarabic = 0xfeb6; 15401 t.sheeninitialarabic = 0xfeb7; 15402 t.sheenmedialarabic = 0xfeb8; 15403 t.sheicoptic = 0x03e3; 15404 t.sheqel = 0x20aa; 15405 t.sheqelhebrew = 0x20aa; 15406 t.sheva = 0x05b0; 15407 t.sheva115 = 0x05b0; 15408 t.sheva15 = 0x05b0; 15409 t.sheva22 = 0x05b0; 15410 t.sheva2e = 0x05b0; 15411 t.shevahebrew = 0x05b0; 15412 t.shevanarrowhebrew = 0x05b0; 15413 t.shevaquarterhebrew = 0x05b0; 15414 t.shevawidehebrew = 0x05b0; 15415 t.shhacyrillic = 0x04bb; 15416 t.shimacoptic = 0x03ed; 15417 t.shin = 0x05e9; 15418 t.shindagesh = 0xfb49; 15419 t.shindageshhebrew = 0xfb49; 15420 t.shindageshshindot = 0xfb2c; 15421 t.shindageshshindothebrew = 0xfb2c; 15422 t.shindageshsindot = 0xfb2d; 15423 t.shindageshsindothebrew = 0xfb2d; 15424 t.shindothebrew = 0x05c1; 15425 t.shinhebrew = 0x05e9; 15426 t.shinshindot = 0xfb2a; 15427 t.shinshindothebrew = 0xfb2a; 15428 t.shinsindot = 0xfb2b; 15429 t.shinsindothebrew = 0xfb2b; 15430 t.shook = 0x0282; 15431 t.sigma = 0x03c3; 15432 t.sigma1 = 0x03c2; 15433 t.sigmafinal = 0x03c2; 15434 t.sigmalunatesymbolgreek = 0x03f2; 15435 t.sihiragana = 0x3057; 15436 t.sikatakana = 0x30b7; 15437 t.sikatakanahalfwidth = 0xff7c; 15438 t.siluqhebrew = 0x05bd; 15439 t.siluqlefthebrew = 0x05bd; 15440 t.similar = 0x223c; 15441 t.sindothebrew = 0x05c2; 15442 t.siosacirclekorean = 0x3274; 15443 t.siosaparenkorean = 0x3214; 15444 t.sioscieuckorean = 0x317e; 15445 t.sioscirclekorean = 0x3266; 15446 t.sioskiyeokkorean = 0x317a; 15447 t.sioskorean = 0x3145; 15448 t.siosnieunkorean = 0x317b; 15449 t.siosparenkorean = 0x3206; 15450 t.siospieupkorean = 0x317d; 15451 t.siostikeutkorean = 0x317c; 15452 t.six = 0x0036; 15453 t.sixarabic = 0x0666; 15454 t.sixbengali = 0x09ec; 15455 t.sixcircle = 0x2465; 15456 t.sixcircleinversesansserif = 0x278f; 15457 t.sixdeva = 0x096c; 15458 t.sixgujarati = 0x0aec; 15459 t.sixgurmukhi = 0x0a6c; 15460 t.sixhackarabic = 0x0666; 15461 t.sixhangzhou = 0x3026; 15462 t.sixideographicparen = 0x3225; 15463 t.sixinferior = 0x2086; 15464 t.sixmonospace = 0xff16; 15465 t.sixoldstyle = 0xf736; 15466 t.sixparen = 0x2479; 15467 t.sixperiod = 0x248d; 15468 t.sixpersian = 0x06f6; 15469 t.sixroman = 0x2175; 15470 t.sixsuperior = 0x2076; 15471 t.sixteencircle = 0x246f; 15472 t.sixteencurrencydenominatorbengali = 0x09f9; 15473 t.sixteenparen = 0x2483; 15474 t.sixteenperiod = 0x2497; 15475 t.sixthai = 0x0e56; 15476 t.slash = 0x002f; 15477 t.slashmonospace = 0xff0f; 15478 t.slong = 0x017f; 15479 t.slongdotaccent = 0x1e9b; 15480 t.smileface = 0x263a; 15481 t.smonospace = 0xff53; 15482 t.sofpasuqhebrew = 0x05c3; 15483 t.softhyphen = 0x00ad; 15484 t.softsigncyrillic = 0x044c; 15485 t.sohiragana = 0x305d; 15486 t.sokatakana = 0x30bd; 15487 t.sokatakanahalfwidth = 0xff7f; 15488 t.soliduslongoverlaycmb = 0x0338; 15489 t.solidusshortoverlaycmb = 0x0337; 15490 t.sorusithai = 0x0e29; 15491 t.sosalathai = 0x0e28; 15492 t.sosothai = 0x0e0b; 15493 t.sosuathai = 0x0e2a; 15494 t.space = 0x0020; 15495 t.spacehackarabic = 0x0020; 15496 t.spade = 0x2660; 15497 t.spadesuitblack = 0x2660; 15498 t.spadesuitwhite = 0x2664; 15499 t.sparen = 0x24ae; 15500 t.squarebelowcmb = 0x033b; 15501 t.squarecc = 0x33c4; 15502 t.squarecm = 0x339d; 15503 t.squarediagonalcrosshatchfill = 0x25a9; 15504 t.squarehorizontalfill = 0x25a4; 15505 t.squarekg = 0x338f; 15506 t.squarekm = 0x339e; 15507 t.squarekmcapital = 0x33ce; 15508 t.squareln = 0x33d1; 15509 t.squarelog = 0x33d2; 15510 t.squaremg = 0x338e; 15511 t.squaremil = 0x33d5; 15512 t.squaremm = 0x339c; 15513 t.squaremsquared = 0x33a1; 15514 t.squareorthogonalcrosshatchfill = 0x25a6; 15515 t.squareupperlefttolowerrightfill = 0x25a7; 15516 t.squareupperrighttolowerleftfill = 0x25a8; 15517 t.squareverticalfill = 0x25a5; 15518 t.squarewhitewithsmallblack = 0x25a3; 15519 t.srsquare = 0x33db; 15520 t.ssabengali = 0x09b7; 15521 t.ssadeva = 0x0937; 15522 t.ssagujarati = 0x0ab7; 15523 t.ssangcieuckorean = 0x3149; 15524 t.ssanghieuhkorean = 0x3185; 15525 t.ssangieungkorean = 0x3180; 15526 t.ssangkiyeokkorean = 0x3132; 15527 t.ssangnieunkorean = 0x3165; 15528 t.ssangpieupkorean = 0x3143; 15529 t.ssangsioskorean = 0x3146; 15530 t.ssangtikeutkorean = 0x3138; 15531 t.ssuperior = 0xf6f2; 15532 t.sterling = 0x00a3; 15533 t.sterlingmonospace = 0xffe1; 15534 t.strokelongoverlaycmb = 0x0336; 15535 t.strokeshortoverlaycmb = 0x0335; 15536 t.subset = 0x2282; 15537 t.subsetnotequal = 0x228a; 15538 t.subsetorequal = 0x2286; 15539 t.succeeds = 0x227b; 15540 t.suchthat = 0x220b; 15541 t.suhiragana = 0x3059; 15542 t.sukatakana = 0x30b9; 15543 t.sukatakanahalfwidth = 0xff7d; 15544 t.sukunarabic = 0x0652; 15545 t.summation = 0x2211; 15546 t.sun = 0x263c; 15547 t.superset = 0x2283; 15548 t.supersetnotequal = 0x228b; 15549 t.supersetorequal = 0x2287; 15550 t.svsquare = 0x33dc; 15551 t.syouwaerasquare = 0x337c; 15552 t.t = 0x0074; 15553 t.tabengali = 0x09a4; 15554 t.tackdown = 0x22a4; 15555 t.tackleft = 0x22a3; 15556 t.tadeva = 0x0924; 15557 t.tagujarati = 0x0aa4; 15558 t.tagurmukhi = 0x0a24; 15559 t.taharabic = 0x0637; 15560 t.tahfinalarabic = 0xfec2; 15561 t.tahinitialarabic = 0xfec3; 15562 t.tahiragana = 0x305f; 15563 t.tahmedialarabic = 0xfec4; 15564 t.taisyouerasquare = 0x337d; 15565 t.takatakana = 0x30bf; 15566 t.takatakanahalfwidth = 0xff80; 15567 t.tatweelarabic = 0x0640; 15568 t.tau = 0x03c4; 15569 t.tav = 0x05ea; 15570 t.tavdages = 0xfb4a; 15571 t.tavdagesh = 0xfb4a; 15572 t.tavdageshhebrew = 0xfb4a; 15573 t.tavhebrew = 0x05ea; 15574 t.tbar = 0x0167; 15575 t.tbopomofo = 0x310a; 15576 t.tcaron = 0x0165; 15577 t.tccurl = 0x02a8; 15578 t.tcedilla = 0x0163; 15579 t.tcheharabic = 0x0686; 15580 t.tchehfinalarabic = 0xfb7b; 15581 t.tchehinitialarabic = 0xfb7c; 15582 t.tchehmedialarabic = 0xfb7d; 15583 t.tcircle = 0x24e3; 15584 t.tcircumflexbelow = 0x1e71; 15585 t.tcommaaccent = 0x0163; 15586 t.tdieresis = 0x1e97; 15587 t.tdotaccent = 0x1e6b; 15588 t.tdotbelow = 0x1e6d; 15589 t.tecyrillic = 0x0442; 15590 t.tedescendercyrillic = 0x04ad; 15591 t.teharabic = 0x062a; 15592 t.tehfinalarabic = 0xfe96; 15593 t.tehhahinitialarabic = 0xfca2; 15594 t.tehhahisolatedarabic = 0xfc0c; 15595 t.tehinitialarabic = 0xfe97; 15596 t.tehiragana = 0x3066; 15597 t.tehjeeminitialarabic = 0xfca1; 15598 t.tehjeemisolatedarabic = 0xfc0b; 15599 t.tehmarbutaarabic = 0x0629; 15600 t.tehmarbutafinalarabic = 0xfe94; 15601 t.tehmedialarabic = 0xfe98; 15602 t.tehmeeminitialarabic = 0xfca4; 15603 t.tehmeemisolatedarabic = 0xfc0e; 15604 t.tehnoonfinalarabic = 0xfc73; 15605 t.tekatakana = 0x30c6; 15606 t.tekatakanahalfwidth = 0xff83; 15607 t.telephone = 0x2121; 15608 t.telephoneblack = 0x260e; 15609 t.telishagedolahebrew = 0x05a0; 15610 t.telishaqetanahebrew = 0x05a9; 15611 t.tencircle = 0x2469; 15612 t.tenideographicparen = 0x3229; 15613 t.tenparen = 0x247d; 15614 t.tenperiod = 0x2491; 15615 t.tenroman = 0x2179; 15616 t.tesh = 0x02a7; 15617 t.tet = 0x05d8; 15618 t.tetdagesh = 0xfb38; 15619 t.tetdageshhebrew = 0xfb38; 15620 t.tethebrew = 0x05d8; 15621 t.tetsecyrillic = 0x04b5; 15622 t.tevirhebrew = 0x059b; 15623 t.tevirlefthebrew = 0x059b; 15624 t.thabengali = 0x09a5; 15625 t.thadeva = 0x0925; 15626 t.thagujarati = 0x0aa5; 15627 t.thagurmukhi = 0x0a25; 15628 t.thalarabic = 0x0630; 15629 t.thalfinalarabic = 0xfeac; 15630 t.thanthakhatlowleftthai = 0xf898; 15631 t.thanthakhatlowrightthai = 0xf897; 15632 t.thanthakhatthai = 0x0e4c; 15633 t.thanthakhatupperleftthai = 0xf896; 15634 t.theharabic = 0x062b; 15635 t.thehfinalarabic = 0xfe9a; 15636 t.thehinitialarabic = 0xfe9b; 15637 t.thehmedialarabic = 0xfe9c; 15638 t.thereexists = 0x2203; 15639 t.therefore = 0x2234; 15640 t.theta = 0x03b8; 15641 t.theta1 = 0x03d1; 15642 t.thetasymbolgreek = 0x03d1; 15643 t.thieuthacirclekorean = 0x3279; 15644 t.thieuthaparenkorean = 0x3219; 15645 t.thieuthcirclekorean = 0x326b; 15646 t.thieuthkorean = 0x314c; 15647 t.thieuthparenkorean = 0x320b; 15648 t.thirteencircle = 0x246c; 15649 t.thirteenparen = 0x2480; 15650 t.thirteenperiod = 0x2494; 15651 t.thonangmonthothai = 0x0e11; 15652 t.thook = 0x01ad; 15653 t.thophuthaothai = 0x0e12; 15654 t.thorn = 0x00fe; 15655 t.thothahanthai = 0x0e17; 15656 t.thothanthai = 0x0e10; 15657 t.thothongthai = 0x0e18; 15658 t.thothungthai = 0x0e16; 15659 t.thousandcyrillic = 0x0482; 15660 t.thousandsseparatorarabic = 0x066c; 15661 t.thousandsseparatorpersian = 0x066c; 15662 t.three = 0x0033; 15663 t.threearabic = 0x0663; 15664 t.threebengali = 0x09e9; 15665 t.threecircle = 0x2462; 15666 t.threecircleinversesansserif = 0x278c; 15667 t.threedeva = 0x0969; 15668 t.threeeighths = 0x215c; 15669 t.threegujarati = 0x0ae9; 15670 t.threegurmukhi = 0x0a69; 15671 t.threehackarabic = 0x0663; 15672 t.threehangzhou = 0x3023; 15673 t.threeideographicparen = 0x3222; 15674 t.threeinferior = 0x2083; 15675 t.threemonospace = 0xff13; 15676 t.threenumeratorbengali = 0x09f6; 15677 t.threeoldstyle = 0xf733; 15678 t.threeparen = 0x2476; 15679 t.threeperiod = 0x248a; 15680 t.threepersian = 0x06f3; 15681 t.threequarters = 0x00be; 15682 t.threequartersemdash = 0xf6de; 15683 t.threeroman = 0x2172; 15684 t.threesuperior = 0x00b3; 15685 t.threethai = 0x0e53; 15686 t.thzsquare = 0x3394; 15687 t.tihiragana = 0x3061; 15688 t.tikatakana = 0x30c1; 15689 t.tikatakanahalfwidth = 0xff81; 15690 t.tikeutacirclekorean = 0x3270; 15691 t.tikeutaparenkorean = 0x3210; 15692 t.tikeutcirclekorean = 0x3262; 15693 t.tikeutkorean = 0x3137; 15694 t.tikeutparenkorean = 0x3202; 15695 t.tilde = 0x02dc; 15696 t.tildebelowcmb = 0x0330; 15697 t.tildecmb = 0x0303; 15698 t.tildecomb = 0x0303; 15699 t.tildedoublecmb = 0x0360; 15700 t.tildeoperator = 0x223c; 15701 t.tildeoverlaycmb = 0x0334; 15702 t.tildeverticalcmb = 0x033e; 15703 t.timescircle = 0x2297; 15704 t.tipehahebrew = 0x0596; 15705 t.tipehalefthebrew = 0x0596; 15706 t.tippigurmukhi = 0x0a70; 15707 t.titlocyrilliccmb = 0x0483; 15708 t.tiwnarmenian = 0x057f; 15709 t.tlinebelow = 0x1e6f; 15710 t.tmonospace = 0xff54; 15711 t.toarmenian = 0x0569; 15712 t.tohiragana = 0x3068; 15713 t.tokatakana = 0x30c8; 15714 t.tokatakanahalfwidth = 0xff84; 15715 t.tonebarextrahighmod = 0x02e5; 15716 t.tonebarextralowmod = 0x02e9; 15717 t.tonebarhighmod = 0x02e6; 15718 t.tonebarlowmod = 0x02e8; 15719 t.tonebarmidmod = 0x02e7; 15720 t.tonefive = 0x01bd; 15721 t.tonesix = 0x0185; 15722 t.tonetwo = 0x01a8; 15723 t.tonos = 0x0384; 15724 t.tonsquare = 0x3327; 15725 t.topatakthai = 0x0e0f; 15726 t.tortoiseshellbracketleft = 0x3014; 15727 t.tortoiseshellbracketleftsmall = 0xfe5d; 15728 t.tortoiseshellbracketleftvertical = 0xfe39; 15729 t.tortoiseshellbracketright = 0x3015; 15730 t.tortoiseshellbracketrightsmall = 0xfe5e; 15731 t.tortoiseshellbracketrightvertical = 0xfe3a; 15732 t.totaothai = 0x0e15; 15733 t.tpalatalhook = 0x01ab; 15734 t.tparen = 0x24af; 15735 t.trademark = 0x2122; 15736 t.trademarksans = 0xf8ea; 15737 t.trademarkserif = 0xf6db; 15738 t.tretroflexhook = 0x0288; 15739 t.triagdn = 0x25bc; 15740 t.triaglf = 0x25c4; 15741 t.triagrt = 0x25ba; 15742 t.triagup = 0x25b2; 15743 t.ts = 0x02a6; 15744 t.tsadi = 0x05e6; 15745 t.tsadidagesh = 0xfb46; 15746 t.tsadidageshhebrew = 0xfb46; 15747 t.tsadihebrew = 0x05e6; 15748 t.tsecyrillic = 0x0446; 15749 t.tsere = 0x05b5; 15750 t.tsere12 = 0x05b5; 15751 t.tsere1e = 0x05b5; 15752 t.tsere2b = 0x05b5; 15753 t.tserehebrew = 0x05b5; 15754 t.tserenarrowhebrew = 0x05b5; 15755 t.tserequarterhebrew = 0x05b5; 15756 t.tserewidehebrew = 0x05b5; 15757 t.tshecyrillic = 0x045b; 15758 t.tsuperior = 0xf6f3; 15759 t.ttabengali = 0x099f; 15760 t.ttadeva = 0x091f; 15761 t.ttagujarati = 0x0a9f; 15762 t.ttagurmukhi = 0x0a1f; 15763 t.tteharabic = 0x0679; 15764 t.ttehfinalarabic = 0xfb67; 15765 t.ttehinitialarabic = 0xfb68; 15766 t.ttehmedialarabic = 0xfb69; 15767 t.tthabengali = 0x09a0; 15768 t.tthadeva = 0x0920; 15769 t.tthagujarati = 0x0aa0; 15770 t.tthagurmukhi = 0x0a20; 15771 t.tturned = 0x0287; 15772 t.tuhiragana = 0x3064; 15773 t.tukatakana = 0x30c4; 15774 t.tukatakanahalfwidth = 0xff82; 15775 t.tusmallhiragana = 0x3063; 15776 t.tusmallkatakana = 0x30c3; 15777 t.tusmallkatakanahalfwidth = 0xff6f; 15778 t.twelvecircle = 0x246b; 15779 t.twelveparen = 0x247f; 15780 t.twelveperiod = 0x2493; 15781 t.twelveroman = 0x217b; 15782 t.twentycircle = 0x2473; 15783 t.twentyhangzhou = 0x5344; 15784 t.twentyparen = 0x2487; 15785 t.twentyperiod = 0x249b; 15786 t.two = 0x0032; 15787 t.twoarabic = 0x0662; 15788 t.twobengali = 0x09e8; 15789 t.twocircle = 0x2461; 15790 t.twocircleinversesansserif = 0x278b; 15791 t.twodeva = 0x0968; 15792 t.twodotenleader = 0x2025; 15793 t.twodotleader = 0x2025; 15794 t.twodotleadervertical = 0xfe30; 15795 t.twogujarati = 0x0ae8; 15796 t.twogurmukhi = 0x0a68; 15797 t.twohackarabic = 0x0662; 15798 t.twohangzhou = 0x3022; 15799 t.twoideographicparen = 0x3221; 15800 t.twoinferior = 0x2082; 15801 t.twomonospace = 0xff12; 15802 t.twonumeratorbengali = 0x09f5; 15803 t.twooldstyle = 0xf732; 15804 t.twoparen = 0x2475; 15805 t.twoperiod = 0x2489; 15806 t.twopersian = 0x06f2; 15807 t.tworoman = 0x2171; 15808 t.twostroke = 0x01bb; 15809 t.twosuperior = 0x00b2; 15810 t.twothai = 0x0e52; 15811 t.twothirds = 0x2154; 15812 t.u = 0x0075; 15813 t.uacute = 0x00fa; 15814 t.ubar = 0x0289; 15815 t.ubengali = 0x0989; 15816 t.ubopomofo = 0x3128; 15817 t.ubreve = 0x016d; 15818 t.ucaron = 0x01d4; 15819 t.ucircle = 0x24e4; 15820 t.ucircumflex = 0x00fb; 15821 t.ucircumflexbelow = 0x1e77; 15822 t.ucyrillic = 0x0443; 15823 t.udattadeva = 0x0951; 15824 t.udblacute = 0x0171; 15825 t.udblgrave = 0x0215; 15826 t.udeva = 0x0909; 15827 t.udieresis = 0x00fc; 15828 t.udieresisacute = 0x01d8; 15829 t.udieresisbelow = 0x1e73; 15830 t.udieresiscaron = 0x01da; 15831 t.udieresiscyrillic = 0x04f1; 15832 t.udieresisgrave = 0x01dc; 15833 t.udieresismacron = 0x01d6; 15834 t.udotbelow = 0x1ee5; 15835 t.ugrave = 0x00f9; 15836 t.ugujarati = 0x0a89; 15837 t.ugurmukhi = 0x0a09; 15838 t.uhiragana = 0x3046; 15839 t.uhookabove = 0x1ee7; 15840 t.uhorn = 0x01b0; 15841 t.uhornacute = 0x1ee9; 15842 t.uhorndotbelow = 0x1ef1; 15843 t.uhorngrave = 0x1eeb; 15844 t.uhornhookabove = 0x1eed; 15845 t.uhorntilde = 0x1eef; 15846 t.uhungarumlaut = 0x0171; 15847 t.uhungarumlautcyrillic = 0x04f3; 15848 t.uinvertedbreve = 0x0217; 15849 t.ukatakana = 0x30a6; 15850 t.ukatakanahalfwidth = 0xff73; 15851 t.ukcyrillic = 0x0479; 15852 t.ukorean = 0x315c; 15853 t.umacron = 0x016b; 15854 t.umacroncyrillic = 0x04ef; 15855 t.umacrondieresis = 0x1e7b; 15856 t.umatragurmukhi = 0x0a41; 15857 t.umonospace = 0xff55; 15858 t.underscore = 0x005f; 15859 t.underscoredbl = 0x2017; 15860 t.underscoremonospace = 0xff3f; 15861 t.underscorevertical = 0xfe33; 15862 t.underscorewavy = 0xfe4f; 15863 t.union = 0x222a; 15864 t.universal = 0x2200; 15865 t.uogonek = 0x0173; 15866 t.uparen = 0x24b0; 15867 t.upblock = 0x2580; 15868 t.upperdothebrew = 0x05c4; 15869 t.upsilon = 0x03c5; 15870 t.upsilondieresis = 0x03cb; 15871 t.upsilondieresistonos = 0x03b0; 15872 t.upsilonlatin = 0x028a; 15873 t.upsilontonos = 0x03cd; 15874 t.uptackbelowcmb = 0x031d; 15875 t.uptackmod = 0x02d4; 15876 t.uragurmukhi = 0x0a73; 15877 t.uring = 0x016f; 15878 t.ushortcyrillic = 0x045e; 15879 t.usmallhiragana = 0x3045; 15880 t.usmallkatakana = 0x30a5; 15881 t.usmallkatakanahalfwidth = 0xff69; 15882 t.ustraightcyrillic = 0x04af; 15883 t.ustraightstrokecyrillic = 0x04b1; 15884 t.utilde = 0x0169; 15885 t.utildeacute = 0x1e79; 15886 t.utildebelow = 0x1e75; 15887 t.uubengali = 0x098a; 15888 t.uudeva = 0x090a; 15889 t.uugujarati = 0x0a8a; 15890 t.uugurmukhi = 0x0a0a; 15891 t.uumatragurmukhi = 0x0a42; 15892 t.uuvowelsignbengali = 0x09c2; 15893 t.uuvowelsigndeva = 0x0942; 15894 t.uuvowelsigngujarati = 0x0ac2; 15895 t.uvowelsignbengali = 0x09c1; 15896 t.uvowelsigndeva = 0x0941; 15897 t.uvowelsigngujarati = 0x0ac1; 15898 t.v = 0x0076; 15899 t.vadeva = 0x0935; 15900 t.vagujarati = 0x0ab5; 15901 t.vagurmukhi = 0x0a35; 15902 t.vakatakana = 0x30f7; 15903 t.vav = 0x05d5; 15904 t.vavdagesh = 0xfb35; 15905 t.vavdagesh65 = 0xfb35; 15906 t.vavdageshhebrew = 0xfb35; 15907 t.vavhebrew = 0x05d5; 15908 t.vavholam = 0xfb4b; 15909 t.vavholamhebrew = 0xfb4b; 15910 t.vavvavhebrew = 0x05f0; 15911 t.vavyodhebrew = 0x05f1; 15912 t.vcircle = 0x24e5; 15913 t.vdotbelow = 0x1e7f; 15914 t.vecyrillic = 0x0432; 15915 t.veharabic = 0x06a4; 15916 t.vehfinalarabic = 0xfb6b; 15917 t.vehinitialarabic = 0xfb6c; 15918 t.vehmedialarabic = 0xfb6d; 15919 t.vekatakana = 0x30f9; 15920 t.venus = 0x2640; 15921 t.verticalbar = 0x007c; 15922 t.verticallineabovecmb = 0x030d; 15923 t.verticallinebelowcmb = 0x0329; 15924 t.verticallinelowmod = 0x02cc; 15925 t.verticallinemod = 0x02c8; 15926 t.vewarmenian = 0x057e; 15927 t.vhook = 0x028b; 15928 t.vikatakana = 0x30f8; 15929 t.viramabengali = 0x09cd; 15930 t.viramadeva = 0x094d; 15931 t.viramagujarati = 0x0acd; 15932 t.visargabengali = 0x0983; 15933 t.visargadeva = 0x0903; 15934 t.visargagujarati = 0x0a83; 15935 t.vmonospace = 0xff56; 15936 t.voarmenian = 0x0578; 15937 t.voicediterationhiragana = 0x309e; 15938 t.voicediterationkatakana = 0x30fe; 15939 t.voicedmarkkana = 0x309b; 15940 t.voicedmarkkanahalfwidth = 0xff9e; 15941 t.vokatakana = 0x30fa; 15942 t.vparen = 0x24b1; 15943 t.vtilde = 0x1e7d; 15944 t.vturned = 0x028c; 15945 t.vuhiragana = 0x3094; 15946 t.vukatakana = 0x30f4; 15947 t.w = 0x0077; 15948 t.wacute = 0x1e83; 15949 t.waekorean = 0x3159; 15950 t.wahiragana = 0x308f; 15951 t.wakatakana = 0x30ef; 15952 t.wakatakanahalfwidth = 0xff9c; 15953 t.wakorean = 0x3158; 15954 t.wasmallhiragana = 0x308e; 15955 t.wasmallkatakana = 0x30ee; 15956 t.wattosquare = 0x3357; 15957 t.wavedash = 0x301c; 15958 t.wavyunderscorevertical = 0xfe34; 15959 t.wawarabic = 0x0648; 15960 t.wawfinalarabic = 0xfeee; 15961 t.wawhamzaabovearabic = 0x0624; 15962 t.wawhamzaabovefinalarabic = 0xfe86; 15963 t.wbsquare = 0x33dd; 15964 t.wcircle = 0x24e6; 15965 t.wcircumflex = 0x0175; 15966 t.wdieresis = 0x1e85; 15967 t.wdotaccent = 0x1e87; 15968 t.wdotbelow = 0x1e89; 15969 t.wehiragana = 0x3091; 15970 t.weierstrass = 0x2118; 15971 t.wekatakana = 0x30f1; 15972 t.wekorean = 0x315e; 15973 t.weokorean = 0x315d; 15974 t.wgrave = 0x1e81; 15975 t.whitebullet = 0x25e6; 15976 t.whitecircle = 0x25cb; 15977 t.whitecircleinverse = 0x25d9; 15978 t.whitecornerbracketleft = 0x300e; 15979 t.whitecornerbracketleftvertical = 0xfe43; 15980 t.whitecornerbracketright = 0x300f; 15981 t.whitecornerbracketrightvertical = 0xfe44; 15982 t.whitediamond = 0x25c7; 15983 t.whitediamondcontainingblacksmalldiamond = 0x25c8; 15984 t.whitedownpointingsmalltriangle = 0x25bf; 15985 t.whitedownpointingtriangle = 0x25bd; 15986 t.whiteleftpointingsmalltriangle = 0x25c3; 15987 t.whiteleftpointingtriangle = 0x25c1; 15988 t.whitelenticularbracketleft = 0x3016; 15989 t.whitelenticularbracketright = 0x3017; 15990 t.whiterightpointingsmalltriangle = 0x25b9; 15991 t.whiterightpointingtriangle = 0x25b7; 15992 t.whitesmallsquare = 0x25ab; 15993 t.whitesmilingface = 0x263a; 15994 t.whitesquare = 0x25a1; 15995 t.whitestar = 0x2606; 15996 t.whitetelephone = 0x260f; 15997 t.whitetortoiseshellbracketleft = 0x3018; 15998 t.whitetortoiseshellbracketright = 0x3019; 15999 t.whiteuppointingsmalltriangle = 0x25b5; 16000 t.whiteuppointingtriangle = 0x25b3; 16001 t.wihiragana = 0x3090; 16002 t.wikatakana = 0x30f0; 16003 t.wikorean = 0x315f; 16004 t.wmonospace = 0xff57; 16005 t.wohiragana = 0x3092; 16006 t.wokatakana = 0x30f2; 16007 t.wokatakanahalfwidth = 0xff66; 16008 t.won = 0x20a9; 16009 t.wonmonospace = 0xffe6; 16010 t.wowaenthai = 0x0e27; 16011 t.wparen = 0x24b2; 16012 t.wring = 0x1e98; 16013 t.wsuperior = 0x02b7; 16014 t.wturned = 0x028d; 16015 t.wynn = 0x01bf; 16016 t.x = 0x0078; 16017 t.xabovecmb = 0x033d; 16018 t.xbopomofo = 0x3112; 16019 t.xcircle = 0x24e7; 16020 t.xdieresis = 0x1e8d; 16021 t.xdotaccent = 0x1e8b; 16022 t.xeharmenian = 0x056d; 16023 t.xi = 0x03be; 16024 t.xmonospace = 0xff58; 16025 t.xparen = 0x24b3; 16026 t.xsuperior = 0x02e3; 16027 t.y = 0x0079; 16028 t.yaadosquare = 0x334e; 16029 t.yabengali = 0x09af; 16030 t.yacute = 0x00fd; 16031 t.yadeva = 0x092f; 16032 t.yaekorean = 0x3152; 16033 t.yagujarati = 0x0aaf; 16034 t.yagurmukhi = 0x0a2f; 16035 t.yahiragana = 0x3084; 16036 t.yakatakana = 0x30e4; 16037 t.yakatakanahalfwidth = 0xff94; 16038 t.yakorean = 0x3151; 16039 t.yamakkanthai = 0x0e4e; 16040 t.yasmallhiragana = 0x3083; 16041 t.yasmallkatakana = 0x30e3; 16042 t.yasmallkatakanahalfwidth = 0xff6c; 16043 t.yatcyrillic = 0x0463; 16044 t.ycircle = 0x24e8; 16045 t.ycircumflex = 0x0177; 16046 t.ydieresis = 0x00ff; 16047 t.ydotaccent = 0x1e8f; 16048 t.ydotbelow = 0x1ef5; 16049 t.yeharabic = 0x064a; 16050 t.yehbarreearabic = 0x06d2; 16051 t.yehbarreefinalarabic = 0xfbaf; 16052 t.yehfinalarabic = 0xfef2; 16053 t.yehhamzaabovearabic = 0x0626; 16054 t.yehhamzaabovefinalarabic = 0xfe8a; 16055 t.yehhamzaaboveinitialarabic = 0xfe8b; 16056 t.yehhamzaabovemedialarabic = 0xfe8c; 16057 t.yehinitialarabic = 0xfef3; 16058 t.yehmedialarabic = 0xfef4; 16059 t.yehmeeminitialarabic = 0xfcdd; 16060 t.yehmeemisolatedarabic = 0xfc58; 16061 t.yehnoonfinalarabic = 0xfc94; 16062 t.yehthreedotsbelowarabic = 0x06d1; 16063 t.yekorean = 0x3156; 16064 t.yen = 0x00a5; 16065 t.yenmonospace = 0xffe5; 16066 t.yeokorean = 0x3155; 16067 t.yeorinhieuhkorean = 0x3186; 16068 t.yerahbenyomohebrew = 0x05aa; 16069 t.yerahbenyomolefthebrew = 0x05aa; 16070 t.yericyrillic = 0x044b; 16071 t.yerudieresiscyrillic = 0x04f9; 16072 t.yesieungkorean = 0x3181; 16073 t.yesieungpansioskorean = 0x3183; 16074 t.yesieungsioskorean = 0x3182; 16075 t.yetivhebrew = 0x059a; 16076 t.ygrave = 0x1ef3; 16077 t.yhook = 0x01b4; 16078 t.yhookabove = 0x1ef7; 16079 t.yiarmenian = 0x0575; 16080 t.yicyrillic = 0x0457; 16081 t.yikorean = 0x3162; 16082 t.yinyang = 0x262f; 16083 t.yiwnarmenian = 0x0582; 16084 t.ymonospace = 0xff59; 16085 t.yod = 0x05d9; 16086 t.yoddagesh = 0xfb39; 16087 t.yoddageshhebrew = 0xfb39; 16088 t.yodhebrew = 0x05d9; 16089 t.yodyodhebrew = 0x05f2; 16090 t.yodyodpatahhebrew = 0xfb1f; 16091 t.yohiragana = 0x3088; 16092 t.yoikorean = 0x3189; 16093 t.yokatakana = 0x30e8; 16094 t.yokatakanahalfwidth = 0xff96; 16095 t.yokorean = 0x315b; 16096 t.yosmallhiragana = 0x3087; 16097 t.yosmallkatakana = 0x30e7; 16098 t.yosmallkatakanahalfwidth = 0xff6e; 16099 t.yotgreek = 0x03f3; 16100 t.yoyaekorean = 0x3188; 16101 t.yoyakorean = 0x3187; 16102 t.yoyakthai = 0x0e22; 16103 t.yoyingthai = 0x0e0d; 16104 t.yparen = 0x24b4; 16105 t.ypogegrammeni = 0x037a; 16106 t.ypogegrammenigreekcmb = 0x0345; 16107 t.yr = 0x01a6; 16108 t.yring = 0x1e99; 16109 t.ysuperior = 0x02b8; 16110 t.ytilde = 0x1ef9; 16111 t.yturned = 0x028e; 16112 t.yuhiragana = 0x3086; 16113 t.yuikorean = 0x318c; 16114 t.yukatakana = 0x30e6; 16115 t.yukatakanahalfwidth = 0xff95; 16116 t.yukorean = 0x3160; 16117 t.yusbigcyrillic = 0x046b; 16118 t.yusbigiotifiedcyrillic = 0x046d; 16119 t.yuslittlecyrillic = 0x0467; 16120 t.yuslittleiotifiedcyrillic = 0x0469; 16121 t.yusmallhiragana = 0x3085; 16122 t.yusmallkatakana = 0x30e5; 16123 t.yusmallkatakanahalfwidth = 0xff6d; 16124 t.yuyekorean = 0x318b; 16125 t.yuyeokorean = 0x318a; 16126 t.yyabengali = 0x09df; 16127 t.yyadeva = 0x095f; 16128 t.z = 0x007a; 16129 t.zaarmenian = 0x0566; 16130 t.zacute = 0x017a; 16131 t.zadeva = 0x095b; 16132 t.zagurmukhi = 0x0a5b; 16133 t.zaharabic = 0x0638; 16134 t.zahfinalarabic = 0xfec6; 16135 t.zahinitialarabic = 0xfec7; 16136 t.zahiragana = 0x3056; 16137 t.zahmedialarabic = 0xfec8; 16138 t.zainarabic = 0x0632; 16139 t.zainfinalarabic = 0xfeb0; 16140 t.zakatakana = 0x30b6; 16141 t.zaqefgadolhebrew = 0x0595; 16142 t.zaqefqatanhebrew = 0x0594; 16143 t.zarqahebrew = 0x0598; 16144 t.zayin = 0x05d6; 16145 t.zayindagesh = 0xfb36; 16146 t.zayindageshhebrew = 0xfb36; 16147 t.zayinhebrew = 0x05d6; 16148 t.zbopomofo = 0x3117; 16149 t.zcaron = 0x017e; 16150 t.zcircle = 0x24e9; 16151 t.zcircumflex = 0x1e91; 16152 t.zcurl = 0x0291; 16153 t.zdot = 0x017c; 16154 t.zdotaccent = 0x017c; 16155 t.zdotbelow = 0x1e93; 16156 t.zecyrillic = 0x0437; 16157 t.zedescendercyrillic = 0x0499; 16158 t.zedieresiscyrillic = 0x04df; 16159 t.zehiragana = 0x305c; 16160 t.zekatakana = 0x30bc; 16161 t.zero = 0x0030; 16162 t.zeroarabic = 0x0660; 16163 t.zerobengali = 0x09e6; 16164 t.zerodeva = 0x0966; 16165 t.zerogujarati = 0x0ae6; 16166 t.zerogurmukhi = 0x0a66; 16167 t.zerohackarabic = 0x0660; 16168 t.zeroinferior = 0x2080; 16169 t.zeromonospace = 0xff10; 16170 t.zerooldstyle = 0xf730; 16171 t.zeropersian = 0x06f0; 16172 t.zerosuperior = 0x2070; 16173 t.zerothai = 0x0e50; 16174 t.zerowidthjoiner = 0xfeff; 16175 t.zerowidthnonjoiner = 0x200c; 16176 t.zerowidthspace = 0x200b; 16177 t.zeta = 0x03b6; 16178 t.zhbopomofo = 0x3113; 16179 t.zhearmenian = 0x056a; 16180 t.zhebrevecyrillic = 0x04c2; 16181 t.zhecyrillic = 0x0436; 16182 t.zhedescendercyrillic = 0x0497; 16183 t.zhedieresiscyrillic = 0x04dd; 16184 t.zihiragana = 0x3058; 16185 t.zikatakana = 0x30b8; 16186 t.zinorhebrew = 0x05ae; 16187 t.zlinebelow = 0x1e95; 16188 t.zmonospace = 0xff5a; 16189 t.zohiragana = 0x305e; 16190 t.zokatakana = 0x30be; 16191 t.zparen = 0x24b5; 16192 t.zretroflexhook = 0x0290; 16193 t.zstroke = 0x01b6; 16194 t.zuhiragana = 0x305a; 16195 t.zukatakana = 0x30ba; 16196 t[".notdef"] = 0x0000; 16197 t.angbracketleftbig = 0x2329; 16198 t.angbracketleftBig = 0x2329; 16199 t.angbracketleftbigg = 0x2329; 16200 t.angbracketleftBigg = 0x2329; 16201 t.angbracketrightBig = 0x232a; 16202 t.angbracketrightbig = 0x232a; 16203 t.angbracketrightBigg = 0x232a; 16204 t.angbracketrightbigg = 0x232a; 16205 t.arrowhookleft = 0x21aa; 16206 t.arrowhookright = 0x21a9; 16207 t.arrowlefttophalf = 0x21bc; 16208 t.arrowleftbothalf = 0x21bd; 16209 t.arrownortheast = 0x2197; 16210 t.arrownorthwest = 0x2196; 16211 t.arrowrighttophalf = 0x21c0; 16212 t.arrowrightbothalf = 0x21c1; 16213 t.arrowsoutheast = 0x2198; 16214 t.arrowsouthwest = 0x2199; 16215 t.backslashbig = 0x2216; 16216 t.backslashBig = 0x2216; 16217 t.backslashBigg = 0x2216; 16218 t.backslashbigg = 0x2216; 16219 t.bardbl = 0x2016; 16220 t.bracehtipdownleft = 0xfe37; 16221 t.bracehtipdownright = 0xfe37; 16222 t.bracehtipupleft = 0xfe38; 16223 t.bracehtipupright = 0xfe38; 16224 t.braceleftBig = 0x007b; 16225 t.braceleftbig = 0x007b; 16226 t.braceleftbigg = 0x007b; 16227 t.braceleftBigg = 0x007b; 16228 t.bracerightBig = 0x007d; 16229 t.bracerightbig = 0x007d; 16230 t.bracerightbigg = 0x007d; 16231 t.bracerightBigg = 0x007d; 16232 t.bracketleftbig = 0x005b; 16233 t.bracketleftBig = 0x005b; 16234 t.bracketleftbigg = 0x005b; 16235 t.bracketleftBigg = 0x005b; 16236 t.bracketrightBig = 0x005d; 16237 t.bracketrightbig = 0x005d; 16238 t.bracketrightbigg = 0x005d; 16239 t.bracketrightBigg = 0x005d; 16240 t.ceilingleftbig = 0x2308; 16241 t.ceilingleftBig = 0x2308; 16242 t.ceilingleftBigg = 0x2308; 16243 t.ceilingleftbigg = 0x2308; 16244 t.ceilingrightbig = 0x2309; 16245 t.ceilingrightBig = 0x2309; 16246 t.ceilingrightbigg = 0x2309; 16247 t.ceilingrightBigg = 0x2309; 16248 t.circledotdisplay = 0x2299; 16249 t.circledottext = 0x2299; 16250 t.circlemultiplydisplay = 0x2297; 16251 t.circlemultiplytext = 0x2297; 16252 t.circleplusdisplay = 0x2295; 16253 t.circleplustext = 0x2295; 16254 t.contintegraldisplay = 0x222e; 16255 t.contintegraltext = 0x222e; 16256 t.coproductdisplay = 0x2210; 16257 t.coproducttext = 0x2210; 16258 t.floorleftBig = 0x230a; 16259 t.floorleftbig = 0x230a; 16260 t.floorleftbigg = 0x230a; 16261 t.floorleftBigg = 0x230a; 16262 t.floorrightbig = 0x230b; 16263 t.floorrightBig = 0x230b; 16264 t.floorrightBigg = 0x230b; 16265 t.floorrightbigg = 0x230b; 16266 t.hatwide = 0x0302; 16267 t.hatwider = 0x0302; 16268 t.hatwidest = 0x0302; 16269 t.intercal = 0x1d40; 16270 t.integraldisplay = 0x222b; 16271 t.integraltext = 0x222b; 16272 t.intersectiondisplay = 0x22c2; 16273 t.intersectiontext = 0x22c2; 16274 t.logicalanddisplay = 0x2227; 16275 t.logicalandtext = 0x2227; 16276 t.logicalordisplay = 0x2228; 16277 t.logicalortext = 0x2228; 16278 t.parenleftBig = 0x0028; 16279 t.parenleftbig = 0x0028; 16280 t.parenleftBigg = 0x0028; 16281 t.parenleftbigg = 0x0028; 16282 t.parenrightBig = 0x0029; 16283 t.parenrightbig = 0x0029; 16284 t.parenrightBigg = 0x0029; 16285 t.parenrightbigg = 0x0029; 16286 t.prime = 0x2032; 16287 t.productdisplay = 0x220f; 16288 t.producttext = 0x220f; 16289 t.radicalbig = 0x221a; 16290 t.radicalBig = 0x221a; 16291 t.radicalBigg = 0x221a; 16292 t.radicalbigg = 0x221a; 16293 t.radicalbt = 0x221a; 16294 t.radicaltp = 0x221a; 16295 t.radicalvertex = 0x221a; 16296 t.slashbig = 0x002f; 16297 t.slashBig = 0x002f; 16298 t.slashBigg = 0x002f; 16299 t.slashbigg = 0x002f; 16300 t.summationdisplay = 0x2211; 16301 t.summationtext = 0x2211; 16302 t.tildewide = 0x02dc; 16303 t.tildewider = 0x02dc; 16304 t.tildewidest = 0x02dc; 16305 t.uniondisplay = 0x22c3; 16306 t.unionmultidisplay = 0x228e; 16307 t.unionmultitext = 0x228e; 16308 t.unionsqdisplay = 0x2294; 16309 t.unionsqtext = 0x2294; 16310 t.uniontext = 0x22c3; 16311 t.vextenddouble = 0x2225; 16312 t.vextendsingle = 0x2223; 16313}); 16314const getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) { 16315 t.space = 0x0020; 16316 t.a1 = 0x2701; 16317 t.a2 = 0x2702; 16318 t.a202 = 0x2703; 16319 t.a3 = 0x2704; 16320 t.a4 = 0x260e; 16321 t.a5 = 0x2706; 16322 t.a119 = 0x2707; 16323 t.a118 = 0x2708; 16324 t.a117 = 0x2709; 16325 t.a11 = 0x261b; 16326 t.a12 = 0x261e; 16327 t.a13 = 0x270c; 16328 t.a14 = 0x270d; 16329 t.a15 = 0x270e; 16330 t.a16 = 0x270f; 16331 t.a105 = 0x2710; 16332 t.a17 = 0x2711; 16333 t.a18 = 0x2712; 16334 t.a19 = 0x2713; 16335 t.a20 = 0x2714; 16336 t.a21 = 0x2715; 16337 t.a22 = 0x2716; 16338 t.a23 = 0x2717; 16339 t.a24 = 0x2718; 16340 t.a25 = 0x2719; 16341 t.a26 = 0x271a; 16342 t.a27 = 0x271b; 16343 t.a28 = 0x271c; 16344 t.a6 = 0x271d; 16345 t.a7 = 0x271e; 16346 t.a8 = 0x271f; 16347 t.a9 = 0x2720; 16348 t.a10 = 0x2721; 16349 t.a29 = 0x2722; 16350 t.a30 = 0x2723; 16351 t.a31 = 0x2724; 16352 t.a32 = 0x2725; 16353 t.a33 = 0x2726; 16354 t.a34 = 0x2727; 16355 t.a35 = 0x2605; 16356 t.a36 = 0x2729; 16357 t.a37 = 0x272a; 16358 t.a38 = 0x272b; 16359 t.a39 = 0x272c; 16360 t.a40 = 0x272d; 16361 t.a41 = 0x272e; 16362 t.a42 = 0x272f; 16363 t.a43 = 0x2730; 16364 t.a44 = 0x2731; 16365 t.a45 = 0x2732; 16366 t.a46 = 0x2733; 16367 t.a47 = 0x2734; 16368 t.a48 = 0x2735; 16369 t.a49 = 0x2736; 16370 t.a50 = 0x2737; 16371 t.a51 = 0x2738; 16372 t.a52 = 0x2739; 16373 t.a53 = 0x273a; 16374 t.a54 = 0x273b; 16375 t.a55 = 0x273c; 16376 t.a56 = 0x273d; 16377 t.a57 = 0x273e; 16378 t.a58 = 0x273f; 16379 t.a59 = 0x2740; 16380 t.a60 = 0x2741; 16381 t.a61 = 0x2742; 16382 t.a62 = 0x2743; 16383 t.a63 = 0x2744; 16384 t.a64 = 0x2745; 16385 t.a65 = 0x2746; 16386 t.a66 = 0x2747; 16387 t.a67 = 0x2748; 16388 t.a68 = 0x2749; 16389 t.a69 = 0x274a; 16390 t.a70 = 0x274b; 16391 t.a71 = 0x25cf; 16392 t.a72 = 0x274d; 16393 t.a73 = 0x25a0; 16394 t.a74 = 0x274f; 16395 t.a203 = 0x2750; 16396 t.a75 = 0x2751; 16397 t.a204 = 0x2752; 16398 t.a76 = 0x25b2; 16399 t.a77 = 0x25bc; 16400 t.a78 = 0x25c6; 16401 t.a79 = 0x2756; 16402 t.a81 = 0x25d7; 16403 t.a82 = 0x2758; 16404 t.a83 = 0x2759; 16405 t.a84 = 0x275a; 16406 t.a97 = 0x275b; 16407 t.a98 = 0x275c; 16408 t.a99 = 0x275d; 16409 t.a100 = 0x275e; 16410 t.a101 = 0x2761; 16411 t.a102 = 0x2762; 16412 t.a103 = 0x2763; 16413 t.a104 = 0x2764; 16414 t.a106 = 0x2765; 16415 t.a107 = 0x2766; 16416 t.a108 = 0x2767; 16417 t.a112 = 0x2663; 16418 t.a111 = 0x2666; 16419 t.a110 = 0x2665; 16420 t.a109 = 0x2660; 16421 t.a120 = 0x2460; 16422 t.a121 = 0x2461; 16423 t.a122 = 0x2462; 16424 t.a123 = 0x2463; 16425 t.a124 = 0x2464; 16426 t.a125 = 0x2465; 16427 t.a126 = 0x2466; 16428 t.a127 = 0x2467; 16429 t.a128 = 0x2468; 16430 t.a129 = 0x2469; 16431 t.a130 = 0x2776; 16432 t.a131 = 0x2777; 16433 t.a132 = 0x2778; 16434 t.a133 = 0x2779; 16435 t.a134 = 0x277a; 16436 t.a135 = 0x277b; 16437 t.a136 = 0x277c; 16438 t.a137 = 0x277d; 16439 t.a138 = 0x277e; 16440 t.a139 = 0x277f; 16441 t.a140 = 0x2780; 16442 t.a141 = 0x2781; 16443 t.a142 = 0x2782; 16444 t.a143 = 0x2783; 16445 t.a144 = 0x2784; 16446 t.a145 = 0x2785; 16447 t.a146 = 0x2786; 16448 t.a147 = 0x2787; 16449 t.a148 = 0x2788; 16450 t.a149 = 0x2789; 16451 t.a150 = 0x278a; 16452 t.a151 = 0x278b; 16453 t.a152 = 0x278c; 16454 t.a153 = 0x278d; 16455 t.a154 = 0x278e; 16456 t.a155 = 0x278f; 16457 t.a156 = 0x2790; 16458 t.a157 = 0x2791; 16459 t.a158 = 0x2792; 16460 t.a159 = 0x2793; 16461 t.a160 = 0x2794; 16462 t.a161 = 0x2192; 16463 t.a163 = 0x2194; 16464 t.a164 = 0x2195; 16465 t.a196 = 0x2798; 16466 t.a165 = 0x2799; 16467 t.a192 = 0x279a; 16468 t.a166 = 0x279b; 16469 t.a167 = 0x279c; 16470 t.a168 = 0x279d; 16471 t.a169 = 0x279e; 16472 t.a170 = 0x279f; 16473 t.a171 = 0x27a0; 16474 t.a172 = 0x27a1; 16475 t.a173 = 0x27a2; 16476 t.a162 = 0x27a3; 16477 t.a174 = 0x27a4; 16478 t.a175 = 0x27a5; 16479 t.a176 = 0x27a6; 16480 t.a177 = 0x27a7; 16481 t.a178 = 0x27a8; 16482 t.a179 = 0x27a9; 16483 t.a193 = 0x27aa; 16484 t.a180 = 0x27ab; 16485 t.a199 = 0x27ac; 16486 t.a181 = 0x27ad; 16487 t.a200 = 0x27ae; 16488 t.a182 = 0x27af; 16489 t.a201 = 0x27b1; 16490 t.a183 = 0x27b2; 16491 t.a184 = 0x27b3; 16492 t.a197 = 0x27b4; 16493 t.a185 = 0x27b5; 16494 t.a194 = 0x27b6; 16495 t.a198 = 0x27b7; 16496 t.a186 = 0x27b8; 16497 t.a195 = 0x27b9; 16498 t.a187 = 0x27ba; 16499 t.a188 = 0x27bb; 16500 t.a189 = 0x27bc; 16501 t.a190 = 0x27bd; 16502 t.a191 = 0x27be; 16503 t.a89 = 0x2768; 16504 t.a90 = 0x2769; 16505 t.a93 = 0x276a; 16506 t.a94 = 0x276b; 16507 t.a91 = 0x276c; 16508 t.a92 = 0x276d; 16509 t.a205 = 0x276e; 16510 t.a85 = 0x276f; 16511 t.a206 = 0x2770; 16512 t.a86 = 0x2771; 16513 t.a87 = 0x2772; 16514 t.a88 = 0x2773; 16515 t.a95 = 0x2774; 16516 t.a96 = 0x2775; 16517 t[".notdef"] = 0x0000; 16518}); 16519 16520;// ./src/core/unicode.js 16521 16522const getSpecialPUASymbols = getLookupTableFactory(function (t) { 16523 t[63721] = 0x00a9; 16524 t[63193] = 0x00a9; 16525 t[63720] = 0x00ae; 16526 t[63194] = 0x00ae; 16527 t[63722] = 0x2122; 16528 t[63195] = 0x2122; 16529 t[637
vendor: 15,628 bytes, lines 16529-16879
1652929] = 0x23a7; 16530 t[63730] = 0x23a8; 16531 t[63731] = 0x23a9; 16532 t[63740] = 0x23ab; 16533 t[63741] = 0x23ac; 16534 t[63742] = 0x23ad; 16535 t[63726] = 0x23a1; 16536 t[63727] = 0x23a2; 16537 t[63728] = 0x23a3; 16538 t[63737] = 0x23a4; 16539 t[63738] = 0x23a5; 16540 t[63739] = 0x23a6; 16541 t[63723] = 0x239b; 16542 t[63724] = 0x239c; 16543 t[63725] = 0x239d; 16544 t[63734] = 0x239e; 16545 t[63735] = 0x239f; 16546 t[63736] = 0x23a0; 16547}); 16548function mapSpecialUnicodeValues(code) { 16549 if (code >= 0xfff0 && code <= 0xffff) { 16550 return 0; 16551 } else if (code >= 0xf600 && code <= 0xf8ff) { 16552 return getSpecialPUASymbols()[code] || code; 16553 } else if (code === 0x00ad) { 16554 return 0x002d; 16555 } 16556 return code; 16557} 16558function getUnicodeForGlyph(name, glyphsUnicodeMap) { 16559 let unicode = glyphsUnicodeMap[name]; 16560 if (unicode !== undefined) { 16561 return unicode; 16562 } 16563 if (!name) { 16564 return -1; 16565 } 16566 if (name[0] === "u") { 16567 const nameLen = name.length; 16568 let hexStr; 16569 if (nameLen === 7 && name[1] === "n" && name[2] === "i") { 16570 hexStr = name.substring(3); 16571 } else if (nameLen >= 5 && nameLen <= 7) { 16572 hexStr = name.substring(1); 16573 } else { 16574 return -1; 16575 } 16576 if (hexStr === hexStr.toUpperCase()) { 16577 unicode = parseInt(hexStr, 16); 16578 if (unicode >= 0) { 16579 return unicode; 16580 } 16581 } 16582 } 16583 return -1; 16584} 16585const UnicodeRanges = [[0x0000, 0x007f], [0x0080, 0x00ff], [0x0100, 0x017f], [0x0180, 0x024f], [0x0250, 0x02af, 0x1d00, 0x1d7f, 0x1d80, 0x1dbf], [0x02b0, 0x02ff, 0xa700, 0xa71f], [0x0300, 0x036f, 0x1dc0, 0x1dff], [0x0370, 0x03ff], [0x2c80, 0x2cff], [0x0400, 0x04ff, 0x0500, 0x052f, 0x2de0, 0x2dff, 0xa640, 0xa69f], [0x0530, 0x058f], [0x0590, 0x05ff], [0xa500, 0xa63f], [0x0600, 0x06ff, 0x0750, 0x077f], [0x07c0, 0x07ff], [0x0900, 0x097f], [0x0980, 0x09ff], [0x0a00, 0x0a7f], [0x0a80, 0x0aff], [0x0b00, 0x0b7f], [0x0b80, 0x0bff], [0x0c00, 0x0c7f], [0x0c80, 0x0cff], [0x0d00, 0x0d7f], [0x0e00, 0x0e7f], [0x0e80, 0x0eff], [0x10a0, 0x10ff, 0x2d00, 0x2d2f], [0x1b00, 0x1b7f], [0x1100, 0x11ff], [0x1e00, 0x1eff, 0x2c60, 0x2c7f, 0xa720, 0xa7ff], [0x1f00, 0x1fff], [0x2000, 0x206f, 0x2e00, 0x2e7f], [0x2070, 0x209f], [0x20a0, 0x20cf], [0x20d0, 0x20ff], [0x2100, 0x214f], [0x2150, 0x218f], [0x2190, 0x21ff, 0x27f0, 0x27ff, 0x2900, 0x297f, 0x2b00, 0x2bff], [0x2200, 0x22ff, 0x2a00, 0x2aff, 0x27c0, 0x27ef, 0x2980, 0x29ff], [0x2300, 0x23ff], [0x2400, 0x243f], [0x2440, 0x245f], [0x2460, 0x24ff], [0x2500, 0x257f], [0x2580, 0x259f], [0x25a0, 0x25ff], [0x2600, 0x26ff], [0x2700, 0x27bf], [0x3000, 0x303f], [0x3040, 0x309f], [0x30a0, 0x30ff, 0x31f0, 0x31ff], [0x3100, 0x312f, 0x31a0, 0x31bf], [0x3130, 0x318f], [0xa840, 0xa87f], [0x3200, 0x32ff], [0x3300, 0x33ff], [0xac00, 0xd7af], [0xd800, 0xdfff], [0x10900, 0x1091f], [0x4e00, 0x9fff, 0x2e80, 0x2eff, 0x2f00, 0x2fdf, 0x2ff0, 0x2fff, 0x3400, 0x4dbf, 0x20000, 0x2a6df, 0x3190, 0x319f], [0xe000, 0xf8ff], [0x31c0, 0x31ef, 0xf900, 0xfaff, 0x2f800, 0x2fa1f], [0xfb00, 0xfb4f], [0xfb50, 0xfdff], [0xfe20, 0xfe2f], [0xfe10, 0xfe1f], [0xfe50, 0xfe6f], [0xfe70, 0xfeff], [0xff00, 0xffef], [0xfff0, 0xffff], [0x0f00, 0x0fff], [0x0700, 0x074f], [0x0780, 0x07bf], [0x0d80, 0x0dff], [0x1000, 0x109f], [0x1200, 0x137f, 0x1380, 0x139f, 0x2d80, 0x2ddf], [0x13a0, 0x13ff], [0x1400, 0x167f], [0x1680, 0x169f], [0x16a0, 0x16ff], [0x1780, 0x17ff], [0x1800, 0x18af], [0x2800, 0x28ff], [0xa000, 0xa48f], [0x1700, 0x171f, 0x1720, 0x173f, 0x1740, 0x175f, 0x1760, 0x177f], [0x10300, 0x1032f], [0x10330, 0x1034f], [0x10400, 0x1044f], [0x1d000, 0x1d0ff, 0x1d100, 0x1d1ff, 0x1d200, 0x1d24f], [0x1d400, 0x1d7ff], [0xff000, 0xffffd], [0xfe00, 0xfe0f, 0xe0100, 0xe01ef], [0xe0000, 0xe007f], [0x1900, 0x194f], [0x1950, 0x197f], [0x1980, 0x19df], [0x1a00, 0x1a1f], [0x2c00, 0x2c5f], [0x2d30, 0x2d7f], [0x4dc0, 0x4dff], [0xa800, 0xa82f], [0x10000, 0x1007f, 0x10080, 0x100ff, 0x10100, 0x1013f], [0x10140, 0x1018f], [0x10380, 0x1039f], [0x103a0, 0x103df], [0x10450, 0x1047f], [0x10480, 0x104af], [0x10800, 0x1083f], [0x10a00, 0x10a5f], [0x1d300, 0x1d35f], [0x12000, 0x123ff, 0x12400, 0x1247f], [0x1d360, 0x1d37f], [0x1b80, 0x1bbf], [0x1c00, 0x1c4f], [0x1c50, 0x1c7f], [0xa880, 0xa8df], [0xa900, 0xa92f], [0xa930, 0xa95f], [0xaa00, 0xaa5f], [0x10190, 0x101cf], [0x101d0, 0x101ff], [0x102a0, 0x102df, 0x10280, 0x1029f, 0x10920, 0x1093f], [0x1f030, 0x1f09f, 0x1f000, 0x1f02f]]; 16586function getUnicodeRangeFor(value, lastPosition = -1) { 16587 if (lastPosition !== -1) { 16588 const range = UnicodeRanges[lastPosition]; 16589 for (let i = 0, ii = range.length; i < ii; i += 2) { 16590 if (value >= range[i] && value <= range[i + 1]) { 16591 return lastPosition; 16592 } 16593 } 16594 } 16595 for (let i = 0, ii = UnicodeRanges.length; i < ii; i++) { 16596 const range = UnicodeRanges[i]; 16597 for (let j = 0, jj = range.length; j < jj; j += 2) { 16598 if (value >= range[j] && value <= range[j + 1]) { 16599 return i; 16600 } 16601 } 16602 } 16603 return -1; 16604} 16605const SpecialCharRegExp = new RegExp("^(\\s)|(\\p{Mn})|(\\p{Cf})$", "u"); 16606const CategoryCache = new Map(); 16607function getCharUnicodeCategory(char) { 16608 const cachedCategory = CategoryCache.get(char); 16609 if (cachedCategory) { 16610 return cachedCategory; 16611 } 16612 const groups = char.match(SpecialCharRegExp); 16613 const category = { 16614 isWhitespace: !!groups?.[1], 16615 isZeroWidthDiacritic: !!groups?.[2], 16616 isInvisibleFormatMark: !!groups?.[3] 16617 }; 16618 CategoryCache.set(char, category); 16619 return category; 16620} 16621function clearUnicodeCaches() { 16622 CategoryCache.clear(); 16623} 16624 16625;// ./src/core/fonts_utils.js 16626 16627 16628 16629 16630 16631const SEAC_ANALYSIS_ENABLED = true; 16632const FontFlags = { 16633 FixedPitch: 1, 16634 Serif: 2, 16635 Symbolic: 4, 16636 Script: 8, 16637 Nonsymbolic: 32, 16638 Italic: 64, 16639 AllCap: 65536, 16640 SmallCap: 131072, 16641 ForceBold: 262144 16642}; 16643const MacStandardGlyphOrdering = [".notdef", ".null", "nonmarkingreturn", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "Adieresis", "Aring", "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute", "agrave", "acircumflex", "adieresis", "atilde", "aring", "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute", "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling", "section", "bullet", "paragraph", "germandbls", "registered", "copyright", "trademark", "acute", "dieresis", "notequal", "AE", "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", "yen", "mu", "partialdiff", "summation", "product", "pi", "integral", "ordfeminine", "ordmasculine", "Omega", "ae", "oslash", "questiondown", "exclamdown", "logicalnot", "radical", "florin", "approxequal", "Delta", "guillemotleft", "guillemotright", "ellipsis", "nonbreakingspace", "Agrave", "Atilde", "Otilde", "OE", "oe", "endash", "emdash", "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide", "lozenge", "ydieresis", "Ydieresis", "fraction", "currency", "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex", "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", "circumflex", "tilde", "macron", "breve", "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", "Lslash", "lslash", "Scaron", "scaron", "Zcaron", "zcaron", "brokenbar", "Eth", "eth", "Yacute", "yacute", "Thorn", "thorn", "minus", "multiply", "onesuperior", "twosuperior", "threesuperior", "onehalf", "onequarter", "threequarters", "franc", "Gbreve", "gbreve", "Idotaccent", "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron", "ccaron", "dcroat"]; 16644function recoverGlyphName(name, glyphsUnicodeMap) { 16645 if (glyphsUnicodeMap[name] !== undefined) { 16646 return name; 16647 } 16648 const unicode = getUnicodeForGlyph(name, glyphsUnicodeMap); 16649 if (unicode !== -1) { 16650 for (const key in glyphsUnicodeMap) { 16651 if (glyphsUnicodeMap[key] === unicode) { 16652 return key; 16653 } 16654 } 16655 } 16656 info("Unable to recover a standard glyph name for: " + name); 16657 return name; 16658} 16659function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) { 16660 const charCodeToGlyphId = Object.create(null); 16661 let glyphId, charCode, baseEncoding; 16662 const isSymbolicFont = !!(properties.flags & FontFlags.Symbolic); 16663 if (properties.isInternalFont) { 16664 baseEncoding = builtInEncoding; 16665 for (charCode = 0; charCode < baseEncoding.length; charCode++) { 16666 glyphId = glyphNames.indexOf(baseEncoding[charCode]); 16667 charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0; 16668 } 16669 } else if (properties.baseEncodingName) { 16670 baseEncoding = getEncoding(properties.baseEncodingName); 16671 for (charCode = 0; charCode < baseEncoding.length; charCode++) { 16672 glyphId = glyphNames.indexOf(baseEncoding[charCode]); 16673 charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0; 16674 } 16675 } else if (isSymbolicFont) { 16676 for (charCode in builtInEncoding) { 16677 charCodeToGlyphId[charCode] = builtInEncoding[charCode]; 16678 } 16679 } else { 16680 baseEncoding = StandardEncoding; 16681 for (charCode = 0; charCode < baseEncoding.length; charCode++) { 16682 glyphId = glyphNames.indexOf(baseEncoding[charCode]); 16683 charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0; 16684 } 16685 } 16686 const differences = properties.differences; 16687 let glyphsUnicodeMap; 16688 if (differences) { 16689 for (charCode in differences) { 16690 const glyphName = differences[charCode]; 16691 glyphId = glyphNames.indexOf(glyphName); 16692 if (glyphId === -1) { 16693 if (!glyphsUnicodeMap) { 16694 glyphsUnicodeMap = getGlyphsUnicode(); 16695 } 16696 const standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap); 16697 if (standardGlyphName !== glyphName) { 16698 glyphId = glyphNames.indexOf(standardGlyphName); 16699 } 16700 } 16701 charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0; 16702 } 16703 } 16704 return charCodeToGlyphId; 16705} 16706function normalizeFontName(name) { 16707 return name.replaceAll(/[,_]/g, "-").replaceAll(/\s/g, ""); 16708} 16709const getVerticalPresentationForm = getLookupTableFactory(t => { 16710 t[0x2013] = 0xfe32; 16711 t[0x2014] = 0xfe31; 16712 t[0x2025] = 0xfe30; 16713 t[0x2026] = 0xfe19; 16714 t[0x3001] = 0xfe11; 16715 t[0x3002] = 0xfe12; 16716 t[0x3008] = 0xfe3f; 16717 t[0x3009] = 0xfe40; 16718 t[0x300a] = 0xfe3d; 16719 t[0x300b] = 0xfe3e; 16720 t[0x300c] = 0xfe41; 16721 t[0x300d] = 0xfe42; 16722 t[0x300e] = 0xfe43; 16723 t[0x300f] = 0xfe44; 16724 t[0x3010] = 0xfe3b; 16725 t[0x3011] = 0xfe3c; 16726 t[0x3014] = 0xfe39; 16727 t[0x3015] = 0xfe3a; 16728 t[0x3016] = 0xfe17; 16729 t[0x3017] = 0xfe18; 16730 t[0xfe4f] = 0xfe34; 16731 t[0xff01] = 0xfe15; 16732 t[0xff08] = 0xfe35; 16733 t[0xff09] = 0xfe36; 16734 t[0xff0c] = 0xfe10; 16735 t[0xff1a] = 0xfe13; 16736 t[0xff1b] = 0xfe14; 16737 t[0xff1f] = 0xfe16; 16738 t[0xff3b] = 0xfe47; 16739 t[0xff3d] = 0xfe48; 16740 t[0xff3f] = 0xfe33; 16741 t[0xff5b] = 0xfe37; 16742 t[0xff5d] = 0xfe38; 16743}); 16744const MAX_SIZE_TO_COMPILE = 1000; 16745function compileType3Glyph({ 16746 data: img, 16747 width, 16748 height 16749}) { 16750 if (width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) { 16751 return null; 16752 } 16753 const POINT_TO_PROCESS_LIMIT = 1000; 16754 const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]); 16755 const width1 = width + 1; 16756 const points = new Uint8Array(width1 * (height + 1)); 16757 let i, j, j0; 16758 const lineSize = width + 7 & ~7; 16759 const data = new Uint8Array(lineSize * height); 16760 let pos = 0; 16761 for (const elem of img) { 16762 let mask = 128; 16763 while (mask > 0) { 16764 data[pos++] = elem & mask ? 0 : 255; 16765 mask >>= 1; 16766 } 16767 } 16768 let count = 0; 16769 pos = 0; 16770 if (data[pos] !== 0) { 16771 points[0] = 1; 16772 ++count; 16773 } 16774 for (j = 1; j < width; j++) { 16775 if (data[pos] !== data[pos + 1]) { 16776 points[j] = data[pos] ? 2 : 1; 16777 ++count; 16778 } 16779 pos++; 16780 } 16781 if (data[pos] !== 0) { 16782 points[j] = 2; 16783 ++count; 16784 } 16785 for (i = 1; i < height; i++) { 16786 pos = i * lineSize; 16787 j0 = i * width1; 16788 if (data[pos - lineSize] !== data[pos]) { 16789 points[j0] = data[pos] ? 1 : 8; 16790 ++count; 16791 } 16792 let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0); 16793 for (j = 1; j < width; j++) { 16794 sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0); 16795 if (POINT_TYPES[sum]) { 16796 points[j0 + j] = POINT_TYPES[sum]; 16797 ++count; 16798 } 16799 pos++; 16800 } 16801 if (data[pos - lineSize] !== data[pos]) { 16802 points[j0 + j] = data[pos] ? 2 : 4; 16803 ++count; 16804 } 16805 if (count > POINT_TO_PROCESS_LIMIT) { 16806 return null; 16807 } 16808 } 16809 pos = lineSize * (height - 1); 16810 j0 = i * width1; 16811 if (data[pos] !== 0) { 16812 points[j0] = 8; 16813 ++count; 16814 } 16815 for (j = 1; j < width; j++) { 16816 if (data[pos] !== data[pos + 1]) { 16817 points[j0 + j] = data[pos] ? 4 : 8; 16818 ++count; 16819 } 16820 pos++; 16821 } 16822 if (data[pos] !== 0) { 16823 points[j0 + j] = 4; 16824 ++count; 16825 } 16826 if (count > POINT_TO_PROCESS_LIMIT) { 16827 return null; 16828 } 16829 const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]); 16830 const pathBuf = []; 16831 const { 16832 a, 16833 b, 16834 c, 16835 d, 16836 e, 16837 f 16838 } = new DOMMatrix().scaleSelf(1 / width, -1 / height).translateSelf(0, -height); 16839 for (i = 0; count && i <= height; i++) { 16840 let p = i * width1; 16841 const end = p + width; 16842 while (p < end && !points[p]) { 16843 p++; 16844 } 16845 if (p === end) { 16846 continue; 16847 } 16848 let x = p % width1; 16849 let y = i; 16850 pathBuf.push(DrawOPS.moveTo, a * x + c * y + e, b * x + d * y + f); 16851 const p0 = p; 16852 let type = points[p]; 16853 do { 16854 const step = steps[type]; 16855 do { 16856 p += step; 16857 } while (!points[p]); 16858 const pp = points[p]; 16859 if (pp !== 5 && pp !== 10) { 16860 type = pp; 16861 points[p] = 0; 16862 } else { 16863 type = pp & 0x33 * type >> 4; 16864 points[p] &= type >> 2 | type << 2; 16865 } 16866 x = p % width1; 16867 y = p / width1 | 0; 16868 pathBuf.push(DrawOPS.lineTo, a * x + c * y + e, b * x + d * y + f); 16869 if (!points[p]) { 16870 --count; 16871 } 16872 } while (p0 !== p); 16873 --i; 16874 } 16875 return [OPS.rawFillPath, [new Float32Array(pathBuf)], new Float32Array([0, 0, width, height])]; 16876} 16877 16878;// ./src/core/charsets.js 16879const ISOAdobeCharset = [".notdef", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "exclamdown", "cent", "sterling", "fraction", "yen", "florin", "section", "currency", "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl", "endash", "dagger", "daggerdbl", "periodce
16879ntered", "paragraph", "bullet", "quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", "ellipsis", "perthousand", "questiondown", "grave", "acute", "circumflex", "tilde", "macron", "breve", "dotaccent", "dieresis", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", "emdash", "AE", "ordfeminine", "Lslash", "Oslash", "OE", "ordmasculine", "ae", "dotlessi", "lslash", "oslash", "oe", "germandbls", "onesuperior", "logicalnot", "mu", "trademark", "Eth", "onehalf", "plusminus", "Thorn", "onequarter", "divide", "brokenbar", "degree", "thorn", "threequarters", "twosuperior", "registered", "minus", "eth", "multiply", "threesuperior", "copyright", "Aacute", "Acircumflex", "Adieresis", "Agrave", "Aring", "Atilde", "Ccedilla", "Eacute", "Ecircumflex", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Ntilde", "Oacute", "Ocircumflex", "Odieresis", "Ograve", "Otilde", "Scaron", "Uacute", "Ucircumflex", "Udieresis", "Ugrave", "Yacute", "Ydieresis", "Zcaron", "aacute", "acircumflex", "adieresis", "agrave", "aring", "atilde", "ccedilla", "eacute", "ecircumflex", "edieresis", "egrave", "iacute", "icircumflex", "idieresis", "igrave", "ntilde", "oacute", "ocircumflex", "odieresis", "ograve", "otilde", "scaron", "uacute", "ucircumflex", "udieresis", "ugrave", "yacute", "ydieresis", "zcaron"]; 16880const ExpertCharset = [".notdef", "space", "exclamsmall", "Hungarumlautsmall", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "commasuperior", "threequartersemdash", "periodsuperior", "questionsmall", "asuperior", "bsuperior", "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior", "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior", "tsuperior", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "exclamdownsmall", "centoldstyle", "Lslashsmall", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall", "Caronsmall", "Dotaccentsmall", "Macronsmall", "figuredash", "hypheninferior", "Ogoneksmall", "Ringsmall", "Cedillasmall", "onequarter", "onehalf", "threequarters", "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "zerosuperior", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", "threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior", "dollarinferior", "periodinferior", "commainferior", "Agravesmall", "Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall", "Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall", "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall", "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall", "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall", "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall", "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall", "Ydieresissmall"]; 16881const ExpertSubsetCharset = [".notdef", "space", "dollaroldstyle", "dollarsuperior", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "commasuperior", "threequartersemdash", "periodsuperior", "asuperior", "bsuperior", "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior", "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior", "tsuperior", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "parenrightinferior", "hyphensuperior", "colonmonetary", "onefitted", "rupiah", "centoldstyle", "figuredash", "hypheninferior", "onequarter", "onehalf", "threequarters", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "zerosuperior", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", "threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior", "dollarinferior", "periodinferior", "commainferior"]; 16882 16883;// ./src/core/cff_parser.js
vendor: 49,602 bytes, lines 16883-18363
16883 16884 16885 16886 16887 16888const MAX_SUBR_NESTING = 10; 16889const CFFStandardStrings = [".notdef", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "exclamdown", "cent", "sterling", "fraction", "yen", "florin", "section", "currency", "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl", "endash", "dagger", "daggerdbl", "periodcentered", "paragraph", "bullet", "quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", "ellipsis", "perthousand", "questiondown", "grave", "acute", "circumflex", "tilde", "macron", "breve", "dotaccent", "dieresis", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", "emdash", "AE", "ordfeminine", "Lslash", "Oslash", "OE", "ordmasculine", "ae", "dotlessi", "lslash", "oslash", "oe", "germandbls", "onesuperior", "logicalnot", "mu", "trademark", "Eth", "onehalf", "plusminus", "Thorn", "onequarter", "divide", "brokenbar", "degree", "thorn", "threequarters", "twosuperior", "registered", "minus", "eth", "multiply", "threesuperior", "copyright", "Aacute", "Acircumflex", "Adieresis", "Agrave", "Aring", "Atilde", "Ccedilla", "Eacute", "Ecircumflex", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Ntilde", "Oacute", "Ocircumflex", "Odieresis", "Ograve", "Otilde", "Scaron", "Uacute", "Ucircumflex", "Udieresis", "Ugrave", "Yacute", "Ydieresis", "Zcaron", "aacute", "acircumflex", "adieresis", "agrave", "aring", "atilde", "ccedilla", "eacute", "ecircumflex", "edieresis", "egrave", "iacute", "icircumflex", "idieresis", "igrave", "ntilde", "oacute", "ocircumflex", "odieresis", "ograve", "otilde", "scaron", "uacute", "ucircumflex", "udieresis", "ugrave", "yacute", "ydieresis", "zcaron", "exclamsmall", "Hungarumlautsmall", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "commasuperior", "threequartersemdash", "periodsuperior", "questionsmall", "asuperior", "bsuperior", "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior", "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior", "tsuperior", "ff", "ffi", "ffl", "parenleftinferior", "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "exclamdownsmall", "centoldstyle", "Lslashsmall", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall", "Caronsmall", "Dotaccentsmall", "Macronsmall", "figuredash", "hypheninferior", "Ogoneksmall", "Ringsmall", "Cedillasmall", "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "zerosuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", "threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior", "dollarinferior", "periodinferior", "commainferior", "Agravesmall", "Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall", "Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall", "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall", "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall", "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall", "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall", "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall", "Ydieresissmall", "001.000", "001.001", "001.002", "001.003", "Black", "Bold", "Book", "Light", "Medium", "Regular", "Roman", "Semibold"]; 16890const NUM_STANDARD_CFF_STRINGS = 391; 16891const CharstringValidationData = [null, { 16892 id: "hstem", 16893 min: 2, 16894 stackClearing: true, 16895 stem: true 16896}, null, { 16897 id: "vstem", 16898 min: 2, 16899 stackClearing: true, 16900 stem: true 16901}, { 16902 id: "vmoveto", 16903 min: 1, 16904 stackClearing: true 16905}, { 16906 id: "rlineto", 16907 min: 2, 16908 resetStack: true 16909}, { 16910 id: "hlineto", 16911 min: 1, 16912 resetStack: true 16913}, { 16914 id: "vlineto", 16915 min: 1, 16916 resetStack: true 16917}, { 16918 id: "rrcurveto", 16919 min: 6, 16920 resetStack: true 16921}, null, { 16922 id: "callsubr", 16923 min: 1, 16924 undefStack: true 16925}, { 16926 id: "return", 16927 min: 0, 16928 undefStack: true 16929}, null, null, { 16930 id: "endchar", 16931 min: 0, 16932 stackClearing: true 16933}, null, null, null, { 16934 id: "hstemhm", 16935 min: 2, 16936 stackClearing: true, 16937 stem: true 16938}, { 16939 id: "hintmask", 16940 min: 0, 16941 stackClearing: true 16942}, { 16943 id: "cntrmask", 16944 min: 0, 16945 stackClearing: true 16946}, { 16947 id: "rmoveto", 16948 min: 2, 16949 stackClearing: true 16950}, { 16951 id: "hmoveto", 16952 min: 1, 16953 stackClearing: true 16954}, { 16955 id: "vstemhm", 16956 min: 2, 16957 stackClearing: true, 16958 stem: true 16959}, { 16960 id: "rcurveline", 16961 min: 8, 16962 resetStack: true 16963}, { 16964 id: "rlinecurve", 16965 min: 8, 16966 resetStack: true 16967}, { 16968 id: "vvcurveto", 16969 min: 4, 16970 resetStack: true 16971}, { 16972 id: "hhcurveto", 16973 min: 4, 16974 resetStack: true 16975}, null, { 16976 id: "callgsubr", 16977 min: 1, 16978 undefStack: true 16979}, { 16980 id: "vhcurveto", 16981 min: 4, 16982 resetStack: true 16983}, { 16984 id: "hvcurveto", 16985 min: 4, 16986 resetStack: true 16987}]; 16988const CharstringValidationData12 = [null, null, null, { 16989 id: "and", 16990 min: 2, 16991 stackDelta: -1 16992}, { 16993 id: "or", 16994 min: 2, 16995 stackDelta: -1 16996}, { 16997 id: "not", 16998 min: 1, 16999 stackDelta: 0 17000}, null, null, null, { 17001 id: "abs", 17002 min: 1, 17003 stackDelta: 0 17004}, { 17005 id: "add", 17006 min: 2, 17007 stackDelta: -1, 17008 stackFn(stack, index) { 17009 stack[index - 2] = stack[index - 2] + stack[index - 1]; 17010 } 17011}, { 17012 id: "sub", 17013 min: 2, 17014 stackDelta: -1, 17015 stackFn(stack, index) { 17016 stack[index - 2] = stack[index - 2] - stack[index - 1]; 17017 } 17018}, { 17019 id: "div", 17020 min: 2, 17021 stackDelta: -1, 17022 stackFn(stack, index) { 17023 stack[index - 2] = stack[index - 2] / stack[index - 1]; 17024 } 17025}, null, { 17026 id: "neg", 17027 min: 1, 17028 stackDelta: 0, 17029 stackFn(stack, index) { 17030 stack[index - 1] = -stack[index - 1]; 17031 } 17032}, { 17033 id: "eq", 17034 min: 2, 17035 stackDelta: -1 17036}, null, null, { 17037 id: "drop", 17038 min: 1, 17039 stackDelta: -1 17040}, null, { 17041 id: "put", 17042 min: 2, 17043 stackDelta: -2 17044}, { 17045 id: "get", 17046 min: 1, 17047 stackDelta: 0 17048}, { 17049 id: "ifelse", 17050 min: 4, 17051 stackDelta: -3 17052}, { 17053 id: "random", 17054 min: 0, 17055 stackDelta: 1 17056}, { 17057 id: "mul", 17058 min: 2, 17059 stackDelta: -1, 17060 stackFn(stack, index) { 17061 stack[index - 2] = stack[index - 2] * stack[index - 1]; 17062 } 17063}, null, { 17064 id: "sqrt", 17065 min: 1, 17066 stackDelta: 0 17067}, { 17068 id: "dup", 17069 min: 1, 17070 stackDelta: 1 17071}, { 17072 id: "exch", 17073 min: 2, 17074 stackDelta: 0 17075}, { 17076 id: "index", 17077 min: 2, 17078 stackDelta: 0 17079}, { 17080 id: "roll", 17081 min: 3, 17082 stackDelta: -2 17083}, null, null, null, { 17084 id: "hflex", 17085 min: 7, 17086 resetStack: true 17087}, { 17088 id: "flex", 17089 min: 13, 17090 resetStack: true 17091}, { 17092 id: "hflex1", 17093 min: 9, 17094 resetStack: true 17095}, { 17096 id: "flex1", 17097 min: 11, 17098 resetStack: true 17099}]; 17100class CFFParser { 17101 constructor(file, properties, seacAnalysisEnabled) { 17102 this.bytes = file.getBytes(); 17103 this.properties = properties; 17104 this.seacAnalysisEnabled = !!seacAnalysisEnabled; 17105 } 17106 parse() { 17107 const properties = this.properties; 17108 const cff = new CFF(); 17109 this.cff = cff; 17110 const header = this.parseHeader(); 17111 const nameIndex = this.parseIndex(header.endPos); 17112 const topDictIndex = this.parseIndex(nameIndex.endPos); 17113 const stringIndex = this.parseIndex(topDictIndex.endPos); 17114 const globalSubrIndex = this.parseIndex(stringIndex.endPos); 17115 const topDictParsed = this.parseDict(topDictIndex.obj.get(0)); 17116 const topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings); 17117 cff.header = header.obj; 17118 cff.names = this.parseNameIndex(nameIndex.obj); 17119 cff.strings = this.parseStringIndex(stringIndex.obj); 17120 cff.topDict = topDict; 17121 cff.globalSubrIndex = globalSubrIndex.obj; 17122 this.parsePrivateDict(cff.topDict); 17123 cff.isCIDFont = topDict.hasName("ROS"); 17124 const charStringOffset = topDict.getByName("CharStrings"); 17125 const charStringIndex = this.parseIndex(charStringOffset).obj; 17126 const fontMatrix = topDict.getByName("FontMatrix"); 17127 if (fontMatrix) { 17128 properties.fontMatrix = fontMatrix; 17129 } 17130 const fontBBox = topDict.getByName("FontBBox"); 17131 if (fontBBox) { 17132 properties.ascent = Math.max(fontBBox[3], fontBBox[1]); 17133 properties.descent = Math.min(fontBBox[1], fontBBox[3]); 17134 properties.ascentScaled = true; 17135 } 17136 let charset, encoding; 17137 if (cff.isCIDFont) { 17138 const fdArrayIndex = this.parseIndex(topDict.getByName("FDArray")).obj; 17139 for (let i = 0, ii = fdArrayIndex.count; i < ii; ++i) { 17140 const dictRaw = fdArrayIndex.get(i); 17141 const fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw), cff.strings); 17142 this.parsePrivateDict(fontDict); 17143 cff.fdArray.push(fontDict); 17144 } 17145 encoding = null; 17146 charset = this.parseCharsets(topDict.getByName("charset"), charStringIndex.count, cff.strings, true); 17147 cff.fdSelect = this.parseFDSelect(topDict.getByName("FDSelect"), charStringIndex.count); 17148 } else { 17149 charset = this.parseCharsets(topDict.getByName("charset"), charStringIndex.count, cff.strings, false); 17150 encoding = this.parseEncoding(topDict.getByName("Encoding"), properties, cff.strings, charset.charset); 17151 } 17152 cff.charset = charset; 17153 cff.encoding = encoding; 17154 const charStringsAndSeacs = this.parseCharStrings({ 17155 charStrings: charStringIndex, 17156 localSubrIndex: topDict.privateDict.subrsIndex, 17157 globalSubrIndex: globalSubrIndex.obj, 17158 fdSelect: cff.fdSelect, 17159 fdArray: cff.fdArray, 17160 privateDict: topDict.privateDict 17161 }); 17162 cff.charStrings = charStringsAndSeacs.charStrings; 17163 cff.seacs = charStringsAndSeacs.seacs; 17164 cff.widths = charStringsAndSeacs.widths; 17165 return cff; 17166 } 17167 parseHeader() { 17168 let bytes = this.bytes; 17169 const bytesLength = bytes.length; 17170 let offset = 0; 17171 while (offset < bytesLength && bytes[offset] !== 1) { 17172 ++offset; 17173 } 17174 if (offset >= bytesLength) { 17175 throw new FormatError("Invalid CFF header"); 17176 } 17177 if (offset !== 0) { 17178 info("cff data is shifted"); 17179 bytes = bytes.subarray(offset); 17180 this.bytes = bytes; 17181 } 17182 const major = bytes[0]; 17183 const minor = bytes[1]; 17184 const hdrSize = bytes[2]; 17185 const offSize = bytes[3]; 17186 const header = new CFFHeader(major, minor, hdrSize, offSize); 17187 return { 17188 obj: header, 17189 endPos: hdrSize 17190 }; 17191 } 17192 parseDict(dict) { 17193 let pos = 0; 17194 function parseOperand() { 17195 let value = dict[pos++]; 17196 if (value === 30) { 17197 return parseFloatOperand(); 17198 } else if (value === 28) { 17199 value = readInt16(dict, pos); 17200 pos += 2; 17201 return value; 17202 } else if (value === 29) { 17203 value = dict[pos++]; 17204 value = value << 8 | dict[pos++]; 17205 value = value << 8 | dict[pos++]; 17206 value = value << 8 | dict[pos++]; 17207 return value; 17208 } else if (value >= 32 && value <= 246) { 17209 return value - 139; 17210 } else if (value >= 247 && value <= 250) { 17211 return (value - 247) * 256 + dict[pos++] + 108; 17212 } else if (value >= 251 && value <= 254) { 17213 return -((value - 251) * 256) - dict[pos++] - 108; 17214 } 17215 warn('CFFParser_parseDict: "' + value + '" is a reserved command.'); 17216 return NaN; 17217 } 17218 function parseFloatOperand() { 17219 let str = ""; 17220 const eof = 15; 17221 const lookup = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "E", "E-", null, "-"]; 17222 const length = dict.length; 17223 while (pos < length) { 17224 const b = dict[pos++]; 17225 const b1 = b >> 4; 17226 const b2 = b & 15; 17227 if (b1 === eof) { 17228 break; 17229 } 17230 str += lookup[b1]; 17231 if (b2 === eof) { 17232 break; 17233 } 17234 str += lookup[b2]; 17235 } 17236 return parseFloat(str); 17237 } 17238 let operands = []; 17239 const entries = []; 17240 pos = 0; 17241 const end = dict.length; 17242 while (pos < end) { 17243 let b = dict[pos]; 17244 if (b <= 21) { 17245 if (b === 12) { 17246 b = b << 8 | dict[++pos]; 17247 } 17248 entries.push([b, operands]); 17249 operands = []; 17250 ++pos; 17251 } else { 17252 operands.push(parseOperand()); 17253 } 17254 } 17255 return entries; 17256 } 17257 parseIndex(pos) { 17258 const cffIndex = new CFFIndex(); 17259 const bytes = this.bytes; 17260 const count = bytes[pos++] << 8 | bytes[pos++]; 17261 const offsets = []; 17262 let end = pos; 17263 let i, ii; 17264 if (count !== 0) { 17265 const offsetSize = bytes[pos++]; 17266 const startPos = pos + (count + 1) * offsetSize - 1; 17267 for (i = 0, ii = count + 1; i < ii; ++i) { 17268 let offset = 0; 17269 for (let j = 0; j < offsetSize; ++j) { 17270 offset <<= 8; 17271 offset += bytes[pos++]; 17272 } 17273 offsets.push(startPos + offset); 17274 } 17275 end = offsets[count]; 17276 } 17277 for (i = 0, ii = offsets.length - 1; i < ii; ++i) { 17278 const offsetStart = offsets[i]; 17279 const offsetEnd = offsets[i + 1]; 17280 cffIndex.add(bytes.subarray(offsetStart, offsetEnd)); 17281 } 17282 return { 17283 obj: cffIndex, 17284 endPos: end 17285 }; 17286 } 17287 parseNameIndex(index) { 17288 const names = []; 17289 for (let i = 0, ii = index.count; i < ii; ++i) { 17290 const name = index.get(i); 17291 names.push(bytesToString(name)); 17292 } 17293 return names; 17294 } 17295 parseStringIndex(index) { 17296 const strings = new CFFStrings(); 17297 for (let i = 0, ii = index.count; i < ii; ++i) { 17298 const data = index.get(i); 17299 strings.add(bytesToString(data)); 17300 } 17301 return strings; 17302 } 17303 createDict(Type, dict, strings) { 17304 const cffDict = new Type(strings); 17305 for (const [key, value] of dict) { 17306 cffDict.setByKey(key, value); 17307 } 17308 return cffDict; 17309 } 17310 parseCharString(state, data, localSubrIndex, globalSubrIndex) { 17311 if (!data || state.callDepth > MAX_SUBR_NESTING) { 17312 return false; 17313 } 17314 let stackSize = state.stackSize; 17315 const stack = state.stack; 17316 let length = data.length; 17317 for (let j = 0; j < length;) { 17318 const value = data[j++]; 17319 let validationCommand = null; 17320 if (value === 12) { 17321 const q = data[j++]; 17322 if (q === 0) { 17323 data[j - 2] = 139; 17324 data[j - 1] = 22; 17325 stackSize = 0; 17326 } else { 17327 validationCommand = CharstringValidationData12[q]; 17328 } 17329 } else if (value === 28) { 17330 stack[stackSize] = readInt16(data, j); 17331 j += 2; 17332 stackSize++; 17333 } else if (value === 14) { 17334 if (stackSize >= 4) { 17335 stackSize -= 4; 17336 if (this.seacAnalysisEnabled) { 17337 state.seac = stack.slice(stackSize, stackSize + 4); 17338 return false; 17339 } 17340 } 17341 validationCommand = CharstringValidationData[value]; 17342 } else if (value >= 32 && value <= 246) { 17343 stack[stackSize] = value - 139; 17344 stackSize++; 17345 } else if (value >= 247 && value <= 254) { 17346 stack[stackSize] = value < 251 ? (value - 247 << 8) + data[j] + 108 : -(value - 251 << 8) - data[j] - 108; 17347 j++; 17348 stackSize++; 17349 } else if (value === 255) { 17350 stack[stackSize] = (data[j] << 24 | data[j + 1] << 16 | data[j + 2] << 8 | data[j + 3]) / 65536; 17351 j += 4; 17352 stackSize++; 17353 } else if (value === 19 || value === 20) { 17354 state.hints += stackSize >> 1; 17355 if (state.hints === 0) { 17356 data.copyWithin(j - 1, j, -1); 17357 j -= 1; 17358 length -= 1; 17359 continue; 17360 } 17361 j += state.hints + 7 >> 3; 17362 stackSize %= 2; 17363 validationCommand = CharstringValidationData[value]; 17364 } else if (value === 10 || value === 29) { 17365 const subrsIndex = value === 10 ? localSubrIndex : globalSubrIndex; 17366 if (!subrsIndex) { 17367 validationCommand = CharstringValidationData[value]; 17368 warn("Missing subrsIndex for " + validationCommand.id); 17369 return false; 17370 } 17371 let bias = 32768; 17372 if (subrsIndex.count < 1240) { 17373 bias = 107; 17374 } else if (subrsIndex.count < 33900) { 17375 bias = 1131; 17376 } 17377 const subrNumber = stack[--stackSize] + bias; 17378 if (subrNumber < 0 || subrNumber >= subrsIndex.count || isNaN(subrNumber)) { 17379 validationCommand = CharstringValidationData[value]; 17380 warn("Out of bounds subrIndex for " + validationCommand.id); 17381 return false; 17382 } 17383 state.stackSize = stackSize; 17384 state.callDepth++; 17385 const valid = this.parseCharString(state, subrsIndex.get(subrNumber), localSubrIndex, globalSubrIndex); 17386 if (!valid) { 17387 return false; 17388 } 17389 state.callDepth--; 17390 stackSize = state.stackSize; 17391 continue; 17392 } else if (value === 11) { 17393 state.stackSize = stackSize; 17394 return true; 17395 } else if (value === 0 && j === data.length) { 17396 data[j - 1] = 14; 17397 validationCommand = CharstringValidationData[14]; 17398 } else if (value === 9) { 17399 data.copyWithin(j - 1, j, -1); 17400 j -= 1; 17401 length -= 1; 17402 continue; 17403 } else { 17404 validationCommand = CharstringValidationData[value]; 17405 } 17406 if (validationCommand) { 17407 if (validationCommand.stem) { 17408 state.hints += stackSize >> 1; 17409 if (value === 3 || value === 23) { 17410 state.hasVStems = true; 17411 } else if (state.hasVStems && (value === 1 || value === 18)) { 17412 warn("CFF stem hints are in wrong order"); 17413 data[j - 1] = value === 1 ? 3 : 23; 17414 } 17415 } 17416 if ("min" in validationCommand) { 17417 if (!state.undefStack && stackSize < validationCommand.min) { 17418 warn("Not enough parameters for " + validationCommand.id + "; actual: " + stackSize + ", expected: " + validationCommand.min); 17419 if (stackSize === 0) { 17420 data[j - 1] = 14; 17421 return true; 17422 } 17423 return false; 17424 } 17425 } 17426 if (state.firstStackClearing && validationCommand.stackClearing) { 17427 state.firstStackClearing = false; 17428 stackSize -= validationCommand.min; 17429 if (stackSize >= 2 && validationCommand.stem) { 17430 stackSize %= 2; 17431 } else if (stackSize > 1) { 17432 warn("Found too many parameters for stack-clearing command"); 17433 } 17434 if (stackSize > 0) { 17435 state.width = stack[stackSize - 1]; 17436 } 17437 } 17438 if ("stackDelta" in validationCommand) { 17439 if ("stackFn" in validationCommand) { 17440 validationCommand.stackFn(stack, stackSize); 17441 } 17442 stackSize += validationCommand.stackDelta; 17443 } else if (validationCommand.stackClearing) { 17444 stackSize = 0; 17445 } else if (validationCommand.resetStack) { 17446 stackSize = 0; 17447 state.undefStack = false; 17448 } else if (validationCommand.undefStack) { 17449 stackSize = 0; 17450 state.undefStack = true; 17451 state.firstStackClearing = false; 17452 } 17453 } 17454 } 17455 if (length < data.length) { 17456 data.fill(14, length); 17457 } 17458 state.stackSize = stackSize; 17459 return true; 17460 } 17461 parseCharStrings({ 17462 charStrings, 17463 localSubrIndex, 17464 globalSubrIndex, 17465 fdSelect, 17466 fdArray, 17467 privateDict 17468 }) { 17469 const seacs = []; 17470 const widths = []; 17471 const count = charStrings.count; 17472 for (let i = 0; i < count; i++) { 17473 const charstring = charStrings.get(i); 17474 const state = { 17475 callDepth: 0, 17476 stackSize: 0, 17477 stack: [], 17478 undefStack: true, 17479 hints: 0, 17480 firstStackClearing: true, 17481 seac: null, 17482 width: null, 17483 hasVStems: false 17484 }; 17485 let valid = true; 17486 let localSubrToUse = null; 17487 let privateDictToUse = privateDict; 17488 if (fdSelect && fdArray.length) { 17489 const fdIndex = fdSelect.getFDIndex(i); 17490 if (fdIndex === -1) { 17491 warn("Glyph index is not in fd select."); 17492 valid = false; 17493 } 17494 if (fdIndex >= fdArray.length) { 17495 warn("Invalid fd index for glyph index."); 17496 valid = false; 17497 } 17498 if (valid) { 17499 privateDictToUse = fdArray[fdIndex].privateDict; 17500 localSubrToUse = privateDictToUse.subrsIndex; 17501 } 17502 } else if (localSubrIndex) { 17503 localSubrToUse = localSubrIndex; 17504 } 17505 if (valid) { 17506 valid = this.parseCharString(state, charstring, localSubrToUse, globalSubrIndex); 17507 } 17508 if (state.width !== null) { 17509 const nominalWidth = privateDictToUse.getByName("nominalWidthX"); 17510 widths[i] = nominalWidth + state.width; 17511 } else { 17512 const defaultWidth = privateDictToUse.getByName("defaultWidthX"); 17513 widths[i] = defaultWidth; 17514 } 17515 if (state.seac !== null) { 17516 seacs[i] = state.seac; 17517 } 17518 if (!valid) { 17519 charStrings.set(i, new Uint8Array([14])); 17520 } 17521 } 17522 return { 17523 charStrings, 17524 seacs, 17525 widths 17526 }; 17527 } 17528 emptyPrivateDictionary(parentDict) { 17529 const privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings); 17530 parentDict.setByKey(18, [0, 0]); 17531 parentDict.privateDict = privateDict; 17532 } 17533 parsePrivateDict(parentDict) { 17534 if (!parentDict.hasName("Private")) { 17535 this.emptyPrivateDictionary(parentDict); 17536 return; 17537 } 17538 const privateOffset = parentDict.getByName("Private"); 17539 if (!Array.isArray(privateOffset) || privateOffset.length !== 2) { 17540 parentDict.removeByName("Private"); 17541 return; 17542 } 17543 const size = privateOffset[0]; 17544 const offset = privateOffset[1]; 17545 if (size === 0 || offset >= this.bytes.length) { 17546 this.emptyPrivateDictionary(parentDict); 17547 return; 17548 } 17549 const privateDictEnd = offset + size; 17550 const dictData = this.bytes.subarray(offset, privateDictEnd); 17551 const dict = this.parseDict(dictData); 17552 const privateDict = this.createDict(CFFPrivateDict, dict, parentDict.strings); 17553 parentDict.privateDict = privateDict; 17554 if (privateDict.getByName("ExpansionFactor") === 0) { 17555 privateDict.setByName("ExpansionFactor", 0.06); 17556 } 17557 if (!privateDict.getByName("Subrs")) { 17558 return; 17559 } 17560 const subrsOffset = privateDict.getByName("Subrs"); 17561 const relativeOffset = offset + subrsOffset; 17562 if (subrsOffset === 0 || relativeOffset >= this.bytes.length) { 17563 this.emptyPrivateDictionary(parentDict); 17564 return; 17565 } 17566 const subrsIndex = this.parseIndex(relativeOffset); 17567 privateDict.subrsIndex = subrsIndex.obj; 17568 } 17569 parseCharsets(pos, length, strings, cid) { 17570 if (pos === 0) { 17571 return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE, ISOAdobeCharset); 17572 } else if (pos === 1) { 17573 return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT, ExpertCharset); 17574 } else if (pos === 2) { 17575 return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET, ExpertSubsetCharset); 17576 } 17577 const bytes = this.bytes; 17578 const start = pos; 17579 const format = bytes[pos++]; 17580 const charset = [cid ? 0 : ".notdef"]; 17581 let id, count, i; 17582 length -= 1; 17583 switch (format) { 17584 case 0: 17585 for (i = 0; i < length; i++) { 17586 id = bytes[pos++] << 8 | bytes[pos++]; 17587 charset.push(cid ? id : strings.get(id)); 17588 } 17589 break; 17590 case 1: 17591 while (charset.length <= length) { 17592 id = bytes[pos++] << 8 | bytes[pos++]; 17593 count = bytes[pos++]; 17594 for (i = 0; i <= count; i++) { 17595 charset.push(cid ? id++ : strings.get(id++)); 17596 } 17597 } 17598 break; 17599 case 2: 17600 while (charset.length <= length) { 17601 id = bytes[pos++] << 8 | bytes[pos++]; 17602 count = bytes[pos++] << 8 | bytes[pos++]; 17603 for (i = 0; i <= count; i++) { 17604 charset.push(cid ? id++ : strings.get(id++)); 17605 } 17606 } 17607 break; 17608 default: 17609 throw new FormatError("Unknown charset format"); 17610 } 17611 const end = pos; 17612 const raw = bytes.subarray(start, end); 17613 return new CFFCharset(false, format, charset, raw); 17614 } 17615 parseEncoding(pos, properties, strings, charset) { 17616 const encoding = Object.create(null); 17617 const bytes = this.bytes; 17618 let predefined = false; 17619 let format, i, ii; 17620 let raw = null; 17621 function readSupplement() { 17622 const supplementsCount = bytes[pos++]; 17623 for (i = 0; i < supplementsCount; i++) { 17624 const code = bytes[pos++]; 17625 const sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff); 17626 encoding[code] = charset.indexOf(strings.get(sid)); 17627 } 17628 } 17629 if (pos === 0 || pos === 1) { 17630 predefined = true; 17631 format = pos; 17632 const baseEncoding = pos ? ExpertEncoding : StandardEncoding; 17633 for (i = 0, ii = charset.length; i < ii; i++) { 17634 const index = baseEncoding.indexOf(charset[i]); 17635 if (index !== -1) { 17636 encoding[index] = i; 17637 } 17638 } 17639 } else { 17640 const dataStart = pos; 17641 format = bytes[pos++]; 17642 switch (format & 0x7f) { 17643 case 0: 17644 const glyphsCount = bytes[pos++]; 17645 for (i = 1; i <= glyphsCount; i++) { 17646 encoding[bytes[pos++]] = i; 17647 } 17648 break; 17649 case 1: 17650 const rangesCount = bytes[pos++]; 17651 let gid = 1; 17652 for (i = 0; i < rangesCount; i++) { 17653 const start = bytes[pos++]; 17654 const left = bytes[pos++]; 17655 for (let j = start; j <= start + left; j++) { 17656 encoding[j] = gid++; 17657 } 17658 } 17659 break; 17660 default: 17661 throw new FormatError(`Unknown encoding format: ${format} in CFF`); 17662 } 17663 const dataEnd = pos; 17664 if (format & 0x80) { 17665 bytes[dataStart] &= 0x7f; 17666 readSupplement(); 17667 } 17668 raw = bytes.subarray(dataStart, dataEnd); 17669 } 17670 format &= 0x7f; 17671 return new CFFEncoding(predefined, format, encoding, raw); 17672 } 17673 parseFDSelect(pos, length) { 17674 const bytes = this.bytes; 17675 const format = bytes[pos++]; 17676 const fdSelect = []; 17677 let i; 17678 switch (format) { 17679 case 0: 17680 for (i = 0; i < length; ++i) { 17681 const id = bytes[pos++]; 17682 fdSelect.push(id); 17683 } 17684 break; 17685 case 3: 17686 const rangesCount = bytes[pos++] << 8 | bytes[pos++]; 17687 for (i = 0; i < rangesCount; ++i) { 17688 let first = bytes[pos++] << 8 | bytes[pos++]; 17689 if (i === 0 && first !== 0) { 17690 warn("parseFDSelect: The first range must have a first GID of 0" + " -- trying to recover."); 17691 first = 0; 17692 } 17693 const fdIndex = bytes[pos++]; 17694 const next = bytes[pos] << 8 | bytes[pos + 1]; 17695 for (let j = first; j < next; ++j) { 17696 fdSelect.push(fdIndex); 17697 } 17698 } 17699 pos += 2; 17700 break; 17701 default: 17702 throw new FormatError(`parseFDSelect: Unknown format "${format}".`); 17703 } 17704 if (fdSelect.length !== length) { 17705 throw new FormatError("parseFDSelect: Invalid font data."); 17706 } 17707 return new CFFFDSelect(format, fdSelect); 17708 } 17709} 17710class CFF { 17711 constructor() { 17712 this.header = null; 17713 this.names = []; 17714 this.topDict = null; 17715 this.strings = new CFFStrings(); 17716 this.globalSubrIndex = null; 17717 this.encoding = null; 17718 this.charset = null; 17719 this.charStrings = null; 17720 this.fdArray = []; 17721 this.fdSelect = null; 17722 this.isCIDFont = false; 17723 } 17724 duplicateFirstGlyph() { 17725 if (this.charStrings.count >= 65535) { 17726 warn("Not enough space in charstrings to duplicate first glyph."); 17727 return; 17728 } 17729 const glyphZero = this.charStrings.get(0); 17730 this.charStrings.add(glyphZero); 17731 if (this.isCIDFont) { 17732 this.fdSelect.fdSelect.push(this.fdSelect.fdSelect[0]); 17733 } 17734 } 17735 hasGlyphId(id) { 17736 if (id < 0 || id >= this.charStrings.count) { 17737 return false; 17738 } 17739 const glyph = this.charStrings.get(id); 17740 return glyph.length > 0; 17741 } 17742} 17743class CFFHeader { 17744 constructor(major, minor, hdrSize, offSize) { 17745 this.major = major; 17746 this.minor = minor; 17747 this.hdrSize = hdrSize; 17748 this.offSize = offSize; 17749 } 17750} 17751class CFFStrings { 17752 constructor() { 17753 this.strings = []; 17754 } 17755 get(index) { 17756 if (index >= 0 && index <= NUM_STANDARD_CFF_STRINGS - 1) { 17757 return CFFStandardStrings[index]; 17758 } 17759 if (index - NUM_STANDARD_CFF_STRINGS <= this.strings.length) { 17760 return this.strings[index - NUM_STANDARD_CFF_STRINGS]; 17761 } 17762 return CFFStandardStrings[0]; 17763 } 17764 getSID(str) { 17765 let index = CFFStandardStrings.indexOf(str); 17766 if (index !== -1) { 17767 return index; 17768 } 17769 index = this.strings.indexOf(str); 17770 if (index !== -1) { 17771 return index + NUM_STANDARD_CFF_STRINGS; 17772 } 17773 return -1; 17774 } 17775 add(value) { 17776 this.strings.push(value); 17777 } 17778 get count() { 17779 return this.strings.length; 17780 } 17781} 17782class CFFIndex { 17783 constructor() { 17784 this.objects = []; 17785 this.length = 0; 17786 } 17787 add(data) { 17788 this.length += data.length; 17789 this.objects.push(data); 17790 } 17791 set(index, data) { 17792 this.length += data.length - this.objects[index].length; 17793 this.objects[index] = data; 17794 } 17795 get(index) { 17796 return this.objects[index]; 17797 } 17798 get count() { 17799 return this.objects.length; 17800 } 17801} 17802class CFFDict { 17803 constructor(tables, strings) { 17804 this.keyToNameMap = tables.keyToNameMap; 17805 this.nameToKeyMap = tables.nameToKeyMap; 17806 this.defaults = tables.defaults; 17807 this.types = tables.types; 17808 this.opcodes = tables.opcodes; 17809 this.order = tables.order; 17810 this.strings = strings; 17811 this.values = Object.create(null); 17812 } 17813 setByKey(key, value) { 17814 if (!(key in this.keyToNameMap)) { 17815 return false; 17816 } 17817 if (value.length === 0) { 17818 return true; 17819 } 17820 for (const val of value) { 17821 if (isNaN(val)) { 17822 warn(`Invalid CFFDict value: "${value}" for key "${key}".`); 17823 return true; 17824 } 17825 } 17826 const type = this.types[key]; 17827 if (type === "num" || type === "sid" || type === "offset") { 17828 value = value[0]; 17829 } 17830 this.values[key] = value; 17831 return true; 17832 } 17833 setByName(name, value) { 17834 if (!(name in this.nameToKeyMap)) { 17835 throw new FormatError(`Invalid dictionary name "${name}"`); 17836 } 17837 this.values[this.nameToKeyMap[name]] = value; 17838 } 17839 hasName(name) { 17840 return this.nameToKeyMap[name] in this.values; 17841 } 17842 getByName(name) { 17843 if (!(name in this.nameToKeyMap)) { 17844 throw new FormatError(`Invalid dictionary name ${name}"`); 17845 } 17846 const key = this.nameToKeyMap[name]; 17847 if (!(key in this.values)) { 17848 return this.defaults[key]; 17849 } 17850 return this.values[key]; 17851 } 17852 removeByName(name) { 17853 delete this.values[this.nameToKeyMap[name]]; 17854 } 17855 static createTables(layout) { 17856 const tables = { 17857 keyToNameMap: {}, 17858 nameToKeyMap: {}, 17859 defaults: {}, 17860 types: {}, 17861 opcodes: {}, 17862 order: [] 17863 }; 17864 for (const entry of layout) { 17865 const key = Array.isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0]; 17866 tables.keyToNameMap[key] = entry[1]; 17867 tables.nameToKeyMap[entry[1]] = key; 17868 tables.types[key] = entry[2]; 17869 tables.defaults[key] = entry[3]; 17870 tables.opcodes[key] = Array.isArray(entry[0]) ? entry[0] : [entry[0]]; 17871 tables.order.push(key); 17872 } 17873 return tables; 17874 } 17875} 17876const CFFTopDictLayout = [[[12, 30], "ROS", ["sid", "sid", "num"], null], [[12, 20], "SyntheticBase", "num", null], [0, "version", "sid", null], [1, "Notice", "sid", null], [[12, 0], "Copyright", "sid", null], [2, "FullName", "sid", null], [3, "FamilyName", "sid", null], [4, "Weight", "sid", null], [[12, 1], "isFixedPitch", "num", 0], [[12, 2], "ItalicAngle", "num", 0], [[12, 3], "UnderlinePosition", "num", -100], [[12, 4], "UnderlineThickness", "num", 50], [[12, 5], "PaintType", "num", 0], [[12, 6], "CharstringType", "num", 2], [[12, 7], "FontMatrix", ["num", "num", "num", "num", "num", "num"], [0.001, 0, 0, 0.001, 0, 0]], [13, "UniqueID", "num", null], [5, "FontBBox", ["num", "num", "num", "num"], [0, 0, 0, 0]], [[12, 8], "StrokeWidth", "num", 0], [14, "XUID", "array", null], [15, "charset", "offset", 0], [16, "Encoding", "offset", 0], [17, "CharStrings", "offset", 0], [18, "Private", ["offset", "offset"], null], [[12, 21], "PostScript", "sid", null], [[12, 22], "BaseFontName", "sid", null], [[12, 23], "BaseFontBlend", "delta", null], [[12, 31], "CIDFontVersion", "num", 0], [[12, 32], "CIDFontRevision", "num", 0], [[12, 33], "CIDFontType", "num", 0], [[12, 34], "CIDCount", "num", 8720], [[12, 35], "UIDBase", "num", null], [[12, 37], "FDSelect", "offset", null], [[12, 36], "FDArray", "offset", null], [[12, 38], "FontName", "sid", null]]; 17877class CFFTopDict extends CFFDict { 17878 static get tables() { 17879 return shadow(this, "tables", this.createTables(CFFTopDictLayout)); 17880 } 17881 constructor(strings) { 17882 super(CFFTopDict.tables, strings); 17883 this.privateDict = null; 17884 } 17885} 17886const CFFPrivateDictLayout = [[6, "BlueValues", "delta", null], [7, "OtherBlues", "delta", null], [8, "FamilyBlues", "delta", null], [9, "FamilyOtherBlues", "delta", null], [[12, 9], "BlueScale", "num", 0.039625], [[12, 10], "BlueShift", "num", 7], [[12, 11], "BlueFuzz", "num", 1], [10, "StdHW", "num", null], [11, "StdVW", "num", null], [[12, 12], "StemSnapH", "delta", null], [[12, 13], "StemSnapV", "delta", null], [[12, 14], "ForceBold", "num", 0], [[12, 17], "LanguageGroup", "num", 0], [[12, 18], "ExpansionFactor", "num", 0.06], [[12, 19], "initialRandomSeed", "num", 0], [20, "defaultWidthX", "num", 0], [21, "nominalWidthX", "num", 0], [19, "Subrs", "offset", null]]; 17887class CFFPrivateDict extends CFFDict { 17888 static get tables() { 17889 return shadow(this, "tables", this.createTables(CFFPrivateDictLayout)); 17890 } 17891 constructor(strings) { 17892 super(CFFPrivateDict.tables, strings); 17893 this.subrsIndex = null; 17894 } 17895} 17896const CFFCharsetPredefinedTypes = { 17897 ISO_ADOBE: 0, 17898 EXPERT: 1, 17899 EXPERT_SUBSET: 2 17900}; 17901class CFFCharset { 17902 constructor(predefined, format, charset, raw) { 17903 this.predefined = predefined; 17904 this.format = format; 17905 this.charset = charset; 17906 this.raw = raw; 17907 } 17908} 17909class CFFEncoding { 17910 constructor(predefined, format, encoding, raw) { 17911 this.predefined = predefined; 17912 this.format = format; 17913 this.encoding = encoding; 17914 this.raw = raw; 17915 } 17916} 17917class CFFFDSelect { 17918 constructor(format, fdSelect) { 17919 this.format = format; 17920 this.fdSelect = fdSelect; 17921 } 17922 getFDIndex(glyphIndex) { 17923 if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) { 17924 return -1; 17925 } 17926 return this.fdSelect[glyphIndex]; 17927 } 17928} 17929class CFFOffsetTracker { 17930 constructor() { 17931 this.offsets = Object.create(null); 17932 } 17933 isTracking(key) { 17934 return key in this.offsets; 17935 } 17936 track(key, location) { 17937 if (key in this.offsets) { 17938 throw new FormatError(`Already tracking location of ${key}`); 17939 } 17940 this.offsets[key] = location; 17941 } 17942 offset(value) { 17943 for (const key in this.offsets) { 17944 this.offsets[key] += value; 17945 } 17946 } 17947 setEntryLocation(key, values, output) { 17948 if (!(key in this.offsets)) { 17949 throw new FormatError(`Not tracking location of ${key}`); 17950 } 17951 const data = output.data; 17952 const dataOffset = this.offsets[key]; 17953 const size = 5; 17954 for (let i = 0, ii = values.length; i < ii; ++i) { 17955 const offset0 = i * size + dataOffset; 17956 const offset1 = offset0 + 1; 17957 const offset2 = offset0 + 2; 17958 const offset3 = offset0 + 3; 17959 const offset4 = offset0 + 4; 17960 if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) { 17961 throw new FormatError("writing to an offset that is not empty"); 17962 } 17963 const value = values[i]; 17964 data[offset0] = 0x1d; 17965 data[offset1] = value >> 24 & 0xff; 17966 data[offset2] = value >> 16 & 0xff; 17967 data[offset3] = value >> 8 & 0xff; 17968 data[offset4] = value & 0xff; 17969 } 17970 } 17971} 17972class CFFCompiler { 17973 constructor(cff) { 17974 this.cff = cff; 17975 } 17976 compile() { 17977 const cff = this.cff; 17978 const output = { 17979 data: [], 17980 length: 0, 17981 add(data) { 17982 try { 17983 this.data.push(...data); 17984 } catch { 17985 this.data = this.data.concat(data); 17986 } 17987 this.length = this.data.length; 17988 } 17989 }; 17990 const header = this.compileHeader(cff.header); 17991 output.add(header); 17992 const nameIndex = this.compileNameIndex(cff.names); 17993 output.add(nameIndex); 17994 if (cff.isCIDFont) { 17995 if (cff.topDict.hasName("FontMatrix")) { 17996 const base = cff.topDict.getByName("FontMatrix"); 17997 cff.topDict.removeByName("FontMatrix"); 17998 for (const subDict of cff.fdArray) { 17999 let matrix = base.slice(0); 18000 if (subDict.hasName("FontMatrix")) { 18001 matrix = Util.transform(matrix, subDict.getByName("FontMatrix")); 18002 } 18003 subDict.setByName("FontMatrix", matrix); 18004 } 18005 } 18006 } 18007 const xuid = cff.topDict.getByName("XUID"); 18008 if (xuid?.length > 16) { 18009 cff.topDict.removeByName("XUID"); 18010 } 18011 cff.topDict.setByName("charset", 0); 18012 let compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont); 18013 output.add(compiled.output); 18014 const topDictTracker = compiled.trackers[0]; 18015 const stringIndex = this.compileStringIndex(cff.strings.strings); 18016 output.add(stringIndex); 18017 const globalSubrIndex = this.compileIndex(cff.globalSubrIndex); 18018 output.add(globalSubrIndex); 18019 if (cff.encoding && cff.topDict.hasName("Encoding")) { 18020 if (cff.encoding.predefined) { 18021 topDictTracker.setEntryLocation("Encoding", [cff.encoding.format], output); 18022 } else { 18023 const encoding = this.compileEncoding(cff.encoding); 18024 topDictTracker.setEntryLocation("Encoding", [output.length], output); 18025 output.add(encoding); 18026 } 18027 } 18028 const charset = this.compileCharset(cff.charset, cff.charStrings.count, cff.strings, cff.isCIDFont); 18029 topDictTracker.setEntryLocation("charset", [output.length], output); 18030 output.add(charset); 18031 const charStrings = this.compileCharStrings(cff.charStrings); 18032 topDictTracker.setEntryLocation("CharStrings", [output.length], output); 18033 output.add(charStrings); 18034 if (cff.isCIDFont) { 18035 topDictTracker.setEntryLocation("FDSelect", [output.length], output); 18036 const fdSelect = this.compileFDSelect(cff.fdSelect); 18037 output.add(fdSelect); 18038 compiled = this.compileTopDicts(cff.fdArray, output.length, true); 18039 topDictTracker.setEntryLocation("FDArray", [output.length], output); 18040 output.add(compiled.output); 18041 const fontDictTrackers = compiled.trackers; 18042 this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output); 18043 } 18044 this.compilePrivateDicts([cff.topDict], [topDictTracker], output); 18045 output.add([0]); 18046 return output.data; 18047 } 18048 encodeNumber(value) { 18049 if (Number.isInteger(value)) { 18050 return this.encodeInteger(value); 18051 } 18052 return this.encodeFloat(value); 18053 } 18054 static get EncodeFloatRegExp() { 18055 return shadow(this, "EncodeFloatRegExp", /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/); 18056 } 18057 encodeFloat(num) { 18058 let value = num.toString(); 18059 const m = CFFCompiler.EncodeFloatRegExp.exec(value); 18060 if (m) { 18061 const epsilon = parseFloat("1e" + ((m[2] ? +m[2] : 0) + m[1].length)); 18062 value = (Math.round(num * epsilon) / epsilon).toString(); 18063 } 18064 let nibbles = ""; 18065 let i, ii; 18066 for (i = 0, ii = value.length; i < ii; ++i) { 18067 const a = value[i]; 18068 if (a === "e") { 18069 nibbles += value[++i] === "-" ? "c" : "b"; 18070 } else if (a === ".") { 18071 nibbles += "a"; 18072 } else if (a === "-") { 18073 nibbles += "e"; 18074 } else { 18075 nibbles += a; 18076 } 18077 } 18078 nibbles += nibbles.length & 1 ? "f" : "ff"; 18079 const out = [30]; 18080 for (i = 0, ii = nibbles.length; i < ii; i += 2) { 18081 out.push(parseInt(nibbles.substring(i, i + 2), 16)); 18082 } 18083 return out; 18084 } 18085 encodeInteger(value) { 18086 let code; 18087 if (value >= -107 && value <= 107) { 18088 code = [value + 139]; 18089 } else if (value >= 108 && value <= 1131) { 18090 value -= 108; 18091 code = [(value >> 8) + 247, value & 0xff]; 18092 } else if (value >= -1131 && value <= -108) { 18093 value = -value - 108; 18094 code = [(value >> 8) + 251, value & 0xff]; 18095 } else if (value >= -32768 && value <= 32767) { 18096 code = [0x1c, value >> 8 & 0xff, value & 0xff]; 18097 } else { 18098 code = [0x1d, value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff]; 18099 } 18100 return code; 18101 } 18102 compileHeader(header) { 18103 return [header.major, header.minor, 4, header.offSize]; 18104 } 18105 compileNameIndex(names) { 18106 const nameIndex = new CFFIndex(); 18107 for (const name of names) { 18108 const length = Math.min(name.length, 127); 18109 let sanitizedName = new Array(length); 18110 for (let j = 0; j < length; j++) { 18111 let char = name[j]; 18112 if (char < "!" || char > "~" || char === "[" || char === "]" || char === "(" || char === ")" || char === "{" || char === "}" || char === "<" || char === ">" || char === "/" || char === "%") { 18113 char = "_"; 18114 } 18115 sanitizedName[j] = char; 18116 } 18117 sanitizedName = sanitizedName.join(""); 18118 if (sanitizedName === "") { 18119 sanitizedName = "Bad_Font_Name"; 18120 } 18121 nameIndex.add(stringToBytes(sanitizedName)); 18122 } 18123 return this.compileIndex(nameIndex); 18124 } 18125 compileTopDicts(dicts, length, removeCidKeys) { 18126 const fontDictTrackers = []; 18127 let fdArrayIndex = new CFFIndex(); 18128 for (const fontDict of dicts) { 18129 if (removeCidKeys) { 18130 fontDict.removeByName("CIDFontVersion"); 18131 fontDict.removeByName("CIDFontRevision"); 18132 fontDict.removeByName("CIDFontType"); 18133 fontDict.removeByName("CIDCount"); 18134 fontDict.removeByName("UIDBase"); 18135 } 18136 const fontDictTracker = new CFFOffsetTracker(); 18137 const fontDictData = this.compileDict(fontDict, fontDictTracker); 18138 fontDictTrackers.push(fontDictTracker); 18139 fdArrayIndex.add(fontDictData); 18140 fontDictTracker.offset(length); 18141 } 18142 fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers); 18143 return { 18144 trackers: fontDictTrackers, 18145 output: fdArrayIndex 18146 }; 18147 } 18148 compilePrivateDicts(dicts, trackers, output) { 18149 for (let i = 0, ii = dicts.length; i < ii; ++i) { 18150 const fontDict = dicts[i]; 18151 const privateDict = fontDict.privateDict; 18152 if (!privateDict || !fontDict.hasName("Private")) { 18153 throw new FormatError("There must be a private dictionary."); 18154 } 18155 const privateDictTracker = new CFFOffsetTracker(); 18156 const privateDictData = this.compileDict(privateDict, privateDictTracker); 18157 let outputLength = output.length; 18158 privateDictTracker.offset(outputLength); 18159 if (!privateDictData.length) { 18160 outputLength = 0; 18161 } 18162 trackers[i].setEntryLocation("Private", [privateDictData.length, outputLength], output); 18163 output.add(privateDictData); 18164 if (privateDict.subrsIndex && privateDict.hasName("Subrs")) { 18165 const subrs = this.compileIndex(privateDict.subrsIndex); 18166 privateDictTracker.setEntryLocation("Subrs", [privateDictData.length], output); 18167 output.add(subrs); 18168 } 18169 } 18170 } 18171 compileDict(dict, offsetTracker) { 18172 const out = []; 18173 for (const key of dict.order) { 18174 if (!(key in dict.values)) { 18175 continue; 18176 } 18177 let values = dict.values[key]; 18178 let types = dict.types[key]; 18179 if (!Array.isArray(types)) { 18180 types = [types]; 18181 } 18182 if (!Array.isArray(values)) { 18183 values = [values]; 18184 } 18185 if (values.length === 0) { 18186 continue; 18187 } 18188 for (let j = 0, jj = types.length; j < jj; ++j) { 18189 const type = types[j]; 18190 const value = values[j]; 18191 switch (type) { 18192 case "num": 18193 case "sid": 18194 out.push(...this.encodeNumber(value)); 18195 break; 18196 case "offset": 18197 const name = dict.keyToNameMap[key]; 18198 if (!offsetTracker.isTracking(name)) { 18199 offsetTracker.track(name, out.length); 18200 } 18201 out.push(0x1d, 0, 0, 0, 0); 18202 break; 18203 case "array": 18204 case "delta": 18205 out.push(...this.encodeNumber(value)); 18206 for (let k = 1, kk = values.length; k < kk; ++k) { 18207 out.push(...this.encodeNumber(values[k])); 18208 } 18209 break; 18210 default: 18211 throw new FormatError(`Unknown data type of ${type}`); 18212 } 18213 } 18214 out.push(...dict.opcodes[key]); 18215 } 18216 return out; 18217 } 18218 compileStringIndex(strings) { 18219 const stringIndex = new CFFIndex(); 18220 for (const string of strings) { 18221 stringIndex.add(stringToBytes(string)); 18222 } 18223 return this.compileIndex(stringIndex); 18224 } 18225 compileCharStrings(charStrings) { 18226 const charStringsIndex = new CFFIndex(); 18227 for (let i = 0; i < charStrings.count; i++) { 18228 const glyph = charStrings.get(i); 18229 if (glyph.length === 0) { 18230 charStringsIndex.add(new Uint8Array([0x8b, 0x0e])); 18231 continue; 18232 } 18233 charStringsIndex.add(glyph); 18234 } 18235 return this.compileIndex(charStringsIndex); 18236 } 18237 compileCharset(charset, numGlyphs, strings, isCIDFont) { 18238 let out; 18239 const numGlyphsLessNotDef = numGlyphs - 1; 18240 if (isCIDFont) { 18241 const nLeft = numGlyphsLessNotDef - 1; 18242 out = new Uint8Array([2, 0, 1, nLeft >> 8 & 0xff, nLeft & 0xff]); 18243 } else { 18244 const length = 1 + numGlyphsLessNotDef * 2; 18245 out = new Uint8Array(length); 18246 out[0] = 0; 18247 let charsetIndex = 0; 18248 const numCharsets = charset.charset.length; 18249 let warned = false; 18250 for (let i = 1; i < out.length; i += 2) { 18251 let sid = 0; 18252 if (charsetIndex < numCharsets) { 18253 const name = charset.charset[charsetIndex++]; 18254 sid = strings.getSID(name); 18255 if (sid === -1) { 18256 sid = 0; 18257 if (!warned) { 18258 warned = true; 18259 warn(`Couldn't find ${name} in CFF strings`); 18260 } 18261 } 18262 } 18263 out[i] = sid >> 8 & 0xff; 18264 out[i + 1] = sid & 0xff; 18265 } 18266 } 18267 return this.compileTypedArray(out); 18268 } 18269 compileEncoding(encoding) { 18270 return this.compileTypedArray(encoding.raw); 18271 } 18272 compileFDSelect(fdSelect) { 18273 const format = fdSelect.format; 18274 let out, i; 18275 switch (format) { 18276 case 0: 18277 out = new Uint8Array(1 + fdSelect.fdSelect.length); 18278 out[0] = format; 18279 for (i = 0; i < fdSelect.fdSelect.length; i++) { 18280 out[i + 1] = fdSelect.fdSelect[i]; 18281 } 18282 break; 18283 case 3: 18284 const start = 0; 18285 let lastFD = fdSelect.fdSelect[0]; 18286 const ranges = [format, 0, 0, start >> 8 & 0xff, start & 0xff, lastFD]; 18287 for (i = 1; i < fdSelect.fdSelect.length; i++) { 18288 const currentFD = fdSelect.fdSelect[i]; 18289 if (currentFD !== lastFD) { 18290 ranges.push(i >> 8 & 0xff, i & 0xff, currentFD); 18291 lastFD = currentFD; 18292 } 18293 } 18294 const numRanges = (ranges.length - 3) / 3; 18295 ranges[1] = numRanges >> 8 & 0xff; 18296 ranges[2] = numRanges & 0xff; 18297 ranges.push(i >> 8 & 0xff, i & 0xff); 18298 out = new Uint8Array(ranges); 18299 break; 18300 } 18301 return this.compileTypedArray(out); 18302 } 18303 compileTypedArray(data) { 18304 return Array.from(data); 18305 } 18306 compileIndex(index, trackers = []) { 18307 const objects = index.objects; 18308 const count = objects.length; 18309 if (count === 0) { 18310 return [0, 0]; 18311 } 18312 const data = [count >> 8 & 0xff, count & 0xff]; 18313 let lastOffset = 1, 18314 i; 18315 for (i = 0; i < count; ++i) { 18316 lastOffset += objects[i].length; 18317 } 18318 let offsetSize; 18319 if (lastOffset < 0x100) { 18320 offsetSize = 1; 18321 } else if (lastOffset < 0x10000) { 18322 offsetSize = 2; 18323 } else if (lastOffset < 0x1000000) { 18324 offsetSize = 3; 18325 } else { 18326 offsetSize = 4; 18327 } 18328 data.push(offsetSize); 18329 let relativeOffset = 1; 18330 for (i = 0; i < count + 1; i++) { 18331 if (offsetSize === 1) { 18332 data.push(relativeOffset & 0xff); 18333 } else if (offsetSize === 2) { 18334 data.push(relativeOffset >> 8 & 0xff, relativeOffset & 0xff); 18335 } else if (offsetSize === 3) { 18336 data.push(relativeOffset >> 16 & 0xff, relativeOffset >> 8 & 0xff, relativeOffset & 0xff); 18337 } else { 18338 data.push(relativeOffset >>> 24 & 0xff, relativeOffset >> 16 & 0xff, relativeOffset >> 8 & 0xff, relativeOffset & 0xff); 18339 } 18340 if (objects[i]) { 18341 relativeOffset += objects[i].length; 18342 } 18343 } 18344 for (i = 0; i < count; i++) { 18345 if (trackers[i]) { 18346 trackers[i].offset(data.length); 18347 } 18348 data.push(...objects[i]); 18349 } 18350 return data; 18351 } 18352} 18353 18354;// ./src/core/standard_fonts.js 18355 18356 18357const getStdFontMap = getLookupTableFactory(function (t) { 18358 t["Times-Roman"] = "Times-Roman"; 18359 t.Helvetica = "Helvetica"; 18360 t.Courier = "Courier"; 18361 t.Symbol = "Symbol"; 18362 t["Times-Bold"] = "Times-Bold"; 18363 t["Helvetica-Bold"] = "Helvetica-Bold";
vendor: 4,595 bytes, lines 18364-18464
18364 t["Courier-Bold"] = "Courier-Bold"; 18365 t.ZapfDingbats = "ZapfDingbats"; 18366 t["Times-Italic"] = "Times-Italic"; 18367 t["Helvetica-Oblique"] = "Helvetica-Oblique"; 18368 t["Courier-Oblique"] = "Courier-Oblique"; 18369 t["Times-BoldItalic"] = "Times-BoldItalic"; 18370 t["Helvetica-BoldOblique"] = "Helvetica-BoldOblique"; 18371 t["Courier-BoldOblique"] = "Courier-BoldOblique"; 18372 t.ArialNarrow = "Helvetica"; 18373 t["ArialNarrow-Bold"] = "Helvetica-Bold"; 18374 t["ArialNarrow-BoldItalic"] = "Helvetica-BoldOblique"; 18375 t["ArialNarrow-Italic"] = "Helvetica-Oblique"; 18376 t.ArialBlack = "Helvetica"; 18377 t["ArialBlack-Bold"] = "Helvetica-Bold"; 18378 t["ArialBlack-BoldItalic"] = "Helvetica-BoldOblique"; 18379 t["ArialBlack-Italic"] = "Helvetica-Oblique"; 18380 t["Arial-Black"] = "Helvetica"; 18381 t["Arial-Black-Bold"] = "Helvetica-Bold"; 18382 t["Arial-Black-BoldItalic"] = "Helvetica-BoldOblique"; 18383 t["Arial-Black-Italic"] = "Helvetica-Oblique"; 18384 t.Arial = "Helvetica"; 18385 t["Arial-Bold"] = "Helvetica-Bold"; 18386 t["Arial-BoldItalic"] = "Helvetica-BoldOblique"; 18387 t["Arial-Italic"] = "Helvetica-Oblique"; 18388 t.ArialMT = "Helvetica"; 18389 t["Arial-BoldItalicMT"] = "Helvetica-BoldOblique"; 18390 t["Arial-BoldMT"] = "Helvetica-Bold"; 18391 t["Arial-ItalicMT"] = "Helvetica-Oblique"; 18392 t["Arial-BoldItalicMT-BoldItalic"] = "Helvetica-BoldOblique"; 18393 t["Arial-BoldMT-Bold"] = "Helvetica-Bold"; 18394 t["Arial-ItalicMT-Italic"] = "Helvetica-Oblique"; 18395 t.ArialUnicodeMS = "Helvetica"; 18396 t["ArialUnicodeMS-Bold"] = "Helvetica-Bold"; 18397 t["ArialUnicodeMS-BoldItalic"] = "Helvetica-BoldOblique"; 18398 t["ArialUnicodeMS-Italic"] = "Helvetica-Oblique"; 18399 t["Courier-BoldItalic"] = "Courier-BoldOblique"; 18400 t["Courier-Italic"] = "Courier-Oblique"; 18401 t.CourierNew = "Courier"; 18402 t["CourierNew-Bold"] = "Courier-Bold"; 18403 t["CourierNew-BoldItalic"] = "Courier-BoldOblique"; 18404 t["CourierNew-Italic"] = "Courier-Oblique"; 18405 t["CourierNewPS-BoldItalicMT"] = "Courier-BoldOblique"; 18406 t["CourierNewPS-BoldMT"] = "Courier-Bold"; 18407 t["CourierNewPS-ItalicMT"] = "Courier-Oblique"; 18408 t.CourierNewPSMT = "Courier"; 18409 t["Helvetica-BoldItalic"] = "Helvetica-BoldOblique"; 18410 t["Helvetica-Italic"] = "Helvetica-Oblique"; 18411 t["HelveticaLTStd-Bold"] = "Helvetica-Bold"; 18412 t["Symbol-Bold"] = "Symbol"; 18413 t["Symbol-BoldItalic"] = "Symbol"; 18414 t["Symbol-Italic"] = "Symbol"; 18415 t.TimesNewRoman = "Times-Roman"; 18416 t["TimesNewRoman-Bold"] = "Times-Bold"; 18417 t["TimesNewRoman-BoldItalic"] = "Times-BoldItalic"; 18418 t["TimesNewRoman-Italic"] = "Times-Italic"; 18419 t.TimesNewRomanPS = "Times-Roman"; 18420 t["TimesNewRomanPS-Bold"] = "Times-Bold"; 18421 t["TimesNewRomanPS-BoldItalic"] = "Times-BoldItalic"; 18422 t["TimesNewRomanPS-BoldItalicMT"] = "Times-BoldItalic"; 18423 t["TimesNewRomanPS-BoldMT"] = "Times-Bold"; 18424 t["TimesNewRomanPS-Italic"] = "Times-Italic"; 18425 t["TimesNewRomanPS-ItalicMT"] = "Times-Italic"; 18426 t.TimesNewRomanPSMT = "Times-Roman"; 18427 t["TimesNewRomanPSMT-Bold"] = "Times-Bold"; 18428 t["TimesNewRomanPSMT-BoldItalic"] = "Times-BoldItalic"; 18429 t["TimesNewRomanPSMT-Italic"] = "Times-Italic"; 18430}); 18431const getFontNameToFileMap = getLookupTableFactory(function (t) { 18432 t.Courier = "FoxitFixed.pfb"; 18433 t["Courier-Bold"] = "FoxitFixedBold.pfb"; 18434 t["Courier-BoldOblique"] = "FoxitFixedBoldItalic.pfb"; 18435 t["Courier-Oblique"] = "FoxitFixedItalic.pfb"; 18436 t.Helvetica = "LiberationSans-Regular.ttf"; 18437 t["Helvetica-Bold"] = "LiberationSans-Bold.ttf"; 18438 t["Helvetica-BoldOblique"] = "LiberationSans-BoldItalic.ttf"; 18439 t["Helvetica-Oblique"] = "LiberationSans-Italic.ttf"; 18440 t["Times-Roman"] = "FoxitSerif.pfb"; 18441 t["Times-Bold"] = "FoxitSerifBold.pfb"; 18442 t["Times-BoldItalic"] = "FoxitSerifBoldItalic.pfb"; 18443 t["Times-Italic"] = "FoxitSerifItalic.pfb"; 18444 t.Symbol = "FoxitSymbol.pfb"; 18445 t.ZapfDingbats = "FoxitDingbats.pfb"; 18446 t["LiberationSans-Regular"] = "LiberationSans-Regular.ttf"; 18447 t["LiberationSans-Bold"] = "LiberationSans-Bold.ttf"; 18448 t["LiberationSans-Italic"] = "LiberationSans-Italic.ttf"; 18449 t["LiberationSans-BoldItalic"] = "LiberationSans-BoldItalic.ttf"; 18450}); 18451const getNonStdFontMap = getLookupTableFactory(function (t) { 18452 t.Calibri = "Helvetica"; 18453 t["Calibri-Bold"] = "Helvetica-Bold"; 18454 t["Calibri-BoldItalic"] = "Helvetica-BoldOblique"; 18455 t["Calibri-Italic"] = "Helvetica-Oblique"; 18456 t.CenturyGothic = "Helvetica"; 18457 t["CenturyGothic-Bold"] = "Helvetica-Bold"; 18458 t["CenturyGothic-BoldItalic"] = "Helvetica-BoldOblique"; 18459 t["CenturyGothic-Italic"] = "Helvetica-Oblique"; 18460 t.ComicSansMS = "Comic Sans MS"; 18461 t["ComicSansMS-Bold"] = "Comic Sans MS-Bold"; 18462 t["ComicSansMS-BoldItalic"] = "Comic Sans MS-BoldItalic"; 18463 t["ComicSansMS-Italic"] = "Comic Sans MS-Italic"; 18464 t.GillSansMT = "Helvetica";
vendor: 42,567 bytes, lines 18465-20210
18465 t["GillSansMT-Bold"] = "Helvetica-Bold"; 18466 t["GillSansMT-BoldItalic"] = "Helvetica-BoldOblique"; 18467 t["GillSansMT-Italic"] = "Helvetica-Oblique"; 18468 t.Impact = "Helvetica"; 18469 t["ItcSymbol-Bold"] = "Helvetica-Bold"; 18470 t["ItcSymbol-BoldItalic"] = "Helvetica-BoldOblique"; 18471 t["ItcSymbol-Book"] = "Helvetica"; 18472 t["ItcSymbol-BookItalic"] = "Helvetica-Oblique"; 18473 t["ItcSymbol-Medium"] = "Helvetica"; 18474 t["ItcSymbol-MediumItalic"] = "Helvetica-Oblique"; 18475 t.LucidaConsole = "Courier"; 18476 t["LucidaConsole-Bold"] = "Courier-Bold"; 18477 t["LucidaConsole-BoldItalic"] = "Courier-BoldOblique"; 18478 t["LucidaConsole-Italic"] = "Courier-Oblique"; 18479 t["LucidaSans-Demi"] = "Helvetica-Bold"; 18480 t["MS-Gothic"] = "MS Gothic"; 18481 t["MS-Gothic-Bold"] = "MS Gothic-Bold"; 18482 t["MS-Gothic-BoldItalic"] = "MS Gothic-BoldItalic"; 18483 t["MS-Gothic-Italic"] = "MS Gothic-Italic"; 18484 t["MS-Mincho"] = "MS Mincho"; 18485 t["MS-Mincho-Bold"] = "MS Mincho-Bold"; 18486 t["MS-Mincho-BoldItalic"] = "MS Mincho-BoldItalic"; 18487 t["MS-Mincho-Italic"] = "MS Mincho-Italic"; 18488 t["MS-PGothic"] = "MS PGothic"; 18489 t["MS-PGothic-Bold"] = "MS PGothic-Bold"; 18490 t["MS-PGothic-BoldItalic"] = "MS PGothic-BoldItalic"; 18491 t["MS-PGothic-Italic"] = "MS PGothic-Italic"; 18492 t["MS-PMincho"] = "MS PMincho"; 18493 t["MS-PMincho-Bold"] = "MS PMincho-Bold"; 18494 t["MS-PMincho-BoldItalic"] = "MS PMincho-BoldItalic"; 18495 t["MS-PMincho-Italic"] = "MS PMincho-Italic"; 18496 t.NuptialScript = "Times-Italic"; 18497 t.SegoeUISymbol = "Helvetica"; 18498}); 18499const getSerifFonts = getLookupTableFactory(function (t) { 18500 t["Adobe Jenson"] = true; 18501 t["Adobe Text"] = true; 18502 t.Albertus = true; 18503 t.Aldus = true; 18504 t.Alexandria = true; 18505 t.Algerian = true; 18506 t["American Typewriter"] = true; 18507 t.Antiqua = true; 18508 t.Apex = true; 18509 t.Arno = true; 18510 t.Aster = true; 18511 t.Aurora = true; 18512 t.Baskerville = true; 18513 t.Bell = true; 18514 t.Bembo = true; 18515 t["Bembo Schoolbook"] = true; 18516 t.Benguiat = true; 18517 t["Berkeley Old Style"] = true; 18518 t["Bernhard Modern"] = true; 18519 t["Berthold City"] = true; 18520 t.Bodoni = true; 18521 t["Bauer Bodoni"] = true; 18522 t["Book Antiqua"] = true; 18523 t.Bookman = true; 18524 t["Bordeaux Roman"] = true; 18525 t["Californian FB"] = true; 18526 t.Calisto = true; 18527 t.Calvert = true; 18528 t.Capitals = true; 18529 t.Cambria = true; 18530 t.Cartier = true; 18531 t.Caslon = true; 18532 t.Catull = true; 18533 t.Centaur = true; 18534 t["Century Old Style"] = true; 18535 t["Century Schoolbook"] = true; 18536 t.Chaparral = true; 18537 t["Charis SIL"] = true; 18538 t.Cheltenham = true; 18539 t["Cholla Slab"] = true; 18540 t.Clarendon = true; 18541 t.Clearface = true; 18542 t.Cochin = true; 18543 t.Colonna = true; 18544 t["Computer Modern"] = true; 18545 t["Concrete Roman"] = true; 18546 t.Constantia = true; 18547 t["Cooper Black"] = true; 18548 t.Corona = true; 18549 t.Ecotype = true; 18550 t.Egyptienne = true; 18551 t.Elephant = true; 18552 t.Excelsior = true; 18553 t.Fairfield = true; 18554 t["FF Scala"] = true; 18555 t.Folkard = true; 18556 t.Footlight = true; 18557 t.FreeSerif = true; 18558 t["Friz Quadrata"] = true; 18559 t.Garamond = true; 18560 t.Gentium = true; 18561 t.Georgia = true; 18562 t.Gloucester = true; 18563 t["Goudy Old Style"] = true; 18564 t["Goudy Schoolbook"] = true; 18565 t["Goudy Pro Font"] = true; 18566 t.Granjon = true; 18567 t["Guardian Egyptian"] = true; 18568 t.Heather = true; 18569 t.Hercules = true; 18570 t["High Tower Text"] = true; 18571 t.Hiroshige = true; 18572 t["Hoefler Text"] = true; 18573 t["Humana Serif"] = true; 18574 t.Imprint = true; 18575 t["Ionic No. 5"] = true; 18576 t.Janson = true; 18577 t.Joanna = true; 18578 t.Korinna = true; 18579 t.Lexicon = true; 18580 t.LiberationSerif = true; 18581 t["Liberation Serif"] = true; 18582 t["Linux Libertine"] = true; 18583 t.Literaturnaya = true; 18584 t.Lucida = true; 18585 t["Lucida Bright"] = true; 18586 t.Melior = true; 18587 t.Memphis = true; 18588 t.Miller = true; 18589 t.Minion = true; 18590 t.Modern = true; 18591 t["Mona Lisa"] = true; 18592 t["Mrs Eaves"] = true; 18593 t["MS Serif"] = true; 18594 t["Museo Slab"] = true; 18595 t["New York"] = true; 18596 t["Nimbus Roman"] = true; 18597 t["NPS Rawlinson Roadway"] = true; 18598 t.NuptialScript = true; 18599 t.Palatino = true; 18600 t.Perpetua = true; 18601 t.Plantin = true; 18602 t["Plantin Schoolbook"] = true; 18603 t.Playbill = true; 18604 t["Poor Richard"] = true; 18605 t["Rawlinson Roadway"] = true; 18606 t.Renault = true; 18607 t.Requiem = true; 18608 t.Rockwell = true; 18609 t.Roman = true; 18610 t["Rotis Serif"] = true; 18611 t.Sabon = true; 18612 t.Scala = true; 18613 t.Seagull = true; 18614 t.Sistina = true; 18615 t.Souvenir = true; 18616 t.STIX = true; 18617 t["Stone Informal"] = true; 18618 t["Stone Serif"] = true; 18619 t.Sylfaen = true; 18620 t.Times = true; 18621 t.Trajan = true; 18622 t["Trinité"] = true; 18623 t["Trump Mediaeval"] = true; 18624 t.Utopia = true; 18625 t["Vale Type"] = true; 18626 t["Bitstream Vera"] = true; 18627 t["Vera Serif"] = true; 18628 t.Versailles = true; 18629 t.Wanted = true; 18630 t.Weiss = true; 18631 t["Wide Latin"] = true; 18632 t.Windsor = true; 18633 t.XITS = true; 18634}); 18635const getSymbolsFonts = getLookupTableFactory(function (t) { 18636 t.Dingbats = true; 18637 t.Symbol = true; 18638 t.ZapfDingbats = true; 18639 t.Wingdings = true; 18640 t["Wingdings-Bold"] = true; 18641 t["Wingdings-Regular"] = true; 18642}); 18643const getGlyphMapForStandardFonts = getLookupTableFactory(function (t) { 18644 t[2] = 10; 18645 t[3] = 32; 18646 t[4] = 33; 18647 t[5] = 34; 18648 t[6] = 35; 18649 t[7] = 36; 18650 t[8] = 37; 18651 t[9] = 38; 18652 t[10] = 39; 18653 t[11] = 40; 18654 t[12] = 41; 18655 t[13] = 42; 18656 t[14] = 43; 18657 t[15] = 44; 18658 t[16] = 45; 18659 t[17] = 46; 18660 t[18] = 47; 18661 t[19] = 48; 18662 t[20] = 49; 18663 t[21] = 50; 18664 t[22] = 51; 18665 t[23] = 52; 18666 t[24] = 53; 18667 t[25] = 54; 18668 t[26] = 55; 18669 t[27] = 56; 18670 t[28] = 57; 18671 t[29] = 58; 18672 t[30] = 894; 18673 t[31] = 60; 18674 t[32] = 61; 18675 t[33] = 62; 18676 t[34] = 63; 18677 t[35] = 64; 18678 t[36] = 65; 18679 t[37] = 66; 18680 t[38] = 67; 18681 t[39] = 68; 18682 t[40] = 69; 18683 t[41] = 70; 18684 t[42] = 71; 18685 t[43] = 72; 18686 t[44] = 73; 18687 t[45] = 74; 18688 t[46] = 75; 18689 t[47] = 76; 18690 t[48] = 77; 18691 t[49] = 78; 18692 t[50] = 79; 18693 t[51] = 80; 18694 t[52] = 81; 18695 t[53] = 82; 18696 t[54] = 83; 18697 t[55] = 84; 18698 t[56] = 85; 18699 t[57] = 86; 18700 t[58] = 87; 18701 t[59] = 88; 18702 t[60] = 89; 18703 t[61] = 90; 18704 t[62] = 91; 18705 t[63] = 92; 18706 t[64] = 93; 18707 t[65] = 94; 18708 t[66] = 95; 18709 t[67] = 96; 18710 t[68] = 97; 18711 t[69] = 98; 18712 t[70] = 99; 18713 t[71] = 100; 18714 t[72] = 101; 18715 t[73] = 102; 18716 t[74] = 103; 18717 t[75] = 104; 18718 t[76] = 105; 18719 t[77] = 106; 18720 t[78] = 107; 18721 t[79] = 108; 18722 t[80] = 109; 18723 t[81] = 110; 18724 t[82] = 111; 18725 t[83] = 112; 18726 t[84] = 113; 18727 t[85] = 114; 18728 t[86] = 115; 18729 t[87] = 116; 18730 t[88] = 117; 18731 t[89] = 118; 18732 t[90] = 119; 18733 t[91] = 120; 18734 t[92] = 121; 18735 t[93] = 122; 18736 t[94] = 123; 18737 t[95] = 124; 18738 t[96] = 125; 18739 t[97] = 126; 18740 t[98] = 196; 18741 t[99] = 197; 18742 t[100] = 199; 18743 t[101] = 201; 18744 t[102] = 209; 18745 t[103] = 214; 18746 t[104] = 220; 18747 t[105] = 225; 18748 t[106] = 224; 18749 t[107] = 226; 18750 t[108] = 228; 18751 t[109] = 227; 18752 t[110] = 229; 18753 t[111] = 231; 18754 t[112] = 233; 18755 t[113] = 232; 18756 t[114] = 234; 18757 t[115] = 235; 18758 t[116] = 237; 18759 t[117] = 236; 18760 t[118] = 238; 18761 t[119] = 239; 18762 t[120] = 241; 18763 t[121] = 243; 18764 t[122] = 242; 18765 t[123] = 244; 18766 t[124] = 246; 18767 t[125] = 245; 18768 t[126] = 250; 18769 t[127] = 249; 18770 t[128] = 251; 18771 t[129] = 252; 18772 t[130] = 8224; 18773 t[131] = 176; 18774 t[132] = 162; 18775 t[133] = 163; 18776 t[134] = 167; 18777 t[135] = 8226; 18778 t[136] = 182; 18779 t[137] = 223; 18780 t[138] = 174; 18781 t[139] = 169; 18782 t[140] = 8482; 18783 t[141] = 180; 18784 t[142] = 168; 18785 t[143] = 8800; 18786 t[144] = 198; 18787 t[145] = 216; 18788 t[146] = 8734; 18789 t[147] = 177; 18790 t[148] = 8804; 18791 t[149] = 8805; 18792 t[150] = 165; 18793 t[151] = 181; 18794 t[152] = 8706; 18795 t[153] = 8721; 18796 t[154] = 8719; 18797 t[156] = 8747; 18798 t[157] = 170; 18799 t[158] = 186; 18800 t[159] = 8486; 18801 t[160] = 230; 18802 t[161] = 248; 18803 t[162] = 191; 18804 t[163] = 161; 18805 t[164] = 172; 18806 t[165] = 8730; 18807 t[166] = 402; 18808 t[167] = 8776; 18809 t[168] = 8710; 18810 t[169] = 171; 18811 t[170] = 187; 18812 t[171] = 8230; 18813 t[179] = 8220; 18814 t[180] = 8221; 18815 t[181] = 8216; 18816 t[182] = 8217; 18817 t[200] = 193; 18818 t[203] = 205; 18819 t[207] = 211; 18820 t[210] = 218; 18821 t[223] = 711; 18822 t[224] = 321; 18823 t[225] = 322; 18824 t[226] = 352; 18825 t[227] = 353; 18826 t[228] = 381; 18827 t[229] = 382; 18828 t[233] = 221; 18829 t[234] = 253; 18830 t[252] = 263; 18831 t[253] = 268; 18832 t[254] = 269; 18833 t[258] = 258; 18834 t[260] = 260; 18835 t[261] = 261; 18836 t[265] = 280; 18837 t[266] = 281; 18838 t[267] = 282; 18839 t[268] = 283; 18840 t[269] = 313; 18841 t[275] = 323; 18842 t[276] = 324; 18843 t[278] = 328; 18844 t[283] = 344; 18845 t[284] = 345; 18846 t[285] = 346; 18847 t[286] = 347; 18848 t[292] = 367; 18849 t[295] = 377; 18850 t[296] = 378; 18851 t[298] = 380; 18852 t[305] = 963; 18853 t[306] = 964; 18854 t[307] = 966; 18855 t[308] = 8215; 18856 t[309] = 8252; 18857 t[310] = 8319; 18858 t[311] = 8359; 18859 t[312] = 8592; 18860 t[313] = 8593; 18861 t[337] = 9552; 18862 t[493] = 1039; 18863 t[494] = 1040; 18864 t[570] = 1040; 18865 t[571] = 1041; 18866 t[572] = 1042; 18867 t[573] = 1043; 18868 t[574] = 1044; 18869 t[575] = 1045; 18870 t[576] = 1046; 18871 t[577] = 1047; 18872 t[578] = 1048; 18873 t[579] = 1049; 18874 t[580] = 1050; 18875 t[581] = 1051; 18876 t[582] = 1052; 18877 t[583] = 1053; 18878 t[584] = 1054; 18879 t[585] = 1055; 18880 t[586] = 1056; 18881 t[587] = 1057; 18882 t[588] = 1058; 18883 t[589] = 1059; 18884 t[590] = 1060; 18885 t[591] = 1061; 18886 t[592] = 1062; 18887 t[593] = 1063; 18888 t[594] = 1064; 18889 t[595] = 1065; 18890 t[596] = 1066; 18891 t[597] = 1067; 18892 t[598] = 1068; 18893 t[599] = 1069; 18894 t[600] = 1070; 18895 t[672] = 1488; 18896 t[673] = 1489; 18897 t[674] = 1490; 18898 t[675] = 1491; 18899 t[676] = 1492; 18900 t[677] = 1493; 18901 t[678] = 1494; 18902 t[679] = 1495; 18903 t[680] = 1496; 18904 t[681] = 1497; 18905 t[682] = 1498; 18906 t[683] = 1499; 18907 t[684] = 1500; 18908 t[685] = 1501; 18909 t[686] = 1502; 18910 t[687] = 1503; 18911 t[688] = 1504; 18912 t[689] = 1505; 18913 t[690] = 1506; 18914 t[691] = 1507; 18915 t[692] = 1508; 18916 t[693] = 1509; 18917 t[694] = 1510; 18918 t[695] = 1511; 18919 t[696] = 1512; 18920 t[697] = 1513; 18921 t[698] = 1514; 18922 t[705] = 1524; 18923 t[706] = 8362; 18924 t[710] = 64288; 18925 t[711] = 64298; 18926 t[759] = 1617; 18927 t[761] = 1776; 18928 t[763] = 1778; 18929 t[775] = 1652; 18930 t[777] = 1764; 18931 t[778] = 1780; 18932 t[779] = 1781; 18933 t[780] = 1782; 18934 t[782] = 771; 18935 t[783] = 64726; 18936 t[786] = 8363; 18937 t[788] = 8532; 18938 t[790] = 768; 18939 t[791] = 769; 18940 t[792] = 768; 18941 t[795] = 803; 18942 t[797] = 64336; 18943 t[798] = 64337; 18944 t[799] = 64342; 18945 t[800] = 64343; 18946 t[801] = 64344; 18947 t[802] = 64345; 18948 t[803] = 64362; 18949 t[804] = 64363; 18950 t[805] = 64364; 18951 t[2424] = 7821; 18952 t[2425] = 7822; 18953 t[2426] = 7823; 18954 t[2427] = 7824; 18955 t[2428] = 7825; 18956 t[2429] = 7826; 18957 t[2430] = 7827; 18958 t[2433] = 7682; 18959 t[2678] = 8045; 18960 t[2679] = 8046; 18961 t[2830] = 1552; 18962 t[2838] = 686; 18963 t[2840] = 751; 18964 t[2842] = 753; 18965 t[2843] = 754; 18966 t[2844] = 755; 18967 t[2846] = 757; 18968 t[2856] = 767; 18969 t[2857] = 848; 18970 t[2858] = 849; 18971 t[2862] = 853; 18972 t[2863] = 854; 18973 t[2864] = 855; 18974 t[2865] = 861; 18975 t[2866] = 862; 18976 t[2906] = 7460; 18977 t[2908] = 7462; 18978 t[2909] = 7463; 18979 t[2910] = 7464; 18980 t[2912] = 7466; 18981 t[2913] = 7467; 18982 t[2914] = 7468; 18983 t[2916] = 7470; 18984 t[2917] = 7471; 18985 t[2918] = 7472; 18986 t[2920] = 7474; 18987 t[2921] = 7475; 18988 t[2922] = 7476; 18989 t[2924] = 7478; 18990 t[2925] = 7479; 18991 t[2926] = 7480; 18992 t[2928] = 7482; 18993 t[2929] = 7483; 18994 t[2930] = 7484; 18995 t[2932] = 7486; 18996 t[2933] = 7487; 18997 t[2934] = 7488; 18998 t[2936] = 7490; 18999 t[2937] = 7491; 19000 t[2938] = 7492; 19001 t[2940] = 7494; 19002 t[2941] = 7495; 19003 t[2942] = 7496; 19004 t[2944] = 7498; 19005 t[2946] = 7500; 19006 t[2948] = 7502; 19007 t[2950] = 7504; 19008 t[2951] = 7505; 19009 t[2952] = 7506; 19010 t[2954] = 7508; 19011 t[2955] = 7509; 19012 t[2956] = 7510; 19013 t[2958] = 7512; 19014 t[2959] = 7513; 19015 t[2960] = 7514; 19016 t[2962] = 7516; 19017 t[2963] = 7517; 19018 t[2964] = 7518; 19019 t[2966] = 7520; 19020 t[2967] = 7521; 19021 t[2968] = 7522; 19022 t[2970] = 7524; 19023 t[2971] = 7525; 19024 t[2972] = 7526; 19025 t[2974] = 7528; 19026 t[2975] = 7529; 19027 t[2976] = 7530; 19028 t[2978] = 1537; 19029 t[2979] = 1538; 19030 t[2980] = 1539; 19031 t[2982] = 1549; 19032 t[2983] = 1551; 19033 t[2984] = 1552; 19034 t[2986] = 1554; 19035 t[2987] = 1555; 19036 t[2988] = 1556; 19037 t[2990] = 1623; 19038 t[2991] = 1624; 19039 t[2995] = 1775; 19040 t[2999] = 1791; 19041 t[3002] = 64290; 19042 t[3003] = 64291; 19043 t[3004] = 64292; 19044 t[3006] = 64294; 19045 t[3007] = 64295; 19046 t[3008] = 64296; 19047 t[3011] = 1900; 19048 t[3014] = 8223; 19049 t[3015] = 8244; 19050 t[3017] = 7532; 19051 t[3018] = 7533; 19052 t[3019] = 7534; 19053 t[3075] = 7590; 19054 t[3076] = 7591; 19055 t[3079] = 7594; 19056 t[3080] = 7595; 19057 t[3083] = 7598; 19058 t[3084] = 7599; 19059 t[3087] = 7602; 19060 t[3088] = 7603; 19061 t[3091] = 7606; 19062 t[3092] = 7607; 19063 t[3095] = 7610; 19064 t[3096] = 7611; 19065 t[3099] = 7614; 19066 t[3100] = 7615; 19067 t[3103] = 7618; 19068 t[3104] = 7619; 19069 t[3107] = 8337; 19070 t[3108] = 8338; 19071 t[3116] = 1884; 19072 t[3119] = 1885; 19073 t[3120] = 1885; 19074 t[3123] = 1886; 19075 t[3124] = 1886; 19076 t[3127] = 1887; 19077 t[3128] = 1887; 19078 t[3131] = 1888; 19079 t[3132] = 1888; 19080 t[3135] = 1889; 19081 t[3136] = 1889; 19082 t[3139] = 1890; 19083 t[3140] = 1890; 19084 t[3143] = 1891; 19085 t[3144] = 1891; 19086 t[3147] = 1892; 19087 t[3148] = 1892; 19088 t[3153] = 580; 19089 t[3154] = 581; 19090 t[3157] = 584; 19091 t[3158] = 585; 19092 t[3161] = 588; 19093 t[3162] = 589; 19094 t[3165] = 891; 19095 t[3166] = 892; 19096 t[3169] = 1274; 19097 t[3170] = 1275; 19098 t[3173] = 1278; 19099 t[3174] = 1279; 19100 t[3181] = 7622; 19101 t[3182] = 7623; 19102 t[3282] = 11799; 19103 t[3316] = 578; 19104 t[3379] = 42785; 19105 t[3393] = 1159; 19106 t[3416] = 8377; 19107}); 19108const getSupplementalGlyphMapForArialBlack = getLookupTableFactory(function (t) { 19109 t[227] = 322; 19110 t[264] = 261; 19111 t[291] = 346; 19112}); 19113const getSupplementalGlyphMapForCalibri = getLookupTableFactory(function (t) { 19114 t[1] = 32; 19115 t[4] = 65; 19116 t[5] = 192; 19117 t[6] = 193; 19118 t[9] = 196; 19119 t[17] = 66; 19120 t[18] = 67; 19121 t[21] = 268; 19122 t[24] = 68; 19123 t[28] = 69; 19124 t[29] = 200; 19125 t[30] = 201; 19126 t[32] = 282; 19127 t[38] = 70; 19128 t[39] = 71; 19129 t[44] = 72; 19130 t[47] = 73; 19131 t[48] = 204; 19132 t[49] = 205; 19133 t[58] = 74; 19134 t[60] = 75; 19135 t[62] = 76; 19136 t[68] = 77; 19137 t[69] = 78; 19138 t[75] = 79; 19139 t[76] = 210; 19140 t[80] = 214; 19141 t[87] = 80; 19142 t[89] = 81; 19143 t[90] = 82; 19144 t[92] = 344; 19145 t[94] = 83; 19146 t[97] = 352; 19147 t[100] = 84; 19148 t[104] = 85; 19149 t[109] = 220; 19150 t[115] = 86; 19151 t[116] = 87; 19152 t[121] = 88; 19153 t[122] = 89; 19154 t[124] = 221; 19155 t[127] = 90; 19156 t[129] = 381; 19157 t[258] = 97; 19158 t[259] = 224; 19159 t[260] = 225; 19160 t[263] = 228; 19161 t[268] = 261; 19162 t[271] = 98; 19163 t[272] = 99; 19164 t[273] = 263; 19165 t[275] = 269; 19166 t[282] = 100; 19167 t[286] = 101; 19168 t[287] = 232; 19169 t[288] = 233; 19170 t[290] = 283; 19171 t[295] = 281; 19172 t[296] = 102; 19173 t[336] = 103; 19174 t[346] = 104; 19175 t[349] = 105; 19176 t[350] = 236; 19177 t[351] = 237; 19178 t[361] = 106; 19179 t[364] = 107; 19180 t[367] = 108; 19181 t[371] = 322; 19182 t[373] = 109; 19183 t[374] = 110; 19184 t[381] = 111; 19185 t[382] = 242; 19186 t[383] = 243; 19187 t[386] = 246; 19188 t[393] = 112; 19189 t[395] = 113; 19190 t[396] = 114; 19191 t[398] = 345; 19192 t[400] = 115; 19193 t[401] = 347; 19194 t[403] = 353; 19195 t[410] = 116; 19196 t[437] = 117; 19197 t[442] = 252; 19198 t[448] = 118; 19199 t[449] = 119; 19200 t[454] = 120; 19201 t[455] = 121; 19202 t[457] = 253; 19203 t[460] = 122; 19204 t[462] = 382; 19205 t[463] = 380; 19206 t[853] = 44; 19207 t[855] = 58; 19208 t[856] = 46; 19209 t[876] = 47; 19210 t[878] = 45; 19211 t[882] = 45; 19212 t[894] = 40; 19213 t[895] = 41; 19214 t[896] = 91; 19215 t[897] = 93; 19216 t[923] = 64; 19217 t[940] = 163; 19218 t[1004] = 48; 19219 t[1005] = 49; 19220 t[1006] = 50; 19221 t[1007] = 51; 19222 t[1008] = 52; 19223 t[1009] = 53; 19224 t[1010] = 54; 19225 t[1011] = 55; 19226 t[1012] = 56; 19227 t[1013] = 57; 19228 t[1081] = 37; 19229 t[1085] = 43; 19230 t[1086] = 45; 19231}); 19232function getStandardFontName(name) { 19233 const fontName = normalizeFontName(name); 19234 const stdFontMap = getStdFontMap(); 19235 return stdFontMap[fontName]; 19236} 19237function isKnownFontName(name) { 19238 const fontName = normalizeFontName(name); 19239 return !!(getStdFontMap()[fontName] || getNonStdFontMap()[fontName] || getSerifFonts()[fontName] || getSymbolsFonts()[fontName]); 19240} 19241 19242;// ./src/core/to_unicode_map.js 19243 19244class ToUnicodeMap { 19245 constructor(cmap = []) { 19246 this._map = cmap; 19247 } 19248 get length() { 19249 return this._map.length; 19250 } 19251 forEach(callback) { 19252 for (const charCode in this._map) { 19253 callback(charCode, this._map[charCode].codePointAt(0)); 19254 } 19255 } 19256 has(i) { 19257 return this._map[i] !== undefined; 19258 } 19259 get(i) { 19260 return this._map[i]; 19261 } 19262 charCodeOf(value) { 19263 const map = this._map; 19264 if (map.length <= 0x10000) { 19265 return map.indexOf(value); 19266 } 19267 for (const charCode in map) { 19268 if (map[charCode] === value) { 19269 return charCode | 0; 19270 } 19271 } 19272 return -1; 19273 } 19274 amend(map) { 19275 for (const charCode in map) { 19276 this._map[charCode] = map[charCode]; 19277 } 19278 } 19279} 19280class IdentityToUnicodeMap { 19281 constructor(firstChar, lastChar) { 19282 this.firstChar = firstChar; 19283 this.lastChar = lastChar; 19284 } 19285 get length() { 19286 return this.lastChar + 1 - this.firstChar; 19287 } 19288 forEach(callback) { 19289 for (let i = this.firstChar, ii = this.lastChar; i <= ii; i++) { 19290 callback(i, i); 19291 } 19292 } 19293 has(i) { 19294 return this.firstChar <= i && i <= this.lastChar; 19295 } 19296 get(i) { 19297 if (this.firstChar <= i && i <= this.lastChar) { 19298 return String.fromCharCode(i); 19299 } 19300 return undefined; 19301 } 19302 charCodeOf(v) { 19303 return Number.isInteger(v) && v >= this.firstChar && v <= this.lastChar ? v : -1; 19304 } 19305 amend(map) { 19306 unreachable("Should not call amend()"); 19307 } 19308} 19309 19310;// ./src/core/cff_font.js 19311 19312 19313 19314class CFFFont { 19315 constructor(file, properties) { 19316 this.properties = properties; 19317 const parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED); 19318 this.cff = parser.parse(); 19319 this.cff.duplicateFirstGlyph(); 19320 const compiler = new CFFCompiler(this.cff); 19321 this.seacs = this.cff.seacs; 19322 try { 19323 this.data = compiler.compile(); 19324 } catch { 19325 warn("Failed to compile font " + properties.loadedName); 19326 this.data = file; 19327 } 19328 this._createBuiltInEncoding(); 19329 } 19330 get numGlyphs() { 19331 return this.cff.charStrings.count; 19332 } 19333 getCharset() { 19334 return this.cff.charset.charset; 19335 } 19336 getGlyphMapping() { 19337 const cff = this.cff; 19338 const properties = this.properties; 19339 const { 19340 cidToGidMap, 19341 cMap 19342 } = properties; 19343 const charsets = cff.charset.charset; 19344 let charCodeToGlyphId; 19345 let glyphId; 19346 if (properties.composite) { 19347 let invCidToGidMap; 19348 if (cidToGidMap?.length > 0) { 19349 invCidToGidMap = Object.create(null); 19350 for (let i = 0, ii = cidToGidMap.length; i < ii; i++) { 19351 const gid = cidToGidMap[i]; 19352 if (gid !== undefined) { 19353 invCidToGidMap[gid] = i; 19354 } 19355 } 19356 } 19357 charCodeToGlyphId = Object.create(null); 19358 let charCode; 19359 if (cff.isCIDFont) { 19360 for (glyphId = 0; glyphId < charsets.length; glyphId++) { 19361 const cid = charsets[glyphId]; 19362 charCode = cMap.charCodeOf(cid); 19363 if (invCidToGidMap?.[charCode] !== undefined) { 19364 charCode = invCidToGidMap[charCode]; 19365 } 19366 charCodeToGlyphId[charCode] = glyphId; 19367 } 19368 } else { 19369 for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) { 19370 charCode = cMap.charCodeOf(glyphId); 19371 charCodeToGlyphId[charCode] = glyphId; 19372 } 19373 } 19374 return charCodeToGlyphId; 19375 } 19376 let encoding = cff.encoding ? cff.encoding.encoding : null; 19377 if (properties.isInternalFont) { 19378 encoding = properties.defaultEncoding; 19379 } 19380 charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets); 19381 return charCodeToGlyphId; 19382 } 19383 hasGlyphId(id) { 19384 return this.cff.hasGlyphId(id); 19385 } 19386 _createBuiltInEncoding() { 19387 const { 19388 charset, 19389 encoding 19390 } = this.cff; 19391 if (!charset || !encoding) { 19392 return; 19393 } 19394 const charsets = charset.charset, 19395 encodings = encoding.encoding; 19396 const map = []; 19397 for (const charCode in encodings) { 19398 const glyphId = encodings[charCode]; 19399 if (glyphId >= 0) { 19400 const glyphName = charsets[glyphId]; 19401 if (glyphName) { 19402 map[charCode] = glyphName; 19403 } 19404 } 19405 } 19406 if (map.length > 0) { 19407 this.properties.builtInEncoding = map; 19408 } 19409 } 19410} 19411 19412;// ./src/core/font_renderer.js 19413 19414 19415 19416 19417 19418 19419function getFloat214(data, offset) { 19420 return readInt16(data, offset) / 16384; 19421} 19422function getSubroutineBias(subrs) { 19423 const numSubrs = subrs.length; 19424 let bias = 32768; 19425 if (numSubrs < 1240) { 19426 bias = 107; 19427 } else if (numSubrs < 33900) { 19428 bias = 1131; 19429 } 19430 return bias; 19431} 19432function parseCmap(data, start, end) { 19433 const offset = readUint16(data, start + 2) === 1 ? readUint32(data, start + 8) : readUint32(data, start + 16); 19434 const format = readUint16(data, start + offset); 19435 let ranges, p, i; 19436 if (format === 4) { 19437 readUint16(data, start + offset + 2); 19438 const segCount = readUint16(data, start + offset + 6) >> 1; 19439 p = start + offset + 14; 19440 ranges = []; 19441 for (i = 0; i < segCount; i++, p += 2) { 19442 ranges[i] = { 19443 end: readUint16(data, p) 19444 }; 19445 } 19446 p += 2; 19447 for (i = 0; i < segCount; i++, p += 2) { 19448 ranges[i].start = readUint16(data, p); 19449 } 19450 for (i = 0; i < segCount; i++, p += 2) { 19451 ranges[i].idDelta = readUint16(data, p); 19452 } 19453 for (i = 0; i < segCount; i++, p += 2) { 19454 let idOffset = readUint16(data, p); 19455 if (idOffset === 0) { 19456 continue; 19457 } 19458 ranges[i].ids = []; 19459 for (let j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) { 19460 ranges[i].ids[j] = readUint16(data, p + idOffset); 19461 idOffset += 2; 19462 } 19463 } 19464 return ranges; 19465 } else if (format === 12) { 19466 const groups = readUint32(data, start + offset + 12); 19467 p = start + offset + 16; 19468 ranges = []; 19469 for (i = 0; i < groups; i++) { 19470 start = readUint32(data, p); 19471 ranges.push({ 19472 start, 19473 end: readUint32(data, p + 4), 19474 idDelta: readUint32(data, p + 8) - start 19475 }); 19476 p += 12; 19477 } 19478 return ranges; 19479 } 19480 throw new FormatError(`unsupported cmap: ${format}`); 19481} 19482function parseCff(data, start, end, seacAnalysisEnabled) { 19483 const properties = {}; 19484 const parser = new CFFParser(new Stream(data, start, end - start), properties, seacAnalysisEnabled); 19485 const cff = parser.parse(); 19486 return { 19487 glyphs: cff.charStrings.objects, 19488 subrs: cff.topDict.privateDict?.subrsIndex?.objects, 19489 gsubrs: cff.globalSubrIndex?.objects, 19490 isCFFCIDFont: cff.isCIDFont, 19491 fdSelect: cff.fdSelect, 19492 fdArray: cff.fdArray 19493 }; 19494} 19495function parseGlyfTable(glyf, loca, isGlyphLocationsLong) { 19496 let itemSize, itemDecode; 19497 if (isGlyphLocationsLong) { 19498 itemSize = 4; 19499 itemDecode = readUint32; 19500 } else { 19501 itemSize = 2; 19502 itemDecode = (data, offset) => 2 * readUint16(data, offset); 19503 } 19504 const glyphs = []; 19505 let startOffset = itemDecode(loca, 0); 19506 for (let j = itemSize; j < loca.length; j += itemSize) { 19507 const endOffset = itemDecode(loca, j); 19508 glyphs.push(glyf.subarray(startOffset, endOffset)); 19509 startOffset = endOffset; 19510 } 19511 return glyphs; 19512} 19513function lookupCmap(ranges, unicode) { 19514 const code = unicode.codePointAt(0); 19515 let gid = 0, 19516 l = 0, 19517 r = ranges.length - 1; 19518 while (l < r) { 19519 const c = l + r + 1 >> 1; 19520 if (code < ranges[c].start) { 19521 r = c - 1; 19522 } else { 19523 l = c; 19524 } 19525 } 19526 if (ranges[l].start <= code && code <= ranges[l].end) { 19527 gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xffff; 19528 } 19529 return { 19530 charCode: code, 19531 glyphId: gid 19532 }; 19533} 19534function compileGlyf(code, cmds, font) { 19535 function moveTo(x, y) { 19536 if (firstPoint) { 19537 cmds.add("L", firstPoint); 19538 } 19539 firstPoint = [x, y]; 19540 cmds.add("M", [x, y]); 19541 } 19542 function lineTo(x, y) { 19543 cmds.add("L", [x, y]); 19544 } 19545 function quadraticCurveTo(xa, ya, x, y) { 19546 cmds.add("Q", [xa, ya, x, y]); 19547 } 19548 let i = 0; 19549 const numberOfContours = readInt16(code, i); 19550 let flags; 19551 let firstPoint = null; 19552 let x = 0, 19553 y = 0; 19554 i += 10; 19555 if (numberOfContours < 0) { 19556 do { 19557 flags = readUint16(code, i); 19558 const glyphIndex = readUint16(code, i + 2); 19559 i += 4; 19560 let arg1, arg2; 19561 if (flags & 0x01) { 19562 if (flags & 0x02) { 19563 arg1 = readInt16(code, i); 19564 arg2 = readInt16(code, i + 2); 19565 } else { 19566 arg1 = readUint16(code, i); 19567 arg2 = readUint16(code, i + 2); 19568 } 19569 i += 4; 19570 } else if (flags & 0x02) { 19571 arg1 = readInt8(code, i++); 19572 arg2 = readInt8(code, i++); 19573 } else { 19574 arg1 = code[i++]; 19575 arg2 = code[i++]; 19576 } 19577 if (flags & 0x02) { 19578 x = arg1; 19579 y = arg2; 19580 } else { 19581 x = 0; 19582 y = 0; 19583 } 19584 let scaleX = 1, 19585 scaleY = 1, 19586 scale01 = 0, 19587 scale10 = 0; 19588 if (flags & 0x08) { 19589 scaleX = scaleY = getFloat214(code, i); 19590 i += 2; 19591 } else if (flags & 0x40) { 19592 scaleX = getFloat214(code, i); 19593 scaleY = getFloat214(code, i + 2); 19594 i += 4; 19595 } else if (flags & 0x80) { 19596 scaleX = getFloat214(code, i); 19597 scale01 = getFloat214(code, i + 2); 19598 scale10 = getFloat214(code, i + 4); 19599 scaleY = getFloat214(code, i + 6); 19600 i += 8; 19601 } 19602 const subglyph = font.glyphs[glyphIndex]; 19603 if (subglyph) { 19604 cmds.save(); 19605 cmds.transform([scaleX, scale01, scale10, scaleY, x, y]); 19606 if (!(flags & 0x02)) {} 19607 compileGlyf(subglyph, cmds, font); 19608 cmds.restore(); 19609 } 19610 } while (flags & 0x20); 19611 } else { 19612 const endPtsOfContours = []; 19613 let j, jj; 19614 for (j = 0; j < numberOfContours; j++) { 19615 endPtsOfContours.push(readUint16(code, i)); 19616 i += 2; 19617 } 19618 const instructionLength = readUint16(code, i); 19619 i += 2 + instructionLength; 19620 const numberOfPoints = endPtsOfContours.at(-1) + 1; 19621 const points = []; 19622 while (points.length < numberOfPoints) { 19623 flags = code[i++]; 19624 let repeat = 1; 19625 if (flags & 0x08) { 19626 repeat += code[i++]; 19627 } 19628 while (repeat-- > 0) { 19629 points.push({ 19630 flags 19631 }); 19632 } 19633 } 19634 for (j = 0; j < numberOfPoints; j++) { 19635 switch (points[j].flags & 0x12) { 19636 case 0x00: 19637 x += readInt16(code, i); 19638 i += 2; 19639 break; 19640 case 0x02: 19641 x -= code[i++]; 19642 break; 19643 case 0x12: 19644 x += code[i++]; 19645 break; 19646 } 19647 points[j].x = x; 19648 } 19649 for (j = 0; j < numberOfPoints; j++) { 19650 switch (points[j].flags & 0x24) { 19651 case 0x00: 19652 y += readInt16(code, i); 19653 i += 2; 19654 break; 19655 case 0x04: 19656 y -= code[i++]; 19657 break; 19658 case 0x24: 19659 y += code[i++]; 19660 break; 19661 } 19662 points[j].y = y; 19663 } 19664 let startPoint = 0; 19665 for (i = 0; i < numberOfContours; i++) { 19666 const endPoint = endPtsOfContours[i]; 19667 const contour = points.slice(startPoint, endPoint + 1); 19668 if (contour[0].flags & 1) { 19669 contour.push(contour[0]); 19670 } else if (contour.at(-1).flags & 1) { 19671 contour.unshift(contour.at(-1)); 19672 } else { 19673 const p = { 19674 flags: 1, 19675 x: (contour[0].x + contour.at(-1).x) / 2, 19676 y: (contour[0].y + contour.at(-1).y) / 2 19677 }; 19678 contour.unshift(p); 19679 contour.push(p); 19680 } 19681 moveTo(contour[0].x, contour[0].y); 19682 for (j = 1, jj = contour.length; j < jj; j++) { 19683 if (contour[j].flags & 1) { 19684 lineTo(contour[j].x, contour[j].y); 19685 } else if (contour[j + 1].flags & 1) { 19686 quadraticCurveTo(contour[j].x, contour[j].y, contour[j + 1].x, contour[j + 1].y); 19687 j++; 19688 } else { 19689 quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2); 19690 } 19691 } 19692 startPoint = endPoint + 1; 19693 } 19694 } 19695} 19696function compileCharString(charStringCode, cmds, font, glyphId) { 19697 function moveTo(x, y) { 19698 if (firstPoint) { 19699 cmds.add("L", firstPoint); 19700 } 19701 firstPoint = [x, y]; 19702 cmds.add("M", [x, y]); 19703 } 19704 function lineTo(x, y) { 19705 cmds.add("L", [x, y]); 19706 } 19707 function bezierCurveTo(x1, y1, x2, y2, x, y) { 19708 cmds.add("C", [x1, y1, x2, y2, x, y]); 19709 } 19710 const stack = []; 19711 let x = 0, 19712 y = 0; 19713 let stems = 0; 19714 let firstPoint = null; 19715 function parse(code) { 19716 let i = 0; 19717 while (i < code.length) { 19718 let stackClean = false; 19719 let v = code[i++]; 19720 let xa, xb, ya, yb, y1, y2, y3, n, subrCode; 19721 switch (v) { 19722 case 1: 19723 stems += stack.length >> 1; 19724 stackClean = true; 19725 break; 19726 case 3: 19727 stems += stack.length >> 1; 19728 stackClean = true; 19729 break; 19730 case 4: 19731 y += stack.pop(); 19732 moveTo(x, y); 19733 stackClean = true; 19734 break; 19735 case 5: 19736 while (stack.length > 0) { 19737 x += stack.shift(); 19738 y += stack.shift(); 19739 lineTo(x, y); 19740 } 19741 break; 19742 case 6: 19743 while (stack.length > 0) { 19744 x += stack.shift(); 19745 lineTo(x, y); 19746 if (stack.length === 0) { 19747 break; 19748 } 19749 y += stack.shift(); 19750 lineTo(x, y); 19751 } 19752 break; 19753 case 7: 19754 while (stack.length > 0) { 19755 y += stack.shift(); 19756 lineTo(x, y); 19757 if (stack.length === 0) { 19758 break; 19759 } 19760 x += stack.shift(); 19761 lineTo(x, y); 19762 } 19763 break; 19764 case 8: 19765 while (stack.length > 0) { 19766 xa = x + stack.shift(); 19767 ya = y + stack.shift(); 19768 xb = xa + stack.shift(); 19769 yb = ya + stack.shift(); 19770 x = xb + stack.shift(); 19771 y = yb + stack.shift(); 19772 bezierCurveTo(xa, ya, xb, yb, x, y); 19773 } 19774 break; 19775 case 10: 19776 n = stack.pop(); 19777 subrCode = null; 19778 if (font.isCFFCIDFont) { 19779 const fdIndex = font.fdSelect.getFDIndex(glyphId); 19780 if (fdIndex >= 0 && fdIndex < font.fdArray.length) { 19781 const fontDict = font.fdArray[fdIndex]; 19782 let subrs; 19783 if (fontDict.privateDict?.subrsIndex) { 19784 subrs = fontDict.privateDict.subrsIndex.objects; 19785 } 19786 if (subrs) { 19787 n += getSubroutineBias(subrs); 19788 subrCode = subrs[n]; 19789 } 19790 } else { 19791 warn("Invalid fd index for glyph index."); 19792 } 19793 } else { 19794 subrCode = font.subrs[n + font.subrsBias]; 19795 } 19796 if (subrCode) { 19797 parse(subrCode); 19798 } 19799 break; 19800 case 11: 19801 return; 19802 case 12: 19803 v = code[i++]; 19804 switch (v) { 19805 case 34: 19806 xa = x + stack.shift(); 19807 xb = xa + stack.shift(); 19808 y1 = y + stack.shift(); 19809 x = xb + stack.shift(); 19810 bezierCurveTo(xa, y, xb, y1, x, y1); 19811 xa = x + stack.shift(); 19812 xb = xa + stack.shift(); 19813 x = xb + stack.shift(); 19814 bezierCurveTo(xa, y1, xb, y, x, y); 19815 break; 19816 case 35: 19817 xa = x + stack.shift(); 19818 ya = y + stack.shift(); 19819 xb = xa + stack.shift(); 19820 yb = ya + stack.shift(); 19821 x = xb + stack.shift(); 19822 y = yb + stack.shift(); 19823 bezierCurveTo(xa, ya, xb, yb, x, y); 19824 xa = x + stack.shift(); 19825 ya = y + stack.shift(); 19826 xb = xa + stack.shift(); 19827 yb = ya + stack.shift(); 19828 x = xb + stack.shift(); 19829 y = yb + stack.shift(); 19830 bezierCurveTo(xa, ya, xb, yb, x, y); 19831 stack.pop(); 19832 break; 19833 case 36: 19834 xa = x + stack.shift(); 19835 y1 = y + stack.shift(); 19836 xb = xa + stack.shift(); 19837 y2 = y1 + stack.shift(); 19838 x = xb + stack.shift(); 19839 bezierCurveTo(xa, y1, xb, y2, x, y2); 19840 xa = x + stack.shift(); 19841 xb = xa + stack.shift(); 19842 y3 = y2 + stack.shift(); 19843 x = xb + stack.shift(); 19844 bezierCurveTo(xa, y2, xb, y3, x, y); 19845 break; 19846 case 37: 19847 const x0 = x, 19848 y0 = y; 19849 xa = x + stack.shift(); 19850 ya = y + stack.shift(); 19851 xb = xa + stack.shift(); 19852 yb = ya + stack.shift(); 19853 x = xb + stack.shift(); 19854 y = yb + stack.shift(); 19855 bezierCurveTo(xa, ya, xb, yb, x, y); 19856 xa = x + stack.shift(); 19857 ya = y + stack.shift(); 19858 xb = xa + stack.shift(); 19859 yb = ya + stack.shift(); 19860 x = xb; 19861 y = yb; 19862 if (Math.abs(x - x0) > Math.abs(y - y0)) { 19863 x += stack.shift(); 19864 } else { 19865 y += stack.shift(); 19866 } 19867 bezierCurveTo(xa, ya, xb, yb, x, y); 19868 break; 19869 default: 19870 throw new FormatError(`unknown operator: 12 ${v}`); 19871 } 19872 break; 19873 case 14: 19874 if (stack.length >= 4) { 19875 const achar = stack.pop(); 19876 const bchar = stack.pop(); 19877 y = stack.pop(); 19878 x = stack.pop(); 19879 cmds.save(); 19880 cmds.translate(x, y); 19881 let cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]])); 19882 compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId); 19883 cmds.restore(); 19884 cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]])); 19885 compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId); 19886 } 19887 return; 19888 case 18: 19889 stems += stack.length >> 1; 19890 stackClean = true; 19891 break; 19892 case 19: 19893 stems += stack.length >> 1; 19894 i += stems + 7 >> 3; 19895 stackClean = true; 19896 break; 19897 case 20: 19898 stems += stack.length >> 1; 19899 i += stems + 7 >> 3; 19900 stackClean = true; 19901 break; 19902 case 21: 19903 y += stack.pop(); 19904 x += stack.pop(); 19905 moveTo(x, y); 19906 stackClean = true; 19907 break; 19908 case 22: 19909 x += stack.pop(); 19910 moveTo(x, y); 19911 stackClean = true; 19912 break; 19913 case 23: 19914 stems += stack.length >> 1; 19915 stackClean = true; 19916 break; 19917 case 24: 19918 while (stack.length > 2) { 19919 xa = x + stack.shift(); 19920 ya = y + stack.shift(); 19921 xb = xa + stack.shift(); 19922 yb = ya + stack.shift(); 19923 x = xb + stack.shift(); 19924 y = yb + stack.shift(); 19925 bezierCurveTo(xa, ya, xb, yb, x, y); 19926 } 19927 x += stack.shift(); 19928 y += stack.shift(); 19929 lineTo(x, y); 19930 break; 19931 case 25: 19932 while (stack.length > 6) { 19933 x += stack.shift(); 19934 y += stack.shift(); 19935 lineTo(x, y); 19936 } 19937 xa = x + stack.shift(); 19938 ya = y + stack.shift(); 19939 xb = xa + stack.shift(); 19940 yb = ya + stack.shift(); 19941 x = xb + stack.shift(); 19942 y = yb + stack.shift(); 19943 bezierCurveTo(xa, ya, xb, yb, x, y); 19944 break; 19945 case 26: 19946 if (stack.length % 2) { 19947 x += stack.shift(); 19948 } 19949 while (stack.length > 0) { 19950 xa = x; 19951 ya = y + stack.shift(); 19952 xb = xa + stack.shift(); 19953 yb = ya + stack.shift(); 19954 x = xb; 19955 y = yb + stack.shift(); 19956 bezierCurveTo(xa, ya, xb, yb, x, y); 19957 } 19958 break; 19959 case 27: 19960 if (stack.length % 2) { 19961 y += stack.shift(); 19962 } 19963 while (stack.length > 0) { 19964 xa = x + stack.shift(); 19965 ya = y; 19966 xb = xa + stack.shift(); 19967 yb = ya + stack.shift(); 19968 x = xb + stack.shift(); 19969 y = yb; 19970 bezierCurveTo(xa, ya, xb, yb, x, y); 19971 } 19972 break; 19973 case 28: 19974 stack.push(readInt16(code, i)); 19975 i += 2; 19976 break; 19977 case 29: 19978 n = stack.pop() + font.gsubrsBias; 19979 subrCode = font.gsubrs[n]; 19980 if (subrCode) { 19981 parse(subrCode); 19982 } 19983 break; 19984 case 30: 19985 while (stack.length > 0) { 19986 xa = x; 19987 ya = y + stack.shift(); 19988 xb = xa + stack.shift(); 19989 yb = ya + stack.shift(); 19990 x = xb + stack.shift(); 19991 y = yb + (stack.length === 1 ? stack.shift() : 0); 19992 bezierCurveTo(xa, ya, xb, yb, x, y); 19993 if (stack.length === 0) { 19994 break; 19995 } 19996 xa = x + stack.shift(); 19997 ya = y; 19998 xb = xa + stack.shift(); 19999 yb = ya + stack.shift(); 20000 y = yb + stack.shift(); 20001 x = xb + (stack.length === 1 ? stack.shift() : 0); 20002 bezierCurveTo(xa, ya, xb, yb, x, y); 20003 } 20004 break; 20005 case 31: 20006 while (stack.length > 0) { 20007 xa = x + stack.shift(); 20008 ya = y; 20009 xb = xa + stack.shift(); 20010 yb = ya + stack.shift(); 20011 y = yb + stack.shift(); 20012 x = xb + (stack.length === 1 ? stack.shift() : 0); 20013 bezierCurveTo(xa, ya, xb, yb, x, y); 20014 if (stack.length === 0) { 20015 break; 20016 } 20017 xa = x; 20018 ya = y + stack.shift(); 20019 xb = xa + stack.shift(); 20020 yb = ya + stack.shift(); 20021 x = xb + stack.shift(); 20022 y = yb + (stack.length === 1 ? stack.shift() : 0); 20023 bezierCurveTo(xa, ya, xb, yb, x, y); 20024 } 20025 break; 20026 default: 20027 if (v < 32) { 20028 throw new FormatError(`unknown operator: ${v}`); 20029 } 20030 if (v < 247) { 20031 stack.push(v - 139); 20032 } else if (v < 251) { 20033 stack.push((v - 247) * 256 + code[i++] + 108); 20034 } else if (v < 255) { 20035 stack.push(-(v - 251) * 256 - code[i++] - 108); 20036 } else { 20037 stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536); 20038 i += 4; 20039 } 20040 break; 20041 } 20042 if (stackClean) { 20043 stack.length = 0; 20044 } 20045 } 20046 } 20047 parse(charStringCode); 20048} 20049const NOOP = ""; 20050class Commands { 20051 cmds = []; 20052 transformStack = []; 20053 currentTransform = [1, 0, 0, 1, 0, 0]; 20054 add(cmd, args) { 20055 if (args) { 20056 const { 20057 currentTransform 20058 } = this; 20059 for (let i = 0, ii = args.length; i < ii; i += 2) { 20060 Util.applyTransform(args, currentTransform, i); 20061 } 20062 this.cmds.push(`${cmd}${args.join(" ")}`); 20063 } else { 20064 this.cmds.push(cmd); 20065 } 20066 } 20067 transform(transf) { 20068 this.currentTransform = Util.transform(this.currentTransform, transf); 20069 } 20070 translate(x, y) { 20071 this.transform([1, 0, 0, 1, x, y]); 20072 } 20073 save() { 20074 this.transformStack.push(this.currentTransform.slice()); 20075 } 20076 restore() { 20077 this.currentTransform = this.transformStack.pop() || [1, 0, 0, 1, 0, 0]; 20078 } 20079 getSVG() { 20080 return this.cmds.join(""); 20081 } 20082} 20083class CompiledFont { 20084 constructor(fontMatrix) { 20085 this.fontMatrix = fontMatrix; 20086 this.compiledGlyphs = Object.create(null); 20087 this.compiledCharCodeToGlyphId = Object.create(null); 20088 } 20089 getPathJs(unicode) { 20090 const { 20091 charCode, 20092 glyphId 20093 } = lookupCmap(this.cmap, unicode); 20094 let fn = this.compiledGlyphs[glyphId], 20095 compileEx; 20096 if (fn === undefined) { 20097 try { 20098 fn = this.compileGlyph(this.glyphs[glyphId], glyphId); 20099 } catch (ex) { 20100 fn = NOOP; 20101 compileEx = ex; 20102 } 20103 this.compiledGlyphs[glyphId] = fn; 20104 } 20105 this.compiledCharCodeToGlyphId[charCode] ??= glyphId; 20106 if (compileEx) { 20107 throw compileEx; 20108 } 20109 return fn; 20110 } 20111 compileGlyph(code, glyphId) { 20112 if (!code?.length || code[0] === 14) { 20113 return NOOP; 20114 } 20115 let fontMatrix = this.fontMatrix; 20116 if (this.isCFFCIDFont) { 20117 const fdIndex = this.fdSelect.getFDIndex(glyphId); 20118 if (fdIndex >= 0 && fdIndex < this.fdArray.length) { 20119 const fontDict = this.fdArray[fdIndex]; 20120 fontMatrix = fontDict.getByName("FontMatrix") || FONT_IDENTITY_MATRIX; 20121 } else { 20122 warn("Invalid fd index for glyph index."); 20123 } 20124 } 20125 assert(isNumberArray(fontMatrix, 6), "Expected a valid fontMatrix."); 20126 const cmds = new Commands(); 20127 cmds.transform(fontMatrix.slice()); 20128 this.compileGlyphImpl(code, cmds, glyphId); 20129 cmds.add("Z"); 20130 return cmds.getSVG(); 20131 } 20132 compileGlyphImpl() { 20133 unreachable("Children classes should implement this."); 20134 } 20135 hasBuiltPath(unicode) { 20136 const { 20137 charCode, 20138 glyphId 20139 } = lookupCmap(this.cmap, unicode); 20140 return this.compiledGlyphs[glyphId] !== undefined && this.compiledCharCodeToGlyphId[charCode] !== undefined; 20141 } 20142} 20143class TrueTypeCompiled extends CompiledFont { 20144 constructor(glyphs, cmap, fontMatrix) { 20145 super(fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0]); 20146 this.glyphs = glyphs; 20147 this.cmap = cmap; 20148 } 20149 compileGlyphImpl(code, cmds) { 20150 compileGlyf(code, cmds, this); 20151 } 20152} 20153class Type2Compiled extends CompiledFont { 20154 constructor(cffInfo, cmap, fontMatrix) { 20155 super(fontMatrix || [0.001, 0, 0, 0.001, 0, 0]); 20156 this.glyphs = cffInfo.glyphs; 20157 this.gsubrs = cffInfo.gsubrs || []; 20158 this.subrs = cffInfo.subrs || []; 20159 this.cmap = cmap; 20160 this.glyphNameMap = getGlyphsUnicode(); 20161 this.gsubrsBias = getSubroutineBias(this.gsubrs); 20162 this.subrsBias = getSubroutineBias(this.subrs); 20163 this.isCFFCIDFont = cffInfo.isCFFCIDFont; 20164 this.fdSelect = cffInfo.fdSelect; 20165 this.fdArray = cffInfo.fdArray; 20166 } 20167 compileGlyphImpl(code, cmds, glyphId) { 20168 compileCharString(code, cmds, this, glyphId); 20169 } 20170} 20171class FontRendererFactory { 20172 static create(font, seacAnalysisEnabled) { 20173 const data = new Uint8Array(font.data); 20174 let cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm; 20175 const numTables = readUint16(data, 4); 20176 for (let i = 0, p = 12; i < numTables; i++, p += 16) { 20177 const tag = bytesToString(data.subarray(p, p + 4)); 20178 const offset = readUint32(data, p + 8); 20179 const length = readUint32(data, p + 12); 20180 switch (tag) { 20181 case "cmap": 20182 cmap = parseCmap(data, offset, offset + length); 20183 break; 20184 case "glyf": 20185 glyf = data.subarray(offset, offset + length); 20186 break; 20187 case "loca": 20188 loca = data.subarray(offset, offset + length); 20189 break; 20190 case "head": 20191 unitsPerEm = readUint16(data, offset + 18); 20192 indexToLocFormat = readUint16(data, offset + 50); 20193 break; 20194 case "CFF ": 20195 cff = parseCff(data, offset, offset + length, seacAnalysisEnabled); 20196 break; 20197 } 20198 } 20199 if (glyf) { 20200 const fontMatrix = !unitsPerEm ? font.fontMatrix : [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]; 20201 return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix); 20202 } 20203 return new Type2Compiled(cff, cmap, font.fontMatrix); 20204 } 20205} 20206 20207;// ./src/core/metrics.js 20208 20209const getMetrics = getLookupTableFactory(function (t) { 20210 t.Courier = 600;
vendor: 20,615 bytes, lines 20211-21210
20211 t["Courier-Bold"] = 600; 20212 t["Courier-BoldOblique"] = 600; 20213 t["Courier-Oblique"] = 600; 20214 t.Helvetica = getLookupTableFactory(function (t) { 20215 t.space = 278; 20216 t.exclam = 278; 20217 t.quotedbl = 355; 20218 t.numbersign = 556; 20219 t.dollar = 556; 20220 t.percent = 889; 20221 t.ampersand = 667; 20222 t.quoteright = 222; 20223 t.parenleft = 333; 20224 t.parenright = 333; 20225 t.asterisk = 389; 20226 t.plus = 584; 20227 t.comma = 278; 20228 t.hyphen = 333; 20229 t.period = 278; 20230 t.slash = 278; 20231 t.zero = 556; 20232 t.one = 556; 20233 t.two = 556; 20234 t.three = 556; 20235 t.four = 556; 20236 t.five = 556; 20237 t.six = 556; 20238 t.seven = 556; 20239 t.eight = 556; 20240 t.nine = 556; 20241 t.colon = 278; 20242 t.semicolon = 278; 20243 t.less = 584; 20244 t.equal = 584; 20245 t.greater = 584; 20246 t.question = 556; 20247 t.at = 1015; 20248 t.A = 667; 20249 t.B = 667; 20250 t.C = 722; 20251 t.D = 722; 20252 t.E = 667; 20253 t.F = 611; 20254 t.G = 778; 20255 t.H = 722; 20256 t.I = 278; 20257 t.J = 500; 20258 t.K = 667; 20259 t.L = 556; 20260 t.M = 833; 20261 t.N = 722; 20262 t.O = 778; 20263 t.P = 667; 20264 t.Q = 778; 20265 t.R = 722; 20266 t.S = 667; 20267 t.T = 611; 20268 t.U = 722; 20269 t.V = 667; 20270 t.W = 944; 20271 t.X = 667; 20272 t.Y = 667; 20273 t.Z = 611; 20274 t.bracketleft = 278; 20275 t.backslash = 278; 20276 t.bracketright = 278; 20277 t.asciicircum = 469; 20278 t.underscore = 556; 20279 t.quoteleft = 222; 20280 t.a = 556; 20281 t.b = 556; 20282 t.c = 500; 20283 t.d = 556; 20284 t.e = 556; 20285 t.f = 278; 20286 t.g = 556; 20287 t.h = 556; 20288 t.i = 222; 20289 t.j = 222; 20290 t.k = 500; 20291 t.l = 222; 20292 t.m = 833; 20293 t.n = 556; 20294 t.o = 556; 20295 t.p = 556; 20296 t.q = 556; 20297 t.r = 333; 20298 t.s = 500; 20299 t.t = 278; 20300 t.u = 556; 20301 t.v = 500; 20302 t.w = 722; 20303 t.x = 500; 20304 t.y = 500; 20305 t.z = 500; 20306 t.braceleft = 334; 20307 t.bar = 260; 20308 t.braceright = 334; 20309 t.asciitilde = 584; 20310 t.exclamdown = 333; 20311 t.cent = 556; 20312 t.sterling = 556; 20313 t.fraction = 167; 20314 t.yen = 556; 20315 t.florin = 556; 20316 t.section = 556; 20317 t.currency = 556; 20318 t.quotesingle = 191; 20319 t.quotedblleft = 333; 20320 t.guillemotleft = 556; 20321 t.guilsinglleft = 333; 20322 t.guilsinglright = 333; 20323 t.fi = 500; 20324 t.fl = 500; 20325 t.endash = 556; 20326 t.dagger = 556; 20327 t.daggerdbl = 556; 20328 t.periodcentered = 278; 20329 t.paragraph = 537; 20330 t.bullet = 350; 20331 t.quotesinglbase = 222; 20332 t.quotedblbase = 333; 20333 t.quotedblright = 333; 20334 t.guillemotright = 556; 20335 t.ellipsis = 1000; 20336 t.perthousand = 1000; 20337 t.questiondown = 611; 20338 t.grave = 333; 20339 t.acute = 333; 20340 t.circumflex = 333; 20341 t.tilde = 333; 20342 t.macron = 333; 20343 t.breve = 333; 20344 t.dotaccent = 333; 20345 t.dieresis = 333; 20346 t.ring = 333; 20347 t.cedilla = 333; 20348 t.hungarumlaut = 333; 20349 t.ogonek = 333; 20350 t.caron = 333; 20351 t.emdash = 1000; 20352 t.AE = 1000; 20353 t.ordfeminine = 370; 20354 t.Lslash = 556; 20355 t.Oslash = 778; 20356 t.OE = 1000; 20357 t.ordmasculine = 365; 20358 t.ae = 889; 20359 t.dotlessi = 278; 20360 t.lslash = 222; 20361 t.oslash = 611; 20362 t.oe = 944; 20363 t.germandbls = 611; 20364 t.Idieresis = 278; 20365 t.eacute = 556; 20366 t.abreve = 556; 20367 t.uhungarumlaut = 556; 20368 t.ecaron = 556; 20369 t.Ydieresis = 667; 20370 t.divide = 584; 20371 t.Yacute = 667; 20372 t.Acircumflex = 667; 20373 t.aacute = 556; 20374 t.Ucircumflex = 722; 20375 t.yacute = 500; 20376 t.scommaaccent = 500; 20377 t.ecircumflex = 556; 20378 t.Uring = 722; 20379 t.Udieresis = 722; 20380 t.aogonek = 556; 20381 t.Uacute = 722; 20382 t.uogonek = 556; 20383 t.Edieresis = 667; 20384 t.Dcroat = 722; 20385 t.commaaccent = 250; 20386 t.copyright = 737; 20387 t.Emacron = 667; 20388 t.ccaron = 500; 20389 t.aring = 556; 20390 t.Ncommaaccent = 722; 20391 t.lacute = 222; 20392 t.agrave = 556; 20393 t.Tcommaaccent = 611; 20394 t.Cacute = 722; 20395 t.atilde = 556; 20396 t.Edotaccent = 667; 20397 t.scaron = 500; 20398 t.scedilla = 500; 20399 t.iacute = 278; 20400 t.lozenge = 471; 20401 t.Rcaron = 722; 20402 t.Gcommaaccent = 778; 20403 t.ucircumflex = 556; 20404 t.acircumflex = 556; 20405 t.Amacron = 667; 20406 t.rcaron = 333; 20407 t.ccedilla = 500; 20408 t.Zdotaccent = 611; 20409 t.Thorn = 667; 20410 t.Omacron = 778; 20411 t.Racute = 722; 20412 t.Sacute = 667; 20413 t.dcaron = 643; 20414 t.Umacron = 722; 20415 t.uring = 556; 20416 t.threesuperior = 333; 20417 t.Ograve = 778; 20418 t.Agrave = 667; 20419 t.Abreve = 667; 20420 t.multiply = 584; 20421 t.uacute = 556; 20422 t.Tcaron = 611; 20423 t.partialdiff = 476; 20424 t.ydieresis = 500; 20425 t.Nacute = 722; 20426 t.icircumflex = 278; 20427 t.Ecircumflex = 667; 20428 t.adieresis = 556; 20429 t.edieresis = 556; 20430 t.cacute = 500; 20431 t.nacute = 556; 20432 t.umacron = 556; 20433 t.Ncaron = 722; 20434 t.Iacute = 278; 20435 t.plusminus = 584; 20436 t.brokenbar = 260; 20437 t.registered = 737; 20438 t.Gbreve = 778; 20439 t.Idotaccent = 278; 20440 t.summation = 600; 20441 t.Egrave = 667; 20442 t.racute = 333; 20443 t.omacron = 556; 20444 t.Zacute = 611; 20445 t.Zcaron = 611; 20446 t.greaterequal = 549; 20447 t.Eth = 722; 20448 t.Ccedilla = 722; 20449 t.lcommaaccent = 222; 20450 t.tcaron = 317; 20451 t.eogonek = 556; 20452 t.Uogonek = 722; 20453 t.Aacute = 667; 20454 t.Adieresis = 667; 20455 t.egrave = 556; 20456 t.zacute = 500; 20457 t.iogonek = 222; 20458 t.Oacute = 778; 20459 t.oacute = 556; 20460 t.amacron = 556; 20461 t.sacute = 500; 20462 t.idieresis = 278; 20463 t.Ocircumflex = 778; 20464 t.Ugrave = 722; 20465 t.Delta = 612; 20466 t.thorn = 556; 20467 t.twosuperior = 333; 20468 t.Odieresis = 778; 20469 t.mu = 556; 20470 t.igrave = 278; 20471 t.ohungarumlaut = 556; 20472 t.Eogonek = 667; 20473 t.dcroat = 556; 20474 t.threequarters = 834; 20475 t.Scedilla = 667; 20476 t.lcaron = 299; 20477 t.Kcommaaccent = 667; 20478 t.Lacute = 556; 20479 t.trademark = 1000; 20480 t.edotaccent = 556; 20481 t.Igrave = 278; 20482 t.Imacron = 278; 20483 t.Lcaron = 556; 20484 t.onehalf = 834; 20485 t.lessequal = 549; 20486 t.ocircumflex = 556; 20487 t.ntilde = 556; 20488 t.Uhungarumlaut = 722; 20489 t.Eacute = 667; 20490 t.emacron = 556; 20491 t.gbreve = 556; 20492 t.onequarter = 834; 20493 t.Scaron = 667; 20494 t.Scommaaccent = 667; 20495 t.Ohungarumlaut = 778; 20496 t.degree = 400; 20497 t.ograve = 556; 20498 t.Ccaron = 722; 20499 t.ugrave = 556; 20500 t.radical = 453; 20501 t.Dcaron = 722; 20502 t.rcommaaccent = 333; 20503 t.Ntilde = 722; 20504 t.otilde = 556; 20505 t.Rcommaaccent = 722; 20506 t.Lcommaaccent = 556; 20507 t.Atilde = 667; 20508 t.Aogonek = 667; 20509 t.Aring = 667; 20510 t.Otilde = 778; 20511 t.zdotaccent = 500; 20512 t.Ecaron = 667; 20513 t.Iogonek = 278; 20514 t.kcommaaccent = 500; 20515 t.minus = 584; 20516 t.Icircumflex = 278; 20517 t.ncaron = 556; 20518 t.tcommaaccent = 278; 20519 t.logicalnot = 584; 20520 t.odieresis = 556; 20521 t.udieresis = 556; 20522 t.notequal = 549; 20523 t.gcommaaccent = 556; 20524 t.eth = 556; 20525 t.zcaron = 500; 20526 t.ncommaaccent = 556; 20527 t.onesuperior = 333; 20528 t.imacron = 278; 20529 t.Euro = 556; 20530 }); 20531 t["Helvetica-Bold"] = getLookupTableFactory(function (t) { 20532 t.space = 278; 20533 t.exclam = 333; 20534 t.quotedbl = 474; 20535 t.numbersign = 556; 20536 t.dollar = 556; 20537 t.percent = 889; 20538 t.ampersand = 722; 20539 t.quoteright = 278; 20540 t.parenleft = 333; 20541 t.parenright = 333; 20542 t.asterisk = 389; 20543 t.plus = 584; 20544 t.comma = 278; 20545 t.hyphen = 333; 20546 t.period = 278; 20547 t.slash = 278; 20548 t.zero = 556; 20549 t.one = 556; 20550 t.two = 556; 20551 t.three = 556; 20552 t.four = 556; 20553 t.five = 556; 20554 t.six = 556; 20555 t.seven = 556; 20556 t.eight = 556; 20557 t.nine = 556; 20558 t.colon = 333; 20559 t.semicolon = 333; 20560 t.less = 584; 20561 t.equal = 584; 20562 t.greater = 584; 20563 t.question = 611; 20564 t.at = 975; 20565 t.A = 722; 20566 t.B = 722; 20567 t.C = 722; 20568 t.D = 722; 20569 t.E = 667; 20570 t.F = 611; 20571 t.G = 778; 20572 t.H = 722; 20573 t.I = 278; 20574 t.J = 556; 20575 t.K = 722; 20576 t.L = 611; 20577 t.M = 833; 20578 t.N = 722; 20579 t.O = 778; 20580 t.P = 667; 20581 t.Q = 778; 20582 t.R = 722; 20583 t.S = 667; 20584 t.T = 611; 20585 t.U = 722; 20586 t.V = 667; 20587 t.W = 944; 20588 t.X = 667; 20589 t.Y = 667; 20590 t.Z = 611; 20591 t.bracketleft = 333; 20592 t.backslash = 278; 20593 t.bracketright = 333; 20594 t.asciicircum = 584; 20595 t.underscore = 556; 20596 t.quoteleft = 278; 20597 t.a = 556; 20598 t.b = 611; 20599 t.c = 556; 20600 t.d = 611; 20601 t.e = 556; 20602 t.f = 333; 20603 t.g = 611; 20604 t.h = 611; 20605 t.i = 278; 20606 t.j = 278; 20607 t.k = 556; 20608 t.l = 278; 20609 t.m = 889; 20610 t.n = 611; 20611 t.o = 611; 20612 t.p = 611; 20613 t.q = 611; 20614 t.r = 389; 20615 t.s = 556; 20616 t.t = 333; 20617 t.u = 611; 20618 t.v = 556; 20619 t.w = 778; 20620 t.x = 556; 20621 t.y = 556; 20622 t.z = 500; 20623 t.braceleft = 389; 20624 t.bar = 280; 20625 t.braceright = 389; 20626 t.asciitilde = 584; 20627 t.exclamdown = 333; 20628 t.cent = 556; 20629 t.sterling = 556; 20630 t.fraction = 167; 20631 t.yen = 556; 20632 t.florin = 556; 20633 t.section = 556; 20634 t.currency = 556; 20635 t.quotesingle = 238; 20636 t.quotedblleft = 500; 20637 t.guillemotleft = 556; 20638 t.guilsinglleft = 333; 20639 t.guilsinglright = 333; 20640 t.fi = 611; 20641 t.fl = 611; 20642 t.endash = 556; 20643 t.dagger = 556; 20644 t.daggerdbl = 556; 20645 t.periodcentered = 278; 20646 t.paragraph = 556; 20647 t.bullet = 350; 20648 t.quotesinglbase = 278; 20649 t.quotedblbase = 500; 20650 t.quotedblright = 500; 20651 t.guillemotright = 556; 20652 t.ellipsis = 1000; 20653 t.perthousand = 1000; 20654 t.questiondown = 611; 20655 t.grave = 333; 20656 t.acute = 333; 20657 t.circumflex = 333; 20658 t.tilde = 333; 20659 t.macron = 333; 20660 t.breve = 333; 20661 t.dotaccent = 333; 20662 t.dieresis = 333; 20663 t.ring = 333; 20664 t.cedilla = 333; 20665 t.hungarumlaut = 333; 20666 t.ogonek = 333; 20667 t.caron = 333; 20668 t.emdash = 1000; 20669 t.AE = 1000; 20670 t.ordfeminine = 370; 20671 t.Lslash = 611; 20672 t.Oslash = 778; 20673 t.OE = 1000; 20674 t.ordmasculine = 365; 20675 t.ae = 889; 20676 t.dotlessi = 278; 20677 t.lslash = 278; 20678 t.oslash = 611; 20679 t.oe = 944; 20680 t.germandbls = 611; 20681 t.Idieresis = 278; 20682 t.eacute = 556; 20683 t.abreve = 556; 20684 t.uhungarumlaut = 611; 20685 t.ecaron = 556; 20686 t.Ydieresis = 667; 20687 t.divide = 584; 20688 t.Yacute = 667; 20689 t.Acircumflex = 722; 20690 t.aacute = 556; 20691 t.Ucircumflex = 722; 20692 t.yacute = 556; 20693 t.scommaaccent = 556; 20694 t.ecircumflex = 556; 20695 t.Uring = 722; 20696 t.Udieresis = 722; 20697 t.aogonek = 556; 20698 t.Uacute = 722; 20699 t.uogonek = 611; 20700 t.Edieresis = 667; 20701 t.Dcroat = 722; 20702 t.commaaccent = 250; 20703 t.copyright = 737; 20704 t.Emacron = 667; 20705 t.ccaron = 556; 20706 t.aring = 556; 20707 t.Ncommaaccent = 722; 20708 t.lacute = 278; 20709 t.agrave = 556; 20710 t.Tcommaaccent = 611; 20711 t.Cacute = 722; 20712 t.atilde = 556; 20713 t.Edotaccent = 667; 20714 t.scaron = 556; 20715 t.scedilla = 556; 20716 t.iacute = 278; 20717 t.lozenge = 494; 20718 t.Rcaron = 722; 20719 t.Gcommaaccent = 778; 20720 t.ucircumflex = 611; 20721 t.acircumflex = 556; 20722 t.Amacron = 722; 20723 t.rcaron = 389; 20724 t.ccedilla = 556; 20725 t.Zdotaccent = 611; 20726 t.Thorn = 667; 20727 t.Omacron = 778; 20728 t.Racute = 722; 20729 t.Sacute = 667; 20730 t.dcaron = 743; 20731 t.Umacron = 722; 20732 t.uring = 611; 20733 t.threesuperior = 333; 20734 t.Ograve = 778; 20735 t.Agrave = 722; 20736 t.Abreve = 722; 20737 t.multiply = 584; 20738 t.uacute = 611; 20739 t.Tcaron = 611; 20740 t.partialdiff = 494; 20741 t.ydieresis = 556; 20742 t.Nacute = 722; 20743 t.icircumflex = 278; 20744 t.Ecircumflex = 667; 20745 t.adieresis = 556; 20746 t.edieresis = 556; 20747 t.cacute = 556; 20748 t.nacute = 611; 20749 t.umacron = 611; 20750 t.Ncaron = 722; 20751 t.Iacute = 278; 20752 t.plusminus = 584; 20753 t.brokenbar = 280; 20754 t.registered = 737; 20755 t.Gbreve = 778; 20756 t.Idotaccent = 278; 20757 t.summation = 600; 20758 t.Egrave = 667; 20759 t.racute = 389; 20760 t.omacron = 611; 20761 t.Zacute = 611; 20762 t.Zcaron = 611; 20763 t.greaterequal = 549; 20764 t.Eth = 722; 20765 t.Ccedilla = 722; 20766 t.lcommaaccent = 278; 20767 t.tcaron = 389; 20768 t.eogonek = 556; 20769 t.Uogonek = 722; 20770 t.Aacute = 722; 20771 t.Adieresis = 722; 20772 t.egrave = 556; 20773 t.zacute = 500; 20774 t.iogonek = 278; 20775 t.Oacute = 778; 20776 t.oacute = 611; 20777 t.amacron = 556; 20778 t.sacute = 556; 20779 t.idieresis = 278; 20780 t.Ocircumflex = 778; 20781 t.Ugrave = 722; 20782 t.Delta = 612; 20783 t.thorn = 611; 20784 t.twosuperior = 333; 20785 t.Odieresis = 778; 20786 t.mu = 611; 20787 t.igrave = 278; 20788 t.ohungarumlaut = 611; 20789 t.Eogonek = 667; 20790 t.dcroat = 611; 20791 t.threequarters = 834; 20792 t.Scedilla = 667; 20793 t.lcaron = 400; 20794 t.Kcommaaccent = 722; 20795 t.Lacute = 611; 20796 t.trademark = 1000; 20797 t.edotaccent = 556; 20798 t.Igrave = 278; 20799 t.Imacron = 278; 20800 t.Lcaron = 611; 20801 t.onehalf = 834; 20802 t.lessequal = 549; 20803 t.ocircumflex = 611; 20804 t.ntilde = 611; 20805 t.Uhungarumlaut = 722; 20806 t.Eacute = 667; 20807 t.emacron = 556; 20808 t.gbreve = 611; 20809 t.onequarter = 834; 20810 t.Scaron = 667; 20811 t.Scommaaccent = 667; 20812 t.Ohungarumlaut = 778; 20813 t.degree = 400; 20814 t.ograve = 611; 20815 t.Ccaron = 722; 20816 t.ugrave = 611; 20817 t.radical = 549; 20818 t.Dcaron = 722; 20819 t.rcommaaccent = 389; 20820 t.Ntilde = 722; 20821 t.otilde = 611; 20822 t.Rcommaaccent = 722; 20823 t.Lcommaaccent = 611; 20824 t.Atilde = 722; 20825 t.Aogonek = 722; 20826 t.Aring = 722; 20827 t.Otilde = 778; 20828 t.zdotaccent = 500; 20829 t.Ecaron = 667; 20830 t.Iogonek = 278; 20831 t.kcommaaccent = 556; 20832 t.minus = 584; 20833 t.Icircumflex = 278; 20834 t.ncaron = 611; 20835 t.tcommaaccent = 333; 20836 t.logicalnot = 584; 20837 t.odieresis = 611; 20838 t.udieresis = 611; 20839 t.notequal = 549; 20840 t.gcommaaccent = 611; 20841 t.eth = 611; 20842 t.zcaron = 500; 20843 t.ncommaaccent = 611; 20844 t.onesuperior = 333; 20845 t.imacron = 278; 20846 t.Euro = 556; 20847 }); 20848 t["Helvetica-BoldOblique"] = getLookupTableFactory(function (t) { 20849 t.space = 278; 20850 t.exclam = 333; 20851 t.quotedbl = 474; 20852 t.numbersign = 556; 20853 t.dollar = 556; 20854 t.percent = 889; 20855 t.ampersand = 722; 20856 t.quoteright = 278; 20857 t.parenleft = 333; 20858 t.parenright = 333; 20859 t.asterisk = 389; 20860 t.plus = 584; 20861 t.comma = 278; 20862 t.hyphen = 333; 20863 t.period = 278; 20864 t.slash = 278; 20865 t.zero = 556; 20866 t.one = 556; 20867 t.two = 556; 20868 t.three = 556; 20869 t.four = 556; 20870 t.five = 556; 20871 t.six = 556; 20872 t.seven = 556; 20873 t.eight = 556; 20874 t.nine = 556; 20875 t.colon = 333; 20876 t.semicolon = 333; 20877 t.less = 584; 20878 t.equal = 584; 20879 t.greater = 584; 20880 t.question = 611; 20881 t.at = 975; 20882 t.A = 722; 20883 t.B = 722; 20884 t.C = 722; 20885 t.D = 722; 20886 t.E = 667; 20887 t.F = 611; 20888 t.G = 778; 20889 t.H = 722; 20890 t.I = 278; 20891 t.J = 556; 20892 t.K = 722; 20893 t.L = 611; 20894 t.M = 833; 20895 t.N = 722; 20896 t.O = 778; 20897 t.P = 667; 20898 t.Q = 778; 20899 t.R = 722; 20900 t.S = 667; 20901 t.T = 611; 20902 t.U = 722; 20903 t.V = 667; 20904 t.W = 944; 20905 t.X = 667; 20906 t.Y = 667; 20907 t.Z = 611; 20908 t.bracketleft = 333; 20909 t.backslash = 278; 20910 t.bracketright = 333; 20911 t.asciicircum = 584; 20912 t.underscore = 556; 20913 t.quoteleft = 278; 20914 t.a = 556; 20915 t.b = 611; 20916 t.c = 556; 20917 t.d = 611; 20918 t.e = 556; 20919 t.f = 333; 20920 t.g = 611; 20921 t.h = 611; 20922 t.i = 278; 20923 t.j = 278; 20924 t.k = 556; 20925 t.l = 278; 20926 t.m = 889; 20927 t.n = 611; 20928 t.o = 611; 20929 t.p = 611; 20930 t.q = 611; 20931 t.r = 389; 20932 t.s = 556; 20933 t.t = 333; 20934 t.u = 611; 20935 t.v = 556; 20936 t.w = 778; 20937 t.x = 556; 20938 t.y = 556; 20939 t.z = 500; 20940 t.braceleft = 389; 20941 t.bar = 280; 20942 t.braceright = 389; 20943 t.asciitilde = 584; 20944 t.exclamdown = 333; 20945 t.cent = 556; 20946 t.sterling = 556; 20947 t.fraction = 167; 20948 t.yen = 556; 20949 t.florin = 556; 20950 t.section = 556; 20951 t.currency = 556; 20952 t.quotesingle = 238; 20953 t.quotedblleft = 500; 20954 t.guillemotleft = 556; 20955 t.guilsinglleft = 333; 20956 t.guilsinglright = 333; 20957 t.fi = 611; 20958 t.fl = 611; 20959 t.endash = 556; 20960 t.dagger = 556; 20961 t.daggerdbl = 556; 20962 t.periodcentered = 278; 20963 t.paragraph = 556; 20964 t.bullet = 350; 20965 t.quotesinglbase = 278; 20966 t.quotedblbase = 500; 20967 t.quotedblright = 500; 20968 t.guillemotright = 556; 20969 t.ellipsis = 1000; 20970 t.perthousand = 1000; 20971 t.questiondown = 611; 20972 t.grave = 333; 20973 t.acute = 333; 20974 t.circumflex = 333; 20975 t.tilde = 333; 20976 t.macron = 333; 20977 t.breve = 333; 20978 t.dotaccent = 333; 20979 t.dieresis = 333; 20980 t.ring = 333; 20981 t.cedilla = 333; 20982 t.hungarumlaut = 333; 20983 t.ogonek = 333; 20984 t.caron = 333; 20985 t.emdash = 1000; 20986 t.AE = 1000; 20987 t.ordfeminine = 370; 20988 t.Lslash = 611; 20989 t.Oslash = 778; 20990 t.OE = 1000; 20991 t.ordmasculine = 365; 20992 t.ae = 889; 20993 t.dotlessi = 278; 20994 t.lslash = 278; 20995 t.oslash = 611; 20996 t.oe = 944; 20997 t.germandbls = 611; 20998 t.Idieresis = 278; 20999 t.eacute = 556; 21000 t.abreve = 556; 21001 t.uhungarumlaut = 611; 21002 t.ecaron = 556; 21003 t.Ydieresis = 667; 21004 t.divide = 584; 21005 t.Yacute = 667; 21006 t.Acircumflex = 722; 21007 t.aacute = 556; 21008 t.Ucircumflex = 722; 21009 t.yacute = 556; 21010 t.scommaaccent = 556; 21011 t.ecircumflex = 556; 21012 t.Uring = 722; 21013 t.Udieresis = 722; 21014 t.aogonek = 556; 21015 t.Uacute = 722; 21016 t.uogonek = 611; 21017 t.Edieresis = 667; 21018 t.Dcroat = 722; 21019 t.commaaccent = 250; 21020 t.copyright = 737; 21021 t.Emacron = 667; 21022 t.ccaron = 556; 21023 t.aring = 556; 21024 t.Ncommaaccent = 722; 21025 t.lacute = 278; 21026 t.agrave = 556; 21027 t.Tcommaaccent = 611; 21028 t.Cacute = 722; 21029 t.atilde = 556; 21030 t.Edotaccent = 667; 21031 t.scaron = 556; 21032 t.scedilla = 556; 21033 t.iacute = 278; 21034 t.lozenge = 494; 21035 t.Rcaron = 722; 21036 t.Gcommaaccent = 778; 21037 t.ucircumflex = 611; 21038 t.acircumflex = 556; 21039 t.Amacron = 722; 21040 t.rcaron = 389; 21041 t.ccedilla = 556; 21042 t.Zdotaccent = 611; 21043 t.Thorn = 667; 21044 t.Omacron = 778; 21045 t.Racute = 722; 21046 t.Sacute = 667; 21047 t.dcaron = 743; 21048 t.Umacron = 722; 21049 t.uring = 611; 21050 t.threesuperior = 333; 21051 t.Ograve = 778; 21052 t.Agrave = 722; 21053 t.Abreve = 722; 21054 t.multiply = 584; 21055 t.uacute = 611; 21056 t.Tcaron = 611; 21057 t.partialdiff = 494; 21058 t.ydieresis = 556; 21059 t.Nacute = 722; 21060 t.icircumflex = 278; 21061 t.Ecircumflex = 667; 21062 t.adieresis = 556; 21063 t.edieresis = 556; 21064 t.cacute = 556; 21065 t.nacute = 611; 21066 t.umacron = 611; 21067 t.Ncaron = 722; 21068 t.Iacute = 278; 21069 t.plusminus = 584; 21070 t.brokenbar = 280; 21071 t.registered = 737; 21072 t.Gbreve = 778; 21073 t.Idotaccent = 278; 21074 t.summation = 600; 21075 t.Egrave = 667; 21076 t.racute = 389; 21077 t.omacron = 611; 21078 t.Zacute = 611; 21079 t.Zcaron = 611; 21080 t.greaterequal = 549; 21081 t.Eth = 722; 21082 t.Ccedilla = 722; 21083 t.lcommaaccent = 278; 21084 t.tcaron = 389; 21085 t.eogonek = 556; 21086 t.Uogonek = 722; 21087 t.Aacute = 722; 21088 t.Adieresis = 722; 21089 t.egrave = 556; 21090 t.zacute = 500; 21091 t.iogonek = 278; 21092 t.Oacute = 778; 21093 t.oacute = 611; 21094 t.amacron = 556; 21095 t.sacute = 556; 21096 t.idieresis = 278; 21097 t.Ocircumflex = 778; 21098 t.Ugrave = 722; 21099 t.Delta = 612; 21100 t.thorn = 611; 21101 t.twosuperior = 333; 21102 t.Odieresis = 778; 21103 t.mu = 611; 21104 t.igrave = 278; 21105 t.ohungarumlaut = 611; 21106 t.Eogonek = 667; 21107 t.dcroat = 611; 21108 t.threequarters = 834; 21109 t.Scedilla = 667; 21110 t.lcaron = 400; 21111 t.Kcommaaccent = 722; 21112 t.Lacute = 611; 21113 t.trademark = 1000; 21114 t.edotaccent = 556; 21115 t.Igrave = 278; 21116 t.Imacron = 278; 21117 t.Lcaron = 611; 21118 t.onehalf = 834; 21119 t.lessequal = 549; 21120 t.ocircumflex = 611; 21121 t.ntilde = 611; 21122 t.Uhungarumlaut = 722; 21123 t.Eacute = 667; 21124 t.emacron = 556; 21125 t.gbreve = 611; 21126 t.onequarter = 834; 21127 t.Scaron = 667; 21128 t.Scommaaccent = 667; 21129 t.Ohungarumlaut = 778; 21130 t.degree = 400; 21131 t.ograve = 611; 21132 t.Ccaron = 722; 21133 t.ugrave = 611; 21134 t.radical = 549; 21135 t.Dcaron = 722; 21136 t.rcommaaccent = 389; 21137 t.Ntilde = 722; 21138 t.otilde = 611; 21139 t.Rcommaaccent = 722; 21140 t.Lcommaaccent = 611; 21141 t.Atilde = 722; 21142 t.Aogonek = 722; 21143 t.Aring = 722; 21144 t.Otilde = 778; 21145 t.zdotaccent = 500; 21146 t.Ecaron = 667; 21147 t.Iogonek = 278; 21148 t.kcommaaccent = 556; 21149 t.minus = 584; 21150 t.Icircumflex = 278; 21151 t.ncaron = 611; 21152 t.tcommaaccent = 333; 21153 t.logicalnot = 584; 21154 t.odieresis = 611; 21155 t.udieresis = 611; 21156 t.notequal = 549; 21157 t.gcommaaccent = 611; 21158 t.eth = 611; 21159 t.zcaron = 500; 21160 t.ncommaaccent = 611; 21161 t.onesuperior = 333; 21162 t.imacron = 278; 21163 t.Euro = 556; 21164 }); 21165 t["Helvetica-Oblique"] = getLookupTableFactory(function (t) { 21166 t.space = 278; 21167 t.exclam = 278; 21168 t.quotedbl = 355; 21169 t.numbersign = 556; 21170 t.dollar = 556; 21171 t.percent = 889; 21172 t.ampersand = 667; 21173 t.quoteright = 222; 21174 t.parenleft = 333; 21175 t.parenright = 333; 21176 t.asterisk = 389; 21177 t.plus = 584; 21178 t.comma = 278; 21179 t.hyphen = 333; 21180 t.period = 278; 21181 t.slash = 278; 21182 t.zero = 556; 21183 t.one = 556; 21184 t.two = 556; 21185 t.three = 556; 21186 t.four = 556; 21187 t.five = 556; 21188 t.six = 556; 21189 t.seven = 556; 21190 t.eight = 556; 21191 t.nine = 556; 21192 t.colon = 278; 21193 t.semicolon = 278; 21194 t.less = 584; 21195 t.equal = 584; 21196 t.greater = 584; 21197 t.question = 556; 21198 t.at = 1015; 21199 t.A = 667; 21200 t.B = 667; 21201 t.C = 722; 21202 t.D = 722; 21203 t.E = 667; 21204 t.F = 611; 21205 t.G = 778; 21206 t.H = 722; 21207 t.I = 278; 21208 t.J = 500; 21209 t.K = 667; 21210 t.L = 556;
vendor: 4,866 bytes, lines 21211-21445
21211 t.M = 833; 21212 t.N = 722; 21213 t.O = 778; 21214 t.P = 667; 21215 t.Q = 778; 21216 t.R = 722; 21217 t.S = 667; 21218 t.T = 611; 21219 t.U = 722; 21220 t.V = 667; 21221 t.W = 944; 21222 t.X = 667; 21223 t.Y = 667; 21224 t.Z = 611; 21225 t.bracketleft = 278; 21226 t.backslash = 278; 21227 t.bracketright = 278; 21228 t.asciicircum = 469; 21229 t.underscore = 556; 21230 t.quoteleft = 222; 21231 t.a = 556; 21232 t.b = 556; 21233 t.c = 500; 21234 t.d = 556; 21235 t.e = 556; 21236 t.f = 278; 21237 t.g = 556; 21238 t.h = 556; 21239 t.i = 222; 21240 t.j = 222; 21241 t.k = 500; 21242 t.l = 222; 21243 t.m = 833; 21244 t.n = 556; 21245 t.o = 556; 21246 t.p = 556; 21247 t.q = 556; 21248 t.r = 333; 21249 t.s = 500; 21250 t.t = 278; 21251 t.u = 556; 21252 t.v = 500; 21253 t.w = 722; 21254 t.x = 500; 21255 t.y = 500; 21256 t.z = 500; 21257 t.braceleft = 334; 21258 t.bar = 260; 21259 t.braceright = 334; 21260 t.asciitilde = 584; 21261 t.exclamdown = 333; 21262 t.cent = 556; 21263 t.sterling = 556; 21264 t.fraction = 167; 21265 t.yen = 556; 21266 t.florin = 556; 21267 t.section = 556; 21268 t.currency = 556; 21269 t.quotesingle = 191; 21270 t.quotedblleft = 333; 21271 t.guillemotleft = 556; 21272 t.guilsinglleft = 333; 21273 t.guilsinglright = 333; 21274 t.fi = 500; 21275 t.fl = 500; 21276 t.endash = 556; 21277 t.dagger = 556; 21278 t.daggerdbl = 556; 21279 t.periodcentered = 278; 21280 t.paragraph = 537; 21281 t.bullet = 350; 21282 t.quotesinglbase = 222; 21283 t.quotedblbase = 333; 21284 t.quotedblright = 333; 21285 t.guillemotright = 556; 21286 t.ellipsis = 1000; 21287 t.perthousand = 1000; 21288 t.questiondown = 611; 21289 t.grave = 333; 21290 t.acute = 333; 21291 t.circumflex = 333; 21292 t.tilde = 333; 21293 t.macron = 333; 21294 t.breve = 333; 21295 t.dotaccent = 333; 21296 t.dieresis = 333; 21297 t.ring = 333; 21298 t.cedilla = 333; 21299 t.hungarumlaut = 333; 21300 t.ogonek = 333; 21301 t.caron = 333; 21302 t.emdash = 1000; 21303 t.AE = 1000; 21304 t.ordfeminine = 370; 21305 t.Lslash = 556; 21306 t.Oslash = 778; 21307 t.OE = 1000; 21308 t.ordmasculine = 365; 21309 t.ae = 889; 21310 t.dotlessi = 278; 21311 t.lslash = 222; 21312 t.oslash = 611; 21313 t.oe = 944; 21314 t.germandbls = 611; 21315 t.Idieresis = 278; 21316 t.eacute = 556; 21317 t.abreve = 556; 21318 t.uhungarumlaut = 556; 21319 t.ecaron = 556; 21320 t.Ydieresis = 667; 21321 t.divide = 584; 21322 t.Yacute = 667; 21323 t.Acircumflex = 667; 21324 t.aacute = 556; 21325 t.Ucircumflex = 722; 21326 t.yacute = 500; 21327 t.scommaaccent = 500; 21328 t.ecircumflex = 556; 21329 t.Uring = 722; 21330 t.Udieresis = 722; 21331 t.aogonek = 556; 21332 t.Uacute = 722; 21333 t.uogonek = 556; 21334 t.Edieresis = 667; 21335 t.Dcroat = 722; 21336 t.commaaccent = 250; 21337 t.copyright = 737; 21338 t.Emacron = 667; 21339 t.ccaron = 500; 21340 t.aring = 556; 21341 t.Ncommaaccent = 722; 21342 t.lacute = 222; 21343 t.agrave = 556; 21344 t.Tcommaaccent = 611; 21345 t.Cacute = 722; 21346 t.atilde = 556; 21347 t.Edotaccent = 667; 21348 t.scaron = 500; 21349 t.scedilla = 500; 21350 t.iacute = 278; 21351 t.lozenge = 471; 21352 t.Rcaron = 722; 21353 t.Gcommaaccent = 778; 21354 t.ucircumflex = 556; 21355 t.acircumflex = 556; 21356 t.Amacron = 667; 21357 t.rcaron = 333; 21358 t.ccedilla = 500; 21359 t.Zdotaccent = 611; 21360 t.Thorn = 667; 21361 t.Omacron = 778; 21362 t.Racute = 722; 21363 t.Sacute = 667; 21364 t.dcaron = 643; 21365 t.Umacron = 722; 21366 t.uring = 556; 21367 t.threesuperior = 333; 21368 t.Ograve = 778; 21369 t.Agrave = 667; 21370 t.Abreve = 667; 21371 t.multiply = 584; 21372 t.uacute = 556; 21373 t.Tcaron = 611; 21374 t.partialdiff = 476; 21375 t.ydieresis = 500; 21376 t.Nacute = 722; 21377 t.icircumflex = 278; 21378 t.Ecircumflex = 667; 21379 t.adieresis = 556; 21380 t.edieresis = 556; 21381 t.cacute = 500; 21382 t.nacute = 556; 21383 t.umacron = 556; 21384 t.Ncaron = 722; 21385 t.Iacute = 278; 21386 t.plusminus = 584; 21387 t.brokenbar = 260; 21388 t.registered = 737; 21389 t.Gbreve = 778; 21390 t.Idotaccent = 278; 21391 t.summation = 600; 21392 t.Egrave = 667; 21393 t.racute = 333; 21394 t.omacron = 556; 21395 t.Zacute = 611; 21396 t.Zcaron = 611; 21397 t.greaterequal = 549; 21398 t.Eth = 722; 21399 t.Ccedilla = 722; 21400 t.lcommaaccent = 222; 21401 t.tcaron = 317; 21402 t.eogonek = 556; 21403 t.Uogonek = 722; 21404 t.Aacute = 667; 21405 t.Adieresis = 667; 21406 t.egrave = 556; 21407 t.zacute = 500; 21408 t.iogonek = 222; 21409 t.Oacute = 778; 21410 t.oacute = 556; 21411 t.amacron = 556; 21412 t.sacute = 500; 21413 t.idieresis = 278; 21414 t.Ocircumflex = 778; 21415 t.Ugrave = 722; 21416 t.Delta = 612; 21417 t.thorn = 556; 21418 t.twosuperior = 333; 21419 t.Odieresis = 778; 21420 t.mu = 556; 21421 t.igrave = 278; 21422 t.ohungarumlaut = 556; 21423 t.Eogonek = 667; 21424 t.dcroat = 556; 21425 t.threequarters = 834; 21426 t.Scedilla = 667; 21427 t.lcaron = 299; 21428 t.Kcommaaccent = 667; 21429 t.Lacute = 556; 21430 t.trademark = 1000; 21431 t.edotaccent = 556; 21432 t.Igrave = 278; 21433 t.Imacron = 278; 21434 t.Lcaron = 556; 21435 t.onehalf = 834; 21436 t.lessequal = 549; 21437 t.ocircumflex = 556; 21438 t.ntilde = 556; 21439 t.Uhungarumlaut = 722; 21440 t.Eacute = 667; 21441 t.emacron = 556; 21442 t.gbreve = 556; 21443 t.onequarter = 834; 21444 t.Scaron = 667; 21445 t.Scommaaccent = 667;
vendor: 25,462 bytes, lines 21446-22670
21446 t.Ohungarumlaut = 778; 21447 t.degree = 400; 21448 t.ograve = 556; 21449 t.Ccaron = 722; 21450 t.ugrave = 556; 21451 t.radical = 453; 21452 t.Dcaron = 722; 21453 t.rcommaaccent = 333; 21454 t.Ntilde = 722; 21455 t.otilde = 556; 21456 t.Rcommaaccent = 722; 21457 t.Lcommaaccent = 556; 21458 t.Atilde = 667; 21459 t.Aogonek = 667; 21460 t.Aring = 667; 21461 t.Otilde = 778; 21462 t.zdotaccent = 500; 21463 t.Ecaron = 667; 21464 t.Iogonek = 278; 21465 t.kcommaaccent = 500; 21466 t.minus = 584; 21467 t.Icircumflex = 278; 21468 t.ncaron = 556; 21469 t.tcommaaccent = 278; 21470 t.logicalnot = 584; 21471 t.odieresis = 556; 21472 t.udieresis = 556; 21473 t.notequal = 549; 21474 t.gcommaaccent = 556; 21475 t.eth = 556; 21476 t.zcaron = 500; 21477 t.ncommaaccent = 556; 21478 t.onesuperior = 333; 21479 t.imacron = 278; 21480 t.Euro = 556; 21481 }); 21482 t.Symbol = getLookupTableFactory(function (t) { 21483 t.space = 250; 21484 t.exclam = 333; 21485 t.universal = 713; 21486 t.numbersign = 500; 21487 t.existential = 549; 21488 t.percent = 833; 21489 t.ampersand = 778; 21490 t.suchthat = 439; 21491 t.parenleft = 333; 21492 t.parenright = 333; 21493 t.asteriskmath = 500; 21494 t.plus = 549; 21495 t.comma = 250; 21496 t.minus = 549; 21497 t.period = 250; 21498 t.slash = 278; 21499 t.zero = 500; 21500 t.one = 500; 21501 t.two = 500; 21502 t.three = 500; 21503 t.four = 500; 21504 t.five = 500; 21505 t.six = 500; 21506 t.seven = 500; 21507 t.eight = 500; 21508 t.nine = 500; 21509 t.colon = 278; 21510 t.semicolon = 278; 21511 t.less = 549; 21512 t.equal = 549; 21513 t.greater = 549; 21514 t.question = 444; 21515 t.congruent = 549; 21516 t.Alpha = 722; 21517 t.Beta = 667; 21518 t.Chi = 722; 21519 t.Delta = 612; 21520 t.Epsilon = 611; 21521 t.Phi = 763; 21522 t.Gamma = 603; 21523 t.Eta = 722; 21524 t.Iota = 333; 21525 t.theta1 = 631; 21526 t.Kappa = 722; 21527 t.Lambda = 686; 21528 t.Mu = 889; 21529 t.Nu = 722; 21530 t.Omicron = 722; 21531 t.Pi = 768; 21532 t.Theta = 741; 21533 t.Rho = 556; 21534 t.Sigma = 592; 21535 t.Tau = 611; 21536 t.Upsilon = 690; 21537 t.sigma1 = 439; 21538 t.Omega = 768; 21539 t.Xi = 645; 21540 t.Psi = 795; 21541 t.Zeta = 611; 21542 t.bracketleft = 333; 21543 t.therefore = 863; 21544 t.bracketright = 333; 21545 t.perpendicular = 658; 21546 t.underscore = 500; 21547 t.radicalex = 500; 21548 t.alpha = 631; 21549 t.beta = 549; 21550 t.chi = 549; 21551 t.delta = 494; 21552 t.epsilon = 439; 21553 t.phi = 521; 21554 t.gamma = 411; 21555 t.eta = 603; 21556 t.iota = 329; 21557 t.phi1 = 603; 21558 t.kappa = 549; 21559 t.lambda = 549; 21560 t.mu = 576; 21561 t.nu = 521; 21562 t.omicron = 549; 21563 t.pi = 549; 21564 t.theta = 521; 21565 t.rho = 549; 21566 t.sigma = 603; 21567 t.tau = 439; 21568 t.upsilon = 576; 21569 t.omega1 = 713; 21570 t.omega = 686; 21571 t.xi = 493; 21572 t.psi = 686; 21573 t.zeta = 494; 21574 t.braceleft = 480; 21575 t.bar = 200; 21576 t.braceright = 480; 21577 t.similar = 549; 21578 t.Euro = 750; 21579 t.Upsilon1 = 620; 21580 t.minute = 247; 21581 t.lessequal = 549; 21582 t.fraction = 167; 21583 t.infinity = 713; 21584 t.florin = 500; 21585 t.club = 753; 21586 t.diamond = 753; 21587 t.heart = 753; 21588 t.spade = 753; 21589 t.arrowboth = 1042; 21590 t.arrowleft = 987; 21591 t.arrowup = 603; 21592 t.arrowright = 987; 21593 t.arrowdown = 603; 21594 t.degree = 400; 21595 t.plusminus = 549; 21596 t.second = 411; 21597 t.greaterequal = 549; 21598 t.multiply = 549; 21599 t.proportional = 713; 21600 t.partialdiff = 494; 21601 t.bullet = 460; 21602 t.divide = 549; 21603 t.notequal = 549; 21604 t.equivalence = 549; 21605 t.approxequal = 549; 21606 t.ellipsis = 1000; 21607 t.arrowvertex = 603; 21608 t.arrowhorizex = 1000; 21609 t.carriagereturn = 658; 21610 t.aleph = 823; 21611 t.Ifraktur = 686; 21612 t.Rfraktur = 795; 21613 t.weierstrass = 987; 21614 t.circlemultiply = 768; 21615 t.circleplus = 768; 21616 t.emptyset = 823; 21617 t.intersection = 768; 21618 t.union = 768; 21619 t.propersuperset = 713; 21620 t.reflexsuperset = 713; 21621 t.notsubset = 713; 21622 t.propersubset = 713; 21623 t.reflexsubset = 713; 21624 t.element = 713; 21625 t.notelement = 713; 21626 t.angle = 768; 21627 t.gradient = 713; 21628 t.registerserif = 790; 21629 t.copyrightserif = 790; 21630 t.trademarkserif = 890; 21631 t.product = 823; 21632 t.radical = 549; 21633 t.dotmath = 250; 21634 t.logicalnot = 713; 21635 t.logicaland = 603; 21636 t.logicalor = 603; 21637 t.arrowdblboth = 1042; 21638 t.arrowdblleft = 987; 21639 t.arrowdblup = 603; 21640 t.arrowdblright = 987; 21641 t.arrowdbldown = 603; 21642 t.lozenge = 494; 21643 t.angleleft = 329; 21644 t.registersans = 790; 21645 t.copyrightsans = 790; 21646 t.trademarksans = 786; 21647 t.summation = 713; 21648 t.parenlefttp = 384; 21649 t.parenleftex = 384; 21650 t.parenleftbt = 384; 21651 t.bracketlefttp = 384; 21652 t.bracketleftex = 384; 21653 t.bracketleftbt = 384; 21654 t.bracelefttp = 494; 21655 t.braceleftmid = 494; 21656 t.braceleftbt = 494; 21657 t.braceex = 494; 21658 t.angleright = 329; 21659 t.integral = 274; 21660 t.integraltp = 686; 21661 t.integralex = 686; 21662 t.integralbt = 686; 21663 t.parenrighttp = 384; 21664 t.parenrightex = 384; 21665 t.parenrightbt = 384; 21666 t.bracketrighttp = 384; 21667 t.bracketrightex = 384; 21668 t.bracketrightbt = 384; 21669 t.bracerighttp = 494; 21670 t.bracerightmid = 494; 21671 t.bracerightbt = 494; 21672 t.apple = 790; 21673 }); 21674 t["Times-Roman"] = getLookupTableFactory(function (t) { 21675 t.space = 250; 21676 t.exclam = 333; 21677 t.quotedbl = 408; 21678 t.numbersign = 500; 21679 t.dollar = 500; 21680 t.percent = 833; 21681 t.ampersand = 778; 21682 t.quoteright = 333; 21683 t.parenleft = 333; 21684 t.parenright = 333; 21685 t.asterisk = 500; 21686 t.plus = 564; 21687 t.comma = 250; 21688 t.hyphen = 333; 21689 t.period = 250; 21690 t.slash = 278; 21691 t.zero = 500; 21692 t.one = 500; 21693 t.two = 500; 21694 t.three = 500; 21695 t.four = 500; 21696 t.five = 500; 21697 t.six = 500; 21698 t.seven = 500; 21699 t.eight = 500; 21700 t.nine = 500; 21701 t.colon = 278; 21702 t.semicolon = 278; 21703 t.less = 564; 21704 t.equal = 564; 21705 t.greater = 564; 21706 t.question = 444; 21707 t.at = 921; 21708 t.A = 722; 21709 t.B = 667; 21710 t.C = 667; 21711 t.D = 722; 21712 t.E = 611; 21713 t.F = 556; 21714 t.G = 722; 21715 t.H = 722; 21716 t.I = 333; 21717 t.J = 389; 21718 t.K = 722; 21719 t.L = 611; 21720 t.M = 889; 21721 t.N = 722; 21722 t.O = 722; 21723 t.P = 556; 21724 t.Q = 722; 21725 t.R = 667; 21726 t.S = 556; 21727 t.T = 611; 21728 t.U = 722; 21729 t.V = 722; 21730 t.W = 944; 21731 t.X = 722; 21732 t.Y = 722; 21733 t.Z = 611; 21734 t.bracketleft = 333; 21735 t.backslash = 278; 21736 t.bracketright = 333; 21737 t.asciicircum = 469; 21738 t.underscore = 500; 21739 t.quoteleft = 333; 21740 t.a = 444; 21741 t.b = 500; 21742 t.c = 444; 21743 t.d = 500; 21744 t.e = 444; 21745 t.f = 333; 21746 t.g = 500; 21747 t.h = 500; 21748 t.i = 278; 21749 t.j = 278; 21750 t.k = 500; 21751 t.l = 278; 21752 t.m = 778; 21753 t.n = 500; 21754 t.o = 500; 21755 t.p = 500; 21756 t.q = 500; 21757 t.r = 333; 21758 t.s = 389; 21759 t.t = 278; 21760 t.u = 500; 21761 t.v = 500; 21762 t.w = 722; 21763 t.x = 500; 21764 t.y = 500; 21765 t.z = 444; 21766 t.braceleft = 480; 21767 t.bar = 200; 21768 t.braceright = 480; 21769 t.asciitilde = 541; 21770 t.exclamdown = 333; 21771 t.cent = 500; 21772 t.sterling = 500; 21773 t.fraction = 167; 21774 t.yen = 500; 21775 t.florin = 500; 21776 t.section = 500; 21777 t.currency = 500; 21778 t.quotesingle = 180; 21779 t.quotedblleft = 444; 21780 t.guillemotleft = 500; 21781 t.guilsinglleft = 333; 21782 t.guilsinglright = 333; 21783 t.fi = 556; 21784 t.fl = 556; 21785 t.endash = 500; 21786 t.dagger = 500; 21787 t.daggerdbl = 500; 21788 t.periodcentered = 250; 21789 t.paragraph = 453; 21790 t.bullet = 350; 21791 t.quotesinglbase = 333; 21792 t.quotedblbase = 444; 21793 t.quotedblright = 444; 21794 t.guillemotright = 500; 21795 t.ellipsis = 1000; 21796 t.perthousand = 1000; 21797 t.questiondown = 444; 21798 t.grave = 333; 21799 t.acute = 333; 21800 t.circumflex = 333; 21801 t.tilde = 333; 21802 t.macron = 333; 21803 t.breve = 333; 21804 t.dotaccent = 333; 21805 t.dieresis = 333; 21806 t.ring = 333; 21807 t.cedilla = 333; 21808 t.hungarumlaut = 333; 21809 t.ogonek = 333; 21810 t.caron = 333; 21811 t.emdash = 1000; 21812 t.AE = 889; 21813 t.ordfeminine = 276; 21814 t.Lslash = 611; 21815 t.Oslash = 722; 21816 t.OE = 889; 21817 t.ordmasculine = 310; 21818 t.ae = 667; 21819 t.dotlessi = 278; 21820 t.lslash = 278; 21821 t.oslash = 500; 21822 t.oe = 722; 21823 t.germandbls = 500; 21824 t.Idieresis = 333; 21825 t.eacute = 444; 21826 t.abreve = 444; 21827 t.uhungarumlaut = 500; 21828 t.ecaron = 444; 21829 t.Ydieresis = 722; 21830 t.divide = 564; 21831 t.Yacute = 722; 21832 t.Acircumflex = 722; 21833 t.aacute = 444; 21834 t.Ucircumflex = 722; 21835 t.yacute = 500; 21836 t.scommaaccent = 389; 21837 t.ecircumflex = 444; 21838 t.Uring = 722; 21839 t.Udieresis = 722; 21840 t.aogonek = 444; 21841 t.Uacute = 722; 21842 t.uogonek = 500; 21843 t.Edieresis = 611; 21844 t.Dcroat = 722; 21845 t.commaaccent = 250; 21846 t.copyright = 760; 21847 t.Emacron = 611; 21848 t.ccaron = 444; 21849 t.aring = 444; 21850 t.Ncommaaccent = 722; 21851 t.lacute = 278; 21852 t.agrave = 444; 21853 t.Tcommaaccent = 611; 21854 t.Cacute = 667; 21855 t.atilde = 444; 21856 t.Edotaccent = 611; 21857 t.scaron = 389; 21858 t.scedilla = 389; 21859 t.iacute = 278; 21860 t.lozenge = 471; 21861 t.Rcaron = 667; 21862 t.Gcommaaccent = 722; 21863 t.ucircumflex = 500; 21864 t.acircumflex = 444; 21865 t.Amacron = 722; 21866 t.rcaron = 333; 21867 t.ccedilla = 444; 21868 t.Zdotaccent = 611; 21869 t.Thorn = 556; 21870 t.Omacron = 722; 21871 t.Racute = 667; 21872 t.Sacute = 556; 21873 t.dcaron = 588; 21874 t.Umacron = 722; 21875 t.uring = 500; 21876 t.threesuperior = 300; 21877 t.Ograve = 722; 21878 t.Agrave = 722; 21879 t.Abreve = 722; 21880 t.multiply = 564; 21881 t.uacute = 500; 21882 t.Tcaron = 611; 21883 t.partialdiff = 476; 21884 t.ydieresis = 500; 21885 t.Nacute = 722; 21886 t.icircumflex = 278; 21887 t.Ecircumflex = 611; 21888 t.adieresis = 444; 21889 t.edieresis = 444; 21890 t.cacute = 444; 21891 t.nacute = 500; 21892 t.umacron = 500; 21893 t.Ncaron = 722; 21894 t.Iacute = 333; 21895 t.plusminus = 564; 21896 t.brokenbar = 200; 21897 t.registered = 760; 21898 t.Gbreve = 722; 21899 t.Idotaccent = 333; 21900 t.summation = 600; 21901 t.Egrave = 611; 21902 t.racute = 333; 21903 t.omacron = 500; 21904 t.Zacute = 611; 21905 t.Zcaron = 611; 21906 t.greaterequal = 549; 21907 t.Eth = 722; 21908 t.Ccedilla = 667; 21909 t.lcommaaccent = 278; 21910 t.tcaron = 326; 21911 t.eogonek = 444; 21912 t.Uogonek = 722; 21913 t.Aacute = 722; 21914 t.Adieresis = 722; 21915 t.egrave = 444; 21916 t.zacute = 444; 21917 t.iogonek = 278; 21918 t.Oacute = 722; 21919 t.oacute = 500; 21920 t.amacron = 444; 21921 t.sacute = 389; 21922 t.idieresis = 278; 21923 t.Ocircumflex = 722; 21924 t.Ugrave = 722; 21925 t.Delta = 612; 21926 t.thorn = 500; 21927 t.twosuperior = 300; 21928 t.Odieresis = 722; 21929 t.mu = 500; 21930 t.igrave = 278; 21931 t.ohungarumlaut = 500; 21932 t.Eogonek = 611; 21933 t.dcroat = 500; 21934 t.threequarters = 750; 21935 t.Scedilla = 556; 21936 t.lcaron = 344; 21937 t.Kcommaaccent = 722; 21938 t.Lacute = 611; 21939 t.trademark = 980; 21940 t.edotaccent = 444; 21941 t.Igrave = 333; 21942 t.Imacron = 333; 21943 t.Lcaron = 611; 21944 t.onehalf = 750; 21945 t.lessequal = 549; 21946 t.ocircumflex = 500; 21947 t.ntilde = 500; 21948 t.Uhungarumlaut = 722; 21949 t.Eacute = 611; 21950 t.emacron = 444; 21951 t.gbreve = 500; 21952 t.onequarter = 750; 21953 t.Scaron = 556; 21954 t.Scommaaccent = 556; 21955 t.Ohungarumlaut = 722; 21956 t.degree = 400; 21957 t.ograve = 500; 21958 t.Ccaron = 667; 21959 t.ugrave = 500; 21960 t.radical = 453; 21961 t.Dcaron = 722; 21962 t.rcommaaccent = 333; 21963 t.Ntilde = 722; 21964 t.otilde = 500; 21965 t.Rcommaaccent = 667; 21966 t.Lcommaaccent = 611; 21967 t.Atilde = 722; 21968 t.Aogonek = 722; 21969 t.Aring = 722; 21970 t.Otilde = 722; 21971 t.zdotaccent = 444; 21972 t.Ecaron = 611; 21973 t.Iogonek = 333; 21974 t.kcommaaccent = 500; 21975 t.minus = 564; 21976 t.Icircumflex = 333; 21977 t.ncaron = 500; 21978 t.tcommaaccent = 278; 21979 t.logicalnot = 564; 21980 t.odieresis = 500; 21981 t.udieresis = 500; 21982 t.notequal = 549; 21983 t.gcommaaccent = 500; 21984 t.eth = 500; 21985 t.zcaron = 444; 21986 t.ncommaaccent = 500; 21987 t.onesuperior = 300; 21988 t.imacron = 278; 21989 t.Euro = 500; 21990 }); 21991 t["Times-Bold"] = getLookupTableFactory(function (t) { 21992 t.space = 250; 21993 t.exclam = 333; 21994 t.quotedbl = 555; 21995 t.numbersign = 500; 21996 t.dollar = 500; 21997 t.percent = 1000; 21998 t.ampersand = 833; 21999 t.quoteright = 333; 22000 t.parenleft = 333; 22001 t.parenright = 333; 22002 t.asterisk = 500; 22003 t.plus = 570; 22004 t.comma = 250; 22005 t.hyphen = 333; 22006 t.period = 250; 22007 t.slash = 278; 22008 t.zero = 500; 22009 t.one = 500; 22010 t.two = 500; 22011 t.three = 500; 22012 t.four = 500; 22013 t.five = 500; 22014 t.six = 500; 22015 t.seven = 500; 22016 t.eight = 500; 22017 t.nine = 500; 22018 t.colon = 333; 22019 t.semicolon = 333; 22020 t.less = 570; 22021 t.equal = 570; 22022 t.greater = 570; 22023 t.question = 500; 22024 t.at = 930; 22025 t.A = 722; 22026 t.B = 667; 22027 t.C = 722; 22028 t.D = 722; 22029 t.E = 667; 22030 t.F = 611; 22031 t.G = 778; 22032 t.H = 778; 22033 t.I = 389; 22034 t.J = 500; 22035 t.K = 778; 22036 t.L = 667; 22037 t.M = 944; 22038 t.N = 722; 22039 t.O = 778; 22040 t.P = 611; 22041 t.Q = 778; 22042 t.R = 722; 22043 t.S = 556; 22044 t.T = 667; 22045 t.U = 722; 22046 t.V = 722; 22047 t.W = 1000; 22048 t.X = 722; 22049 t.Y = 722; 22050 t.Z = 667; 22051 t.bracketleft = 333; 22052 t.backslash = 278; 22053 t.bracketright = 333; 22054 t.asciicircum = 581; 22055 t.underscore = 500; 22056 t.quoteleft = 333; 22057 t.a = 500; 22058 t.b = 556; 22059 t.c = 444; 22060 t.d = 556; 22061 t.e = 444; 22062 t.f = 333; 22063 t.g = 500; 22064 t.h = 556; 22065 t.i = 278; 22066 t.j = 333; 22067 t.k = 556; 22068 t.l = 278; 22069 t.m = 833; 22070 t.n = 556; 22071 t.o = 500; 22072 t.p = 556; 22073 t.q = 556; 22074 t.r = 444; 22075 t.s = 389; 22076 t.t = 333; 22077 t.u = 556; 22078 t.v = 500; 22079 t.w = 722; 22080 t.x = 500; 22081 t.y = 500; 22082 t.z = 444; 22083 t.braceleft = 394; 22084 t.bar = 220; 22085 t.braceright = 394; 22086 t.asciitilde = 520; 22087 t.exclamdown = 333; 22088 t.cent = 500; 22089 t.sterling = 500; 22090 t.fraction = 167; 22091 t.yen = 500; 22092 t.florin = 500; 22093 t.section = 500; 22094 t.currency = 500; 22095 t.quotesingle = 278; 22096 t.quotedblleft = 500; 22097 t.guillemotleft = 500; 22098 t.guilsinglleft = 333; 22099 t.guilsinglright = 333; 22100 t.fi = 556; 22101 t.fl = 556; 22102 t.endash = 500; 22103 t.dagger = 500; 22104 t.daggerdbl = 500; 22105 t.periodcentered = 250; 22106 t.paragraph = 540; 22107 t.bullet = 350; 22108 t.quotesinglbase = 333; 22109 t.quotedblbase = 500; 22110 t.quotedblright = 500; 22111 t.guillemotright = 500; 22112 t.ellipsis = 1000; 22113 t.perthousand = 1000; 22114 t.questiondown = 500; 22115 t.grave = 333; 22116 t.acute = 333; 22117 t.circumflex = 333; 22118 t.tilde = 333; 22119 t.macron = 333; 22120 t.breve = 333; 22121 t.dotaccent = 333; 22122 t.dieresis = 333; 22123 t.ring = 333; 22124 t.cedilla = 333; 22125 t.hungarumlaut = 333; 22126 t.ogonek = 333; 22127 t.caron = 333; 22128 t.emdash = 1000; 22129 t.AE = 1000; 22130 t.ordfeminine = 300; 22131 t.Lslash = 667; 22132 t.Oslash = 778; 22133 t.OE = 1000; 22134 t.ordmasculine = 330; 22135 t.ae = 722; 22136 t.dotlessi = 278; 22137 t.lslash = 278; 22138 t.oslash = 500; 22139 t.oe = 722; 22140 t.germandbls = 556; 22141 t.Idieresis = 389; 22142 t.eacute = 444; 22143 t.abreve = 500; 22144 t.uhungarumlaut = 556; 22145 t.ecaron = 444; 22146 t.Ydieresis = 722; 22147 t.divide = 570; 22148 t.Yacute = 722; 22149 t.Acircumflex = 722; 22150 t.aacute = 500; 22151 t.Ucircumflex = 722; 22152 t.yacute = 500; 22153 t.scommaaccent = 389; 22154 t.ecircumflex = 444; 22155 t.Uring = 722; 22156 t.Udieresis = 722; 22157 t.aogonek = 500; 22158 t.Uacute = 722; 22159 t.uogonek = 556; 22160 t.Edieresis = 667; 22161 t.Dcroat = 722; 22162 t.commaaccent = 250; 22163 t.copyright = 747; 22164 t.Emacron = 667; 22165 t.ccaron = 444; 22166 t.aring = 500; 22167 t.Ncommaaccent = 722; 22168 t.lacute = 278; 22169 t.agrave = 500; 22170 t.Tcommaaccent = 667; 22171 t.Cacute = 722; 22172 t.atilde = 500; 22173 t.Edotaccent = 667; 22174 t.scaron = 389; 22175 t.scedilla = 389; 22176 t.iacute = 278; 22177 t.lozenge = 494; 22178 t.Rcaron = 722; 22179 t.Gcommaaccent = 778; 22180 t.ucircumflex = 556; 22181 t.acircumflex = 500; 22182 t.Amacron = 722; 22183 t.rcaron = 444; 22184 t.ccedilla = 444; 22185 t.Zdotaccent = 667; 22186 t.Thorn = 611; 22187 t.Omacron = 778; 22188 t.Racute = 722; 22189 t.Sacute = 556; 22190 t.dcaron = 672; 22191 t.Umacron = 722; 22192 t.uring = 556; 22193 t.threesuperior = 300; 22194 t.Ograve = 778; 22195 t.Agrave = 722; 22196 t.Abreve = 722; 22197 t.multiply = 570; 22198 t.uacute = 556; 22199 t.Tcaron = 667; 22200 t.partialdiff = 494; 22201 t.ydieresis = 500; 22202 t.Nacute = 722; 22203 t.icircumflex = 278; 22204 t.Ecircumflex = 667; 22205 t.adieresis = 500; 22206 t.edieresis = 444; 22207 t.cacute = 444; 22208 t.nacute = 556; 22209 t.umacron = 556; 22210 t.Ncaron = 722; 22211 t.Iacute = 389; 22212 t.plusminus = 570; 22213 t.brokenbar = 220; 22214 t.registered = 747; 22215 t.Gbreve = 778; 22216 t.Idotaccent = 389; 22217 t.summation = 600; 22218 t.Egrave = 667; 22219 t.racute = 444; 22220 t.omacron = 500; 22221 t.Zacute = 667; 22222 t.Zcaron = 667; 22223 t.greaterequal = 549; 22224 t.Eth = 722; 22225 t.Ccedilla = 722; 22226 t.lcommaaccent = 278; 22227 t.tcaron = 416; 22228 t.eogonek = 444; 22229 t.Uogonek = 722; 22230 t.Aacute = 722; 22231 t.Adieresis = 722; 22232 t.egrave = 444; 22233 t.zacute = 444; 22234 t.iogonek = 278; 22235 t.Oacute = 778; 22236 t.oacute = 500; 22237 t.amacron = 500; 22238 t.sacute = 389; 22239 t.idieresis = 278; 22240 t.Ocircumflex = 778; 22241 t.Ugrave = 722; 22242 t.Delta = 612; 22243 t.thorn = 556; 22244 t.twosuperior = 300; 22245 t.Odieresis = 778; 22246 t.mu = 556; 22247 t.igrave = 278; 22248 t.ohungarumlaut = 500; 22249 t.Eogonek = 667; 22250 t.dcroat = 556; 22251 t.threequarters = 750; 22252 t.Scedilla = 556; 22253 t.lcaron = 394; 22254 t.Kcommaaccent = 778; 22255 t.Lacute = 667; 22256 t.trademark = 1000; 22257 t.edotaccent = 444; 22258 t.Igrave = 389; 22259 t.Imacron = 389; 22260 t.Lcaron = 667; 22261 t.onehalf = 750; 22262 t.lessequal = 549; 22263 t.ocircumflex = 500; 22264 t.ntilde = 556; 22265 t.Uhungarumlaut = 722; 22266 t.Eacute = 667; 22267 t.emacron = 444; 22268 t.gbreve = 500; 22269 t.onequarter = 750; 22270 t.Scaron = 556; 22271 t.Scommaaccent = 556; 22272 t.Ohungarumlaut = 778; 22273 t.degree = 400; 22274 t.ograve = 500; 22275 t.Ccaron = 722; 22276 t.ugrave = 556; 22277 t.radical = 549; 22278 t.Dcaron = 722; 22279 t.rcommaaccent = 444; 22280 t.Ntilde = 722; 22281 t.otilde = 500; 22282 t.Rcommaaccent = 722; 22283 t.Lcommaaccent = 667; 22284 t.Atilde = 722; 22285 t.Aogonek = 722; 22286 t.Aring = 722; 22287 t.Otilde = 778; 22288 t.zdotaccent = 444; 22289 t.Ecaron = 667; 22290 t.Iogonek = 389; 22291 t.kcommaaccent = 556; 22292 t.minus = 570; 22293 t.Icircumflex = 389; 22294 t.ncaron = 556; 22295 t.tcommaaccent = 333; 22296 t.logicalnot = 570; 22297 t.odieresis = 500; 22298 t.udieresis = 556; 22299 t.notequal = 549; 22300 t.gcommaaccent = 500; 22301 t.eth = 500; 22302 t.zcaron = 444; 22303 t.ncommaaccent = 556; 22304 t.onesuperior = 300; 22305 t.imacron = 278; 22306 t.Euro = 500; 22307 }); 22308 t["Times-BoldItalic"] = getLookupTableFactory(function (t) { 22309 t.space = 250; 22310 t.exclam = 389; 22311 t.quotedbl = 555; 22312 t.numbersign = 500; 22313 t.dollar = 500; 22314 t.percent = 833; 22315 t.ampersand = 778; 22316 t.quoteright = 333; 22317 t.parenleft = 333; 22318 t.parenright = 333; 22319 t.asterisk = 500; 22320 t.plus = 570; 22321 t.comma = 250; 22322 t.hyphen = 333; 22323 t.period = 250; 22324 t.slash = 278; 22325 t.zero = 500; 22326 t.one = 500; 22327 t.two = 500; 22328 t.three = 500; 22329 t.four = 500; 22330 t.five = 500; 22331 t.six = 500; 22332 t.seven = 500; 22333 t.eight = 500; 22334 t.nine = 500; 22335 t.colon = 333; 22336 t.semicolon = 333; 22337 t.less = 570; 22338 t.equal = 570; 22339 t.greater = 570; 22340 t.question = 500; 22341 t.at = 832; 22342 t.A = 667; 22343 t.B = 667; 22344 t.C = 667; 22345 t.D = 722; 22346 t.E = 667; 22347 t.F = 667; 22348 t.G = 722; 22349 t.H = 778; 22350 t.I = 389; 22351 t.J = 500; 22352 t.K = 667; 22353 t.L = 611; 22354 t.M = 889; 22355 t.N = 722; 22356 t.O = 722; 22357 t.P = 611; 22358 t.Q = 722; 22359 t.R = 667; 22360 t.S = 556; 22361 t.T = 611; 22362 t.U = 722; 22363 t.V = 667; 22364 t.W = 889; 22365 t.X = 667; 22366 t.Y = 611; 22367 t.Z = 611; 22368 t.bracketleft = 333; 22369 t.backslash = 278; 22370 t.bracketright = 333; 22371 t.asciicircum = 570; 22372 t.underscore = 500; 22373 t.quoteleft = 333; 22374 t.a = 500; 22375 t.b = 500; 22376 t.c = 444; 22377 t.d = 500; 22378 t.e = 444; 22379 t.f = 333; 22380 t.g = 500; 22381 t.h = 556; 22382 t.i = 278; 22383 t.j = 278; 22384 t.k = 500; 22385 t.l = 278; 22386 t.m = 778; 22387 t.n = 556; 22388 t.o = 500; 22389 t.p = 500; 22390 t.q = 500; 22391 t.r = 389; 22392 t.s = 389; 22393 t.t = 278; 22394 t.u = 556; 22395 t.v = 444; 22396 t.w = 667; 22397 t.x = 500; 22398 t.y = 444; 22399 t.z = 389; 22400 t.braceleft = 348; 22401 t.bar = 220; 22402 t.braceright = 348; 22403 t.asciitilde = 570; 22404 t.exclamdown = 389; 22405 t.cent = 500; 22406 t.sterling = 500; 22407 t.fraction = 167; 22408 t.yen = 500; 22409 t.florin = 500; 22410 t.section = 500; 22411 t.currency = 500; 22412 t.quotesingle = 278; 22413 t.quotedblleft = 500; 22414 t.guillemotleft = 500; 22415 t.guilsinglleft = 333; 22416 t.guilsinglright = 333; 22417 t.fi = 556; 22418 t.fl = 556; 22419 t.endash = 500; 22420 t.dagger = 500; 22421 t.daggerdbl = 500; 22422 t.periodcentered = 250; 22423 t.paragraph = 500; 22424 t.bullet = 350; 22425 t.quotesinglbase = 333; 22426 t.quotedblbase = 500; 22427 t.quotedblright = 500; 22428 t.guillemotright = 500; 22429 t.ellipsis = 1000; 22430 t.perthousand = 1000; 22431 t.questiondown = 500; 22432 t.grave = 333; 22433 t.acute = 333; 22434 t.circumflex = 333; 22435 t.tilde = 333; 22436 t.macron = 333; 22437 t.breve = 333; 22438 t.dotaccent = 333; 22439 t.dieresis = 333; 22440 t.ring = 333; 22441 t.cedilla = 333; 22442 t.hungarumlaut = 333; 22443 t.ogonek = 333; 22444 t.caron = 333; 22445 t.emdash = 1000; 22446 t.AE = 944; 22447 t.ordfeminine = 266; 22448 t.Lslash = 611; 22449 t.Oslash = 722; 22450 t.OE = 944; 22451 t.ordmasculine = 300; 22452 t.ae = 722; 22453 t.dotlessi = 278; 22454 t.lslash = 278; 22455 t.oslash = 500; 22456 t.oe = 722; 22457 t.germandbls = 500; 22458 t.Idieresis = 389; 22459 t.eacute = 444; 22460 t.abreve = 500; 22461 t.uhungarumlaut = 556; 22462 t.ecaron = 444; 22463 t.Ydieresis = 611; 22464 t.divide = 570; 22465 t.Yacute = 611; 22466 t.Acircumflex = 667; 22467 t.aacute = 500; 22468 t.Ucircumflex = 722; 22469 t.yacute = 444; 22470 t.scommaaccent = 389; 22471 t.ecircumflex = 444; 22472 t.Uring = 722; 22473 t.Udieresis = 722; 22474 t.aogonek = 500; 22475 t.Uacute = 722; 22476 t.uogonek = 556; 22477 t.Edieresis = 667; 22478 t.Dcroat = 722; 22479 t.commaaccent = 250; 22480 t.copyright = 747; 22481 t.Emacron = 667; 22482 t.ccaron = 444; 22483 t.aring = 500; 22484 t.Ncommaaccent = 722; 22485 t.lacute = 278; 22486 t.agrave = 500; 22487 t.Tcommaaccent = 611; 22488 t.Cacute = 667; 22489 t.atilde = 500; 22490 t.Edotaccent = 667; 22491 t.scaron = 389; 22492 t.scedilla = 389; 22493 t.iacute = 278; 22494 t.lozenge = 494; 22495 t.Rcaron = 667; 22496 t.Gcommaaccent = 722; 22497 t.ucircumflex = 556; 22498 t.acircumflex = 500; 22499 t.Amacron = 667; 22500 t.rcaron = 389; 22501 t.ccedilla = 444; 22502 t.Zdotaccent = 611; 22503 t.Thorn = 611; 22504 t.Omacron = 722; 22505 t.Racute = 667; 22506 t.Sacute = 556; 22507 t.dcaron = 608; 22508 t.Umacron = 722; 22509 t.uring = 556; 22510 t.threesuperior = 300; 22511 t.Ograve = 722; 22512 t.Agrave = 667; 22513 t.Abreve = 667; 22514 t.multiply = 570; 22515 t.uacute = 556; 22516 t.Tcaron = 611; 22517 t.partialdiff = 494; 22518 t.ydieresis = 444; 22519 t.Nacute = 722; 22520 t.icircumflex = 278; 22521 t.Ecircumflex = 667; 22522 t.adieresis = 500; 22523 t.edieresis = 444; 22524 t.cacute = 444; 22525 t.nacute = 556; 22526 t.umacron = 556; 22527 t.Ncaron = 722; 22528 t.Iacute = 389; 22529 t.plusminus = 570; 22530 t.brokenbar = 220; 22531 t.registered = 747; 22532 t.Gbreve = 722; 22533 t.Idotaccent = 389; 22534 t.summation = 600; 22535 t.Egrave = 667; 22536 t.racute = 389; 22537 t.omacron = 500; 22538 t.Zacute = 611; 22539 t.Zcaron = 611; 22540 t.greaterequal = 549; 22541 t.Eth = 722; 22542 t.Ccedilla = 667; 22543 t.lcommaaccent = 278; 22544 t.tcaron = 366; 22545 t.eogonek = 444; 22546 t.Uogonek = 722; 22547 t.Aacute = 667; 22548 t.Adieresis = 667; 22549 t.egrave = 444; 22550 t.zacute = 389; 22551 t.iogonek = 278; 22552 t.Oacute = 722; 22553 t.oacute = 500; 22554 t.amacron = 500; 22555 t.sacute = 389; 22556 t.idieresis = 278; 22557 t.Ocircumflex = 722; 22558 t.Ugrave = 722; 22559 t.Delta = 612; 22560 t.thorn = 500; 22561 t.twosuperior = 300; 22562 t.Odieresis = 722; 22563 t.mu = 576; 22564 t.igrave = 278; 22565 t.ohungarumlaut = 500; 22566 t.Eogonek = 667; 22567 t.dcroat = 500; 22568 t.threequarters = 750; 22569 t.Scedilla = 556; 22570 t.lcaron = 382; 22571 t.Kcommaaccent = 667; 22572 t.Lacute = 611; 22573 t.trademark = 1000; 22574 t.edotaccent = 444; 22575 t.Igrave = 389; 22576 t.Imacron = 389; 22577 t.Lcaron = 611; 22578 t.onehalf = 750; 22579 t.lessequal = 549; 22580 t.ocircumflex = 500; 22581 t.ntilde = 556; 22582 t.Uhungarumlaut = 722; 22583 t.Eacute = 667; 22584 t.emacron = 444; 22585 t.gbreve = 500; 22586 t.onequarter = 750; 22587 t.Scaron = 556; 22588 t.Scommaaccent = 556; 22589 t.Ohungarumlaut = 722; 22590 t.degree = 400; 22591 t.ograve = 500; 22592 t.Ccaron = 667; 22593 t.ugrave = 556; 22594 t.radical = 549; 22595 t.Dcaron = 722; 22596 t.rcommaaccent = 389; 22597 t.Ntilde = 722; 22598 t.otilde = 500; 22599 t.Rcommaaccent = 667; 22600 t.Lcommaaccent = 611; 22601 t.Atilde = 667; 22602 t.Aogonek = 667; 22603 t.Aring = 667; 22604 t.Otilde = 722; 22605 t.zdotaccent = 389; 22606 t.Ecaron = 667; 22607 t.Iogonek = 389; 22608 t.kcommaaccent = 500; 22609 t.minus = 606; 22610 t.Icircumflex = 389; 22611 t.ncaron = 556; 22612 t.tcommaaccent = 278; 22613 t.logicalnot = 606; 22614 t.odieresis = 500; 22615 t.udieresis = 556; 22616 t.notequal = 549; 22617 t.gcommaaccent = 500; 22618 t.eth = 500; 22619 t.zcaron = 389; 22620 t.ncommaaccent = 556; 22621 t.onesuperior = 300; 22622 t.imacron = 278; 22623 t.Euro = 500; 22624 }); 22625 t["Times-Italic"] = getLookupTableFactory(function (t) { 22626 t.space = 250; 22627 t.exclam = 333; 22628 t.quotedbl = 420; 22629 t.numbersign = 500; 22630 t.dollar = 500; 22631 t.percent = 833; 22632 t.ampersand = 778; 22633 t.quoteright = 333; 22634 t.parenleft = 333; 22635 t.parenright = 333; 22636 t.asterisk = 500; 22637 t.plus = 675; 22638 t.comma = 250; 22639 t.hyphen = 333; 22640 t.period = 250; 22641 t.slash = 278; 22642 t.zero = 500; 22643 t.one = 500; 22644 t.two = 500; 22645 t.three = 500; 22646 t.four = 500; 22647 t.five = 500; 22648 t.six = 500; 22649 t.seven = 500; 22650 t.eight = 500; 22651 t.nine = 500; 22652 t.colon = 333; 22653 t.semicolon = 333; 22654 t.less = 675; 22655 t.equal = 675; 22656 t.greater = 675; 22657 t.question = 500; 22658 t.at = 920; 22659 t.A = 611; 22660 t.B = 611; 22661 t.C = 667; 22662 t.D = 722; 22663 t.E = 611; 22664 t.F = 611; 22665 t.G = 722; 22666 t.H = 722; 22667 t.I = 333; 22668 t.J = 444; 22669 t.K = 667; 22670 t.L = 556;
vendor: 4,861 bytes, lines 22671-22905
22671 t.M = 833; 22672 t.N = 667; 22673 t.O = 722; 22674 t.P = 611; 22675 t.Q = 722; 22676 t.R = 611; 22677 t.S = 500; 22678 t.T = 556; 22679 t.U = 722; 22680 t.V = 611; 22681 t.W = 833; 22682 t.X = 611; 22683 t.Y = 556; 22684 t.Z = 556; 22685 t.bracketleft = 389; 22686 t.backslash = 278; 22687 t.bracketright = 389; 22688 t.asciicircum = 422; 22689 t.underscore = 500; 22690 t.quoteleft = 333; 22691 t.a = 500; 22692 t.b = 500; 22693 t.c = 444; 22694 t.d = 500; 22695 t.e = 444; 22696 t.f = 278; 22697 t.g = 500; 22698 t.h = 500; 22699 t.i = 278; 22700 t.j = 278; 22701 t.k = 444; 22702 t.l = 278; 22703 t.m = 722; 22704 t.n = 500; 22705 t.o = 500; 22706 t.p = 500; 22707 t.q = 500; 22708 t.r = 389; 22709 t.s = 389; 22710 t.t = 278; 22711 t.u = 500; 22712 t.v = 444; 22713 t.w = 667; 22714 t.x = 444; 22715 t.y = 444; 22716 t.z = 389; 22717 t.braceleft = 400; 22718 t.bar = 275; 22719 t.braceright = 400; 22720 t.asciitilde = 541; 22721 t.exclamdown = 389; 22722 t.cent = 500; 22723 t.sterling = 500; 22724 t.fraction = 167; 22725 t.yen = 500; 22726 t.florin = 500; 22727 t.section = 500; 22728 t.currency = 500; 22729 t.quotesingle = 214; 22730 t.quotedblleft = 556; 22731 t.guillemotleft = 500; 22732 t.guilsinglleft = 333; 22733 t.guilsinglright = 333; 22734 t.fi = 500; 22735 t.fl = 500; 22736 t.endash = 500; 22737 t.dagger = 500; 22738 t.daggerdbl = 500; 22739 t.periodcentered = 250; 22740 t.paragraph = 523; 22741 t.bullet = 350; 22742 t.quotesinglbase = 333; 22743 t.quotedblbase = 556; 22744 t.quotedblright = 556; 22745 t.guillemotright = 500; 22746 t.ellipsis = 889; 22747 t.perthousand = 1000; 22748 t.questiondown = 500; 22749 t.grave = 333; 22750 t.acute = 333; 22751 t.circumflex = 333; 22752 t.tilde = 333; 22753 t.macron = 333; 22754 t.breve = 333; 22755 t.dotaccent = 333; 22756 t.dieresis = 333; 22757 t.ring = 333; 22758 t.cedilla = 333; 22759 t.hungarumlaut = 333; 22760 t.ogonek = 333; 22761 t.caron = 333; 22762 t.emdash = 889; 22763 t.AE = 889; 22764 t.ordfeminine = 276; 22765 t.Lslash = 556; 22766 t.Oslash = 722; 22767 t.OE = 944; 22768 t.ordmasculine = 310; 22769 t.ae = 667; 22770 t.dotlessi = 278; 22771 t.lslash = 278; 22772 t.oslash = 500; 22773 t.oe = 667; 22774 t.germandbls = 500; 22775 t.Idieresis = 333; 22776 t.eacute = 444; 22777 t.abreve = 500; 22778 t.uhungarumlaut = 500; 22779 t.ecaron = 444; 22780 t.Ydieresis = 556; 22781 t.divide = 675; 22782 t.Yacute = 556; 22783 t.Acircumflex = 611; 22784 t.aacute = 500; 22785 t.Ucircumflex = 722; 22786 t.yacute = 444; 22787 t.scommaaccent = 389; 22788 t.ecircumflex = 444; 22789 t.Uring = 722; 22790 t.Udieresis = 722; 22791 t.aogonek = 500; 22792 t.Uacute = 722; 22793 t.uogonek = 500; 22794 t.Edieresis = 611; 22795 t.Dcroat = 722; 22796 t.commaaccent = 250; 22797 t.copyright = 760; 22798 t.Emacron = 611; 22799 t.ccaron = 444; 22800 t.aring = 500; 22801 t.Ncommaaccent = 667; 22802 t.lacute = 278; 22803 t.agrave = 500; 22804 t.Tcommaaccent = 556; 22805 t.Cacute = 667; 22806 t.atilde = 500; 22807 t.Edotaccent = 611; 22808 t.scaron = 389; 22809 t.scedilla = 389; 22810 t.iacute = 278; 22811 t.lozenge = 471; 22812 t.Rcaron = 611; 22813 t.Gcommaaccent = 722; 22814 t.ucircumflex = 500; 22815 t.acircumflex = 500; 22816 t.Amacron = 611; 22817 t.rcaron = 389; 22818 t.ccedilla = 444; 22819 t.Zdotaccent = 556; 22820 t.Thorn = 611; 22821 t.Omacron = 722; 22822 t.Racute = 611; 22823 t.Sacute = 500; 22824 t.dcaron = 544; 22825 t.Umacron = 722; 22826 t.uring = 500; 22827 t.threesuperior = 300; 22828 t.Ograve = 722; 22829 t.Agrave = 611; 22830 t.Abreve = 611; 22831 t.multiply = 675; 22832 t.uacute = 500; 22833 t.Tcaron = 556; 22834 t.partialdiff = 476; 22835 t.ydieresis = 444; 22836 t.Nacute = 667; 22837 t.icircumflex = 278; 22838 t.Ecircumflex = 611; 22839 t.adieresis = 500; 22840 t.edieresis = 444; 22841 t.cacute = 444; 22842 t.nacute = 500; 22843 t.umacron = 500; 22844 t.Ncaron = 667; 22845 t.Iacute = 333; 22846 t.plusminus = 675; 22847 t.brokenbar = 275; 22848 t.registered = 760; 22849 t.Gbreve = 722; 22850 t.Idotaccent = 333; 22851 t.summation = 600; 22852 t.Egrave = 611; 22853 t.racute = 389; 22854 t.omacron = 500; 22855 t.Zacute = 556; 22856 t.Zcaron = 556; 22857 t.greaterequal = 549; 22858 t.Eth = 722; 22859 t.Ccedilla = 667; 22860 t.lcommaaccent = 278; 22861 t.tcaron = 300; 22862 t.eogonek = 444; 22863 t.Uogonek = 722; 22864 t.Aacute = 611; 22865 t.Adieresis = 611; 22866 t.egrave = 444; 22867 t.zacute = 389; 22868 t.iogonek = 278; 22869 t.Oacute = 722; 22870 t.oacute = 500; 22871 t.amacron = 500; 22872 t.sacute = 389; 22873 t.idieresis = 278; 22874 t.Ocircumflex = 722; 22875 t.Ugrave = 722; 22876 t.Delta = 612; 22877 t.thorn = 500; 22878 t.twosuperior = 300; 22879 t.Odieresis = 722; 22880 t.mu = 500; 22881 t.igrave = 278; 22882 t.ohungarumlaut = 500; 22883 t.Eogonek = 611; 22884 t.dcroat = 500; 22885 t.threequarters = 750; 22886 t.Scedilla = 500; 22887 t.lcaron = 300; 22888 t.Kcommaaccent = 667; 22889 t.Lacute = 556; 22890 t.trademark = 980; 22891 t.edotaccent = 444; 22892 t.Igrave = 333; 22893 t.Imacron = 333; 22894 t.Lcaron = 611; 22895 t.onehalf = 750; 22896 t.lessequal = 549; 22897 t.ocircumflex = 500; 22898 t.ntilde = 500; 22899 t.Uhungarumlaut = 722; 22900 t.Eacute = 611; 22901 t.emacron = 444; 22902 t.gbreve = 500; 22903 t.onequarter = 750; 22904 t.Scaron = 500; 22905 t.Scommaaccent = 500;
vendor: 5,928 bytes, lines 22906-23234
22906 t.Ohungarumlaut = 722; 22907 t.degree = 400; 22908 t.ograve = 500; 22909 t.Ccaron = 667; 22910 t.ugrave = 500; 22911 t.radical = 453; 22912 t.Dcaron = 722; 22913 t.rcommaaccent = 389; 22914 t.Ntilde = 667; 22915 t.otilde = 500; 22916 t.Rcommaaccent = 611; 22917 t.Lcommaaccent = 556; 22918 t.Atilde = 611; 22919 t.Aogonek = 611; 22920 t.Aring = 611; 22921 t.Otilde = 722; 22922 t.zdotaccent = 389; 22923 t.Ecaron = 611; 22924 t.Iogonek = 333; 22925 t.kcommaaccent = 444; 22926 t.minus = 675; 22927 t.Icircumflex = 333; 22928 t.ncaron = 500; 22929 t.tcommaaccent = 278; 22930 t.logicalnot = 675; 22931 t.odieresis = 500; 22932 t.udieresis = 500; 22933 t.notequal = 549; 22934 t.gcommaaccent = 500; 22935 t.eth = 500; 22936 t.zcaron = 389; 22937 t.ncommaaccent = 500; 22938 t.onesuperior = 300; 22939 t.imacron = 278; 22940 t.Euro = 500; 22941 }); 22942 t.ZapfDingbats = getLookupTableFactory(function (t) { 22943 t.space = 278; 22944 t.a1 = 974; 22945 t.a2 = 961; 22946 t.a202 = 974; 22947 t.a3 = 980; 22948 t.a4 = 719; 22949 t.a5 = 789; 22950 t.a119 = 790; 22951 t.a118 = 791; 22952 t.a117 = 690; 22953 t.a11 = 960; 22954 t.a12 = 939; 22955 t.a13 = 549; 22956 t.a14 = 855; 22957 t.a15 = 911; 22958 t.a16 = 933; 22959 t.a105 = 911; 22960 t.a17 = 945; 22961 t.a18 = 974; 22962 t.a19 = 755; 22963 t.a20 = 846; 22964 t.a21 = 762; 22965 t.a22 = 761; 22966 t.a23 = 571; 22967 t.a24 = 677; 22968 t.a25 = 763; 22969 t.a26 = 760; 22970 t.a27 = 759; 22971 t.a28 = 754; 22972 t.a6 = 494; 22973 t.a7 = 552; 22974 t.a8 = 537; 22975 t.a9 = 577; 22976 t.a10 = 692; 22977 t.a29 = 786; 22978 t.a30 = 788; 22979 t.a31 = 788; 22980 t.a32 = 790; 22981 t.a33 = 793; 22982 t.a34 = 794; 22983 t.a35 = 816; 22984 t.a36 = 823; 22985 t.a37 = 789; 22986 t.a38 = 841; 22987 t.a39 = 823; 22988 t.a40 = 833; 22989 t.a41 = 816; 22990 t.a42 = 831; 22991 t.a43 = 923; 22992 t.a44 = 744; 22993 t.a45 = 723; 22994 t.a46 = 749; 22995 t.a47 = 790; 22996 t.a48 = 792; 22997 t.a49 = 695; 22998 t.a50 = 776; 22999 t.a51 = 768; 23000 t.a52 = 792; 23001 t.a53 = 759; 23002 t.a54 = 707; 23003 t.a55 = 708; 23004 t.a56 = 682; 23005 t.a57 = 701; 23006 t.a58 = 826; 23007 t.a59 = 815; 23008 t.a60 = 789; 23009 t.a61 = 789; 23010 t.a62 = 707; 23011 t.a63 = 687; 23012 t.a64 = 696; 23013 t.a65 = 689; 23014 t.a66 = 786; 23015 t.a67 = 787; 23016 t.a68 = 713; 23017 t.a69 = 791; 23018 t.a70 = 785; 23019 t.a71 = 791; 23020 t.a72 = 873; 23021 t.a73 = 761; 23022 t.a74 = 762; 23023 t.a203 = 762; 23024 t.a75 = 759; 23025 t.a204 = 759; 23026 t.a76 = 892; 23027 t.a77 = 892; 23028 t.a78 = 788; 23029 t.a79 = 784; 23030 t.a81 = 438; 23031 t.a82 = 138; 23032 t.a83 = 277; 23033 t.a84 = 415; 23034 t.a97 = 392; 23035 t.a98 = 392; 23036 t.a99 = 668; 23037 t.a100 = 668; 23038 t.a89 = 390; 23039 t.a90 = 390; 23040 t.a93 = 317; 23041 t.a94 = 317; 23042 t.a91 = 276; 23043 t.a92 = 276; 23044 t.a205 = 509; 23045 t.a85 = 509; 23046 t.a206 = 410; 23047 t.a86 = 410; 23048 t.a87 = 234; 23049 t.a88 = 234; 23050 t.a95 = 334; 23051 t.a96 = 334; 23052 t.a101 = 732; 23053 t.a102 = 544; 23054 t.a103 = 544; 23055 t.a104 = 910; 23056 t.a106 = 667; 23057 t.a107 = 760; 23058 t.a108 = 760; 23059 t.a112 = 776; 23060 t.a111 = 595; 23061 t.a110 = 694; 23062 t.a109 = 626; 23063 t.a120 = 788; 23064 t.a121 = 788; 23065 t.a122 = 788; 23066 t.a123 = 788; 23067 t.a124 = 788; 23068 t.a125 = 788; 23069 t.a126 = 788; 23070 t.a127 = 788; 23071 t.a128 = 788; 23072 t.a129 = 788; 23073 t.a130 = 788; 23074 t.a131 = 788; 23075 t.a132 = 788; 23076 t.a133 = 788; 23077 t.a134 = 788; 23078 t.a135 = 788; 23079 t.a136 = 788; 23080 t.a137 = 788; 23081 t.a138 = 788; 23082 t.a139 = 788; 23083 t.a140 = 788; 23084 t.a141 = 788; 23085 t.a142 = 788; 23086 t.a143 = 788; 23087 t.a144 = 788; 23088 t.a145 = 788; 23089 t.a146 = 788; 23090 t.a147 = 788; 23091 t.a148 = 788; 23092 t.a149 = 788; 23093 t.a150 = 788; 23094 t.a151 = 788; 23095 t.a152 = 788; 23096 t.a153 = 788; 23097 t.a154 = 788; 23098 t.a155 = 788; 23099 t.a156 = 788; 23100 t.a157 = 788; 23101 t.a158 = 788; 23102 t.a159 = 788; 23103 t.a160 = 894; 23104 t.a161 = 838; 23105 t.a163 = 1016; 23106 t.a164 = 458; 23107 t.a196 = 748; 23108 t.a165 = 924; 23109 t.a192 = 748; 23110 t.a166 = 918; 23111 t.a167 = 927; 23112 t.a168 = 928; 23113 t.a169 = 928; 23114 t.a170 = 834; 23115 t.a171 = 873; 23116 t.a172 = 828; 23117 t.a173 = 924; 23118 t.a162 = 924; 23119 t.a174 = 917; 23120 t.a175 = 930; 23121 t.a176 = 931; 23122 t.a177 = 463; 23123 t.a178 = 883; 23124 t.a179 = 836; 23125 t.a193 = 836; 23126 t.a180 = 867; 23127 t.a199 = 867; 23128 t.a181 = 696; 23129 t.a200 = 696; 23130 t.a182 = 874; 23131 t.a201 = 874; 23132 t.a183 = 760; 23133 t.a184 = 946; 23134 t.a197 = 771; 23135 t.a185 = 865; 23136 t.a194 = 771; 23137 t.a198 = 888; 23138 t.a186 = 967; 23139 t.a195 = 888; 23140 t.a187 = 831; 23141 t.a188 = 873; 23142 t.a189 = 927; 23143 t.a190 = 970; 23144 t.a191 = 918; 23145 }); 23146}); 23147const getFontBasicMetrics = getLookupTableFactory(function (t) { 23148 t.Courier = { 23149 ascent: 629, 23150 descent: -157, 23151 capHeight: 562, 23152 xHeight: -426 23153 }; 23154 t["Courier-Bold"] = { 23155 ascent: 629, 23156 descent: -157, 23157 capHeight: 562, 23158 xHeight: 439 23159 }; 23160 t["Courier-Oblique"] = { 23161 ascent: 629, 23162 descent: -157, 23163 capHeight: 562, 23164 xHeight: 426 23165 }; 23166 t["Courier-BoldOblique"] = { 23167 ascent: 629, 23168 descent: -157, 23169 capHeight: 562, 23170 xHeight: 426 23171 }; 23172 t.Helvetica = { 23173 ascent: 718, 23174 descent: -207, 23175 capHeight: 718, 23176 xHeight: 523 23177 }; 23178 t["Helvetica-Bold"] = { 23179 ascent: 718, 23180 descent: -207, 23181 capHeight: 718, 23182 xHeight: 532 23183 }; 23184 t["Helvetica-Oblique"] = { 23185 ascent: 718, 23186 descent: -207, 23187 capHeight: 718, 23188 xHeight: 523 23189 }; 23190 t["Helvetica-BoldOblique"] = { 23191 ascent: 718, 23192 descent: -207, 23193 capHeight: 718, 23194 xHeight: 532 23195 }; 23196 t["Times-Roman"] = { 23197 ascent: 683, 23198 descent: -217, 23199 capHeight: 662, 23200 xHeight: 450 23201 }; 23202 t["Times-Bold"] = { 23203 ascent: 683, 23204 descent: -217, 23205 capHeight: 676, 23206 xHeight: 461 23207 }; 23208 t["Times-Italic"] = { 23209 ascent: 683, 23210 descent: -217, 23211 capHeight: 653, 23212 xHeight: 441 23213 }; 23214 t["Times-BoldItalic"] = { 23215 ascent: 683, 23216 descent: -217, 23217 capHeight: 669, 23218 xHeight: 462 23219 }; 23220 t.Symbol = { 23221 ascent: Math.NaN, 23222 descent: Math.NaN, 23223 capHeight: Math.NaN, 23224 xHeight: Math.NaN 23225 }; 23226 t.ZapfDingbats = { 23227 ascent: Math.NaN, 23228 descent: Math.NaN, 23229 capHeight: Math.NaN, 23230 xHeight: Math.NaN 23231 }; 23232}); 23233 23234;// ./src/core/
vendor: 15,369 bytes, lines 23234-23762
23234glyf.js 23235const ON_CURVE_POINT = 1 << 0; 23236const X_SHORT_VECTOR = 1 << 1; 23237const Y_SHORT_VECTOR = 1 << 2; 23238const REPEAT_FLAG = 1 << 3; 23239const X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR = 1 << 4; 23240const Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR = 1 << 5; 23241const OVERLAP_SIMPLE = 1 << 6; 23242const ARG_1_AND_2_ARE_WORDS = 1 << 0; 23243const ARGS_ARE_XY_VALUES = 1 << 1; 23244const WE_HAVE_A_SCALE = 1 << 3; 23245const MORE_COMPONENTS = 1 << 5; 23246const WE_HAVE_AN_X_AND_Y_SCALE = 1 << 6; 23247const WE_HAVE_A_TWO_BY_TWO = 1 << 7; 23248const WE_HAVE_INSTRUCTIONS = 1 << 8; 23249class GlyfTable { 23250 constructor({ 23251 glyfTable, 23252 isGlyphLocationsLong, 23253 locaTable, 23254 numGlyphs 23255 }) { 23256 this.glyphs = []; 23257 const loca = new DataView(locaTable.buffer, locaTable.byteOffset, locaTable.byteLength); 23258 const glyf = new DataView(glyfTable.buffer, glyfTable.byteOffset, glyfTable.byteLength); 23259 const offsetSize = isGlyphLocationsLong ? 4 : 2; 23260 let prev = isGlyphLocationsLong ? loca.getUint32(0) : 2 * loca.getUint16(0); 23261 let pos = 0; 23262 for (let i = 0; i < numGlyphs; i++) { 23263 pos += offsetSize; 23264 const next = isGlyphLocationsLong ? loca.getUint32(pos) : 2 * loca.getUint16(pos); 23265 if (next === prev) { 23266 this.glyphs.push(new Glyph({})); 23267 continue; 23268 } 23269 const glyph = Glyph.parse(prev, glyf); 23270 this.glyphs.push(glyph); 23271 prev = next; 23272 } 23273 } 23274 getSize() { 23275 return Math.sumPrecise(this.glyphs.map(g => g.getSize() + 3 & ~3)); 23276 } 23277 write() { 23278 const totalSize = this.getSize(); 23279 const glyfTable = new DataView(new ArrayBuffer(totalSize)); 23280 const isLocationLong = totalSize > 0x1fffe; 23281 const offsetSize = isLocationLong ? 4 : 2; 23282 const locaTable = new DataView(new ArrayBuffer((this.glyphs.length + 1) * offsetSize)); 23283 if (isLocationLong) { 23284 locaTable.setUint32(0, 0); 23285 } else { 23286 locaTable.setUint16(0, 0); 23287 } 23288 let pos = 0; 23289 let locaIndex = 0; 23290 for (const glyph of this.glyphs) { 23291 pos += glyph.write(pos, glyfTable); 23292 pos = pos + 3 & ~3; 23293 locaIndex += offsetSize; 23294 if (isLocationLong) { 23295 locaTable.setUint32(locaIndex, pos); 23296 } else { 23297 locaTable.setUint16(locaIndex, pos >> 1); 23298 } 23299 } 23300 return { 23301 isLocationLong, 23302 loca: new Uint8Array(locaTable.buffer), 23303 glyf: new Uint8Array(glyfTable.buffer) 23304 }; 23305 } 23306 scale(factors) { 23307 for (let i = 0, ii = this.glyphs.length; i < ii; i++) { 23308 this.glyphs[i].scale(factors[i]); 23309 } 23310 } 23311} 23312class Glyph { 23313 constructor({ 23314 header = null, 23315 simple = null, 23316 composites = null 23317 }) { 23318 this.header = header; 23319 this.simple = simple; 23320 this.composites = composites; 23321 } 23322 static parse(pos, glyf) { 23323 const [read, header] = GlyphHeader.parse(pos, glyf); 23324 pos += read; 23325 if (header.numberOfContours < 0) { 23326 const composites = []; 23327 while (true) { 23328 const [n, composite] = CompositeGlyph.parse(pos, glyf); 23329 pos += n; 23330 composites.push(composite); 23331 if (!(composite.flags & MORE_COMPONENTS)) { 23332 break; 23333 } 23334 } 23335 return new Glyph({ 23336 header, 23337 composites 23338 }); 23339 } 23340 const simple = SimpleGlyph.parse(pos, glyf, header.numberOfContours); 23341 return new Glyph({ 23342 header, 23343 simple 23344 }); 23345 } 23346 getSize() { 23347 if (!this.header) { 23348 return 0; 23349 } 23350 const size = this.simple ? this.simple.getSize() : Math.sumPrecise(this.composites.map(c => c.getSize())); 23351 return this.header.getSize() + size; 23352 } 23353 write(pos, buf) { 23354 if (!this.header) { 23355 return 0; 23356 } 23357 const spos = pos; 23358 pos += this.header.write(pos, buf); 23359 if (this.simple) { 23360 pos += this.simple.write(pos, buf); 23361 } else { 23362 for (const composite of this.composites) { 23363 pos += composite.write(pos, buf); 23364 } 23365 } 23366 return pos - spos; 23367 } 23368 scale(factor) { 23369 if (!this.header) { 23370 return; 23371 } 23372 const xMiddle = (this.header.xMin + this.header.xMax) / 2; 23373 this.header.scale(xMiddle, factor); 23374 if (this.simple) { 23375 this.simple.scale(xMiddle, factor); 23376 } else { 23377 for (const composite of this.composites) { 23378 composite.scale(xMiddle, factor); 23379 } 23380 } 23381 } 23382} 23383class GlyphHeader { 23384 constructor({ 23385 numberOfContours, 23386 xMin, 23387 yMin, 23388 xMax, 23389 yMax 23390 }) { 23391 this.numberOfContours = numberOfContours; 23392 this.xMin = xMin; 23393 this.yMin = yMin; 23394 this.xMax = xMax; 23395 this.yMax = yMax; 23396 } 23397 static parse(pos, glyf) { 23398 return [10, new GlyphHeader({ 23399 numberOfContours: glyf.getInt16(pos), 23400 xMin: glyf.getInt16(pos + 2), 23401 yMin: glyf.getInt16(pos + 4), 23402 xMax: glyf.getInt16(pos + 6), 23403 yMax: glyf.getInt16(pos + 8) 23404 })]; 23405 } 23406 getSize() { 23407 return 10; 23408 } 23409 write(pos, buf) { 23410 buf.setInt16(pos, this.numberOfContours); 23411 buf.setInt16(pos + 2, this.xMin); 23412 buf.setInt16(pos + 4, this.yMin); 23413 buf.setInt16(pos + 6, this.xMax); 23414 buf.setInt16(pos + 8, this.yMax); 23415 return 10; 23416 } 23417 scale(x, factor) { 23418 this.xMin = Math.round(x + (this.xMin - x) * factor); 23419 this.xMax = Math.round(x + (this.xMax - x) * factor); 23420 } 23421} 23422class Contour { 23423 constructor({ 23424 flags, 23425 xCoordinates, 23426 yCoordinates 23427 }) { 23428 this.xCoordinates = xCoordinates; 23429 this.yCoordinates = yCoordinates; 23430 this.flags = flags; 23431 } 23432} 23433class SimpleGlyph { 23434 constructor({ 23435 contours, 23436 instructions 23437 }) { 23438 this.contours = contours; 23439 this.instructions = instructions; 23440 } 23441 static parse(pos, glyf, numberOfContours) { 23442 const endPtsOfContours = []; 23443 for (let i = 0; i < numberOfContours; i++) { 23444 const endPt = glyf.getUint16(pos); 23445 pos += 2; 23446 endPtsOfContours.push(endPt); 23447 } 23448 const numberOfPt = endPtsOfContours[numberOfContours - 1] + 1; 23449 const instructionLength = glyf.getUint16(pos); 23450 pos += 2; 23451 const instructions = new Uint8Array(glyf).slice(pos, pos + instructionLength); 23452 pos += instructionLength; 23453 const flags = []; 23454 for (let i = 0; i < numberOfPt; pos++, i++) { 23455 let flag = glyf.getUint8(pos); 23456 flags.push(flag); 23457 if (flag & REPEAT_FLAG) { 23458 const count = glyf.getUint8(++pos); 23459 flag ^= REPEAT_FLAG; 23460 for (let m = 0; m < count; m++) { 23461 flags.push(flag); 23462 } 23463 i += count; 23464 } 23465 } 23466 const allXCoordinates = []; 23467 let xCoordinates = []; 23468 let yCoordinates = []; 23469 let pointFlags = []; 23470 const contours = []; 23471 let endPtsOfContoursIndex = 0; 23472 let lastCoordinate = 0; 23473 for (let i = 0; i < numberOfPt; i++) { 23474 const flag = flags[i]; 23475 if (flag & X_SHORT_VECTOR) { 23476 const x = glyf.getUint8(pos++); 23477 lastCoordinate += flag & X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR ? x : -x; 23478 xCoordinates.push(lastCoordinate); 23479 } else if (flag & X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR) { 23480 xCoordinates.push(lastCoordinate); 23481 } else { 23482 lastCoordinate += glyf.getInt16(pos); 23483 pos += 2; 23484 xCoordinates.push(lastCoordinate); 23485 } 23486 if (endPtsOfContours[endPtsOfContoursIndex] === i) { 23487 endPtsOfContoursIndex++; 23488 allXCoordinates.push(xCoordinates); 23489 xCoordinates = []; 23490 } 23491 } 23492 lastCoordinate = 0; 23493 endPtsOfContoursIndex = 0; 23494 for (let i = 0; i < numberOfPt; i++) { 23495 const flag = flags[i]; 23496 if (flag & Y_SHORT_VECTOR) { 23497 const y = glyf.getUint8(pos++); 23498 lastCoordinate += flag & Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR ? y : -y; 23499 yCoordinates.push(lastCoordinate); 23500 } else if (flag & Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR) { 23501 yCoordinates.push(lastCoordinate); 23502 } else { 23503 lastCoordinate += glyf.getInt16(pos); 23504 pos += 2; 23505 yCoordinates.push(lastCoordinate); 23506 } 23507 pointFlags.push(flag & ON_CURVE_POINT | flag & OVERLAP_SIMPLE); 23508 if (endPtsOfContours[endPtsOfContoursIndex] === i) { 23509 xCoordinates = allXCoordinates[endPtsOfContoursIndex]; 23510 endPtsOfContoursIndex++; 23511 contours.push(new Contour({ 23512 flags: pointFlags, 23513 xCoordinates, 23514 yCoordinates 23515 })); 23516 yCoordinates = []; 23517 pointFlags = []; 23518 } 23519 } 23520 return new SimpleGlyph({ 23521 contours, 23522 instructions 23523 }); 23524 } 23525 getSize() { 23526 let size = this.contours.length * 2 + 2 + this.instructions.length; 23527 let lastX = 0; 23528 let lastY = 0; 23529 for (const contour of this.contours) { 23530 size += contour.flags.length; 23531 for (let i = 0, ii = contour.xCoordinates.length; i < ii; i++) { 23532 const x = contour.xCoordinates[i]; 23533 const y = contour.yCoordinates[i]; 23534 let abs = Math.abs(x - lastX); 23535 if (abs > 255) { 23536 size += 2; 23537 } else if (abs > 0) { 23538 size += 1; 23539 } 23540 lastX = x; 23541 abs = Math.abs(y - lastY); 23542 if (abs > 255) { 23543 size += 2; 23544 } else if (abs > 0) { 23545 size += 1; 23546 } 23547 lastY = y; 23548 } 23549 } 23550 return size; 23551 } 23552 write(pos, buf) { 23553 const spos = pos; 23554 const xCoordinates = []; 23555 const yCoordinates = []; 23556 const flags = []; 23557 let lastX = 0; 23558 let lastY = 0; 23559 for (const contour of this.contours) { 23560 for (let i = 0, ii = contour.xCoordinates.length; i < ii; i++) { 23561 let flag = contour.flags[i]; 23562 const x = contour.xCoordinates[i]; 23563 let delta = x - lastX; 23564 if (delta === 0) { 23565 flag |= X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR; 23566 xCoordinates.push(0); 23567 } else { 23568 const abs = Math.abs(delta); 23569 if (abs <= 255) { 23570 flag |= delta >= 0 ? X_SHORT_VECTOR | X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR : X_SHORT_VECTOR; 23571 xCoordinates.push(abs); 23572 } else { 23573 xCoordinates.push(delta); 23574 } 23575 } 23576 lastX = x; 23577 const y = contour.yCoordinates[i]; 23578 delta = y - lastY; 23579 if (delta === 0) { 23580 flag |= Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR; 23581 yCoordinates.push(0); 23582 } else { 23583 const abs = Math.abs(delta); 23584 if (abs <= 255) { 23585 flag |= delta >= 0 ? Y_SHORT_VECTOR | Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR : Y_SHORT_VECTOR; 23586 yCoordinates.push(abs); 23587 } else { 23588 yCoordinates.push(delta); 23589 } 23590 } 23591 lastY = y; 23592 flags.push(flag); 23593 } 23594 buf.setUint16(pos, xCoordinates.length - 1); 23595 pos += 2; 23596 } 23597 buf.setUint16(pos, this.instructions.length); 23598 pos += 2; 23599 if (this.instructions.length) { 23600 new Uint8Array(buf.buffer, 0, buf.buffer.byteLength).set(this.instructions, pos); 23601 pos += this.instructions.length; 23602 } 23603 for (const flag of flags) { 23604 buf.setUint8(pos++, flag); 23605 } 23606 for (let i = 0, ii = xCoordinates.length; i < ii; i++) { 23607 const x = xCoordinates[i]; 23608 const flag = flags[i]; 23609 if (flag & X_SHORT_VECTOR) { 23610 buf.setUint8(pos++, x); 23611 } else if (!(flag & X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR)) { 23612 buf.setInt16(pos, x); 23613 pos += 2; 23614 } 23615 } 23616 for (let i = 0, ii = yCoordinates.length; i < ii; i++) { 23617 const y = yCoordinates[i]; 23618 const flag = flags[i]; 23619 if (flag & Y_SHORT_VECTOR) { 23620 buf.setUint8(pos++, y); 23621 } else if (!(flag & Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR)) { 23622 buf.setInt16(pos, y); 23623 pos += 2; 23624 } 23625 } 23626 return pos - spos; 23627 } 23628 scale(x, factor) { 23629 for (const contour of this.contours) { 23630 if (contour.xCoordinates.length === 0) { 23631 continue; 23632 } 23633 for (let i = 0, ii = contour.xCoordinates.length; i < ii; i++) { 23634 contour.xCoordinates[i] = Math.round(x + (contour.xCoordinates[i] - x) * factor); 23635 } 23636 } 23637 } 23638} 23639class CompositeGlyph { 23640 constructor({ 23641 flags, 23642 glyphIndex, 23643 argument1, 23644 argument2, 23645 transf, 23646 instructions 23647 }) { 23648 this.flags = flags; 23649 this.glyphIndex = glyphIndex; 23650 this.argument1 = argument1; 23651 this.argument2 = argument2; 23652 this.transf = transf; 23653 this.instructions = instructions; 23654 } 23655 static parse(pos, glyf) { 23656 const spos = pos; 23657 const transf = []; 23658 let flags = glyf.getUint16(pos); 23659 const glyphIndex = glyf.getUint16(pos + 2); 23660 pos += 4; 23661 let argument1, argument2; 23662 if (flags & ARG_1_AND_2_ARE_WORDS) { 23663 if (flags & ARGS_ARE_XY_VALUES) { 23664 argument1 = glyf.getInt16(pos); 23665 argument2 = glyf.getInt16(pos + 2); 23666 } else { 23667 argument1 = glyf.getUint16(pos); 23668 argument2 = glyf.getUint16(pos + 2); 23669 } 23670 pos += 4; 23671 flags ^= ARG_1_AND_2_ARE_WORDS; 23672 } else { 23673 if (flags & ARGS_ARE_XY_VALUES) { 23674 argument1 = glyf.getInt8(pos); 23675 argument2 = glyf.getInt8(pos + 1); 23676 } else { 23677 argument1 = glyf.getUint8(pos); 23678 argument2 = glyf.getUint8(pos + 1); 23679 } 23680 pos += 2; 23681 } 23682 if (flags & WE_HAVE_A_SCALE) { 23683 transf.push(glyf.getUint16(pos)); 23684 pos += 2; 23685 } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) { 23686 transf.push(glyf.getUint16(pos), glyf.getUint16(pos + 2)); 23687 pos += 4; 23688 } else if (flags & WE_HAVE_A_TWO_BY_TWO) { 23689 transf.push(glyf.getUint16(pos), glyf.getUint16(pos + 2), glyf.getUint16(pos + 4), glyf.getUint16(pos + 6)); 23690 pos += 8; 23691 } 23692 let instructions = null; 23693 if (flags & WE_HAVE_INSTRUCTIONS) { 23694 const instructionLength = glyf.getUint16(pos); 23695 pos += 2; 23696 instructions = new Uint8Array(glyf).slice(pos, pos + instructionLength); 23697 pos += instructionLength; 23698 } 23699 return [pos - spos, new CompositeGlyph({ 23700 flags, 23701 glyphIndex, 23702 argument1, 23703 argument2, 23704 transf, 23705 instructions 23706 })]; 23707 } 23708 getSize() { 23709 let size = 2 + 2 + this.transf.length * 2; 23710 if (this.flags & WE_HAVE_INSTRUCTIONS) { 23711 size += 2 + this.instructions.length; 23712 } 23713 size += 2; 23714 if (this.flags & 2) { 23715 if (!(this.argument1 >= -128 && this.argument1 <= 127 && this.argument2 >= -128 && this.argument2 <= 127)) { 23716 size += 2; 23717 } 23718 } else if (!(this.argument1 >= 0 && this.argument1 <= 255 && this.argument2 >= 0 && this.argument2 <= 255)) { 23719 size += 2; 23720 } 23721 return size; 23722 } 23723 write(pos, buf) { 23724 const spos = pos; 23725 if (this.flags & ARGS_ARE_XY_VALUES) { 23726 if (!(this.argument1 >= -128 && this.argument1 <= 127 && this.argument2 >= -128 && this.argument2 <= 127)) { 23727 this.flags |= ARG_1_AND_2_ARE_WORDS; 23728 } 23729 } else if (!(this.argument1 >= 0 && this.argument1 <= 255 && this.argument2 >= 0 && this.argument2 <= 255)) { 23730 this.flags |= ARG_1_AND_2_ARE_WORDS; 23731 } 23732 buf.setUint16(pos, this.flags); 23733 buf.setUint16(pos + 2, this.glyphIndex); 23734 pos += 4; 23735 if (this.flags & ARG_1_AND_2_ARE_WORDS) { 23736 if (this.flags & ARGS_ARE_XY_VALUES) { 23737 buf.setInt16(pos, this.argument1); 23738 buf.setInt16(pos + 2, this.argument2); 23739 } else { 23740 buf.setUint16(pos, this.argument1); 23741 buf.setUint16(pos + 2, this.argument2); 23742 } 23743 pos += 4; 23744 } else { 23745 buf.setUint8(pos, this.argument1); 23746 buf.setUint8(pos + 1, this.argument2); 23747 pos += 2; 23748 } 23749 if (this.flags & WE_HAVE_INSTRUCTIONS) { 23750 buf.setUint16(pos, this.instructions.length); 23751 pos += 2; 23752 if (this.instructions.length) { 23753 new Uint8Array(buf.buffer, 0, buf.buffer.byteLength).set(this.instructions, pos); 23754 pos += this.instructions.length; 23755 } 23756 } 23757 return pos - spos; 23758 } 23759 scale(x, factor) {} 23760} 23761 23762;// ./src/core/opentype_file_builder.js
vendor: 3,297 bytes, lines 23762-23872
23762 23763 23764 23765function writeInt16(dest, offset, num) { 23766 dest[offset] = num >> 8 & 0xff; 23767 dest[offset + 1] = num & 0xff; 23768} 23769function writeInt32(dest, offset, num) { 23770 dest[offset] = num >> 24 & 0xff; 23771 dest[offset + 1] = num >> 16 & 0xff; 23772 dest[offset + 2] = num >> 8 & 0xff; 23773 dest[offset + 3] = num & 0xff; 23774} 23775function writeData(dest, offset, data) { 23776 if (data instanceof Uint8Array) { 23777 dest.set(data, offset); 23778 } else if (typeof data === "string") { 23779 for (let i = 0, ii = data.length; i < ii; i++) { 23780 dest[offset++] = data.charCodeAt(i) & 0xff; 23781 } 23782 } else { 23783 for (const num of data) { 23784 dest[offset++] = num & 0xff; 23785 } 23786 } 23787} 23788const OTF_HEADER_SIZE = 12; 23789const OTF_TABLE_ENTRY_SIZE = 16; 23790class OpenTypeFileBuilder { 23791 constructor(sfnt) { 23792 this.sfnt = sfnt; 23793 this.tables = Object.create(null); 23794 } 23795 static getSearchParams(entriesCount, entrySize) { 23796 let maxPower2 = 1, 23797 log2 = 0; 23798 while ((maxPower2 ^ entriesCount) > maxPower2) { 23799 maxPower2 <<= 1; 23800 log2++; 23801 } 23802 const searchRange = maxPower2 * entrySize; 23803 return { 23804 range: searchRange, 23805 entry: log2, 23806 rangeShift: entrySize * entriesCount - searchRange 23807 }; 23808 } 23809 toArray() { 23810 let sfnt = this.sfnt; 23811 const tables = this.tables; 23812 const tablesNames = Object.keys(tables); 23813 tablesNames.sort(); 23814 const numTables = tablesNames.length; 23815 let i, j, jj, table, tableName; 23816 let offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE; 23817 const tableOffsets = [offset]; 23818 for (i = 0; i < numTables; i++) { 23819 table = tables[tablesNames[i]]; 23820 const paddedLength = (table.length + 3 & ~3) >>> 0; 23821 offset += paddedLength; 23822 tableOffsets.push(offset); 23823 } 23824 const file = new Uint8Array(offset); 23825 for (i = 0; i < numTables; i++) { 23826 table = tables[tablesNames[i]]; 23827 writeData(file, tableOffsets[i], table); 23828 } 23829 if (sfnt === "true") { 23830 sfnt = string32(0x00010000); 23831 } 23832 file[0] = sfnt.charCodeAt(0) & 0xff; 23833 file[1] = sfnt.charCodeAt(1) & 0xff; 23834 file[2] = sfnt.charCodeAt(2) & 0xff; 23835 file[3] = sfnt.charCodeAt(3) & 0xff; 23836 writeInt16(file, 4, numTables); 23837 const searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16); 23838 writeInt16(file, 6, searchParams.range); 23839 writeInt16(file, 8, searchParams.entry); 23840 writeInt16(file, 10, searchParams.rangeShift); 23841 offset = OTF_HEADER_SIZE; 23842 for (i = 0; i < numTables; i++) { 23843 tableName = tablesNames[i]; 23844 file[offset] = tableName.charCodeAt(0) & 0xff; 23845 file[offset + 1] = tableName.charCodeAt(1) & 0xff; 23846 file[offset + 2] = tableName.charCodeAt(2) & 0xff; 23847 file[offset + 3] = tableName.charCodeAt(3) & 0xff; 23848 let checksum = 0; 23849 for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) { 23850 const quad = readUint32(file, j); 23851 checksum = checksum + quad >>> 0; 23852 } 23853 writeInt32(file, offset + 4, checksum); 23854 writeInt32(file, offset + 8, tableOffsets[i]); 23855 writeInt32(file, offset + 12, tables[tableName].length); 23856 offset += OTF_TABLE_ENTRY_SIZE; 23857 } 23858 return file; 23859 } 23860 addTable(tag, data) { 23861 if (tag in this.tables) { 23862 throw new Error("Table " + tag + " already exists"); 23863 } 23864 this.tables[tag] = data; 23865 } 23866} 23867 23868;// ./src/core/type1_parser.js 23869 23870 23871 23872
vendor: 3,855 bytes, lines 23873-24010
23873const HINTING_ENABLED = false; 23874const COMMAND_MAP = { 23875 hstem: [1], 23876 vstem: [3], 23877 vmoveto: [4], 23878 rlineto: [5], 23879 hlineto: [6], 23880 vlineto: [7], 23881 rrcurveto: [8], 23882 callsubr: [10], 23883 flex: [12, 35], 23884 drop: [12, 18], 23885 endchar: [14], 23886 rmoveto: [21], 23887 hmoveto: [22], 23888 vhcurveto: [30], 23889 hvcurveto: [31] 23890}; 23891class Type1CharString { 23892 constructor() { 23893 this.width = 0; 23894 this.lsb = 0; 23895 this.flexing = false; 23896 this.output = []; 23897 this.stack = []; 23898 } 23899 convert(encoded, subrs, seacAnalysisEnabled) { 23900 const count = encoded.length; 23901 let error = false; 23902 let wx, sbx, subrNumber; 23903 for (let i = 0; i < count; i++) { 23904 let value = encoded[i]; 23905 if (value < 32) { 23906 if (value === 12) { 23907 value = (value << 8) + encoded[++i]; 23908 } 23909 switch (value) { 23910 case 1: 23911 if (!HINTING_ENABLED) { 23912 this.stack = []; 23913 break; 23914 } 23915 error = this.executeCommand(2, COMMAND_MAP.hstem); 23916 break; 23917 case 3: 23918 if (!HINTING_ENABLED) { 23919 this.stack = []; 23920 break; 23921 } 23922 error = this.executeCommand(2, COMMAND_MAP.vstem); 23923 break; 23924 case 4: 23925 if (this.flexing) { 23926 if (this.stack.length < 1) { 23927 error = true; 23928 break; 23929 } 23930 const dy = this.stack.pop(); 23931 this.stack.push(0, dy); 23932 break; 23933 } 23934 error = this.executeCommand(1, COMMAND_MAP.vmoveto); 23935 break; 23936 case 5: 23937 error = this.executeCommand(2, COMMAND_MAP.rlineto); 23938 break; 23939 case 6: 23940 error = this.executeCommand(1, COMMAND_MAP.hlineto); 23941 break; 23942 case 7: 23943 error = this.executeCommand(1, COMMAND_MAP.vlineto); 23944 break; 23945 case 8: 23946 error = this.executeCommand(6, COMMAND_MAP.rrcurveto); 23947 break; 23948 case 9: 23949 this.stack = []; 23950 break; 23951 case 10: 23952 if (this.stack.length < 1) { 23953 error = true; 23954 break; 23955 } 23956 subrNumber = this.stack.pop(); 23957 if (!subrs[subrNumber]) { 23958 error = true; 23959 break; 23960 } 23961 error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled); 23962 break; 23963 case 11: 23964 return error; 23965 case 13: 23966 if (this.stack.length < 2) { 23967 error = true; 23968 break; 23969 } 23970 wx = this.stack.pop(); 23971 sbx = this.stack.pop(); 23972 this.lsb = sbx; 23973 this.width = wx; 23974 this.stack.push(wx, sbx); 23975 error = this.executeCommand(2, COMMAND_MAP.hmoveto); 23976 break; 23977 case 14: 23978 this.output.push(COMMAND_MAP.endchar[0]); 23979 break; 23980 case 21: 23981 if (this.flexing) { 23982 break; 23983 } 23984 error = this.executeCommand(2, COMMAND_MAP.rmoveto); 23985 break; 23986 case 22: 23987 if (this.flexing) { 23988 this.stack.push(0); 23989 break; 23990 } 23991 error = this.executeCommand(1, COMMAND_MAP.hmoveto); 23992 break; 23993 case 30: 23994 error = this.executeCommand(4, COMMAND_MAP.vhcurveto); 23995 break; 23996 case 31: 23997 error = this.executeCommand(4, COMMAND_MAP.hvcurveto); 23998 break; 23999 case (12 << 8) + 0: 24000 this.stack = []; 24001 break; 24002 case (12 << 8) + 1: 24003 if (!HINTING_ENABLED) { 24004 this.stack = []; 24005 break; 24006 } 24007 error = this.executeCommand(2, COMMAND_MAP.vstem); 24008 break; 24009 case (12 << 8) + 2: 24010 if (!HINTING_ENABLED
vendor: 7,485 bytes, lines 24010-24252
24010) { 24011 this.stack = []; 24012 break; 24013 } 24014 error = this.executeCommand(2, COMMAND_MAP.hstem); 24015 break; 24016 case (12 << 8) + 6: 24017 if (seacAnalysisEnabled) { 24018 const asb = this.stack.at(-5); 24019 this.seac = this.stack.splice(-4, 4); 24020 this.seac[0] += this.lsb - asb; 24021 error = this.executeCommand(0, COMMAND_MAP.endchar); 24022 } else { 24023 error = this.executeCommand(4, COMMAND_MAP.endchar); 24024 } 24025 break; 24026 case (12 << 8) + 7: 24027 if (this.stack.length < 4) { 24028 error = true; 24029 break; 24030 } 24031 this.stack.pop(); 24032 wx = this.stack.pop(); 24033 const sby = this.stack.pop(); 24034 sbx = this.stack.pop(); 24035 this.lsb = sbx; 24036 this.width = wx; 24037 this.stack.push(wx, sbx, sby); 24038 error = this.executeCommand(3, COMMAND_MAP.rmoveto); 24039 break; 24040 case (12 << 8) + 12: 24041 if (this.stack.length < 2) { 24042 error = true; 24043 break; 24044 } 24045 const num2 = this.stack.pop(); 24046 const num1 = this.stack.pop(); 24047 this.stack.push(num1 / num2); 24048 break; 24049 case (12 << 8) + 16: 24050 if (this.stack.length < 2) { 24051 error = true; 24052 break; 24053 } 24054 subrNumber = this.stack.pop(); 24055 const numArgs = this.stack.pop(); 24056 if (subrNumber === 0 && numArgs === 3) { 24057 const flexArgs = this.stack.splice(-17, 17); 24058 this.stack.push(flexArgs[2] + flexArgs[0], flexArgs[3] + flexArgs[1], flexArgs[4], flexArgs[5], flexArgs[6], flexArgs[7], flexArgs[8], flexArgs[9], flexArgs[10], flexArgs[11], flexArgs[12], flexArgs[13], flexArgs[14]); 24059 error = this.executeCommand(13, COMMAND_MAP.flex, true); 24060 this.flexing = false; 24061 this.stack.push(flexArgs[15], flexArgs[16]); 24062 } else if (subrNumber === 1 && numArgs === 0) { 24063 this.flexing = true; 24064 } 24065 break; 24066 case (12 << 8) + 17: 24067 break; 24068 case (12 << 8) + 33: 24069 this.stack = []; 24070 break; 24071 default: 24072 warn('Unknown type 1 charstring command of "' + value + '"'); 24073 break; 24074 } 24075 if (error) { 24076 break; 24077 } 24078 continue; 24079 } else if (value <= 246) { 24080 value -= 139; 24081 } else if (value <= 250) { 24082 value = (value - 247) * 256 + encoded[++i] + 108; 24083 } else if (value <= 254) { 24084 value = -((value - 251) * 256) - encoded[++i] - 108; 24085 } else { 24086 value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0; 24087 } 24088 this.stack.push(value); 24089 } 24090 return error; 24091 } 24092 executeCommand(howManyArgs, command, keepStack) { 24093 const stackLength = this.stack.length; 24094 if (howManyArgs > stackLength) { 24095 return true; 24096 } 24097 const start = stackLength - howManyArgs; 24098 for (let i = start; i < stackLength; i++) { 24099 let value = this.stack[i]; 24100 if (Number.isInteger(value)) { 24101 this.output.push(28, value >> 8 & 0xff, value & 0xff); 24102 } else { 24103 value = 65536 * value | 0; 24104 this.output.push(255, value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff); 24105 } 24106 } 24107 this.output.push(...command); 24108 if (keepStack) { 24109 this.stack.splice(start, howManyArgs); 24110 } else { 24111 this.stack.length = 0; 24112 } 24113 return false; 24114 } 24115} 24116const EEXEC_ENCRYPT_KEY = 55665; 24117const CHAR_STRS_ENCRYPT_KEY = 4330; 24118function isHexDigit(code) { 24119 return code >= 48 && code <= 57 || code >= 65 && code <= 70 || code >= 97 && code <= 102; 24120} 24121function decrypt(data, key, discardNumber) { 24122 if (discardNumber >= data.length) { 24123 return new Uint8Array(0); 24124 } 24125 const c1 = 52845, 24126 c2 = 22719; 24127 let r = key | 0, 24128 i, 24129 j; 24130 for (i = 0; i < discardNumber; i++) { 24131 r = (data[i] + r) * c1 + c2 & (1 << 16) - 1; 24132 } 24133 const count = data.length - discardNumber; 24134 const decrypted = new Uint8Array(count); 24135 for (i = discardNumber, j = 0; j < count; i++, j++) { 24136 const value = data[i]; 24137 decrypted[j] = value ^ r >> 8; 24138 r = (value + r) * c1 + c2 & (1 << 16) - 1; 24139 } 24140 return decrypted; 24141} 24142function decryptAscii(data, key, discardNumber) { 24143 const c1 = 52845, 24144 c2 = 22719; 24145 let r = key | 0; 24146 const count = data.length, 24147 maybeLength = count >>> 1; 24148 const decrypted = new Uint8Array(maybeLength); 24149 let i, j; 24150 for (i = 0, j = 0; i < count; i++) { 24151 const digit1 = data[i]; 24152 if (!isHexDigit(digit1)) { 24153 continue; 24154 } 24155 i++; 24156 let digit2; 24157 while (i < count && !isHexDigit(digit2 = data[i])) { 24158 i++; 24159 } 24160 if (i < count) { 24161 const value = parseInt(String.fromCharCode(digit1, digit2), 16); 24162 decrypted[j++] = value ^ r >> 8; 24163 r = (value + r) * c1 + c2 & (1 << 16) - 1; 24164 } 24165 } 24166 return decrypted.slice(discardNumber, j); 24167} 24168function isSpecial(c) { 24169 return c === 0x2f || c === 0x5b || c === 0x5d || c === 0x7b || c === 0x7d || c === 0x28 || c === 0x29; 24170} 24171class Type1Parser { 24172 constructor(stream, encrypted, seacAnalysisEnabled) { 24173 if (encrypted) { 24174 const data = stream.getBytes(); 24175 const isBinary = !((isHexDigit(data[0]) || isWhiteSpace(data[0])) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]) && isHexDigit(data[4]) && isHexDigit(data[5]) && isHexDigit(data[6]) && isHexDigit(data[7])); 24176 stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4)); 24177 } 24178 this.seacAnalysisEnabled = !!seacAnalysisEnabled; 24179 this.stream = stream; 24180 this.nextChar(); 24181 } 24182 readNumberArray() { 24183 this.getToken(); 24184 const array = []; 24185 while (true) { 24186 const token = this.getToken(); 24187 if (token === null || token === "]" || token === "}") { 24188 break; 24189 } 24190 array.push(parseFloat(token || 0)); 24191 } 24192 return array; 24193 } 24194 readNumber() { 24195 const token = this.getToken(); 24196 return parseFloat(token || 0); 24197 } 24198 readInt() { 24199 const token = this.getToken(); 24200 return parseInt(token || 0, 10) | 0; 24201 } 24202 readBoolean() { 24203 const token = this.getToken(); 24204 return token === "true" ? 1 : 0; 24205 } 24206 nextChar() { 24207 return this.currentChar = this.stream.getByte(); 24208 } 24209 prevChar() { 24210 this.stream.skip(-2); 24211 return this.currentChar = this.stream.getByte(); 24212 } 24213 getToken() { 24214 let comment = false; 24215 let ch = this.currentChar; 24216 while (true) { 24217 if (ch === -1) { 24218 return null; 24219 } 24220 if (comment) { 24221 if (ch === 0x0a || ch === 0x0d) { 24222 comment = false; 24223 } 24224 } else if (ch === 0x25) { 24225 comment = true; 24226 } else if (!isWhiteSpace(ch)) { 24227 break; 24228 } 24229 ch = this.nextChar(); 24230 } 24231 if (isSpecial(ch)) { 24232 this.nextChar(); 24233 return String.fromCharCode(ch); 24234 } 24235 let token = ""; 24236 do { 24237 token += String.fromCharCode(ch); 24238 ch = this.nextChar(); 24239 } while (ch >= 0 && !isWhiteSpace(ch) && !isSpecial(ch)); 24240 return token; 24241 } 24242 readCharStrings(bytes, lenIV) { 24243 if (lenIV === -1) { 24244 return bytes; 24245 } 24246 return decrypt(bytes, CHAR_STRS_ENCRYPT_KEY, lenIV); 24247 } 24248 extractFontProgram(properties) { 24249 const stream = this.stream; 24250 const subrs = [], 24251 charstrings = []; 24252 const privateData =
vendor: 5,695 bytes, lines 24252-24433
24252Object.create(null); 24253 privateData.lenIV = 4; 24254 const program = { 24255 subrs: [], 24256 charstrings: [], 24257 properties: { 24258 privateData 24259 } 24260 }; 24261 let token, length, data, lenIV; 24262 while ((token = this.getToken()) !== null) { 24263 if (token !== "/") { 24264 continue; 24265 } 24266 token = this.getToken(); 24267 switch (token) { 24268 case "CharStrings": 24269 this.getToken(); 24270 this.getToken(); 24271 this.getToken(); 24272 this.getToken(); 24273 while (true) { 24274 token = this.getToken(); 24275 if (token === null || token === "end") { 24276 break; 24277 } 24278 if (token !== "/") { 24279 continue; 24280 } 24281 const glyph = this.getToken(); 24282 length = this.readInt(); 24283 this.getToken(); 24284 data = length > 0 ? stream.getBytes(length) : new Uint8Array(0); 24285 lenIV = program.properties.privateData.lenIV; 24286 const encoded = this.readCharStrings(data, lenIV); 24287 this.nextChar(); 24288 token = this.getToken(); 24289 if (token === "noaccess") { 24290 this.getToken(); 24291 } else if (token === "/") { 24292 this.prevChar(); 24293 } 24294 charstrings.push({ 24295 glyph, 24296 encoded 24297 }); 24298 } 24299 break; 24300 case "Subrs": 24301 this.readInt(); 24302 this.getToken(); 24303 while (this.getToken() === "dup") { 24304 const index = this.readInt(); 24305 length = this.readInt(); 24306 this.getToken(); 24307 data = length > 0 ? stream.getBytes(length) : new Uint8Array(0); 24308 lenIV = program.properties.privateData.lenIV; 24309 const encoded = this.readCharStrings(data, lenIV); 24310 this.nextChar(); 24311 token = this.getToken(); 24312 if (token === "noaccess") { 24313 this.getToken(); 24314 } 24315 subrs[index] = encoded; 24316 } 24317 break; 24318 case "BlueValues": 24319 case "OtherBlues": 24320 case "FamilyBlues": 24321 case "FamilyOtherBlues": 24322 const blueArray = this.readNumberArray(); 24323 if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) { 24324 program.properties.privateData[token] = blueArray; 24325 } 24326 break; 24327 case "StemSnapH": 24328 case "StemSnapV": 24329 program.properties.privateData[token] = this.readNumberArray(); 24330 break; 24331 case "StdHW": 24332 case "StdVW": 24333 program.properties.privateData[token] = this.readNumberArray()[0]; 24334 break; 24335 case "BlueShift": 24336 case "lenIV": 24337 case "BlueFuzz": 24338 case "BlueScale": 24339 case "LanguageGroup": 24340 program.properties.privateData[token] = this.readNumber(); 24341 break; 24342 case "ExpansionFactor": 24343 program.properties.privateData[token] = this.readNumber() || 0.06; 24344 break; 24345 case "ForceBold": 24346 program.properties.privateData[token] = this.readBoolean(); 24347 break; 24348 } 24349 } 24350 for (const { 24351 encoded, 24352 glyph 24353 } of charstrings) { 24354 const charString = new Type1CharString(); 24355 const error = charString.convert(encoded, subrs, this.seacAnalysisEnabled); 24356 let output = charString.output; 24357 if (error) { 24358 output = [14]; 24359 } 24360 const charStringObject = { 24361 glyphName: glyph, 24362 charstring: output, 24363 width: charString.width, 24364 lsb: charString.lsb, 24365 seac: charString.seac 24366 }; 24367 if (glyph === ".notdef") { 24368 program.charstrings.unshift(charStringObject); 24369 } else { 24370 program.charstrings.push(charStringObject); 24371 } 24372 if (properties.builtInEncoding) { 24373 const index = properties.builtInEncoding.indexOf(glyph); 24374 if (index > -1 && properties.widths[index] === undefined && index >= properties.firstChar && index <= properties.lastChar) { 24375 properties.widths[index] = charString.width; 24376 } 24377 } 24378 } 24379 return program; 24380 } 24381 extractFontHeader(properties) { 24382 let token; 24383 while ((token = this.getToken()) !== null) { 24384 if (token !== "/") { 24385 continue; 24386 } 24387 token = this.getToken(); 24388 switch (token) { 24389 case "FontMatrix": 24390 const matrix = this.readNumberArray(); 24391 properties.fontMatrix = matrix; 24392 break; 24393 case "Encoding": 24394 const encodingArg = this.getToken(); 24395 let encoding; 24396 if (!/^\d+$/.test(encodingArg)) { 24397 encoding = getEncoding(encodingArg); 24398 } else { 24399 encoding = []; 24400 const size = parseInt(encodingArg, 10) | 0; 24401 this.getToken(); 24402 for (let j = 0; j < size; j++) { 24403 token = this.getToken(); 24404 while (token !== "dup" && token !== "def") { 24405 token = this.getToken(); 24406 if (token === null) { 24407 return; 24408 } 24409 } 24410 if (token === "def") { 24411 break; 24412 } 24413 const index = this.readInt(); 24414 this.getToken(); 24415 const glyph = this.getToken(); 24416 encoding[index] = glyph; 24417 this.getToken(); 24418 } 24419 } 24420 properties.builtInEncoding = encoding; 24421 break; 24422 case "FontBBox": 24423 const fontBBox = this.readNumberArray(); 24424 properties.ascent = Math.max(fontBBox[3], fontBBox[1]); 24425 properties.descent = Math.min(fontBBox[1], fontBBox[3]); 24426 properties.ascentScaled = true; 24427 break; 24428 } 24429 } 24430 } 24431} 24432 24433;// ./src/core/type1_font.js
vendor: 42,746 bytes, lines 24433-25703
24433 24434 24435 24436 24437 24438 24439 24440function findBlock(streamBytes, signature, startIndex) { 24441 const streamBytesLength = streamBytes.length; 24442 const signatureLength = signature.length; 24443 const scanLength = streamBytesLength - signatureLength; 24444 let i = startIndex, 24445 found = false; 24446 while (i < scanLength) { 24447 let j = 0; 24448 while (j < signatureLength && streamBytes[i + j] === signature[j]) { 24449 j++; 24450 } 24451 if (j >= signatureLength) { 24452 i += j; 24453 while (i < streamBytesLength && isWhiteSpace(streamBytes[i])) { 24454 i++; 24455 } 24456 found = true; 24457 break; 24458 } 24459 i++; 24460 } 24461 return { 24462 found, 24463 length: i 24464 }; 24465} 24466function getHeaderBlock(stream, suggestedLength) { 24467 const EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63]; 24468 const streamStartPos = stream.pos; 24469 let headerBytes, headerBytesLength, block; 24470 try { 24471 headerBytes = stream.getBytes(suggestedLength); 24472 headerBytesLength = headerBytes.length; 24473 } catch {} 24474 if (headerBytesLength === suggestedLength) { 24475 block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length); 24476 if (block.found && block.length === suggestedLength) { 24477 return { 24478 stream: new Stream(headerBytes), 24479 length: suggestedLength 24480 }; 24481 } 24482 } 24483 warn('Invalid "Length1" property in Type1 font -- trying to recover.'); 24484 stream.pos = streamStartPos; 24485 const SCAN_BLOCK_LENGTH = 2048; 24486 let actualLength; 24487 while (true) { 24488 const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH); 24489 block = findBlock(scanBytes, EEXEC_SIGNATURE, 0); 24490 if (block.length === 0) { 24491 break; 24492 } 24493 stream.pos += block.length; 24494 if (block.found) { 24495 actualLength = stream.pos - streamStartPos; 24496 break; 24497 } 24498 } 24499 stream.pos = streamStartPos; 24500 if (actualLength) { 24501 return { 24502 stream: new Stream(stream.getBytes(actualLength)), 24503 length: actualLength 24504 }; 24505 } 24506 warn('Unable to recover "Length1" property in Type1 font -- using as is.'); 24507 return { 24508 stream: new Stream(stream.getBytes(suggestedLength)), 24509 length: suggestedLength 24510 }; 24511} 24512function getEexecBlock(stream, suggestedLength) { 24513 const eexecBytes = stream.getBytes(); 24514 if (eexecBytes.length === 0) { 24515 throw new FormatError("getEexecBlock - no font program found."); 24516 } 24517 return { 24518 stream: new Stream(eexecBytes), 24519 length: eexecBytes.length 24520 }; 24521} 24522class Type1Font { 24523 constructor(name, file, properties) { 24524 const PFB_HEADER_SIZE = 6; 24525 let headerBlockLength = properties.length1; 24526 let eexecBlockLength = properties.length2; 24527 let pfbHeader = file.peekBytes(PFB_HEADER_SIZE); 24528 const pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01; 24529 if (pfbHeaderPresent) { 24530 file.skip(PFB_HEADER_SIZE); 24531 headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2]; 24532 } 24533 const headerBlock = getHeaderBlock(file, headerBlockLength); 24534 const headerBlockParser = new Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED); 24535 headerBlockParser.extractFontHeader(properties); 24536 if (pfbHeaderPresent) { 24537 pfbHeader = file.getBytes(PFB_HEADER_SIZE); 24538 eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2]; 24539 } 24540 const eexecBlock = getEexecBlock(file, eexecBlockLength); 24541 const eexecBlockParser = new Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED); 24542 const data = eexecBlockParser.extractFontProgram(properties); 24543 for (const key in data.properties) { 24544 properties[key] = data.properties[key]; 24545 } 24546 const charstrings = data.charstrings; 24547 const type2Charstrings = this.getType2Charstrings(charstrings); 24548 const subrs = this.getType2Subrs(data.subrs); 24549 this.charstrings = charstrings; 24550 this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties); 24551 this.seacs = this.getSeacs(data.charstrings); 24552 } 24553 get numGlyphs() { 24554 return this.charstrings.length + 1; 24555 } 24556 getCharset() { 24557 const charset = [".notdef"]; 24558 for (const { 24559 glyphName 24560 } of this.charstrings) { 24561 charset.push(glyphName); 24562 } 24563 return charset; 24564 } 24565 getGlyphMapping(properties) { 24566 const charstrings = this.charstrings; 24567 if (properties.composite) { 24568 const charCodeToGlyphId = Object.create(null); 24569 for (let glyphId = 0, charstringsLen = charstrings.length; glyphId < charstringsLen; glyphId++) { 24570 const charCode = properties.cMap.charCodeOf(glyphId); 24571 charCodeToGlyphId[charCode] = glyphId + 1; 24572 } 24573 return charCodeToGlyphId; 24574 } 24575 const glyphNames = [".notdef"]; 24576 let builtInEncoding, glyphId; 24577 for (glyphId = 0; glyphId < charstrings.length; glyphId++) { 24578 glyphNames.push(charstrings[glyphId].glyphName); 24579 } 24580 const encoding = properties.builtInEncoding; 24581 if (encoding) { 24582 builtInEncoding = Object.create(null); 24583 for (const charCode in encoding) { 24584 glyphId = glyphNames.indexOf(encoding[charCode]); 24585 if (glyphId >= 0) { 24586 builtInEncoding[charCode] = glyphId; 24587 } 24588 } 24589 } 24590 return type1FontGlyphMapping(properties, builtInEncoding, glyphNames); 24591 } 24592 hasGlyphId(id) { 24593 if (id < 0 || id >= this.numGlyphs) { 24594 return false; 24595 } 24596 if (id === 0) { 24597 return true; 24598 } 24599 const glyph = this.charstrings[id - 1]; 24600 return glyph.charstring.length > 0; 24601 } 24602 getSeacs(charstrings) { 24603 const seacMap = []; 24604 for (let i = 0, ii = charstrings.length; i < ii; i++) { 24605 const charstring = charstrings[i]; 24606 if (charstring.seac) { 24607 seacMap[i + 1] = charstring.seac; 24608 } 24609 } 24610 return seacMap; 24611 } 24612 getType2Charstrings(type1Charstrings) { 24613 const type2Charstrings = []; 24614 for (const type1Charstring of type1Charstrings) { 24615 type2Charstrings.push(type1Charstring.charstring); 24616 } 24617 return type2Charstrings; 24618 } 24619 getType2Subrs(type1Subrs) { 24620 let bias = 0; 24621 const count = type1Subrs.length; 24622 if (count < 1133) { 24623 bias = 107; 24624 } else if (count < 33769) { 24625 bias = 1131; 24626 } else { 24627 bias = 32768; 24628 } 24629 const type2Subrs = []; 24630 let i; 24631 for (i = 0; i < bias; i++) { 24632 type2Subrs.push([0x0b]); 24633 } 24634 for (i = 0; i < count; i++) { 24635 type2Subrs.push(type1Subrs[i]); 24636 } 24637 return type2Subrs; 24638 } 24639 wrap(name, glyphs, charstrings, subrs, properties) { 24640 const cff = new CFF(); 24641 cff.header = new CFFHeader(1, 0, 4, 4); 24642 cff.names = [name]; 24643 const topDict = new CFFTopDict(); 24644 topDict.setByName("version", 391); 24645 topDict.setByName("Notice", 392); 24646 topDict.setByName("FullName", 393); 24647 topDict.setByName("FamilyName", 394); 24648 topDict.setByName("Weight", 395); 24649 topDict.setByName("Encoding", null); 24650 topDict.setByName("FontMatrix", properties.fontMatrix); 24651 topDict.setByName("FontBBox", properties.bbox); 24652 topDict.setByName("charset", null); 24653 topDict.setByName("CharStrings", null); 24654 topDict.setByName("Private", null); 24655 cff.topDict = topDict; 24656 const strings = new CFFStrings(); 24657 strings.add("Version 0.11"); 24658 strings.add("See original notice"); 24659 strings.add(name); 24660 strings.add(name); 24661 strings.add("Medium"); 24662 cff.strings = strings; 24663 cff.globalSubrIndex = new CFFIndex(); 24664 const count = glyphs.length; 24665 const charsetArray = [".notdef"]; 24666 let i, ii; 24667 for (i = 0; i < count; i++) { 24668 const glyphName = charstrings[i].glyphName; 24669 const index = CFFStandardStrings.indexOf(glyphName); 24670 if (index === -1) { 24671 strings.add(glyphName); 24672 } 24673 charsetArray.push(glyphName); 24674 } 24675 cff.charset = new CFFCharset(false, 0, charsetArray); 24676 const charStringsIndex = new CFFIndex(); 24677 charStringsIndex.add([0x8b, 0x0e]); 24678 for (i = 0; i < count; i++) { 24679 charStringsIndex.add(glyphs[i]); 24680 } 24681 cff.charStrings = charStringsIndex; 24682 const privateDict = new CFFPrivateDict(); 24683 privateDict.setByName("Subrs", null); 24684 const fields = ["BlueValues", "OtherBlues", "FamilyBlues", "FamilyOtherBlues", "StemSnapH", "StemSnapV", "BlueShift", "BlueFuzz", "BlueScale", "LanguageGroup", "ExpansionFactor", "ForceBold", "StdHW", "StdVW"]; 24685 for (i = 0, ii = fields.length; i < ii; i++) { 24686 const field = fields[i]; 24687 if (!(field in properties.privateData)) { 24688 continue; 24689 } 24690 const value = properties.privateData[field]; 24691 if (Array.isArray(value)) { 24692 for (let j = value.length - 1; j > 0; j--) { 24693 value[j] -= value[j - 1]; 24694 } 24695 } 24696 privateDict.setByName(field, value); 24697 } 24698 cff.topDict.privateDict = privateDict; 24699 const subrIndex = new CFFIndex(); 24700 for (i = 0, ii = subrs.length; i < ii; i++) { 24701 subrIndex.add(subrs[i]); 24702 } 24703 privateDict.subrsIndex = subrIndex; 24704 const compiler = new CFFCompiler(cff); 24705 return compiler.compile(); 24706 } 24707} 24708 24709;// ./src/core/fonts.js 24710 24711 24712 24713 24714 24715 24716 24717 24718 24719 24720 24721 24722 24723 24724 24725 24726 24727const PRIVATE_USE_AREAS = [[0xe000, 0xf8ff], [0x100000, 0x10fffd]]; 24728const PDF_GLYPH_SPACE_UNITS = 1000; 24729const EXPORT_DATA_PROPERTIES = ["ascent", "bbox", "black", "bold", "charProcOperatorList", "cssFontInfo", "data", "defaultVMetrics", "defaultWidth", "descent", "disableFontFace", "fallbackName", "fontExtraProperties", "fontMatrix", "isInvalidPDFjsFont", "isType3Font", "italic", "loadedName", "mimetype", "missingFile", "name", "remeasure", "systemFontInfo", "vertical"]; 24730const EXPORT_DATA_EXTRA_PROPERTIES = ["cMap", "composite", "defaultEncoding", "differences", "isMonospace", "isSerifFont", "isSymbolicFont", "seacMap", "subtype", "toFontChar", "toUnicode", "type", "vmetrics", "widths"]; 24731function adjustWidths(properties) { 24732 if (!properties.fontMatrix) { 24733 return; 24734 } 24735 if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) { 24736 return; 24737 } 24738 const scale = 0.001 / properties.fontMatrix[0]; 24739 const glyphsWidths = properties.widths; 24740 for (const glyph in glyphsWidths) { 24741 glyphsWidths[glyph] *= scale; 24742 } 24743 properties.defaultWidth *= scale; 24744} 24745function adjustTrueTypeToUnicode(properties, isSymbolicFont, nameRecords) { 24746 if (properties.isInternalFont) { 24747 return; 24748 } 24749 if (properties.hasIncludedToUnicodeMap) { 24750 return; 24751 } 24752 if (properties.hasEncoding) { 24753 return; 24754 } 24755 if (properties.toUnicode instanceof IdentityToUnicodeMap) { 24756 return; 24757 } 24758 if (!isSymbolicFont) { 24759 return; 24760 } 24761 if (nameRecords.length === 0) { 24762 return; 24763 } 24764 if (properties.defaultEncoding === WinAnsiEncoding) { 24765 return; 24766 } 24767 for (const r of nameRecords) { 24768 if (!isWinNameRecord(r)) { 24769 return; 24770 } 24771 } 24772 const encoding = WinAnsiEncoding; 24773 const toUnicode = [], 24774 glyphsUnicodeMap = getGlyphsUnicode(); 24775 for (const charCode in encoding) { 24776 const glyphName = encoding[charCode]; 24777 if (glyphName === "") { 24778 continue; 24779 } 24780 const unicode = glyphsUnicodeMap[glyphName]; 24781 if (unicode === undefined) { 24782 continue; 24783 } 24784 toUnicode[charCode] = String.fromCharCode(unicode); 24785 } 24786 if (toUnicode.length > 0) { 24787 properties.toUnicode.amend(toUnicode); 24788 } 24789} 24790function adjustType1ToUnicode(properties, builtInEncoding) { 24791 if (properties.isInternalFont) { 24792 return; 24793 } 24794 if (properties.hasIncludedToUnicodeMap) { 24795 return; 24796 } 24797 if (builtInEncoding === properties.defaultEncoding) { 24798 return; 24799 } 24800 if (properties.toUnicode instanceof IdentityToUnicodeMap) { 24801 return; 24802 } 24803 const toUnicode = [], 24804 glyphsUnicodeMap = getGlyphsUnicode(); 24805 for (const charCode in builtInEncoding) { 24806 if (properties.hasEncoding) { 24807 if (properties.baseEncodingName || properties.differences[charCode] !== undefined) { 24808 continue; 24809 } 24810 } 24811 const glyphName = builtInEncoding[charCode]; 24812 const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap); 24813 if (unicode !== -1) { 24814 toUnicode[charCode] = String.fromCharCode(unicode); 24815 } 24816 } 24817 if (toUnicode.length > 0) { 24818 properties.toUnicode.amend(toUnicode); 24819 } 24820} 24821function amendFallbackToUnicode(properties) { 24822 if (!properties.fallbackToUnicode) { 24823 return; 24824 } 24825 if (properties.toUnicode instanceof IdentityToUnicodeMap) { 24826 return; 24827 } 24828 const toUnicode = []; 24829 for (const charCode in properties.fallbackToUnicode) { 24830 if (properties.toUnicode.has(charCode)) { 24831 continue; 24832 } 24833 toUnicode[charCode] = properties.fallbackToUnicode[charCode]; 24834 } 24835 if (toUnicode.length > 0) { 24836 properties.toUnicode.amend(toUnicode); 24837 } 24838} 24839class fonts_Glyph { 24840 constructor(originalCharCode, fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) { 24841 this.originalCharCode = originalCharCode; 24842 this.fontChar = fontChar; 24843 this.unicode = unicode; 24844 this.accent = accent; 24845 this.width = width; 24846 this.vmetric = vmetric; 24847 this.operatorListId = operatorListId; 24848 this.isSpace = isSpace; 24849 this.isInFont = isInFont; 24850 } 24851 get category() { 24852 return shadow(this, "category", getCharUnicodeCategory(this.unicode), true); 24853 } 24854} 24855function int16(b0, b1) { 24856 return (b0 << 8) + b1; 24857} 24858function writeSignedInt16(bytes, index, value) { 24859 bytes[index + 1] = value; 24860 bytes[index] = value >>> 8; 24861} 24862function signedInt16(b0, b1) { 24863 const value = (b0 << 8) + b1; 24864 return value & 1 << 15 ? value - 0x10000 : value; 24865} 24866function writeUint32(bytes, index, value) { 24867 bytes[index + 3] = value & 0xff; 24868 bytes[index + 2] = value >>> 8; 24869 bytes[index + 1] = value >>> 16; 24870 bytes[index] = value >>> 24; 24871} 24872function int32(b0, b1, b2, b3) { 24873 return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3; 24874} 24875function string16(value) { 24876 return String.fromCharCode(value >> 8 & 0xff, value & 0xff); 24877} 24878function safeString16(value) { 24879 if (value > 0x7fff) { 24880 value = 0x7fff; 24881 } else if (value < -0x8000) { 24882 value = -0x8000; 24883 } 24884 return String.fromCharCode(value >> 8 & 0xff, value & 0xff); 24885} 24886function isTrueTypeFile(file) { 24887 const header = file.peekBytes(4); 24888 return readUint32(header, 0) === 0x00010000 || bytesToString(header) === "true"; 24889} 24890function isTrueTypeCollectionFile(file) { 24891 const header = file.peekBytes(4); 24892 return bytesToString(header) === "ttcf"; 24893} 24894function isOpenTypeFile(file) { 24895 const header = file.peekBytes(4); 24896 return bytesToString(header) === "OTTO"; 24897} 24898function isType1File(file) { 24899 const header = file.peekBytes(2); 24900 if (header[0] === 0x25 && header[1] === 0x21) { 24901 return true; 24902 } 24903 if (header[0] === 0x80 && header[1] === 0x01) { 24904 return true; 24905 } 24906 return false; 24907} 24908function isCFFFile(file) { 24909 const header = file.peekBytes(4); 24910 if (header[0] >= 1 && header[3] >= 1 && header[3] <= 4) { 24911 return true; 24912 } 24913 return false; 24914} 24915function getFontFileType(file, { 24916 type, 24917 subtype, 24918 composite 24919}) { 24920 let fileType, fileSubtype; 24921 if (isTrueTypeFile(file) || isTrueTypeCollectionFile(file)) { 24922 fileType = composite ? "CIDFontType2" : "TrueType"; 24923 } else if (isOpenTypeFile(file)) { 24924 fileType = composite ? "CIDFontType2" : "OpenType"; 24925 } else if (isType1File(file)) { 24926 if (composite) { 24927 fileType = "CIDFontType0"; 24928 } else { 24929 fileType = type === "MMType1" ? "MMType1" : "Type1"; 24930 } 24931 } else if (isCFFFile(file)) { 24932 if (composite) { 24933 fileType = "CIDFontType0"; 24934 fileSubtype = "CIDFontType0C"; 24935 } else { 24936 fileType = type === "MMType1" ? "MMType1" : "Type1"; 24937 fileSubtype = "Type1C"; 24938 } 24939 } else { 24940 warn("getFontFileType: Unable to detect correct font file Type/Subtype."); 24941 fileType = type; 24942 fileSubtype = subtype; 24943 } 24944 return [fileType, fileSubtype]; 24945} 24946function applyStandardFontGlyphMap(map, glyphMap) { 24947 for (const charCode in glyphMap) { 24948 map[+charCode] = glyphMap[charCode]; 24949 } 24950} 24951function buildToFontChar(encoding, glyphsUnicodeMap, differences) { 24952 const toFontChar = []; 24953 let unicode; 24954 for (let i = 0, ii = encoding.length; i < ii; i++) { 24955 unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap); 24956 if (unicode !== -1) { 24957 toFontChar[i] = unicode; 24958 } 24959 } 24960 for (const charCode in differences) { 24961 unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap); 24962 if (unicode !== -1) { 24963 toFontChar[+charCode] = unicode; 24964 } 24965 } 24966 return toFontChar; 24967} 24968function isMacNameRecord(r) { 24969 return r.platform === 1 && r.encoding === 0 && r.language === 0; 24970} 24971function isWinNameRecord(r) { 24972 return r.platform === 3 && r.encoding === 1 && r.language === 0x409; 24973} 24974function convertCidString(charCode, cid, shouldThrow = false) { 24975 switch (cid.length) { 24976 case 1: 24977 return cid.charCodeAt(0); 24978 case 2: 24979 return cid.charCodeAt(0) << 8 | cid.charCodeAt(1); 24980 } 24981 const msg = `Unsupported CID string (charCode ${charCode}): "${cid}".`; 24982 if (shouldThrow) { 24983 throw new FormatError(msg); 24984 } 24985 warn(msg); 24986 return cid; 24987} 24988function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId, toUnicode) { 24989 const newMap = Object.create(null); 24990 const toUnicodeExtraMap = new Map(); 24991 const toFontChar = []; 24992 const usedGlyphIds = new Set(); 24993 let privateUseAreaIndex = 0; 24994 const privateUseOffetStart = PRIVATE_USE_AREAS[privateUseAreaIndex][0]; 24995 let nextAvailableFontCharCode = privateUseOffetStart; 24996 let privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1]; 24997 const isInPrivateArea = code => PRIVATE_USE_AREAS[0][0] <= code && code <= PRIVATE_USE_AREAS[0][1] || PRIVATE_USE_AREAS[1][0] <= code && code <= PRIVATE_USE_AREAS[1][1]; 24998 let LIGATURE_TO_UNICODE = null; 24999 for (const originalCharCode in charCodeToGlyphId) { 25000 let glyphId = charCodeToGlyphId[originalCharCode]; 25001 if (!hasGlyph(glyphId)) { 25002 continue; 25003 } 25004 if (nextAvailableFontCharCode > privateUseOffetEnd) { 25005 privateUseAreaIndex++; 25006 if (privateUseAreaIndex >= PRIVATE_USE_AREAS.length) { 25007 warn("Ran out of space in font private use area."); 25008 break; 25009 } 25010 nextAvailableFontCharCode = PRIVATE_USE_AREAS[privateUseAreaIndex][0]; 25011 privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1]; 25012 } 25013 const fontCharCode = nextAvailableFontCharCode++; 25014 if (glyphId === 0) { 25015 glyphId = newGlyphZeroId; 25016 } 25017 let unicode = toUnicode.get(originalCharCode); 25018 if (typeof unicode === "string") { 25019 if (unicode.length === 1) { 25020 unicode = unicode.codePointAt(0); 25021 } else { 25022 if (!LIGATURE_TO_UNICODE) { 25023 LIGATURE_TO_UNICODE = new Map(); 25024 for (let i = 0xfb00; i <= 0xfb4f; i++) { 25025 const normalized = String.fromCharCode(i).normalize("NFKD"); 25026 if (normalized.length > 1) { 25027 LIGATURE_TO_UNICODE.set(normalized, i); 25028 } 25029 } 25030 } 25031 unicode = LIGATURE_TO_UNICODE.get(unicode) || unicode.codePointAt(0); 25032 } 25033 } 25034 if (unicode && !isInPrivateArea(unicode) && !usedGlyphIds.has(glyphId)) { 25035 toUnicodeExtraMap.set(unicode, glyphId); 25036 usedGlyphIds.add(glyphId); 25037 } 25038 newMap[fontCharCode] = glyphId; 25039 toFontChar[originalCharCode] = fontCharCode; 25040 } 25041 return { 25042 toFontChar, 25043 charCodeToGlyphId: newMap, 25044 toUnicodeExtraMap, 25045 nextAvailableFontCharCode 25046 }; 25047} 25048function getRanges(glyphs, toUnicodeExtraMap, numGlyphs) { 25049 const codes = []; 25050 for (const charCode in glyphs) { 25051 if (glyphs[charCode] >= numGlyphs) { 25052 continue; 25053 } 25054 codes.push({ 25055 fontCharCode: charCode | 0, 25056 glyphId: glyphs[charCode] 25057 }); 25058 } 25059 if (toUnicodeExtraMap) { 25060 for (const [unicode, glyphId] of toUnicodeExtraMap) { 25061 if (glyphId >= numGlyphs) { 25062 continue; 25063 } 25064 codes.push({ 25065 fontCharCode: unicode, 25066 glyphId 25067 }); 25068 } 25069 } 25070 if (codes.length === 0) { 25071 codes.push({ 25072 fontCharCode: 0, 25073 glyphId: 0 25074 }); 25075 } 25076 codes.sort((a, b) => a.fontCharCode - b.fontCharCode); 25077 const ranges = []; 25078 const length = codes.length; 25079 for (let n = 0; n < length;) { 25080 const start = codes[n].fontCharCode; 25081 const codeIndices = [codes[n].glyphId]; 25082 ++n; 25083 let end = start; 25084 while (n < length && end + 1 === codes[n].fontCharCode) { 25085 codeIndices.push(codes[n].glyphId); 25086 ++end; 25087 ++n; 25088 if (end === 0xffff) { 25089 break; 25090 } 25091 } 25092 ranges.push([start, end, codeIndices]); 25093 } 25094 return ranges; 25095} 25096function createCmapTable(glyphs, toUnicodeExtraMap, numGlyphs) { 25097 const ranges = getRanges(glyphs, toUnicodeExtraMap, numGlyphs); 25098 const numTables = ranges.at(-1)[1] > 0xffff ? 2 : 1; 25099 let cmap = "\x00\x00" + string16(numTables) + "\x00\x03" + "\x00\x01" + string32(4 + numTables * 8); 25100 let i, ii, j, jj; 25101 for (i = ranges.length - 1; i >= 0; --i) { 25102 if (ranges[i][0] <= 0xffff) { 25103 break; 25104 } 25105 } 25106 const bmpLength = i + 1; 25107 if (ranges[i][0] < 0xffff && ranges[i][1] === 0xffff) { 25108 ranges[i][1] = 0xfffe; 25109 } 25110 const trailingRangesCount = ranges[i][1] < 0xffff ? 1 : 0; 25111 const segCount = bmpLength + trailingRangesCount; 25112 const searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2); 25113 let startCount = ""; 25114 let endCount = ""; 25115 let idDeltas = ""; 25116 let idRangeOffsets = ""; 25117 let glyphsIds = ""; 25118 let bias = 0; 25119 let range, start, end, codes; 25120 for (i = 0, ii = bmpLength; i < ii; i++) { 25121 range = ranges[i]; 25122 start = range[0]; 25123 end = range[1]; 25124 startCount += string16(start); 25125 endCount += string16(end); 25126 codes = range[2]; 25127 let contiguous = true; 25128 for (j = 1, jj = codes.length; j < jj; ++j) { 25129 if (codes[j] !== codes[j - 1] + 1) { 25130 contiguous = false; 25131 break; 25132 } 25133 } 25134 if (!contiguous) { 25135 const offset = (segCount - i) * 2 + bias * 2; 25136 bias += end - start + 1; 25137 idDeltas += string16(0); 25138 idRangeOffsets += string16(offset); 25139 for (j = 0, jj = codes.length; j < jj; ++j) { 25140 glyphsIds += string16(codes[j]); 25141 } 25142 } else { 25143 const startCode = codes[0]; 25144 idDeltas += string16(startCode - start & 0xffff); 25145 idRangeOffsets += string16(0); 25146 } 25147 } 25148 if (trailingRangesCount > 0) { 25149 endCount += "\xFF\xFF"; 25150 startCount += "\xFF\xFF"; 25151 idDeltas += "\x00\x01"; 25152 idRangeOffsets += "\x00\x00"; 25153 } 25154 const format314 = "\x00\x00" + string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + "\x00\x00" + startCount + idDeltas + idRangeOffsets + glyphsIds; 25155 let format31012 = ""; 25156 let header31012 = ""; 25157 if (numTables > 1) { 25158 cmap += "\x00\x03" + "\x00\x0A" + string32(4 + numTables * 8 + 4 + format314.length); 25159 format31012 = ""; 25160 for (i = 0, ii = ranges.length; i < ii; i++) { 25161 range = ranges[i]; 25162 start = range[0]; 25163 codes = range[2]; 25164 let code = codes[0]; 25165 for (j = 1, jj = codes.length; j < jj; ++j) { 25166 if (codes[j] !== codes[j - 1] + 1) { 25167 end = range[0] + j - 1; 25168 format31012 += string32(start) + string32(end) + string32(code); 25169 start = end + 1; 25170 code = codes[j]; 25171 } 25172 } 25173 format31012 += string32(start) + string32(range[1]) + string32(code); 25174 } 25175 header31012 = "\x00\x0C" + "\x00\x00" + string32(format31012.length + 16) + "\x00\x00\x00\x00" + string32(format31012.length / 12); 25176 } 25177 return cmap + "\x00\x04" + string16(format314.length + 4) + format314 + header31012 + format31012; 25178} 25179function validateOS2Table(os2, file) { 25180 file.pos = (file.start || 0) + os2.offset; 25181 const version = file.getUint16(); 25182 file.skip(60); 25183 const selection = file.getUint16(); 25184 if (version < 4 && selection & 0x0300) { 25185 return false; 25186 } 25187 const firstChar = file.getUint16(); 25188 const lastChar = file.getUint16(); 25189 if (firstChar > lastChar) { 25190 return false; 25191 } 25192 file.skip(6); 25193 const usWinAscent = file.getUint16(); 25194 if (usWinAscent === 0) { 25195 return false; 25196 } 25197 os2.data[8] = os2.data[9] = 0; 25198 return true; 25199} 25200function createOS2Table(properties, charstrings, override) { 25201 override ||= { 25202 unitsPerEm: 0, 25203 yMax: 0, 25204 yMin: 0, 25205 ascent: 0, 25206 descent: 0 25207 }; 25208 let ulUnicodeRange1 = 0; 25209 let ulUnicodeRange2 = 0; 25210 let ulUnicodeRange3 = 0; 25211 let ulUnicodeRange4 = 0; 25212 let firstCharIndex = null; 25213 let lastCharIndex = 0; 25214 let position = -1; 25215 if (charstrings) { 25216 for (let code in charstrings) { 25217 code |= 0; 25218 if (firstCharIndex > code || !firstCharIndex) { 25219 firstCharIndex = code; 25220 } 25221 if (lastCharIndex < code) { 25222 lastCharIndex = code; 25223 } 25224 position = getUnicodeRangeFor(code, position); 25225 if (position < 32) { 25226 ulUnicodeRange1 |= 1 << position; 25227 } else if (position < 64) { 25228 ulUnicodeRange2 |= 1 << position - 32; 25229 } else if (position < 96) { 25230 ulUnicodeRange3 |= 1 << position - 64; 25231 } else if (position < 123) { 25232 ulUnicodeRange4 |= 1 << position - 96; 25233 } else { 25234 throw new FormatError("Unicode ranges Bits > 123 are reserved for internal usage"); 25235 } 25236 } 25237 if (lastCharIndex > 0xffff) { 25238 lastCharIndex = 0xffff; 25239 } 25240 } else { 25241 firstCharIndex = 0; 25242 lastCharIndex = 255; 25243 } 25244 const bbox = properties.bbox || [0, 0, 0, 0]; 25245 const unitsPerEm = override.unitsPerEm || (properties.fontMatrix ? 1 / Math.max(...properties.fontMatrix.slice(0, 4).map(Math.abs)) : 1000); 25246 const scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS; 25247 const typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3])); 25248 let typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1])); 25249 if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) { 25250 typoDescent = -typoDescent; 25251 } 25252 const winAscent = override.yMax || typoAscent; 25253 const winDescent = -override.yMin || -typoDescent; 25254 return "\x00\x03" + "\x02\x24" + "\x01\xF4" + "\x00\x05" + "\x00\x00" + "\x02\x8A" + "\x02\xBB" + "\x00\x00" + "\x00\x8C" + "\x02\x8A" + "\x02\xBB" + "\x00\x00" + "\x01\xDF" + "\x00\x31" + "\x01\x02" + "\x00\x00" + "\x00\x00\x06" + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + "\x00\x00\x00\x00\x00\x00" + string32(ulUnicodeRange1) + string32(ulUnicodeRange2) + string32(ulUnicodeRange3) + string32(ulUnicodeRange4) + "\x2A\x32\x31\x2A" + string16(properties.italicAngle ? 1 : 0) + string16(firstCharIndex || properties.firstChar) + string16(lastCharIndex || properties.lastChar) + string16(typoAscent) + string16(typoDescent) + "\x00\x64" + string16(winAscent) + string16(winDescent) + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + string16(properties.xHeight) + string16(properties.capHeight) + string16(0) + string16(firstCharIndex || properties.firstChar) + "\x00\x03"; 25255} 25256function createPostTable(properties) { 25257 const angle = Math.floor(properties.italicAngle * 2 ** 16); 25258 return "\x00\x03\x00\x00" + string32(angle) + "\x00\x00" + "\x00\x00" + string32(properties.fixedPitch ? 1 : 0) + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00"; 25259} 25260function createPostscriptName(name) { 25261 return name.replaceAll(/[^\x21-\x7E]|[[\](){}<>/%]/g, "").slice(0, 63); 25262} 25263function createNameTable(name, proto) { 25264 if (!proto) { 25265 proto = [[], []]; 25266 } 25267 const strings = [proto[0][0] || "Original licence", proto[0][1] || name, proto[0][2] || "Unknown", proto[0][3] || "uniqueID", proto[0][4] || name, proto[0][5] || "Version 0.11", proto[0][6] || createPostscriptName(name), proto[0][7] || "Unknown", proto[0][8] || "Unknown", proto[0][9] || "Unknown"]; 25268 const stringsUnicode = []; 25269 let i, ii, j, jj, str; 25270 for (i = 0, ii = strings.length; i < ii; i++) { 25271 str = proto[1][i] || strings[i]; 25272 const strBufUnicode = []; 25273 for (j = 0, jj = str.length; j < jj; j++) { 25274 strBufUnicode.push(string16(str.charCodeAt(j))); 25275 } 25276 stringsUnicode.push(strBufUnicode.join("")); 25277 } 25278 const names = [strings, stringsUnicode]; 25279 const platforms = ["\x00\x01", "\x00\x03"]; 25280 const encodings = ["\x00\x00", "\x00\x01"]; 25281 const languages = ["\x00\x00", "\x04\x09"]; 25282 const namesRecordCount = strings.length * platforms.length; 25283 let nameTable = "\x00\x00" + string16(namesRecordCount) + string16(namesRecordCount * 12 + 6); 25284 let strOffset = 0; 25285 for (i = 0, ii = platforms.length; i < ii; i++) { 25286 const strs = names[i]; 25287 for (j = 0, jj = strs.length; j < jj; j++) { 25288 str = strs[j]; 25289 const nameRecord = platforms[i] + encodings[i] + languages[i] + string16(j) + string16(str.length) + string16(strOffset); 25290 nameTable += nameRecord; 25291 strOffset += str.length; 25292 } 25293 } 25294 nameTable += strings.join("") + stringsUnicode.join(""); 25295 return nameTable; 25296} 25297class Font { 25298 constructor(name, file, properties, evaluatorOptions) { 25299 this.name = name; 25300 this.psName = null; 25301 this.mimetype = null; 25302 this.disableFontFace = evaluatorOptions.disableFontFace; 25303 this.fontExtraProperties = evaluatorOptions.fontExtraProperties; 25304 this.loadedName = properties.loadedName; 25305 this.isType3Font = properties.isType3Font; 25306 this.missingFile = false; 25307 this.cssFontInfo = properties.cssFontInfo; 25308 this._charsCache = Object.create(null); 25309 this._glyphCache = Object.create(null); 25310 let isSerifFont = !!(properties.flags & FontFlags.Serif); 25311 if (!isSerifFont && !properties.isSimulatedFlags) { 25312 const stdFontMap = getStdFontMap(), 25313 nonStdFontMap = getNonStdFontMap(), 25314 serifFonts = getSerifFonts(); 25315 for (const namePart of name.split("+")) { 25316 let fontName = namePart.replaceAll(/[,_]/g, "-"); 25317 fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName; 25318 fontName = fontName.split("-", 1)[0]; 25319 if (serifFonts[fontName]) { 25320 isSerifFont = true; 25321 break; 25322 } 25323 } 25324 } 25325 this.isSerifFont = isSerifFont; 25326 this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic); 25327 this.isMonospace = !!(properties.flags & FontFlags.FixedPitch); 25328 let { 25329 type, 25330 subtype 25331 } = properties; 25332 this.type = type; 25333 this.subtype = subtype; 25334 this.systemFontInfo = properties.systemFontInfo; 25335 const matches = name.match(/^InvalidPDFjsFont_(.*)_\d+$/); 25336 this.isInvalidPDFjsFont = !!matches; 25337 if (this.isInvalidPDFjsFont) { 25338 this.fallbackName = matches[1]; 25339 } else if (this.isMonospace) { 25340 this.fallbackName = "monospace"; 25341 } else if (this.isSerifFont) { 25342 this.fallbackName = "serif"; 25343 } else { 25344 this.fallbackName = "sans-serif"; 25345 } 25346 if (this.systemFontInfo?.guessFallback) { 25347 this.systemFontInfo.guessFallback = false; 25348 this.systemFontInfo.css += `,${this.fallbackName}`; 25349 } 25350 this.differences = properties.differences; 25351 this.widths = properties.widths; 25352 this.defaultWidth = properties.defaultWidth; 25353 this.composite = properties.composite; 25354 this.cMap = properties.cMap; 25355 this.capHeight = properties.capHeight / PDF_GLYPH_SPACE_UNITS; 25356 this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS; 25357 this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS; 25358 this.lineHeight = this.ascent - this.descent; 25359 this.fontMatrix = properties.fontMatrix; 25360 this.bbox = properties.bbox; 25361 this.defaultEncoding = properties.defaultEncoding; 25362 this.toUnicode = properties.toUnicode; 25363 this.toFontChar = []; 25364 if (properties.type === "Type3") { 25365 for (let charCode = 0; charCode < 256; charCode++) { 25366 this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode]; 25367 } 25368 return; 25369 } 25370 this.cidEncoding = properties.cidEncoding || ""; 25371 this.vertical = !!properties.vertical; 25372 if (this.vertical) { 25373 this.vmetrics = properties.vmetrics; 25374 this.defaultVMetrics = properties.defaultVMetrics; 25375 } 25376 if (!file || file.isEmpty) { 25377 if (file) { 25378 warn('Font file is empty in "' + name + '" (' + this.loadedName + ")"); 25379 } 25380 this.fallbackToSystemFont(properties); 25381 return; 25382 } 25383 [type, subtype] = getFontFileType(file, properties); 25384 if (type !== this.type || subtype !== this.subtype) { 25385 info("Inconsistent font file Type/SubType, expected: " + `${this.type}/${this.subtype} but found: ${type}/${subtype}.`); 25386 } 25387 let data; 25388 try { 25389 switch (type) { 25390 case "MMType1": 25391 info("MMType1 font (" + name + "), falling back to Type1."); 25392 case "Type1": 25393 case "CIDFontType0": 25394 this.mimetype = "font/opentype"; 25395 const cff = subtype === "Type1C" || subtype === "CIDFontType0C" ? new CFFFont(file, properties) : new Type1Font(name, file, properties); 25396 adjustWidths(properties); 25397 data = this.convert(name, cff, properties); 25398 break; 25399 case "OpenType": 25400 case "TrueType": 25401 case "CIDFontType2": 25402 this.mimetype = "font/opentype"; 25403 data = this.checkAndRepair(name, file, properties); 25404 adjustWidths(properties); 25405 if (this.isOpenType) { 25406 type = "OpenType"; 25407 } 25408 break; 25409 default: 25410 throw new FormatError(`Font ${type} is not supported`); 25411 } 25412 } catch (e) { 25413 warn(e); 25414 this.fallbackToSystemFont(properties); 25415 return; 25416 } 25417 amendFallbackToUnicode(properties); 25418 this.data = data; 25419 this.type = type; 25420 this.subtype = subtype; 25421 this.fontMatrix = properties.fontMatrix; 25422 this.widths = properties.widths; 25423 this.defaultWidth = properties.defaultWidth; 25424 this.toUnicode = properties.toUnicode; 25425 this.seacMap = properties.seacMap; 25426 } 25427 get renderer() { 25428 const renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED); 25429 return shadow(this, "renderer", renderer); 25430 } 25431 exportData() { 25432 const data = Object.create(null); 25433 for (const prop of EXPORT_DATA_PROPERTIES) { 25434 const value = this[prop]; 25435 if (value !== undefined) { 25436 data[prop] = value; 25437 } 25438 } 25439 if (!this.fontExtraProperties) { 25440 return { 25441 data 25442 }; 25443 } 25444 const extra = Object.create(null); 25445 for (const prop of EXPORT_DATA_EXTRA_PROPERTIES) { 25446 const value = this[prop]; 25447 if (value !== undefined) { 25448 extra[prop] = value; 25449 } 25450 } 25451 return { 25452 data, 25453 extra 25454 }; 25455 } 25456 fallbackToSystemFont(properties) { 25457 this.missingFile = true; 25458 const { 25459 name, 25460 type 25461 } = this; 25462 let fontName = normalizeFontName(name); 25463 const stdFontMap = getStdFontMap(), 25464 nonStdFontMap = getNonStdFontMap(); 25465 const isStandardFont = !!stdFontMap[fontName]; 25466 const isMappedToStandardFont = !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]); 25467 fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName; 25468 const fontBasicMetricsMap = getFontBasicMetrics(); 25469 const metrics = fontBasicMetricsMap[fontName]; 25470 if (metrics) { 25471 if (isNaN(this.ascent)) { 25472 this.ascent = metrics.ascent / PDF_GLYPH_SPACE_UNITS; 25473 } 25474 if (isNaN(this.descent)) { 25475 this.descent = metrics.descent / PDF_GLYPH_SPACE_UNITS; 25476 } 25477 if (isNaN(this.capHeight)) { 25478 this.capHeight = metrics.capHeight / PDF_GLYPH_SPACE_UNITS; 25479 } 25480 } 25481 this.bold = /bold/gi.test(fontName); 25482 this.italic = /oblique|italic/gi.test(fontName); 25483 this.black = /Black/g.test(name); 25484 const isNarrow = /Narrow/g.test(name); 25485 this.remeasure = (!isStandardFont || isNarrow) && Object.keys(this.widths).length > 0; 25486 if ((isStandardFont || isMappedToStandardFont) && type === "CIDFontType2" && this.cidEncoding.startsWith("Identity-")) { 25487 const cidToGidMap = properties.cidToGidMap; 25488 const map = []; 25489 applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts()); 25490 if (/Arial-?Black/i.test(name)) { 25491 applyStandardFontGlyphMap(map, getSupplementalGlyphMapForArialBlack()); 25492 } else if (/Calibri/i.test(name)) { 25493 applyStandardFontGlyphMap(map, getSupplementalGlyphMapForCalibri()); 25494 } 25495 if (cidToGidMap) { 25496 for (const charCode in map) { 25497 const cid = map[charCode]; 25498 if (cidToGidMap[cid] !== undefined) { 25499 map[+charCode] = cidToGidMap[cid]; 25500 } 25501 } 25502 if (cidToGidMap.length !== this.toUnicode.length && properties.hasIncludedToUnicodeMap && this.toUnicode instanceof IdentityToUnicodeMap) { 25503 this.toUnicode.forEach(function (charCode, unicodeCharCode) { 25504 const cid = map[charCode]; 25505 if (cidToGidMap[cid] === undefined) { 25506 map[+charCode] = unicodeCharCode; 25507 } 25508 }); 25509 } 25510 } 25511 if (!(this.toUnicode instanceof IdentityToUnicodeMap)) { 25512 this.toUnicode.forEach(function (charCode, unicodeCharCode) { 25513 map[+charCode] = unicodeCharCode; 25514 }); 25515 } 25516 this.toFontChar = map; 25517 this.toUnicode = new ToUnicodeMap(map); 25518 } else if (/Symbol/i.test(fontName)) { 25519 this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(), this.differences); 25520 } else if (/Dingbats/i.test(fontName)) { 25521 this.toFontChar = buildToFontChar(ZapfDingbatsEncoding, getDingbatsGlyphsUnicode(), this.differences); 25522 } else if (isStandardFont || isMappedToStandardFont) { 25523 const map = buildToFontChar(this.defaultEncoding, getGlyphsUnicode(), this.differences); 25524 if (type === "CIDFontType2" && !this.cidEncoding.startsWith("Identity-") && !(this.toUnicode instanceof IdentityToUnicodeMap)) { 25525 this.toUnicode.forEach(function (charCode, unicodeCharCode) { 25526 map[+charCode] = unicodeCharCode; 25527 }); 25528 } 25529 this.toFontChar = map; 25530 } else { 25531 const glyphsUnicodeMap = getGlyphsUnicode(); 25532 const map = []; 25533 this.toUnicode.forEach((charCode, unicodeCharCode) => { 25534 if (!this.composite) { 25535 const glyphName = this.differences[charCode] || this.defaultEncoding[charCode]; 25536 const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap); 25537 if (unicode !== -1) { 25538 unicodeCharCode = unicode; 25539 } 25540 } 25541 map[+charCode] = unicodeCharCode; 25542 }); 25543 if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) { 25544 if (/Tahoma|Verdana/i.test(name)) { 25545 applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts()); 25546 } 25547 } 25548 this.toFontChar = map; 25549 } 25550 amendFallbackToUnicode(properties); 25551 this.loadedName = fontName.split("-", 1)[0]; 25552 } 25553 checkAndRepair(name, font, properties) { 25554 const VALID_TABLES = ["OS/2", "cmap", "head", "hhea", "hmtx", "maxp", "name", "post", "loca", "glyf", "fpgm", "prep", "cvt ", "CFF "]; 25555 function readTables(file, numTables) { 25556 const tables = Object.create(null); 25557 tables["OS/2"] = null; 25558 tables.cmap = null; 25559 tables.head = null; 25560 tables.hhea = null; 25561 tables.hmtx = null; 25562 tables.maxp = null; 25563 tables.name = null; 25564 tables.post = null; 25565 for (let i = 0; i < numTables; i++) { 25566 const table = readTableEntry(file); 25567 if (!VALID_TABLES.includes(table.tag)) { 25568 continue; 25569 } 25570 if (table.length === 0) { 25571 continue; 25572 } 25573 tables[table.tag] = table; 25574 } 25575 return tables; 25576 } 25577 function readTableEntry(file) { 25578 const tag = file.getString(4); 25579 const checksum = file.getInt32() >>> 0; 25580 const offset = file.getInt32() >>> 0; 25581 const length = file.getInt32() >>> 0; 25582 const previousPosition = file.pos; 25583 file.pos = file.start || 0; 25584 file.skip(offset); 25585 const data = file.getBytes(length); 25586 file.pos = previousPosition; 25587 if (tag === "head") { 25588 data[8] = data[9] = data[10] = data[11] = 0; 25589 data[17] |= 0x20; 25590 } 25591 return { 25592 tag, 25593 checksum, 25594 length, 25595 offset, 25596 data 25597 }; 25598 } 25599 function readOpenTypeHeader(ttf) { 25600 return { 25601 version: ttf.getString(4), 25602 numTables: ttf.getUint16(), 25603 searchRange: ttf.getUint16(), 25604 entrySelector: ttf.getUint16(), 25605 rangeShift: ttf.getUint16() 25606 }; 25607 } 25608 function readTrueTypeCollectionHeader(ttc) { 25609 const ttcTag = ttc.getString(4); 25610 assert(ttcTag === "ttcf", "Must be a TrueType Collection font."); 25611 const majorVersion = ttc.getUint16(); 25612 const minorVersion = ttc.getUint16(); 25613 const numFonts = ttc.getInt32() >>> 0; 25614 const offsetTable = []; 25615 for (let i = 0; i < numFonts; i++) { 25616 offsetTable.push(ttc.getInt32() >>> 0); 25617 } 25618 const header = { 25619 ttcTag, 25620 majorVersion, 25621 minorVersion, 25622 numFonts, 25623 offsetTable 25624 }; 25625 switch (majorVersion) { 25626 case 1: 25627 return header; 25628 case 2: 25629 header.dsigTag = ttc.getInt32() >>> 0; 25630 header.dsigLength = ttc.getInt32() >>> 0; 25631 header.dsigOffset = ttc.getInt32() >>> 0; 25632 return header; 25633 } 25634 throw new FormatError(`Invalid TrueType Collection majorVersion: ${majorVersion}.`); 25635 } 25636 function readTrueTypeCollectionData(ttc, fontName) { 25637 const { 25638 numFonts, 25639 offsetTable 25640 } = readTrueTypeCollectionHeader(ttc); 25641 const fontNameParts = fontName.split("+"); 25642 let fallbackData; 25643 for (let i = 0; i < numFonts; i++) { 25644 ttc.pos = (ttc.start || 0) + offsetTable[i]; 25645 const potentialHeader = readOpenTypeHeader(ttc); 25646 const potentialTables = readTables(ttc, potentialHeader.numTables); 25647 if (!potentialTables.name) { 25648 throw new FormatError('TrueType Collection font must contain a "name" table.'); 25649 } 25650 const [nameTable] = readNameTable(potentialTables.name); 25651 for (let j = 0, jj = nameTable.length; j < jj; j++) { 25652 for (let k = 0, kk = nameTable[j].length; k < kk; k++) { 25653 const nameEntry = nameTable[j][k]?.replaceAll(/\s/g, ""); 25654 if (!nameEntry) { 25655 continue; 25656 } 25657 if (nameEntry === fontName) { 25658 return { 25659 header: potentialHeader, 25660 tables: potentialTables 25661 }; 25662 } 25663 if (fontNameParts.length < 2) { 25664 continue; 25665 } 25666 for (const part of fontNameParts) { 25667 if (nameEntry === part) { 25668 fallbackData = { 25669 name: part, 25670 header: potentialHeader, 25671 tables: potentialTables 25672 }; 25673 } 25674 } 25675 } 25676 } 25677 } 25678 if (fallbackData) { 25679 warn(`TrueType Collection does not contain "${fontName}" font, ` + `falling back to "${fallbackData.name}" font instead.`); 25680 return { 25681 header: fallbackData.header, 25682 tables: fallbackData.tables 25683 }; 25684 } 25685 throw new FormatError(`TrueType Collection does not contain "${fontName}" font.`); 25686 } 25687 function readCmapTable(cmap, file, isSymbolicFont, hasEncoding) { 25688 if (!cmap) { 25689 warn("No cmap table available."); 25690 return { 25691 platformId: -1, 25692 encodingId: -1, 25693 mappings: [], 25694 hasShortCmap: false 25695 }; 25696 } 25697 let segment; 25698 let start = (file.start || 0) + cmap.offset; 25699 file.pos = start; 25700 file.skip(2); 25701 const numTables = file.getUint16(); 25702 let potentialTable; 25703 let canBreak = false;
vendor: 5,443 bytes, lines 25704-25864
25704 for (let i = 0; i < numTables; i++) { 25705 const platformId = file.getUint16(); 25706 const encodingId = file.getUint16(); 25707 const offset = file.getInt32() >>> 0; 25708 let useTable = false; 25709 if (potentialTable?.platformId === platformId && potentialTable?.encodingId === encodingId) { 25710 continue; 25711 } 25712 if (platformId === 0 && (encodingId === 0 || encodingId === 1 || encodingId === 3)) { 25713 useTable = true; 25714 } else if (platformId === 1 && encodingId === 0) { 25715 useTable = true; 25716 } else if (platformId === 3 && encodingId === 1 && (hasEncoding || !potentialTable)) { 25717 useTable = true; 25718 if (!isSymbolicFont) { 25719 canBreak = true; 25720 } 25721 } else if (isSymbolicFont && platformId === 3 && encodingId === 0) { 25722 useTable = true; 25723 let correctlySorted = true; 25724 if (i < numTables - 1) { 25725 const nextBytes = file.peekBytes(2), 25726 nextPlatformId = int16(nextBytes[0], nextBytes[1]); 25727 if (nextPlatformId < platformId) { 25728 correctlySorted = false; 25729 } 25730 } 25731 if (correctlySorted) { 25732 canBreak = true; 25733 } 25734 } 25735 if (useTable) { 25736 potentialTable = { 25737 platformId, 25738 encodingId, 25739 offset 25740 }; 25741 } 25742 if (canBreak) { 25743 break; 25744 } 25745 } 25746 if (potentialTable) { 25747 file.pos = start + potentialTable.offset; 25748 } 25749 if (!potentialTable || file.peekByte() === -1) { 25750 warn("Could not find a preferred cmap table."); 25751 return { 25752 platformId: -1, 25753 encodingId: -1, 25754 mappings: [], 25755 hasShortCmap: false 25756 }; 25757 } 25758 const format = file.getUint16(); 25759 let hasShortCmap = false; 25760 const mappings = []; 25761 let j, glyphId; 25762 if (format === 0) { 25763 file.skip(2 + 2); 25764 for (j = 0; j < 256; j++) { 25765 const index = file.getByte(); 25766 if (!index) { 25767 continue; 25768 } 25769 mappings.push({ 25770 charCode: j, 25771 glyphId: index 25772 }); 25773 } 25774 hasShortCmap = true; 25775 } else if (format === 2) { 25776 file.skip(2 + 2); 25777 const subHeaderKeys = []; 25778 let maxSubHeaderKey = 0; 25779 for (let i = 0; i < 256; i++) { 25780 const subHeaderKey = file.getUint16() >> 3; 25781 subHeaderKeys.push(subHeaderKey); 25782 maxSubHeaderKey = Math.max(subHeaderKey, maxSubHeaderKey); 25783 } 25784 const subHeaders = []; 25785 for (let i = 0; i <= maxSubHeaderKey; i++) { 25786 subHeaders.push({ 25787 firstCode: file.getUint16(), 25788 entryCount: file.getUint16(), 25789 idDelta: signedInt16(file.getByte(), file.getByte()), 25790 idRangePos: file.pos + file.getUint16() 25791 }); 25792 } 25793 for (let i = 0; i < 256; i++) { 25794 if (subHeaderKeys[i] === 0) { 25795 file.pos = subHeaders[0].idRangePos + 2 * i; 25796 glyphId = file.getUint16(); 25797 mappings.push({ 25798 charCode: i, 25799 glyphId 25800 }); 25801 } else { 25802 const s = subHeaders[subHeaderKeys[i]]; 25803 for (j = 0; j < s.entryCount; j++) { 25804 const charCode = (i << 8) + j + s.firstCode; 25805 file.pos = s.idRangePos + 2 * j; 25806 glyphId = file.getUint16(); 25807 if (glyphId !== 0) { 25808 glyphId = (glyphId + s.idDelta) % 65536; 25809 } 25810 mappings.push({ 25811 charCode, 25812 glyphId 25813 }); 25814 } 25815 } 25816 } 25817 } else if (format === 4) { 25818 file.skip(2 + 2); 25819 const segCount = file.getUint16() >> 1; 25820 file.skip(6); 25821 const segments = []; 25822 let segIndex; 25823 for (segIndex = 0; segIndex < segCount; segIndex++) { 25824 segments.push({ 25825 end: file.getUint16() 25826 }); 25827 } 25828 file.skip(2); 25829 for (segIndex = 0; segIndex < segCount; segIndex++) { 25830 segments[segIndex].start = file.getUint16(); 25831 } 25832 for (segIndex = 0; segIndex < segCount; segIndex++) { 25833 segments[segIndex].delta = file.getUint16(); 25834 } 25835 let offsetsCount = 0, 25836 offsetIndex; 25837 for (segIndex = 0; segIndex < segCount; segIndex++) { 25838 segment = segments[segIndex]; 25839 const rangeOffset = file.getUint16(); 25840 if (!rangeOffset) { 25841 segment.offsetIndex = -1; 25842 continue; 25843 } 25844 offsetIndex = (rangeOffset >> 1) - (segCount - segIndex); 25845 segment.offsetIndex = offsetIndex; 25846 offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1); 25847 } 25848 const offsets = []; 25849 for (j = 0; j < offsetsCount; j++) { 25850 offsets.push(file.getUint16()); 25851 } 25852 for (segIndex = 0; segIndex < segCount; segIndex++) { 25853 segment = segments[segIndex]; 25854 start = segment.start; 25855 const end = segment.end; 25856 const delta = segment.delta; 25857 offsetIndex = segment.offsetIndex; 25858 for (j = start; j <= end; j++) { 25859 if (j === 0xffff) { 25860 continue; 25861 } 25862 glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start]; 25863 glyphId = glyphId + delta & 0xffff; 25864 mappings.push({
vendor: 18,251 bytes, lines 25865-26388
25865 charCode: j, 25866 glyphId 25867 }); 25868 } 25869 } 25870 } else if (format === 6) { 25871 file.skip(2 + 2); 25872 const firstCode = file.getUint16(); 25873 const entryCount = file.getUint16(); 25874 for (j = 0; j < entryCount; j++) { 25875 glyphId = file.getUint16(); 25876 const charCode = firstCode + j; 25877 mappings.push({ 25878 charCode, 25879 glyphId 25880 }); 25881 } 25882 } else if (format === 12) { 25883 file.skip(2 + 4 + 4); 25884 const nGroups = file.getInt32() >>> 0; 25885 for (j = 0; j < nGroups; j++) { 25886 const startCharCode = file.getInt32() >>> 0; 25887 const endCharCode = file.getInt32() >>> 0; 25888 let glyphCode = file.getInt32() >>> 0; 25889 for (let charCode = startCharCode; charCode <= endCharCode; charCode++) { 25890 mappings.push({ 25891 charCode, 25892 glyphId: glyphCode++ 25893 }); 25894 } 25895 } 25896 } else { 25897 warn("cmap table has unsupported format: " + format); 25898 return { 25899 platformId: -1, 25900 encodingId: -1, 25901 mappings: [], 25902 hasShortCmap: false 25903 }; 25904 } 25905 mappings.sort((a, b) => a.charCode - b.charCode); 25906 const finalMappings = [], 25907 seenCharCodes = new Set(); 25908 for (const map of mappings) { 25909 const { 25910 charCode 25911 } = map; 25912 if (seenCharCodes.has(charCode)) { 25913 continue; 25914 } 25915 seenCharCodes.add(charCode); 25916 finalMappings.push(map); 25917 } 25918 return { 25919 platformId: potentialTable.platformId, 25920 encodingId: potentialTable.encodingId, 25921 mappings: finalMappings, 25922 hasShortCmap 25923 }; 25924 } 25925 function sanitizeMetrics(file, header, metrics, headTable, numGlyphs, dupFirstEntry) { 25926 if (!header) { 25927 if (metrics) { 25928 metrics.data = null; 25929 } 25930 return; 25931 } 25932 file.pos = (file.start || 0) + header.offset; 25933 file.pos += 4; 25934 file.pos += 2; 25935 file.pos += 2; 25936 file.pos += 2; 25937 file.pos += 2; 25938 file.pos += 2; 25939 file.pos += 2; 25940 file.pos += 2; 25941 file.pos += 2; 25942 file.pos += 2; 25943 const caretOffset = file.getUint16(); 25944 file.pos += 8; 25945 file.pos += 2; 25946 let numOfMetrics = file.getUint16(); 25947 if (caretOffset !== 0) { 25948 const macStyle = int16(headTable.data[44], headTable.data[45]); 25949 if (!(macStyle & 2)) { 25950 header.data[22] = 0; 25951 header.data[23] = 0; 25952 } 25953 } 25954 if (numOfMetrics > numGlyphs) { 25955 info(`The numOfMetrics (${numOfMetrics}) should not be ` + `greater than the numGlyphs (${numGlyphs}).`); 25956 numOfMetrics = numGlyphs; 25957 header.data[34] = (numOfMetrics & 0xff00) >> 8; 25958 header.data[35] = numOfMetrics & 0x00ff; 25959 } 25960 const numOfSidebearings = numGlyphs - numOfMetrics; 25961 const numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1); 25962 if (numMissing > 0) { 25963 const entries = new Uint8Array(metrics.length + numMissing * 2); 25964 entries.set(metrics.data); 25965 if (dupFirstEntry) { 25966 entries[metrics.length] = metrics.data[2]; 25967 entries[metrics.length + 1] = metrics.data[3]; 25968 } 25969 metrics.data = entries; 25970 } 25971 } 25972 function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) { 25973 const glyphProfile = { 25974 length: 0, 25975 sizeOfInstructions: 0 25976 }; 25977 if (sourceStart < 0 || sourceStart >= source.length || sourceEnd > source.length || sourceEnd - sourceStart <= 12) { 25978 return glyphProfile; 25979 } 25980 const glyf = source.subarray(sourceStart, sourceEnd); 25981 const xMin = signedInt16(glyf[2], glyf[3]); 25982 const yMin = signedInt16(glyf[4], glyf[5]); 25983 const xMax = signedInt16(glyf[6], glyf[7]); 25984 const yMax = signedInt16(glyf[8], glyf[9]); 25985 if (xMin > xMax) { 25986 writeSignedInt16(glyf, 2, xMax); 25987 writeSignedInt16(glyf, 6, xMin); 25988 } 25989 if (yMin > yMax) { 25990 writeSignedInt16(glyf, 4, yMax); 25991 writeSignedInt16(glyf, 8, yMin); 25992 } 25993 const contoursCount = signedInt16(glyf[0], glyf[1]); 25994 if (contoursCount < 0) { 25995 if (contoursCount < -1) { 25996 return glyphProfile; 25997 } 25998 dest.set(glyf, destStart); 25999 glyphProfile.length = glyf.length; 26000 return glyphProfile; 26001 } 26002 let i, 26003 j = 10, 26004 flagsCount = 0; 26005 for (i = 0; i < contoursCount; i++) { 26006 const endPoint = glyf[j] << 8 | glyf[j + 1]; 26007 flagsCount = endPoint + 1; 26008 j += 2; 26009 } 26010 const instructionsStart = j; 26011 const instructionsLength = glyf[j] << 8 | glyf[j + 1]; 26012 glyphProfile.sizeOfInstructions = instructionsLength; 26013 j += 2 + instructionsLength; 26014 const instructionsEnd = j; 26015 let coordinatesLength = 0; 26016 for (i = 0; i < flagsCount; i++) { 26017 const flag = glyf[j++]; 26018 if (flag & 0xc0) { 26019 glyf[j - 1] = flag & 0x3f; 26020 } 26021 let xLength = 2; 26022 if (flag & 2) { 26023 xLength = 1; 26024 } else if (flag & 16) { 26025 xLength = 0; 26026 } 26027 let yLength = 2; 26028 if (flag & 4) { 26029 yLength = 1; 26030 } else if (flag & 32) { 26031 yLength = 0; 26032 } 26033 const xyLength = xLength + yLength; 26034 coordinatesLength += xyLength; 26035 if (flag & 8) { 26036 const repeat = glyf[j++]; 26037 if (repeat === 0) { 26038 glyf[j - 1] ^= 8; 26039 } 26040 i += repeat; 26041 coordinatesLength += repeat * xyLength; 26042 } 26043 } 26044 if (coordinatesLength === 0) { 26045 return glyphProfile; 26046 } 26047 let glyphDataLength = j + coordinatesLength; 26048 if (glyphDataLength > glyf.length) { 26049 return glyphProfile; 26050 } 26051 if (!hintsValid && instructionsLength > 0) { 26052 dest.set(glyf.subarray(0, instructionsStart), destStart); 26053 dest.set([0, 0], destStart + instructionsStart); 26054 dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2); 26055 glyphDataLength -= instructionsLength; 26056 if (glyf.length - glyphDataLength > 3) { 26057 glyphDataLength = glyphDataLength + 3 & ~3; 26058 } 26059 glyphProfile.length = glyphDataLength; 26060 return glyphProfile; 26061 } 26062 if (glyf.length - glyphDataLength > 3) { 26063 glyphDataLength = glyphDataLength + 3 & ~3; 26064 dest.set(glyf.subarray(0, glyphDataLength), destStart); 26065 glyphProfile.length = glyphDataLength; 26066 return glyphProfile; 26067 } 26068 dest.set(glyf, destStart); 26069 glyphProfile.length = glyf.length; 26070 return glyphProfile; 26071 } 26072 function sanitizeHead(head, numGlyphs, locaLength) { 26073 const data = head.data; 26074 const version = int32(data[0], data[1], data[2], data[3]); 26075 if (version >> 16 !== 1) { 26076 info("Attempting to fix invalid version in head table: " + version); 26077 data[0] = 0; 26078 data[1] = 1; 26079 data[2] = 0; 26080 data[3] = 0; 26081 } 26082 const indexToLocFormat = int16(data[50], data[51]); 26083 if (indexToLocFormat < 0 || indexToLocFormat > 1) { 26084 info("Attempting to fix invalid indexToLocFormat in head table: " + indexToLocFormat); 26085 const numGlyphsPlusOne = numGlyphs + 1; 26086 if (locaLength === numGlyphsPlusOne << 1) { 26087 data[50] = 0; 26088 data[51] = 0; 26089 } else if (locaLength === numGlyphsPlusOne << 2) { 26090 data[50] = 0; 26091 data[51] = 1; 26092 } else { 26093 throw new FormatError("Could not fix indexToLocFormat: " + indexToLocFormat); 26094 } 26095 } 26096 } 26097 function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions) { 26098 let itemSize, itemDecode, itemEncode; 26099 if (isGlyphLocationsLong) { 26100 itemSize = 4; 26101 itemDecode = function fontItemDecodeLong(data, offset) { 26102 return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]; 26103 }; 26104 itemEncode = function fontItemEncodeLong(data, offset, value) { 26105 data[offset] = value >>> 24 & 0xff; 26106 data[offset + 1] = value >> 16 & 0xff; 26107 data[offset + 2] = value >> 8 & 0xff; 26108 data[offset + 3] = value & 0xff; 26109 }; 26110 } else { 26111 itemSize = 2; 26112 itemDecode = function fontItemDecode(data, offset) { 26113 return data[offset] << 9 | data[offset + 1] << 1; 26114 }; 26115 itemEncode = function fontItemEncode(data, offset, value) { 26116 data[offset] = value >> 9 & 0xff; 26117 data[offset + 1] = value >> 1 & 0xff; 26118 }; 26119 } 26120 const numGlyphsOut = dupFirstEntry ? numGlyphs + 1 : numGlyphs; 26121 const locaDataSize = itemSize * (1 + numGlyphsOut); 26122 const locaData = new Uint8Array(locaDataSize); 26123 locaData.set(loca.data.subarray(0, locaDataSize)); 26124 loca.data = locaData; 26125 const oldGlyfData = glyf.data; 26126 const oldGlyfDataLength = oldGlyfData.length; 26127 const newGlyfData = new Uint8Array(oldGlyfDataLength); 26128 let i, j; 26129 const locaEntries = []; 26130 for (i = 0, j = 0; i < numGlyphs + 1; i++, j += itemSize) { 26131 let offset = itemDecode(locaData, j); 26132 if (offset > oldGlyfDataLength) { 26133 offset = oldGlyfDataLength; 26134 } 26135 locaEntries.push({ 26136 index: i, 26137 offset, 26138 endOffset: 0 26139 }); 26140 } 26141 locaEntries.sort((a, b) => a.offset - b.offset); 26142 for (i = 0; i < numGlyphs; i++) { 26143 locaEntries[i].endOffset = locaEntries[i + 1].offset; 26144 } 26145 locaEntries.sort((a, b) => a.index - b.index); 26146 for (i = 0; i < numGlyphs; i++) { 26147 const { 26148 offset, 26149 endOffset 26150 } = locaEntries[i]; 26151 if (offset !== 0 || endOffset !== 0) { 26152 break; 26153 } 26154 const nextOffset = locaEntries[i + 1].offset; 26155 if (nextOffset === 0) { 26156 continue; 26157 } 26158 locaEntries[i].endOffset = nextOffset; 26159 break; 26160 } 26161 const last = locaEntries.at(-2); 26162 if (last.offset !== 0 && last.endOffset === 0) { 26163 last.endOffset = oldGlyfDataLength; 26164 } 26165 const missingGlyphs = Object.create(null); 26166 let writeOffset = 0; 26167 itemEncode(locaData, 0, writeOffset); 26168 for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) { 26169 const glyphProfile = sanitizeGlyph(oldGlyfData, locaEntries[i].offset, locaEntries[i].endOffset, newGlyfData, writeOffset, hintsValid); 26170 const newLength = glyphProfile.length; 26171 if (newLength === 0) { 26172 missingGlyphs[i] = true; 26173 } 26174 if (glyphProfile.sizeOfInstructions > maxSizeOfInstructions) { 26175 maxSizeOfInstructions = glyphProfile.sizeOfInstructions; 26176 } 26177 writeOffset += newLength; 26178 itemEncode(locaData, j, writeOffset); 26179 } 26180 if (writeOffset === 0) { 26181 const simpleGlyph = new Uint8Array([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]); 26182 for (i = 0, j = itemSize; i < numGlyphsOut; i++, j += itemSize) { 26183 itemEncode(locaData, j, simpleGlyph.length); 26184 } 26185 glyf.data = simpleGlyph; 26186 } else if (dupFirstEntry) { 26187 const firstEntryLength = itemDecode(locaData, itemSize); 26188 if (newGlyfData.length > firstEntryLength + writeOffset) { 26189 glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset); 26190 } else { 26191 glyf.data = new Uint8Array(firstEntryLength + writeOffset); 26192 glyf.data.set(newGlyfData.subarray(0, writeOffset)); 26193 } 26194 glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset); 26195 itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength); 26196 } else { 26197 glyf.data = newGlyfData.subarray(0, writeOffset); 26198 } 26199 return { 26200 missingGlyphs, 26201 maxSizeOfInstructions 26202 }; 26203 } 26204 function readPostScriptTable(post, propertiesObj, maxpNumGlyphs) { 26205 const start = (font.start || 0) + post.offset; 26206 font.pos = start; 26207 const length = post.length, 26208 end = start + length; 26209 const version = font.getInt32(); 26210 font.skip(28); 26211 let glyphNames; 26212 let valid = true; 26213 let i; 26214 switch (version) { 26215 case 0x00010000: 26216 glyphNames = MacStandardGlyphOrdering; 26217 break; 26218 case 0x00020000: 26219 const numGlyphs = font.getUint16(); 26220 if (numGlyphs !== maxpNumGlyphs) { 26221 valid = false; 26222 break; 26223 } 26224 const glyphNameIndexes = []; 26225 for (i = 0; i < numGlyphs; ++i) { 26226 const index = font.getUint16(); 26227 if (index >= 32768) { 26228 valid = false; 26229 break; 26230 } 26231 glyphNameIndexes.push(index); 26232 } 26233 if (!valid) { 26234 break; 26235 } 26236 const customNames = [], 26237 strBuf = []; 26238 while (font.pos < end) { 26239 const stringLength = font.getByte(); 26240 strBuf.length = stringLength; 26241 for (i = 0; i < stringLength; ++i) { 26242 strBuf[i] = String.fromCharCode(font.getByte()); 26243 } 26244 customNames.push(strBuf.join("")); 26245 } 26246 glyphNames = []; 26247 for (i = 0; i < numGlyphs; ++i) { 26248 const j = glyphNameIndexes[i]; 26249 if (j < 258) { 26250 glyphNames.push(MacStandardGlyphOrdering[j]); 26251 continue; 26252 } 26253 glyphNames.push(customNames[j - 258]); 26254 } 26255 break; 26256 case 0x00030000: 26257 break; 26258 default: 26259 warn("Unknown/unsupported post table version " + version); 26260 valid = false; 26261 if (propertiesObj.defaultEncoding) { 26262 glyphNames = propertiesObj.defaultEncoding; 26263 } 26264 break; 26265 } 26266 propertiesObj.glyphNames = glyphNames; 26267 return valid; 26268 } 26269 function readNameTable(nameTable) { 26270 const start = (font.start || 0) + nameTable.offset; 26271 font.pos = start; 26272 const names = [[], []], 26273 records = []; 26274 const length = nameTable.length, 26275 end = start + length; 26276 const format = font.getUint16(); 26277 const FORMAT_0_HEADER_LENGTH = 6; 26278 if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) { 26279 return [names, records]; 26280 } 26281 const numRecords = font.getUint16(); 26282 const stringsStart = font.getUint16(); 26283 const NAME_RECORD_LENGTH = 12; 26284 let i, ii; 26285 for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) { 26286 const r = { 26287 platform: font.getUint16(), 26288 encoding: font.getUint16(), 26289 language: font.getUint16(), 26290 name: font.getUint16(), 26291 length: font.getUint16(), 26292 offset: font.getUint16() 26293 }; 26294 if (isMacNameRecord(r) || isWinNameRecord(r)) { 26295 records.push(r); 26296 } 26297 } 26298 for (i = 0, ii = records.length; i < ii; i++) { 26299 const record = records[i]; 26300 if (record.length <= 0) { 26301 continue; 26302 } 26303 const pos = start + stringsStart + record.offset; 26304 if (pos + record.length > end) { 26305 continue; 26306 } 26307 font.pos = pos; 26308 const nameIndex = record.name; 26309 if (record.encoding) { 26310 let str = ""; 26311 for (let j = 0, jj = record.length; j < jj; j += 2) { 26312 str += String.fromCharCode(font.getUint16()); 26313 } 26314 names[1][nameIndex] = str; 26315 } else { 26316 names[0][nameIndex] = font.getString(record.length); 26317 } 26318 } 26319 return [names, records]; 26320 } 26321 const TTOpsStackDeltas = [0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1, 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1, 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2, 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1, -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2]; 26322 function sanitizeTTProgram(table, ttContext) { 26323 let data = table.data; 26324 let i = 0, 26325 j, 26326 n, 26327 b, 26328 funcId, 26329 pc, 26330 lastEndf = 0, 26331 lastDeff = 0; 26332 const stack = []; 26333 const callstack = []; 26334 const functionsCalled = []; 26335 let tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions; 26336 let inFDEF = false, 26337 ifLevel = 0, 26338 inELSE = 0; 26339 for (let ii = data.length; i < ii;) { 26340 const op = data[i++]; 26341 if (op === 0x40) { 26342 n = data[i++]; 26343 if (inFDEF || inELSE) { 26344 i += n; 26345 } else { 26346 for (j = 0; j < n; j++) { 26347 stack.push(data[i++]); 26348 } 26349 } 26350 } else if (op === 0x41) { 26351 n = data[i++]; 26352 if (inFDEF || inELSE) { 26353 i += n * 2; 26354 } else { 26355 for (j = 0; j < n; j++) { 26356 b = data[i++]; 26357 stack.push(b << 8 | data[i++]); 26358 } 26359 } 26360 } else if ((op & 0xf8) === 0xb0) { 26361 n = op - 0xb0 + 1; 26362 if (inFDEF || inELSE) { 26363 i += n; 26364 } else { 26365 for (j = 0; j < n; j++) { 26366 stack.push(data[i++]); 26367 } 26368 } 26369 } else if ((op & 0xf8) === 0xb8) { 26370 n = op - 0xb8 + 1; 26371 if (inFDEF || inELSE) { 26372 i += n * 2; 26373 } else { 26374 for (j = 0; j < n; j++) { 26375 b = data[i++]; 26376 stack.push(signedInt16(b, data[i++])); 26377 } 26378 } 26379 } else if (op === 0x2b && !tooComplexToFollowFunctions) { 26380 if (!inFDEF && !inELSE) { 26381 funcId = stack.at(-1); 26382 if (isNaN(funcId)) { 26383 info("TT: CALL empty stack (or invalid entry)."); 26384 } else { 26385 ttContext.functionsUsed[funcId] = true; 26386 if (funcId in ttContext.functionsStackDeltas) { 26387 const newStackLength = stack.length + ttContext.functionsStackDeltas[funcId]; 26388 if (newStackLength < 0) {
vendor: 4,189 bytes, lines 26389-26517
26389 warn("TT: CALL invalid functions stack delta."); 26390 ttContext.hintsValid = false; 26391 return; 26392 } 26393 stack.length = newStackLength; 26394 } else if (funcId in ttContext.functionsDefined && !functionsCalled.includes(funcId)) { 26395 callstack.push({ 26396 data, 26397 i, 26398 stackTop: stack.length - 1 26399 }); 26400 functionsCalled.push(funcId); 26401 pc = ttContext.functionsDefined[funcId]; 26402 if (!pc) { 26403 warn("TT: CALL non-existent function"); 26404 ttContext.hintsValid = false; 26405 return; 26406 } 26407 data = pc.data; 26408 i = pc.i; 26409 } 26410 } 26411 } 26412 } else if (op === 0x2c && !tooComplexToFollowFunctions) { 26413 if (inFDEF || inELSE) { 26414 warn("TT: nested FDEFs not allowed"); 26415 tooComplexToFollowFunctions = true; 26416 } 26417 inFDEF = true; 26418 lastDeff = i; 26419 funcId = stack.pop(); 26420 ttContext.functionsDefined[funcId] = { 26421 data, 26422 i 26423 }; 26424 } else if (op === 0x2d) { 26425 if (inFDEF) { 26426 inFDEF = false; 26427 lastEndf = i; 26428 } else { 26429 pc = callstack.pop(); 26430 if (!pc) { 26431 warn("TT: ENDF bad stack"); 26432 ttContext.hintsValid = false; 26433 return; 26434 } 26435 funcId = functionsCalled.pop(); 26436 data = pc.data; 26437 i = pc.i; 26438 ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop; 26439 } 26440 } else if (op === 0x89) { 26441 if (inFDEF || inELSE) { 26442 warn("TT: nested IDEFs not allowed"); 26443 tooComplexToFollowFunctions = true; 26444 } 26445 inFDEF = true; 26446 lastDeff = i; 26447 } else if (op === 0x58) { 26448 ++ifLevel; 26449 } else if (op === 0x1b) { 26450 inELSE = ifLevel; 26451 } else if (op === 0x59) { 26452 if (inELSE === ifLevel) { 26453 inELSE = 0; 26454 } 26455 --ifLevel; 26456 } else if (op === 0x1c) { 26457 if (!inFDEF && !inELSE) { 26458 const offset = stack.at(-1); 26459 if (offset > 0) { 26460 i += offset - 1; 26461 } 26462 } 26463 } 26464 if (!inFDEF && !inELSE) { 26465 let stackDelta = 0; 26466 if (op <= 0x8e) { 26467 stackDelta = TTOpsStackDeltas[op]; 26468 } else if (op >= 0xc0 && op <= 0xdf) { 26469 stackDelta = -1; 26470 } else if (op >= 0xe0) { 26471 stackDelta = -2; 26472 } 26473 if (op >= 0x71 && op <= 0x75) { 26474 n = stack.pop(); 26475 if (!isNaN(n)) { 26476 stackDelta = -n * 2; 26477 } 26478 } 26479 while (stackDelta < 0 && stack.length > 0) { 26480 stack.pop(); 26481 stackDelta++; 26482 } 26483 while (stackDelta > 0) { 26484 stack.push(NaN); 26485 stackDelta--; 26486 } 26487 } 26488 } 26489 ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions; 26490 const content = [data]; 26491 if (i > data.length) { 26492 content.push(new Uint8Array(i - data.length)); 26493 } 26494 if (lastDeff > lastEndf) { 26495 warn("TT: complementing a missing function tail"); 26496 content.push(new Uint8Array([0x22, 0x2d])); 26497 } 26498 foldTTTable(table, content); 26499 } 26500 function checkInvalidFunctions(ttContext, maxFunctionDefs) { 26501 if (ttContext.tooComplexToFollowFunctions) { 26502 return; 26503 } 26504 if (ttContext.functionsDefined.length > maxFunctionDefs) { 26505 warn("TT: more functions defined than expected"); 26506 ttContext.hintsValid = false; 26507 return; 26508 } 26509 for (let j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) { 26510 if (j > maxFunctionDefs) { 26511 warn("TT: invalid function id: " + j); 26512 ttContext.hintsValid = false; 26513 return; 26514 } 26515 if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) { 26516 warn("TT: undefined function: " + j); 26517 ttContext.hintsValid = false;
vendor: 55,489 bytes, lines 26518-28015
26518 return; 26519 } 26520 } 26521 } 26522 function foldTTTable(table, content) { 26523 if (content.length > 1) { 26524 let newLength = 0; 26525 let j, jj; 26526 for (j = 0, jj = content.length; j < jj; j++) { 26527 newLength += content[j].length; 26528 } 26529 newLength = newLength + 3 & ~3; 26530 const result = new Uint8Array(newLength); 26531 let pos = 0; 26532 for (j = 0, jj = content.length; j < jj; j++) { 26533 result.set(content[j], pos); 26534 pos += content[j].length; 26535 } 26536 table.data = result; 26537 table.length = newLength; 26538 } 26539 } 26540 function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) { 26541 const ttContext = { 26542 functionsDefined: [], 26543 functionsUsed: [], 26544 functionsStackDeltas: [], 26545 tooComplexToFollowFunctions: false, 26546 hintsValid: true 26547 }; 26548 if (fpgm) { 26549 sanitizeTTProgram(fpgm, ttContext); 26550 } 26551 if (prep) { 26552 sanitizeTTProgram(prep, ttContext); 26553 } 26554 if (fpgm) { 26555 checkInvalidFunctions(ttContext, maxFunctionDefs); 26556 } 26557 if (cvt && cvt.length & 1) { 26558 const cvtData = new Uint8Array(cvt.length + 1); 26559 cvtData.set(cvt.data); 26560 cvt.data = cvtData; 26561 } 26562 return ttContext.hintsValid; 26563 } 26564 font = new Stream(new Uint8Array(font.getBytes())); 26565 let header, tables; 26566 if (isTrueTypeCollectionFile(font)) { 26567 const ttcData = readTrueTypeCollectionData(font, this.name); 26568 header = ttcData.header; 26569 tables = ttcData.tables; 26570 } else { 26571 header = readOpenTypeHeader(font); 26572 tables = readTables(font, header.numTables); 26573 } 26574 let cff, cffFile; 26575 const isTrueType = !tables["CFF "]; 26576 if (!isTrueType) { 26577 const isComposite = properties.composite && (properties.cidToGidMap?.length > 0 || !(properties.cMap instanceof IdentityCMap)); 26578 if (header.version === "OTTO" && !isComposite || !tables.head || !tables.hhea || !tables.maxp || !tables.post) { 26579 cffFile = new Stream(tables["CFF "].data); 26580 cff = new CFFFont(cffFile, properties); 26581 return this.convert(name, cff, properties); 26582 } 26583 delete tables.glyf; 26584 delete tables.loca; 26585 delete tables.fpgm; 26586 delete tables.prep; 26587 delete tables["cvt "]; 26588 this.isOpenType = true; 26589 } else { 26590 if (!tables.loca) { 26591 throw new FormatError('Required "loca" table is not found'); 26592 } 26593 if (!tables.glyf) { 26594 warn('Required "glyf" table is not found -- trying to recover.'); 26595 tables.glyf = { 26596 tag: "glyf", 26597 data: new Uint8Array(0) 26598 }; 26599 } 26600 this.isOpenType = false; 26601 } 26602 if (!tables.maxp) { 26603 throw new FormatError('Required "maxp" table is not found'); 26604 } 26605 font.pos = (font.start || 0) + tables.maxp.offset; 26606 let version = font.getInt32(); 26607 const numGlyphs = font.getUint16(); 26608 if (version !== 0x00010000 && version !== 0x00005000) { 26609 if (tables.maxp.length === 6) { 26610 version = 0x0005000; 26611 } else if (tables.maxp.length >= 32) { 26612 version = 0x00010000; 26613 } else { 26614 throw new FormatError(`"maxp" table has a wrong version number`); 26615 } 26616 writeUint32(tables.maxp.data, 0, version); 26617 } 26618 if (properties.scaleFactors?.length === numGlyphs && isTrueType) { 26619 const { 26620 scaleFactors 26621 } = properties; 26622 const isGlyphLocationsLong = int16(tables.head.data[50], tables.head.data[51]); 26623 const glyphs = new GlyfTable({ 26624 glyfTable: tables.glyf.data, 26625 isGlyphLocationsLong, 26626 locaTable: tables.loca.data, 26627 numGlyphs 26628 }); 26629 glyphs.scale(scaleFactors); 26630 const { 26631 glyf, 26632 loca, 26633 isLocationLong 26634 } = glyphs.write(); 26635 tables.glyf.data = glyf; 26636 tables.loca.data = loca; 26637 if (isLocationLong !== !!isGlyphLocationsLong) { 26638 tables.head.data[50] = 0; 26639 tables.head.data[51] = isLocationLong ? 1 : 0; 26640 } 26641 const metrics = tables.hmtx.data; 26642 for (let i = 0; i < numGlyphs; i++) { 26643 const j = 4 * i; 26644 const advanceWidth = Math.round(scaleFactors[i] * int16(metrics[j], metrics[j + 1])); 26645 metrics[j] = advanceWidth >> 8 & 0xff; 26646 metrics[j + 1] = advanceWidth & 0xff; 26647 const lsb = Math.round(scaleFactors[i] * signedInt16(metrics[j + 2], metrics[j + 3])); 26648 writeSignedInt16(metrics, j + 2, lsb); 26649 } 26650 } 26651 let numGlyphsOut = numGlyphs + 1; 26652 let dupFirstEntry = true; 26653 if (numGlyphsOut > 0xffff) { 26654 dupFirstEntry = false; 26655 numGlyphsOut = numGlyphs; 26656 warn("Not enough space in glyfs to duplicate first glyph."); 26657 } 26658 let maxFunctionDefs = 0; 26659 let maxSizeOfInstructions = 0; 26660 if (version >= 0x00010000 && tables.maxp.length >= 32) { 26661 font.pos += 8; 26662 const maxZones = font.getUint16(); 26663 if (maxZones > 2) { 26664 tables.maxp.data[14] = 0; 26665 tables.maxp.data[15] = 2; 26666 } 26667 font.pos += 4; 26668 maxFunctionDefs = font.getUint16(); 26669 font.pos += 4; 26670 maxSizeOfInstructions = font.getUint16(); 26671 } 26672 tables.maxp.data[4] = numGlyphsOut >> 8; 26673 tables.maxp.data[5] = numGlyphsOut & 255; 26674 const hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep, tables["cvt "], maxFunctionDefs); 26675 if (!hintsValid) { 26676 delete tables.fpgm; 26677 delete tables.prep; 26678 delete tables["cvt "]; 26679 } 26680 sanitizeMetrics(font, tables.hhea, tables.hmtx, tables.head, numGlyphsOut, dupFirstEntry); 26681 if (!tables.head) { 26682 throw new FormatError('Required "head" table is not found'); 26683 } 26684 sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0); 26685 let missingGlyphs = Object.create(null); 26686 if (isTrueType) { 26687 const isGlyphLocationsLong = int16(tables.head.data[50], tables.head.data[51]); 26688 const glyphsInfo = sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions); 26689 missingGlyphs = glyphsInfo.missingGlyphs; 26690 if (version >= 0x00010000 && tables.maxp.length >= 32) { 26691 tables.maxp.data[26] = glyphsInfo.maxSizeOfInstructions >> 8; 26692 tables.maxp.data[27] = glyphsInfo.maxSizeOfInstructions & 255; 26693 } 26694 } 26695 if (!tables.hhea) { 26696 throw new FormatError('Required "hhea" table is not found'); 26697 } 26698 if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) { 26699 tables.hhea.data[10] = 0xff; 26700 tables.hhea.data[11] = 0xff; 26701 } 26702 const metricsOverride = { 26703 unitsPerEm: int16(tables.head.data[18], tables.head.data[19]), 26704 yMax: signedInt16(tables.head.data[42], tables.head.data[43]), 26705 yMin: signedInt16(tables.head.data[38], tables.head.data[39]), 26706 ascent: signedInt16(tables.hhea.data[4], tables.hhea.data[5]), 26707 descent: signedInt16(tables.hhea.data[6], tables.hhea.data[7]), 26708 lineGap: signedInt16(tables.hhea.data[8], tables.hhea.data[9]) 26709 }; 26710 this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm; 26711 this.descent = metricsOverride.descent / metricsOverride.unitsPerEm; 26712 this.lineGap = metricsOverride.lineGap / metricsOverride.unitsPerEm; 26713 if (this.cssFontInfo?.lineHeight) { 26714 this.lineHeight = this.cssFontInfo.metrics.lineHeight; 26715 this.lineGap = this.cssFontInfo.metrics.lineGap; 26716 } else { 26717 this.lineHeight = this.ascent - this.descent + this.lineGap; 26718 } 26719 if (tables.post) { 26720 readPostScriptTable(tables.post, properties, numGlyphs); 26721 } 26722 tables.post = { 26723 tag: "post", 26724 data: createPostTable(properties) 26725 }; 26726 const charCodeToGlyphId = Object.create(null); 26727 function hasGlyph(glyphId) { 26728 return !missingGlyphs[glyphId]; 26729 } 26730 if (properties.composite) { 26731 const cidToGidMap = properties.cidToGidMap || []; 26732 const isCidToGidMapEmpty = cidToGidMap.length === 0; 26733 properties.cMap.forEach(function (charCode, cid) { 26734 if (typeof cid === "string") { 26735 cid = convertCidString(charCode, cid, true); 26736 } 26737 if (cid > 0xffff) { 26738 throw new FormatError("Max size of CID is 65,535"); 26739 } 26740 let glyphId = -1; 26741 if (isCidToGidMapEmpty) { 26742 glyphId = cid; 26743 } else if (cidToGidMap[cid] !== undefined) { 26744 glyphId = cidToGidMap[cid]; 26745 } 26746 if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId)) { 26747 charCodeToGlyphId[charCode] = glyphId; 26748 } 26749 }); 26750 } else { 26751 const cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont, properties.hasEncoding); 26752 const cmapPlatformId = cmapTable.platformId; 26753 const cmapEncodingId = cmapTable.encodingId; 26754 const cmapMappings = cmapTable.mappings; 26755 let baseEncoding = [], 26756 forcePostTable = false; 26757 if (properties.hasEncoding && (properties.baseEncodingName === "MacRomanEncoding" || properties.baseEncodingName === "WinAnsiEncoding")) { 26758 baseEncoding = getEncoding(properties.baseEncodingName); 26759 } 26760 if (properties.hasEncoding && !this.isSymbolicFont && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0)) { 26761 const glyphsUnicodeMap = getGlyphsUnicode(); 26762 for (let charCode = 0; charCode < 256; charCode++) { 26763 let glyphName; 26764 if (this.differences[charCode] !== undefined) { 26765 glyphName = this.differences[charCode]; 26766 } else if (baseEncoding.length && baseEncoding[charCode] !== "") { 26767 glyphName = baseEncoding[charCode]; 26768 } else { 26769 glyphName = StandardEncoding[charCode]; 26770 } 26771 if (!glyphName) { 26772 continue; 26773 } 26774 const standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap); 26775 let unicodeOrCharCode; 26776 if (cmapPlatformId === 3 && cmapEncodingId === 1) { 26777 unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName]; 26778 } else if (cmapPlatformId === 1 && cmapEncodingId === 0) { 26779 unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName); 26780 } 26781 if (unicodeOrCharCode === undefined) { 26782 if (!properties.glyphNames && properties.hasIncludedToUnicodeMap && !(this.toUnicode instanceof IdentityToUnicodeMap)) { 26783 const unicode = this.toUnicode.get(charCode); 26784 if (unicode) { 26785 unicodeOrCharCode = unicode.codePointAt(0); 26786 } 26787 } 26788 if (unicodeOrCharCode === undefined) { 26789 continue; 26790 } 26791 } 26792 for (const mapping of cmapMappings) { 26793 if (mapping.charCode !== unicodeOrCharCode) { 26794 continue; 26795 } 26796 charCodeToGlyphId[charCode] = mapping.glyphId; 26797 break; 26798 } 26799 } 26800 } else if (cmapPlatformId === 0) { 26801 for (const mapping of cmapMappings) { 26802 charCodeToGlyphId[mapping.charCode] = mapping.glyphId; 26803 } 26804 forcePostTable = true; 26805 } else if (cmapPlatformId === 3 && cmapEncodingId === 0) { 26806 for (const mapping of cmapMappings) { 26807 let charCode = mapping.charCode; 26808 if (charCode >= 0xf000 && charCode <= 0xf0ff) { 26809 charCode &= 0xff; 26810 } 26811 charCodeToGlyphId[charCode] = mapping.glyphId; 26812 } 26813 } else { 26814 for (const mapping of cmapMappings) { 26815 charCodeToGlyphId[mapping.charCode] = mapping.glyphId; 26816 } 26817 } 26818 if (properties.glyphNames && (baseEncoding.length || this.differences.length)) { 26819 for (let i = 0; i < 256; ++i) { 26820 if (!forcePostTable && charCodeToGlyphId[i] !== undefined) { 26821 continue; 26822 } 26823 const glyphName = this.differences[i] || baseEncoding[i]; 26824 if (!glyphName) { 26825 continue; 26826 } 26827 const glyphId = properties.glyphNames.indexOf(glyphName); 26828 if (glyphId > 0 && hasGlyph(glyphId)) { 26829 charCodeToGlyphId[i] = glyphId; 26830 } 26831 } 26832 } 26833 } 26834 if (charCodeToGlyphId.length === 0) { 26835 charCodeToGlyphId[0] = 0; 26836 } 26837 let glyphZeroId = numGlyphsOut - 1; 26838 if (!dupFirstEntry) { 26839 glyphZeroId = 0; 26840 } 26841 if (!properties.cssFontInfo) { 26842 const newMapping = adjustMapping(charCodeToGlyphId, hasGlyph, glyphZeroId, this.toUnicode); 26843 this.toFontChar = newMapping.toFontChar; 26844 tables.cmap = { 26845 tag: "cmap", 26846 data: createCmapTable(newMapping.charCodeToGlyphId, newMapping.toUnicodeExtraMap, numGlyphsOut) 26847 }; 26848 if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"], font)) { 26849 tables["OS/2"] = { 26850 tag: "OS/2", 26851 data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride) 26852 }; 26853 } 26854 } 26855 if (!isTrueType) { 26856 try { 26857 cffFile = new Stream(tables["CFF "].data); 26858 const parser = new CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED); 26859 cff = parser.parse(); 26860 cff.duplicateFirstGlyph(); 26861 const compiler = new CFFCompiler(cff); 26862 tables["CFF "].data = compiler.compile(); 26863 } catch { 26864 warn("Failed to compile font " + properties.loadedName); 26865 } 26866 } 26867 if (!tables.name) { 26868 tables.name = { 26869 tag: "name", 26870 data: createNameTable(this.name) 26871 }; 26872 } else { 26873 const [namePrototype, nameRecords] = readNameTable(tables.name); 26874 tables.name.data = createNameTable(name, namePrototype); 26875 this.psName = namePrototype[0][6] || null; 26876 if (!properties.composite) { 26877 adjustTrueTypeToUnicode(properties, this.isSymbolicFont, nameRecords); 26878 } 26879 } 26880 const builder = new OpenTypeFileBuilder(header.version); 26881 for (const tableTag in tables) { 26882 builder.addTable(tableTag, tables[tableTag].data); 26883 } 26884 return builder.toArray(); 26885 } 26886 convert(fontName, font, properties) { 26887 properties.fixedPitch = false; 26888 if (properties.builtInEncoding) { 26889 adjustType1ToUnicode(properties, properties.builtInEncoding); 26890 } 26891 let glyphZeroId = 1; 26892 if (font instanceof CFFFont) { 26893 glyphZeroId = font.numGlyphs - 1; 26894 } 26895 const mapping = font.getGlyphMapping(properties); 26896 let newMapping = null; 26897 let newCharCodeToGlyphId = mapping; 26898 let toUnicodeExtraMap = null; 26899 if (!properties.cssFontInfo) { 26900 newMapping = adjustMapping(mapping, font.hasGlyphId.bind(font), glyphZeroId, this.toUnicode); 26901 this.toFontChar = newMapping.toFontChar; 26902 newCharCodeToGlyphId = newMapping.charCodeToGlyphId; 26903 toUnicodeExtraMap = newMapping.toUnicodeExtraMap; 26904 } 26905 const numGlyphs = font.numGlyphs; 26906 function getCharCodes(charCodeToGlyphId, glyphId) { 26907 let charCodes = null; 26908 for (const charCode in charCodeToGlyphId) { 26909 if (glyphId === charCodeToGlyphId[charCode]) { 26910 (charCodes ||= []).push(charCode | 0); 26911 } 26912 } 26913 return charCodes; 26914 } 26915 function createCharCode(charCodeToGlyphId, glyphId) { 26916 for (const charCode in charCodeToGlyphId) { 26917 if (glyphId === charCodeToGlyphId[charCode]) { 26918 return charCode | 0; 26919 } 26920 } 26921 newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId; 26922 return newMapping.nextAvailableFontCharCode++; 26923 } 26924 const seacs = font.seacs; 26925 if (newMapping && SEAC_ANALYSIS_ENABLED && seacs?.length) { 26926 const matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX; 26927 const charset = font.getCharset(); 26928 const seacMap = Object.create(null); 26929 for (let glyphId in seacs) { 26930 glyphId |= 0; 26931 const seac = seacs[glyphId]; 26932 const baseGlyphName = StandardEncoding[seac[2]]; 26933 const accentGlyphName = StandardEncoding[seac[3]]; 26934 const baseGlyphId = charset.indexOf(baseGlyphName); 26935 const accentGlyphId = charset.indexOf(accentGlyphName); 26936 if (baseGlyphId < 0 || accentGlyphId < 0) { 26937 continue; 26938 } 26939 const accentOffset = { 26940 x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4], 26941 y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5] 26942 }; 26943 const charCodes = getCharCodes(mapping, glyphId); 26944 if (!charCodes) { 26945 continue; 26946 } 26947 for (const charCode of charCodes) { 26948 const charCodeToGlyphId = newMapping.charCodeToGlyphId; 26949 const baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId); 26950 const accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId); 26951 seacMap[charCode] = { 26952 baseFontCharCode, 26953 accentFontCharCode, 26954 accentOffset 26955 }; 26956 } 26957 } 26958 properties.seacMap = seacMap; 26959 } 26960 const unitsPerEm = properties.fontMatrix ? 1 / Math.max(...properties.fontMatrix.slice(0, 4).map(Math.abs)) : 1000; 26961 const builder = new OpenTypeFileBuilder("\x4F\x54\x54\x4F"); 26962 builder.addTable("CFF ", font.data); 26963 builder.addTable("OS/2", createOS2Table(properties, newCharCodeToGlyphId)); 26964 builder.addTable("cmap", createCmapTable(newCharCodeToGlyphId, toUnicodeExtraMap, numGlyphs)); 26965 builder.addTable("head", "\x00\x01\x00\x00" + "\x00\x00\x10\x00" + "\x00\x00\x00\x00" + "\x5F\x0F\x3C\xF5" + "\x00\x00" + safeString16(unitsPerEm) + "\x00\x00\x00\x00\x9e\x0b\x7e\x27" + "\x00\x00\x00\x00\x9e\x0b\x7e\x27" + "\x00\x00" + safeString16(properties.descent) + "\x0F\xFF" + safeString16(properties.ascent) + string16(properties.italicAngle ? 2 : 0) + "\x00\x11" + "\x00\x00" + "\x00\x00" + "\x00\x00"); 26966 builder.addTable("hhea", "\x00\x01\x00\x00" + safeString16(properties.ascent) + safeString16(properties.descent) + "\x00\x00" + "\xFF\xFF" + "\x00\x00" + "\x00\x00" + "\x00\x00" + safeString16(properties.capHeight) + safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x00\x00" + string16(numGlyphs)); 26967 builder.addTable("hmtx", function fontFieldsHmtx() { 26968 const charstrings = font.charstrings; 26969 const cffWidths = font.cff ? font.cff.widths : null; 26970 let hmtx = "\x00\x00\x00\x00"; 26971 for (let i = 1, ii = numGlyphs; i < ii; i++) { 26972 let width = 0; 26973 if (charstrings) { 26974 const charstring = charstrings[i - 1]; 26975 width = "width" in charstring ? charstring.width : 0; 26976 } else if (cffWidths) { 26977 width = Math.ceil(cffWidths[i] || 0); 26978 } 26979 hmtx += string16(width) + string16(0); 26980 } 26981 return hmtx; 26982 }()); 26983 builder.addTable("maxp", "\x00\x00\x50\x00" + string16(numGlyphs)); 26984 builder.addTable("name", createNameTable(fontName)); 26985 builder.addTable("post", createPostTable(properties)); 26986 return builder.toArray(); 26987 } 26988 get _spaceWidth() { 26989 const possibleSpaceReplacements = ["space", "minus", "one", "i", "I"]; 26990 let width; 26991 for (const glyphName of possibleSpaceReplacements) { 26992 if (glyphName in this.widths) { 26993 width = this.widths[glyphName]; 26994 break; 26995 } 26996 const glyphsUnicodeMap = getGlyphsUnicode(); 26997 const glyphUnicode = glyphsUnicodeMap[glyphName]; 26998 let charcode = 0; 26999 if (this.composite && this.cMap.contains(glyphUnicode)) { 27000 charcode = this.cMap.lookup(glyphUnicode); 27001 if (typeof charcode === "string") { 27002 charcode = convertCidString(glyphUnicode, charcode); 27003 } 27004 } 27005 if (!charcode && this.toUnicode) { 27006 charcode = this.toUnicode.charCodeOf(glyphUnicode); 27007 } 27008 if (charcode <= 0) { 27009 charcode = glyphUnicode; 27010 } 27011 width = this.widths[charcode]; 27012 if (width) { 27013 break; 27014 } 27015 } 27016 return shadow(this, "_spaceWidth", width || this.defaultWidth); 27017 } 27018 _charToGlyph(charcode, isSpace = false) { 27019 let glyph = this._glyphCache[charcode]; 27020 if (glyph?.isSpace === isSpace) { 27021 return glyph; 27022 } 27023 let fontCharCode, width, operatorListId; 27024 let widthCode = charcode; 27025 if (this.cMap?.contains(charcode)) { 27026 widthCode = this.cMap.lookup(charcode); 27027 if (typeof widthCode === "string") { 27028 widthCode = convertCidString(charcode, widthCode); 27029 } 27030 } 27031 width = this.widths[widthCode]; 27032 if (typeof width !== "number") { 27033 width = this.defaultWidth; 27034 } 27035 const vmetric = this.vmetrics?.[widthCode]; 27036 let unicode = this.toUnicode.get(charcode) || charcode; 27037 if (typeof unicode === "number") { 27038 unicode = String.fromCharCode(unicode); 27039 } 27040 let isInFont = this.toFontChar[charcode] !== undefined; 27041 fontCharCode = this.toFontChar[charcode] || charcode; 27042 if (this.missingFile) { 27043 const glyphName = this.differences[charcode] || this.defaultEncoding[charcode]; 27044 if ((glyphName === ".notdef" || glyphName === "") && this.type === "Type1") { 27045 fontCharCode = 0x20; 27046 if (glyphName === "") { 27047 width ||= this._spaceWidth; 27048 unicode = String.fromCharCode(fontCharCode); 27049 } 27050 } 27051 fontCharCode = mapSpecialUnicodeValues(fontCharCode); 27052 } 27053 if (this.isType3Font) { 27054 operatorListId = fontCharCode; 27055 } 27056 let accent = null; 27057 if (this.seacMap?.[charcode]) { 27058 isInFont = true; 27059 const seac = this.seacMap[charcode]; 27060 fontCharCode = seac.baseFontCharCode; 27061 accent = { 27062 fontChar: String.fromCodePoint(seac.accentFontCharCode), 27063 offset: seac.accentOffset 27064 }; 27065 } 27066 let fontChar = ""; 27067 if (typeof fontCharCode === "number") { 27068 if (fontCharCode <= 0x10ffff) { 27069 fontChar = String.fromCodePoint(fontCharCode); 27070 } else { 27071 warn(`charToGlyph - invalid fontCharCode: ${fontCharCode}`); 27072 } 27073 } 27074 if (this.missingFile && this.vertical && fontChar.length === 1) { 27075 const vertical = getVerticalPresentationForm()[fontChar.charCodeAt(0)]; 27076 if (vertical) { 27077 fontChar = unicode = String.fromCharCode(vertical); 27078 } 27079 } 27080 glyph = new fonts_Glyph(charcode, fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont); 27081 return this._glyphCache[charcode] = glyph; 27082 } 27083 charsToGlyphs(chars) { 27084 let glyphs = this._charsCache[chars]; 27085 if (glyphs) { 27086 return glyphs; 27087 } 27088 glyphs = []; 27089 if (this.cMap) { 27090 const c = Object.create(null), 27091 ii = chars.length; 27092 let i = 0; 27093 while (i < ii) { 27094 this.cMap.readCharCode(chars, i, c); 27095 const { 27096 charcode, 27097 length 27098 } = c; 27099 i += length; 27100 const glyph = this._charToGlyph(charcode, length === 1 && chars.charCodeAt(i - 1) === 0x20); 27101 glyphs.push(glyph); 27102 } 27103 } else { 27104 for (let i = 0, ii = chars.length; i < ii; ++i) { 27105 const charcode = chars.charCodeAt(i); 27106 const glyph = this._charToGlyph(charcode, charcode === 0x20); 27107 glyphs.push(glyph); 27108 } 27109 } 27110 return this._charsCache[chars] = glyphs; 27111 } 27112 getCharPositions(chars) { 27113 const positions = []; 27114 if (this.cMap) { 27115 const c = Object.create(null); 27116 let i = 0; 27117 while (i < chars.length) { 27118 this.cMap.readCharCode(chars, i, c); 27119 const length = c.length; 27120 positions.push([i, i + length]); 27121 i += length; 27122 } 27123 } else { 27124 for (let i = 0, ii = chars.length; i < ii; ++i) { 27125 positions.push([i, i + 1]); 27126 } 27127 } 27128 return positions; 27129 } 27130 get glyphCacheValues() { 27131 return Object.values(this._glyphCache); 27132 } 27133 encodeString(str) { 27134 const buffers = []; 27135 const currentBuf = []; 27136 const hasCurrentBufErrors = () => buffers.length % 2 === 1; 27137 const getCharCode = this.toUnicode instanceof IdentityToUnicodeMap ? unicode => this.toUnicode.charCodeOf(unicode) : unicode => this.toUnicode.charCodeOf(String.fromCodePoint(unicode)); 27138 for (let i = 0, ii = str.length; i < ii; i++) { 27139 const unicode = str.codePointAt(i); 27140 if (unicode > 0xd7ff && (unicode < 0xe000 || unicode > 0xfffd)) { 27141 i++; 27142 } 27143 if (this.toUnicode) { 27144 const charCode = getCharCode(unicode); 27145 if (charCode !== -1) { 27146 if (hasCurrentBufErrors()) { 27147 buffers.push(currentBuf.join("")); 27148 currentBuf.length = 0; 27149 } 27150 const charCodeLength = this.cMap ? this.cMap.getCharCodeLength(charCode) : 1; 27151 for (let j = charCodeLength - 1; j >= 0; j--) { 27152 currentBuf.push(String.fromCharCode(charCode >> 8 * j & 0xff)); 27153 } 27154 continue; 27155 } 27156 } 27157 if (!hasCurrentBufErrors()) { 27158 buffers.push(currentBuf.join("")); 27159 currentBuf.length = 0; 27160 } 27161 currentBuf.push(String.fromCodePoint(unicode)); 27162 } 27163 buffers.push(currentBuf.join("")); 27164 return buffers; 27165 } 27166} 27167class ErrorFont { 27168 constructor(error) { 27169 this.error = error; 27170 this.loadedName = "g_font_error"; 27171 this.missingFile = true; 27172 } 27173 charsToGlyphs() { 27174 return []; 27175 } 27176 encodeString(chars) { 27177 return [chars]; 27178 } 27179 exportData() { 27180 return { 27181 error: this.error 27182 }; 27183 } 27184} 27185 27186;// ./src/core/pattern.js 27187 27188 27189 27190 27191const ShadingType = { 27192 FUNCTION_BASED: 1, 27193 AXIAL: 2, 27194 RADIAL: 3, 27195 FREE_FORM_MESH: 4, 27196 LATTICE_FORM_MESH: 5, 27197 COONS_PATCH_MESH: 6, 27198 TENSOR_PATCH_MESH: 7 27199}; 27200class Pattern { 27201 constructor() { 27202 unreachable("Cannot initialize Pattern."); 27203 } 27204 static parseShading(shading, xref, res, pdfFunctionFactory, globalColorSpaceCache, localColorSpaceCache) { 27205 const dict = shading instanceof BaseStream ? shading.dict : shading; 27206 const type = dict.get("ShadingType"); 27207 try { 27208 switch (type) { 27209 case ShadingType.AXIAL: 27210 case ShadingType.RADIAL: 27211 return new RadialAxialShading(dict, xref, res, pdfFunctionFactory, globalColorSpaceCache, localColorSpaceCache); 27212 case ShadingType.FREE_FORM_MESH: 27213 case ShadingType.LATTICE_FORM_MESH: 27214 case ShadingType.COONS_PATCH_MESH: 27215 case ShadingType.TENSOR_PATCH_MESH: 27216 return new MeshShading(shading, xref, res, pdfFunctionFactory, globalColorSpaceCache, localColorSpaceCache); 27217 default: 27218 throw new FormatError("Unsupported ShadingType: " + type); 27219 } 27220 } catch (ex) { 27221 if (ex instanceof MissingDataException) { 27222 throw ex; 27223 } 27224 warn(ex); 27225 return new DummyShading(); 27226 } 27227 } 27228} 27229class BaseShading { 27230 static SMALL_NUMBER = 1e-6; 27231 getIR() { 27232 unreachable("Abstract method `getIR` called."); 27233 } 27234} 27235class RadialAxialShading extends BaseShading { 27236 constructor(dict, xref, resources, pdfFunctionFactory, globalColorSpaceCache, localColorSpaceCache) { 27237 super(); 27238 this.shadingType = dict.get("ShadingType"); 27239 let coordsLen = 0; 27240 if (this.shadingType === ShadingType.AXIAL) { 27241 coordsLen = 4; 27242 } else if (this.shadingType === ShadingType.RADIAL) { 27243 coordsLen = 6; 27244 } 27245 this.coordsArr = dict.getArray("Coords"); 27246 if (!isNumberArray(this.coordsArr, coordsLen)) { 27247 throw new FormatError("RadialAxialShading: Invalid /Coords array."); 27248 } 27249 const cs = ColorSpaceUtils.parse({ 27250 cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"), 27251 xref, 27252 resources, 27253 pdfFunctionFactory, 27254 globalColorSpaceCache, 27255 localColorSpaceCache 27256 }); 27257 this.bbox = lookupNormalRect(dict.getArray("BBox"), null); 27258 let t0 = 0.0, 27259 t1 = 1.0; 27260 const domainArr = dict.getArray("Domain"); 27261 if (isNumberArray(domainArr, 2)) { 27262 [t0, t1] = domainArr; 27263 } 27264 let extendStart = false, 27265 extendEnd = false; 27266 const extendArr = dict.getArray("Extend"); 27267 if (isBooleanArray(extendArr, 2)) { 27268 [extendStart, extendEnd] = extendArr; 27269 } 27270 if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) { 27271 const [x1, y1, r1, x2, y2, r2] = this.coordsArr; 27272 const distance = Math.hypot(x1 - x2, y1 - y2); 27273 if (r1 <= r2 + distance && r2 <= r1 + distance) { 27274 warn("Unsupported radial gradient."); 27275 } 27276 } 27277 this.extendStart = extendStart; 27278 this.extendEnd = extendEnd; 27279 const fnObj = dict.getRaw("Function"); 27280 const fn = pdfFunctionFactory.create(fnObj, true); 27281 const NUMBER_OF_SAMPLES = 840; 27282 const step = (t1 - t0) / NUMBER_OF_SAMPLES; 27283 const colorStops = this.colorStops = []; 27284 if (t0 >= t1 || step <= 0) { 27285 info("Bad shading domain."); 27286 return; 27287 } 27288 const color = new Float32Array(cs.numComps), 27289 ratio = new Float32Array(1); 27290 let iBase = 0; 27291 ratio[0] = t0; 27292 fn(ratio, 0, color, 0); 27293 const rgbBuffer = new Uint8ClampedArray(3); 27294 cs.getRgb(color, 0, rgbBuffer); 27295 let [rBase, gBase, bBase] = rgbBuffer; 27296 colorStops.push([0, Util.makeHexColor(rBase, gBase, bBase)]); 27297 let iPrev = 1; 27298 ratio[0] = t0 + step; 27299 fn(ratio, 0, color, 0); 27300 cs.getRgb(color, 0, rgbBuffer); 27301 let [rPrev, gPrev, bPrev] = rgbBuffer; 27302 let maxSlopeR = rPrev - rBase + 1; 27303 let maxSlopeG = gPrev - gBase + 1; 27304 let maxSlopeB = bPrev - bBase + 1; 27305 let minSlopeR = rPrev - rBase - 1; 27306 let minSlopeG = gPrev - gBase - 1; 27307 let minSlopeB = bPrev - bBase - 1; 27308 for (let i = 2; i < NUMBER_OF_SAMPLES; i++) { 27309 ratio[0] = t0 + i * step; 27310 fn(ratio, 0, color, 0); 27311 cs.getRgb(color, 0, rgbBuffer); 27312 const [r, g, b] = rgbBuffer; 27313 const run = i - iBase; 27314 maxSlopeR = Math.min(maxSlopeR, (r - rBase + 1) / run); 27315 maxSlopeG = Math.min(maxSlopeG, (g - gBase + 1) / run); 27316 maxSlopeB = Math.min(maxSlopeB, (b - bBase + 1) / run); 27317 minSlopeR = Math.max(minSlopeR, (r - rBase - 1) / run); 27318 minSlopeG = Math.max(minSlopeG, (g - gBase - 1) / run); 27319 minSlopeB = Math.max(minSlopeB, (b - bBase - 1) / run); 27320 const slopesExist = minSlopeR <= maxSlopeR && minSlopeG <= maxSlopeG && minSlopeB <= maxSlopeB; 27321 if (!slopesExist) { 27322 const cssColor = Util.makeHexColor(rPrev, gPrev, bPrev); 27323 colorStops.push([iPrev / NUMBER_OF_SAMPLES, cssColor]); 27324 maxSlopeR = r - rPrev + 1; 27325 maxSlopeG = g - gPrev + 1; 27326 maxSlopeB = b - bPrev + 1; 27327 minSlopeR = r - rPrev - 1; 27328 minSlopeG = g - gPrev - 1; 27329 minSlopeB = b - bPrev - 1; 27330 iBase = iPrev; 27331 rBase = rPrev; 27332 gBase = gPrev; 27333 bBase = bPrev; 27334 } 27335 iPrev = i; 27336 rPrev = r; 27337 gPrev = g; 27338 bPrev = b; 27339 } 27340 colorStops.push([1, Util.makeHexColor(rPrev, gPrev, bPrev)]); 27341 let background = "transparent"; 27342 if (dict.has("Background")) { 27343 background = cs.getRgbHex(dict.get("Background"), 0); 27344 } 27345 if (!extendStart) { 27346 colorStops.unshift([0, background]); 27347 colorStops[1][0] += BaseShading.SMALL_NUMBER; 27348 } 27349 if (!extendEnd) { 27350 colorStops.at(-1)[0] -= BaseShading.SMALL_NUMBER; 27351 colorStops.push([1, background]); 27352 } 27353 this.colorStops = colorStops; 27354 } 27355 getIR() { 27356 const { 27357 coordsArr, 27358 shadingType 27359 } = this; 27360 let type, p0, p1, r0, r1; 27361 if (shadingType === ShadingType.AXIAL) { 27362 p0 = [coordsArr[0], coordsArr[1]]; 27363 p1 = [coordsArr[2], coordsArr[3]]; 27364 r0 = null; 27365 r1 = null; 27366 type = "axial"; 27367 } else if (shadingType === ShadingType.RADIAL) { 27368 p0 = [coordsArr[0], coordsArr[1]]; 27369 p1 = [coordsArr[3], coordsArr[4]]; 27370 r0 = coordsArr[2]; 27371 r1 = coordsArr[5]; 27372 type = "radial"; 27373 } else { 27374 unreachable(`getPattern type unknown: ${shadingType}`); 27375 } 27376 return ["RadialAxial", type, this.bbox, this.colorStops, p0, p1, r0, r1]; 27377 } 27378} 27379class MeshStreamReader { 27380 constructor(stream, context) { 27381 this.stream = stream; 27382 this.context = context; 27383 this.buffer = 0; 27384 this.bufferLength = 0; 27385 const numComps = context.numComps; 27386 this.tmpCompsBuf = new Float32Array(numComps); 27387 const csNumComps = context.colorSpace.numComps; 27388 this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf; 27389 } 27390 get hasData() { 27391 if (this.stream.end) { 27392 return this.stream.pos < this.stream.end; 27393 } 27394 if (this.bufferLength > 0) { 27395 return true; 27396 } 27397 const nextByte = this.stream.getByte(); 27398 if (nextByte < 0) { 27399 return false; 27400 } 27401 this.buffer = nextByte; 27402 this.bufferLength = 8; 27403 return true; 27404 } 27405 readBits(n) { 27406 const { 27407 stream 27408 } = this; 27409 let { 27410 buffer, 27411 bufferLength 27412 } = this; 27413 if (n === 32) { 27414 if (bufferLength === 0) { 27415 return stream.getInt32() >>> 0; 27416 } 27417 buffer = buffer << 24 | stream.getByte() << 16 | stream.getByte() << 8 | stream.getByte(); 27418 const nextByte = stream.getByte(); 27419 this.buffer = nextByte & (1 << bufferLength) - 1; 27420 return (buffer << 8 - bufferLength | (nextByte & 0xff) >> bufferLength) >>> 0; 27421 } 27422 if (n === 8 && bufferLength === 0) { 27423 return stream.getByte(); 27424 } 27425 while (bufferLength < n) { 27426 buffer = buffer << 8 | stream.getByte(); 27427 bufferLength += 8; 27428 } 27429 bufferLength -= n; 27430 this.bufferLength = bufferLength; 27431 this.buffer = buffer & (1 << bufferLength) - 1; 27432 return buffer >> bufferLength; 27433 } 27434 align() { 27435 this.buffer = 0; 27436 this.bufferLength = 0; 27437 } 27438 readFlag() { 27439 return this.readBits(this.context.bitsPerFlag); 27440 } 27441 readCoordinate() { 27442 const { 27443 bitsPerCoordinate, 27444 decode 27445 } = this.context; 27446 const xi = this.readBits(bitsPerCoordinate); 27447 const yi = this.readBits(bitsPerCoordinate); 27448 const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10; 27449 return [xi * scale * (decode[1] - decode[0]) + decode[0], yi * scale * (decode[3] - decode[2]) + decode[2]]; 27450 } 27451 readComponents() { 27452 const { 27453 bitsPerComponent, 27454 colorFn, 27455 colorSpace, 27456 decode, 27457 numComps 27458 } = this.context; 27459 const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10; 27460 const components = this.tmpCompsBuf; 27461 for (let i = 0, j = 4; i < numComps; i++, j += 2) { 27462 const ci = this.readBits(bitsPerComponent); 27463 components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j]; 27464 } 27465 const color = this.tmpCsCompsBuf; 27466 colorFn?.(components, 0, color, 0); 27467 return colorSpace.getRgb(color, 0); 27468 } 27469} 27470let bCache = Object.create(null); 27471function buildB(count) { 27472 const lut = []; 27473 for (let i = 0; i <= count; i++) { 27474 const t = i / count, 27475 t_ = 1 - t; 27476 lut.push(new Float32Array([t_ ** 3, 3 * t * t_ ** 2, 3 * t ** 2 * t_, t ** 3])); 27477 } 27478 return lut; 27479} 27480function getB(count) { 27481 return bCache[count] ||= buildB(count); 27482} 27483function clearPatternCaches() { 27484 bCache = Object.create(null); 27485} 27486class MeshShading extends BaseShading { 27487 static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3; 27488 static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20; 27489 static TRIANGLE_DENSITY = 20; 27490 constructor(stream, xref, resources, pdfFunctionFactory, globalColorSpaceCache, localColorSpaceCache) { 27491 super(); 27492 if (!(stream instanceof BaseStream)) { 27493 throw new FormatError("Mesh data is not a stream"); 27494 } 27495 const dict = stream.dict; 27496 this.shadingType = dict.get("ShadingType"); 27497 this.bbox = lookupNormalRect(dict.getArray("BBox"), null); 27498 const cs = ColorSpaceUtils.parse({ 27499 cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"), 27500 xref, 27501 resources, 27502 pdfFunctionFactory, 27503 globalColorSpaceCache, 27504 localColorSpaceCache 27505 }); 27506 this.background = dict.has("Background") ? cs.getRgb(dict.get("Background"), 0) : null; 27507 const fnObj = dict.getRaw("Function"); 27508 const fn = fnObj ? pdfFunctionFactory.create(fnObj, true) : null; 27509 this.coords = []; 27510 this.colors = []; 27511 this.figures = []; 27512 const decodeContext = { 27513 bitsPerCoordinate: dict.get("BitsPerCoordinate"), 27514 bitsPerComponent: dict.get("BitsPerComponent"), 27515 bitsPerFlag: dict.get("BitsPerFlag"), 27516 decode: dict.getArray("Decode"), 27517 colorFn: fn, 27518 colorSpace: cs, 27519 numComps: fn ? 1 : cs.numComps 27520 }; 27521 const reader = new MeshStreamReader(stream, decodeContext); 27522 let patchMesh = false; 27523 switch (this.shadingType) { 27524 case ShadingType.FREE_FORM_MESH: 27525 this._decodeType4Shading(reader); 27526 break; 27527 case ShadingType.LATTICE_FORM_MESH: 27528 const verticesPerRow = dict.get("VerticesPerRow") | 0; 27529 if (verticesPerRow < 2) { 27530 throw new FormatError("Invalid VerticesPerRow"); 27531 } 27532 this._decodeType5Shading(reader, verticesPerRow); 27533 break; 27534 case ShadingType.COONS_PATCH_MESH: 27535 this._decodeType6Shading(reader); 27536 patchMesh = true; 27537 break; 27538 case ShadingType.TENSOR_PATCH_MESH: 27539 this._decodeType7Shading(reader); 27540 patchMesh = true; 27541 break; 27542 default: 27543 unreachable("Unsupported mesh type."); 27544 break; 27545 } 27546 if (patchMesh) { 27547 this._updateBounds(); 27548 for (let i = 0, ii = this.figures.length; i < ii; i++) { 27549 this._buildFigureFromPatch(i); 27550 } 27551 } 27552 this._updateBounds(); 27553 this._packData(); 27554 } 27555 _decodeType4Shading(reader) { 27556 const coords = this.coords; 27557 const colors = this.colors; 27558 const operators = []; 27559 const ps = []; 27560 let verticesLeft = 0; 27561 while (reader.hasData) { 27562 const f = reader.readFlag(); 27563 const coord = reader.readCoordinate(); 27564 const color = reader.readComponents(); 27565 if (verticesLeft === 0) { 27566 if (!(0 <= f && f <= 2)) { 27567 throw new FormatError("Unknown type4 flag"); 27568 } 27569 switch (f) { 27570 case 0: 27571 verticesLeft = 3; 27572 break; 27573 case 1: 27574 ps.push(ps.at(-2), ps.at(-1)); 27575 verticesLeft = 1; 27576 break; 27577 case 2: 27578 ps.push(ps.at(-3), ps.at(-1)); 27579 verticesLeft = 1; 27580 break; 27581 } 27582 operators.push(f); 27583 } 27584 ps.push(coords.length); 27585 coords.push(coord); 27586 colors.push(color); 27587 verticesLeft--; 27588 reader.align(); 27589 } 27590 this.figures.push({ 27591 type: "triangles", 27592 coords: new Int32Array(ps), 27593 colors: new Int32Array(ps) 27594 }); 27595 } 27596 _decodeType5Shading(reader, verticesPerRow) { 27597 const coords = this.coords; 27598 const colors = this.colors; 27599 const ps = []; 27600 while (reader.hasData) { 27601 const coord = reader.readCoordinate(); 27602 const color = reader.readComponents(); 27603 ps.push(coords.length); 27604 coords.push(coord); 27605 colors.push(color); 27606 } 27607 this.figures.push({ 27608 type: "lattice", 27609 coords: new Int32Array(ps), 27610 colors: new Int32Array(ps), 27611 verticesPerRow 27612 }); 27613 } 27614 _decodeType6Shading(reader) { 27615 const coords = this.coords; 27616 const colors = this.colors; 27617 const ps = new Int32Array(16); 27618 const cs = new Int32Array(4); 27619 while (reader.hasData) { 27620 const f = reader.readFlag(); 27621 if (!(0 <= f && f <= 3)) { 27622 throw new FormatError("Unknown type6 flag"); 27623 } 27624 const pi = coords.length; 27625 for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) { 27626 coords.push(reader.readCoordinate()); 27627 } 27628 const ci = colors.length; 27629 for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) { 27630 colors.push(reader.readComponents()); 27631 } 27632 let tmp1, tmp2, tmp3, tmp4; 27633 switch (f) { 27634 case 0: 27635 ps[12] = pi + 3; 27636 ps[13] = pi + 4; 27637 ps[14] = pi + 5; 27638 ps[15] = pi + 6; 27639 ps[8] = pi + 2; 27640 ps[11] = pi + 7; 27641 ps[4] = pi + 1; 27642 ps[7] = pi + 8; 27643 ps[0] = pi; 27644 ps[1] = pi + 11; 27645 ps[2] = pi + 10; 27646 ps[3] = pi + 9; 27647 cs[2] = ci + 1; 27648 cs[3] = ci + 2; 27649 cs[0] = ci; 27650 cs[1] = ci + 3; 27651 break; 27652 case 1: 27653 tmp1 = ps[12]; 27654 tmp2 = ps[13]; 27655 tmp3 = ps[14]; 27656 tmp4 = ps[15]; 27657 ps[12] = tmp4; 27658 ps[13] = pi + 0; 27659 ps[14] = pi + 1; 27660 ps[15] = pi + 2; 27661 ps[8] = tmp3; 27662 ps[11] = pi + 3; 27663 ps[4] = tmp2; 27664 ps[7] = pi + 4; 27665 ps[0] = tmp1; 27666 ps[1] = pi + 7; 27667 ps[2] = pi + 6; 27668 ps[3] = pi + 5; 27669 tmp1 = cs[2]; 27670 tmp2 = cs[3]; 27671 cs[2] = tmp2; 27672 cs[3] = ci; 27673 cs[0] = tmp1; 27674 cs[1] = ci + 1; 27675 break; 27676 case 2: 27677 tmp1 = ps[15]; 27678 tmp2 = ps[11]; 27679 ps[12] = ps[3]; 27680 ps[13] = pi + 0; 27681 ps[14] = pi + 1; 27682 ps[15] = pi + 2; 27683 ps[8] = ps[7]; 27684 ps[11] = pi + 3; 27685 ps[4] = tmp2; 27686 ps[7] = pi + 4; 27687 ps[0] = tmp1; 27688 ps[1] = pi + 7; 27689 ps[2] = pi + 6; 27690 ps[3] = pi + 5; 27691 tmp1 = cs[3]; 27692 cs[2] = cs[1]; 27693 cs[3] = ci; 27694 cs[0] = tmp1; 27695 cs[1] = ci + 1; 27696 break; 27697 case 3: 27698 ps[12] = ps[0]; 27699 ps[13] = pi + 0; 27700 ps[14] = pi + 1; 27701 ps[15] = pi + 2; 27702 ps[8] = ps[1]; 27703 ps[11] = pi + 3; 27704 ps[4] = ps[2]; 27705 ps[7] = pi + 4; 27706 ps[0] = ps[3]; 27707 ps[1] = pi + 7; 27708 ps[2] = pi + 6; 27709 ps[3] = pi + 5; 27710 cs[2] = cs[0]; 27711 cs[3] = ci; 27712 cs[0] = cs[1]; 27713 cs[1] = ci + 1; 27714 break; 27715 } 27716 ps[5] = coords.length; 27717 coords.push([(-4 * coords[ps[0]][0] - coords[ps[15]][0] + 6 * (coords[ps[4]][0] + coords[ps[1]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9, (-4 * coords[ps[0]][1] - coords[ps[15]][1] + 6 * (coords[ps[4]][1] + coords[ps[1]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9]); 27718 ps[6] = coords.length; 27719 coords.push([(-4 * coords[ps[3]][0] - coords[ps[12]][0] + 6 * (coords[ps[2]][0] + coords[ps[7]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9, (-4 * coords[ps[3]][1] - coords[ps[12]][1] + 6 * (coords[ps[2]][1] + coords[ps[7]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9]); 27720 ps[9] = coords.length; 27721 coords.push([(-4 * coords[ps[12]][0] - coords[ps[3]][0] + 6 * (coords[ps[8]][0] + coords[ps[13]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9, (-4 * coords[ps[12]][1] - coords[ps[3]][1] + 6 * (coords[ps[8]][1] + coords[ps[13]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9]); 27722 ps[10] = coords.length; 27723 coords.push([(-4 * coords[ps[15]][0] - coords[ps[0]][0] + 6 * (coords[ps[11]][0] + coords[ps[14]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9, (-4 * coords[ps[15]][1] - coords[ps[0]][1] + 6 * (coords[ps[11]][1] + coords[ps[14]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9]); 27724 this.figures.push({ 27725 type: "patch", 27726 coords: new Int32Array(ps), 27727 colors: new Int32Array(cs) 27728 }); 27729 } 27730 } 27731 _decodeType7Shading(reader) { 27732 const coords = this.coords; 27733 const colors = this.colors; 27734 const ps = new Int32Array(16); 27735 const cs = new Int32Array(4); 27736 while (reader.hasData) { 27737 const f = reader.readFlag(); 27738 if (!(0 <= f && f <= 3)) { 27739 throw new FormatError("Unknown type7 flag"); 27740 } 27741 const pi = coords.length; 27742 for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) { 27743 coords.push(reader.readCoordinate()); 27744 } 27745 const ci = colors.length; 27746 for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) { 27747 colors.push(reader.readComponents()); 27748 } 27749 let tmp1, tmp2, tmp3, tmp4; 27750 switch (f) { 27751 case 0: 27752 ps[12] = pi + 3; 27753 ps[13] = pi + 4; 27754 ps[14] = pi + 5; 27755 ps[15] = pi + 6; 27756 ps[8] = pi + 2; 27757 ps[9] = pi + 13; 27758 ps[10] = pi + 14; 27759 ps[11] = pi + 7; 27760 ps[4] = pi + 1; 27761 ps[5] = pi + 12; 27762 ps[6] = pi + 15; 27763 ps[7] = pi + 8; 27764 ps[0] = pi; 27765 ps[1] = pi + 11; 27766 ps[2] = pi + 10; 27767 ps[3] = pi + 9; 27768 cs[2] = ci + 1; 27769 cs[3] = ci + 2; 27770 cs[0] = ci; 27771 cs[1] = ci + 3; 27772 break; 27773 case 1: 27774 tmp1 = ps[12]; 27775 tmp2 = ps[13]; 27776 tmp3 = ps[14]; 27777 tmp4 = ps[15]; 27778 ps[12] = tmp4; 27779 ps[13] = pi + 0; 27780 ps[14] = pi + 1; 27781 ps[15] = pi + 2; 27782 ps[8] = tmp3; 27783 ps[9] = pi + 9; 27784 ps[10] = pi + 10; 27785 ps[11] = pi + 3; 27786 ps[4] = tmp2; 27787 ps[5] = pi + 8; 27788 ps[6] = pi + 11; 27789 ps[7] = pi + 4; 27790 ps[0] = tmp1; 27791 ps[1] = pi + 7; 27792 ps[2] = pi + 6; 27793 ps[3] = pi + 5; 27794 tmp1 = cs[2]; 27795 tmp2 = cs[3]; 27796 cs[2] = tmp2; 27797 cs[3] = ci; 27798 cs[0] = tmp1; 27799 cs[1] = ci + 1; 27800 break; 27801 case 2: 27802 tmp1 = ps[15]; 27803 tmp2 = ps[11]; 27804 ps[12] = ps[3]; 27805 ps[13] = pi + 0; 27806 ps[14] = pi + 1; 27807 ps[15] = pi + 2; 27808 ps[8] = ps[7]; 27809 ps[9] = pi + 9; 27810 ps[10] = pi + 10; 27811 ps[11] = pi + 3; 27812 ps[4] = tmp2; 27813 ps[5] = pi + 8; 27814 ps[6] = pi + 11; 27815 ps[7] = pi + 4; 27816 ps[0] = tmp1; 27817 ps[1] = pi + 7; 27818 ps[2] = pi + 6; 27819 ps[3] = pi + 5; 27820 tmp1 = cs[3]; 27821 cs[2] = cs[1]; 27822 cs[3] = ci; 27823 cs[0] = tmp1; 27824 cs[1] = ci + 1; 27825 break; 27826 case 3: 27827 ps[12] = ps[0]; 27828 ps[13] = pi + 0; 27829 ps[14] = pi + 1; 27830 ps[15] = pi + 2; 27831 ps[8] = ps[1]; 27832 ps[9] = pi + 9; 27833 ps[10] = pi + 10; 27834 ps[11] = pi + 3; 27835 ps[4] = ps[2]; 27836 ps[5] = pi + 8; 27837 ps[6] = pi + 11; 27838 ps[7] = pi + 4; 27839 ps[0] = ps[3]; 27840 ps[1] = pi + 7; 27841 ps[2] = pi + 6; 27842 ps[3] = pi + 5; 27843 cs[2] = cs[0]; 27844 cs[3] = ci; 27845 cs[0] = cs[1]; 27846 cs[1] = ci + 1; 27847 break; 27848 } 27849 this.figures.push({ 27850 type: "patch", 27851 coords: new Int32Array(ps), 27852 colors: new Int32Array(cs) 27853 }); 27854 } 27855 } 27856 _buildFigureFromPatch(index) { 27857 const figure = this.figures[index]; 27858 assert(figure.type === "patch", "Unexpected patch mesh figure"); 27859 const coords = this.coords, 27860 colors = this.colors; 27861 const pi = figure.coords; 27862 const ci = figure.colors; 27863 const figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]); 27864 const figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]); 27865 const figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]); 27866 const figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]); 27867 let splitXBy = Math.ceil((figureMaxX - figureMinX) * MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0])); 27868 splitXBy = MathClamp(splitXBy, MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT, MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT); 27869 let splitYBy = Math.ceil((figureMaxY - figureMinY) * MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1])); 27870 splitYBy = MathClamp(splitYBy, MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT, MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT); 27871 const verticesPerRow = splitXBy + 1; 27872 const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow); 27873 const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow); 27874 let k = 0; 27875 const cl = new Uint8Array(3), 27876 cr = new Uint8Array(3); 27877 const c0 = colors[ci[0]], 27878 c1 = colors[ci[1]], 27879 c2 = colors[ci[2]], 27880 c3 = colors[ci[3]]; 27881 const bRow = getB(splitYBy), 27882 bCol = getB(splitXBy); 27883 for (let row = 0; row <= splitYBy; row++) { 27884 cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0; 27885 cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0; 27886 cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0; 27887 cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0; 27888 cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0; 27889 cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0; 27890 for (let col = 0; col <= splitXBy; col++, k++) { 27891 if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) { 27892 continue; 27893 } 27894 let x = 0, 27895 y = 0; 27896 let q = 0; 27897 for (let i = 0; i <= 3; i++) { 27898 for (let j = 0; j <= 3; j++, q++) { 27899 const m = bRow[row][i] * bCol[col][j]; 27900 x += coords[pi[q]][0] * m; 27901 y += coords[pi[q]][1] * m; 27902 } 27903 } 27904 figureCoords[k] = coords.length; 27905 coords.push([x, y]); 27906 figureColors[k] = colors.length; 27907 const newColor = new Uint8Array(3); 27908 newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0; 27909 newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0; 27910 newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0; 27911 colors.push(newColor); 27912 } 27913 } 27914 figureCoords[0] = pi[0]; 27915 figureColors[0] = ci[0]; 27916 figureCoords[splitXBy] = pi[3]; 27917 figureColors[splitXBy] = ci[1]; 27918 figureCoords[verticesPerRow * splitYBy] = pi[12]; 27919 figureColors[verticesPerRow * splitYBy] = ci[2]; 27920 figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15]; 27921 figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3]; 27922 this.figures[index] = { 27923 type: "lattice", 27924 coords: figureCoords, 27925 colors: figureColors, 27926 verticesPerRow 27927 }; 27928 } 27929 _updateBounds() { 27930 let minX = this.coords[0][0], 27931 minY = this.coords[0][1], 27932 maxX = minX, 27933 maxY = minY; 27934 for (let i = 1, ii = this.coords.length; i < ii; i++) { 27935 const x = this.coords[i][0], 27936 y = this.coords[i][1]; 27937 minX = minX > x ? x : minX; 27938 minY = minY > y ? y : minY; 27939 maxX = maxX < x ? x : maxX; 27940 maxY = maxY < y ? y : maxY; 27941 } 27942 this.bounds = [minX, minY, maxX, maxY]; 27943 } 27944 _packData() { 27945 let i, ii, j, jj; 27946 const coords = this.coords; 27947 const coordsPacked = new Float32Array(coords.length * 2); 27948 for (i = 0, j = 0, ii = coords.length; i < ii; i++) { 27949 const xy = coords[i]; 27950 coordsPacked[j++] = xy[0]; 27951 coordsPacked[j++] = xy[1]; 27952 } 27953 this.coords = coordsPacked; 27954 const colors = this.colors; 27955 const colorsPacked = new Uint8Array(colors.length * 3); 27956 for (i = 0, j = 0, ii = colors.length; i < ii; i++) { 27957 const c = colors[i]; 27958 colorsPacked[j++] = c[0]; 27959 colorsPacked[j++] = c[1]; 27960 colorsPacked[j++] = c[2]; 27961 } 27962 this.colors = colorsPacked; 27963 const figures = this.figures; 27964 for (i = 0, ii = figures.length; i < ii; i++) { 27965 const figure = figures[i], 27966 ps = figure.coords, 27967 cs = figure.colors; 27968 for (j = 0, jj = ps.length; j < jj; j++) { 27969 ps[j] *= 2; 27970 cs[j] *= 3; 27971 } 27972 } 27973 } 27974 getIR() { 27975 const { 27976 bounds 27977 } = this; 27978 if (bounds[2] - bounds[0] === 0 || bounds[3] - bounds[1] === 0) { 27979 throw new FormatError(`Invalid MeshShading bounds: [${bounds}].`); 27980 } 27981 return ["Mesh", this.shadingType, this.coords, this.colors, this.figures, bounds, this.bbox, this.background]; 27982 } 27983} 27984class DummyShading extends BaseShading { 27985 getIR() { 27986 return ["Dummy"]; 27987 } 27988} 27989function getTilingPatternIR(operatorList, dict, color) { 27990 const matrix = lookupMatrix(dict.getArray("Matrix"), IDENTITY_MATRIX); 27991 const bbox = lookupNormalRect(dict.getArray("BBox"), null); 27992 if (!bbox || bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) { 27993 throw new FormatError(`Invalid getTilingPatternIR /BBox array.`); 27994 } 27995 const xstep = dict.get("XStep"); 27996 if (typeof xstep !== "number") { 27997 throw new FormatError(`Invalid getTilingPatternIR /XStep value.`); 27998 } 27999 const ystep = dict.get("YStep"); 28000 if (typeof ystep !== "number") { 28001 throw new FormatError(`Invalid getTilingPatternIR /YStep value.`); 28002 } 28003 const paintType = dict.get("PaintType"); 28004 if (!Number.isInteger(paintType)) { 28005 throw new FormatError(`Invalid getTilingPatternIR /PaintType value.`); 28006 } 28007 const tilingType = dict.get("TilingType"); 28008 if (!Number.isInteger(tilingType)) { 28009 throw new FormatError(`Invalid getTilingPatternIR /TilingType value.`); 28010 } 28011 return ["TilingPattern", color, operatorList, matrix, bbox, xstep, ystep, paintType, tilingType]; 28012} 28013 28014;// ./src/core/calibri_factors.js 28015const CalibriBoldFactors = [1.3877, 1, 1, 1, 0.97801, 0.92482, 0.89552, 0.91133, 0.81988, 0.97566, 0.98152, 0.93548, 0.93548, 1.2798, 0.85284, 0.92794, 1, 0.96134, 1.54657, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.82845, 0.82845, 0.85284, 0.85284, 0.85284, 0.75859, 0.92138, 0.83908, 0.7762, 0.73293, 0.87289, 0.73133, 0.7514, 0.81921, 0.87356, 0.95958, 0.59526, 0.75727, 0.69225, 1.04924, 0.9121, 0.86943, 0.79795, 0.88198, 0.77958, 0.70864, 0.81055, 0.90399, 0.88653, 0.96017, 0.82577, 0.77892, 0.78257, 0.97507, 1.54657, 0.97507, 0.85284, 0.89552, 0.90176, 0.88762, 0.8785, 0.75241, 0.8785, 0.90518, 0.95015, 0.77618, 0.8785, 0.88401, 0.91916, 0.86304, 0.88401, 0.91488, 0.8785, 0.8801, 0.8785, 0.8785, 0.91343, 0.7173, 1.04106, 0.8785, 0.85075, 0.95794, 0.82616, 0.85162, 0.79492, 0.88331, 1.69808, 0.88331, 0.85284, 0.97801, 0.89552, 0.91133, 0.89552, 0.91133, 1.7801, 0.89552, 1.24487, 1.13254, 1.12401, 0.96839, 0.85284, 0.68787, 0.70645, 0.85592, 0.90747, 1.01466, 1.0088, 0.90323, 1, 1.07463, 1, 0.91056, 0.75806, 1.19118, 0.96839, 0.78864, 0.82845, 0.84133, 0.75859, 0.83908, 0.83908, 0.83908, 0.83908, 0.83908, 0.83908, 0.77539, 0.73293, 0.73133, 0.73133, 0.73133, 0.73133, 0.95958, 0.95958, 0.95958, 0.95958, 0.88506, 0.9121, 0.86943, 0.86943, 0.86943, 0.86943, 0.86943, 0.85284, 0.87508, 0.90399, 0.90399, 0.90399, 0.90399, 0.77892, 0.79795, 0.90807, 0.88762, 0.88762, 0.88762, 0.88762, 0.88762, 0.88762, 0.8715, 0.75241, 0.90518, 0.90518, 0.90518, 0.90518, 0.88401, 0.88401, 0.88401, 0.88401, 0.8785, 0.8785, 0.8801, 0.8801, 0.8801, 0.8801, 0.8801, 0.90747, 0.89049, 0.8785, 0.8785, 0.8785, 0.8785, 0.85162, 0.8785, 0.85162, 0.83908, 0.88762, 0.83908, 0.88762, 0.83908, 0.88762, 0.73293, 0.75241, 0.73293, 0.75241, 0.73293, 0.75241, 0.73293, 0.75241, 0.87289, 0.83016, 0.88506, 0.93125, 0.73133, 0.90518, 0.73133, 0.90518, 0.73133, 0.90518, 0.73133, 0.90518, 0.73133, 0.90518, 0.81921, 0.77618, 0.81921, 0.77618, 0.81921, 0.77618, 1, 1, 0.87356, 0.8785, 0.91075, 0.89608, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.76229, 0.90167, 0.59526, 0.91916, 1, 1, 0.86304, 0.69225, 0.88401, 1, 1, 0.70424, 0.79468, 0.91926, 0.88175, 0.70823, 0.94903, 0.9121, 0.8785, 1, 1, 0.9121, 0.8785, 0.87802, 0.88656, 0.8785, 0.86943, 0.8801, 0.86943, 0.8801, 0.86943, 0.8801, 0.87402, 0.89291, 0.77958, 0.91343, 1, 1, 0.77958, 0.91343, 0.70864, 0.7173, 0.70864, 0.7173, 0.70864, 0.7173, 0.70864, 0.7173, 1, 1, 0.81055, 0.75841, 0.81055, 1.06452, 0.90399, 0.8785, 0.90399, 0.8785, 0.90399, 0.8785, 0.90399, 0.8785, 0.90399, 0.8785, 0.90399, 0.8785, 0.96017, 0.95794, 0.77892, 0.85162, 0.77892, 0.78257, 0.79492, 0.78257, 0.79492, 0.78257, 0.79492, 0.9297, 0.56892, 0.83908, 0.88762, 0.77539, 0.8715, 0.87508, 0.89049, 1, 1, 0.81055, 1.04106, 1.20528, 1.20528, 1, 1.15543, 0.70674, 0.98387, 0.94721, 1.33431, 1.45894, 0.95161, 1.06303, 0.83908, 0.80352, 0.57184, 0.6965, 0.56289, 0.82001, 0.56029, 0.81235, 1.02988, 0.83908, 0.7762, 0.68156, 0.80367, 0.73133, 0.78257, 0.87356, 0.86943, 0.95958, 0.75727, 0.89019, 1.04924, 0.9121, 0.7648, 0.86943, 0.87356, 0.79795, 0.78275, 0.81055, 0.77892,
vendor: 2,277 bytes, lines 28015-28020
280150.9762, 0.82577, 0.99819, 0.84896, 0.95958, 0.77892, 0.96108, 1.01407, 0.89049, 1.02988, 0.94211, 0.96108, 0.8936, 0.84021, 0.87842, 0.96399, 0.79109, 0.89049, 1.00813, 1.02988, 0.86077, 0.87445, 0.92099, 0.84723, 0.86513, 0.8801, 0.75638, 0.85714, 0.78216, 0.79586, 0.87965, 0.94211, 0.97747, 0.78287, 0.97926, 0.84971, 1.02988, 0.94211, 0.8801, 0.94211, 0.84971, 0.73133, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90264, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90518, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90548, 1, 1, 1, 1, 1, 1, 0.96017, 0.95794, 0.96017, 0.95794, 0.96017, 0.95794, 0.77892, 0.85162, 1, 1, 0.89552, 0.90527, 1, 0.90363, 0.92794, 0.92794, 0.92794, 0.92794, 0.87012, 0.87012, 0.87012, 0.89552, 0.89552, 1.42259, 0.71143, 1.06152, 1, 1, 1.03372, 1.03372, 0.97171, 1.4956, 2.2807, 0.93835, 0.83406, 0.91133, 0.84107, 0.91133, 1, 1, 1, 0.72021, 1, 1.23108, 0.83489, 0.88525, 0.88525, 0.81499, 0.90527, 1.81055, 0.90527, 1.81055, 1.31006, 1.53711, 0.94434, 1.08696, 1, 0.95018, 0.77192, 0.85284, 0.90747, 1.17534, 0.69825, 0.9716, 1.37077, 0.90747, 0.90747, 0.85356, 0.90747, 0.90747, 1.44947, 0.85284, 0.8941, 0.8941, 0.70572, 0.8, 0.70572, 0.70572, 0.70572, 0.70572, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.99862, 0.99862, 1, 1, 1, 1, 1, 1.08004, 0.91027, 1, 1, 1, 0.99862, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90727, 0.90727, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28016const CalibriBoldMetrics = { 28017 lineHeight: 1.2207, 28018 lineGap: 0.2207 28019}; 28020const CalibriBoldItalicFactors = [1.3877, 1, 1, 1, 0.97801, 0.92482, 0.89552, 0.91133, 0.81988, 0.97566, 0.98152, 0.93548, 0.93548, 1.2798, 0.85284, 0.92794, 1, 0.96134, 1.56239, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.82845, 0.82845, 0.85284, 0.85284, 0.85284, 0.75859, 0.92138, 0.83908, 0.7762, 0.71805, 0.87289, 0.73133, 0.7514, 0.81921, 0.87356, 0.95958, 0.59526, 0.75727, 0.69225, 1.04924, 0.90872, 0.85938, 0.79795, 0.87068, 0.77958, 0.69766, 0.81055, 0.90399, 0.88653, 0.96068, 0.82577, 0.77892,
vendor: 1,685 bytes, line 28020
280200.78257, 0.97507, 1.529, 0.97507, 0.85284, 0.89552, 0.90176, 0.94908, 0.86411, 0.74012, 0.86411, 0.88323, 0.95015, 0.86411, 0.86331, 0.88401, 0.91916, 0.86304, 0.88401, 0.9039, 0.86331, 0.86331, 0.86411, 0.86411, 0.90464, 0.70852, 1.04106, 0.86331, 0.84372, 0.95794, 0.82616, 0.84548, 0.79492, 0.88331, 1.69808, 0.88331, 0.85284, 0.97801, 0.89552, 0.91133, 0.89552, 0.91133, 1.7801, 0.89552, 1.24487, 1.13254, 1.19129, 0.96839, 0.85284, 0.68787, 0.70645, 0.85592, 0.90747, 1.01466, 1.0088, 0.90323, 1, 1.07463, 1, 0.91056, 0.75806, 1.19118, 0.96839, 0.78864, 0.82845, 0.84133, 0.75859, 0.83908, 0.83908, 0.83908, 0.83908, 0.83908, 0.83908, 0.77539, 0.71805, 0.73133, 0.73133, 0.73133, 0.73133, 0.95958, 0.95958, 0.95958, 0.95958, 0.88506, 0.90872, 0.85938, 0.85938, 0.85938, 0.85938, 0.85938, 0.85284, 0.87068, 0.90399, 0.90399, 0.90399, 0.90399, 0.77892, 0.79795, 0.90807, 0.94908, 0.94908, 0.94908, 0.94908, 0.94908, 0.94908, 0.85887, 0.74012, 0.88323, 0.88323, 0.88323, 0.88323, 0.88401, 0.88401, 0.88401, 0.88401, 0.8785, 0.86331, 0.86331, 0.86331, 0.86331, 0.86331, 0.86331, 0.90747, 0.89049, 0.86331, 0.86331, 0.86331, 0.86331, 0.84548, 0.86411, 0.84548, 0.83908, 0.94908, 0.83908, 0.94908, 0.83908, 0.94908, 0.71805, 0.74012, 0.71805, 0.74012, 0.71805, 0.74012, 0.71805, 0.74012, 0.87289, 0.79538, 0.88506, 0.92726, 0.73133, 0.88323, 0.73133, 0.88323, 0.73133, 0.88323, 0.73133, 0.88323, 0.73133, 0.88323, 0.81921, 0.86411, 0.81921, 0.86411, 0.81921, 0.86411, 1, 1, 0.87356, 0.86331, 0.91075, 0.8777, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.76467, 0.90167, 0.59526, 0.91916, 1, 1, 0.86304, 0.69225, 0.88401, 1, 1, 0.70424, 0.7
vendor: 3,143 bytes, lines 28020-28025
280207312, 0.91926, 0.88175, 0.70823, 0.94903, 0.90872, 0.86331, 1, 1, 0.90872, 0.86331, 0.86906, 0.88116, 0.86331, 0.85938, 0.86331, 0.85938, 0.86331, 0.85938, 0.86331, 0.87402, 0.86549, 0.77958, 0.90464, 1, 1, 0.77958, 0.90464, 0.69766, 0.70852, 0.69766, 0.70852, 0.69766, 0.70852, 0.69766, 0.70852, 1, 1, 0.81055, 0.75841, 0.81055, 1.06452, 0.90399, 0.86331, 0.90399, 0.86331, 0.90399, 0.86331, 0.90399, 0.86331, 0.90399, 0.86331, 0.90399, 0.86331, 0.96068, 0.95794, 0.77892, 0.84548, 0.77892, 0.78257, 0.79492, 0.78257, 0.79492, 0.78257, 0.79492, 0.9297, 0.56892, 0.83908, 0.94908, 0.77539, 0.85887, 0.87068, 0.89049, 1, 1, 0.81055, 1.04106, 1.20528, 1.20528, 1, 1.15543, 0.70088, 0.98387, 0.94721, 1.33431, 1.45894, 0.95161, 1.48387, 0.83908, 0.80352, 0.57118, 0.6965, 0.56347, 0.79179, 0.55853, 0.80346, 1.02988, 0.83908, 0.7762, 0.67174, 0.86036, 0.73133, 0.78257, 0.87356, 0.86441, 0.95958, 0.75727, 0.89019, 1.04924, 0.90872, 0.74889, 0.85938, 0.87891, 0.79795, 0.7957, 0.81055, 0.77892, 0.97447, 0.82577, 0.97466, 0.87179, 0.95958, 0.77892, 0.94252, 0.95612, 0.8753, 1.02988, 0.92733, 0.94252, 0.87411, 0.84021, 0.8728, 0.95612, 0.74081, 0.8753, 1.02189, 1.02988, 0.84814, 0.87445, 0.91822, 0.84723, 0.85668, 0.86331, 0.81344, 0.87581, 0.76422, 0.82046, 0.96057, 0.92733, 0.99375, 0.78022, 0.95452, 0.86015, 1.02988, 0.92733, 0.86331, 0.92733, 0.86015, 0.73133, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90631, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.88323, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.85174, 1, 1, 1, 1, 1, 1, 0.96068, 0.95794, 0.96068, 0.95794, 0.96068, 0.95794, 0.77892, 0.84548, 1, 1, 0.89552, 0.90527, 1, 0.90363, 0.92794, 0.92794, 0.92794, 0.89807, 0.87012, 0.87012, 0.87012, 0.89552, 0.89552, 1.42259, 0.71094, 1.06152, 1, 1, 1.03372, 1.03372, 0.97171, 1.4956, 2.2807, 0.92972, 0.83406, 0.91133, 0.83326, 0.91133, 1, 1, 1, 0.72021, 1, 1.23108, 0.83489, 0.88525, 0.88525, 0.81499, 0.90616, 1.81055, 0.90527, 1.81055, 1.3107, 1.53711, 0.94434, 1.08696, 1, 0.95018, 0.77192, 0.85284, 0.90747, 1.17534, 0.69825, 0.9716, 1.37077, 0.90747, 0.90747, 0.85356, 0.90747, 0.90747, 1.44947, 0.85284, 0.8941, 0.8941, 0.70572, 0.8, 0.70572, 0.70572, 0.70572, 0.70572, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.99862, 0.99862, 1, 1, 1, 1, 1, 1.08004, 0.91027, 1, 1, 1, 0.99862, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90727, 0.90727, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28021const CalibriBoldItalicMetrics = { 28022 lineHeight: 1.2207, 28023 lineGap: 0.2207 28024}; 28025const CalibriItalicFactors = [1.3877, 1, 1, 1, 1.17223, 1.1293, 0.89552, 0.91133, 0.80395, 1.02269, 1.15601, 0.91056, 0.91056, 1.2798, 0.85284, 0.89807, 1, 0.90861, 1.39543, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.96309, 0.96309, 0.85284, 0.85284, 0.85284, 0.83319, 0.88071, 0.8675, 0.81552, 0.72346, 0.85193, 0.73206, 0.7522, 0.81105, 0.86275, 0.90685, 0.6377, 0.77892,
vendor: 3,657 bytes, line 28025
280250.75593, 1.02638, 0.89249, 0.84118, 0.77452, 0.85374, 0.75186, 0.67789, 0.79776, 0.88844, 0.85066, 0.94309, 0.77818, 0.7306, 0.76659, 1.10369, 1.38313, 1.10369, 1.06139, 0.89552, 0.8739, 0.9245, 0.9245, 0.83203, 0.9245, 0.85865, 1.09842, 0.9245, 0.9245, 1.03297, 1.07692, 0.90918, 1.03297, 0.94959, 0.9245, 0.92274, 0.9245, 0.9245, 1.02933, 0.77832, 1.20562, 0.9245, 0.8916, 0.98986, 0.86621, 0.89453, 0.79004, 0.94152, 1.77256, 0.94152, 0.85284, 0.97801, 0.89552, 0.91133, 0.89552, 0.91133, 1.91729, 0.89552, 1.17889, 1.13254, 1.16359, 0.92098, 0.85284, 0.68787, 0.71353, 0.84737, 0.90747, 1.0088, 1.0044, 0.87683, 1, 1.09091, 1, 0.92229, 0.739, 1.15642, 0.92098, 0.76288, 0.80504, 0.80972, 0.75859, 0.8675, 0.8675, 0.8675, 0.8675, 0.8675, 0.8675, 0.76318, 0.72346, 0.73206, 0.73206, 0.73206, 0.73206, 0.90685, 0.90685, 0.90685, 0.90685, 0.86477, 0.89249, 0.84118, 0.84118, 0.84118, 0.84118, 0.84118, 0.85284, 0.84557, 0.88844, 0.88844, 0.88844, 0.88844, 0.7306, 0.77452, 0.86331, 0.9245, 0.9245, 0.9245, 0.9245, 0.9245, 0.9245, 0.84843, 0.83203, 0.85865, 0.85865, 0.85865, 0.85865, 0.82601, 0.82601, 0.82601, 0.82601, 0.94469, 0.9245, 0.92274, 0.92274, 0.92274, 0.92274, 0.92274, 0.90747, 0.86651, 0.9245, 0.9245, 0.9245, 0.9245, 0.89453, 0.9245, 0.89453, 0.8675, 0.9245, 0.8675, 0.9245, 0.8675, 0.9245, 0.72346, 0.83203, 0.72346, 0.83203, 0.72346, 0.83203, 0.72346, 0.83203, 0.85193, 0.8875, 0.86477, 0.99034, 0.73206, 0.85865, 0.73206, 0.85865, 0.73206, 0.85865, 0.73206, 0.85865, 0.73206, 0.85865, 0.81105, 0.9245, 0.81105, 0.9245, 0.81105, 0.9245, 1, 1, 0.86275, 0.9245, 0.90872, 0.93591, 0.90685, 0.82601, 0.90685, 0.82601, 0.90685, 0.82601, 0.90685, 1.03297, 0.90685, 0.82601, 0.77896, 1.05611, 0.6377, 1.07692, 1, 1, 0.90918, 0.75593, 1.03297, 1, 1, 0.76032, 0.9375, 0.98156, 0.93407, 0.77261, 1.11429, 0.89249, 0.9245, 1, 1, 0.89249, 0.9245, 0.92534, 0.86698, 0.9245, 0.84118, 0.92274, 0.84118, 0.92274, 0.84118, 0.92274, 0.8667, 0.86291, 0.75186, 1.02933, 1, 1, 0.75186, 1.02933, 0.67789, 0.77832, 0.67789, 0.77832, 0.67789, 0.77832, 0.67789, 0.77832, 1, 1, 0.79776, 0.97655, 0.79776, 1.23023, 0.88844, 0.9245, 0.88844, 0.9245, 0.88844, 0.9245, 0.88844, 0.9245, 0.88844, 0.9245, 0.88844, 0.9245, 0.94309, 0.98986, 0.7306, 0.89453, 0.7306, 0.76659, 0.79004, 0.76659, 0.79004, 0.76659, 0.79004, 1.09231, 0.54873, 0.8675, 0.9245, 0.76318, 0.84843, 0.84557, 0.86651, 1, 1, 0.79776, 1.20562, 1.18622, 1.18622, 1, 1.1437, 0.67009, 0.96334, 0.93695, 1.35191, 1.40909, 0.95161, 1.48387, 0.8675, 0.90861, 0.6192, 0.7363, 0.64824, 0.82411, 0.56321, 0.85696, 1.23516, 0.8675, 0.81552, 0.7286, 0.84134, 0.73206, 0.76659, 0.86275, 0.84369, 0.90685, 0.77892, 0.85871, 1.02638, 0.89249, 0.75828, 0.84118, 0.85984, 0.77452, 0.76466, 0.79776, 0.7306, 0.90782, 0.77818, 0.903, 0.87291, 0.90685, 0.7306, 0.99058, 1.03667, 0.94635, 1.23516, 0.9849, 0.99058, 0.92393, 0.8916, 0.942, 1.03667, 0.75026, 0.94635, 1.0297, 1.23516, 0.90918, 0.94048, 0.98217, 0.89746, 0.84153, 0.92274, 0.82507, 0.88832, 0.84438, 0.88178, 1.03525, 0.9849, 1.00225, 0.78086, 0.97248, 0.89404, 1.23516, 0.9849, 0.92274, 0.9849, 0.89404, 0.73206, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.89693, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.85865, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90933, 1, 1, 1, 1, 1, 1, 0.94309, 0.98986, 0.94309, 0.98986, 0.94309, 0.98986, 0.7306, 0.89453, 1, 1, 0.89552, 0.90527, 1, 0.90186, 1.12308, 1.12308, 1.12308, 1.12308, 1.2566, 1.2566, 1.2566, 0.89552, 0.89552, 1.42259, 0.68994, 1.03809, 1, 1, 1.0176, 1.01
vendor: 1,221 bytes, lines 28025-28030
2802576, 1.11523, 1.4956, 2.01462, 0.97858, 0.82616, 0.91133, 0.83437, 0.91133, 1, 1, 1, 0.70508, 1, 1.23108, 0.79801, 0.84426, 0.84426, 0.774, 0.90572, 1.81055, 0.90749, 1.81055, 1.28809, 1.55469, 0.94434, 1.07806, 1, 0.97094, 0.7589, 0.85284, 0.90747, 1.19658, 0.69825, 0.97622, 1.33512, 0.90747, 0.90747, 0.85284, 0.90747, 0.90747, 1.44947, 0.85284, 0.8941, 0.8941, 0.70572, 0.8, 0.70572, 0.70572, 0.70572, 0.70572, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.99862, 0.99862, 1, 1, 1, 1, 1, 1.0336, 0.91027, 1, 1, 1, 0.99862, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.05859, 1.05859, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28026const CalibriItalicMetrics = { 28027 lineHeight: 1.2207, 28028 lineGap: 0.2207 28029}; 28030const CalibriRegularFactors = [1.3877, 1, 1, 1, 1.17223, 1.1293, 0.89552, 0.91133, 0.80395, 1.02269, 1.15601, 0.91056, 0.91056, 1.2798, 0.85284, 0.89807, 1, 0.90861, 1.39016, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.96309, 0.96309, 0.85284, 0.85284, 0.85284, 0.83319, 0.88071, 0.8675, 0.81552, 0.73834, 0.85193, 0.73206, 0.7522, 0.81105, 0.86275, 0.90685, 0.6377, 0.77892,
vendor: 3,690 bytes, line 28030
280300.75593, 1.02638, 0.89385, 0.85122, 0.77452, 0.86503, 0.75186, 0.68887, 0.79776, 0.88844, 0.85066, 0.94258, 0.77818, 0.7306, 0.76659, 1.10369, 1.39016, 1.10369, 1.06139, 0.89552, 0.8739, 0.86128, 0.94469, 0.8457, 0.94469, 0.89464, 1.09842, 0.84636, 0.94469, 1.03297, 1.07692, 0.90918, 1.03297, 0.95897, 0.94469, 0.9482, 0.94469, 0.94469, 1.04692, 0.78223, 1.20562, 0.94469, 0.90332, 0.98986, 0.86621, 0.90527, 0.79004, 0.94152, 1.77256, 0.94152, 0.85284, 0.97801, 0.89552, 0.91133, 0.89552, 0.91133, 1.91729, 0.89552, 1.17889, 1.13254, 1.08707, 0.92098, 0.85284, 0.68787, 0.71353, 0.84737, 0.90747, 1.0088, 1.0044, 0.87683, 1, 1.09091, 1, 0.92229, 0.739, 1.15642, 0.92098, 0.76288, 0.80504, 0.80972, 0.75859, 0.8675, 0.8675, 0.8675, 0.8675, 0.8675, 0.8675, 0.76318, 0.73834, 0.73206, 0.73206, 0.73206, 0.73206, 0.90685, 0.90685, 0.90685, 0.90685, 0.86477, 0.89385, 0.85122, 0.85122, 0.85122, 0.85122, 0.85122, 0.85284, 0.85311, 0.88844, 0.88844, 0.88844, 0.88844, 0.7306, 0.77452, 0.86331, 0.86128, 0.86128, 0.86128, 0.86128, 0.86128, 0.86128, 0.8693, 0.8457, 0.89464, 0.89464, 0.89464, 0.89464, 0.82601, 0.82601, 0.82601, 0.82601, 0.94469, 0.94469, 0.9482, 0.9482, 0.9482, 0.9482, 0.9482, 0.90747, 0.86651, 0.94469, 0.94469, 0.94469, 0.94469, 0.90527, 0.94469, 0.90527, 0.8675, 0.86128, 0.8675, 0.86128, 0.8675, 0.86128, 0.73834, 0.8457, 0.73834, 0.8457, 0.73834, 0.8457, 0.73834, 0.8457, 0.85193, 0.92454, 0.86477, 0.9921, 0.73206, 0.89464, 0.73206, 0.89464, 0.73206, 0.89464, 0.73206, 0.89464, 0.73206, 0.89464, 0.81105, 0.84636, 0.81105, 0.84636, 0.81105, 0.84636, 1, 1, 0.86275, 0.94469, 0.90872, 0.95786, 0.90685, 0.82601, 0.90685, 0.82601, 0.90685, 0.82601, 0.90685, 1.03297, 0.90685, 0.82601, 0.77741, 1.05611, 0.6377, 1.07692, 1, 1, 0.90918, 0.75593, 1.03297, 1, 1, 0.76032, 0.90452, 0.98156, 1.11842, 0.77261, 1.11429, 0.89385, 0.94469, 1, 1, 0.89385, 0.94469, 0.95877, 0.86901, 0.94469, 0.85122, 0.9482, 0.85122, 0.9482, 0.85122, 0.9482, 0.8667, 0.90016, 0.75186, 1.04692, 1, 1, 0.75186, 1.04692, 0.68887, 0.78223, 0.68887, 0.78223, 0.68887, 0.78223, 0.68887, 0.78223, 1, 1, 0.79776, 0.92188, 0.79776, 1.23023, 0.88844, 0.94469, 0.88844, 0.94469, 0.88844, 0.94469, 0.88844, 0.94469, 0.88844, 0.94469, 0.88844, 0.94469, 0.94258, 0.98986, 0.7306, 0.90527, 0.7306, 0.76659, 0.79004, 0.76659, 0.79004, 0.76659, 0.79004, 1.09231, 0.54873, 0.8675, 0.86128, 0.76318, 0.8693, 0.85311, 0.86651, 1, 1, 0.79776, 1.20562, 1.18622, 1.18622, 1, 1.1437, 0.67742, 0.96334, 0.93695, 1.35191, 1.40909, 0.95161, 1.48387, 0.86686, 0.90861, 0.62267, 0.74359, 0.65649, 0.85498, 0.56963, 0.88254, 1.23516, 0.8675, 0.81552, 0.75443, 0.84503, 0.73206, 0.76659, 0.86275, 0.85122, 0.90685, 0.77892, 0.85746, 1.02638, 0.89385, 0.75657, 0.85122, 0.86275, 0.77452, 0.74171, 0.79776, 0.7306, 0.95165, 0.77818, 0.89772, 0.88831, 0.90685, 0.7306, 0.98142, 1.02191, 0.96576, 1.23516, 0.99018, 0.98142, 0.9236, 0.89258, 0.94035, 1.02191, 0.78848, 0.96576, 0.9561, 1.23516, 0.90918, 0.92578, 0.95424, 0.89746, 0.83969, 0.9482, 0.80113, 0.89442, 0.85208, 0.86155, 0.98022, 0.99018, 1.00452, 0.81209, 0.99247, 0.89181, 1.23516, 0.99018, 0.9482, 0.99018, 0.89181, 0.73206, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.88844, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.89464, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.96766, 1, 1, 1, 1, 1, 1, 0.94258, 0.98986, 0.94258, 0.98986, 0.94258, 0.98986, 0.7306, 0.90527, 1, 1, 0.89552, 0.90527, 1, 0.90186, 1.12308, 1.12308, 1.12308, 1.12308, 1.2566, 1.2566, 1.2566, 0.89552, 0.89552, 1.42259, 0.69043, 1.03809, 1, 1, 1.0176, 1.01
vendor: 56,964 bytes, lines 28030-28074
2803076, 1.11523, 1.4956, 2.01462, 0.99331, 0.82616, 0.91133, 0.84286, 0.91133, 1, 1, 1, 0.70508, 1, 1.23108, 0.79801, 0.84426, 0.84426, 0.774, 0.90527, 1.81055, 0.90527, 1.81055, 1.28809, 1.55469, 0.94434, 1.07806, 1, 0.97094, 0.7589, 0.85284, 0.90747, 1.19658, 0.69825, 0.97622, 1.33512, 0.90747, 0.90747, 0.85356, 0.90747, 0.90747, 1.44947, 0.85284, 0.8941, 0.8941, 0.70572, 0.8, 0.70572, 0.70572, 0.70572, 0.70572, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.99862, 0.99862, 1, 1, 1, 1, 1, 1.0336, 0.91027, 1, 1, 1, 0.99862, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.05859, 1.05859, 1, 1, 1, 1.07185, 0.99413, 0.96334, 1.08065, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28031const CalibriRegularMetrics = { 28032 lineHeight: 1.2207, 28033 lineGap: 0.2207 28034}; 28035 28036;// ./src/core/helvetica_factors.js 28037const HelveticaBoldFactors = [0.76116, 1, 1, 1.0006, 0.99998, 0.99974, 0.99973, 0.99973, 0.99982, 0.99977, 1.00087, 0.99998, 0.99998, 0.99959, 1.00003, 1.0006, 0.99998, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99998, 1, 1.00003, 1.00003, 1.00003, 1.00026, 0.9999, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00026, 1.00022, 0.99977, 1.0006, 0.99973, 0.99977, 1.00026, 0.99999, 0.99977, 1.00022, 1.00001, 1.00022, 0.99977, 1.00001, 1.00026, 0.99977, 1.00001, 1.00016, 1.00001, 1.00001, 1.00026, 0.99998, 1.0006, 0.99998, 1.00003, 0.99973, 0.99998, 0.99973, 1.00026, 0.99973, 1.00026, 0.99973, 0.99998, 1.00026, 1.00026, 1.0006, 1.0006, 0.99973, 1.0006, 0.99982, 1.00026, 1.00026, 1.00026, 1.00026, 0.99959, 0.99973, 0.99998, 1.00026, 0.99973, 1.00022, 0.99973, 0.99973, 1, 0.99959, 1.00077, 0.99959, 1.00003, 0.99998, 0.99973, 0.99973, 0.99973, 0.99973, 1.00077, 0.99973, 0.99998, 1.00025, 0.99968, 0.99973, 1.00003, 1.00025, 0.60299, 1.00024, 1.06409, 1, 1, 0.99998, 1, 0.99973, 1.0006, 0.99998, 1, 0.99936, 0.99973, 1.00002, 1.00002, 1.00002, 1.00026, 0.99977, 0.99977, 0.99977, 0.99977, 0.99977, 0.99977, 1, 0.99977, 1.00001, 1.00001, 1.00001, 1.00001, 1.0006, 1.0006, 1.0006, 1.0006, 0.99977, 0.99977, 1.00022, 1.00022, 1.00022, 1.00022, 1.00022, 1.00003, 1.00022, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00001, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99982, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.06409, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 0.99973, 1.00026, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 1.03374, 0.99977, 1.00026, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.00042, 0.99973, 0.99973, 1.0006, 0.99977, 0.99973, 0.99973, 1.00026, 1.0006, 1.00026, 1.0006, 1.00026, 1.03828, 1.00026, 0.99999, 1.00026, 1.0006, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.9993, 0.9998, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1, 1.00016, 0.99977, 0.99959, 0.99977, 0.99959, 0.99977, 0.99959, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00026, 0.99998, 1.00026, 0.8121, 1.00026, 0.99998, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 1.00016, 1.00022, 1.00001, 0.99973, 1.00001, 1.00026, 1, 1.00026, 1, 1.00026, 1, 1.0006, 0.99973, 0.99977, 0.99973, 1, 0.99982, 1.00022, 1.00026, 1.00001, 0.99973, 1.00026, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 1.00034, 0.99977, 1, 0.99997, 1.00026, 1.00078, 1.00036, 0.99973, 1.00013, 1.0006, 0.99977, 0.99977, 0.99988, 0.85148, 1.00001, 1.00026, 0.99977, 1.00022, 1.0006, 0.99977, 1.00001, 0.99999, 0.99977, 1.00069, 1.00022, 0.99977, 1.00001, 0.99984, 1.00026, 1.00001, 1.00024, 1.00001, 0.9999, 1, 1.0006, 1.00001, 1.00041, 0.99962, 1.00026, 1.0006, 0.99995, 1.00041, 0.99942, 0.99973, 0.99927, 1.00082, 0.99902, 1.00026, 1.00087, 1.0006, 1.00069, 0.99973, 0.99867, 0.99973, 0.9993, 1.00026, 1.00049, 1.00056, 1, 0.99988, 0.99935, 0.99995, 0.99954, 1.00055, 0.99945, 1.00032, 1.0006, 0.99995, 1.00026, 0.99995, 1.00032, 1.00001, 1.00008, 0.99971, 1.00019, 0.9994, 1.00001, 1.0006, 1.00044, 0.99973, 1.00023, 1.00047, 1, 0.99942, 0.99561, 0.99989, 1.00035, 0.99977, 1.00035, 0.99977, 1.00019, 0.99944, 1.00001, 1.00021, 0.99926, 1.00035, 1.00035, 0.99942, 1.00048, 0.99999, 0.99977, 1.00022, 1.00035, 1.00001, 0.99977, 1.00026, 0.99989, 1.00057, 1.00001, 0.99936, 1.00052, 1.00012, 0.99996, 1.00043, 1, 1.00035, 0.9994, 0.99976, 1.00035, 0.99973, 1.00052, 1.00041, 1.00119, 1.00037, 0.99973, 1.00002, 0.99986, 1.00041, 1.00041, 0.99902, 0.9996, 1.00034, 0.99999, 1.00026, 0.99999, 1.00026, 0.99973, 1.00052, 0.99973, 1, 0.99973, 1.00041, 1.00075, 0.9994, 1.0003, 0.99999, 1, 1.00041, 0.99955, 1, 0.99915, 0.99973, 0.99973, 1.00026, 1.00119, 0.99955, 0.99973, 1.0006, 0.99911, 1.0006, 1.00026, 0.99972, 1.00026, 0.99902, 1.00041, 0.99973, 0.99999, 1, 1, 1.00038, 1.0005, 1.00016, 1.00022, 1.00016, 1.00022, 1.00016, 1.00022, 1.00001, 0.99973, 1, 1, 0.99973, 1, 1, 0.99955, 1.0006, 1.0006, 1.0006, 1.0006, 1, 1, 1, 0.99973, 0.99973, 0.99972, 1, 1, 1.00106, 0.99999, 0.99998, 0.99998, 0.99999, 0.99998, 1.66475, 1, 0.99973, 0.99973, 1.00023, 0.99973, 0.99971, 1.00047, 1.00023, 1, 0.99991, 0.99984, 1.00002, 1.00002, 1.00002, 1.00002, 1, 1, 1, 1, 1, 1, 1, 0.99972, 1, 1.20985, 1.39713, 1.00003, 1.00031, 1.00015, 1, 0.99561, 1.00027, 1.00031, 1.00031, 0.99915, 1.00031, 1.00031, 0.99999, 1.00003, 0.99999, 0.99999, 1.41144, 1.6, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.40579, 1.40579, 1.36625, 0.99999, 1, 0.99861, 0.99861, 1, 1.00026, 1.00026, 1.00026, 1.00026, 0.99972, 0.99999, 0.99999, 0.99999, 0.99999, 1.40483, 1, 0.99977, 1.00054, 1, 1, 0.99953, 0.99962, 1.00042, 0.9995, 1, 1, 1, 1, 1, 1, 1, 1, 0.99998, 0.99998, 0.99998, 0.99998, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28038const HelveticaBoldMetrics = { 28039 lineHeight: 1.2, 28040 lineGap: 0.2 28041}; 28042const HelveticaBoldItalicFactors = [0.76116, 1, 1, 1.0006, 0.99998, 0.99974, 0.99973, 0.99973, 0.99982, 0.99977, 1.00087, 0.99998, 0.99998, 0.99959, 1.00003, 1.0006, 0.99998, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99998, 1, 1.00003, 1.00003, 1.00003, 1.00026, 0.9999, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00026, 1.00022, 0.99977, 1.0006, 0.99973, 0.99977, 1.00026, 0.99999, 0.99977, 1.00022, 1.00001, 1.00022, 0.99977, 1.00001, 1.00026, 0.99977, 1.00001, 1.00016, 1.00001, 1.00001, 1.00026, 0.99998, 1.0006, 0.99998, 1.00003, 0.99973, 0.99998, 0.99973, 1.00026, 0.99973, 1.00026, 0.99973, 0.99998, 1.00026, 1.00026, 1.0006, 1.0006, 0.99973, 1.0006, 0.99982, 1.00026, 1.00026, 1.00026, 1.00026, 0.99959, 0.99973, 0.99998, 1.00026, 0.99973, 1.00022, 0.99973, 0.99973, 1, 0.99959, 1.00077, 0.99959, 1.00003, 0.99998, 0.99973, 0.99973, 0.99973, 0.99973, 1.00077, 0.99973, 0.99998, 1.00025, 0.99968, 0.99973, 1.00003, 1.00025, 0.60299, 1.00024, 1.06409, 1, 1, 0.99998, 1, 0.99973, 1.0006, 0.99998, 1, 0.99936, 0.99973, 1.00002, 1.00002, 1.00002, 1.00026, 0.99977, 0.99977, 0.99977, 0.99977, 0.99977, 0.99977, 1, 0.99977, 1.00001, 1.00001, 1.00001, 1.00001, 1.0006, 1.0006, 1.0006, 1.0006, 0.99977, 0.99977, 1.00022, 1.00022, 1.00022, 1.00022, 1.00022, 1.00003, 1.00022, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00001, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99982, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.06409, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 0.99973, 1.00026, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 1.0044, 0.99977, 1.00026, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 0.99971, 0.99973, 0.99973, 1.0006, 0.99977, 0.99973, 0.99973, 1.00026, 1.0006, 1.00026, 1.0006, 1.00026, 1.01011, 1.00026, 0.99999, 1.00026, 1.0006, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.9993, 0.9998, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1, 1.00016, 0.99977, 0.99959, 0.99977, 0.99959, 0.99977, 0.99959, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00026, 0.99998, 1.00026, 0.8121, 1.00026, 0.99998, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 1.00016, 1.00022, 1.00001, 0.99973, 1.00001, 1.00026, 1, 1.00026, 1, 1.00026, 1, 1.0006, 0.99973, 0.99977, 0.99973, 1, 0.99982, 1.00022, 1.00026, 1.00001, 0.99973, 1.00026, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99977, 1, 1, 1.00026, 0.99969, 0.99972, 0.99981, 0.9998, 1.0006, 0.99977, 0.99977, 1.00022, 0.91155, 1.00001, 1.00026, 0.99977, 1.00022, 1.0006, 0.99977, 1.00001, 0.99999, 0.99977, 0.99966, 1.00022, 1.00032, 1.00001, 0.99944, 1.00026, 1.00001, 0.99968, 1.00001, 1.00047, 1, 1.0006, 1.00001, 0.99981, 1.00101, 1.00026, 1.0006, 0.99948, 0.99981, 1.00064, 0.99973, 0.99942, 1.00101, 1.00061, 1.00026, 1.00069, 1.0006, 1.00014, 0.99973, 1.01322, 0.99973, 1.00065, 1.00026, 1.00012, 0.99923, 1, 1.00064, 1.00076, 0.99948, 1.00055, 1.00063, 1.00007, 0.99943, 1.0006, 0.99948, 1.00026, 0.99948, 0.99943, 1.00001, 1.00001, 1.00029, 1.00038, 1.00035, 1.00001, 1.0006, 1.0006, 0.99973, 0.99978, 1.00001, 1.00057, 0.99989, 0.99967, 0.99964, 0.99967, 0.99977, 0.99999, 0.99977, 1.00038, 0.99977, 1.00001, 0.99973, 1.00066, 0.99967, 0.99967, 1.00041, 0.99998, 0.99999, 0.99977, 1.00022, 0.99967, 1.00001, 0.99977, 1.00026, 0.99964, 1.00031, 1.00001, 0.99999, 0.99999, 1, 1.00023, 1, 1, 0.99999, 1.00035, 1.00001, 0.99999, 0.99973, 0.99977, 0.99999, 1.00058, 0.99973, 0.99973, 0.99955, 0.9995, 1.00026, 1.00026, 1.00032, 0.99989, 1.00034, 0.99999, 1.00026, 1.00026, 1.00026, 0.99973, 0.45998, 0.99973, 1.00026, 0.99973, 1.00001, 0.99999, 0.99982, 0.99994, 0.99996, 1, 1.00042, 1.00044, 1.00029, 1.00023, 0.99973, 0.99973, 1.00026, 0.99949, 1.00002, 0.99973, 1.0006, 1.0006, 1.0006, 0.99975, 1.00026, 1.00026, 1.00032, 0.98685, 0.99973, 1.00026, 1, 1, 0.99966, 1.00044, 1.00016, 1.00022, 1.00016, 1.00022, 1.00016, 1.00022, 1.00001, 0.99973, 1, 1, 0.99973, 1, 1, 0.99955, 1.0006, 1.0006, 1.0006, 1.0006, 1, 1, 1, 0.99973, 0.99973, 0.99972, 1, 1, 1.00106, 0.99999, 0.99998, 0.99998, 0.99999, 0.99998, 1.66475, 1, 0.99973, 0.99973, 1, 0.99973, 0.99971, 0.99978, 1, 1, 0.99991, 0.99984, 1.00002, 1.00002, 1.00002, 1.00002, 1.00098, 1, 1, 1, 1.00049, 1, 1, 0.99972, 1, 1.20985, 1.39713, 1.00003, 1.00031, 1.00015, 1, 0.99561, 1.00027, 1.00031, 1.00031, 0.99915, 1.00031, 1.00031, 0.99999, 1.00003, 0.99999, 0.99999, 1.41144, 1.6, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.40579, 1.40579, 1.36625, 0.99999, 1, 0.99861, 0.99861, 1, 1.00026, 1.00026, 1.00026, 1.00026, 0.99972, 0.99999, 0.99999, 0.99999, 0.99999, 1.40483, 1, 0.99977, 1.00054, 1, 1, 0.99953, 0.99962, 1.00042, 0.9995, 1, 1, 1, 1, 1, 1, 1, 1, 0.99998, 0.99998, 0.99998, 0.99998, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28043const HelveticaBoldItalicMetrics = { 28044 lineHeight: 1.35, 28045 lineGap: 0.2 28046}; 28047const HelveticaItalicFactors = [0.76116, 1, 1, 1.0006, 1.0006, 1.00006, 0.99973, 0.99973, 0.99982, 1.00001, 1.00043, 0.99998, 0.99998, 0.99959, 1.00003, 1.0006, 0.99998, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1, 1.00003, 1.00003, 1.00003, 0.99973, 0.99987, 1.00001, 1.00001, 0.99977, 0.99977, 1.00001, 1.00026, 1.00022, 0.99977, 1.0006, 1, 1.00001, 0.99973, 0.99999, 0.99977, 1.00022, 1.00001, 1.00022, 0.99977, 1.00001, 1.00026, 0.99977, 1.00001, 1.00016, 1.00001, 1.00001, 1.00026, 1.0006, 1.0006, 1.0006, 0.99949, 0.99973, 0.99998, 0.99973, 0.99973, 1, 0.99973, 0.99973, 1.0006, 0.99973, 0.99973, 0.99924, 0.99924, 1, 0.99924, 0.99999, 0.99973, 0.99973, 0.99973, 0.99973, 0.99998, 1, 1.0006, 0.99973, 1, 0.99977, 1, 1, 1, 1.00005, 1.0009, 1.00005, 1.00003, 0.99998, 0.99973, 0.99973, 0.99973, 0.99973, 1.0009, 0.99973, 0.99998, 1.00025, 0.99968, 0.99973, 1.00003, 1.00025, 0.60299, 1.00024, 1.06409, 1, 1, 0.99998, 1, 0.9998, 1.0006, 0.99998, 1, 0.99936, 0.99973, 1.00002, 1.00002, 1.00002, 1.00026, 1.00001, 1.00001, 1.00001, 1.00001, 1.00001, 1.00001, 1, 0.99977, 1.00001, 1.00001, 1.00001, 1.00001, 1.0006, 1.0006, 1.0006, 1.0006, 0.99977, 0.99977, 1.00022, 1.00022, 1.00022, 1.00022, 1.00022, 1.00003, 1.00022, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00001, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99982, 1, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.06409, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 1, 0.99973, 1, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 0.99977, 1, 0.99977, 1, 0.99977, 1, 0.99977, 1, 0.99977, 1.0288, 0.99977, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 0.99924, 1.0006, 1.0006, 0.99946, 1.00034, 1, 0.99924, 1.00001, 1, 1, 0.99973, 0.99924, 0.99973, 0.99924, 0.99973, 1.06311, 0.99973, 1.00024, 0.99973, 0.99924, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 1.00041, 0.9998, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1, 1.00016, 0.99977, 0.99998, 0.99977, 0.99998, 0.99977, 0.99998, 1.00001, 1, 1.00001, 1, 1.00001, 1, 1.00001, 1, 1.00026, 1.0006, 1.00026, 0.89547, 1.00026, 1.0006, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 1.00016, 0.99977, 1.00001, 1, 1.00001, 1.00026, 1, 1.00026, 1, 1.00026, 1, 0.99924, 0.99973, 1.00001, 0.99973, 1, 0.99982, 1.00022, 1.00026, 1.00001, 1, 1.00026, 1.0006, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 1.00001, 1, 1.00054, 0.99977, 1.00084, 1.00007, 0.99973, 1.00013, 0.99924, 1.00001, 1.00001, 0.99945, 0.91221, 1.00001, 1.00026, 0.99977, 1.00022, 1.0006, 1.00001, 1.00001, 0.99999, 0.99977, 0.99933, 1.00022, 1.00054, 1.00001, 1.00065, 1.00026, 1.00001, 1.0001, 1.00001, 1.00052, 1, 1.0006, 1.00001, 0.99945, 0.99897, 0.99968, 0.99924, 1.00036, 0.99945, 0.99949, 1, 1.0006, 0.99897, 0.99918, 0.99968, 0.99911, 0.99924, 1, 0.99962, 1.01487, 1, 1.0005, 0.99973, 1.00012, 1.00043, 1, 0.99995, 0.99994, 1.00036, 0.99947, 1.00019, 1.00063, 1.00025, 0.99924, 1.00036, 0.99973, 1.00036, 1.00025, 1.00001, 1.00001, 1.00027, 1.0001, 1.00068, 1.00001, 1.0006, 1.0006, 1, 1.00008, 0.99957, 0.99972, 0.9994, 0.99954, 0.99975, 1.00051, 1.00001, 1.00019, 1.00001, 1.0001, 0.99986, 1.00001, 1.00001, 1.00038, 0.99954, 0.99954, 0.9994, 1.00066, 0.99999, 0.99977, 1.00022, 1.00054, 1.00001, 0.99977, 1.00026, 0.99975, 1.0001, 1.00001, 0.99993, 0.9995, 0.99955, 1.00016, 0.99978, 0.99974, 1.00019, 1.00022, 0.99955, 1.00053, 0.99973, 1.00089, 1.00005, 0.99967, 1.00048, 0.99973, 1.00002, 1.00034, 0.99973, 0.99973, 0.99964, 1.00006, 1.00066, 0.99947, 0.99973, 0.98894, 0.99973, 1, 0.44898, 1, 0.99946, 1, 1.00039, 1.00082, 0.99991, 0.99991, 0.99985, 1.00022, 1.00023, 1.00061, 1.00006, 0.99966, 0.99973, 0.99973, 0.99973, 1.00019, 1.0008, 1, 0.99924, 0.99924, 0.99924, 0.99983, 1.00044, 0.99973, 0.99964, 0.98332, 1, 0.99973, 1, 1, 0.99962, 0.99895, 1.00016, 0.99977, 1.00016, 0.99977, 1.00016, 0.99977, 1.00001, 1, 1, 1, 0.99973, 1, 1, 0.99955, 0.99924, 0.99924, 0.99924, 0.99924, 0.99998, 0.99998, 0.99998, 0.99973, 0.99973, 0.99972, 1, 1, 1.00267, 0.99999, 0.99998, 0.99998, 1, 0.99998, 1.66475, 1, 0.99973, 0.99973, 1.00023, 0.99973, 1.00423, 0.99925, 0.99999, 1, 0.99991, 0.99984, 1.00002, 1.00002, 1.00002, 1.00002, 1.00049, 1, 1.00245, 1, 1, 1, 1, 0.96329, 1, 1.20985, 1.39713, 1.00003, 0.8254, 1.00015, 1, 1.00035, 1.00027, 1.00031, 1.00031, 1.00003, 1.00031, 1.00031, 0.99999, 1.00003, 0.99999, 0.99999, 1.41144, 1.6, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.40579, 1.40579, 1.36625, 0.99999, 1, 0.99861, 0.99861, 1, 1.00026, 1.00026, 1.00026, 1.00026, 0.95317, 0.99999, 0.99999, 0.99999, 0.99999, 1.40483, 1, 0.99977, 1.00054, 1, 1, 0.99953, 0.99962, 1.00042, 0.9995, 1, 1, 1, 1, 1, 1, 1, 1, 0.99998, 0.99998, 0.99998, 0.99998, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28048const HelveticaItalicMetrics = { 28049 lineHeight: 1.35, 28050 lineGap: 0.2 28051}; 28052const HelveticaRegularFactors = [0.76116, 1, 1, 1.0006, 1.0006, 1.00006, 0.99973, 0.99973, 0.99982, 1.00001, 1.00043, 0.99998, 0.99998, 0.99959, 1.00003, 1.0006, 0.99998, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1, 1.00003, 1.00003, 1.00003, 0.99973, 0.99987, 1.00001, 1.00001, 0.99977, 0.99977, 1.00001, 1.00026, 1.00022, 0.99977, 1.0006, 1, 1.00001, 0.99973, 0.99999, 0.99977, 1.00022, 1.00001, 1.00022, 0.99977, 1.00001, 1.00026, 0.99977, 1.00001, 1.00016, 1.00001, 1.00001, 1.00026, 1.0006, 1.0006, 1.0006, 0.99949, 0.99973, 0.99998, 0.99973, 0.99973, 1, 0.99973, 0.99973, 1.0006, 0.99973, 0.99973, 0.99924, 0.99924, 1, 0.99924, 0.99999, 0.99973, 0.99973, 0.99973, 0.99973, 0.99998, 1, 1.0006, 0.99973, 1, 0.99977, 1, 1, 1, 1.00005, 1.0009, 1.00005, 1.00003, 0.99998, 0.99973, 0.99973, 0.99973, 0.99973, 1.0009, 0.99973, 0.99998, 1.00025, 0.99968, 0.99973, 1.00003, 1.00025, 0.60299, 1.00024, 1.06409, 1, 1, 0.99998, 1, 0.9998, 1.0006, 0.99998, 1, 0.99936, 0.99973, 1.00002, 1.00002, 1.00002, 1.00026, 1.00001, 1.00001, 1.00001, 1.00001, 1.00001, 1.00001, 1, 0.99977, 1.00001, 1.00001, 1.00001, 1.00001, 1.0006, 1.0006, 1.0006, 1.0006, 0.99977, 0.99977, 1.00022, 1.00022, 1.00022, 1.00022, 1.00022, 1.00003, 1.00022, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00001, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99982, 1, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.06409, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 1, 0.99973, 1, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 0.99977, 1, 0.99977, 1, 0.99977, 1, 0.99977, 1, 0.99977, 1.04596, 0.99977, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 0.99924, 1.0006, 1.0006, 1.00019, 1.00034, 1, 0.99924, 1.00001, 1, 1, 0.99973, 0.99924, 0.99973, 0.99924, 0.99973, 1.02572, 0.99973, 1.00005, 0.99973, 0.99924, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99999, 0.9998, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1, 1.00016, 0.99977, 0.99998, 0.99977, 0.99998, 0.99977, 0.99998, 1.00001, 1, 1.00001, 1, 1.00001, 1, 1.00001, 1, 1.00026, 1.0006, 1.00026, 0.84533, 1.00026, 1.0006, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 1.00016, 0.99977, 1.00001, 1, 1.00001, 1.00026, 1, 1.00026, 1, 1.00026, 1, 0.99924, 0.99973, 1.00001, 0.99973, 1, 0.99982, 1.00022, 1.00026, 1.00001, 1, 1.00026, 1.0006, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99928, 1, 0.99977, 1.00013, 1.00055, 0.99947, 0.99945, 0.99941, 0.99924, 1.00001, 1.00001, 1.0004, 0.91621, 1.00001, 1.00026, 0.99977, 1.00022, 1.0006, 1.00001, 1.00005, 0.99999, 0.99977, 1.00015, 1.00022, 0.99977, 1.00001, 0.99973, 1.00026, 1.00001, 1.00019, 1.00001, 0.99946, 1, 1.0006, 1.00001, 0.99978, 1.00045, 0.99973, 0.99924, 1.00023, 0.99978, 0.99966, 1, 1.00065, 1.00045, 1.00019, 0.99973, 0.99973, 0.99924, 1, 1, 0.96499, 1, 1.00055, 0.99973, 1.00008, 1.00027, 1, 0.9997, 0.99995, 1.00023, 0.99933, 1.00019, 1.00015, 1.00031, 0.99924, 1.00023, 0.99973, 1.00023, 1.00031, 1.00001, 0.99928, 1.00029, 1.00092, 1.00035, 1.00001, 1.0006, 1.0006, 1, 0.99988, 0.99975, 1, 1.00082, 0.99561, 0.9996, 1.00035, 1.00001, 0.99962, 1.00001, 1.00092, 0.99964, 1.00001, 0.99963, 0.99999, 1.00035, 1.00035, 1.00082, 0.99962, 0.99999, 0.99977, 1.00022, 1.00035, 1.00001, 0.99977, 1.00026, 0.9996, 0.99967, 1.00001, 1.00034, 1.00074, 1.00054, 1.00053, 1.00063, 0.99971, 0.99962, 1.00035, 0.99975, 0.99977, 0.99973, 1.00043, 0.99953, 1.0007, 0.99915, 0.99973, 1.00008, 0.99892, 1.00073, 1.00073, 1.00114, 0.99915, 1.00073, 0.99955, 0.99973, 1.00092, 0.99973, 1, 0.99998, 1, 1.0003, 1, 1.00043, 1.00001, 0.99969, 1.0003, 1, 1.00035, 1.00001, 0.9995, 1, 1.00092, 0.99973, 0.99973, 0.99973, 1.0007, 0.9995, 1, 0.99924, 1.0006, 0.99924, 0.99972, 1.00062, 0.99973, 1.00114, 1.00073, 1, 0.99955, 1, 1, 1.00047, 0.99968, 1.00016, 0.99977, 1.00016, 0.99977, 1.00016, 0.99977, 1.00001, 1, 1, 1, 0.99973, 1, 1, 0.99955, 0.99924, 0.99924, 0.99924, 0.99924, 0.99998, 0.99998, 0.99998, 0.99973, 0.99973, 0.99972, 1, 1, 1.00267, 0.99999, 0.99998, 0.99998, 1, 0.99998, 1.66475, 1, 0.99973, 0.99973, 1.00023, 0.99973, 0.99971, 0.99925, 1.00023, 1, 0.99991, 0.99984, 1.00002, 1.00002, 1.00002, 1.00002, 1, 1, 1, 1, 1, 1, 1, 0.96329, 1, 1.20985, 1.39713, 1.00003, 0.8254, 1.00015, 1, 1.00035, 1.00027, 1.00031, 1.00031, 0.99915, 1.00031, 1.00031, 0.99999, 1.00003, 0.99999, 0.99999, 1.41144, 1.6, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.40579, 1.40579, 1.36625, 0.99999, 1, 0.99861, 0.99861, 1, 1.00026, 1.00026, 1.00026, 1.00026, 0.95317, 0.99999, 0.99999, 0.99999, 0.99999, 1.40483, 1, 0.99977, 1.00054, 1, 1, 0.99953, 0.99962, 1.00042, 0.9995, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28053const HelveticaRegularMetrics = { 28054 lineHeight: 1.2, 28055 lineGap: 0.2 28056}; 28057 28058;// ./src/core/liberationsans_widths.js 28059const LiberationSansBoldWidths = [365, 0, 333, 278, 333, 474, 556, 556, 889, 722, 238, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 333, 333, 584, 584, 584, 611, 975, 722, 722, 722, 722, 667, 611, 778, 722, 278, 556, 722, 611, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 333, 278, 333, 584, 556, 333, 556, 611, 556, 611, 556, 333, 611, 611, 278, 278, 556, 278, 889, 611, 611, 611, 611, 389, 556, 333, 611, 556, 778, 556, 556, 500, 389, 280, 389, 584, 333, 556, 556, 556, 556, 280, 556, 333, 737, 370, 556, 584, 737, 552, 400, 549, 333, 333, 333, 576, 556, 278, 333, 333, 365, 556, 834, 834, 834, 611, 722, 722, 722, 722, 722, 722, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278, 722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611, 556, 556, 556, 556, 556, 556, 889, 556, 556, 556, 556, 556, 278, 278, 278, 278, 611, 611, 611, 611, 611, 611, 611, 549, 611, 611, 611, 611, 611, 556, 611, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 719, 722, 611, 667, 556, 667, 556, 667, 556, 667, 556, 667, 556, 778, 611, 778, 611, 778, 611, 778, 611, 722, 611, 722, 611, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 785, 556, 556, 278, 722, 556, 556, 611, 278, 611, 278, 611, 385, 611, 479, 611, 278, 722, 611, 722, 611, 722, 611, 708, 723, 611, 778, 611, 778, 611, 778, 611, 1000, 944, 722, 389, 722, 389, 722, 389, 667, 556, 667, 556, 667, 556, 667, 556, 611, 333, 611, 479, 611, 333, 722, 611, 722, 611, 722, 611, 722, 611, 722, 611, 722, 611, 944, 778, 667, 556, 667, 611, 500, 611, 500, 611, 500, 278, 556, 722, 556, 1000, 889, 778, 611, 667, 556, 611, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 465, 722, 333, 853, 906, 474, 825, 927, 838, 278, 722, 722, 601, 719, 667, 611, 722, 778, 278, 722, 667, 833, 722, 644, 778, 722, 667, 600, 611, 667, 821, 667, 809, 802, 278, 667, 615, 451, 611, 278, 582, 615, 610, 556, 606, 475, 460, 611, 541, 278, 558, 556, 612, 556, 445, 611, 766, 619, 520, 684, 446, 582, 715, 576, 753, 845, 278, 582, 611, 582, 845, 667, 669, 885, 567, 711, 667, 278, 276, 556, 1094, 1062, 875, 610, 722, 622, 719, 722, 719, 722, 567, 712, 667, 904, 626, 719, 719, 610, 702, 833, 722, 778, 719, 667, 722, 611, 622, 854, 667, 730, 703, 1005, 1019, 870, 979, 719, 711, 1031, 719, 556, 618, 615, 417, 635, 556, 709, 497, 615, 615, 500, 635, 740, 604, 611, 604, 611, 556, 490, 556, 875, 556, 615, 581, 833, 844, 729, 854, 615, 552, 854, 583, 556, 556, 611, 417, 552, 556, 278, 281, 278, 969, 906, 611, 500, 615, 556, 604, 778, 611, 487, 447, 944, 778, 944, 778, 944, 778, 667, 556, 333, 333, 556, 1000, 1000, 552, 278, 278, 278, 278, 500, 500, 500, 556, 556, 350, 1000, 1000, 240, 479, 333, 333, 604, 333, 167, 396, 556, 556, 1094, 556, 885, 489, 1115, 1000, 768, 600, 834, 834, 834, 834, 1000, 500, 1000, 500, 1000, 500, 500, 494, 612, 823, 713, 584, 549, 713, 979, 722, 274, 549, 549, 583, 549, 549, 604, 584, 604, 604, 708, 625, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 729, 604, 604, 354, 354, 1000, 990, 990, 990, 990, 494, 604, 604, 604, 604, 354, 1021, 1052, 917, 750, 750, 531, 656, 594, 510, 500, 750, 750, 611, 611, 333, 333, 333, 333, 333, 333, 333, 333, 222, 222, 333, 333, 333, 333, 333, 333, 333, 333]; 28060const LiberationSansBoldMapping = [-1, -1, -1, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 402, 506, 507, 508, 509, 510, 511, 536, 537, 538, 539, 710, 711, 713, 728, 729, 730, 731, 732, 733, 900, 901, 902, 903, 904, 905, 906, 908, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1138, 1139, 1168, 1169, 7808, 7809, 7810, 7811, 7812, 7813, 7922, 7923, 8208, 8209, 8211, 8212, 8213, 8215, 8216, 8217, 8218, 8219, 8220, 8221, 8222, 8224, 8225, 8226, 8230, 8240, 8242, 8243, 8249, 8250, 8252, 8254, 8260, 8319, 8355, 8356, 8359, 8364, 8453, 8467, 8470, 8482, 8486, 8494, 8539, 8540, 8541, 8542, 8592, 8593, 8594, 8595, 8596, 8597, 8616, 8706, 8710, 8719, 8721, 8722, 8730, 8734, 8735, 8745, 8747, 8776, 8800, 8801, 8804, 8805, 8962, 8976, 8992, 8993, 9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508, 9516, 9524, 9532, 9552, 9553, 9554, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566, 9567, 9568, 9569, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 9600, 9604, 9608, 9612, 9616, 9617, 9618, 9619, 9632, 9633, 9642, 9643, 9644, 9650, 9658, 9660, 9668, 9674, 9675, 9679, 9688, 9689, 9702, 9786, 9787, 9788, 9792, 9794, 9824, 9827, 9829, 9830, 9834, 9835, 9836, 61441, 61442, 61445, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]; 28061const LiberationSansBoldItalicWidths = [365, 0, 333, 278, 333, 474, 556, 556, 889, 722, 238, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 333, 333, 584, 584, 584, 611, 975, 722, 722, 722, 722, 667, 611, 778, 722, 278, 556, 722, 611, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 333, 278, 333, 584, 556, 333, 556, 611, 556, 611, 556, 333, 611, 611, 278, 278, 556, 278, 889, 611, 611, 611, 611, 389, 556, 333, 611, 556, 778, 556, 556, 500, 389, 280, 389, 584, 333, 556, 556, 556, 556, 280, 556, 333, 737, 370, 556, 584, 737, 552, 400, 549, 333, 333, 333, 576, 556, 278, 333, 333, 365, 556, 834, 834, 834, 611, 722, 722, 722, 722, 722, 722, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278, 722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611, 556, 556, 556, 556, 556, 556, 889, 556, 556, 556, 556, 556, 278, 278, 278, 278, 611, 611, 611, 611, 611, 611, 611, 549, 611, 611, 611, 611, 611, 556, 611, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 740, 722, 611, 667, 556, 667, 556, 667, 556, 667, 556, 667, 556, 778, 611, 778, 611, 778, 611, 778, 611, 722, 611, 722, 611, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 782, 556, 556, 278, 722, 556, 556, 611, 278, 611, 278, 611, 396, 611, 479, 611, 278, 722, 611, 722, 611, 722, 611, 708, 723, 611, 778, 611, 778, 611, 778, 611, 1000, 944, 722, 389, 722, 389, 722, 389, 667, 556, 667, 556, 667, 556, 667, 556, 611, 333, 611, 479, 611, 333, 722, 611, 722, 611, 722, 611, 722, 611, 722, 611, 722, 611, 944, 778, 667, 556, 667, 611, 500, 611, 500, 611, 500, 278, 556, 722, 556, 1000, 889, 778, 611, 667, 556, 611, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 722, 333, 854, 906, 473, 844, 930, 847, 278, 722, 722, 610, 671, 667, 611, 722, 778, 278, 722, 667, 833, 722, 657, 778, 718, 667, 590, 611, 667, 822, 667, 829, 781, 278, 667, 620, 479, 611, 278, 591, 620, 621, 556, 610, 479, 492, 611, 558, 278, 566, 556, 603, 556, 450, 611, 712, 605, 532, 664, 409, 591, 704, 578, 773, 834, 278, 591, 611, 591, 834, 667, 667, 886, 614, 719, 667, 278, 278, 556, 1094, 1042, 854, 622, 719, 677, 719, 722, 708, 722, 614, 722, 667, 927, 643, 719, 719, 615, 687, 833, 722, 778, 719, 667, 722, 611, 677, 781, 667, 729, 708, 979, 989, 854, 1000, 708, 719, 1042, 729, 556, 619, 604, 534, 618, 556, 736, 510, 611, 611, 507, 622, 740, 604, 611, 611, 611, 556, 889, 556, 885, 556, 646, 583, 889, 935, 707, 854, 594, 552, 865, 589, 556, 556, 611, 469, 563, 556, 278, 278, 278, 969, 906, 611, 507, 619, 556, 611, 778, 611, 575, 467, 944, 778, 944, 778, 944, 778, 667, 556, 333, 333, 556, 1000, 1000, 552, 278, 278, 278, 278, 500, 500, 500, 556, 556, 350, 1000, 1000, 240, 479, 333, 333, 604, 333, 167, 396, 556, 556, 1104, 556, 885, 516, 1146, 1000, 768, 600, 834, 834, 834, 834, 999, 500, 1000, 500, 1000, 500, 500, 494, 612, 823, 713, 584, 549, 713, 979, 722, 274, 549, 549, 583, 549, 549, 604, 584, 604, 604, 708, 625, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 729, 604, 604, 354, 354, 1000, 990, 990, 990, 990, 494, 604, 604, 604, 604, 354, 1021, 1052, 917, 750, 750, 531, 656, 594, 510, 500, 750, 750, 611, 611, 333, 333, 333, 333, 333, 333, 333, 333, 222, 222, 333, 333, 333, 333, 333, 333, 333, 333]; 28062const LiberationSansBoldItalicMapping = [-1, -1, -1, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 402, 506, 507, 508, 509, 510, 511, 536, 537, 538, 539, 710, 711, 713, 728, 729, 730, 731, 732, 733, 900, 901, 902, 903, 904, 905, 906, 908, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1138, 1139, 1168, 1169, 7808, 7809, 7810, 7811, 7812, 7813, 7922, 7923, 8208, 8209, 8211, 8212, 8213, 8215, 8216, 8217, 8218, 8219, 8220, 8221, 8222, 8224, 8225, 8226, 8230, 8240, 8242, 8243, 8249, 8250, 8252, 8254, 8260, 8319, 8355, 8356, 8359, 8364, 8453, 8467, 8470, 8482, 8486, 8494, 8539, 8540, 8541, 8542, 8592, 8593, 8594, 8595, 8596, 8597, 8616, 8706, 8710, 8719, 8721, 8722, 8730, 8734, 8735, 8745, 8747, 8776, 8800, 8801, 8804, 8805, 8962, 8976, 8992, 8993, 9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508, 9516, 9524, 9532, 9552, 9553, 9554, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566, 9567, 9568, 9569, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 9600, 9604, 9608, 9612, 9616, 9617, 9618, 9619, 9632, 9633, 9642, 9643, 9644, 9650, 9658, 9660, 9668, 9674, 9675, 9679, 9688, 9689, 9702, 9786, 9787, 9788, 9792, 9794, 9824, 9827, 9829, 9830, 9834, 9835, 9836, 61441, 61442, 61445, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]; 28063const LiberationSansItalicWidths = [365, 0, 333, 278, 278, 355, 556, 556, 889, 667, 191, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 278, 278, 584, 584, 584, 556, 1015, 667, 667, 722, 722, 667, 611, 778, 722, 278, 500, 667, 556, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556, 333, 556, 556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556, 556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334, 584, 333, 556, 556, 556, 556, 260, 556, 333, 737, 370, 556, 584, 737, 552, 400, 549, 333, 333, 333, 576, 537, 278, 333, 333, 365, 556, 834, 834, 834, 611, 667, 667, 667, 667, 667, 667, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278, 722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611, 556, 556, 556, 556, 556, 556, 889, 500, 556, 556, 556, 556, 278, 278, 278, 278, 556, 556, 556, 556, 556, 556, 556, 549, 611, 556, 556, 556, 556, 500, 556, 500, 667, 556, 667, 556, 667, 556, 722, 500, 722, 500, 722, 500, 722, 500, 722, 625, 722, 556, 667, 556, 667, 556, 667, 556, 667, 556, 667, 556, 778, 556, 778, 556, 778, 556, 778, 556, 722, 556, 722, 556, 278, 278, 278, 278, 278, 278, 278, 222, 278, 278, 733, 444, 500, 222, 667, 500, 500, 556, 222, 556, 222, 556, 281, 556, 400, 556, 222, 722, 556, 722, 556, 722, 556, 615, 723, 556, 778, 556, 778, 556, 778, 556, 1000, 944, 722, 333, 722, 333, 722, 333, 667, 500, 667, 500, 667, 500, 667, 500, 611, 278, 611, 354, 611, 278, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 944, 722, 667, 500, 667, 611, 500, 611, 500, 611, 500, 222, 556, 667, 556, 1000, 889, 778, 611, 667, 500, 611, 278, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 667, 278, 789, 846, 389, 794, 865, 775, 222, 667, 667, 570, 671, 667, 611, 722, 778, 278, 667, 667, 833, 722, 648, 778, 725, 667, 600, 611, 667, 837, 667, 831, 761, 278, 667, 570, 439, 555, 222, 550, 570, 571, 500, 556, 439, 463, 555, 542, 222, 500, 492, 548, 500, 447, 556, 670, 573, 486, 603, 374, 550, 652, 546, 728, 779, 222, 550, 556, 550, 779, 667, 667, 843, 544, 708, 667, 278, 278, 500, 1066, 982, 844, 589, 715, 639, 724, 667, 651, 667, 544, 704, 667, 917, 614, 715, 715, 589, 686, 833, 722, 778, 725, 667, 722, 611, 639, 795, 667, 727, 673, 920, 923, 805, 886, 651, 694, 1022, 682, 556, 562, 522, 493, 553, 556, 688, 465, 556, 556, 472, 564, 686, 550, 556, 556, 556, 500, 833, 500, 835, 500, 572, 518, 830, 851, 621, 736, 526, 492, 752, 534, 556, 556, 556, 378, 496, 500, 222, 222, 222, 910, 828, 556, 472, 565, 500, 556, 778, 556, 492, 339, 944, 722, 944, 722, 944, 722, 667, 500, 333, 333, 556, 1000, 1000, 552, 222, 222, 222, 222, 333, 333, 333, 556, 556, 350, 1000, 1000, 188, 354, 333, 333, 500, 333, 167, 365, 556, 556, 1094, 556, 885, 323, 1083, 1000, 768, 600, 834, 834, 834, 834, 1000, 500, 998, 500, 1000, 500, 500, 494, 612, 823, 713, 584, 549, 713, 979, 719, 274, 549, 549, 584, 549, 549, 604, 584, 604, 604, 708, 625, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 729, 604, 604, 354, 354, 1000, 990, 990, 990, 990, 494, 604, 604, 604, 604, 354, 1021, 1052, 917, 750, 750, 531, 656, 594, 510, 500, 750, 750, 500, 500, 333, 333, 333, 333, 333, 333, 333, 333, 222, 222, 294, 294, 324, 324, 316, 328, 398, 285]; 28064const LiberationSansItalicMapping = [-1, -1, -1, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 402, 506, 507, 508, 509, 510, 511, 536, 537, 538, 539, 710, 711, 713, 728, 729, 730, 731, 732, 733, 900, 901, 902, 903, 904, 905, 906, 908, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1138, 1139, 1168, 1169, 7808, 7809, 7810, 7811, 7812, 7813, 7922, 7923, 8208, 8209, 8211, 8212, 8213, 8215, 8216, 8217, 8218, 8219, 8220, 8221, 8222, 8224, 8225, 8226, 8230, 8240, 8242, 8243, 8249, 8250, 8252, 8254, 8260, 8319, 8355, 8356, 8359, 8364, 8453, 8467, 8470, 8482, 8486, 8494, 8539, 8540, 8541, 8542, 8592, 8593, 8594, 8595, 8596, 8597, 8616, 8706, 8710, 8719, 8721, 8722, 8730, 8734, 8735, 8745, 8747, 8776, 8800, 8801, 8804, 8805, 8962, 8976, 8992, 8993, 9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508, 9516, 9524, 9532, 9552, 9553, 9554, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566, 9567, 9568, 9569, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 9600, 9604, 9608, 9612, 9616, 9617, 9618, 9619, 9632, 9633, 9642, 9643, 9644, 9650, 9658, 9660, 9668, 9674, 9675, 9679, 9688, 9689, 9702, 9786, 9787, 9788, 9792, 9794, 9824, 9827, 9829, 9830, 9834, 9835, 9836, 61441, 61442, 61445, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]; 28065const LiberationSansRegularWidths = [365, 0, 333, 278, 278, 355, 556, 556, 889, 667, 191, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 278, 278, 584, 584, 584, 556, 1015, 667, 667, 722, 722, 667, 611, 778, 722, 278, 500, 667, 556, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556, 333, 556, 556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556, 556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334, 584, 333, 556, 556, 556, 556, 260, 556, 333, 737, 370, 556, 584, 737, 552, 400, 549, 333, 333, 333, 576, 537, 278, 333, 333, 365, 556, 834, 834, 834, 611, 667, 667, 667, 667, 667, 667, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278, 722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611, 556, 556, 556, 556, 556, 556, 889, 500, 556, 556, 556, 556, 278, 278, 278, 278, 556, 556, 556, 556, 556, 556, 556, 549, 611, 556, 556, 556, 556, 500, 556, 500, 667, 556, 667, 556, 667, 556, 722, 500, 722, 500, 722, 500, 722, 500, 722, 615, 722, 556, 667, 556, 667, 556, 667, 556, 667, 556, 667, 556, 778, 556, 778, 556, 778, 556, 778, 556, 722, 556, 722, 556, 278, 278, 278, 278, 278, 278, 278, 222, 278, 278, 735, 444, 500, 222, 667, 500, 500, 556, 222, 556, 222, 556, 292, 556, 334, 556, 222, 722, 556, 722, 556, 722, 556, 604, 723, 556, 778, 556, 778, 556, 778, 556, 1000, 944, 722, 333, 722, 333, 722, 333, 667, 500, 667, 500, 667, 500, 667, 500, 611, 278, 611, 375, 611, 278, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 944, 722, 667, 500, 667, 611, 500, 611, 500, 611, 500, 222, 556, 667, 556, 1000, 889, 778, 611, 667, 500, 611, 278, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 667, 278, 784, 838, 384, 774, 855, 752, 222, 667, 667, 551, 668, 667, 611, 722, 778, 278, 667, 668, 833, 722, 650, 778, 722, 667, 618, 611, 667, 798, 667, 835, 748, 278, 667, 578, 446, 556, 222, 547, 578, 575, 500, 557, 446, 441, 556, 556, 222, 500, 500, 576, 500, 448, 556, 690, 569, 482, 617, 395, 547, 648, 525, 713, 781, 222, 547, 556, 547, 781, 667, 667, 865, 542, 719, 667, 278, 278, 500, 1057, 1010, 854, 583, 722, 635, 719, 667, 656, 667, 542, 677, 667, 923, 604, 719, 719, 583, 656, 833, 722, 778, 719, 667, 722, 611, 635, 760, 667, 740, 667, 917, 938, 792, 885, 656, 719, 1010, 722, 556, 573, 531, 365, 583, 556, 669, 458, 559, 559, 438, 583, 688, 552, 556, 542, 556, 500, 458, 500, 823, 500, 573, 521, 802, 823, 625, 719, 521, 510, 750, 542, 556, 556, 556, 365, 510, 500, 222, 278, 222, 906, 812, 556, 438, 559, 500, 552, 778, 556, 489, 411, 944, 722, 944, 722, 944, 722, 667, 500, 333, 333, 556, 1000, 1000, 552, 222, 222, 222, 222, 333, 333, 333, 556, 556, 350, 1000, 1000, 188, 354, 333, 333, 500, 333, 167, 365, 556, 556, 1094, 556, 885, 323, 1073, 1000, 768, 600, 834, 834, 834, 834, 1000, 500, 1000, 500, 1000, 500, 500, 494, 612, 823, 713, 584, 549, 713, 979, 719, 274, 549, 549, 583, 549, 549, 604, 584, 604, 604, 708, 625, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 729, 604, 604, 354, 354, 1000, 990, 990, 990, 990, 494, 604, 604, 604, 604, 354, 1021, 1052, 917, 750, 750, 531, 656, 594, 510, 500, 750, 750, 500, 500, 333, 333, 333, 333, 333, 333, 333, 333, 222, 222, 294, 294, 324, 324, 316, 328, 398, 285]; 28066const LiberationSansRegularMapping = [-1, -1, -1, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 402, 506, 507, 508, 509, 510, 511, 536, 537, 538, 539, 710, 711, 713, 728, 729, 730, 731, 732, 733, 900, 901, 902, 903, 904, 905, 906, 908, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1138, 1139, 1168, 1169, 7808, 7809, 7810, 7811, 7812, 7813, 7922, 7923, 8208, 8209, 8211, 8212, 8213, 8215, 8216, 8217, 8218, 8219, 8220, 8221, 8222, 8224, 8225, 8226, 8230, 8240, 8242, 8243, 8249, 8250, 8252, 8254, 8260, 8319, 8355, 8356, 8359, 8364, 8453, 8467, 8470, 8482, 8486, 8494, 8539, 8540, 8541, 8542, 8592, 8593, 8594, 8595, 8596, 8597, 8616, 8706, 8710, 8719, 8721, 8722, 8730, 8734, 8735, 8745, 8747, 8776, 8800, 8801, 8804, 8805, 8962, 8976, 8992, 8993, 9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508, 9516, 9524, 9532, 9552, 9553, 9554, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566, 9567, 9568, 9569, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 9600, 9604, 9608, 9612, 9616, 9617, 9618, 9619, 9632, 9633, 9642, 9643, 9644, 9650, 9658, 9660, 9668, 9674, 9675, 9679, 9688, 9689, 9702, 9786, 9787, 9788, 9792, 9794, 9824, 9827, 9829, 9830, 9834, 9835, 9836, 61441, 61442, 61445, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]; 28067 28068;// ./src/core/myriadpro_factors.js 28069const MyriadProBoldFactors = [1.36898, 1, 1, 0.72706, 0.80479, 0.83734, 0.98894, 0.99793, 0.9897, 0.93884, 0.86209, 0.94292, 0.94292, 1.16661, 1.02058, 0.93582, 0.96694, 0.93582, 1.19137, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.78076, 0.78076, 1.02058, 1.02058, 1.02058, 0.72851, 0.78966, 0.90838, 0.83637, 0.82391, 0.96376, 0.80061, 0.86275, 0.8768, 0.95407, 1.0258, 0.73901, 0.85022, 0.83655, 1.0156, 0.95546, 0.92179, 0.87107, 0.92179, 0.82114, 0.8096, 0.89713, 0.94438, 0.95353, 0.94083, 0.91905, 0.90406, 0.9446, 0.94292, 1.18777, 0.94292, 1.02058, 0.89903, 0.90088, 0.94938, 0.97898, 0.81093, 0.97571, 0.94938, 1.024, 0.9577, 0.95933, 0.98621, 1.0474, 0.97455, 0.98981, 0.9672, 0.95933, 0.9446, 0.97898, 0.97407, 0.97646, 0.78036, 1.10208, 0.95442, 0.95298, 0.97579, 0.9332, 0.94039, 0.938, 0.80687, 1.01149, 0.80687, 1.02058, 0.80479, 0.99793, 0.99793, 0.99793, 0.99793, 1.01149, 1.00872, 0.90088, 0.91882, 1.0213, 0.8361, 1.02058, 0.62295, 0.54324, 0.89022, 1.08595, 1, 1, 0.90088, 1, 0.97455, 0.93582, 0.90088, 1, 1.05686, 0.8361, 0.99642, 0.99642, 0.99642, 0.72851, 0.90838, 0.90838, 0.90838, 0.90838, 0.90838, 0.90838, 0.868, 0.82391, 0.80061, 0.80061, 0.80061, 0.80061, 1.0258, 1.0258, 1.0258, 1.0258, 0.97484, 0.95546, 0.92179, 0.92179, 0.92179, 0.92179, 0.92179, 1.02058, 0.92179, 0.94438, 0.94438, 0.94438, 0.94438, 0.90406, 0.86958, 0.98225, 0.94938, 0.94938, 0.94938, 0.94938, 0.94938, 0.94938, 0.9031, 0.81093, 0.94938, 0.94938, 0.94938, 0.94938, 0.98621, 0.98621, 0.98621, 0.98621, 0.93969, 0.95933, 0.9446, 0.9446, 0.9446, 0.9446, 0.9446, 1.08595, 0.9446, 0.95442, 0.95442, 0.95442, 0.95442, 0.94039, 0.97898, 0.94039, 0.90838, 0.94938, 0.90838, 0.94938, 0.90838, 0.94938, 0.82391, 0.81093, 0.82391, 0.81093, 0.82391, 0.81093, 0.82391, 0.81093, 0.96376, 0.84313, 0.97484, 0.97571, 0.80061, 0.94938, 0.80061, 0.94938, 0.80061, 0.94938, 0.80061, 0.94938, 0.80061, 0.94938, 0.8768, 0.9577, 0.8768, 0.9577, 0.8768, 0.9577, 1, 1, 0.95407, 0.95933, 0.97069, 0.95933, 1.0258, 0.98621, 1.0258, 0.98621, 1.0258, 0.98621, 1.0258, 0.98621, 1.0258, 0.98621, 0.887, 1.01591, 0.73901, 1.0474, 1, 1, 0.97455, 0.83655, 0.98981, 1, 1, 0.83655, 0.73977, 0.83655, 0.73903, 0.84638, 1.033, 0.95546, 0.95933, 1, 1, 0.95546, 0.95933, 0.8271, 0.95417, 0.95933, 0.92179, 0.9446, 0.92179, 0.9446, 0.92179, 0.9446, 0.936, 0.91964, 0.82114, 0.97646, 1, 1, 0.82114, 0.97646, 0.8096, 0.78036, 0.8096, 0.78036, 1, 1, 0.8096, 0.78036, 1, 1, 0.89713, 0.77452, 0.89713, 1.10208, 0.94438, 0.95442, 0.94438, 0.95442, 0.94438, 0.95442, 0.94438, 0.95442, 0.94438, 0.95442, 0.94438, 0.95442, 0.94083, 0.97579, 0.90406, 0.94039, 0.90406, 0.9446, 0.938, 0.9446, 0.938, 0.9446, 0.938, 1, 0.99793, 0.90838, 0.94938, 0.868, 0.9031, 0.92179, 0.9446, 1, 1, 0.89713, 1.10208, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90989, 0.9358, 0.91945, 0.83181, 0.75261, 0.87992, 0.82976, 0.96034, 0.83689, 0.97268, 1.0078, 0.90838, 0.83637, 0.8019, 0.90157, 0.80061, 0.9446, 0.95407, 0.92436, 1.0258, 0.85022, 0.97153, 1.0156, 0.95546, 0.89192, 0.92179, 0.92361, 0.87107, 0.96318, 0.89713, 0.93704, 0.95638, 0.91905, 0.91709, 0.92796, 1.0258, 0.93704, 0.94836, 1.0373, 0.95933, 1.0078, 0.95871, 0.94836, 0.96174, 0.92601, 0.9498, 0.98607, 0.95776, 0.95933, 1.05453, 1.0078, 0.98275, 0.9314, 0.95617, 0.91701, 1.05993, 0.9446, 0.78367, 0.9553, 1, 0.86832, 1.0128, 0.95871, 0.99394, 0.87548, 0.96361, 0.86774, 1.0078, 0.95871, 0.9446, 0.95871, 0.86774, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.94083, 0.97579, 0.94083, 0.97579, 0.94083, 0.97579, 0.90406, 0.94039, 0.96694, 1, 0.89903, 1, 1, 1, 0.93582, 0.93582, 0.93582, 1, 0.908, 0.908, 0.918, 0.94219, 0.94219, 0.96544, 1, 1.285, 1, 1, 0.81079, 0.81079, 1, 1, 0.74854, 1, 1, 1, 1, 0.99793, 1, 1, 1, 0.65, 1, 1.36145, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.17173, 1, 0.80535, 0.76169, 1.02058, 1.0732, 1.05486, 1, 1, 1.30692, 1.08595, 1.08595, 1, 1.08595, 1.08595, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.16161, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28070const MyriadProBoldMetrics = { 28071 lineHeight: 1.2, 28072 lineGap: 0.2 28073}; 28074const MyriadProBoldItalicFactors = [1.36898, 1, 1, 0.66227, 0.80779, 0.81625, 0.97276, 0.97276, 0.97733, 0.92222, 0.83266, 0.94292, 0.94292, 1.16148, 1.02058, 0.93582, 0.96694, 0.93582, 1.17337, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.78076, 0.78076, 1.02058, 1.02058, 1.02058, 0.71541, 0.76813, 0.85576, 0.80591, 0.80729, 0.94299, 0.77512, 0.83655, 0.86523, 0.92222, 0.9862
vendor: 1,447 bytes, line 28074
280741, 0.71743, 0.81698, 0.79726, 0.98558, 0.92222, 0.90637, 0.83809, 0.90637, 0.80729, 0.76463, 0.86275, 0.90699, 0.91605, 0.9154, 0.85308, 0.85458, 0.90531, 0.94292, 1.21296, 0.94292, 1.02058, 0.89903, 1.18616, 0.99613, 0.91677, 0.78216, 0.91677, 0.90083, 0.98796, 0.9135, 0.92168, 0.95381, 0.98981, 0.95298, 0.95381, 0.93459, 0.92168, 0.91513, 0.92004, 0.91677, 0.95077, 0.748, 1.04502, 0.91677, 0.92061, 0.94236, 0.89544, 0.89364, 0.9, 0.80687, 0.8578, 0.80687, 1.02058, 0.80779, 0.97276, 0.97276, 0.97276, 0.97276, 0.8578, 0.99973, 1.18616, 0.91339, 1.08074, 0.82891, 1.02058, 0.55509, 0.71526, 0.89022, 1.08595, 1, 1, 1.18616, 1, 0.96736, 0.93582, 1.18616, 1, 1.04864, 0.82711, 0.99043, 0.99043, 0.99043, 0.71541, 0.85576, 0.85576, 0.85576, 0.85576, 0.85576, 0.85576, 0.845, 0.80729, 0.77512, 0.77512, 0.77512, 0.77512, 0.98621, 0.98621, 0.98621, 0.98621, 0.95961, 0.92222, 0.90637, 0.90637, 0.90637, 0.90637, 0.90637, 1.02058, 0.90251, 0.90699, 0.90699, 0.90699, 0.90699, 0.85458, 0.83659, 0.94951, 0.99613, 0.99613, 0.99613, 0.99613, 0.99613, 0.99613, 0.85811, 0.78216, 0.90083, 0.90083, 0.90083, 0.90083, 0.95381, 0.95381, 0.95381, 0.95381, 0.9135, 0.92168, 0.91513, 0.91513, 0.91513, 0.91513, 0.91513, 1.08595, 0.91677, 0.91677, 0.91677, 0.91677, 0.91677, 0.89364, 0.92332, 0.89364, 0.85576, 0.99613, 0.85576, 0.99613, 0.85576, 0.99613, 0.80729, 0.78216, 0.80729, 0.78216, 0.80729, 0.78216, 0.80729, 0.78216, 0.94299, 0.76783, 0.95961, 0.916
vendor: 38,091 bytes, lines 28074-28310
2807477, 0.77512, 0.90083, 0.77512, 0.90083, 0.77512, 0.90083, 0.77512, 0.90083, 0.77512, 0.90083, 0.86523, 0.9135, 0.86523, 0.9135, 0.86523, 0.9135, 1, 1, 0.92222, 0.92168, 0.92222, 0.92168, 0.98621, 0.95381, 0.98621, 0.95381, 0.98621, 0.95381, 0.98621, 0.95381, 0.98621, 0.95381, 0.86036, 0.97096, 0.71743, 0.98981, 1, 1, 0.95298, 0.79726, 0.95381, 1, 1, 0.79726, 0.6894, 0.79726, 0.74321, 0.81691, 1.0006, 0.92222, 0.92168, 1, 1, 0.92222, 0.92168, 0.79464, 0.92098, 0.92168, 0.90637, 0.91513, 0.90637, 0.91513, 0.90637, 0.91513, 0.909, 0.87514, 0.80729, 0.95077, 1, 1, 0.80729, 0.95077, 0.76463, 0.748, 0.76463, 0.748, 1, 1, 0.76463, 0.748, 1, 1, 0.86275, 0.72651, 0.86275, 1.04502, 0.90699, 0.91677, 0.90699, 0.91677, 0.90699, 0.91677, 0.90699, 0.91677, 0.90699, 0.91677, 0.90699, 0.91677, 0.9154, 0.94236, 0.85458, 0.89364, 0.85458, 0.90531, 0.9, 0.90531, 0.9, 0.90531, 0.9, 1, 0.97276, 0.85576, 0.99613, 0.845, 0.85811, 0.90251, 0.91677, 1, 1, 0.86275, 1.04502, 1.18616, 1.18616, 1.18616, 1.18616, 1.18616, 1.18616, 1.18616, 1.18616, 1.18616, 1.00899, 1.30628, 0.85576, 0.80178, 0.66862, 0.7927, 0.69323, 0.88127, 0.72459, 0.89711, 0.95381, 0.85576, 0.80591, 0.7805, 0.94729, 0.77512, 0.90531, 0.92222, 0.90637, 0.98621, 0.81698, 0.92655, 0.98558, 0.92222, 0.85359, 0.90637, 0.90976, 0.83809, 0.94523, 0.86275, 0.83509, 0.93157, 0.85308, 0.83392, 0.92346, 0.98621, 0.83509, 0.92886, 0.91324, 0.92168, 0.95381, 0.90646, 0.92886, 0.90557, 0.86847, 0.90276, 0.91324, 0.86842, 0.92168, 0.99531, 0.95381, 0.9224, 0.85408, 0.92699, 0.86847, 1.0051, 0.91513, 0.80487, 0.93481, 1, 0.88159, 1.05214, 0.90646, 0.97355, 0.81539, 0.89398, 0.85923, 0.95381, 0.90646, 0.91513, 0.90646, 0.85923, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9154, 0.94236, 0.9154, 0.94236, 0.9154, 0.94236, 0.85458, 0.89364, 0.96694, 1, 0.89903, 1, 1, 1, 0.91782, 0.91782, 0.91782, 1, 0.896, 0.896, 0.896, 0.9332, 0.9332, 0.95973, 1, 1.26, 1, 1, 0.80479, 0.80178, 1, 1, 0.85633, 1, 1, 1, 1, 0.97276, 1, 1, 1, 0.698, 1, 1.36145, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.14542, 1, 0.79199, 0.78694, 1.02058, 1.03493, 1.05486, 1, 1, 1.23026, 1.08595, 1.08595, 1, 1.08595, 1.08595, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.20006, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28075const MyriadProBoldItalicMetrics = { 28076 lineHeight: 1.2, 28077 lineGap: 0.2 28078}; 28079const MyriadProItalicFactors = [1.36898, 1, 1, 0.65507, 0.84943, 0.85639, 0.88465, 0.88465, 0.86936, 0.88307, 0.86948, 0.85283, 0.85283, 1.06383, 1.02058, 0.75945, 0.9219, 0.75945, 1.17337, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.75945, 0.75945, 1.02058, 1.02058, 1.02058, 0.69046, 0.70926, 0.85158, 0.77812, 0.76852, 0.89591, 0.70466, 0.76125, 0.80094, 0.86822, 0.83864, 0.728, 0.77212, 0.79475, 0.93637, 0.87514, 0.8588, 0.76013, 0.8588, 0.72421, 0.69866, 0.77598, 0.85991, 0.80811, 0.87832, 0.78112, 0.77512, 0.8562, 1.0222, 1.18417, 1.0222, 1.27014, 0.89903, 1.15012, 0.93859, 0.94399, 0.846, 0.94399, 0.81453, 1.0186, 0.94219, 0.96017, 1.03075, 1.02175, 0.912, 1.03075, 0.96998, 0.96017, 0.93859, 0.94399, 0.94399, 0.95493, 0.746, 1.12658, 0.94578, 0.91, 0.979, 0.882, 0.882, 0.83, 0.85034, 0.83537, 0.85034, 1.02058, 0.70869, 0.88465, 0.88465, 0.88465, 0.88465, 0.83537, 0.90083, 1.15012, 0.9161, 0.94565, 0.73541, 1.02058, 0.53609, 0.69353, 0.79519, 1.08595, 1, 1, 1.15012, 1, 0.91974, 0.75945, 1.15012, 1, 0.9446, 0.73361, 0.9005, 0.9005, 0.9005, 0.62864, 0.85158, 0.85158, 0.85158, 0.85158, 0.85158, 0.85158, 0.773, 0.76852, 0.70466, 0.70466, 0.70466, 0.70466, 0.83864, 0.83864, 0.83864, 0.83864, 0.90561, 0.87514, 0.8588, 0.8588, 0.8588, 0.8588, 0.8588, 1.02058, 0.85751, 0.85991, 0.85991, 0.85991, 0.85991, 0.77512, 0.76013, 0.88075, 0.93859, 0.93859, 0.93859, 0.93859, 0.93859, 0.93859, 0.8075, 0.846, 0.81453, 0.81453, 0.81453, 0.81453, 0.82424, 0.82424, 0.82424, 0.82424, 0.9278, 0.96017, 0.93859, 0.93859, 0.93859, 0.93859, 0.93859, 1.08595, 0.8562, 0.94578, 0.94578, 0.94578, 0.94578, 0.882, 0.94578, 0.882, 0.85158, 0.93859, 0.85158, 0.93859, 0.85158, 0.93859, 0.76852, 0.846, 0.76852, 0.846, 0.76852, 0.846, 0.76852, 0.846, 0.89591, 0.8544, 0.90561, 0.94399, 0.70466, 0.81453, 0.70466, 0.81453, 0.70466, 0.81453, 0.70466, 0.81453, 0.70466, 0.81453, 0.80094, 0.94219, 0.80094, 0.94219, 0.80094, 0.94219, 1, 1, 0.86822, 0.96017, 0.86822, 0.96017, 0.83864, 0.82424, 0.83864, 0.82424, 0.83864, 0.82424, 0.83864, 1.03075, 0.83864, 0.82424, 0.81402, 1.02738, 0.728, 1.02175, 1, 1, 0.912, 0.79475, 1.03075, 1, 1, 0.79475, 0.83911, 0.79475, 0.66266, 0.80553, 1.06676, 0.87514, 0.96017, 1, 1, 0.87514, 0.96017, 0.86865, 0.87396, 0.96017, 0.8588, 0.93859, 0.8588, 0.93859, 0.8588, 0.93859, 0.867, 0.84759, 0.72421, 0.95493, 1, 1, 0.72421, 0.95493, 0.69866, 0.746, 0.69866, 0.746, 1, 1, 0.69866, 0.746, 1, 1, 0.77598, 0.88417, 0.77598, 1.12658, 0.85991, 0.94578, 0.85991, 0.94578, 0.85991, 0.94578, 0.85991, 0.94578, 0.85991, 0.94578, 0.85991, 0.94578, 0.87832, 0.979, 0.77512, 0.882, 0.77512, 0.8562, 0.83, 0.8562, 0.83, 0.8562, 0.83, 1, 0.88465, 0.85158, 0.93859, 0.773, 0.8075, 0.85751, 0.8562, 1, 1, 0.77598, 1.12658, 1.15012, 1.15012, 1.15012, 1.15012, 1.15012, 1.15313, 1.15012, 1.15012, 1.15012, 1.08106, 1.03901, 0.85158, 0.77025, 0.62264, 0.7646, 0.65351, 0.86026, 0.69461, 0.89947, 1.03075, 0.85158, 0.77812, 0.76449, 0.88836, 0.70466, 0.8562, 0.86822, 0.8588, 0.83864, 0.77212, 0.85308, 0.93637, 0.87514, 0.82352, 0.8588, 0.85701, 0.76013, 0.89058, 0.77598, 0.8156, 0.82565, 0.78112, 0.77899, 0.89386, 0.83864, 0.8156, 0.9486, 0.92388, 0.96186, 1.03075, 0.91123, 0.9486, 0.93298, 0.878, 0.93942, 0.92388, 0.84596, 0.96186, 0.95119, 1.03075, 0.922, 0.88787, 0.95829, 0.88, 0.93559, 0.93859, 0.78815, 0.93758, 1, 0.89217, 1.03737, 0.91123, 0.93969, 0.77487, 0.85769, 0.86799, 1.03075, 0.91123, 0.93859, 0.91123, 0.86799, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.87832, 0.979, 0.87832, 0.979, 0.87832, 0.979, 0.77512, 0.882, 0.9219, 1, 0.89903, 1, 1, 1, 0.87321, 0.87321, 0.87321, 1, 1.027, 1.027, 1.027, 0.86847, 0.86847, 0.79121, 1, 1.124, 1, 1, 0.73572, 0.73572, 1, 1, 0.85034, 1, 1, 1, 1, 0.88465, 1, 1, 1, 0.669, 1, 1.36145, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.04828, 1, 0.74948, 0.75187, 1.02058, 0.98391, 1.02119, 1, 1, 1.06233, 1.08595, 1.08595, 1, 1.08595, 1.08595, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.05233, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28080const MyriadProItalicMetrics = { 28081 lineHeight: 1.2, 28082 lineGap: 0.2 28083}; 28084const MyriadProRegularFactors = [1.36898, 1, 1, 0.76305, 0.82784, 0.94935, 0.89364, 0.92241, 0.89073, 0.90706, 0.98472, 0.85283, 0.85283, 1.0664, 1.02058, 0.74505, 0.9219, 0.74505, 1.23456, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.74505, 0.74505, 1.02058, 1.02058, 1.02058, 0.73002, 0.72601, 0.91755, 0.8126, 0.80314, 0.92222, 0.73764, 0.79726, 0.83051, 0.90284, 0.86023, 0.74, 0.8126, 0.84869, 0.96518, 0.91115, 0.8858, 0.79761, 0.8858, 0.74498, 0.73914, 0.81363, 0.89591, 0.83659, 0.89633, 0.85608, 0.8111, 0.90531, 1.0222, 1.22736, 1.0222, 1.27014, 0.89903, 0.90088, 0.86667, 1.0231, 0.896, 1.01411, 0.90083, 1.05099, 1.00512, 0.99793, 1.05326, 1.09377, 0.938, 1.06226, 1.00119, 0.99793, 0.98714, 1.0231, 1.01231, 0.98196, 0.792, 1.19137, 0.99074, 0.962, 1.01915, 0.926, 0.942, 0.856, 0.85034, 0.92006, 0.85034, 1.02058, 0.69067, 0.92241, 0.92241, 0.92241, 0.92241, 0.92006, 0.9332, 0.90088, 0.91882, 0.93484, 0.75339, 1.02058, 0.56866, 0.54324, 0.79519, 1.08595, 1, 1, 0.90088, 1, 0.95325, 0.74505, 0.90088, 1, 0.97198, 0.75339, 0.91009, 0.91009, 0.91009, 0.66466, 0.91755, 0.91755, 0.91755, 0.91755, 0.91755, 0.91755, 0.788, 0.80314, 0.73764, 0.73764, 0.73764, 0.73764, 0.86023, 0.86023, 0.86023, 0.86023, 0.92915, 0.91115, 0.8858, 0.8858, 0.8858, 0.8858, 0.8858, 1.02058, 0.8858, 0.89591, 0.89591, 0.89591, 0.89591, 0.8111, 0.79611, 0.89713, 0.86667, 0.86667, 0.86667, 0.86667, 0.86667, 0.86667, 0.86936, 0.896, 0.90083, 0.90083, 0.90083, 0.90083, 0.84224, 0.84224, 0.84224, 0.84224, 0.97276, 0.99793, 0.98714, 0.98714, 0.98714, 0.98714, 0.98714, 1.08595, 0.89876, 0.99074, 0.99074, 0.99074, 0.99074, 0.942, 1.0231, 0.942, 0.91755, 0.86667, 0.91755, 0.86667, 0.91755, 0.86667, 0.80314, 0.896, 0.80314, 0.896, 0.80314, 0.896, 0.80314, 0.896, 0.92222, 0.93372, 0.92915, 1.01411, 0.73764, 0.90083, 0.73764, 0.90083, 0.73764, 0.90083, 0.73764, 0.90083, 0.73764, 0.90083, 0.83051, 1.00512, 0.83051, 1.00512, 0.83051, 1.00512, 1, 1, 0.90284, 0.99793, 0.90976, 0.99793, 0.86023, 0.84224, 0.86023, 0.84224, 0.86023, 0.84224, 0.86023, 1.05326, 0.86023, 0.84224, 0.82873, 1.07469, 0.74, 1.09377, 1, 1, 0.938, 0.84869, 1.06226, 1, 1, 0.84869, 0.83704, 0.84869, 0.81441, 0.85588, 1.08927, 0.91115, 0.99793, 1, 1, 0.91115, 0.99793, 0.91887, 0.90991, 0.99793, 0.8858, 0.98714, 0.8858, 0.98714, 0.8858, 0.98714, 0.894, 0.91434, 0.74498, 0.98196, 1, 1, 0.74498, 0.98196, 0.73914, 0.792, 0.73914, 0.792, 1, 1, 0.73914, 0.792, 1, 1, 0.81363, 0.904, 0.81363, 1.19137, 0.89591, 0.99074, 0.89591, 0.99074, 0.89591, 0.99074, 0.89591, 0.99074, 0.89591, 0.99074, 0.89591, 0.99074, 0.89633, 1.01915, 0.8111, 0.942, 0.8111, 0.90531, 0.856, 0.90531, 0.856, 0.90531, 0.856, 1, 0.92241, 0.91755, 0.86667, 0.788, 0.86936, 0.8858, 0.89876, 1, 1, 0.81363, 1.19137, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90388, 1.03901, 0.92138, 0.78105, 0.7154, 0.86169, 0.80513, 0.94007, 0.82528, 0.98612, 1.06226, 0.91755, 0.8126, 0.81884, 0.92819, 0.73764, 0.90531, 0.90284, 0.8858, 0.86023, 0.8126, 0.91172, 0.96518, 0.91115, 0.83089, 0.8858, 0.87791, 0.79761, 0.89297, 0.81363, 0.88157, 0.89992, 0.85608, 0.81992, 0.94307, 0.86023, 0.88157, 0.95308, 0.98699, 0.99793, 1.06226, 0.95817, 0.95308, 0.97358, 0.928, 0.98088, 0.98699, 0.92761, 0.99793, 0.96017, 1.06226, 0.986, 0.944, 0.95978, 0.938, 0.96705, 0.98714, 0.80442, 0.98972, 1, 0.89762, 1.04552, 0.95817, 0.99007, 0.87064, 0.91879, 0.88888, 1.06226, 0.95817, 0.98714, 0.95817, 0.88888, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.89633, 1.01915, 0.89633, 1.01915, 0.89633, 1.01915, 0.8111, 0.942, 0.9219, 1, 0.89903, 1, 1, 1, 0.93173, 0.93173, 0.93173, 1, 1.06304, 1.06304, 1.06904, 0.89903, 0.89903, 0.80549, 1, 1.156, 1, 1, 0.76575, 0.76575, 1, 1, 0.72458, 1, 1, 1, 1, 0.92241, 1, 1, 1, 0.619, 1, 1.36145, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.07257, 1, 0.74705, 0.71119, 1.02058, 1.024, 1.02119, 1, 1, 1.1536, 1.08595, 1.08595, 1, 1.08595, 1.08595, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.05638, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28085const MyriadProRegularMetrics = { 28086 lineHeight: 1.2, 28087 lineGap: 0.2 28088}; 28089 28090;// ./src/core/segoeui_factors.js 28091const SegoeuiBoldFactors = [1.76738, 1, 1, 0.99297, 0.9824, 1.04016, 1.06497, 1.03424, 0.97529, 1.17647, 1.23203, 1.1085, 1.1085, 1.16939, 1.2107, 0.9754, 1.21408, 0.9754, 1.59578, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 0.81378, 0.81378, 1.2107, 1.2107, 1.2107, 0.71703, 0.97847, 0.97363, 0.88776, 0.8641, 1.02096, 0.79795, 0.85132, 0.914, 1.06085, 1.1406, 0.8007, 0.89858, 0.83693, 1.14889, 1.09398, 0.97489, 0.92094, 0.97489, 0.90399, 0.84041, 0.95923, 1.00135, 1, 1.06467, 0.98243, 0.90996, 0.99361, 1.1085, 1.56942, 1.1085, 1.2107, 0.74627, 0.94282, 0.96752, 1.01519, 0.86304, 1.01359, 0.97278, 1.15103, 1.01359, 0.98561, 1.02285, 1.02285, 1.00527, 1.02285, 1.0302, 0.99041, 1.0008, 1.01519, 1.01359, 1.02258, 0.79104, 1.16862, 0.99041, 0.97454, 1.02511, 0.99298, 0.96752, 0.95801, 0.94856, 1.16579, 0.94856, 1.2107, 0.9824, 1.03424, 1.03424, 1, 1.03424, 1.16579, 0.8727, 1.3871, 1.18622, 1.10818, 1.04478, 1.2107, 1.18622, 0.75155, 0.94994, 1.28826, 1.21408, 1.21408, 0.91056, 1, 0.91572, 0.9754, 0.64663, 1.18328, 1.24866, 1.04478, 1.14169, 1.15749, 1.17389, 0.71703, 0.97363, 0.97363, 0.97363, 0.97363, 0.97363, 0.97363, 0.93506, 0.8641, 0.79795, 0.79795, 0.79795, 0.79795, 1.1406, 1.1406, 1.1406, 1.1406, 1.02096, 1.09398, 0.97426, 0.97426, 0.97426, 0.97426, 0.97426, 1.2107, 0.97489, 1.00135, 1.00135, 1.00135, 1.00135, 0.90996, 0.92094, 1.02798, 0.96752, 0.96752, 0.96752, 0.96752, 0.96752, 0.96752, 0.93136, 0.86304, 0.97278, 0.97278, 0.97278, 0.97278, 1.02285, 1.02285, 1.02285, 1.02285, 0.97122, 0.99041, 1, 1, 1, 1, 1, 1.28826, 1.0008, 0.99041, 0.99041, 0.99041, 0.99041, 0.96752, 1.01519, 0.96752, 0.97363, 0.96752, 0.97363, 0.96752, 0.97363, 0.96752, 0.8641, 0.86304, 0.8641, 0.86304, 0.8641, 0.86304, 0.8641, 0.86304, 1.02096, 1.03057, 1.02096, 1.03517, 0.79795, 0.97278, 0.79795, 0.97278, 0.79795, 0.97278, 0.79795, 0.97278, 0.79795, 0.97278, 0.914, 1.01359, 0.914, 1.01359, 0.914, 1.01359, 1, 1, 1.06085, 0.98561, 1.06085, 1.00879, 1.1406, 1.02285, 1.1406, 1.02285, 1.1406, 1.02285, 1.1406, 1.02285, 1.1406, 1.02285, 0.97138, 1.08692, 0.8007, 1.02285, 1, 1, 1.00527, 0.83693, 1.02285, 1, 1, 0.83693, 0.9455, 0.83693, 0.90418, 0.83693, 1.13005, 1.09398, 0.99041, 1, 1, 1.09398, 0.99041, 0.96692, 1.09251, 0.99041, 0.97489, 1.0008, 0.97489, 1.0008, 0.97489, 1.0008, 0.93994, 0.97931, 0.90399, 1.02258, 1, 1, 0.90399, 1.02258, 0.84041, 0.79104, 0.84041, 0.79104, 0.84041, 0.79104, 0.84041, 0.79104, 1, 1, 0.95923, 1.07034, 0.95923, 1.16862, 1.00135, 0.99041, 1.00135, 0.99041, 1.00135, 0.99041, 1.00135, 0.99041, 1.00135, 0.99041, 1.00135, 0.99041, 1.06467, 1.02511, 0.90996, 0.96752, 0.90996, 0.99361, 0.95801, 0.99361, 0.95801, 0.99361, 0.95801, 1.07733, 1.03424, 0.97363, 0.96752, 0.93506, 0.93136, 0.97489, 1.0008, 1, 1, 0.95923, 1.16862, 1.15103, 1.15103, 1.01173, 1.03959, 0.75953, 0.81378, 0.79912, 1.15103, 1.21994, 0.95161, 0.87815, 1.01149, 0.81525, 0.7676, 0.98167, 1.01134, 1.02546, 0.84097, 1.03089, 1.18102, 0.97363, 0.88776, 0.85134, 0.97826, 0.79795, 0.99361, 1.06085, 0.97489, 1.1406, 0.89858, 1.0388, 1.14889, 1.09398, 0.86039, 0.97489, 1.0595, 0.92094, 0.94793, 0.95923, 0.90996, 0.99346, 0.98243, 1.02112, 0.95493, 1.1406, 0.90996, 1.03574, 1.02597, 1.0008, 1.18102, 1.06628, 1.03574, 1.0192, 1.01932, 1.00886, 0.97531, 1.0106, 1.0008, 1.13189, 1.18102, 1.02277, 0.98683, 1.0016, 0.99561, 1.07237, 1.0008, 0.90434, 0.99921, 0.93803, 0.8965, 1.23085, 1.06628, 1.04983, 0.96268, 1.0499, 0.98439, 1.18102, 1.06628, 1.0008, 1.06628, 0.98439, 0.79795, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.09466, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.97278, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.02065, 1, 1, 1, 1, 1, 1, 1.06467, 1.02511, 1.06467, 1.02511, 1.06467, 1.02511, 0.90996, 0.96752, 1, 1.21408, 0.89903, 1, 1, 0.75155, 1.04394, 1.04394, 1.04394, 1.04394, 0.98633, 0.98633, 0.98633, 0.73047, 0.73047, 1.20642, 0.91211, 1.25635, 1.222, 1.02956, 1.03372, 1.03372, 0.96039, 1.24633, 1, 1.12454, 0.93503, 1.03424, 1.19687, 1.03424, 1, 1, 1, 0.771, 1, 1, 1.15749, 1.15749, 1.15749, 1.10948, 0.86279, 0.94434, 0.86279, 0.94434, 0.86182, 1, 1, 1.16897, 1, 0.96085, 0.90137, 1.2107, 1.18416, 1.13973, 0.69825, 0.9716, 2.10339, 1.29004, 1.29004, 1.21172, 1.29004, 1.29004, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.42603, 1, 0.99862, 0.99862, 1, 0.87025, 0.87025, 0.87025, 0.87025, 1.18874, 1.42603, 1, 1.42603, 1.42603, 0.99862, 1, 1, 1, 1, 1, 1.2886, 1.04315, 1.15296, 1.34163, 1, 1, 1, 1.09193, 1.09193, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28092const SegoeuiBoldMetrics = { 28093 lineHeight: 1.33008, 28094 lineGap: 0 28095}; 28096const SegoeuiBoldItalicFactors = [1.76738, 1, 1, 0.98946, 1.03959, 1.04016, 1.02809, 1.036, 0.97639, 1.10953, 1.23203, 1.11144, 1.11144, 1.16939, 1.21237, 0.9754, 1.21261, 0.9754, 1.59754, 1.036, 1.036, 1.036, 1.036, 1.036, 1.036, 1.036, 1.036, 1.036, 1.036, 0.81378, 0.81378, 1.21237, 1.21237, 1.21237, 0.73541, 0.97847, 0.97363, 0.89723, 0.87897, 1.0426, 0.79429, 0.85292, 0.91149, 1.05815, 1.1406, 0.79631, 0.90128, 0.83853, 1.04396, 1.10615, 0.97552, 0.94436, 0.97552, 0.88641, 0.80527, 0.96083, 1.00135, 1, 1.06777, 0.9817, 0.91142, 0.99361, 1.11144, 1.57293, 1.11144, 1.21237, 0.74627, 1.31818, 1.06585, 0.97042, 0.83055, 0.97042, 0.93503, 1.1261, 0.97042, 0.97922, 1.14236, 0.94552, 1.01054, 1.14236, 1.02471, 0.97922, 0.94165, 0.97042, 0.97042, 1.0276, 0.78929, 1.1261, 0.97922, 0.95874, 1.02197, 0.98507, 0.96752, 0.97168, 0.95107, 1.16579, 0.95107, 1.21237, 1.03959, 1.036, 1.036, 1, 1.036, 1.16579, 0.87357, 1.31818, 1.18754, 1.26781, 1.05356, 1.21237, 1.18622, 0.79487, 0.94994, 1.29004, 1.24047, 1.24047, 1.31818, 1, 0.91484, 0.9754, 1.31818, 1.1349, 1.24866, 1.05356, 1.13934, 1.15574, 1.17389, 0.73541, 0.97363, 0.97363, 0.97363, 0.97363, 0.97363, 0.97363, 0.94385, 0.87897, 0.79429, 0.79429, 0.79429, 0.79429, 1.1406, 1.1406, 1.1406, 1.1406, 1.0426, 1.10615, 0.97552, 0.97552, 0.97552, 0.97552, 0.97552, 1.21237, 0.97552, 1.00135, 1.00135, 1.00135, 1.00135, 0.91142, 0.94436, 0.98721, 1.06585, 1.06585, 1.06585, 1.06585, 1.06585, 1.06585, 0.96705, 0.83055, 0.93503, 0.93503, 0.93503, 0.93503, 1.14236, 1.14236, 1.14236, 1.14236, 0.93125, 0.97922, 0.94165, 0.94165, 0.94165, 0.94165, 0.94165, 1.29004, 0.94165, 0.97922, 0.97922, 0.97922, 0.97922, 0.96752, 0.97042, 0.96752, 0.97363, 1.06585, 0.97363, 1.06585, 0.97363, 1.06585, 0.87897, 0.83055, 0.87897, 0.83055, 0.87897, 0.83055, 0.87897, 0.83055, 1.0426, 1.0033, 1.0426, 0.97042, 0.79429, 0.93503, 0.79429, 0.93503, 0.79429, 0.93503, 0.79429, 0.93503, 0.79429, 0.93503, 0.91149, 0.97042, 0.91149, 0.97042, 0.91149, 0.97042, 1, 1, 1.05815, 0.97922, 1.05815, 0.97922, 1.1406, 1.14236, 1.1406, 1.14236, 1.1406, 1.14236, 1.1406, 1.14236, 1.1406, 1.14236, 0.97441, 1.04302, 0.79631, 1.01582, 1, 1, 1.01054, 0.83853, 1.14236, 1, 1, 0.83853, 1.09125, 0.83853, 0.90418, 0.83853, 1.19508, 1.10615, 0.97922, 1, 1, 1.10615, 0.97922, 1.01034, 1.10466, 0.97922, 0.97552, 0.94165, 0.97552, 0.94165, 0.97552, 0.94165, 0.91602, 0.91981, 0.88641, 1.0276, 1, 1, 0.88641, 1.0276, 0.80527, 0.78929, 0.80527, 0.78929, 0.80527, 0.78929, 0.80527, 0.78929, 1, 1, 0.96083, 1.05403, 0.95923, 1.16862, 1.00135, 0.97922, 1.00135, 0.97922, 1.00135, 0.97922, 1.00135, 0.97922, 1.00135, 0.97922, 1.00135, 0.97922, 1.06777, 1.02197, 0.91142, 0.96752, 0.91142, 0.99361, 0.97168, 0.99361, 0.97168, 0.99361, 0.97168, 1.23199, 1.036, 0.97363, 1.06585, 0.94385, 0.96705, 0.97552, 0.94165, 1, 1, 0.96083, 1.1261, 1.31818, 1.31818, 1.31818, 1.31818, 1.31818, 1.31818, 1.31818, 1.31818, 1.31818, 0.95161, 1.27126, 1.00811, 0.83284, 0.77702, 0.99137, 0.95253, 1.0347, 0.86142, 1.07205, 1.14236, 0.97363, 0.89723, 0.86869, 1.09818, 0.79429, 0.99361, 1.05815, 0.97552, 1.1406, 0.90128, 1.06662, 1.04396, 1.10615, 0.84918, 0.97552, 1.04694, 0.94436, 0.98015, 0.96083, 0.91142, 1.00356, 0.9817, 1.01945, 0.98999, 1.1406, 0.91142, 1.04961, 0.9898, 1.00639, 1.14236, 1.07514, 1.04961, 0.99607, 1.02897, 1.008, 0.9898, 0.95134, 1.00639, 1.11121, 1.14236, 1.00518, 0.97981, 1.02186, 1, 1.08578, 0.94165, 0.99314, 0.98387, 0.93028, 0.93377, 1.35125, 1.07514, 1.10687, 0.93491, 1.04232, 1.00351, 1.14236, 1.07514, 0.94165, 1.07514, 1.00351, 0.79429, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.09097, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.93503, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.96609, 1, 1, 1, 1, 1, 1, 1.06777, 1.02197, 1.06777, 1.02197, 1.06777, 1.02197, 0.91142, 0.96752, 1, 1.21261, 0.89903, 1, 1, 0.75155, 1.04745, 1.04745, 1.04745, 1.04394, 0.98633, 0.98633, 0.98633, 0.72959, 0.72959, 1.20502, 0.91406, 1.26514, 1.222, 1.02956, 1.03372, 1.03372, 0.96039, 1.24633, 1, 1.09125, 0.93327, 1.03336, 1.16541, 1.036, 1, 1, 1, 0.771, 1, 1, 1.15574, 1.15574, 1.15574, 1.15574, 0.86364, 0.94434, 0.86279, 0.94434, 0.86224, 1, 1, 1.16798, 1, 0.96085, 0.90068, 1.21237, 1.18416, 1.13904, 0.69825, 0.9716, 2.10339, 1.29004, 1.29004, 1.21339, 1.29004, 1.29004, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.42603, 1, 0.99862, 0.99862, 1, 0.87025, 0.87025, 0.87025, 0.87025, 1.18775, 1.42603, 1, 1.42603, 1.42603, 0.99862, 1, 1, 1, 1, 1, 1.2886, 1.04315, 1.15296, 1.34163, 1, 1, 1, 1.13269, 1.13269, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28097const SegoeuiBoldItalicMetrics = { 28098 lineHeight: 1.33008, 28099 lineGap: 0 28100}; 28101const SegoeuiItalicFactors = [1.76738, 1, 1, 0.98946, 1.14763, 1.05365, 1.06234, 0.96927, 0.92586, 1.15373, 1.18414, 0.91349, 0.91349, 1.07403, 1.17308, 0.78383, 1.20088, 0.78383, 1.42531, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.78383, 0.78383, 1.17308, 1.17308, 1.17308, 0.77349, 0.94565, 0.94729, 0.85944, 0.88506, 0.9858, 0.74817, 0.80016, 0.88449, 0.98039, 0.95782, 0.69238, 0.89898, 0.83231, 0.98183, 1.03989, 0.96924, 0.86237, 0.96924, 0.80595, 0.74524, 0.86091, 0.95402, 0.94143, 0.98448, 0.8858, 0.83089, 0.93285, 1.0949, 1.39016, 1.0949, 1.45994, 0.74627, 1.04839, 0.97454, 0.97454, 0.87207, 0.97454, 0.87533, 1.06151, 0.97454, 1.00176, 1.16484, 1.08132, 0.98047, 1.16484, 1.02989, 1.01054, 0.96225, 0.97454, 0.97454, 1.06598, 0.79004, 1.16344, 1.00351, 0.94629, 0.9973, 0.91016, 0.96777, 0.9043, 0.91082, 0.92481, 0.91082, 1.17308, 0.95748, 0.96927, 0.96927, 1, 0.96927, 0.92481, 0.80597, 1.04839, 1.23393, 1.1781, 0.9245, 1.17308, 1.20808, 0.63218, 0.94261, 1.24822, 1.09971, 1.09971, 1.04839, 1, 0.85273, 0.78032, 1.04839, 1.09971, 1.22326, 0.9245, 1.09836, 1.13525, 1.15222, 0.70424, 0.94729, 0.94729, 0.94729, 0.94729, 0.94729, 0.94729, 0.85498, 0.88506, 0.74817, 0.74817, 0.74817, 0.74817, 0.95782, 0.95782, 0.95782, 0.95782, 0.9858, 1.03989, 0.96924, 0.96924, 0.96924, 0.96924, 0.96924, 1.17308, 0.96924, 0.95402, 0.95402, 0.95402, 0.95402, 0.83089, 0.86237, 0.88409, 0.97454, 0.97454, 0.97454, 0.97454, 0.97454, 0.97454, 0.92916, 0.87207, 0.87533, 0.87533, 0.87533, 0.87533, 0.93146, 0.93146, 0.93146, 0.93146, 0.93854, 1.01054, 0.96225, 0.96225, 0.96225, 0.96225, 0.96225, 1.24822, 0.8761, 1.00351, 1.00351, 1.00351, 1.00351, 0.96777, 0.97454, 0.96777, 0.94729, 0.97454, 0.94729, 0.97454, 0.94729, 0.97454, 0.88506, 0.87207, 0.88506, 0.87207, 0.88506, 0.87207, 0.88506, 0.87207, 0.9858, 0.95391, 0.9858, 0.97454, 0.74817, 0.87533, 0.74817, 0.87533, 0.74817, 0.87533, 0.74817, 0.87533, 0.74817, 0.87533, 0.88449, 0.97454, 0.88449, 0.97454, 0.88449, 0.97454, 1, 1, 0.98039, 1.00176, 0.98039, 1.00176, 0.95782, 0.93146, 0.95782, 0.93146, 0.95782, 0.93146, 0.95782, 1.16484, 0.95782, 0.93146, 0.84421, 1.12761, 0.69238, 1.08132, 1, 1, 0.98047, 0.83231, 1.16484, 1, 1, 0.84723, 1.04861, 0.84723, 0.78755, 0.83231, 1.23736, 1.03989, 1.01054, 1, 1, 1.03989, 1.01054, 0.9857, 1.03849, 1.01054, 0.96924, 0.96225, 0.96924, 0.96225, 0.96924, 0.96225, 0.92383, 0.90171, 0.80595, 1.06598, 1, 1, 0.80595, 1.06598, 0.74524, 0.79004, 0.74524, 0.79004, 0.74524, 0.79004, 0.74524, 0.79004, 1, 1, 0.86091, 1.02759, 0.85771, 1.16344, 0.95402, 1.00351, 0.95402, 1.00351, 0.95402, 1.00351, 0.95402, 1.00351, 0.95402, 1.00351, 0.95402, 1.00351, 0.98448, 0.9973, 0.83089, 0.96777, 0.83089, 0.93285, 0.9043, 0.93285, 0.9043, 0.93285, 0.9043, 1.31868, 0.96927, 0.94729, 0.97454, 0.85498, 0.92916, 0.96924, 0.8761, 1, 1, 0.86091, 1.16344, 1.04839, 1.04839, 1.04839, 1.04839, 1.04839, 1.04839, 1.04839, 1.04839, 1.04839, 0.81965, 0.81965, 0.94729, 0.78032, 0.71022, 0.90883, 0.84171, 0.99877, 0.77596, 1.05734, 1.2, 0.94729, 0.85944, 0.82791, 0.9607, 0.74817, 0.93285, 0.98039, 0.96924, 0.95782, 0.89898, 0.98316, 0.98183, 1.03989, 0.78614, 0.96924, 0.97642, 0.86237, 0.86075, 0.86091, 0.83089, 0.90082, 0.8858, 0.97296, 1.01284, 0.95782, 0.83089, 1.0976, 1.04, 1.03342, 1.2, 1.0675, 1.0976, 0.98205, 1.03809, 1.05097, 1.04, 0.95364, 1.03342, 1.05401, 1.2, 1.02148, 1.0119, 1.04724, 1.0127, 1.02732, 0.96225, 0.8965, 0.97783, 0.93574, 0.94818, 1.30679, 1.0675, 1.11826, 0.99821, 1.0557, 1.0326, 1.2, 1.0675, 0.96225, 1.0675, 1.0326, 0.74817, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.03754, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.87533, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.98705, 1, 1, 1, 1, 1, 1, 0.98448, 0.9973, 0.98448, 0.9973, 0.98448, 0.9973, 0.83089, 0.96777, 1, 1.20088, 0.89903, 1, 1, 0.75155, 0.94945, 0.94945, 0.94945, 0.94945, 1.12317, 1.12317, 1.12317, 0.67603, 0.67603, 1.15621, 0.73584, 1.21191, 1.22135, 1.06483, 0.94868, 0.94868, 0.95996, 1.24633, 1, 1.07497, 0.87709, 0.96927, 1.01473, 0.96927, 1, 1, 1, 0.77295, 1, 1, 1.09836, 1.09836, 1.09836, 1.01522, 0.86321, 0.94434, 0.8649, 0.94434, 0.86182, 1, 1, 1.083, 1, 0.91578, 0.86438, 1.17308, 1.18416, 1.14589, 0.69825, 0.97622, 1.96791, 1.24822, 1.24822, 1.17308, 1.24822, 1.24822, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.42603, 1, 0.99862, 0.99862, 1, 0.87025, 0.87025, 0.87025, 0.87025, 1.17984, 1.42603, 1, 1.42603, 1.42603, 0.99862, 1, 1, 1, 1, 1, 1.2886, 1.04315, 1.15296, 1.34163, 1, 1, 1, 1.10742, 1.10742, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28102const SegoeuiItalicMetrics = { 28103 lineHeight: 1.33008, 28104 lineGap: 0 28105}; 28106const SegoeuiRegularFactors = [1.76738, 1, 1, 0.98594, 1.02285, 1.10454, 1.06234, 0.96927, 0.92037, 1.19985, 1.2046, 0.90616, 0.90616, 1.07152, 1.1714, 0.78032, 1.20088, 0.78032, 1.40246, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.78032, 0.78032, 1.1714, 1.1714, 1.1714, 0.80597, 0.94084, 0.96706, 0.85944, 0.85734, 0.97093, 0.75842, 0.79936, 0.88198, 0.9831, 0.95782, 0.71387, 0.86969, 0.84636, 1.07796, 1.03584, 0.96924, 0.83968, 0.96924, 0.82826, 0.79649, 0.85771, 0.95132, 0.93119, 0.98965, 0.88433, 0.8287, 0.93365, 1.08612, 1.3638, 1.08612, 1.45786, 0.74627, 0.80499, 0.91484, 1.05707, 0.92383, 1.05882, 0.9403, 1.12654, 1.05882, 1.01756, 1.09011, 1.09011, 0.99414, 1.09011, 1.034, 1.01756, 1.05356, 1.05707, 1.05882, 1.04399, 0.84863, 1.21968, 1.01756, 0.95801, 1.00068, 0.91797, 0.96777, 0.9043, 0.90351, 0.92105, 0.90351, 1.1714, 0.85337, 0.96927, 0.96927, 0.99912, 0.96927, 0.92105, 0.80597, 1.2434, 1.20808, 1.05937, 0.90957, 1.1714, 1.20808, 0.75155, 0.94261, 1.24644, 1.09971, 1.09971, 0.84751, 1, 0.85273, 0.78032, 0.61584, 1.05425, 1.17914, 0.90957, 1.08665, 1.11593, 1.14169, 0.73381, 0.96706, 0.96706, 0.96706, 0.96706, 0.96706, 0.96706, 0.86035, 0.85734, 0.75842, 0.75842, 0.75842, 0.75842, 0.95782, 0.95782, 0.95782, 0.95782, 0.97093, 1.03584, 0.96924, 0.96924, 0.96924, 0.96924, 0.96924, 1.1714, 0.96924, 0.95132, 0.95132, 0.95132, 0.95132, 0.8287, 0.83968, 0.89049, 0.91484, 0.91484, 0.91484, 0.91484, 0.91484, 0.91484, 0.93575, 0.92383, 0.9403, 0.9403, 0.9403, 0.9403, 0.8717, 0.8717, 0.8717, 0.8717, 1.00527, 1.01756, 1.05356, 1.05356, 1.05356, 1.05356, 1.05356, 1.24644, 0.95923, 1.01756, 1.01756, 1.01756, 1.01756, 0.96777, 1.05707, 0.96777, 0.96706, 0.91484, 0.96706, 0.91484, 0.96706, 0.91484, 0.85734, 0.92383, 0.85734, 0.92383, 0.85734, 0.92383, 0.85734, 0.92383, 0.97093, 1.0969, 0.97093, 1.05882, 0.75842, 0.9403, 0.75842, 0.9403, 0.75842, 0.9403, 0.75842, 0.9403, 0.75842, 0.9403, 0.88198, 1.05882, 0.88198, 1.05882, 0.88198, 1.05882, 1, 1, 0.9831, 1.01756, 0.9831, 1.01756, 0.95782, 0.8717, 0.95782, 0.8717, 0.95782, 0.8717, 0.95782, 1.09011, 0.95782, 0.8717, 0.84784, 1.11551, 0.71387, 1.09011, 1, 1, 0.99414, 0.84636, 1.09011, 1, 1, 0.84636, 1.0536, 0.84636, 0.94298, 0.84636, 1.23297, 1.03584, 1.01756, 1, 1, 1.03584, 1.01756, 1.00323, 1.03444, 1.01756, 0.96924, 1.05356, 0.96924, 1.05356, 0.96924, 1.05356, 0.93066, 0.98293, 0.82826, 1.04399, 1, 1, 0.82826, 1.04399, 0.79649, 0.84863, 0.79649, 0.84863, 0.79649, 0.84863, 0.79649, 0.84863, 1, 1, 0.85771, 1.17318, 0.85771, 1.21968, 0.95132, 1.01756, 0.95132, 1.01756, 0.95132, 1.01756, 0.95132, 1.01756, 0.95132, 1.01756, 0.95132, 1.01756, 0.98965, 1.00068, 0.8287, 0.96777, 0.8287, 0.93365, 0.9043, 0.93365, 0.9043, 0.93365, 0.9043, 1.08571, 0.96927, 0.96706, 0.91484, 0.86035, 0.93575, 0.96924, 0.95923, 1, 1, 0.85771, 1.21968, 1.11437, 1.11437, 0.93109, 0.91202, 0.60411, 0.84164, 0.55572, 1.01173, 0.97361, 0.81818, 0.81818, 0.96635, 0.78032, 0.72727, 0.92366, 0.98601, 1.03405, 0.77968, 1.09799, 1.2, 0.96706, 0.85944, 0.85638, 0.96491, 0.75842, 0.93365, 0.9831, 0.96924, 0.95782, 0.86969, 0.94152, 1.07796, 1.03584, 0.78437, 0.96924, 0.98715, 0.83968, 0.83491, 0.85771, 0.8287, 0.94492, 0.88433, 0.9287, 1.0098, 0.95782, 0.8287, 1.0625, 0.98248, 1.03424, 1.2, 1.01071, 1.0625, 0.95246, 1.03809, 1.04912, 0.98248, 1.00221, 1.03424, 1.05443, 1.2, 1.04785, 0.99609, 1.00169, 1.05176, 0.99346, 1.05356, 0.9087, 1.03004, 0.95542, 0.93117, 1.23362, 1.01071, 1.07831, 1.02512, 1.05205, 1.03502, 1.2, 1.01071, 1.05356, 1.01071, 1.03502, 0.75842, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.03719, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9403, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.04021, 1, 1, 1, 1, 1, 1, 0.98965, 1.00068, 0.98965, 1.00068, 0.98965, 1.00068, 0.8287, 0.96777, 1, 1.20088, 0.89903, 1, 1, 0.75155, 1.03077, 1.03077, 1.03077, 1.03077, 1.13196, 1.13196, 1.13196, 0.67428, 0.67428, 1.16039, 0.73291, 1.20996, 1.22135, 1.06483, 0.94868, 0.94868, 0.95996, 1.24633, 1, 1.07497, 0.87796, 0.96927, 1.01518, 0.96927, 1, 1, 1, 0.77295, 1, 1, 1.10539, 1.10539, 1.11358, 1.06967, 0.86279, 0.94434, 0.86279, 0.94434, 0.86182, 1, 1, 1.083, 1, 0.91578, 0.86507, 1.1714, 1.18416, 1.14589, 0.69825, 0.97622, 1.9697, 1.24822, 1.24822, 1.17238, 1.24822, 1.24822, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.42603, 1, 0.99862, 0.99862, 1, 0.87025, 0.87025, 0.87025, 0.87025, 1.18083, 1.42603, 1, 1.42603, 1.42603, 0.99862, 1, 1, 1, 1, 1, 1.2886, 1.04315, 1.15296, 1.34163, 1, 1, 1, 1.10938, 1.10938, 1, 1, 1, 1.05425, 1.09971, 1.09971, 1.09971, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; 28107const SegoeuiRegularMetrics = { 28108 lineHeight: 1.33008, 28109 lineGap: 0 28110}; 28111 28112;// ./src/core/xfa_fonts.js 28113 28114 28115 28116 28117 28118 28119 28120 28121const getXFAFontMap = getLookupTableFactory(function (t) { 28122 t["MyriadPro-Regular"] = t["PdfJS-Fallback-Regular"] = { 28123 name: "LiberationSans-Regular", 28124 factors: MyriadProRegularFactors, 28125 baseWidths: LiberationSansRegularWidths, 28126 baseMapping: LiberationSansRegularMapping, 28127 metrics: MyriadProRegularMetrics 28128 }; 28129 t["MyriadPro-Bold"] = t["PdfJS-Fallback-Bold"] = { 28130 name: "LiberationSans-Bold", 28131 factors: MyriadProBoldFactors, 28132 baseWidths: LiberationSansBoldWidths, 28133 baseMapping: LiberationSansBoldMapping, 28134 metrics: MyriadProBoldMetrics 28135 }; 28136 t["MyriadPro-It"] = t["MyriadPro-Italic"] = t["PdfJS-Fallback-Italic"] = { 28137 name: "LiberationSans-Italic", 28138 factors: MyriadProItalicFactors, 28139 baseWidths: LiberationSansItalicWidths, 28140 baseMapping: LiberationSansItalicMapping, 28141 metrics: MyriadProItalicMetrics 28142 }; 28143 t["MyriadPro-BoldIt"] = t["MyriadPro-BoldItalic"] = t["PdfJS-Fallback-BoldItalic"] = { 28144 name: "LiberationSans-BoldItalic", 28145 factors: MyriadProBoldItalicFactors, 28146 baseWidths: LiberationSansBoldItalicWidths, 28147 baseMapping: LiberationSansBoldItalicMapping, 28148 metrics: MyriadProBoldItalicMetrics 28149 }; 28150 t.ArialMT = t.Arial = t["Arial-Regular"] = { 28151 name: "LiberationSans-Regular", 28152 baseWidths: LiberationSansRegularWidths, 28153 baseMapping: LiberationSansRegularMapping 28154 }; 28155 t["Arial-BoldMT"] = t["Arial-Bold"] = { 28156 name: "LiberationSans-Bold", 28157 baseWidths: LiberationSansBoldWidths, 28158 baseMapping: LiberationSansBoldMapping 28159 }; 28160 t["Arial-ItalicMT"] = t["Arial-Italic"] = { 28161 name: "LiberationSans-Italic", 28162 baseWidths: LiberationSansItalicWidths, 28163 baseMapping: LiberationSansItalicMapping 28164 }; 28165 t["Arial-BoldItalicMT"] = t["Arial-BoldItalic"] = { 28166 name: "LiberationSans-BoldItalic", 28167 baseWidths: LiberationSansBoldItalicWidths, 28168 baseMapping: LiberationSansBoldItalicMapping 28169 }; 28170 t["Calibri-Regular"] = { 28171 name: "LiberationSans-Regular", 28172 factors: CalibriRegularFactors, 28173 baseWidths: LiberationSansRegularWidths, 28174 baseMapping: LiberationSansRegularMapping, 28175 metrics: CalibriRegularMetrics 28176 }; 28177 t["Calibri-Bold"] = { 28178 name: "LiberationSans-Bold", 28179 factors: CalibriBoldFactors, 28180 baseWidths: LiberationSansBoldWidths, 28181 baseMapping: LiberationSansBoldMapping, 28182 metrics: CalibriBoldMetrics 28183 }; 28184 t["Calibri-Italic"] = { 28185 name: "LiberationSans-Italic", 28186 factors: CalibriItalicFactors, 28187 baseWidths: LiberationSansItalicWidths, 28188 baseMapping: LiberationSansItalicMapping, 28189 metrics: CalibriItalicMetrics 28190 }; 28191 t["Calibri-BoldItalic"] = { 28192 name: "LiberationSans-BoldItalic", 28193 factors: CalibriBoldItalicFactors, 28194 baseWidths: LiberationSansBoldItalicWidths, 28195 baseMapping: LiberationSansBoldItalicMapping, 28196 metrics: CalibriBoldItalicMetrics 28197 }; 28198 t["Segoeui-Regular"] = { 28199 name: "LiberationSans-Regular", 28200 factors: SegoeuiRegularFactors, 28201 baseWidths: LiberationSansRegularWidths, 28202 baseMapping: LiberationSansRegularMapping, 28203 metrics: SegoeuiRegularMetrics 28204 }; 28205 t["Segoeui-Bold"] = { 28206 name: "LiberationSans-Bold", 28207 factors: SegoeuiBoldFactors, 28208 baseWidths: LiberationSansBoldWidths, 28209 baseMapping: LiberationSansBoldMapping, 28210 metrics: SegoeuiBoldMetrics 28211 }; 28212 t["Segoeui-Italic"] = { 28213 name: "LiberationSans-Italic", 28214 factors: SegoeuiItalicFactors, 28215 baseWidths: LiberationSansItalicWidths, 28216 baseMapping: LiberationSansItalicMapping, 28217 metrics: SegoeuiItalicMetrics 28218 }; 28219 t["Segoeui-BoldItalic"] = { 28220 name: "LiberationSans-BoldItalic", 28221 factors: SegoeuiBoldItalicFactors, 28222 baseWidths: LiberationSansBoldItalicWidths, 28223 baseMapping: LiberationSansBoldItalicMapping, 28224 metrics: SegoeuiBoldItalicMetrics 28225 }; 28226 t["Helvetica-Regular"] = t.Helvetica = { 28227 name: "LiberationSans-Regular", 28228 factors: HelveticaRegularFactors, 28229 baseWidths: LiberationSansRegularWidths, 28230 baseMapping: LiberationSansRegularMapping, 28231 metrics: HelveticaRegularMetrics 28232 }; 28233 t["Helvetica-Bold"] = { 28234 name: "LiberationSans-Bold", 28235 factors: HelveticaBoldFactors, 28236 baseWidths: LiberationSansBoldWidths, 28237 baseMapping: LiberationSansBoldMapping, 28238 metrics: HelveticaBoldMetrics 28239 }; 28240 t["Helvetica-Italic"] = { 28241 name: "LiberationSans-Italic", 28242 factors: HelveticaItalicFactors, 28243 baseWidths: LiberationSansItalicWidths, 28244 baseMapping: LiberationSansItalicMapping, 28245 metrics: HelveticaItalicMetrics 28246 }; 28247 t["Helvetica-BoldItalic"] = { 28248 name: "LiberationSans-BoldItalic", 28249 factors: HelveticaBoldItalicFactors, 28250 baseWidths: LiberationSansBoldItalicWidths, 28251 baseMapping: LiberationSansBoldItalicMapping, 28252 metrics: HelveticaBoldItalicMetrics 28253 }; 28254}); 28255function getXfaFontName(name) { 28256 const fontName = normalizeFontName(name); 28257 const fontMap = getXFAFontMap(); 28258 return fontMap[fontName]; 28259} 28260function getXfaFontWidths(name) { 28261 const info = getXfaFontName(name); 28262 if (!info) { 28263 return null; 28264 } 28265 const { 28266 baseWidths, 28267 baseMapping, 28268 factors 28269 } = info; 28270 const rescaledBaseWidths = !factors ? baseWidths : baseWidths.map((w, i) => w * factors[i]); 28271 let currentCode = -2; 28272 let currentArray; 28273 const newWidths = []; 28274 for (const [unicode, glyphIndex] of baseMapping.map((charUnicode, index) => [charUnicode, index]).sort(([unicode1], [unicode2]) => unicode1 - unicode2)) { 28275 if (unicode === -1) { 28276 continue; 28277 } 28278 if (unicode === currentCode + 1) { 28279 currentArray.push(rescaledBaseWidths[glyphIndex]); 28280 currentCode += 1; 28281 } else { 28282 currentCode = unicode; 28283 currentArray = [rescaledBaseWidths[glyphIndex]]; 28284 newWidths.push(unicode, currentArray); 28285 } 28286 } 28287 return newWidths; 28288} 28289function getXfaFontDict(name) { 28290 const widths = getXfaFontWidths(name); 28291 const dict = new Dict(null); 28292 dict.set("BaseFont", Name.get(name)); 28293 dict.set("Type", Name.get("Font")); 28294 dict.set("Subtype", Name.get("CIDFontType2")); 28295 dict.set("Encoding", Name.get("Identity-H")); 28296 dict.set("CIDToGIDMap", Name.get("Identity")); 28297 dict.set("W", widths); 28298 dict.set("FirstChar", widths[0]); 28299 dict.set("LastChar", widths.at(-2) + widths.at(-1).length - 1); 28300 const descriptor = new Dict(null); 28301 dict.set("FontDescriptor", descriptor); 28302 const systemInfo = new Dict(null); 28303 systemInfo.set("Ordering", "Identity"); 28304 systemInfo.set("Registry", "Adobe"); 28305 systemInfo.set("Supplement", 0); 28306 dict.set("CIDSystemInfo", systemInfo); 28307 return dict; 28308} 28309 28310;// ./src/core/p
28310s_parser.js
vendor: 5,083 bytes, lines 28310-28501
28310 28311 28312 28313 28314class PostScriptParser { 28315 constructor(lexer) { 28316 this.lexer = lexer; 28317 this.operators = []; 28318 this.token = null; 28319 this.prev = null; 28320 } 28321 nextToken() { 28322 this.prev = this.token; 28323 this.token = this.lexer.getToken(); 28324 } 28325 accept(type) { 28326 if (this.token.type === type) { 28327 this.nextToken(); 28328 return true; 28329 } 28330 return false; 28331 } 28332 expect(type) { 28333 if (this.accept(type)) { 28334 return true; 28335 } 28336 throw new FormatError(`Unexpected symbol: found ${this.token.type} expected ${type}.`); 28337 } 28338 parse() { 28339 this.nextToken(); 28340 this.expect(PostScriptTokenTypes.LBRACE); 28341 this.parseBlock(); 28342 this.expect(PostScriptTokenTypes.RBRACE); 28343 return this.operators; 28344 } 28345 parseBlock() { 28346 while (true) { 28347 if (this.accept(PostScriptTokenTypes.NUMBER)) { 28348 this.operators.push(this.prev.value); 28349 } else if (this.accept(PostScriptTokenTypes.OPERATOR)) { 28350 this.operators.push(this.prev.value); 28351 } else if (this.accept(PostScriptTokenTypes.LBRACE)) { 28352 this.parseCondition(); 28353 } else { 28354 return; 28355 } 28356 } 28357 } 28358 parseCondition() { 28359 const conditionLocation = this.operators.length; 28360 this.operators.push(null, null); 28361 this.parseBlock(); 28362 this.expect(PostScriptTokenTypes.RBRACE); 28363 if (this.accept(PostScriptTokenTypes.IF)) { 28364 this.operators[conditionLocation] = this.operators.length; 28365 this.operators[conditionLocation + 1] = "jz"; 28366 } else if (this.accept(PostScriptTokenTypes.LBRACE)) { 28367 const jumpLocation = this.operators.length; 28368 this.operators.push(null, null); 28369 const endOfTrue = this.operators.length; 28370 this.parseBlock(); 28371 this.expect(PostScriptTokenTypes.RBRACE); 28372 this.expect(PostScriptTokenTypes.IFELSE); 28373 this.operators[jumpLocation] = this.operators.length; 28374 this.operators[jumpLocation + 1] = "j"; 28375 this.operators[conditionLocation] = endOfTrue; 28376 this.operators[conditionLocation + 1] = "jz"; 28377 } else { 28378 throw new FormatError("PS Function: error parsing conditional."); 28379 } 28380 } 28381} 28382const PostScriptTokenTypes = { 28383 LBRACE: 0, 28384 RBRACE: 1, 28385 NUMBER: 2, 28386 OPERATOR: 3, 28387 IF: 4, 28388 IFELSE: 5 28389}; 28390class PostScriptToken { 28391 static get opCache() { 28392 return shadow(this, "opCache", Object.create(null)); 28393 } 28394 constructor(type, value) { 28395 this.type = type; 28396 this.value = value; 28397 } 28398 static getOperator(op) { 28399 return PostScriptToken.opCache[op] ||= new PostScriptToken(PostScriptTokenTypes.OPERATOR, op); 28400 } 28401 static get LBRACE() { 28402 return shadow(this, "LBRACE", new PostScriptToken(PostScriptTokenTypes.LBRACE, "{")); 28403 } 28404 static get RBRACE() { 28405 return shadow(this, "RBRACE", new PostScriptToken(PostScriptTokenTypes.RBRACE, "}")); 28406 } 28407 static get IF() { 28408 return shadow(this, "IF", new PostScriptToken(PostScriptTokenTypes.IF, "IF")); 28409 } 28410 static get IFELSE() { 28411 return shadow(this, "IFELSE", new PostScriptToken(PostScriptTokenTypes.IFELSE, "IFELSE")); 28412 } 28413} 28414class PostScriptLexer { 28415 constructor(stream) { 28416 this.stream = stream; 28417 this.nextChar(); 28418 this.strBuf = []; 28419 } 28420 nextChar() { 28421 return this.currentChar = this.stream.getByte(); 28422 } 28423 getToken() { 28424 let comment = false; 28425 let ch = this.currentChar; 28426 while (true) { 28427 if (ch < 0) { 28428 return EOF; 28429 } 28430 if (comment) { 28431 if (ch === 0x0a || ch === 0x0d) { 28432 comment = false; 28433 } 28434 } else if (ch === 0x25) { 28435 comment = true; 28436 } else if (!isWhiteSpace(ch)) { 28437 break; 28438 } 28439 ch = this.nextChar(); 28440 } 28441 switch (ch | 0) { 28442 case 0x30: 28443 case 0x31: 28444 case 0x32: 28445 case 0x33: 28446 case 0x34: 28447 case 0x35: 28448 case 0x36: 28449 case 0x37: 28450 case 0x38: 28451 case 0x39: 28452 case 0x2b: 28453 case 0x2d: 28454 case 0x2e: 28455 return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber()); 28456 case 0x7b: 28457 this.nextChar(); 28458 return PostScriptToken.LBRACE; 28459 case 0x7d: 28460 this.nextChar(); 28461 return PostScriptToken.RBRACE; 28462 } 28463 const strBuf = this.strBuf; 28464 strBuf.length = 0; 28465 strBuf[0] = String.fromCharCode(ch); 28466 while ((ch = this.nextChar()) >= 0 && (ch >= 0x41 && ch <= 0x5a || ch >= 0x61 && ch <= 0x7a)) { 28467 strBuf.push(String.fromCharCode(ch)); 28468 } 28469 const str = strBuf.join(""); 28470 switch (str.toLowerCase()) { 28471 case "if": 28472 return PostScriptToken.IF; 28473 case "ifelse": 28474 return PostScriptToken.IFELSE; 28475 default: 28476 return PostScriptToken.getOperator(str); 28477 } 28478 } 28479 getNumber() { 28480 let ch = this.currentChar; 28481 const strBuf = this.strBuf; 28482 strBuf.length = 0; 28483 strBuf[0] = String.fromCharCode(ch); 28484 while ((ch = this.nextChar()) >= 0) { 28485 if (ch >= 0x30 && ch <= 0x39 || ch === 0x2d || ch === 0x2e) { 28486 strBuf.push(String.fromCharCode(ch)); 28487 } else { 28488 break; 28489 } 28490 } 28491 const value = parseFloat(strBuf.join("")); 28492 if (isNaN(value)) { 28493 throw new FormatError(`Invalid floating point number: ${value}`); 28494 } 28495 return value; 28496 } 28497} 28498 28499;// ./src/core/image_utils.js 28500 28501
vendor: 4,141 bytes, lines 28502-28672
28502class BaseLocalCache { 28503 constructor(options) { 28504 this._onlyRefs = options?.onlyRefs === true; 28505 if (!this._onlyRefs) { 28506 this._nameRefMap = new Map(); 28507 this._imageMap = new Map(); 28508 } 28509 this._imageCache = new RefSetCache(); 28510 } 28511 getByName(name) { 28512 if (this._onlyRefs) { 28513 unreachable("Should not call `getByName` method."); 28514 } 28515 const ref = this._nameRefMap.get(name); 28516 if (ref) { 28517 return this.getByRef(ref); 28518 } 28519 return this._imageMap.get(name) || null; 28520 } 28521 getByRef(ref) { 28522 return this._imageCache.get(ref) || null; 28523 } 28524 set(name, ref, data) { 28525 unreachable("Abstract method `set` called."); 28526 } 28527} 28528class LocalImageCache extends BaseLocalCache { 28529 set(name, ref = null, data) { 28530 if (typeof name !== "string") { 28531 throw new Error('LocalImageCache.set - expected "name" argument.'); 28532 } 28533 if (ref) { 28534 if (this._imageCache.has(ref)) { 28535 return; 28536 } 28537 this._nameRefMap.set(name, ref); 28538 this._imageCache.put(ref, data); 28539 return; 28540 } 28541 if (this._imageMap.has(name)) { 28542 return; 28543 } 28544 this._imageMap.set(name, data); 28545 } 28546} 28547class LocalColorSpaceCache extends BaseLocalCache { 28548 set(name = null, ref = null, data) { 28549 if (typeof name !== "string" && !ref) { 28550 throw new Error('LocalColorSpaceCache.set - expected "name" and/or "ref" argument.'); 28551 } 28552 if (ref) { 28553 if (this._imageCache.has(ref)) { 28554 return; 28555 } 28556 if (name !== null) { 28557 this._nameRefMap.set(name, ref); 28558 } 28559 this._imageCache.put(ref, data); 28560 return; 28561 } 28562 if (this._imageMap.has(name)) { 28563 return; 28564 } 28565 this._imageMap.set(name, data); 28566 } 28567} 28568class LocalFunctionCache extends BaseLocalCache { 28569 constructor(options) { 28570 super({ 28571 onlyRefs: true 28572 }); 28573 } 28574 set(name = null, ref, data) { 28575 if (!ref) { 28576 throw new Error('LocalFunctionCache.set - expected "ref" argument.'); 28577 } 28578 if (this._imageCache.has(ref)) { 28579 return; 28580 } 28581 this._imageCache.put(ref, data); 28582 } 28583} 28584class LocalGStateCache extends BaseLocalCache { 28585 set(name, ref = null, data) { 28586 if (typeof name !== "string") { 28587 throw new Error('LocalGStateCache.set - expected "name" argument.'); 28588 } 28589 if (ref) { 28590 if (this._imageCache.has(ref)) { 28591 return; 28592 } 28593 this._nameRefMap.set(name, ref); 28594 this._imageCache.put(ref, data); 28595 return; 28596 } 28597 if (this._imageMap.has(name)) { 28598 return; 28599 } 28600 this._imageMap.set(name, data); 28601 } 28602} 28603class LocalTilingPatternCache extends BaseLocalCache { 28604 constructor(options) { 28605 super({ 28606 onlyRefs: true 28607 }); 28608 } 28609 set(name = null, ref, data) { 28610 if (!ref) { 28611 throw new Error('LocalTilingPatternCache.set - expected "ref" argument.'); 28612 } 28613 if (this._imageCache.has(ref)) { 28614 return; 28615 } 28616 this._imageCache.put(ref, data); 28617 } 28618} 28619class RegionalImageCache extends BaseLocalCache { 28620 constructor(options) { 28621 super({ 28622 onlyRefs: true 28623 }); 28624 } 28625 set(name = null, ref, data) { 28626 if (!ref) { 28627 throw new Error('RegionalImageCache.set - expected "ref" argument.'); 28628 } 28629 if (this._imageCache.has(ref)) { 28630 return; 28631 } 28632 this._imageCache.put(ref, data); 28633 } 28634} 28635class GlobalColorSpaceCache extends BaseLocalCache { 28636 constructor(options) { 28637 super({ 28638 onlyRefs: true 28639 }); 28640 } 28641 set(name = null, ref, data) { 28642 if (!ref) { 28643 throw new Error('GlobalColorSpaceCache.set - expected "ref" argument.'); 28644 } 28645 if (this._imageCache.has(ref)) { 28646 return; 28647 } 28648 this._imageCache.put(ref, data); 28649 } 28650 clear() { 28651 this._imageCache.clear(); 28652 } 28653} 28654class GlobalImageCache { 28655 static NUM_PAGES_THRESHOLD = 2; 28656 static MIN_IMAGES_TO_CACHE = 10; 28657 static MAX_BYTE_SIZE = 5e7; 28658 #decodeFailedSet = new RefSet(); 28659 constructor() { 28660 this._refCache = new RefSetCache(); 28661 this._imageCache = new RefSetCache(); 28662 } 28663 get #byteSize() { 28664 let byteSize = 0; 28665 for (const imageData of this._imageCache) { 28666 byteSize += imageData.byteSize; 28667 } 28668 return byteSize; 28669 } 28670 get #cacheLimitReached() { 28671 if (this._imageCache.size < GlobalImageCache.MIN_IMAGES_TO_CACHE) { 28672 return false;
vendor: 1,826 bytes, lines 28673-28747
28673 } 28674 if (this.#byteSize < GlobalImageCache.MAX_BYTE_SIZE) { 28675 return false; 28676 } 28677 return true; 28678 } 28679 shouldCache(ref, pageIndex) { 28680 let pageIndexSet = this._refCache.get(ref); 28681 if (!pageIndexSet) { 28682 pageIndexSet = new Set(); 28683 this._refCache.put(ref, pageIndexSet); 28684 } 28685 pageIndexSet.add(pageIndex); 28686 if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) { 28687 return false; 28688 } 28689 if (!this._imageCache.has(ref) && this.#cacheLimitReached) { 28690 return false; 28691 } 28692 return true; 28693 } 28694 addDecodeFailed(ref) { 28695 this.#decodeFailedSet.put(ref); 28696 } 28697 hasDecodeFailed(ref) { 28698 return this.#decodeFailedSet.has(ref); 28699 } 28700 addByteSize(ref, byteSize) { 28701 const imageData = this._imageCache.get(ref); 28702 if (!imageData) { 28703 return; 28704 } 28705 if (imageData.byteSize) { 28706 return; 28707 } 28708 imageData.byteSize = byteSize; 28709 } 28710 getData(ref, pageIndex) { 28711 const pageIndexSet = this._refCache.get(ref); 28712 if (!pageIndexSet) { 28713 return null; 28714 } 28715 if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) { 28716 return null; 28717 } 28718 const imageData = this._imageCache.get(ref); 28719 if (!imageData) { 28720 return null; 28721 } 28722 pageIndexSet.add(pageIndex); 28723 return imageData; 28724 } 28725 setData(ref, data) { 28726 if (!this._refCache.has(ref)) { 28727 throw new Error('GlobalImageCache.setData - expected "shouldCache" to have been called.'); 28728 } 28729 if (this._imageCache.has(ref)) { 28730 return; 28731 } 28732 if (this.#cacheLimitReached) { 28733 warn("GlobalImageCache.setData - cache limit reached."); 28734 return; 28735 } 28736 this._imageCache.put(ref, data); 28737 } 28738 clear(onlyData = false) { 28739 if (!onlyData) { 28740 this.#decodeFailedSet.clear(); 28741 this._refCache.clear(); 28742 } 28743 this._imageCache.clear(); 28744 } 28745} 28746 28747;// ./src/core/function.js
vendor: 57,701 bytes, lines 28747-30629
28747 28748 28749 28750 28751 28752 28753 28754class PDFFunctionFactory { 28755 constructor({ 28756 xref, 28757 isEvalSupported = true 28758 }) { 28759 this.xref = xref; 28760 this.isEvalSupported = isEvalSupported !== false; 28761 } 28762 create(fn, parseArray = false) { 28763 let fnRef, parsedFn; 28764 if (fn instanceof Ref) { 28765 fnRef = fn; 28766 } else if (fn instanceof Dict) { 28767 fnRef = fn.objId; 28768 } else if (fn instanceof BaseStream) { 28769 fnRef = fn.dict?.objId; 28770 } 28771 if (fnRef) { 28772 const cachedFn = this._localFunctionCache.getByRef(fnRef); 28773 if (cachedFn) { 28774 return cachedFn; 28775 } 28776 } 28777 const fnObj = this.xref.fetchIfRef(fn); 28778 if (Array.isArray(fnObj)) { 28779 if (!parseArray) { 28780 throw new Error('PDFFunctionFactory.create - expected "parseArray" argument.'); 28781 } 28782 parsedFn = PDFFunction.parseArray(this, fnObj); 28783 } else { 28784 parsedFn = PDFFunction.parse(this, fnObj); 28785 } 28786 if (fnRef) { 28787 this._localFunctionCache.set(null, fnRef, parsedFn); 28788 } 28789 return parsedFn; 28790 } 28791 get _localFunctionCache() { 28792 return shadow(this, "_localFunctionCache", new LocalFunctionCache()); 28793 } 28794} 28795function toNumberArray(arr) { 28796 if (!Array.isArray(arr)) { 28797 return null; 28798 } 28799 if (!isNumberArray(arr, null)) { 28800 return arr.map(x => +x); 28801 } 28802 return arr; 28803} 28804class PDFFunction { 28805 static getSampleArray(size, outputSize, bps, stream) { 28806 let i, ii; 28807 let length = 1; 28808 for (i = 0, ii = size.length; i < ii; i++) { 28809 length *= size[i]; 28810 } 28811 length *= outputSize; 28812 const array = new Array(length); 28813 let codeSize = 0; 28814 let codeBuf = 0; 28815 const sampleMul = 1.0 / (2.0 ** bps - 1); 28816 const strBytes = stream.getBytes((length * bps + 7) / 8); 28817 let strIdx = 0; 28818 for (i = 0; i < length; i++) { 28819 while (codeSize < bps) { 28820 codeBuf <<= 8; 28821 codeBuf |= strBytes[strIdx++]; 28822 codeSize += 8; 28823 } 28824 codeSize -= bps; 28825 array[i] = (codeBuf >> codeSize) * sampleMul; 28826 codeBuf &= (1 << codeSize) - 1; 28827 } 28828 return array; 28829 } 28830 static parse(factory, fn) { 28831 const dict = fn.dict || fn; 28832 const typeNum = dict.get("FunctionType"); 28833 switch (typeNum) { 28834 case 0: 28835 return this.constructSampled(factory, fn, dict); 28836 case 1: 28837 break; 28838 case 2: 28839 return this.constructInterpolated(factory, dict); 28840 case 3: 28841 return this.constructStiched(factory, dict); 28842 case 4: 28843 return this.constructPostScript(factory, fn, dict); 28844 } 28845 throw new FormatError("Unknown type of function"); 28846 } 28847 static parseArray(factory, fnObj) { 28848 const { 28849 xref 28850 } = factory; 28851 const fnArray = []; 28852 for (const fn of fnObj) { 28853 fnArray.push(this.parse(factory, xref.fetchIfRef(fn))); 28854 } 28855 return function (src, srcOffset, dest, destOffset) { 28856 for (let i = 0, ii = fnArray.length; i < ii; i++) { 28857 fnArray[i](src, srcOffset, dest, destOffset + i); 28858 } 28859 }; 28860 } 28861 static constructSampled(factory, fn, dict) { 28862 function toMultiArray(arr) { 28863 const inputLength = arr.length; 28864 const out = []; 28865 let index = 0; 28866 for (let i = 0; i < inputLength; i += 2) { 28867 out[index++] = [arr[i], arr[i + 1]]; 28868 } 28869 return out; 28870 } 28871 function interpolate(x, xmin, xmax, ymin, ymax) { 28872 return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin)); 28873 } 28874 let domain = toNumberArray(dict.getArray("Domain")); 28875 let range = toNumberArray(dict.getArray("Range")); 28876 if (!domain || !range) { 28877 throw new FormatError("No domain or range"); 28878 } 28879 const inputSize = domain.length / 2; 28880 const outputSize = range.length / 2; 28881 domain = toMultiArray(domain); 28882 range = toMultiArray(range); 28883 const size = toNumberArray(dict.getArray("Size")); 28884 const bps = dict.get("BitsPerSample"); 28885 const order = dict.get("Order") || 1; 28886 if (order !== 1) { 28887 info("No support for cubic spline interpolation: " + order); 28888 } 28889 let encode = toNumberArray(dict.getArray("Encode")); 28890 if (!encode) { 28891 encode = []; 28892 for (let i = 0; i < inputSize; ++i) { 28893 encode.push([0, size[i] - 1]); 28894 } 28895 } else { 28896 encode = toMultiArray(encode); 28897 } 28898 let decode = toNumberArray(dict.getArray("Decode")); 28899 decode = !decode ? range : toMultiArray(decode); 28900 const samples = this.getSampleArray(size, outputSize, bps, fn); 28901 return function constructSampledFn(src, srcOffset, dest, destOffset) { 28902 const cubeVertices = 1 << inputSize; 28903 const cubeN = new Float64Array(cubeVertices).fill(1); 28904 const cubeVertex = new Uint32Array(cubeVertices); 28905 let i, j; 28906 let k = outputSize, 28907 pos = 1; 28908 for (i = 0; i < inputSize; ++i) { 28909 const domain_2i = domain[i][0]; 28910 const domain_2i_1 = domain[i][1]; 28911 const xi = MathClamp(src[srcOffset + i], domain_2i, domain_2i_1); 28912 let e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]); 28913 const size_i = size[i]; 28914 e = MathClamp(e, 0, size_i - 1); 28915 const e0 = e < size_i - 1 ? Math.floor(e) : e - 1; 28916 const n0 = e0 + 1 - e; 28917 const n1 = e - e0; 28918 const offset0 = e0 * k; 28919 const offset1 = offset0 + k; 28920 for (j = 0; j < cubeVertices; j++) { 28921 if (j & pos) { 28922 cubeN[j] *= n1; 28923 cubeVertex[j] += offset1; 28924 } else { 28925 cubeN[j] *= n0; 28926 cubeVertex[j] += offset0; 28927 } 28928 } 28929 k *= size_i; 28930 pos <<= 1; 28931 } 28932 for (j = 0; j < outputSize; ++j) { 28933 let rj = 0; 28934 for (i = 0; i < cubeVertices; i++) { 28935 rj += samples[cubeVertex[i] + j] * cubeN[i]; 28936 } 28937 rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]); 28938 dest[destOffset + j] = MathClamp(rj, range[j][0], range[j][1]); 28939 } 28940 }; 28941 } 28942 static constructInterpolated(factory, dict) { 28943 const c0 = toNumberArray(dict.getArray("C0")) || [0]; 28944 const c1 = toNumberArray(dict.getArray("C1")) || [1]; 28945 const n = dict.get("N"); 28946 const diff = []; 28947 for (let i = 0, ii = c0.length; i < ii; ++i) { 28948 diff.push(c1[i] - c0[i]); 28949 } 28950 const length = diff.length; 28951 return function constructInterpolatedFn(src, srcOffset, dest, destOffset) { 28952 const x = n === 1 ? src[srcOffset] : src[srcOffset] ** n; 28953 for (let j = 0; j < length; ++j) { 28954 dest[destOffset + j] = c0[j] + x * diff[j]; 28955 } 28956 }; 28957 } 28958 static constructStiched(factory, dict) { 28959 const domain = toNumberArray(dict.getArray("Domain")); 28960 if (!domain) { 28961 throw new FormatError("No domain"); 28962 } 28963 const inputSize = domain.length / 2; 28964 if (inputSize !== 1) { 28965 throw new FormatError("Bad domain for stiched function"); 28966 } 28967 const { 28968 xref 28969 } = factory; 28970 const fns = []; 28971 for (const fn of dict.get("Functions")) { 28972 fns.push(this.parse(factory, xref.fetchIfRef(fn))); 28973 } 28974 const bounds = toNumberArray(dict.getArray("Bounds")); 28975 const encode = toNumberArray(dict.getArray("Encode")); 28976 const tmpBuf = new Float32Array(1); 28977 return function constructStichedFn(src, srcOffset, dest, destOffset) { 28978 const v = MathClamp(src[srcOffset], domain[0], domain[1]); 28979 const length = bounds.length; 28980 let i; 28981 for (i = 0; i < length; ++i) { 28982 if (v < bounds[i]) { 28983 break; 28984 } 28985 } 28986 let dmin = domain[0]; 28987 if (i > 0) { 28988 dmin = bounds[i - 1]; 28989 } 28990 let dmax = domain[1]; 28991 if (i < bounds.length) { 28992 dmax = bounds[i]; 28993 } 28994 const rmin = encode[2 * i]; 28995 const rmax = encode[2 * i + 1]; 28996 tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin); 28997 fns[i](tmpBuf, 0, dest, destOffset); 28998 }; 28999 } 29000 static constructPostScript(factory, fn, dict) { 29001 const domain = toNumberArray(dict.getArray("Domain")); 29002 const range = toNumberArray(dict.getArray("Range")); 29003 if (!domain) { 29004 throw new FormatError("No domain."); 29005 } 29006 if (!range) { 29007 throw new FormatError("No range."); 29008 } 29009 const lexer = new PostScriptLexer(fn); 29010 const parser = new PostScriptParser(lexer); 29011 const code = parser.parse(); 29012 if (factory.isEvalSupported && FeatureTest.isEvalSupported) { 29013 const compiled = new PostScriptCompiler().compile(code, domain, range); 29014 if (compiled) { 29015 return new Function("src", "srcOffset", "dest", "destOffset", compiled); 29016 } 29017 } 29018 info("Unable to compile PS function"); 29019 const numOutputs = range.length >> 1; 29020 const numInputs = domain.length >> 1; 29021 const evaluator = new PostScriptEvaluator(code); 29022 const cache = Object.create(null); 29023 const MAX_CACHE_SIZE = 2048 * 4; 29024 let cache_available = MAX_CACHE_SIZE; 29025 const tmpBuf = new Float32Array(numInputs); 29026 return function constructPostScriptFn(src, srcOffset, dest, destOffset) { 29027 let i, value; 29028 let key = ""; 29029 const input = tmpBuf; 29030 for (i = 0; i < numInputs; i++) { 29031 value = src[srcOffset + i]; 29032 input[i] = value; 29033 key += value + "_"; 29034 } 29035 const cachedValue = cache[key]; 29036 if (cachedValue !== undefined) { 29037 dest.set(cachedValue, destOffset); 29038 return; 29039 } 29040 const output = new Float32Array(numOutputs); 29041 const stack = evaluator.execute(input); 29042 const stackIndex = stack.length - numOutputs; 29043 for (i = 0; i < numOutputs; i++) { 29044 value = stack[stackIndex + i]; 29045 let bound = range[i * 2]; 29046 if (value < bound) { 29047 value = bound; 29048 } else { 29049 bound = range[i * 2 + 1]; 29050 if (value > bound) { 29051 value = bound; 29052 } 29053 } 29054 output[i] = value; 29055 } 29056 if (cache_available > 0) { 29057 cache_available--; 29058 cache[key] = output; 29059 } 29060 dest.set(output, destOffset); 29061 }; 29062 } 29063} 29064function isPDFFunction(v) { 29065 let fnDict; 29066 if (v instanceof Dict) { 29067 fnDict = v; 29068 } else if (v instanceof BaseStream) { 29069 fnDict = v.dict; 29070 } else { 29071 return false; 29072 } 29073 return fnDict.has("FunctionType"); 29074} 29075class PostScriptStack { 29076 static MAX_STACK_SIZE = 100; 29077 constructor(initialStack) { 29078 this.stack = initialStack ? Array.from(initialStack) : []; 29079 } 29080 push(value) { 29081 if (this.stack.length >= PostScriptStack.MAX_STACK_SIZE) { 29082 throw new Error("PostScript function stack overflow."); 29083 } 29084 this.stack.push(value); 29085 } 29086 pop() { 29087 if (this.stack.length <= 0) { 29088 throw new Error("PostScript function stack underflow."); 29089 } 29090 return this.stack.pop(); 29091 } 29092 copy(n) { 29093 if (this.stack.length + n >= PostScriptStack.MAX_STACK_SIZE) { 29094 throw new Error("PostScript function stack overflow."); 29095 } 29096 const stack = this.stack; 29097 for (let i = stack.length - n, j = n - 1; j >= 0; j--, i++) { 29098 stack.push(stack[i]); 29099 } 29100 } 29101 index(n) { 29102 this.push(this.stack[this.stack.length - n - 1]); 29103 } 29104 roll(n, p) { 29105 const stack = this.stack; 29106 const l = stack.length - n; 29107 const r = stack.length - 1; 29108 const c = l + (p - Math.floor(p / n) * n); 29109 for (let i = l, j = r; i < j; i++, j--) { 29110 const t = stack[i]; 29111 stack[i] = stack[j]; 29112 stack[j] = t; 29113 } 29114 for (let i = l, j = c - 1; i < j; i++, j--) { 29115 const t = stack[i]; 29116 stack[i] = stack[j]; 29117 stack[j] = t; 29118 } 29119 for (let i = c, j = r; i < j; i++, j--) { 29120 const t = stack[i]; 29121 stack[i] = stack[j]; 29122 stack[j] = t; 29123 } 29124 } 29125} 29126class PostScriptEvaluator { 29127 constructor(operators) { 29128 this.operators = operators; 29129 } 29130 execute(initialStack) { 29131 const stack = new PostScriptStack(initialStack); 29132 let counter = 0; 29133 const operators = this.operators; 29134 const length = operators.length; 29135 let operator, a, b; 29136 while (counter < length) { 29137 operator = operators[counter++]; 29138 if (typeof operator === "number") { 29139 stack.push(operator); 29140 continue; 29141 } 29142 switch (operator) { 29143 case "jz": 29144 b = stack.pop(); 29145 a = stack.pop(); 29146 if (!a) { 29147 counter = b; 29148 } 29149 break; 29150 case "j": 29151 a = stack.pop(); 29152 counter = a; 29153 break; 29154 case "abs": 29155 a = stack.pop(); 29156 stack.push(Math.abs(a)); 29157 break; 29158 case "add": 29159 b = stack.pop(); 29160 a = stack.pop(); 29161 stack.push(a + b); 29162 break; 29163 case "and": 29164 b = stack.pop(); 29165 a = stack.pop(); 29166 if (typeof a === "boolean" && typeof b === "boolean") { 29167 stack.push(a && b); 29168 } else { 29169 stack.push(a & b); 29170 } 29171 break; 29172 case "atan": 29173 b = stack.pop(); 29174 a = stack.pop(); 29175 a = Math.atan2(a, b) / Math.PI * 180; 29176 if (a < 0) { 29177 a += 360; 29178 } 29179 stack.push(a); 29180 break; 29181 case "bitshift": 29182 b = stack.pop(); 29183 a = stack.pop(); 29184 if (a > 0) { 29185 stack.push(a << b); 29186 } else { 29187 stack.push(a >> b); 29188 } 29189 break; 29190 case "ceiling": 29191 a = stack.pop(); 29192 stack.push(Math.ceil(a)); 29193 break; 29194 case "copy": 29195 a = stack.pop(); 29196 stack.copy(a); 29197 break; 29198 case "cos": 29199 a = stack.pop(); 29200 stack.push(Math.cos(a % 360 / 180 * Math.PI)); 29201 break; 29202 case "cvi": 29203 a = stack.pop() | 0; 29204 stack.push(a); 29205 break; 29206 case "cvr": 29207 break; 29208 case "div": 29209 b = stack.pop(); 29210 a = stack.pop(); 29211 stack.push(a / b); 29212 break; 29213 case "dup": 29214 stack.copy(1); 29215 break; 29216 case "eq": 29217 b = stack.pop(); 29218 a = stack.pop(); 29219 stack.push(a === b); 29220 break; 29221 case "exch": 29222 stack.roll(2, 1); 29223 break; 29224 case "exp": 29225 b = stack.pop(); 29226 a = stack.pop(); 29227 stack.push(a ** b); 29228 break; 29229 case "false": 29230 stack.push(false); 29231 break; 29232 case "floor": 29233 a = stack.pop(); 29234 stack.push(Math.floor(a)); 29235 break; 29236 case "ge": 29237 b = stack.pop(); 29238 a = stack.pop(); 29239 stack.push(a >= b); 29240 break; 29241 case "gt": 29242 b = stack.pop(); 29243 a = stack.pop(); 29244 stack.push(a > b); 29245 break; 29246 case "idiv": 29247 b = stack.pop(); 29248 a = stack.pop(); 29249 stack.push(a / b | 0); 29250 break; 29251 case "index": 29252 a = stack.pop(); 29253 stack.index(a); 29254 break; 29255 case "le": 29256 b = stack.pop(); 29257 a = stack.pop(); 29258 stack.push(a <= b); 29259 break; 29260 case "ln": 29261 a = stack.pop(); 29262 stack.push(Math.log(a)); 29263 break; 29264 case "log": 29265 a = stack.pop(); 29266 stack.push(Math.log10(a)); 29267 break; 29268 case "lt": 29269 b = stack.pop(); 29270 a = stack.pop(); 29271 stack.push(a < b); 29272 break; 29273 case "mod": 29274 b = stack.pop(); 29275 a = stack.pop(); 29276 stack.push(a % b); 29277 break; 29278 case "mul": 29279 b = stack.pop(); 29280 a = stack.pop(); 29281 stack.push(a * b); 29282 break; 29283 case "ne": 29284 b = stack.pop(); 29285 a = stack.pop(); 29286 stack.push(a !== b); 29287 break; 29288 case "neg": 29289 a = stack.pop(); 29290 stack.push(-a); 29291 break; 29292 case "not": 29293 a = stack.pop(); 29294 if (typeof a === "boolean") { 29295 stack.push(!a); 29296 } else { 29297 stack.push(~a); 29298 } 29299 break; 29300 case "or": 29301 b = stack.pop(); 29302 a = stack.pop(); 29303 if (typeof a === "boolean" && typeof b === "boolean") { 29304 stack.push(a || b); 29305 } else { 29306 stack.push(a | b); 29307 } 29308 break; 29309 case "pop": 29310 stack.pop(); 29311 break; 29312 case "roll": 29313 b = stack.pop(); 29314 a = stack.pop(); 29315 stack.roll(a, b); 29316 break; 29317 case "round": 29318 a = stack.pop(); 29319 stack.push(Math.round(a)); 29320 break; 29321 case "sin": 29322 a = stack.pop(); 29323 stack.push(Math.sin(a % 360 / 180 * Math.PI)); 29324 break; 29325 case "sqrt": 29326 a = stack.pop(); 29327 stack.push(Math.sqrt(a)); 29328 break; 29329 case "sub": 29330 b = stack.pop(); 29331 a = stack.pop(); 29332 stack.push(a - b); 29333 break; 29334 case "true": 29335 stack.push(true); 29336 break; 29337 case "truncate": 29338 a = stack.pop(); 29339 a = a < 0 ? Math.ceil(a) : Math.floor(a); 29340 stack.push(a); 29341 break; 29342 case "xor": 29343 b = stack.pop(); 29344 a = stack.pop(); 29345 if (typeof a === "boolean" && typeof b === "boolean") { 29346 stack.push(a !== b); 29347 } else { 29348 stack.push(a ^ b); 29349 } 29350 break; 29351 default: 29352 throw new FormatError(`Unknown operator ${operator}`); 29353 } 29354 } 29355 return stack.stack; 29356 } 29357} 29358class AstNode { 29359 constructor(type) { 29360 this.type = type; 29361 } 29362 visit(visitor) { 29363 unreachable("abstract method"); 29364 } 29365} 29366class AstArgument extends AstNode { 29367 constructor(index, min, max) { 29368 super("args"); 29369 this.index = index; 29370 this.min = min; 29371 this.max = max; 29372 } 29373 visit(visitor) { 29374 visitor.visitArgument(this); 29375 } 29376} 29377class AstLiteral extends AstNode { 29378 constructor(number) { 29379 super("literal"); 29380 this.number = number; 29381 this.min = number; 29382 this.max = number; 29383 } 29384 visit(visitor) { 29385 visitor.visitLiteral(this); 29386 } 29387} 29388class AstBinaryOperation extends AstNode { 29389 constructor(op, arg1, arg2, min, max) { 29390 super("binary"); 29391 this.op = op; 29392 this.arg1 = arg1; 29393 this.arg2 = arg2; 29394 this.min = min; 29395 this.max = max; 29396 } 29397 visit(visitor) { 29398 visitor.visitBinaryOperation(this); 29399 } 29400} 29401class AstMin extends AstNode { 29402 constructor(arg, max) { 29403 super("max"); 29404 this.arg = arg; 29405 this.min = arg.min; 29406 this.max = max; 29407 } 29408 visit(visitor) { 29409 visitor.visitMin(this); 29410 } 29411} 29412class AstVariable extends AstNode { 29413 constructor(index, min, max) { 29414 super("var"); 29415 this.index = index; 29416 this.min = min; 29417 this.max = max; 29418 } 29419 visit(visitor) { 29420 visitor.visitVariable(this); 29421 } 29422} 29423class AstVariableDefinition extends AstNode { 29424 constructor(variable, arg) { 29425 super("definition"); 29426 this.variable = variable; 29427 this.arg = arg; 29428 } 29429 visit(visitor) { 29430 visitor.visitVariableDefinition(this); 29431 } 29432} 29433class ExpressionBuilderVisitor { 29434 constructor() { 29435 this.parts = []; 29436 } 29437 visitArgument(arg) { 29438 this.parts.push("Math.max(", arg.min, ", Math.min(", arg.max, ", src[srcOffset + ", arg.index, "]))"); 29439 } 29440 visitVariable(variable) { 29441 this.parts.push("v", variable.index); 29442 } 29443 visitLiteral(literal) { 29444 this.parts.push(literal.number); 29445 } 29446 visitBinaryOperation(operation) { 29447 this.parts.push("("); 29448 operation.arg1.visit(this); 29449 this.parts.push(" ", operation.op, " "); 29450 operation.arg2.visit(this); 29451 this.parts.push(")"); 29452 } 29453 visitVariableDefinition(definition) { 29454 this.parts.push("var "); 29455 definition.variable.visit(this); 29456 this.parts.push(" = "); 29457 definition.arg.visit(this); 29458 this.parts.push(";"); 29459 } 29460 visitMin(max) { 29461 this.parts.push("Math.min("); 29462 max.arg.visit(this); 29463 this.parts.push(", ", max.max, ")"); 29464 } 29465 toString() { 29466 return this.parts.join(""); 29467 } 29468} 29469function buildAddOperation(num1, num2) { 29470 if (num2.type === "literal" && num2.number === 0) { 29471 return num1; 29472 } 29473 if (num1.type === "literal" && num1.number === 0) { 29474 return num2; 29475 } 29476 if (num2.type === "literal" && num1.type === "literal") { 29477 return new AstLiteral(num1.number + num2.number); 29478 } 29479 return new AstBinaryOperation("+", num1, num2, num1.min + num2.min, num1.max + num2.max); 29480} 29481function buildMulOperation(num1, num2) { 29482 if (num2.type === "literal") { 29483 if (num2.number === 0) { 29484 return new AstLiteral(0); 29485 } else if (num2.number === 1) { 29486 return num1; 29487 } else if (num1.type === "literal") { 29488 return new AstLiteral(num1.number * num2.number); 29489 } 29490 } 29491 if (num1.type === "literal") { 29492 if (num1.number === 0) { 29493 return new AstLiteral(0); 29494 } else if (num1.number === 1) { 29495 return num2; 29496 } 29497 } 29498 const min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max); 29499 const max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max); 29500 return new AstBinaryOperation("*", num1, num2, min, max); 29501} 29502function buildSubOperation(num1, num2) { 29503 if (num2.type === "literal") { 29504 if (num2.number === 0) { 29505 return num1; 29506 } else if (num1.type === "literal") { 29507 return new AstLiteral(num1.number - num2.number); 29508 } 29509 } 29510 if (num2.type === "binary" && num2.op === "-" && num1.type === "literal" && num1.number === 1 && num2.arg1.type === "literal" && num2.arg1.number === 1) { 29511 return num2.arg2; 29512 } 29513 return new AstBinaryOperation("-", num1, num2, num1.min - num2.max, num1.max - num2.min); 29514} 29515function buildMinOperation(num1, max) { 29516 if (num1.min >= max) { 29517 return new AstLiteral(max); 29518 } else if (num1.max <= max) { 29519 return num1; 29520 } 29521 return new AstMin(num1, max); 29522} 29523class PostScriptCompiler { 29524 compile(code, domain, range) { 29525 const stack = []; 29526 const instructions = []; 29527 const inputSize = domain.length >> 1, 29528 outputSize = range.length >> 1; 29529 let lastRegister = 0; 29530 let n, j; 29531 let num1, num2, ast1, ast2, tmpVar, item; 29532 for (let i = 0; i < inputSize; i++) { 29533 stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1])); 29534 } 29535 for (let i = 0, ii = code.length; i < ii; i++) { 29536 item = code[i]; 29537 if (typeof item === "number") { 29538 stack.push(new AstLiteral(item)); 29539 continue; 29540 } 29541 switch (item) { 29542 case "add": 29543 if (stack.length < 2) { 29544 return null; 29545 } 29546 num2 = stack.pop(); 29547 num1 = stack.pop(); 29548 stack.push(buildAddOperation(num1, num2)); 29549 break; 29550 case "cvr": 29551 if (stack.length < 1) { 29552 return null; 29553 } 29554 break; 29555 case "mul": 29556 if (stack.length < 2) { 29557 return null; 29558 } 29559 num2 = stack.pop(); 29560 num1 = stack.pop(); 29561 stack.push(buildMulOperation(num1, num2)); 29562 break; 29563 case "sub": 29564 if (stack.length < 2) { 29565 return null; 29566 } 29567 num2 = stack.pop(); 29568 num1 = stack.pop(); 29569 stack.push(buildSubOperation(num1, num2)); 29570 break; 29571 case "exch": 29572 if (stack.length < 2) { 29573 return null; 29574 } 29575 ast1 = stack.pop(); 29576 ast2 = stack.pop(); 29577 stack.push(ast1, ast2); 29578 break; 29579 case "pop": 29580 if (stack.length < 1) { 29581 return null; 29582 } 29583 stack.pop(); 29584 break; 29585 case "index": 29586 if (stack.length < 1) { 29587 return null; 29588 } 29589 num1 = stack.pop(); 29590 if (num1.type !== "literal") { 29591 return null; 29592 } 29593 n = num1.number; 29594 if (n < 0 || !Number.isInteger(n) || stack.length < n) { 29595 return null; 29596 } 29597 ast1 = stack[stack.length - n - 1]; 29598 if (ast1.type === "literal" || ast1.type === "var") { 29599 stack.push(ast1); 29600 break; 29601 } 29602 tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max); 29603 stack[stack.length - n - 1] = tmpVar; 29604 stack.push(tmpVar); 29605 instructions.push(new AstVariableDefinition(tmpVar, ast1)); 29606 break; 29607 case "dup": 29608 if (stack.length < 1) { 29609 return null; 29610 } 29611 if (typeof code[i + 1] === "number" && code[i + 2] === "gt" && code[i + 3] === i + 7 && code[i + 4] === "jz" && code[i + 5] === "pop" && code[i + 6] === code[i + 1]) { 29612 num1 = stack.pop(); 29613 stack.push(buildMinOperation(num1, code[i + 1])); 29614 i += 6; 29615 break; 29616 } 29617 ast1 = stack.at(-1); 29618 if (ast1.type === "literal" || ast1.type === "var") { 29619 stack.push(ast1); 29620 break; 29621 } 29622 tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max); 29623 stack[stack.length - 1] = tmpVar; 29624 stack.push(tmpVar); 29625 instructions.push(new AstVariableDefinition(tmpVar, ast1)); 29626 break; 29627 case "roll": 29628 if (stack.length < 2) { 29629 return null; 29630 } 29631 num2 = stack.pop(); 29632 num1 = stack.pop(); 29633 if (num2.type !== "literal" || num1.type !== "literal") { 29634 return null; 29635 } 29636 j = num2.number; 29637 n = num1.number; 29638 if (n <= 0 || !Number.isInteger(n) || !Number.isInteger(j) || stack.length < n) { 29639 return null; 29640 } 29641 j = (j % n + n) % n; 29642 if (j === 0) { 29643 break; 29644 } 29645 stack.push(...stack.splice(stack.length - n, n - j)); 29646 break; 29647 default: 29648 return null; 29649 } 29650 } 29651 if (stack.length !== outputSize) { 29652 return null; 29653 } 29654 const result = []; 29655 for (const instruction of instructions) { 29656 const statementBuilder = new ExpressionBuilderVisitor(); 29657 instruction.visit(statementBuilder); 29658 result.push(statementBuilder.toString()); 29659 } 29660 for (let i = 0, ii = stack.length; i < ii; i++) { 29661 const expr = stack[i], 29662 statementBuilder = new ExpressionBuilderVisitor(); 29663 expr.visit(statementBuilder); 29664 const min = range[i * 2], 29665 max = range[i * 2 + 1]; 29666 const out = [statementBuilder.toString()]; 29667 if (min > expr.min) { 29668 out.unshift("Math.max(", min, ", "); 29669 out.push(")"); 29670 } 29671 if (max < expr.max) { 29672 out.unshift("Math.min(", max, ", "); 29673 out.push(")"); 29674 } 29675 out.unshift("dest[destOffset + ", i, "] = "); 29676 out.push(";"); 29677 result.push(out.join("")); 29678 } 29679 return result.join("\n"); 29680 } 29681} 29682 29683;// ./src/core/bidi.js 29684 29685const baseTypes = ["BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "S", "B", "S", "WS", "B", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "B", "B", "B", "S", "WS", "ON", "ON", "ET", "ET", "ET", "ON", "ON", "ON", "ON", "ON", "ES", "CS", "ES", "CS", "CS", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "CS", "ON", "ON", "ON", "ON", "ON", "ON", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "ON", "ON", "ON", "ON", "ON", "ON", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "ON", "ON", "ON", "ON", "BN", "BN", "BN", "BN", "BN", "BN", "B", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "CS", "ON", "ET", "ET", "ET", "ET", "ON", "ON", "ON", "ON", "L", "ON", "ON", "BN", "ON", "ON", "ET", "ET", "EN", "EN", "ON", "L", "ON", "ON", "ON", "EN", "L", "ON", "ON", "ON", "ON", "ON", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "ON", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "ON", "L", "L", "L", "L", "L", "L", "L", "L"]; 29686const arabicTypes = ["AN", "AN", "AN", "AN", "AN", "AN", "ON", "ON", "AL", "ET", "ET", "AL", "CS", "AL", "ON", "ON", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AL", "AL", "", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "ET", "AN", "AN", "AL", "AL", "AL", "NSM", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AN", "ON", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AL", "AL", "NSM", "NSM", "ON", "NSM", "NSM", "NSM", "NSM", "AL", "AL", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "AL", "AL", "AL", "AL", "AL", "AL"]; 29687function isOdd(i) { 29688 return (i & 1) !== 0; 29689} 29690function isEven(i) { 29691 return (i & 1) === 0; 29692} 29693function findUnequal(arr, start, value) { 29694 let j, jj; 29695 for (j = start, jj = arr.length; j < jj; ++j) { 29696 if (arr[j] !== value) { 29697 return j; 29698 } 29699 } 29700 return j; 29701} 29702function reverseValues(arr, start, end) { 29703 for (let i = start, j = end - 1; i < j; ++i, --j) { 29704 const temp = arr[i]; 29705 arr[i] = arr[j]; 29706 arr[j] = temp; 29707 } 29708} 29709function createBidiText(str, isLTR, vertical = false) { 29710 let dir = "ltr"; 29711 if (vertical) { 29712 dir = "ttb"; 29713 } else if (!isLTR) { 29714 dir = "rtl"; 29715 } 29716 return { 29717 str, 29718 dir 29719 }; 29720} 29721const chars = []; 29722const types = []; 29723function bidi(str, startLevel = -1, vertical = false) { 29724 let isLTR = true; 29725 const strLength = str.length; 29726 if (strLength === 0 || vertical) { 29727 return createBidiText(str, isLTR, vertical); 29728 } 29729 chars.length = strLength; 29730 types.length = strLength; 29731 let numBidi = 0; 29732 let i, ii; 29733 for (i = 0; i < strLength; ++i) { 29734 chars[i] = str.charAt(i); 29735 const charCode = str.charCodeAt(i); 29736 let charType = "L"; 29737 if (charCode <= 0x00ff) { 29738 charType = baseTypes[charCode]; 29739 } else if (0x0590 <= charCode && charCode <= 0x05f4) { 29740 charType = "R"; 29741 } else if (0x0600 <= charCode && charCode <= 0x06ff) { 29742 charType = arabicTypes[charCode & 0xff]; 29743 if (!charType) { 29744 warn("Bidi: invalid Unicode character " + charCode.toString(16)); 29745 } 29746 } else if (0x0700 <= charCode && charCode <= 0x08ac || 0xfb50 <= charCode && charCode <= 0xfdff || 0xfe70 <= charCode && charCode <= 0xfeff) { 29747 charType = "AL"; 29748 } 29749 if (charType === "R" || charType === "AL" || charType === "AN") { 29750 numBidi++; 29751 } 29752 types[i] = charType; 29753 } 29754 if (numBidi === 0) { 29755 isLTR = true; 29756 return createBidiText(str, isLTR); 29757 } 29758 if (startLevel === -1) { 29759 if (numBidi / strLength < 0.3 && strLength > 4) { 29760 isLTR = true; 29761 startLevel = 0; 29762 } else { 29763 isLTR = false; 29764 startLevel = 1; 29765 } 29766 } 29767 const levels = []; 29768 for (i = 0; i < strLength; ++i) { 29769 levels[i] = startLevel; 29770 } 29771 const e = isOdd(startLevel) ? "R" : "L"; 29772 const sor = e; 29773 const eor = sor; 29774 let lastType = sor; 29775 for (i = 0; i < strLength; ++i) { 29776 if (types[i] === "NSM") { 29777 types[i] = lastType; 29778 } else { 29779 lastType = types[i]; 29780 } 29781 } 29782 lastType = sor; 29783 let t; 29784 for (i = 0; i < strLength; ++i) { 29785 t = types[i]; 29786 if (t === "EN") { 29787 types[i] = lastType === "AL" ? "AN" : "EN"; 29788 } else if (t === "R" || t === "L" || t === "AL") { 29789 lastType = t; 29790 } 29791 } 29792 for (i = 0; i < strLength; ++i) { 29793 t = types[i]; 29794 if (t === "AL") { 29795 types[i] = "R"; 29796 } 29797 } 29798 for (i = 1; i < strLength - 1; ++i) { 29799 if (types[i] === "ES" && types[i - 1] === "EN" && types[i + 1] === "EN") { 29800 types[i] = "EN"; 29801 } 29802 if (types[i] === "CS" && (types[i - 1] === "EN" || types[i - 1] === "AN") && types[i + 1] === types[i - 1]) { 29803 types[i] = types[i - 1]; 29804 } 29805 } 29806 for (i = 0; i < strLength; ++i) { 29807 if (types[i] === "EN") { 29808 for (let j = i - 1; j >= 0; --j) { 29809 if (types[j] !== "ET") { 29810 break; 29811 } 29812 types[j] = "EN"; 29813 } 29814 for (let j = i + 1; j < strLength; ++j) { 29815 if (types[j] !== "ET") { 29816 break; 29817 } 29818 types[j] = "EN"; 29819 } 29820 } 29821 } 29822 for (i = 0; i < strLength; ++i) { 29823 t = types[i]; 29824 if (t === "WS" || t === "ES" || t === "ET" || t === "CS") { 29825 types[i] = "ON"; 29826 } 29827 } 29828 lastType = sor; 29829 for (i = 0; i < strLength; ++i) { 29830 t = types[i]; 29831 if (t === "EN") { 29832 types[i] = lastType === "L" ? "L" : "EN"; 29833 } else if (t === "R" || t === "L") { 29834 lastType = t; 29835 } 29836 } 29837 for (i = 0; i < strLength; ++i) { 29838 if (types[i] === "ON") { 29839 const end = findUnequal(types, i + 1, "ON"); 29840 let before = sor; 29841 if (i > 0) { 29842 before = types[i - 1]; 29843 } 29844 let after = eor; 29845 if (end + 1 < strLength) { 29846 after = types[end + 1]; 29847 } 29848 if (before !== "L") { 29849 before = "R"; 29850 } 29851 if (after !== "L") { 29852 after = "R"; 29853 } 29854 if (before === after) { 29855 types.fill(before, i, end); 29856 } 29857 i = end - 1; 29858 } 29859 } 29860 for (i = 0; i < strLength; ++i) { 29861 if (types[i] === "ON") { 29862 types[i] = e; 29863 } 29864 } 29865 for (i = 0; i < strLength; ++i) { 29866 t = types[i]; 29867 if (isEven(levels[i])) { 29868 if (t === "R") { 29869 levels[i] += 1; 29870 } else if (t === "AN" || t === "EN") { 29871 levels[i] += 2; 29872 } 29873 } else if (t === "L" || t === "AN" || t === "EN") { 29874 levels[i] += 1; 29875 } 29876 } 29877 let highestLevel = -1; 29878 let lowestOddLevel = 99; 29879 let level; 29880 for (i = 0, ii = levels.length; i < ii; ++i) { 29881 level = levels[i]; 29882 if (highestLevel < level) { 29883 highestLevel = level; 29884 } 29885 if (lowestOddLevel > level && isOdd(level)) { 29886 lowestOddLevel = level; 29887 } 29888 } 29889 for (level = highestLevel; level >= lowestOddLevel; --level) { 29890 let start = -1; 29891 for (i = 0, ii = levels.length; i < ii; ++i) { 29892 if (levels[i] < level) { 29893 if (start >= 0) { 29894 reverseValues(chars, start, i); 29895 start = -1; 29896 } 29897 } else if (start < 0) { 29898 start = i; 29899 } 29900 } 29901 if (start >= 0) { 29902 reverseValues(chars, start, levels.length); 29903 } 29904 } 29905 for (i = 0, ii = chars.length; i < ii; ++i) { 29906 const ch = chars[i]; 29907 if (ch === "<" || ch === ">") { 29908 chars[i] = ""; 29909 } 29910 } 29911 return createBidiText(chars.join(""), isLTR); 29912} 29913 29914;// ./src/shared/obj-bin-transform.js 29915 29916class CssFontInfo { 29917 #buffer; 29918 #view; 29919 #decoder; 29920 static strings = ["fontFamily", "fontWeight", "italicAngle"]; 29921 static write(info) { 29922 const encoder = new TextEncoder(); 29923 const encodedStrings = {}; 29924 let stringsLength = 0; 29925 for (const prop of CssFontInfo.strings) { 29926 const encoded = encoder.encode(info[prop]); 29927 encodedStrings[prop] = encoded; 29928 stringsLength += 4 + encoded.length; 29929 } 29930 const buffer = new ArrayBuffer(stringsLength); 29931 const data = new Uint8Array(buffer); 29932 const view = new DataView(buffer); 29933 let offset = 0; 29934 for (const prop of CssFontInfo.strings) { 29935 const encoded = encodedStrings[prop]; 29936 const length = encoded.length; 29937 view.setUint32(offset, length); 29938 data.set(encoded, offset + 4); 29939 offset += 4 + length; 29940 } 29941 assert(offset === buffer.byteLength, "CssFontInfo.write: Buffer overflow"); 29942 return buffer; 29943 } 29944 constructor(buffer) { 29945 this.#buffer = buffer; 29946 this.#view = new DataView(this.#buffer); 29947 this.#decoder = new TextDecoder(); 29948 } 29949 #readString(index) { 29950 assert(index < CssFontInfo.strings.length, "Invalid string index"); 29951 let offset = 0; 29952 for (let i = 0; i < index; i++) { 29953 offset += this.#view.getUint32(offset) + 4; 29954 } 29955 const length = this.#view.getUint32(offset); 29956 return this.#decoder.decode(new Uint8Array(this.#buffer, offset + 4, length)); 29957 } 29958 get fontFamily() { 29959 return this.#readString(0); 29960 } 29961 get fontWeight() { 29962 return this.#readString(1); 29963 } 29964 get italicAngle() { 29965 return this.#readString(2); 29966 } 29967} 29968class SystemFontInfo { 29969 #buffer; 29970 #view; 29971 #decoder; 29972 static strings = ["css", "loadedName", "baseFontName", "src"]; 29973 static write(info) { 29974 const encoder = new TextEncoder(); 29975 const encodedStrings = {}; 29976 let stringsLength = 0; 29977 for (const prop of SystemFontInfo.strings) { 29978 const encoded = encoder.encode(info[prop]); 29979 encodedStrings[prop] = encoded; 29980 stringsLength += 4 + encoded.length; 29981 } 29982 stringsLength += 4; 29983 let encodedStyleStyle, 29984 encodedStyleWeight, 29985 lengthEstimate = 1 + stringsLength; 29986 if (info.style) { 29987 encodedStyleStyle = encoder.encode(info.style.style); 29988 encodedStyleWeight = encoder.encode(info.style.weight); 29989 lengthEstimate += 4 + encodedStyleStyle.length + 4 + encodedStyleWeight.length; 29990 } 29991 const buffer = new ArrayBuffer(lengthEstimate); 29992 const data = new Uint8Array(buffer); 29993 const view = new DataView(buffer); 29994 let offset = 0; 29995 view.setUint8(offset++, info.guessFallback ? 1 : 0); 29996 view.setUint32(offset, 0); 29997 offset += 4; 29998 stringsLength = 0; 29999 for (const prop of SystemFontInfo.strings) { 30000 const encoded = encodedStrings[prop]; 30001 const length = encoded.length; 30002 stringsLength += 4 + length; 30003 view.setUint32(offset, length); 30004 data.set(encoded, offset + 4); 30005 offset += 4 + length; 30006 } 30007 view.setUint32(offset - stringsLength - 4, stringsLength); 30008 if (info.style) { 30009 view.setUint32(offset, encodedStyleStyle.length); 30010 data.set(encodedStyleStyle, offset + 4); 30011 offset += 4 + encodedStyleStyle.length; 30012 view.setUint32(offset, encodedStyleWeight.length); 30013 data.set(encodedStyleWeight, offset + 4); 30014 offset += 4 + encodedStyleWeight.length; 30015 } 30016 assert(offset <= buffer.byteLength, "SubstitionInfo.write: Buffer overflow"); 30017 return buffer.transferToFixedLength(offset); 30018 } 30019 constructor(buffer) { 30020 this.#buffer = buffer; 30021 this.#view = new DataView(this.#buffer); 30022 this.#decoder = new TextDecoder(); 30023 } 30024 get guessFallback() { 30025 return this.#view.getUint8(0) !== 0; 30026 } 30027 #readString(index) { 30028 assert(index < SystemFontInfo.strings.length, "Invalid string index"); 30029 let offset = 5; 30030 for (let i = 0; i < index; i++) { 30031 offset += this.#view.getUint32(offset) + 4; 30032 } 30033 const length = this.#view.getUint32(offset); 30034 return this.#decoder.decode(new Uint8Array(this.#buffer, offset + 4, length)); 30035 } 30036 get css() { 30037 return this.#readString(0); 30038 } 30039 get loadedName() { 30040 return this.#readString(1); 30041 } 30042 get baseFontName() { 30043 return this.#readString(2); 30044 } 30045 get src() { 30046 return this.#readString(3); 30047 } 30048 get style() { 30049 let offset = 1; 30050 offset += 4 + this.#view.getUint32(offset); 30051 const styleLength = this.#view.getUint32(offset); 30052 const style = this.#decoder.decode(new Uint8Array(this.#buffer, offset + 4, styleLength)); 30053 offset += 4 + styleLength; 30054 const weightLength = this.#view.getUint32(offset); 30055 const weight = this.#decoder.decode(new Uint8Array(this.#buffer, offset + 4, weightLength)); 30056 return { 30057 style, 30058 weight 30059 }; 30060 } 30061} 30062class FontInfo { 30063 static bools = ["black", "bold", "disableFontFace", "fontExtraProperties", "isInvalidPDFjsFont", "isType3Font", "italic", "missingFile", "remeasure", "vertical"]; 30064 static numbers = ["ascent", "defaultWidth", "descent"]; 30065 static strings = ["fallbackName", "loadedName", "mimetype", "name"]; 30066 static #OFFSET_NUMBERS = Math.ceil(this.bools.length * 2 / 8); 30067 static #OFFSET_BBOX = this.#OFFSET_NUMBERS + this.numbers.length * 8; 30068 static #OFFSET_FONT_MATRIX = this.#OFFSET_BBOX + 1 + 2 * 4; 30069 static #OFFSET_DEFAULT_VMETRICS = this.#OFFSET_FONT_MATRIX + 1 + 8 * 6; 30070 static #OFFSET_STRINGS = this.#OFFSET_DEFAULT_VMETRICS + 1 + 2 * 3; 30071 #buffer; 30072 #decoder; 30073 #view; 30074 constructor({ 30075 data, 30076 extra 30077 }) { 30078 this.#buffer = data; 30079 this.#decoder = new TextDecoder(); 30080 this.#view = new DataView(this.#buffer); 30081 if (extra) { 30082 Object.assign(this, extra); 30083 } 30084 } 30085 #readBoolean(index) { 30086 assert(index < FontInfo.bools.length, "Invalid boolean index"); 30087 const byteOffset = Math.floor(index / 4); 30088 const bitOffset = index * 2 % 8; 30089 const value = this.#view.getUint8(byteOffset) >> bitOffset & 0x03; 30090 return value === 0x00 ? undefined : value === 0x02; 30091 } 30092 get black() { 30093 return this.#readBoolean(0); 30094 } 30095 get bold() { 30096 return this.#readBoolean(1); 30097 } 30098 get disableFontFace() { 30099 return this.#readBoolean(2); 30100 } 30101 get fontExtraProperties() { 30102 return this.#readBoolean(3); 30103 } 30104 get isInvalidPDFjsFont() { 30105 return this.#readBoolean(4); 30106 } 30107 get isType3Font() { 30108 return this.#readBoolean(5); 30109 } 30110 get italic() { 30111 return this.#readBoolean(6); 30112 } 30113 get missingFile() { 30114 return this.#readBoolean(7); 30115 } 30116 get remeasure() { 30117 return this.#readBoolean(8); 30118 } 30119 get vertical() { 30120 return this.#readBoolean(9); 30121 } 30122 #readNumber(index) { 30123 assert(index < FontInfo.numbers.length, "Invalid number index"); 30124 return this.#view.getFloat64(FontInfo.#OFFSET_NUMBERS + index * 8); 30125 } 30126 get ascent() { 30127 return this.#readNumber(0); 30128 } 30129 get defaultWidth() { 30130 return this.#readNumber(1); 30131 } 30132 get descent() { 30133 return this.#readNumber(2); 30134 } 30135 get bbox() { 30136 let offset = FontInfo.#OFFSET_BBOX; 30137 const numCoords = this.#view.getUint8(offset); 30138 if (numCoords === 0) { 30139 return undefined; 30140 } 30141 offset += 1; 30142 const bbox = []; 30143 for (let i = 0; i < 4; i++) { 30144 bbox.push(this.#view.getInt16(offset, true)); 30145 offset += 2; 30146 } 30147 return bbox; 30148 } 30149 get fontMatrix() { 30150 let offset = FontInfo.#OFFSET_FONT_MATRIX; 30151 const numPoints = this.#view.getUint8(offset); 30152 if (numPoints === 0) { 30153 return undefined; 30154 } 30155 offset += 1; 30156 const fontMatrix = []; 30157 for (let i = 0; i < 6; i++) { 30158 fontMatrix.push(this.#view.getFloat64(offset, true)); 30159 offset += 8; 30160 } 30161 return fontMatrix; 30162 } 30163 get defaultVMetrics() { 30164 let offset = FontInfo.#OFFSET_DEFAULT_VMETRICS; 30165 const numMetrics = this.#view.getUint8(offset); 30166 if (numMetrics === 0) { 30167 return undefined; 30168 } 30169 offset += 1; 30170 const defaultVMetrics = []; 30171 for (let i = 0; i < 3; i++) { 30172 defaultVMetrics.push(this.#view.getInt16(offset, true)); 30173 offset += 2; 30174 } 30175 return defaultVMetrics; 30176 } 30177 #readString(index) { 30178 assert(index < FontInfo.strings.length, "Invalid string index"); 30179 let offset = FontInfo.#OFFSET_STRINGS + 4; 30180 for (let i = 0; i < index; i++) { 30181 offset += this.#view.getUint32(offset) + 4; 30182 } 30183 const length = this.#view.getUint32(offset); 30184 const stringData = new Uint8Array(length); 30185 stringData.set(new Uint8Array(this.#buffer, offset + 4, length)); 30186 return this.#decoder.decode(stringData); 30187 } 30188 get fallbackName() { 30189 return this.#readString(0); 30190 } 30191 get loadedName() { 30192 return this.#readString(1); 30193 } 30194 get mimetype() { 30195 return this.#readString(2); 30196 } 30197 get name() { 30198 return this.#readString(3); 30199 } 30200 get data() { 30201 let offset = FontInfo.#OFFSET_STRINGS; 30202 const stringsLength = this.#view.getUint32(offset); 30203 offset += 4 + stringsLength; 30204 const systemFontInfoLength = this.#view.getUint32(offset); 30205 offset += 4 + systemFontInfoLength; 30206 const cssFontInfoLength = this.#view.getUint32(offset); 30207 offset += 4 + cssFontInfoLength; 30208 const length = this.#view.getUint32(offset); 30209 if (length === 0) { 30210 return undefined; 30211 } 30212 return new Uint8Array(this.#buffer, offset + 4, length); 30213 } 30214 clearData() { 30215 let offset = FontInfo.#OFFSET_STRINGS; 30216 const stringsLength = this.#view.getUint32(offset); 30217 offset += 4 + stringsLength; 30218 const systemFontInfoLength = this.#view.getUint32(offset); 30219 offset += 4 + systemFontInfoLength; 30220 const cssFontInfoLength = this.#view.getUint32(offset); 30221 offset += 4 + cssFontInfoLength; 30222 const length = this.#view.getUint32(offset); 30223 const data = new Uint8Array(this.#buffer, offset + 4, length); 30224 data.fill(0); 30225 this.#view.setUint32(offset, 0); 30226 } 30227 get cssFontInfo() { 30228 let offset = FontInfo.#OFFSET_STRINGS; 30229 const stringsLength = this.#view.getUint32(offset); 30230 offset += 4 + stringsLength; 30231 const systemFontInfoLength = this.#view.getUint32(offset); 30232 offset += 4 + systemFontInfoLength; 30233 const cssFontInfoLength = this.#view.getUint32(offset); 30234 if (cssFontInfoLength === 0) { 30235 return null; 30236 } 30237 const cssFontInfoData = new Uint8Array(cssFontInfoLength); 30238 cssFontInfoData.set(new Uint8Array(this.#buffer, offset + 4, cssFontInfoLength)); 30239 return new CssFontInfo(cssFontInfoData.buffer); 30240 } 30241 get systemFontInfo() { 30242 let offset = FontInfo.#OFFSET_STRINGS; 30243 const stringsLength = this.#view.getUint32(offset); 30244 offset += 4 + stringsLength; 30245 const systemFontInfoLength = this.#view.getUint32(offset); 30246 if (systemFontInfoLength === 0) { 30247 return null; 30248 } 30249 const systemFontInfoData = new Uint8Array(systemFontInfoLength); 30250 systemFontInfoData.set(new Uint8Array(this.#buffer, offset + 4, systemFontInfoLength)); 30251 return new SystemFontInfo(systemFontInfoData.buffer); 30252 } 30253 static write(font) { 30254 const systemFontInfoBuffer = font.systemFontInfo ? SystemFontInfo.write(font.systemFontInfo) : null; 30255 const cssFontInfoBuffer = font.cssFontInfo ? CssFontInfo.write(font.cssFontInfo) : null; 30256 const encoder = new TextEncoder(); 30257 const encodedStrings = {}; 30258 let stringsLength = 0; 30259 for (const prop of FontInfo.strings) { 30260 encodedStrings[prop] = encoder.encode(font[prop]); 30261 stringsLength += 4 + encodedStrings[prop].length; 30262 } 30263 const lengthEstimate = FontInfo.#OFFSET_STRINGS + 4 + stringsLength + 4 + (systemFontInfoBuffer ? systemFontInfoBuffer.byteLength : 0) + 4 + (cssFontInfoBuffer ? cssFontInfoBuffer.byteLength : 0) + 4 + (font.data ? font.data.length : 0); 30264 const buffer = new ArrayBuffer(lengthEstimate); 30265 const data = new Uint8Array(buffer); 30266 const view = new DataView(buffer); 30267 let offset = 0; 30268 const numBools = FontInfo.bools.length; 30269 let boolByte = 0, 30270 boolBit = 0; 30271 for (let i = 0; i < numBools; i++) { 30272 const value = font[FontInfo.bools[i]]; 30273 const bits = value === undefined ? 0x00 : value ? 0x02 : 0x01; 30274 boolByte |= bits << boolBit; 30275 boolBit += 2; 30276 if (boolBit === 8 || i === numBools - 1) { 30277 view.setUint8(offset++, boolByte); 30278 boolByte = 0; 30279 boolBit = 0; 30280 } 30281 } 30282 assert(offset === FontInfo.#OFFSET_NUMBERS, "FontInfo.write: Boolean properties offset mismatch"); 30283 for (const prop of FontInfo.numbers) { 30284 view.setFloat64(offset, font[prop]); 30285 offset += 8; 30286 } 30287 assert(offset === FontInfo.#OFFSET_BBOX, "FontInfo.write: Number properties offset mismatch"); 30288 if (font.bbox) { 30289 view.setUint8(offset++, 4); 30290 for (const coord of font.bbox) { 30291 view.setInt16(offset, coord, true); 30292 offset += 2; 30293 } 30294 } else { 30295 view.setUint8(offset++, 0); 30296 offset += 2 * 4; 30297 } 30298 assert(offset === FontInfo.#OFFSET_FONT_MATRIX, "FontInfo.write: BBox properties offset mismatch"); 30299 if (font.fontMatrix) { 30300 view.setUint8(offset++, 6); 30301 for (const point of font.fontMatrix) { 30302 view.setFloat64(offset, point, true); 30303 offset += 8; 30304 } 30305 } else { 30306 view.setUint8(offset++, 0); 30307 offset += 8 * 6; 30308 } 30309 assert(offset === FontInfo.#OFFSET_DEFAULT_VMETRICS, "FontInfo.write: FontMatrix properties offset mismatch"); 30310 if (font.defaultVMetrics) { 30311 view.setUint8(offset++, 1); 30312 for (const metric of font.defaultVMetrics) { 30313 view.setInt16(offset, metric, true); 30314 offset += 2; 30315 } 30316 } else { 30317 view.setUint8(offset++, 0); 30318 offset += 3 * 2; 30319 } 30320 assert(offset === FontInfo.#OFFSET_STRINGS, "FontInfo.write: DefaultVMetrics properties offset mismatch"); 30321 view.setUint32(FontInfo.#OFFSET_STRINGS, 0); 30322 offset += 4; 30323 for (const prop of FontInfo.strings) { 30324 const encoded = encodedStrings[prop]; 30325 const length = encoded.length; 30326 view.setUint32(offset, length); 30327 data.set(encoded, offset + 4); 30328 offset += 4 + length; 30329 } 30330 view.setUint32(FontInfo.#OFFSET_STRINGS, offset - FontInfo.#OFFSET_STRINGS - 4); 30331 if (!systemFontInfoBuffer) { 30332 view.setUint32(offset, 0); 30333 offset += 4; 30334 } else { 30335 const length = systemFontInfoBuffer.byteLength; 30336 view.setUint32(offset, length); 30337 assert(offset + 4 + length <= buffer.byteLength, "FontInfo.write: Buffer overflow at systemFontInfo"); 30338 data.set(new Uint8Array(systemFontInfoBuffer), offset + 4); 30339 offset += 4 + length; 30340 } 30341 if (!cssFontInfoBuffer) { 30342 view.setUint32(offset, 0); 30343 offset += 4; 30344 } else { 30345 const length = cssFontInfoBuffer.byteLength; 30346 view.setUint32(offset, length); 30347 assert(offset + 4 + length <= buffer.byteLength, "FontInfo.write: Buffer overflow at cssFontInfo"); 30348 data.set(new Uint8Array(cssFontInfoBuffer), offset + 4); 30349 offset += 4 + length; 30350 } 30351 if (font.data === undefined) { 30352 view.setUint32(offset, 0); 30353 offset += 4; 30354 } else { 30355 view.setUint32(offset, font.data.length); 30356 data.set(font.data, offset + 4); 30357 offset += 4 + font.data.length; 30358 } 30359 assert(offset <= buffer.byteLength, "FontInfo.write: Buffer overflow"); 30360 return buffer.transferToFixedLength(offset); 30361 } 30362} 30363 30364;// ./src/core/font_substitutions.js 30365 30366 30367 30368const NORMAL = { 30369 style: "normal", 30370 weight: "normal" 30371}; 30372const BOLD = { 30373 style: "normal", 30374 weight: "bold" 30375}; 30376const ITALIC = { 30377 style: "italic", 30378 weight: "normal" 30379}; 30380const BOLDITALIC = { 30381 style: "italic", 30382 weight: "bold" 30383}; 30384const substitutionMap = new Map([["Times-Roman", { 30385 local: ["Times New Roman", "Times-Roman", "Times", "Liberation Serif", "Nimbus Roman", "Nimbus Roman L", "Tinos", "Thorndale", "TeX Gyre Termes", "FreeSerif", "Linux Libertine O", "Libertinus Serif", "DejaVu Serif", "Bitstream Vera Serif", "Ubuntu"], 30386 style: NORMAL, 30387 ultimate: "serif" 30388}], ["Times-Bold", { 30389 alias: "Times-Roman", 30390 style: BOLD, 30391 ultimate: "serif" 30392}], ["Times-Italic", { 30393 alias: "Times-Roman", 30394 style: ITALIC, 30395 ultimate: "serif" 30396}], ["Times-BoldItalic", { 30397 alias: "Times-Roman", 30398 style: BOLDITALIC, 30399 ultimate: "serif" 30400}], ["Helvetica", { 30401 local: ["Helvetica", "Helvetica Neue", "Arial", "Arial Nova", "Liberation Sans", "Arimo", "Nimbus Sans", "Nimbus Sans L", "A030", "TeX Gyre Heros", "FreeSans", "DejaVu Sans", "Albany", "Bitstream Vera Sans", "Arial Unicode MS", "Microsoft Sans Serif", "Apple Symbols", "Cantarell"], 30402 path: "LiberationSans-Regular.ttf", 30403 style: NORMAL, 30404 ultimate: "sans-serif" 30405}], ["Helvetica-Bold", { 30406 alias: "Helvetica", 30407 path: "LiberationSans-Bold.ttf", 30408 style: BOLD, 30409 ultimate: "sans-serif" 30410}], ["Helvetica-Oblique", { 30411 alias: "Helvetica", 30412 path: "LiberationSans-Italic.ttf", 30413 style: ITALIC, 30414 ultimate: "sans-serif" 30415}], ["Helvetica-BoldOblique", { 30416 alias: "Helvetica", 30417 path: "LiberationSans-BoldItalic.ttf", 30418 style: BOLDITALIC, 30419 ultimate: "sans-serif" 30420}], ["Courier", { 30421 local: ["Courier", "Courier New", "Liberation Mono", "Nimbus Mono", "Nimbus Mono L", "Cousine", "Cumberland", "TeX Gyre Cursor", "FreeMono", "Linux Libertine Mono O", "Libertinus Mono"], 30422 style: NORMAL, 30423 ultimate: "monospace" 30424}], ["Courier-Bold", { 30425 alias: "Courier", 30426 style: BOLD, 30427 ultimate: "monospace" 30428}], ["Courier-Oblique", { 30429 alias: "Courier", 30430 style: ITALIC, 30431 ultimate: "monospace" 30432}], ["Courier-BoldOblique", { 30433 alias: "Courier", 30434 style: BOLDITALIC, 30435 ultimate: "monospace" 30436}], ["ArialBlack", { 30437 local: ["Arial Black"], 30438 style: { 30439 style: "normal", 30440 weight: "900" 30441 }, 30442 fallback: "Helvetica-Bold" 30443}], ["ArialBlack-Bold", { 30444 alias: "ArialBlack" 30445}], ["ArialBlack-Italic", { 30446 alias: "ArialBlack", 30447 style: { 30448 style: "italic", 30449 weight: "900" 30450 }, 30451 fallback: "Helvetica-BoldOblique" 30452}], ["ArialBlack-BoldItalic", { 30453 alias: "ArialBlack-Italic" 30454}], ["ArialNarrow", { 30455 local: ["Arial Narrow", "Liberation Sans Narrow", "Helvetica Condensed", "Nimbus Sans Narrow", "TeX Gyre Heros Cn"], 30456 style: NORMAL, 30457 fallback: "Helvetica" 30458}], ["ArialNarrow-Bold", { 30459 alias: "ArialNarrow", 30460 style: BOLD, 30461 fallback: "Helvetica-Bold" 30462}], ["ArialNarrow-Italic", { 30463 alias: "ArialNarrow", 30464 style: ITALIC, 30465 fallback: "Helvetica-Oblique" 30466}], ["ArialNarrow-BoldItalic", { 30467 alias: "ArialNarrow", 30468 style: BOLDITALIC, 30469 fallback: "Helvetica-BoldOblique" 30470}], ["Calibri", { 30471 local: ["Calibri", "Carlito"], 30472 style: NORMAL, 30473 fallback: "Helvetica" 30474}], ["Calibri-Bold", { 30475 alias: "Calibri", 30476 style: BOLD, 30477 fallback: "Helvetica-Bold" 30478}], ["Calibri-Italic", { 30479 alias: "Calibri", 30480 style: ITALIC, 30481 fallback: "Helvetica-Oblique" 30482}], ["Calibri-BoldItalic", { 30483 alias: "Calibri", 30484 style: BOLDITALIC, 30485 fallback: "Helvetica-BoldOblique" 30486}], ["Wingdings", { 30487 local: ["Wingdings", "URW Dingbats"], 30488 style: NORMAL 30489}], ["Wingdings-Regular", { 30490 alias: "Wingdings" 30491}], ["Wingdings-Bold", { 30492 alias: "Wingdings" 30493}]]); 30494const fontAliases = new Map([["Arial-Black", "ArialBlack"]]); 30495function getStyleToAppend(style) { 30496 switch (style) { 30497 case BOLD: 30498 return "Bold"; 30499 case ITALIC: 30500 return "Italic"; 30501 case BOLDITALIC: 30502 return "Bold Italic"; 30503 default: 30504 if (style?.weight === "bold") { 30505 return "Bold"; 30506 } 30507 if (style?.style === "italic") { 30508 return "Italic"; 30509 } 30510 } 30511 return ""; 30512} 30513function getFamilyName(str) { 30514 const keywords = new Set(["thin", "extralight", "ultralight", "demilight", "semilight", "light", "book", "regular", "normal", "medium", "demibold", "semibold", "bold", "extrabold", "ultrabold", "black", "heavy", "extrablack", "ultrablack", "roman", "italic", "oblique", "ultracondensed", "extracondensed", "condensed", "semicondensed", "normal", "semiexpanded", "expanded", "extraexpanded", "ultraexpanded", "bolditalic"]); 30515 return str.split(/[- ,+]+/g).filter(tok => !keywords.has(tok.toLowerCase())).join(" "); 30516} 30517function generateFont({ 30518 alias, 30519 local, 30520 path, 30521 fallback, 30522 style, 30523 ultimate 30524}, src, localFontPath, useFallback = true, usePath = true, append = "") { 30525 const result = { 30526 style: null, 30527 ultimate: null 30528 }; 30529 if (local) { 30530 const extra = append ? ` ${append}` : ""; 30531 for (const name of local) { 30532 src.push(`local(${name}${extra})`); 30533 } 30534 } 30535 if (alias) { 30536 const substitution = substitutionMap.get(alias); 30537 const aliasAppend = append || getStyleToAppend(style); 30538 Object.assign(result, generateFont(substitution, src, localFontPath, useFallback && !fallback, usePath && !path, aliasAppend)); 30539 } 30540 if (style) { 30541 result.style = style; 30542 } 30543 if (ultimate) { 30544 result.ultimate = ultimate; 30545 } 30546 if (useFallback && fallback) { 30547 const fallbackInfo = substitutionMap.get(fallback); 30548 const { 30549 ultimate: fallbackUltimate 30550 } = generateFont(fallbackInfo, src, localFontPath, useFallback, usePath && !path, append); 30551 result.ultimate ||= fallbackUltimate; 30552 } 30553 if (usePath && path && localFontPath) { 30554 src.push(`url(${localFontPath}${path})`); 30555 } 30556 return result; 30557} 30558function getFontSubstitution(systemFontCache, idFactory, localFontPath, baseFontName, standardFontName, type) { 30559 if (baseFontName.startsWith("InvalidPDFjsFont_")) { 30560 return null; 30561 } 30562 if ((type === "TrueType" || type === "Type1") && /^[A-Z]{6}\+/.test(baseFontName)) { 30563 baseFontName = baseFontName.slice(7); 30564 } 30565 baseFontName = normalizeFontName(baseFontName); 30566 const key = baseFontName; 30567 let substitutionInfo = systemFontCache.get(key); 30568 if (substitutionInfo) { 30569 return substitutionInfo; 30570 } 30571 let substitution = substitutionMap.get(baseFontName); 30572 if (!substitution) { 30573 for (const [alias, subst] of fontAliases) { 30574 if (baseFontName.startsWith(alias)) { 30575 baseFontName = `${subst}${baseFontName.substring(alias.length)}`; 30576 substitution = substitutionMap.get(baseFontName); 30577 break; 30578 } 30579 } 30580 } 30581 let mustAddBaseFont = false; 30582 if (!substitution) { 30583 substitution = substitutionMap.get(standardFontName); 30584 mustAddBaseFont = true; 30585 } 30586 const loadedName = `${idFactory.getDocId()}_s${idFactory.createFontId()}`; 30587 if (!substitution) { 30588 if (!validateFontName(baseFontName)) { 30589 warn(`Cannot substitute the font because of its name: ${baseFontName}`); 30590 systemFontCache.set(key, null); 30591 return null; 30592 } 30593 const bold = /bold/gi.test(baseFontName); 30594 const italic = /oblique|italic/gi.test(baseFontName); 30595 const style = bold && italic && BOLDITALIC || bold && BOLD || italic && ITALIC || NORMAL; 30596 substitutionInfo = { 30597 css: `"${getFamilyName(baseFontName)}",${loadedName}`, 30598 guessFallback: true, 30599 loadedName, 30600 baseFontName, 30601 src: `local(${baseFontName})`, 30602 style 30603 }; 30604 systemFontCache.set(key, substitutionInfo); 30605 return substitutionInfo; 30606 } 30607 const src = []; 30608 if (mustAddBaseFont && validateFontName(baseFontName)) { 30609 src.push(`local(${baseFontName})`); 30610 } 30611 const { 30612 style, 30613 ultimate 30614 } = generateFont(substitution, src, localFontPath); 30615 const guessFallback = ultimate === null; 30616 const fallback = guessFallback ? "" : `,${ultimate}`; 30617 substitutionInfo = { 30618 css: `"${getFamilyName(baseFontName)}",${loadedName}${fallback}`, 30619 guessFallback, 30620 loadedName, 30621 baseFontName, 30622 src: src.join(","), 30623 style 30624 }; 30625 systemFontCache.set(key, substitutionInfo); 30626 return substitutionInfo; 30627} 30628 30629;// ./src/shared/murmurhash3.js
vendor: 2,880 bytes, lines 30630-30722
30630const SEED = 0xc3d2e1f0; 30631const MASK_HIGH = 0xffff0000; 30632const MASK_LOW = 0xffff; 30633class MurmurHash3_64 { 30634 constructor(seed) { 30635 this.h1 = seed ? seed & 0xffffffff : SEED; 30636 this.h2 = seed ? seed & 0xffffffff : SEED; 30637 } 30638 update(input) { 30639 let data, length; 30640 if (typeof input === "string") { 30641 data = new Uint8Array(input.length * 2); 30642 length = 0; 30643 for (let i = 0, ii = input.length; i < ii; i++) { 30644 const code = input.charCodeAt(i); 30645 if (code <= 0xff) { 30646 data[length++] = code; 30647 } else { 30648 data[length++] = code >>> 8; 30649 data[length++] = code & 0xff; 30650 } 30651 } 30652 } else if (ArrayBuffer.isView(input)) { 30653 data = input.slice(); 30654 length = data.byteLength; 30655 } else { 30656 throw new Error("Invalid data format, must be a string or TypedArray."); 30657 } 30658 const blockCounts = length >> 2; 30659 const tailLength = length - blockCounts * 4; 30660 const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts); 30661 let k1 = 0, 30662 k2 = 0; 30663 let h1 = this.h1, 30664 h2 = this.h2; 30665 const C1 = 0xcc9e2d51, 30666 C2 = 0x1b873593; 30667 const C1_LOW = C1 & MASK_LOW, 30668 C2_LOW = C2 & MASK_LOW; 30669 for (let i = 0; i < blockCounts; i++) { 30670 if (i & 1) { 30671 k1 = dataUint32[i]; 30672 k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW; 30673 k1 = k1 << 15 | k1 >>> 17; 30674 k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW; 30675 h1 ^= k1; 30676 h1 = h1 << 13 | h1 >>> 19; 30677 h1 = h1 * 5 + 0xe6546b64; 30678 } else { 30679 k2 = dataUint32[i]; 30680 k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW; 30681 k2 = k2 << 15 | k2 >>> 17; 30682 k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW; 30683 h2 ^= k2; 30684 h2 = h2 << 13 | h2 >>> 19; 30685 h2 = h2 * 5 + 0xe6546b64; 30686 } 30687 } 30688 k1 = 0; 30689 switch (tailLength) { 30690 case 3: 30691 k1 ^= data[blockCounts * 4 + 2] << 16; 30692 case 2: 30693 k1 ^= data[blockCounts * 4 + 1] << 8; 30694 case 1: 30695 k1 ^= data[blockCounts * 4]; 30696 k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW; 30697 k1 = k1 << 15 | k1 >>> 17; 30698 k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW; 30699 if (blockCounts & 1) { 30700 h1 ^= k1; 30701 } else { 30702 h2 ^= k1; 30703 } 30704 } 30705 this.h1 = h1; 30706 this.h2 = h2; 30707 } 30708 hexdigest() { 30709 let h1 = this.h1, 30710 h2 = this.h2; 30711 h1 ^= h2 >>> 1; 30712 h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW; 30713 h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16; 30714 h1 ^= h2 >>> 1; 30715 h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW; 30716 h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16; 30717 h1 ^= h2 >>> 1; 30718 return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0"); 30719 } 30720} 30721 30722;// ./src/core/image.js
vendor: 35,471 bytes, lines 30722-31930
30722 30723 30724 30725 30726 30727 30728 30729 30730 30731 30732 30733function resizeImageMask(src, bpc, w1, h1, w2, h2) { 30734 const length = w2 * h2; 30735 let dest; 30736 if (bpc <= 8) { 30737 dest = new Uint8Array(length); 30738 } else if (bpc <= 16) { 30739 dest = new Uint16Array(length); 30740 } else { 30741 dest = new Uint32Array(length); 30742 } 30743 const xRatio = w1 / w2; 30744 const yRatio = h1 / h2; 30745 let i, 30746 j, 30747 py, 30748 newIndex = 0, 30749 oldIndex; 30750 const xScaled = new Uint16Array(w2); 30751 const w1Scanline = w1; 30752 for (i = 0; i < w2; i++) { 30753 xScaled[i] = Math.floor(i * xRatio); 30754 } 30755 for (i = 0; i < h2; i++) { 30756 py = Math.floor(i * yRatio) * w1Scanline; 30757 for (j = 0; j < w2; j++) { 30758 oldIndex = py + xScaled[j]; 30759 dest[newIndex++] = src[oldIndex]; 30760 } 30761 } 30762 return dest; 30763} 30764class PDFImage { 30765 constructor({ 30766 xref, 30767 res, 30768 image, 30769 isInline = false, 30770 smask = null, 30771 mask = null, 30772 isMask = false, 30773 pdfFunctionFactory, 30774 globalColorSpaceCache, 30775 localColorSpaceCache 30776 }) { 30777 this.image = image; 30778 const dict = image.dict; 30779 const filter = dict.get("F", "Filter"); 30780 let filterName; 30781 if (filter instanceof Name) { 30782 filterName = filter.name; 30783 } else if (Array.isArray(filter)) { 30784 const filterZero = xref.fetchIfRef(filter[0]); 30785 if (filterZero instanceof Name) { 30786 filterName = filterZero.name; 30787 } 30788 } 30789 switch (filterName) { 30790 case "JPXDecode": 30791 ({ 30792 width: image.width, 30793 height: image.height, 30794 componentsCount: image.numComps, 30795 bitsPerComponent: image.bitsPerComponent 30796 } = JpxImage.parseImageProperties(image.stream)); 30797 image.stream.reset(); 30798 const reducePower = ImageResizer.getReducePowerForJPX(image.width, image.height, image.numComps); 30799 this.jpxDecoderOptions = { 30800 numComponents: 0, 30801 isIndexedColormap: false, 30802 smaskInData: dict.has("SMaskInData"), 30803 reducePower 30804 }; 30805 if (reducePower) { 30806 const factor = 2 ** reducePower; 30807 image.width = Math.ceil(image.width / factor); 30808 image.height = Math.ceil(image.height / factor); 30809 } 30810 break; 30811 case "JBIG2Decode": 30812 image.bitsPerComponent = 1; 30813 image.numComps = 1; 30814 break; 30815 } 30816 let width = dict.get("W", "Width"); 30817 let height = dict.get("H", "Height"); 30818 if (Number.isInteger(image.width) && image.width > 0 && Number.isInteger(image.height) && image.height > 0 && (image.width !== width || image.height !== height)) { 30819 warn("PDFImage - using the Width/Height of the image data, " + "rather than the image dictionary."); 30820 width = image.width; 30821 height = image.height; 30822 } else { 30823 const validWidth = typeof width === "number" && width > 0, 30824 validHeight = typeof height === "number" && height > 0; 30825 if (!validWidth || !validHeight) { 30826 if (!image.fallbackDims) { 30827 throw new FormatError(`Invalid image width: ${width} or height: ${height}`); 30828 } 30829 warn("PDFImage - using the Width/Height of the parent image, for SMask/Mask data."); 30830 if (!validWidth) { 30831 width = image.fallbackDims.width; 30832 } 30833 if (!validHeight) { 30834 height = image.fallbackDims.height; 30835 } 30836 } 30837 } 30838 this.width = width; 30839 this.height = height; 30840 this.interpolate = dict.get("I", "Interpolate"); 30841 this.imageMask = dict.get("IM", "ImageMask") || false; 30842 this.matte = dict.get("Matte") || false; 30843 let bitsPerComponent = image.bitsPerComponent; 30844 if (!bitsPerComponent) { 30845 bitsPerComponent = dict.get("BPC", "BitsPerComponent"); 30846 if (!bitsPerComponent) { 30847 if (this.imageMask) { 30848 bitsPerComponent = 1; 30849 } else { 30850 throw new FormatError(`Bits per component missing in image: ${this.imageMask}`); 30851 } 30852 } 30853 } 30854 this.bpc = bitsPerComponent; 30855 if (!this.imageMask) { 30856 let colorSpace = dict.getRaw("CS") || dict.getRaw("ColorSpace"); 30857 const hasColorSpace = !!colorSpace; 30858 if (!hasColorSpace) { 30859 if (this.jpxDecoderOptions) { 30860 colorSpace = Name.get("DeviceRGBA"); 30861 } else { 30862 switch (image.numComps) { 30863 case 1: 30864 colorSpace = Name.get("DeviceGray"); 30865 break; 30866 case 3: 30867 colorSpace = Name.get("DeviceRGB"); 30868 break; 30869 case 4: 30870 colorSpace = Name.get("DeviceCMYK"); 30871 break; 30872 default: 30873 throw new Error(`Images with ${image.numComps} color components not supported.`); 30874 } 30875 } 30876 } else if (this.jpxDecoderOptions?.smaskInData) { 30877 colorSpace = Name.get("DeviceRGBA"); 30878 } 30879 this.colorSpace = ColorSpaceUtils.parse({ 30880 cs: colorSpace, 30881 xref, 30882 resources: isInline ? res : null, 30883 pdfFunctionFactory, 30884 globalColorSpaceCache, 30885 localColorSpaceCache 30886 }); 30887 this.numComps = this.colorSpace.numComps; 30888 if (this.jpxDecoderOptions) { 30889 this.jpxDecoderOptions.numComponents = hasColorSpace ? this.numComps : 0; 30890 this.jpxDecoderOptions.isIndexedColormap = this.colorSpace.name === "Indexed"; 30891 } 30892 } 30893 this.decode = dict.getArray("D", "Decode"); 30894 this.needsDecode = false; 30895 if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode, bitsPerComponent) || isMask && !ColorSpace.isDefaultDecode(this.decode, 1))) { 30896 this.needsDecode = true; 30897 const max = (1 << bitsPerComponent) - 1; 30898 this.decodeCoefficients = []; 30899 this.decodeAddends = []; 30900 const isIndexed = this.colorSpace?.name === "Indexed"; 30901 for (let i = 0, j = 0; i < this.decode.length; i += 2, ++j) { 30902 const dmin = this.decode[i]; 30903 const dmax = this.decode[i + 1]; 30904 this.decodeCoefficients[j] = isIndexed ? (dmax - dmin) / max : dmax - dmin; 30905 this.decodeAddends[j] = isIndexed ? dmin : max * dmin; 30906 } 30907 } 30908 if (smask) { 30909 smask.fallbackDims ??= { 30910 width, 30911 height 30912 }; 30913 this.smask = new PDFImage({ 30914 xref, 30915 res, 30916 image: smask, 30917 isInline, 30918 pdfFunctionFactory, 30919 globalColorSpaceCache, 30920 localColorSpaceCache 30921 }); 30922 } else if (mask) { 30923 if (mask instanceof BaseStream) { 30924 const maskDict = mask.dict, 30925 imageMask = maskDict.get("IM", "ImageMask"); 30926 if (!imageMask) { 30927 warn("Ignoring /Mask in image without /ImageMask."); 30928 } else { 30929 mask.fallbackDims ??= { 30930 width, 30931 height 30932 }; 30933 this.mask = new PDFImage({ 30934 xref, 30935 res, 30936 image: mask, 30937 isInline, 30938 isMask: true, 30939 pdfFunctionFactory, 30940 globalColorSpaceCache, 30941 localColorSpaceCache 30942 }); 30943 } 30944 } else { 30945 this.mask = mask; 30946 } 30947 } 30948 } 30949 static async buildImage({ 30950 xref, 30951 res, 30952 image, 30953 isInline = false, 30954 pdfFunctionFactory, 30955 globalColorSpaceCache, 30956 localColorSpaceCache 30957 }) { 30958 const imageData = image; 30959 let smaskData = null; 30960 let maskData = null; 30961 const smask = image.dict.get("SMask"); 30962 const mask = image.dict.get("Mask"); 30963 if (smask) { 30964 if (smask instanceof BaseStream) { 30965 smaskData = smask; 30966 } else { 30967 warn("Unsupported /SMask format."); 30968 } 30969 } else if (mask) { 30970 if (mask instanceof BaseStream || Array.isArray(mask)) { 30971 maskData = mask; 30972 } else { 30973 warn("Unsupported /Mask format."); 30974 } 30975 } 30976 return new PDFImage({ 30977 xref, 30978 res, 30979 image: imageData, 30980 isInline, 30981 smask: smaskData, 30982 mask: maskData, 30983 pdfFunctionFactory, 30984 globalColorSpaceCache, 30985 localColorSpaceCache 30986 }); 30987 } 30988 static async createMask({ 30989 image, 30990 isOffscreenCanvasSupported = false 30991 }) { 30992 const { 30993 dict 30994 } = image; 30995 const width = dict.get("W", "Width"); 30996 const height = dict.get("H", "Height"); 30997 const interpolate = dict.get("I", "Interpolate"); 30998 const decode = dict.getArray("D", "Decode"); 30999 const inverseDecode = decode?.[0] > 0; 31000 const computedLength = (width + 7 >> 3) * height; 31001 const imgArray = image.getBytes(computedLength); 31002 const isSingleOpaquePixel = width === 1 && height === 1 && inverseDecode === (imgArray.length === 0 || !!(imgArray[0] & 128)); 31003 if (isSingleOpaquePixel) { 31004 return { 31005 isSingleOpaquePixel 31006 }; 31007 } 31008 if (isOffscreenCanvasSupported) { 31009 if (ImageResizer.needsToBeResized(width, height)) { 31010 const data = new Uint8ClampedArray(width * height * 4); 31011 convertBlackAndWhiteToRGBA({ 31012 src: imgArray, 31013 dest: data, 31014 width, 31015 height, 31016 nonBlackColor: 0, 31017 inverseDecode 31018 }); 31019 return ImageResizer.createImage({ 31020 kind: ImageKind.RGBA_32BPP, 31021 data, 31022 width, 31023 height, 31024 interpolate 31025 }); 31026 } 31027 const canvas = new OffscreenCanvas(width, height); 31028 const ctx = canvas.getContext("2d"); 31029 const imgData = ctx.createImageData(width, height); 31030 convertBlackAndWhiteToRGBA({ 31031 src: imgArray, 31032 dest: imgData.data, 31033 width, 31034 height, 31035 nonBlackColor: 0, 31036 inverseDecode 31037 }); 31038 ctx.putImageData(imgData, 0, 0); 31039 const bitmap = canvas.transferToImageBitmap(); 31040 return { 31041 data: null, 31042 width, 31043 height, 31044 interpolate, 31045 bitmap 31046 }; 31047 } 31048 const actualLength = imgArray.byteLength; 31049 const haveFullData = computedLength === actualLength; 31050 let data; 31051 if (image instanceof DecodeStream && (!inverseDecode || haveFullData)) { 31052 data = imgArray; 31053 } else if (!inverseDecode) { 31054 data = new Uint8Array(imgArray); 31055 } else { 31056 data = new Uint8Array(computedLength); 31057 data.set(imgArray); 31058 data.fill(0xff, actualLength); 31059 } 31060 if (inverseDecode) { 31061 for (let i = 0; i < actualLength; i++) { 31062 data[i] ^= 0xff; 31063 } 31064 } 31065 return { 31066 data, 31067 width, 31068 height, 31069 interpolate 31070 }; 31071 } 31072 get drawWidth() { 31073 return Math.max(this.width, this.smask?.width || 0, this.mask?.width || 0); 31074 } 31075 get drawHeight() { 31076 return Math.max(this.height, this.smask?.height || 0, this.mask?.height || 0); 31077 } 31078 decodeBuffer(buffer) { 31079 const bpc = this.bpc; 31080 const numComps = this.numComps; 31081 const decodeAddends = this.decodeAddends; 31082 const decodeCoefficients = this.decodeCoefficients; 31083 const max = (1 << bpc) - 1; 31084 let i, ii; 31085 if (bpc === 1) { 31086 for (i = 0, ii = buffer.length; i < ii; i++) { 31087 buffer[i] = +!buffer[i]; 31088 } 31089 return; 31090 } 31091 let index = 0; 31092 for (i = 0, ii = this.width * this.height; i < ii; i++) { 31093 for (let j = 0; j < numComps; j++) { 31094 buffer[index] = MathClamp(decodeAddends[j] + buffer[index] * decodeCoefficients[j], 0, max); 31095 index++; 31096 } 31097 } 31098 } 31099 getComponents(buffer) { 31100 const bpc = this.bpc; 31101 if (bpc === 8) { 31102 return buffer; 31103 } 31104 const width = this.width; 31105 const height = this.height; 31106 const numComps = this.numComps; 31107 const length = width * height * numComps; 31108 let bufferPos = 0; 31109 let output; 31110 if (bpc <= 8) { 31111 output = new Uint8Array(length); 31112 } else if (bpc <= 16) { 31113 output = new Uint16Array(length); 31114 } else { 31115 output = new Uint32Array(length); 31116 } 31117 const rowComps = width * numComps; 31118 const max = (1 << bpc) - 1; 31119 let i = 0, 31120 ii, 31121 buf; 31122 if (bpc === 1) { 31123 let mask, loop1End, loop2End; 31124 for (let j = 0; j < height; j++) { 31125 loop1End = i + (rowComps & ~7); 31126 loop2End = i + rowComps; 31127 while (i < loop1End) { 31128 buf = buffer[bufferPos++]; 31129 output[i] = buf >> 7 & 1; 31130 output[i + 1] = buf >> 6 & 1; 31131 output[i + 2] = buf >> 5 & 1; 31132 output[i + 3] = buf >> 4 & 1; 31133 output[i + 4] = buf >> 3 & 1; 31134 output[i + 5] = buf >> 2 & 1; 31135 output[i + 6] = buf >> 1 & 1; 31136 output[i + 7] = buf & 1; 31137 i += 8; 31138 } 31139 if (i < loop2End) { 31140 buf = buffer[bufferPos++]; 31141 mask = 128; 31142 while (i < loop2End) { 31143 output[i++] = +!!(buf & mask); 31144 mask >>= 1; 31145 } 31146 } 31147 } 31148 } else { 31149 let bits = 0; 31150 buf = 0; 31151 for (i = 0, ii = length; i < ii; ++i) { 31152 if (i % rowComps === 0) { 31153 buf = 0; 31154 bits = 0; 31155 } 31156 while (bits < bpc) { 31157 buf = buf << 8 | buffer[bufferPos++]; 31158 bits += 8; 31159 } 31160 const remainingBits = bits - bpc; 31161 let value = buf >> remainingBits; 31162 if (value < 0) { 31163 value = 0; 31164 } else if (value > max) { 31165 value = max; 31166 } 31167 output[i] = value; 31168 buf &= (1 << remainingBits) - 1; 31169 bits = remainingBits; 31170 } 31171 } 31172 return output; 31173 } 31174 async fillOpacity(rgbaBuf, width, height, actualHeight, image) { 31175 const smask = this.smask; 31176 const mask = this.mask; 31177 let alphaBuf, sw, sh, i, ii, j; 31178 if (smask) { 31179 sw = smask.width; 31180 sh = smask.height; 31181 alphaBuf = new Uint8ClampedArray(sw * sh); 31182 await smask.fillGrayBuffer(alphaBuf); 31183 if (sw !== width || sh !== height) { 31184 alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height); 31185 } 31186 } else if (mask) { 31187 if (mask instanceof PDFImage) { 31188 sw = mask.width; 31189 sh = mask.height; 31190 alphaBuf = new Uint8ClampedArray(sw * sh); 31191 mask.numComps = 1; 31192 await mask.fillGrayBuffer(alphaBuf); 31193 for (i = 0, ii = sw * sh; i < ii; ++i) { 31194 alphaBuf[i] = 255 - alphaBuf[i]; 31195 } 31196 if (sw !== width || sh !== height) { 31197 alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height); 31198 } 31199 } else if (Array.isArray(mask)) { 31200 alphaBuf = new Uint8ClampedArray(width * height); 31201 const numComps = this.numComps; 31202 for (i = 0, ii = width * height; i < ii; ++i) { 31203 let opacity = 0; 31204 const imageOffset = i * numComps; 31205 for (j = 0; j < numComps; ++j) { 31206 const color = image[imageOffset + j]; 31207 const maskOffset = j * 2; 31208 if (color < mask[maskOffset] || color > mask[maskOffset + 1]) { 31209 opacity = 255; 31210 break; 31211 } 31212 } 31213 alphaBuf[i] = opacity; 31214 } 31215 } else { 31216 throw new FormatError("Unknown mask format."); 31217 } 31218 } 31219 if (alphaBuf) { 31220 for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) { 31221 rgbaBuf[j] = alphaBuf[i]; 31222 } 31223 } else { 31224 for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) { 31225 rgbaBuf[j] = 255; 31226 } 31227 } 31228 } 31229 undoPreblend(buffer, width, height) { 31230 const matte = this.smask?.matte; 31231 if (!matte) { 31232 return; 31233 } 31234 const matteRgb = this.colorSpace.getRgb(matte, 0); 31235 const matteR = matteRgb[0]; 31236 const matteG = matteRgb[1]; 31237 const matteB = matteRgb[2]; 31238 const length = width * height * 4; 31239 for (let i = 0; i < length; i += 4) { 31240 const alpha = buffer[i + 3]; 31241 if (alpha === 0) { 31242 buffer[i] = 255; 31243 buffer[i + 1] = 255; 31244 buffer[i + 2] = 255; 31245 continue; 31246 } 31247 const k = 255 / alpha; 31248 buffer[i] = (buffer[i] - matteR) * k + matteR; 31249 buffer[i + 1] = (buffer[i + 1] - matteG) * k + matteG; 31250 buffer[i + 2] = (buffer[i + 2] - matteB) * k + matteB; 31251 } 31252 } 31253 async createImageData(forceRGBA = false, isOffscreenCanvasSupported = false) { 31254 const drawWidth = this.drawWidth; 31255 const drawHeight = this.drawHeight; 31256 const imgData = { 31257 width: drawWidth, 31258 height: drawHeight, 31259 interpolate: this.interpolate, 31260 kind: 0, 31261 data: null 31262 }; 31263 const numComps = this.numComps; 31264 const originalWidth = this.width; 31265 const originalHeight = this.height; 31266 const bpc = this.bpc; 31267 const rowBytes = originalWidth * numComps * bpc + 7 >> 3; 31268 const mustBeResized = isOffscreenCanvasSupported && ImageResizer.needsToBeResized(drawWidth, drawHeight); 31269 if (!this.smask && !this.mask && this.colorSpace.name === "DeviceRGBA") { 31270 imgData.kind = ImageKind.RGBA_32BPP; 31271 const imgArray = imgData.data = await this.getImageBytes(originalHeight * originalWidth * 4, {}); 31272 if (isOffscreenCanvasSupported) { 31273 if (!mustBeResized) { 31274 return this.createBitmap(ImageKind.RGBA_32BPP, drawWidth, drawHeight, imgArray); 31275 } 31276 return ImageResizer.createImage(imgData, false); 31277 } 31278 return imgData; 31279 } 31280 if (!forceRGBA) { 31281 let kind; 31282 if (this.colorSpace.name === "DeviceGray" && bpc === 1) { 31283 kind = ImageKind.GRAYSCALE_1BPP; 31284 } else if (this.colorSpace.name === "DeviceRGB" && bpc === 8 && !this.needsDecode) { 31285 kind = ImageKind.RGB_24BPP; 31286 } 31287 if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) { 31288 const image = await this.#getImage(originalWidth, originalHeight); 31289 if (image) { 31290 return image; 31291 } 31292 const data = await this.getImageBytes(originalHeight * rowBytes, {}); 31293 if (isOffscreenCanvasSupported) { 31294 if (mustBeResized) { 31295 return ImageResizer.createImage({ 31296 data, 31297 kind, 31298 width: drawWidth, 31299 height: drawHeight, 31300 interpolate: this.interpolate 31301 }, this.needsDecode); 31302 } 31303 return this.createBitmap(kind, originalWidth, originalHeight, data); 31304 } 31305 imgData.kind = kind; 31306 imgData.data = data; 31307 if (this.needsDecode) { 31308 assert(kind === ImageKind.GRAYSCALE_1BPP, "PDFImage.createImageData: The image must be grayscale."); 31309 const buffer = imgData.data; 31310 for (let i = 0, ii = buffer.length; i < ii; i++) { 31311 buffer[i] ^= 0xff; 31312 } 31313 } 31314 return imgData; 31315 } 31316 if (this.image instanceof JpegStream && !this.smask && !this.mask && !this.needsDecode) { 31317 let imageLength = originalHeight * rowBytes; 31318 if (isOffscreenCanvasSupported && !mustBeResized) { 31319 let isHandled = false; 31320 switch (this.colorSpace.name) { 31321 case "DeviceGray": 31322 imageLength *= 4; 31323 isHandled = true; 31324 break; 31325 case "DeviceRGB": 31326 imageLength = imageLength / 3 * 4; 31327 isHandled = true; 31328 break; 31329 case "DeviceCMYK": 31330 isHandled = true; 31331 break; 31332 } 31333 if (isHandled) { 31334 const image = await this.#getImage(drawWidth, drawHeight); 31335 if (image) { 31336 return image; 31337 } 31338 const rgba = await this.getImageBytes(imageLength, { 31339 drawWidth, 31340 drawHeight, 31341 forceRGBA: true 31342 }); 31343 return this.createBitmap(ImageKind.RGBA_32BPP, drawWidth, drawHeight, rgba); 31344 } 31345 } else { 31346 switch (this.colorSpace.name) { 31347 case "DeviceGray": 31348 imageLength *= 3; 31349 case "DeviceRGB": 31350 case "DeviceCMYK": 31351 imgData.kind = ImageKind.RGB_24BPP; 31352 imgData.data = await this.getImageBytes(imageLength, { 31353 drawWidth, 31354 drawHeight, 31355 forceRGB: true 31356 }); 31357 if (mustBeResized) { 31358 return ImageResizer.createImage(imgData); 31359 } 31360 return imgData; 31361 } 31362 } 31363 } 31364 } 31365 const imgArray = await this.getImageBytes(originalHeight * rowBytes, { 31366 internal: true 31367 }); 31368 const actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight; 31369 const comps = this.getComponents(imgArray); 31370 let alpha01, maybeUndoPreblend; 31371 let canvas, ctx, canvasImgData, data; 31372 if (isOffscreenCanvasSupported && !mustBeResized) { 31373 canvas = new OffscreenCanvas(drawWidth, drawHeight); 31374 ctx = canvas.getContext("2d"); 31375 canvasImgData = ctx.createImageData(drawWidth, drawHeight); 31376 data = canvasImgData.data; 31377 } 31378 imgData.kind = ImageKind.RGBA_32BPP; 31379 if (!forceRGBA && !this.smask && !this.mask) { 31380 if (!isOffscreenCanvasSupported || mustBeResized) { 31381 imgData.kind = ImageKind.RGB_24BPP; 31382 data = new Uint8ClampedArray(drawWidth * drawHeight * 3); 31383 alpha01 = 0; 31384 } else { 31385 const arr = new Uint32Array(data.buffer); 31386 arr.fill(FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff); 31387 alpha01 = 1; 31388 } 31389 maybeUndoPreblend = false; 31390 } else { 31391 if (!isOffscreenCanvasSupported || mustBeResized) { 31392 data = new Uint8ClampedArray(drawWidth * drawHeight * 4); 31393 } 31394 alpha01 = 1; 31395 maybeUndoPreblend = true; 31396 await this.fillOpacity(data, drawWidth, drawHeight, actualHeight, comps); 31397 } 31398 if (this.needsDecode) { 31399 this.decodeBuffer(comps); 31400 } 31401 this.colorSpace.fillRgb(data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01); 31402 if (maybeUndoPreblend) { 31403 this.undoPreblend(data, drawWidth, actualHeight); 31404 } 31405 if (isOffscreenCanvasSupported && !mustBeResized) { 31406 ctx.putImageData(canvasImgData, 0, 0); 31407 const bitmap = canvas.transferToImageBitmap(); 31408 return { 31409 data: null, 31410 width: drawWidth, 31411 height: drawHeight, 31412 bitmap, 31413 interpolate: this.interpolate 31414 }; 31415 } 31416 imgData.data = data; 31417 if (mustBeResized) { 31418 return ImageResizer.createImage(imgData); 31419 } 31420 return imgData; 31421 } 31422 async fillGrayBuffer(buffer) { 31423 const numComps = this.numComps; 31424 if (numComps !== 1) { 31425 throw new FormatError(`Reading gray scale from a color image: ${numComps}`); 31426 } 31427 const width = this.width; 31428 const height = this.height; 31429 const bpc = this.bpc; 31430 const rowBytes = width * numComps * bpc + 7 >> 3; 31431 const imgArray = await this.getImageBytes(height * rowBytes, { 31432 internal: true 31433 }); 31434 const comps = this.getComponents(imgArray); 31435 let i, length; 31436 if (bpc === 1) { 31437 length = width * height; 31438 if (this.needsDecode) { 31439 for (i = 0; i < length; ++i) { 31440 buffer[i] = comps[i] - 1 & 255; 31441 } 31442 } else { 31443 for (i = 0; i < length; ++i) { 31444 buffer[i] = -comps[i] & 255; 31445 } 31446 } 31447 return; 31448 } 31449 if (this.needsDecode) { 31450 this.decodeBuffer(comps); 31451 } 31452 length = width * height; 31453 const scale = 255 / ((1 << bpc) - 1); 31454 for (i = 0; i < length; ++i) { 31455 buffer[i] = scale * comps[i]; 31456 } 31457 } 31458 createBitmap(kind, width, height, src) { 31459 const canvas = new OffscreenCanvas(width, height); 31460 const ctx = canvas.getContext("2d"); 31461 let imgData; 31462 if (kind === ImageKind.RGBA_32BPP) { 31463 imgData = new ImageData(src, width, height); 31464 } else { 31465 imgData = ctx.createImageData(width, height); 31466 convertToRGBA({ 31467 kind, 31468 src, 31469 dest: new Uint32Array(imgData.data.buffer), 31470 width, 31471 height, 31472 inverseDecode: this.needsDecode 31473 }); 31474 } 31475 ctx.putImageData(imgData, 0, 0); 31476 const bitmap = canvas.transferToImageBitmap(); 31477 return { 31478 data: null, 31479 width, 31480 height, 31481 bitmap, 31482 interpolate: this.interpolate 31483 }; 31484 } 31485 async #getImage(width, height) { 31486 const bitmap = await this.image.getTransferableImage(); 31487 if (!bitmap) { 31488 return null; 31489 } 31490 return { 31491 data: null, 31492 width, 31493 height, 31494 bitmap, 31495 interpolate: this.interpolate 31496 }; 31497 } 31498 async getImageBytes(length, { 31499 drawWidth, 31500 drawHeight, 31501 forceRGBA = false, 31502 forceRGB = false, 31503 internal = false 31504 }) { 31505 this.image.reset(); 31506 this.image.drawWidth = drawWidth || this.width; 31507 this.image.drawHeight = drawHeight || this.height; 31508 this.image.forceRGBA = !!forceRGBA; 31509 this.image.forceRGB = !!forceRGB; 31510 const imageBytes = await this.image.getImageData(length, this.jpxDecoderOptions); 31511 if (internal || this.image instanceof DecodeStream) { 31512 return imageBytes; 31513 } 31514 assert(imageBytes instanceof Uint8Array, 'PDFImage.getImageBytes: Unsupported "imageBytes" type.'); 31515 return new Uint8Array(imageBytes); 31516 } 31517} 31518 31519;// ./src/core/evaluator.js 31520 31521 31522 31523 31524 31525 31526 31527 31528 31529 31530 31531 31532 31533 31534 31535 31536 31537 31538 31539 31540 31541 31542 31543 31544 31545 31546 31547const DefaultPartialEvaluatorOptions = Object.freeze({ 31548 maxImageSize: -1, 31549 disableFontFace: false, 31550 ignoreErrors: false, 31551 isEvalSupported: true, 31552 isOffscreenCanvasSupported: false, 31553 isImageDecoderSupported: false, 31554 canvasMaxAreaInBytes: -1, 31555 fontExtraProperties: false, 31556 useSystemFonts: true, 31557 useWasm: true, 31558 useWorkerFetch: true, 31559 cMapUrl: null, 31560 iccUrl: null, 31561 standardFontDataUrl: null, 31562 wasmUrl: null 31563}); 31564const PatternType = { 31565 TILING: 1, 31566 SHADING: 2 31567}; 31568const TEXT_CHUNK_BATCH_SIZE = 10; 31569const deferred = Promise.resolve(); 31570function normalizeBlendMode(value, parsingArray = false) { 31571 if (Array.isArray(value)) { 31572 for (const val of value) { 31573 const maybeBM = normalizeBlendMode(val, true); 31574 if (maybeBM) { 31575 return maybeBM; 31576 } 31577 } 31578 warn(`Unsupported blend mode Array: ${value}`); 31579 return "source-over"; 31580 } 31581 if (!(value instanceof Name)) { 31582 if (parsingArray) { 31583 return null; 31584 } 31585 return "source-over"; 31586 } 31587 switch (value.name) { 31588 case "Normal": 31589 case "Compatible": 31590 return "source-over"; 31591 case "Multiply": 31592 return "multiply"; 31593 case "Screen": 31594 return "screen"; 31595 case "Overlay": 31596 return "overlay"; 31597 case "Darken": 31598 return "darken"; 31599 case "Lighten": 31600 return "lighten"; 31601 case "ColorDodge": 31602 return "color-dodge"; 31603 case "ColorBurn": 31604 return "color-burn"; 31605 case "HardLight": 31606 return "hard-light"; 31607 case "SoftLight": 31608 return "soft-light"; 31609 case "Difference": 31610 return "difference"; 31611 case "Exclusion": 31612 return "exclusion"; 31613 case "Hue": 31614 return "hue"; 31615 case "Saturation": 31616 return "saturation"; 31617 case "Color": 31618 return "color"; 31619 case "Luminosity": 31620 return "luminosity"; 31621 } 31622 if (parsingArray) { 31623 return null; 31624 } 31625 warn(`Unsupported blend mode: ${value.name}`); 31626 return "source-over"; 31627} 31628function addCachedImageOps(opList, { 31629 objId, 31630 fn, 31631 args, 31632 optionalContent, 31633 hasMask 31634}) { 31635 if (objId) { 31636 opList.addDependency(objId); 31637 } 31638 opList.addImageOps(fn, args, optionalContent, hasMask); 31639 if (fn === OPS.paintImageMaskXObject && args[0]?.count > 0) { 31640 args[0].count++; 31641 } 31642} 31643class TimeSlotManager { 31644 static TIME_SLOT_DURATION_MS = 20; 31645 static CHECK_TIME_EVERY = 100; 31646 constructor() { 31647 this.reset(); 31648 } 31649 check() { 31650 if (++this.checked < TimeSlotManager.CHECK_TIME_EVERY) { 31651 return false; 31652 } 31653 this.checked = 0; 31654 return this.endTime <= Date.now(); 31655 } 31656 reset() { 31657 this.endTime = Date.now() + TimeSlotManager.TIME_SLOT_DURATION_MS; 31658 this.checked = 0; 31659 } 31660} 31661class PartialEvaluator { 31662 constructor({ 31663 xref, 31664 handler, 31665 pageIndex, 31666 idFactory, 31667 fontCache, 31668 builtInCMapCache, 31669 standardFontDataCache, 31670 globalColorSpaceCache, 31671 globalImageCache, 31672 systemFontCache, 31673 options = null 31674 }) { 31675 this.xref = xref; 31676 this.handler = handler; 31677 this.pageIndex = pageIndex; 31678 this.idFactory = idFactory; 31679 this.fontCache = fontCache; 31680 this.builtInCMapCache = builtInCMapCache; 31681 this.standardFontDataCache = standardFontDataCache; 31682 this.globalColorSpaceCache = globalColorSpaceCache; 31683 this.globalImageCache = globalImageCache; 31684 this.systemFontCache = systemFontCache; 31685 this.options = options || DefaultPartialEvaluatorOptions; 31686 this.type3FontRefs = null; 31687 this._regionalImageCache = new RegionalImageCache(); 31688 this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this); 31689 } 31690 get _pdfFunctionFactory() { 31691 const pdfFunctionFactory = new PDFFunctionFactory({ 31692 xref: this.xref, 31693 isEvalSupported: this.options.isEvalSupported 31694 }); 31695 return shadow(this, "_pdfFunctionFactory", pdfFunctionFactory); 31696 } 31697 get parsingType3Font() { 31698 return !!this.type3FontRefs; 31699 } 31700 clone(newOptions = null) { 31701 const newEvaluator = Object.create(this); 31702 newEvaluator.options = Object.assign(Object.create(null), this.options, newOptions); 31703 return newEvaluator; 31704 } 31705 hasBlendModes(resources, nonBlendModesSet) { 31706 if (!(resources instanceof Dict)) { 31707 return false; 31708 } 31709 if (resources.objId && nonBlendModesSet.has(resources.objId)) { 31710 return false; 31711 } 31712 const processed = new RefSet(nonBlendModesSet); 31713 if (resources.objId) { 31714 processed.put(resources.objId); 31715 } 31716 const nodes = [resources], 31717 xref = this.xref; 31718 while (nodes.length) { 31719 const node = nodes.shift(); 31720 const graphicStates = node.get("ExtGState"); 31721 if (graphicStates instanceof Dict) { 31722 for (let graphicState of graphicStates.getRawValues()) { 31723 if (graphicState instanceof Ref) { 31724 if (processed.has(graphicState)) { 31725 continue; 31726 } 31727 try { 31728 graphicState = xref.fetch(graphicState); 31729 } catch (ex) { 31730 processed.put(graphicState); 31731 info(`hasBlendModes - ignoring ExtGState: "${ex}".`); 31732 continue; 31733 } 31734 } 31735 if (!(graphicState instanceof Dict)) { 31736 continue; 31737 } 31738 if (graphicState.objId) { 31739 processed.put(graphicState.objId); 31740 } 31741 const bm = graphicState.get("BM"); 31742 if (bm instanceof Name) { 31743 if (bm.name !== "Normal") { 31744 return true; 31745 } 31746 continue; 31747 } 31748 if (bm !== undefined && Array.isArray(bm)) { 31749 for (const element of bm) { 31750 if (element instanceof Name && element.name !== "Normal") { 31751 return true; 31752 } 31753 } 31754 } 31755 } 31756 } 31757 const xObjects = node.get("XObject"); 31758 if (!(xObjects instanceof Dict)) { 31759 continue; 31760 } 31761 for (let xObject of xObjects.getRawValues()) { 31762 if (xObject instanceof Ref) { 31763 if (processed.has(xObject)) { 31764 continue; 31765 } 31766 try { 31767 xObject = xref.fetch(xObject); 31768 } catch (ex) { 31769 processed.put(xObject); 31770 info(`hasBlendModes - ignoring XObject: "${ex}".`); 31771 continue; 31772 } 31773 } 31774 if (!(xObject instanceof BaseStream)) { 31775 continue; 31776 } 31777 if (xObject.dict.objId) { 31778 processed.put(xObject.dict.objId); 31779 } 31780 const xResources = xObject.dict.get("Resources"); 31781 if (!(xResources instanceof Dict)) { 31782 continue; 31783 } 31784 if (xResources.objId && processed.has(xResources.objId)) { 31785 continue; 31786 } 31787 nodes.push(xResources); 31788 if (xResources.objId) { 31789 processed.put(xResources.objId); 31790 } 31791 } 31792 } 31793 for (const ref of processed) { 31794 nonBlendModesSet.put(ref); 31795 } 31796 return false; 31797 } 31798 async fetchBuiltInCMap(name) { 31799 const cachedData = this.builtInCMapCache.get(name); 31800 if (cachedData) { 31801 return cachedData; 31802 } 31803 let data; 31804 if (this.options.useWorkerFetch) { 31805 data = { 31806 cMapData: await fetchBinaryData(`${this.options.cMapUrl}${name}.bcmap`), 31807 isCompressed: true 31808 }; 31809 } else { 31810 data = await this.handler.sendWithPromise("FetchBinaryData", { 31811 type: "cMapReaderFactory", 31812 name 31813 }); 31814 } 31815 this.builtInCMapCache.set(name, data); 31816 return data; 31817 } 31818 async fetchStandardFontData(name) { 31819 const cachedData = this.standardFontDataCache.get(name); 31820 if (cachedData) { 31821 return new Stream(cachedData); 31822 } 31823 if (this.options.useSystemFonts && name !== "Symbol" && name !== "ZapfDingbats") { 31824 return null; 31825 } 31826 const standardFontNameToFileName = getFontNameToFileMap(), 31827 filename = standardFontNameToFileName[name]; 31828 let data; 31829 try { 31830 if (this.options.useWorkerFetch) { 31831 data = await fetchBinaryData(`${this.options.standardFontDataUrl}${filename}`); 31832 } else { 31833 data = await this.handler.sendWithPromise("FetchBinaryData", { 31834 type: "standardFontDataFactory", 31835 filename 31836 }); 31837 } 31838 } catch (ex) { 31839 warn(ex); 31840 return null; 31841 } 31842 this.standardFontDataCache.set(name, data); 31843 return new Stream(data); 31844 } 31845 async buildFormXObject(resources, xobj, smask, operatorList, task, initialState, localColorSpaceCache, seenRefs) { 31846 const { 31847 dict 31848 } = xobj; 31849 const matrix = lookupMatrix(dict.getArray("Matrix"), null); 31850 const bbox = lookupNormalRect(dict.getArray("BBox"), null); 31851 let optionalContent, groupOptions; 31852 if (dict.has("OC")) { 31853 optionalContent = await this.parseMarkedContentProps(dict.get("OC"), resources); 31854 } 31855 if (optionalContent !== undefined) { 31856 operatorList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]); 31857 } 31858 const group = dict.get("Group"); 31859 if (group) { 31860 groupOptions = { 31861 matrix, 31862 bbox, 31863 smask, 31864 isolated: false, 31865 knockout: false 31866 }; 31867 const groupSubtype = group.get("S"); 31868 let colorSpace = null; 31869 if (isName(groupSubtype, "Transparency")) { 31870 groupOptions.isolated = group.get("I") || false; 31871 groupOptions.knockout = group.get("K") || false; 31872 if (group.has("CS")) { 31873 const cs = this._getColorSpace(group.getRaw("CS"), resources, localColorSpaceCache); 31874 colorSpace = cs instanceof ColorSpace ? cs : await this._handleColorSpace(cs); 31875 } 31876 } 31877 if (smask?.backdrop) { 31878 colorSpace ||= ColorSpaceUtils.rgb; 31879 smask.backdrop = colorSpace.getRgbHex(smask.backdrop, 0); 31880 } 31881 operatorList.addOp(OPS.beginGroup, [groupOptions]); 31882 } 31883 const f32matrix = matrix && new Float32Array(matrix); 31884 const f32bbox = !group && bbox && new Float32Array(bbox) || null; 31885 const args = [f32matrix, f32bbox]; 31886 operatorList.addOp(OPS.paintFormXObjectBegin, args); 31887 const localResources = dict.get("Resources"); 31888 await this.getOperatorList({ 31889 stream: xobj, 31890 task, 31891 resources: localResources instanceof Dict ? localResources : resources, 31892 operatorList, 31893 initialState, 31894 prevRefs: seenRefs 31895 }); 31896 operatorList.addOp(OPS.paintFormXObjectEnd, []); 31897 if (group) { 31898 operatorList.addOp(OPS.endGroup, [groupOptions]); 31899 } 31900 if (optionalContent !== undefined) { 31901 operatorList.addOp(OPS.endMarkedContent, []); 31902 } 31903 } 31904 _sendImgData(objId, imgData, cacheGlobally = false) { 31905 const transfers = imgData ? [imgData.bitmap || imgData.data.buffer] : null; 31906 if (this.parsingType3Font || cacheGlobally) { 31907 return this.handler.send("commonobj", [objId, "Image", imgData], transfers); 31908 } 31909 return this.handler.send("obj", [objId, this.pageIndex, "Image", imgData], transfers); 31910 } 31911 async buildPaintImageXObject({ 31912 resources, 31913 image, 31914 isInline = false, 31915 operatorList, 31916 cacheKey, 31917 localImageCache, 31918 localColorSpaceCache 31919 }) { 31920 const { 31921 maxImageSize, 31922 ignoreErrors, 31923 isOffscreenCanvasSupported 31924 } = this.options; 31925 const { 31926 dict 31927 } = image; 31928 const imageRef = dict.objId; 31929 const w = dict.get("W", "Width"); 31930 const h = dict.get("H", "Height");
vendor: 4,382 bytes, lines 31931-32062
31931 if (!(w && typeof w === "number") || !(h && typeof h === "number")) { 31932 warn("Image dimensions are missing, or not numbers."); 31933 return; 31934 } 31935 if (maxImageSize !== -1 && w * h > maxImageSize) { 31936 const msg = "Image exceeded maximum allowed size and was removed."; 31937 if (!ignoreErrors) { 31938 throw new Error(msg); 31939 } 31940 warn(msg); 31941 return; 31942 } 31943 let optionalContent; 31944 if (dict.has("OC")) { 31945 optionalContent = await this.parseMarkedContentProps(dict.get("OC"), resources); 31946 } 31947 const imageMask = dict.get("IM", "ImageMask") || false; 31948 let imgData, fn, args; 31949 if (imageMask) { 31950 imgData = await PDFImage.createMask({ 31951 image, 31952 isOffscreenCanvasSupported: isOffscreenCanvasSupported && !this.parsingType3Font 31953 }); 31954 if (imgData.isSingleOpaquePixel) { 31955 fn = OPS.paintSolidColorImageMask; 31956 args = []; 31957 operatorList.addImageOps(fn, args, optionalContent); 31958 if (cacheKey) { 31959 const cacheData = { 31960 fn, 31961 args, 31962 optionalContent 31963 }; 31964 localImageCache.set(cacheKey, imageRef, cacheData); 31965 if (imageRef) { 31966 this._regionalImageCache.set(null, imageRef, cacheData); 31967 } 31968 } 31969 return; 31970 } 31971 if (this.parsingType3Font) { 31972 args = compileType3Glyph(imgData); 31973 if (args) { 31974 operatorList.addImageOps(OPS.constructPath, args, optionalContent); 31975 return; 31976 } 31977 warn("Cannot compile Type3 glyph."); 31978 operatorList.addImageOps(OPS.paintImageMaskXObject, [imgData], optionalContent); 31979 return; 31980 } 31981 const objId = `mask_${this.idFactory.createObjId()}`; 31982 operatorList.addDependency(objId); 31983 imgData.dataLen = imgData.bitmap ? imgData.width * imgData.height * 4 : imgData.data.length; 31984 this._sendImgData(objId, imgData); 31985 fn = OPS.paintImageMaskXObject; 31986 args = [{ 31987 data: objId, 31988 width: imgData.width, 31989 height: imgData.height, 31990 interpolate: imgData.interpolate, 31991 count: 1 31992 }]; 31993 operatorList.addImageOps(fn, args, optionalContent); 31994 if (cacheKey) { 31995 const cacheData = { 31996 objId, 31997 fn, 31998 args, 31999 optionalContent 32000 }; 32001 localImageCache.set(cacheKey, imageRef, cacheData); 32002 if (imageRef) { 32003 this._regionalImageCache.set(null, imageRef, cacheData); 32004 } 32005 } 32006 return; 32007 } 32008 const SMALL_IMAGE_DIMENSIONS = 200; 32009 const hasMask = dict.has("SMask") || dict.has("Mask"); 32010 if (isInline && w + h < SMALL_IMAGE_DIMENSIONS && !hasMask) { 32011 try { 32012 const imageObj = new PDFImage({ 32013 xref: this.xref, 32014 res: resources, 32015 image, 32016 isInline, 32017 pdfFunctionFactory: this._pdfFunctionFactory, 32018 globalColorSpaceCache: this.globalColorSpaceCache, 32019 localColorSpaceCache 32020 }); 32021 imgData = await imageObj.createImageData(true, false); 32022 operatorList.addImageOps(OPS.paintInlineImageXObject, [imgData], optionalContent); 32023 } catch (reason) { 32024 const msg = `Unable to decode inline image: "${reason}".`; 32025 if (!ignoreErrors) { 32026 throw new Error(msg); 32027 } 32028 warn(msg); 32029 } 32030 return; 32031 } 32032 let objId = `img_${this.idFactory.createObjId()}`, 32033 cacheGlobally = false, 32034 globalCacheData = null; 32035 if (this.parsingType3Font) { 32036 objId = `${this.idFactory.getDocId()}_type3_${objId}`; 32037 } else if (cacheKey && imageRef) { 32038 cacheGlobally = this.globalImageCache.shouldCache(imageRef, this.pageIndex); 32039 if (cacheGlobally) { 32040 assert(!isInline, "Cannot cache an inline image globally."); 32041 objId = `${this.idFactory.getDocId()}_${objId}`; 32042 } 32043 } 32044 operatorList.addDependency(objId); 32045 fn = OPS.paintImageXObject; 32046 args = [objId, w, h]; 32047 operatorList.addImageOps(fn, args, optionalContent, hasMask); 32048 if (cacheGlobally) { 32049 globalCacheData = { 32050 objId, 32051 fn, 32052 args, 32053 optionalContent, 32054 hasMask, 32055 byteSize: 0 32056 }; 32057 if (this.globalImageCache.hasDecodeFailed(imageRef)) { 32058 this.globalImageCache.setData(imageRef, globalCacheData); 32059 this._sendImgData(objId, null, cacheGlobally); 32060 return; 32061 } 32062 if (w * h > 250000 || hasMask) {
vendor: 9,138 bytes, lines 32063-32349
32063 const localLength = await this.handler.sendWithPromise("commonobj", [objId, "CopyLocalImage", { 32064 imageRef 32065 }]); 32066 if (localLength) { 32067 this.globalImageCache.setData(imageRef, globalCacheData); 32068 this.globalImageCache.addByteSize(imageRef, localLength); 32069 return; 32070 } 32071 } 32072 } 32073 PDFImage.buildImage({ 32074 xref: this.xref, 32075 res: resources, 32076 image, 32077 isInline, 32078 pdfFunctionFactory: this._pdfFunctionFactory, 32079 globalColorSpaceCache: this.globalColorSpaceCache, 32080 localColorSpaceCache 32081 }).then(async imageObj => { 32082 imgData = await imageObj.createImageData(false, isOffscreenCanvasSupported); 32083 imgData.dataLen = imgData.bitmap ? imgData.width * imgData.height * 4 : imgData.data.length; 32084 imgData.ref = imageRef; 32085 if (cacheGlobally) { 32086 this.globalImageCache.addByteSize(imageRef, imgData.dataLen); 32087 } 32088 return this._sendImgData(objId, imgData, cacheGlobally); 32089 }).catch(reason => { 32090 warn(`Unable to decode image "${objId}": "${reason}".`); 32091 if (imageRef) { 32092 this.globalImageCache.addDecodeFailed(imageRef); 32093 } 32094 return this._sendImgData(objId, null, cacheGlobally); 32095 }); 32096 if (cacheKey) { 32097 const cacheData = { 32098 objId, 32099 fn, 32100 args, 32101 optionalContent, 32102 hasMask 32103 }; 32104 localImageCache.set(cacheKey, imageRef, cacheData); 32105 if (imageRef) { 32106 this._regionalImageCache.set(null, imageRef, cacheData); 32107 if (cacheGlobally) { 32108 assert(globalCacheData, "The global cache-data must be available."); 32109 this.globalImageCache.setData(imageRef, globalCacheData); 32110 } 32111 } 32112 } 32113 } 32114 handleSMask(smask, resources, operatorList, task, stateManager, localColorSpaceCache, seenRefs) { 32115 const smaskContent = smask.get("G"); 32116 const smaskOptions = { 32117 subtype: smask.get("S").name, 32118 backdrop: smask.get("BC") 32119 }; 32120 const transferObj = smask.get("TR"); 32121 if (isPDFFunction(transferObj)) { 32122 const transferFn = this._pdfFunctionFactory.create(transferObj); 32123 const transferMap = new Uint8Array(256); 32124 const tmp = new Float32Array(1); 32125 for (let i = 0; i < 256; i++) { 32126 tmp[0] = i / 255; 32127 transferFn(tmp, 0, tmp, 0); 32128 transferMap[i] = tmp[0] * 255 | 0; 32129 } 32130 smaskOptions.transferMap = transferMap; 32131 } 32132 return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone({ 32133 newPath: true 32134 }), localColorSpaceCache, seenRefs); 32135 } 32136 handleTransferFunction(tr) { 32137 let transferArray; 32138 if (Array.isArray(tr)) { 32139 transferArray = tr; 32140 } else if (isPDFFunction(tr)) { 32141 transferArray = [tr]; 32142 } else { 32143 return null; 32144 } 32145 const transferMaps = []; 32146 let numFns = 0, 32147 numEffectfulFns = 0; 32148 for (const entry of transferArray) { 32149 const transferObj = this.xref.fetchIfRef(entry); 32150 numFns++; 32151 if (isName(transferObj, "Identity")) { 32152 transferMaps.push(null); 32153 continue; 32154 } else if (!isPDFFunction(transferObj)) { 32155 return null; 32156 } 32157 const transferFn = this._pdfFunctionFactory.create(transferObj); 32158 const transferMap = new Uint8Array(256), 32159 tmp = new Float32Array(1); 32160 for (let j = 0; j < 256; j++) { 32161 tmp[0] = j / 255; 32162 transferFn(tmp, 0, tmp, 0); 32163 transferMap[j] = tmp[0] * 255 | 0; 32164 } 32165 transferMaps.push(transferMap); 32166 numEffectfulFns++; 32167 } 32168 if (!(numFns === 1 || numFns === 4)) { 32169 return null; 32170 } 32171 if (numEffectfulFns === 0) { 32172 return null; 32173 } 32174 return transferMaps; 32175 } 32176 handleTilingType(fn, color, resources, pattern, patternDict, operatorList, task, localTilingPatternCache) { 32177 const tilingOpList = new OperatorList(); 32178 const patternResources = Dict.merge({ 32179 xref: this.xref, 32180 dictArray: [patternDict.get("Resources"), resources] 32181 }); 32182 return this.getOperatorList({ 32183 stream: pattern, 32184 task, 32185 resources: patternResources, 32186 operatorList: tilingOpList 32187 }).then(function () { 32188 const operatorListIR = tilingOpList.getIR(); 32189 const tilingPatternIR = getTilingPatternIR(operatorListIR, patternDict, color); 32190 operatorList.addDependencies(tilingOpList.dependencies); 32191 operatorList.addOp(fn, tilingPatternIR); 32192 if (patternDict.objId) { 32193 localTilingPatternCache.set(null, patternDict.objId, { 32194 operatorListIR, 32195 dict: patternDict 32196 }); 32197 } 32198 }).catch(reason => { 32199 if (reason instanceof AbortException) { 32200 return; 32201 } 32202 if (this.options.ignoreErrors) { 32203 warn(`handleTilingType - ignoring pattern: "${reason}".`); 32204 return; 32205 } 32206 throw reason; 32207 }); 32208 } 32209 async handleSetFont(resources, fontArgs, fontRef, operatorList, task, state, fallbackFontDict = null, cssFontInfo = null) { 32210 const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null; 32211 const translated = await this.loadFont(fontName, fontRef, resources, task, fallbackFontDict, cssFontInfo); 32212 if (translated.font.isType3Font) { 32213 operatorList.addDependencies(translated.type3Dependencies); 32214 } 32215 state.font = translated.font; 32216 translated.send(this.handler); 32217 return translated.loadedName; 32218 } 32219 handleText(chars, state) { 32220 const font = state.font; 32221 const glyphs = font.charsToGlyphs(chars); 32222 if (font.data) { 32223 const isAddToPathSet = !!(state.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG); 32224 if (isAddToPathSet || state.fillColorSpace.name === "Pattern" || font.disableFontFace) { 32225 PartialEvaluator.buildFontPaths(font, glyphs, this.handler, this.options); 32226 } 32227 } 32228 return glyphs; 32229 } 32230 ensureStateFont(state) { 32231 if (state.font) { 32232 return; 32233 } 32234 const reason = new FormatError("Missing setFont (Tf) operator before text rendering operator."); 32235 if (this.options.ignoreErrors) { 32236 warn(`ensureStateFont: "${reason}".`); 32237 return; 32238 } 32239 throw reason; 32240 } 32241 async setGState({ 32242 resources, 32243 gState, 32244 operatorList, 32245 cacheKey, 32246 task, 32247 stateManager, 32248 localGStateCache, 32249 localColorSpaceCache, 32250 seenRefs 32251 }) { 32252 const gStateRef = gState.objId; 32253 let isSimpleGState = true; 32254 const gStateObj = []; 32255 let promise = Promise.resolve(); 32256 for (const [key, value] of gState) { 32257 switch (key) { 32258 case "Type": 32259 break; 32260 case "LW": 32261 if (typeof value !== "number") { 32262 warn(`Invalid LW (line width): ${value}`); 32263 break; 32264 } 32265 gStateObj.push([key, Math.abs(value)]); 32266 break; 32267 case "LC": 32268 case "LJ": 32269 case "ML": 32270 case "D": 32271 case "RI": 32272 case "FL": 32273 case "CA": 32274 case "ca": 32275 gStateObj.push([key, value]); 32276 break; 32277 case "Font": 32278 isSimpleGState = false; 32279 promise = promise.then(() => this.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) { 32280 operatorList.addDependency(loadedName); 32281 gStateObj.push([key, [loadedName, value[1]]]); 32282 })); 32283 break; 32284 case "BM": 32285 gStateObj.push([key, normalizeBlendMode(value)]); 32286 break; 32287 case "SMask": 32288 if (isName(value, "None")) { 32289 gStateObj.push([key, false]); 32290 break; 32291 } 32292 if (value instanceof Dict) { 32293 isSimpleGState = false; 32294 promise = promise.then(() => this.handleSMask(value, resources, operatorList, task, stateManager, localColorSpaceCache, seenRefs)); 32295 gStateObj.push([key, true]); 32296 } else { 32297 warn("Unsupported SMask type"); 32298 } 32299 break; 32300 case "TR": 32301 const transferMaps = this.handleTransferFunction(value); 32302 gStateObj.push([key, transferMaps]); 32303 break; 32304 case "OP": 32305 case "op": 32306 case "OPM": 32307 case "BG": 32308 case "BG2": 32309 case "UCR": 32310 case "UCR2": 32311 case "TR2": 32312 case "HT": 32313 case "SM": 32314 case "SA": 32315 case "AIS": 32316 case "TK": 32317 info("graphic state operator " + key); 32318 break; 32319 default: 32320 info("Unknown graphic state operator " + key); 32321 break; 32322 } 32323 } 32324 await promise; 32325 if (gStateObj.length > 0) { 32326 operatorList.addOp(OPS.setGState, [gStateObj]); 32327 } 32328 if (isSimpleGState) { 32329 localGStateCache.set(cacheKey, gStateRef, gStateObj); 32330 } 32331 } 32332 loadFont(fontName, font, resources, task, fallbackFontDict = null, cssFontInfo = null) { 32333 const errorFont = async () => new TranslatedFont({ 32334 loadedName: "g_font_error", 32335 font: new ErrorFont(`Font "${fontName}" is not available.`), 32336 dict: font 32337 }); 32338 let fontRef; 32339 if (font) { 32340 if (font instanceof Ref) { 32341 fontRef = font; 32342 } 32343 } else { 32344 const fontRes = resources.get("Font"); 32345 if (fontRes) { 32346 fontRef = fontRes.getRaw(fontName); 32347 } 32348 } 32349 if (fontRef) {
vendor: 1,534 bytes, lines 32350-32395
32350 if (this.type3FontRefs?.has(fontRef)) { 32351 return errorFont(); 32352 } 32353 if (this.fontCache.has(fontRef)) { 32354 return this.fontCache.get(fontRef); 32355 } 32356 try { 32357 font = this.xref.fetchIfRef(fontRef); 32358 } catch (ex) { 32359 warn(`loadFont - lookup failed: "${ex}".`); 32360 } 32361 } 32362 if (!(font instanceof Dict)) { 32363 if (!this.options.ignoreErrors && !this.parsingType3Font) { 32364 warn(`Font "${fontName}" is not available.`); 32365 return errorFont(); 32366 } 32367 warn(`Font "${fontName}" is not available -- attempting to fallback to a default font.`); 32368 font = fallbackFontDict || PartialEvaluator.fallbackFontDict; 32369 } 32370 if (font.cacheKey && this.fontCache.has(font.cacheKey)) { 32371 return this.fontCache.get(font.cacheKey); 32372 } 32373 const { 32374 promise, 32375 resolve 32376 } = Promise.withResolvers(); 32377 let preEvaluatedFont; 32378 try { 32379 preEvaluatedFont = this.preEvaluateFont(font); 32380 preEvaluatedFont.cssFontInfo = cssFontInfo; 32381 } catch (reason) { 32382 warn(`loadFont - preEvaluateFont failed: "${reason}".`); 32383 return errorFont(); 32384 } 32385 const { 32386 descriptor, 32387 hash 32388 } = preEvaluatedFont; 32389 const fontRefIsRef = fontRef instanceof Ref; 32390 let fontID; 32391 if (hash && descriptor instanceof Dict) { 32392 const fontAliases = descriptor.fontAliases ||= Object.create(null); 32393 if (fontAliases[hash]) { 32394 const aliasFontRef = fontAliases[hash].aliasRef; 32395 if (fontRefIsRef && aliasFontRef && this.fontCache.has(ali
vendor: 33,713 bytes, lines 32395-33340
32395asFontRef)) { 32396 this.fontCache.putAlias(fontRef, aliasFontRef); 32397 return this.fontCache.get(fontRef); 32398 } 32399 } else { 32400 fontAliases[hash] = { 32401 fontID: this.idFactory.createFontId() 32402 }; 32403 } 32404 if (fontRefIsRef) { 32405 fontAliases[hash].aliasRef = fontRef; 32406 } 32407 fontID = fontAliases[hash].fontID; 32408 } else { 32409 fontID = this.idFactory.createFontId(); 32410 } 32411 assert(fontID?.startsWith("f"), 'The "fontID" must be (correctly) defined.'); 32412 if (fontRefIsRef) { 32413 this.fontCache.put(fontRef, promise); 32414 } else { 32415 font.cacheKey = `cacheKey_${fontID}`; 32416 this.fontCache.put(font.cacheKey, promise); 32417 } 32418 font.loadedName = `${this.idFactory.getDocId()}_${fontID}`; 32419 this.translateFont(preEvaluatedFont).then(async translatedFont => { 32420 const translated = new TranslatedFont({ 32421 loadedName: font.loadedName, 32422 font: translatedFont, 32423 dict: font 32424 }); 32425 if (translatedFont.isType3Font) { 32426 try { 32427 await translated.loadType3Data(this, resources, task); 32428 } catch (reason) { 32429 throw new Error(`Type3 font load error: ${reason}`); 32430 } 32431 } 32432 resolve(translated); 32433 }).catch(reason => { 32434 warn(`loadFont - translateFont failed: "${reason}".`); 32435 resolve(new TranslatedFont({ 32436 loadedName: font.loadedName, 32437 font: new ErrorFont(reason?.message), 32438 dict: font 32439 })); 32440 }); 32441 return promise; 32442 } 32443 buildPath(fn, args, state) { 32444 const { 32445 pathMinMax: minMax, 32446 pathBuffer 32447 } = state; 32448 switch (fn | 0) { 32449 case OPS.rectangle: 32450 { 32451 const x = state.currentPointX = args[0]; 32452 const y = state.currentPointY = args[1]; 32453 const width = args[2]; 32454 const height = args[3]; 32455 const xw = x + width; 32456 const yh = y + height; 32457 if (width === 0 || height === 0) { 32458 pathBuffer.push(DrawOPS.moveTo, x, y, DrawOPS.lineTo, xw, yh, DrawOPS.closePath); 32459 } else { 32460 pathBuffer.push(DrawOPS.moveTo, x, y, DrawOPS.lineTo, xw, y, DrawOPS.lineTo, xw, yh, DrawOPS.lineTo, x, yh, DrawOPS.closePath); 32461 } 32462 Util.rectBoundingBox(x, y, xw, yh, minMax); 32463 break; 32464 } 32465 case OPS.moveTo: 32466 { 32467 const x = state.currentPointX = args[0]; 32468 const y = state.currentPointY = args[1]; 32469 pathBuffer.push(DrawOPS.moveTo, x, y); 32470 Util.pointBoundingBox(x, y, minMax); 32471 break; 32472 } 32473 case OPS.lineTo: 32474 { 32475 const x = state.currentPointX = args[0]; 32476 const y = state.currentPointY = args[1]; 32477 pathBuffer.push(DrawOPS.lineTo, x, y); 32478 Util.pointBoundingBox(x, y, minMax); 32479 break; 32480 } 32481 case OPS.curveTo: 32482 { 32483 const startX = state.currentPointX; 32484 const startY = state.currentPointY; 32485 const [x1, y1, x2, y2, x, y] = args; 32486 state.currentPointX = x; 32487 state.currentPointY = y; 32488 pathBuffer.push(DrawOPS.curveTo, x1, y1, x2, y2, x, y); 32489 Util.bezierBoundingBox(startX, startY, x1, y1, x2, y2, x, y, minMax); 32490 break; 32491 } 32492 case OPS.curveTo2: 32493 { 32494 const startX = state.currentPointX; 32495 const startY = state.currentPointY; 32496 const [x1, y1, x, y] = args; 32497 state.currentPointX = x; 32498 state.currentPointY = y; 32499 pathBuffer.push(DrawOPS.curveTo, startX, startY, x1, y1, x, y); 32500 Util.bezierBoundingBox(startX, startY, startX, startY, x1, y1, x, y, minMax); 32501 break; 32502 } 32503 case OPS.curveTo3: 32504 { 32505 const startX = state.currentPointX; 32506 const startY = state.currentPointY; 32507 const [x1, y1, x, y] = args; 32508 state.currentPointX = x; 32509 state.currentPointY = y; 32510 pathBuffer.push(DrawOPS.curveTo, x1, y1, x, y, x, y); 32511 Util.bezierBoundingBox(startX, startY, x1, y1, x, y, x, y, minMax); 32512 break; 32513 } 32514 case OPS.closePath: 32515 pathBuffer.push(DrawOPS.closePath); 32516 break; 32517 } 32518 } 32519 _getColorSpace(cs, resources, localColorSpaceCache) { 32520 return ColorSpaceUtils.parse({ 32521 cs, 32522 xref: this.xref, 32523 resources, 32524 pdfFunctionFactory: this._pdfFunctionFactory, 32525 globalColorSpaceCache: this.globalColorSpaceCache, 32526 localColorSpaceCache, 32527 asyncIfNotCached: true 32528 }); 32529 } 32530 async _handleColorSpace(csPromise) { 32531 try { 32532 return await csPromise; 32533 } catch (ex) { 32534 if (ex instanceof AbortException) { 32535 return null; 32536 } 32537 if (this.options.ignoreErrors) { 32538 warn(`_handleColorSpace - ignoring ColorSpace: "${ex}".`); 32539 return null; 32540 } 32541 throw ex; 32542 } 32543 } 32544 parseShading({ 32545 shading, 32546 resources, 32547 localColorSpaceCache, 32548 localShadingPatternCache 32549 }) { 32550 let id = localShadingPatternCache.get(shading); 32551 if (id) { 32552 return id; 32553 } 32554 let patternIR; 32555 try { 32556 const shadingFill = Pattern.parseShading(shading, this.xref, resources, this._pdfFunctionFactory, this.globalColorSpaceCache, localColorSpaceCache); 32557 patternIR = shadingFill.getIR(); 32558 } catch (reason) { 32559 if (reason instanceof AbortException) { 32560 return null; 32561 } 32562 if (this.options.ignoreErrors) { 32563 warn(`parseShading - ignoring shading: "${reason}".`); 32564 localShadingPatternCache.set(shading, null); 32565 return null; 32566 } 32567 throw reason; 32568 } 32569 id = `pattern_${this.idFactory.createObjId()}`; 32570 if (this.parsingType3Font) { 32571 id = `${this.idFactory.getDocId()}_type3_${id}`; 32572 } 32573 localShadingPatternCache.set(shading, id); 32574 if (this.parsingType3Font) { 32575 this.handler.send("commonobj", [id, "Pattern", patternIR]); 32576 } else { 32577 this.handler.send("obj", [id, this.pageIndex, "Pattern", patternIR]); 32578 } 32579 return id; 32580 } 32581 handleColorN(operatorList, fn, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache) { 32582 const patternName = args.pop(); 32583 if (patternName instanceof Name) { 32584 const rawPattern = patterns.getRaw(patternName.name); 32585 const localTilingPattern = rawPattern instanceof Ref && localTilingPatternCache.getByRef(rawPattern); 32586 if (localTilingPattern) { 32587 try { 32588 const color = cs.base ? cs.base.getRgbHex(args, 0) : null; 32589 const tilingPatternIR = getTilingPatternIR(localTilingPattern.operatorListIR, localTilingPattern.dict, color); 32590 operatorList.addOp(fn, tilingPatternIR); 32591 return undefined; 32592 } catch {} 32593 } 32594 const pattern = this.xref.fetchIfRef(rawPattern); 32595 if (pattern) { 32596 const dict = pattern instanceof BaseStream ? pattern.dict : pattern; 32597 const typeNum = dict.get("PatternType"); 32598 if (typeNum === PatternType.TILING) { 32599 const color = cs.base ? cs.base.getRgbHex(args, 0) : null; 32600 return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task, localTilingPatternCache); 32601 } else if (typeNum === PatternType.SHADING) { 32602 const shading = dict.get("Shading"); 32603 const objId = this.parseShading({ 32604 shading, 32605 resources, 32606 localColorSpaceCache, 32607 localShadingPatternCache 32608 }); 32609 if (objId) { 32610 const matrix = lookupMatrix(dict.getArray("Matrix"), null); 32611 operatorList.addOp(fn, ["Shading", objId, matrix]); 32612 } 32613 return undefined; 32614 } 32615 throw new FormatError(`Unknown PatternType: ${typeNum}`); 32616 } 32617 } 32618 throw new FormatError(`Unknown PatternName: ${patternName}`); 32619 } 32620 _parseVisibilityExpression(array, nestingCounter, currentResult) { 32621 const MAX_NESTING = 10; 32622 if (++nestingCounter > MAX_NESTING) { 32623 warn("Visibility expression is too deeply nested"); 32624 return; 32625 } 32626 const length = array.length; 32627 const operator = this.xref.fetchIfRef(array[0]); 32628 if (length < 2 || !(operator instanceof Name)) { 32629 warn("Invalid visibility expression"); 32630 return; 32631 } 32632 switch (operator.name) { 32633 case "And": 32634 case "Or": 32635 case "Not": 32636 currentResult.push(operator.name); 32637 break; 32638 default: 32639 warn(`Invalid operator ${operator.name} in visibility expression`); 32640 return; 32641 } 32642 for (let i = 1; i < length; i++) { 32643 const raw = array[i]; 32644 const object = this.xref.fetchIfRef(raw); 32645 if (Array.isArray(object)) { 32646 const nestedResult = []; 32647 currentResult.push(nestedResult); 32648 this._parseVisibilityExpression(object, nestingCounter, nestedResult); 32649 } else if (raw instanceof Ref) { 32650 currentResult.push(raw.toString()); 32651 } 32652 } 32653 } 32654 async parseMarkedContentProps(contentProperties, resources) { 32655 let optionalContent; 32656 if (contentProperties instanceof Name) { 32657 const properties = resources.get("Properties"); 32658 optionalContent = properties.get(contentProperties.name); 32659 } else if (contentProperties instanceof Dict) { 32660 optionalContent = contentProperties; 32661 } else { 32662 throw new FormatError("Optional content properties malformed."); 32663 } 32664 const optionalContentType = optionalContent.get("Type")?.name; 32665 if (optionalContentType === "OCG") { 32666 return { 32667 type: optionalContentType, 32668 id: optionalContent.objId 32669 }; 32670 } else if (optionalContentType === "OCMD") { 32671 const expression = optionalContent.get("VE"); 32672 if (Array.isArray(expression)) { 32673 const result = []; 32674 this._parseVisibilityExpression(expression, 0, result); 32675 if (result.length > 0) { 32676 return { 32677 type: "OCMD", 32678 expression: result 32679 }; 32680 } 32681 } 32682 const optionalContentGroups = optionalContent.get("OCGs"); 32683 if (Array.isArray(optionalContentGroups) || optionalContentGroups instanceof Dict) { 32684 const groupIds = []; 32685 if (Array.isArray(optionalContentGroups)) { 32686 for (const ocg of optionalContentGroups) { 32687 groupIds.push(ocg.toString()); 32688 } 32689 } else { 32690 groupIds.push(optionalContentGroups.objId); 32691 } 32692 return { 32693 type: optionalContentType, 32694 ids: groupIds, 32695 policy: optionalContent.get("P") instanceof Name ? optionalContent.get("P").name : null, 32696 expression: null 32697 }; 32698 } else if (optionalContentGroups instanceof Ref) { 32699 return { 32700 type: optionalContentType, 32701 id: optionalContentGroups.toString() 32702 }; 32703 } 32704 } 32705 return null; 32706 } 32707 getOperatorList({ 32708 stream, 32709 task, 32710 resources, 32711 operatorList, 32712 initialState = null, 32713 fallbackFontDict = null, 32714 prevRefs = null 32715 }) { 32716 const objId = stream.dict?.objId; 32717 const seenRefs = new RefSet(prevRefs); 32718 if (objId) { 32719 if (prevRefs?.has(objId)) { 32720 throw new Error(`getOperatorList - ignoring circular reference: ${objId}`); 32721 } 32722 seenRefs.put(objId); 32723 } 32724 resources ||= Dict.empty; 32725 initialState ||= new EvalState(); 32726 if (!operatorList) { 32727 throw new Error('getOperatorList: missing "operatorList" parameter'); 32728 } 32729 const self = this; 32730 const xref = this.xref; 32731 const localImageCache = new LocalImageCache(); 32732 const localColorSpaceCache = new LocalColorSpaceCache(); 32733 const localGStateCache = new LocalGStateCache(); 32734 const localTilingPatternCache = new LocalTilingPatternCache(); 32735 const localShadingPatternCache = new Map(); 32736 const xobjs = resources.get("XObject") || Dict.empty; 32737 const patterns = resources.get("Pattern") || Dict.empty; 32738 const stateManager = new StateManager(initialState); 32739 const preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager); 32740 const timeSlotManager = new TimeSlotManager(); 32741 function closePendingRestoreOPS(argument) { 32742 for (let i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) { 32743 operatorList.addOp(OPS.restore, []); 32744 } 32745 } 32746 return new Promise(function promiseBody(resolve, reject) { 32747 const next = function (promise) { 32748 Promise.all([promise, operatorList.ready]).then(function () { 32749 try { 32750 promiseBody(resolve, reject); 32751 } catch (ex) { 32752 reject(ex); 32753 } 32754 }, reject); 32755 }; 32756 task.ensureNotTerminated(); 32757 timeSlotManager.reset(); 32758 const operation = {}; 32759 let stop, i, ii, cs, name, isValidName; 32760 while (!(stop = timeSlotManager.check())) { 32761 operation.args = null; 32762 if (!preprocessor.read(operation)) { 32763 break; 32764 } 32765 let args = operation.args; 32766 let fn = operation.fn; 32767 switch (fn | 0) { 32768 case OPS.paintXObject: 32769 isValidName = args[0] instanceof Name; 32770 name = args[0].name; 32771 if (isValidName) { 32772 const localImage = localImageCache.getByName(name); 32773 if (localImage) { 32774 addCachedImageOps(operatorList, localImage); 32775 args = null; 32776 continue; 32777 } 32778 } 32779 next(new Promise(function (resolveXObject, rejectXObject) { 32780 if (!isValidName) { 32781 throw new FormatError("XObject must be referred to by name."); 32782 } 32783 let xobj = xobjs.getRaw(name); 32784 if (xobj instanceof Ref) { 32785 const cachedImage = localImageCache.getByRef(xobj) || self._regionalImageCache.getByRef(xobj) || self.globalImageCache.getData(xobj, self.pageIndex); 32786 if (cachedImage) { 32787 addCachedImageOps(operatorList, cachedImage); 32788 resolveXObject(); 32789 return; 32790 } 32791 xobj = xref.fetch(xobj); 32792 } 32793 if (!(xobj instanceof BaseStream)) { 32794 throw new FormatError("XObject should be a stream"); 32795 } 32796 const type = xobj.dict.get("Subtype"); 32797 if (!(type instanceof Name)) { 32798 throw new FormatError("XObject should have a Name subtype"); 32799 } 32800 if (type.name === "Form") { 32801 stateManager.save(); 32802 self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone({ 32803 newPath: true 32804 }), localColorSpaceCache, seenRefs).then(function () { 32805 stateManager.restore(); 32806 resolveXObject(); 32807 }, rejectXObject); 32808 return; 32809 } else if (type.name === "Image") { 32810 self.buildPaintImageXObject({ 32811 resources, 32812 image: xobj, 32813 operatorList, 32814 cacheKey: name, 32815 localImageCache, 32816 localColorSpaceCache 32817 }).then(resolveXObject, rejectXObject); 32818 return; 32819 } else if (type.name === "PS") { 32820 info("Ignored XObject subtype PS"); 32821 } else { 32822 throw new FormatError(`Unhandled XObject subtype ${type.name}`); 32823 } 32824 resolveXObject(); 32825 }).catch(function (reason) { 32826 if (reason instanceof AbortException) { 32827 return; 32828 } 32829 if (self.options.ignoreErrors) { 32830 warn(`getOperatorList - ignoring XObject: "${reason}".`); 32831 return; 32832 } 32833 throw reason; 32834 })); 32835 return; 32836 case OPS.setFont: 32837 const fontSize = args[1]; 32838 next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state, fallbackFontDict).then(function (loadedName) { 32839 operatorList.addDependency(loadedName); 32840 operatorList.addOp(OPS.setFont, [loadedName, fontSize]); 32841 })); 32842 return; 32843 case OPS.endInlineImage: 32844 const cacheKey = args[0].cacheKey; 32845 if (cacheKey) { 32846 const localImage = localImageCache.getByName(cacheKey); 32847 if (localImage) { 32848 addCachedImageOps(operatorList, localImage); 32849 args = null; 32850 continue; 32851 } 32852 } 32853 next(self.buildPaintImageXObject({ 32854 resources, 32855 image: args[0], 32856 isInline: true, 32857 operatorList, 32858 cacheKey, 32859 localImageCache, 32860 localColorSpaceCache 32861 })); 32862 return; 32863 case OPS.showText: 32864 if (!stateManager.state.font) { 32865 self.ensureStateFont(stateManager.state); 32866 continue; 32867 } 32868 args[0] = self.handleText(args[0], stateManager.state); 32869 break; 32870 case OPS.showSpacedText: 32871 if (!stateManager.state.font) { 32872 self.ensureStateFont(stateManager.state); 32873 continue; 32874 } 32875 const combinedGlyphs = [], 32876 state = stateManager.state; 32877 for (const arrItem of args[0]) { 32878 if (typeof arrItem === "string") { 32879 combinedGlyphs.push(...self.handleText(arrItem, state)); 32880 } else if (typeof arrItem === "number") { 32881 combinedGlyphs.push(arrItem); 32882 } 32883 } 32884 args[0] = combinedGlyphs; 32885 fn = OPS.showText; 32886 break; 32887 case OPS.nextLineShowText: 32888 if (!stateManager.state.font) { 32889 self.ensureStateFont(stateManager.state); 32890 continue; 32891 } 32892 operatorList.addOp(OPS.nextLine); 32893 args[0] = self.handleText(args[0], stateManager.state); 32894 fn = OPS.showText; 32895 break; 32896 case OPS.nextLineSetSpacingShowText: 32897 if (!stateManager.state.font) { 32898 self.ensureStateFont(stateManager.state); 32899 continue; 32900 } 32901 operatorList.addOp(OPS.nextLine); 32902 operatorList.addOp(OPS.setWordSpacing, [args.shift()]); 32903 operatorList.addOp(OPS.setCharSpacing, [args.shift()]); 32904 args[0] = self.handleText(args[0], stateManager.state); 32905 fn = OPS.showText; 32906 break; 32907 case OPS.setTextRenderingMode: 32908 stateManager.state.textRenderingMode = args[0]; 32909 break; 32910 case OPS.setFillColorSpace: 32911 { 32912 const fillCS = self._getColorSpace(args[0], resources, localColorSpaceCache); 32913 if (fillCS instanceof ColorSpace) { 32914 stateManager.state.fillColorSpace = fillCS; 32915 continue; 32916 } 32917 next(self._handleColorSpace(fillCS).then(colorSpace => { 32918 stateManager.state.fillColorSpace = colorSpace || ColorSpaceUtils.gray; 32919 })); 32920 return; 32921 } 32922 case OPS.setStrokeColorSpace: 32923 { 32924 const strokeCS = self._getColorSpace(args[0], resources, localColorSpaceCache); 32925 if (strokeCS instanceof ColorSpace) { 32926 stateManager.state.strokeColorSpace = strokeCS; 32927 continue; 32928 } 32929 next(self._handleColorSpace(strokeCS).then(colorSpace => { 32930 stateManager.state.strokeColorSpace = colorSpace || ColorSpaceUtils.gray; 32931 })); 32932 return; 32933 } 32934 case OPS.setFillColor: 32935 cs = stateManager.state.fillColorSpace; 32936 args = [cs.getRgbHex(args, 0)]; 32937 fn = OPS.setFillRGBColor; 32938 break; 32939 case OPS.setStrokeColor: 32940 cs = stateManager.state.strokeColorSpace; 32941 args = [cs.getRgbHex(args, 0)]; 32942 fn = OPS.setStrokeRGBColor; 32943 break; 32944 case OPS.setFillGray: 32945 stateManager.state.fillColorSpace = ColorSpaceUtils.gray; 32946 args = [ColorSpaceUtils.gray.getRgbHex(args, 0)]; 32947 fn = OPS.setFillRGBColor; 32948 break; 32949 case OPS.setStrokeGray: 32950 stateManager.state.strokeColorSpace = ColorSpaceUtils.gray; 32951 args = [ColorSpaceUtils.gray.getRgbHex(args, 0)]; 32952 fn = OPS.setStrokeRGBColor; 32953 break; 32954 case OPS.setFillCMYKColor: 32955 stateManager.state.fillColorSpace = ColorSpaceUtils.cmyk; 32956 args = [ColorSpaceUtils.cmyk.getRgbHex(args, 0)]; 32957 fn = OPS.setFillRGBColor; 32958 break; 32959 case OPS.setStrokeCMYKColor: 32960 stateManager.state.strokeColorSpace = ColorSpaceUtils.cmyk; 32961 args = [ColorSpaceUtils.cmyk.getRgbHex(args, 0)]; 32962 fn = OPS.setStrokeRGBColor; 32963 break; 32964 case OPS.setFillRGBColor: 32965 stateManager.state.fillColorSpace = ColorSpaceUtils.rgb; 32966 args = [ColorSpaceUtils.rgb.getRgbHex(args, 0)]; 32967 break; 32968 case OPS.setStrokeRGBColor: 32969 stateManager.state.strokeColorSpace = ColorSpaceUtils.rgb; 32970 args = [ColorSpaceUtils.rgb.getRgbHex(args, 0)]; 32971 break; 32972 case OPS.setFillColorN: 32973 cs = stateManager.state.patternFillColorSpace; 32974 if (!cs) { 32975 if (isNumberArray(args, null)) { 32976 args = [ColorSpaceUtils.gray.getRgbHex(args, 0)]; 32977 fn = OPS.setFillRGBColor; 32978 break; 32979 } 32980 args = []; 32981 fn = OPS.setFillTransparent; 32982 break; 32983 } 32984 if (cs.name === "Pattern") { 32985 next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache)); 32986 return; 32987 } 32988 args = [cs.getRgbHex(args, 0)]; 32989 fn = OPS.setFillRGBColor; 32990 break; 32991 case OPS.setStrokeColorN: 32992 cs = stateManager.state.patternStrokeColorSpace; 32993 if (!cs) { 32994 if (isNumberArray(args, null)) { 32995 args = [ColorSpaceUtils.gray.getRgbHex(args, 0)]; 32996 fn = OPS.setStrokeRGBColor; 32997 break; 32998 } 32999 args = []; 33000 fn = OPS.setStrokeTransparent; 33001 break; 33002 } 33003 if (cs.name === "Pattern") { 33004 next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache)); 33005 return; 33006 } 33007 args = [cs.getRgbHex(args, 0)]; 33008 fn = OPS.setStrokeRGBColor; 33009 break; 33010 case OPS.shadingFill: 33011 let shading; 33012 try { 33013 const shadingRes = resources.get("Shading"); 33014 if (!shadingRes) { 33015 throw new FormatError("No shading resource found"); 33016 } 33017 shading = shadingRes.get(args[0].name); 33018 if (!shading) { 33019 throw new FormatError("No shading object found"); 33020 } 33021 } catch (reason) { 33022 if (reason instanceof AbortException) { 33023 continue; 33024 } 33025 if (self.options.ignoreErrors) { 33026 warn(`getOperatorList - ignoring Shading: "${reason}".`); 33027 continue; 33028 } 33029 throw reason; 33030 } 33031 const patternId = self.parseShading({ 33032 shading, 33033 resources, 33034 localColorSpaceCache, 33035 localShadingPatternCache 33036 }); 33037 if (!patternId) { 33038 continue; 33039 } 33040 args = [patternId]; 33041 fn = OPS.shadingFill; 33042 break; 33043 case OPS.setGState: 33044 isValidName = args[0] instanceof Name; 33045 name = args[0].name; 33046 if (isValidName) { 33047 const localGStateObj = localGStateCache.getByName(name); 33048 if (localGStateObj) { 33049 if (localGStateObj.length > 0) { 33050 operatorList.addOp(OPS.setGState, [localGStateObj]); 33051 } 33052 args = null; 33053 continue; 33054 } 33055 } 33056 next(new Promise(function (resolveGState, rejectGState) { 33057 if (!isValidName) { 33058 throw new FormatError("GState must be referred to by name."); 33059 } 33060 const extGState = resources.get("ExtGState"); 33061 if (!(extGState instanceof Dict)) { 33062 throw new FormatError("ExtGState should be a dictionary."); 33063 } 33064 const gState = extGState.get(name); 33065 if (!(gState instanceof Dict)) { 33066 throw new FormatError("GState should be a dictionary."); 33067 } 33068 self.setGState({ 33069 resources, 33070 gState, 33071 operatorList, 33072 cacheKey: name, 33073 task, 33074 stateManager, 33075 localGStateCache, 33076 localColorSpaceCache, 33077 seenRefs 33078 }).then(resolveGState, rejectGState); 33079 }).catch(function (reason) { 33080 if (reason instanceof AbortException) { 33081 return; 33082 } 33083 if (self.options.ignoreErrors) { 33084 warn(`getOperatorList - ignoring ExtGState: "${reason}".`); 33085 return; 33086 } 33087 throw reason; 33088 })); 33089 return; 33090 case OPS.setLineWidth: 33091 { 33092 const [thickness] = args; 33093 if (typeof thickness !== "number") { 33094 warn(`Invalid setLineWidth: ${thickness}`); 33095 continue; 33096 } 33097 args[0] = Math.abs(thickness); 33098 break; 33099 } 33100 case OPS.setDash: 33101 { 33102 const dashPhase = args[1]; 33103 if (typeof dashPhase !== "number") { 33104 warn(`Invalid setDash: ${dashPhase}`); 33105 continue; 33106 } 33107 const dashArray = args[0]; 33108 if (!Array.isArray(dashArray)) { 33109 warn(`Invalid setDash: ${dashArray}`); 33110 continue; 33111 } 33112 if (dashArray.some(x => typeof x !== "number")) { 33113 args[0] = dashArray.filter(x => typeof x === "number"); 33114 } 33115 break; 33116 } 33117 case OPS.moveTo: 33118 case OPS.lineTo: 33119 case OPS.curveTo: 33120 case OPS.curveTo2: 33121 case OPS.curveTo3: 33122 case OPS.closePath: 33123 case OPS.rectangle: 33124 self.buildPath(fn, args, stateManager.state); 33125 continue; 33126 case OPS.stroke: 33127 case OPS.closeStroke: 33128 case OPS.fill: 33129 case OPS.eoFill: 33130 case OPS.fillStroke: 33131 case OPS.eoFillStroke: 33132 case OPS.closeFillStroke: 33133 case OPS.closeEOFillStroke: 33134 case OPS.endPath: 33135 { 33136 const { 33137 state: { 33138 pathBuffer, 33139 pathMinMax 33140 } 33141 } = stateManager; 33142 if (fn === OPS.closeStroke || fn === OPS.closeFillStroke || fn === OPS.closeEOFillStroke) { 33143 pathBuffer.push(DrawOPS.closePath); 33144 } 33145 if (pathBuffer.length === 0) { 33146 operatorList.addOp(OPS.constructPath, [fn, [null], null]); 33147 } else { 33148 operatorList.addOp(OPS.constructPath, [fn, [new Float32Array(pathBuffer)], pathMinMax.slice()]); 33149 pathBuffer.length = 0; 33150 pathMinMax.set([Infinity, Infinity, -Infinity, -Infinity], 0); 33151 } 33152 continue; 33153 } 33154 case OPS.setTextMatrix: 33155 operatorList.addOp(fn, [new Float32Array(args)]); 33156 continue; 33157 case OPS.markPoint: 33158 case OPS.markPointProps: 33159 case OPS.beginCompat: 33160 case OPS.endCompat: 33161 continue; 33162 case OPS.beginMarkedContentProps: 33163 if (!(args[0] instanceof Name)) { 33164 warn(`Expected name for beginMarkedContentProps arg0=${args[0]}`); 33165 operatorList.addOp(OPS.beginMarkedContentProps, ["OC", null]); 33166 continue; 33167 } 33168 if (args[0].name === "OC") { 33169 next(self.parseMarkedContentProps(args[1], resources).then(data => { 33170 operatorList.addOp(OPS.beginMarkedContentProps, ["OC", data]); 33171 }).catch(reason => { 33172 if (reason instanceof AbortException) { 33173 return; 33174 } 33175 if (self.options.ignoreErrors) { 33176 warn(`getOperatorList - ignoring beginMarkedContentProps: "${reason}".`); 33177 operatorList.addOp(OPS.beginMarkedContentProps, ["OC", null]); 33178 return; 33179 } 33180 throw reason; 33181 })); 33182 return; 33183 } 33184 args = [args[0].name, args[1] instanceof Dict ? args[1].get("MCID") : null]; 33185 break; 33186 case OPS.beginMarkedContent: 33187 case OPS.endMarkedContent: 33188 default: 33189 if (args !== null) { 33190 for (i = 0, ii = args.length; i < ii; i++) { 33191 if (args[i] instanceof Dict) { 33192 break; 33193 } 33194 } 33195 if (i < ii) { 33196 warn("getOperatorList - ignoring operator: " + fn); 33197 continue; 33198 } 33199 } 33200 } 33201 operatorList.addOp(fn, args); 33202 } 33203 if (stop) { 33204 next(deferred); 33205 return; 33206 } 33207 closePendingRestoreOPS(); 33208 resolve(); 33209 }).catch(reason => { 33210 if (reason instanceof AbortException) { 33211 return; 33212 } 33213 if (this.options.ignoreErrors) { 33214 warn(`getOperatorList - ignoring errors during "${task.name}" ` + `task: "${reason}".`); 33215 closePendingRestoreOPS(); 33216 return; 33217 } 33218 throw reason; 33219 }); 33220 } 33221 getTextContent({ 33222 stream, 33223 task, 33224 resources, 33225 stateManager = null, 33226 includeMarkedContent = false, 33227 sink, 33228 seenStyles = new Set(), 33229 viewBox, 33230 lang = null, 33231 markedContentData = null, 33232 disableNormalization = false, 33233 keepWhiteSpace = false, 33234 prevRefs = null, 33235 intersector = null 33236 }) { 33237 const objId = stream.dict?.objId; 33238 const seenRefs = new RefSet(prevRefs); 33239 if (objId) { 33240 if (prevRefs?.has(objId)) { 33241 throw new Error(`getTextContent - ignoring circular reference: ${objId}`); 33242 } 33243 seenRefs.put(objId); 33244 } 33245 resources ||= Dict.empty; 33246 stateManager ||= new StateManager(new TextState()); 33247 if (includeMarkedContent) { 33248 markedContentData ||= { 33249 level: 0 33250 }; 33251 } 33252 const textContent = { 33253 items: [], 33254 styles: Object.create(null), 33255 lang 33256 }; 33257 const textContentItem = { 33258 initialized: false, 33259 str: [], 33260 totalWidth: 0, 33261 totalHeight: 0, 33262 width: 0, 33263 height: 0, 33264 vertical: false, 33265 prevTransform: null, 33266 textAdvanceScale: 0, 33267 spaceInFlowMin: 0, 33268 spaceInFlowMax: 0, 33269 trackingSpaceMin: Infinity, 33270 negativeSpaceMax: -Infinity, 33271 notASpace: -Infinity, 33272 transform: null, 33273 fontName: null, 33274 hasEOL: false 33275 }; 33276 const twoLastChars = [" ", " "]; 33277 let twoLastCharsPos = 0; 33278 function saveLastChar(char) { 33279 const nextPos = (twoLastCharsPos + 1) % 2; 33280 const ret = twoLastChars[twoLastCharsPos] !== " " && twoLastChars[nextPos] === " "; 33281 twoLastChars[twoLastCharsPos] = char; 33282 twoLastCharsPos = nextPos; 33283 return !keepWhiteSpace && ret; 33284 } 33285 function shouldAddWhitepsace() { 33286 return !keepWhiteSpace && twoLastChars[twoLastCharsPos] !== " " && twoLastChars[(twoLastCharsPos + 1) % 2] === " "; 33287 } 33288 function resetLastChars() { 33289 twoLastChars[0] = twoLastChars[1] = " "; 33290 twoLastCharsPos = 0; 33291 } 33292 const TRACKING_SPACE_FACTOR = 0.102; 33293 const NOT_A_SPACE_FACTOR = 0.03; 33294 const NEGATIVE_SPACE_FACTOR = -0.2; 33295 const SPACE_IN_FLOW_MIN_FACTOR = 0.102; 33296 const SPACE_IN_FLOW_MAX_FACTOR = 0.6; 33297 const VERTICAL_SHIFT_RATIO = 0.25; 33298 const self = this; 33299 const xref = this.xref; 33300 const showSpacedTextBuffer = []; 33301 let xobjs = null; 33302 const emptyXObjectCache = new LocalImageCache(); 33303 const emptyGStateCache = new LocalGStateCache(); 33304 const preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager); 33305 let textState; 33306 function pushWhitespace({ 33307 width = 0, 33308 height = 0, 33309 transform = textContentItem.prevTransform, 33310 fontName = textContentItem.fontName 33311 }) { 33312 intersector?.addExtraChar(" "); 33313 textContent.items.push({ 33314 str: " ", 33315 dir: "ltr", 33316 width, 33317 height, 33318 transform, 33319 fontName, 33320 hasEOL: false 33321 }); 33322 } 33323 function getCurrentTextTransform() { 33324 const font = textState.font; 33325 const tsm = [textState.fontSize * textState.textHScale, 0, 0, textState.fontSize, 0, textState.textRise]; 33326 if (font.isType3Font && (textState.fontSize <= 1 || font.isCharBBox) && !isArrayEqual(textState.fontMatrix, FONT_IDENTITY_MATRIX)) { 33327 const glyphHeight = font.bbox[3] - font.bbox[1]; 33328 if (glyphHeight > 0) { 33329 tsm[3] *= glyphHeight * textState.fontMatrix[3]; 33330 } 33331 } 33332 return Util.transform(textState.ctm, Util.transform(textState.textMatrix, tsm)); 33333 } 33334 function ensureTextContentItem() { 33335 if (textContentItem.initialized) { 33336 return textContentItem; 33337 } 33338 const { 33339 font, 33340 loadedName
vendor: 1,135 bytes, lines 33341-33366
33341 } = textState; 33342 if (!seenStyles.has(loadedName)) { 33343 seenStyles.add(loadedName); 33344 textContent.styles[loadedName] = { 33345 fontFamily: font.fallbackName, 33346 ascent: font.ascent, 33347 descent: font.descent, 33348 vertical: font.vertical 33349 }; 33350 if (self.options.fontExtraProperties && font.systemFontInfo) { 33351 const style = textContent.styles[loadedName]; 33352 style.fontSubstitution = font.systemFontInfo.css; 33353 style.fontSubstitutionLoadedName = font.systemFontInfo.loadedName; 33354 } 33355 } 33356 textContentItem.fontName = loadedName; 33357 const trm = textContentItem.transform = getCurrentTextTransform(); 33358 if (!font.vertical) { 33359 textContentItem.width = textContentItem.totalWidth = 0; 33360 textContentItem.height = textContentItem.totalHeight = Math.hypot(trm[2], trm[3]); 33361 textContentItem.vertical = false; 33362 } else { 33363 textContentItem.width = textContentItem.totalWidth = Math.hypot(trm[0], trm[1]); 33364 textContentItem.height = textContentItem.totalHeight = 0; 33365 textContentItem.vertical = true; 33366 }
vendor: 33,034 bytes, lines 33367-34265
33367 const scaleLineX = Math.hypot(textState.textLineMatrix[0], textState.textLineMatrix[1]); 33368 const scaleCtmX = Math.hypot(textState.ctm[0], textState.ctm[1]); 33369 textContentItem.textAdvanceScale = scaleCtmX * scaleLineX; 33370 const { 33371 fontSize 33372 } = textState; 33373 textContentItem.trackingSpaceMin = fontSize * TRACKING_SPACE_FACTOR; 33374 textContentItem.notASpace = fontSize * NOT_A_SPACE_FACTOR; 33375 textContentItem.negativeSpaceMax = fontSize * NEGATIVE_SPACE_FACTOR; 33376 textContentItem.spaceInFlowMin = fontSize * SPACE_IN_FLOW_MIN_FACTOR; 33377 textContentItem.spaceInFlowMax = fontSize * SPACE_IN_FLOW_MAX_FACTOR; 33378 textContentItem.hasEOL = false; 33379 textContentItem.initialized = true; 33380 return textContentItem; 33381 } 33382 function updateAdvanceScale() { 33383 if (!textContentItem.initialized) { 33384 return; 33385 } 33386 const scaleLineX = Math.hypot(textState.textLineMatrix[0], textState.textLineMatrix[1]); 33387 const scaleCtmX = Math.hypot(textState.ctm[0], textState.ctm[1]); 33388 const scaleFactor = scaleCtmX * scaleLineX; 33389 if (scaleFactor === textContentItem.textAdvanceScale) { 33390 return; 33391 } 33392 if (!textContentItem.vertical) { 33393 textContentItem.totalWidth += textContentItem.width * textContentItem.textAdvanceScale; 33394 textContentItem.width = 0; 33395 } else { 33396 textContentItem.totalHeight += textContentItem.height * textContentItem.textAdvanceScale; 33397 textContentItem.height = 0; 33398 } 33399 textContentItem.textAdvanceScale = scaleFactor; 33400 } 33401 function runBidiTransform(textChunk) { 33402 let text = textChunk.str.join(""); 33403 if (!disableNormalization) { 33404 text = normalizeUnicode(text); 33405 } 33406 const bidiResult = bidi(text, -1, textChunk.vertical); 33407 return { 33408 str: bidiResult.str, 33409 dir: bidiResult.dir, 33410 width: Math.abs(textChunk.totalWidth), 33411 height: Math.abs(textChunk.totalHeight), 33412 transform: textChunk.transform, 33413 fontName: textChunk.fontName, 33414 hasEOL: textChunk.hasEOL 33415 }; 33416 } 33417 async function handleSetFont(fontName, fontRef) { 33418 const translated = await self.loadFont(fontName, fontRef, resources, task); 33419 textState.loadedName = translated.loadedName; 33420 textState.font = translated.font; 33421 textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX; 33422 } 33423 function applyInverseRotation(x, y, matrix) { 33424 const scale = Math.hypot(matrix[0], matrix[1]); 33425 return [(matrix[0] * x + matrix[1] * y) / scale, (matrix[2] * x + matrix[3] * y) / scale]; 33426 } 33427 function compareWithLastPosition(glyphWidth) { 33428 const currentTransform = getCurrentTextTransform(); 33429 let posX = currentTransform[4]; 33430 let posY = currentTransform[5]; 33431 if (textState.font?.vertical) { 33432 if (posX < viewBox[0] || posX > viewBox[2] || posY + glyphWidth < viewBox[1] || posY > viewBox[3]) { 33433 return false; 33434 } 33435 } else if (posX + glyphWidth < viewBox[0] || posX > viewBox[2] || posY < viewBox[1] || posY > viewBox[3]) { 33436 return false; 33437 } 33438 if (!textState.font || !textContentItem.prevTransform) { 33439 return true; 33440 } 33441 let lastPosX = textContentItem.prevTransform[4]; 33442 let lastPosY = textContentItem.prevTransform[5]; 33443 if (lastPosX === posX && lastPosY === posY) { 33444 return true; 33445 } 33446 let rotate = -1; 33447 if (currentTransform[0] && currentTransform[1] === 0 && currentTransform[2] === 0) { 33448 rotate = currentTransform[0] > 0 ? 0 : 180; 33449 } else if (currentTransform[1] && currentTransform[0] === 0 && currentTransform[3] === 0) { 33450 rotate = currentTransform[1] > 0 ? 90 : 270; 33451 } 33452 switch (rotate) { 33453 case 0: 33454 break; 33455 case 90: 33456 [posX, posY] = [posY, posX]; 33457 [lastPosX, lastPosY] = [lastPosY, lastPosX]; 33458 break; 33459 case 180: 33460 [posX, posY, lastPosX, lastPosY] = [-posX, -posY, -lastPosX, -lastPosY]; 33461 break; 33462 case 270: 33463 [posX, posY] = [-posY, -posX]; 33464 [lastPosX, lastPosY] = [-lastPosY, -lastPosX]; 33465 break; 33466 default: 33467 [posX, posY] = applyInverseRotation(posX, posY, currentTransform); 33468 [lastPosX, lastPosY] = applyInverseRotation(lastPosX, lastPosY, textContentItem.prevTransform); 33469 } 33470 if (textState.font.vertical) { 33471 const advanceY = (lastPosY - posY) / textContentItem.textAdvanceScale; 33472 const advanceX = posX - lastPosX; 33473 const textOrientation = Math.sign(textContentItem.height); 33474 if (advanceY < textOrientation * textContentItem.negativeSpaceMax) { 33475 if (Math.abs(advanceX) > 0.5 * textContentItem.width) { 33476 appendEOL(); 33477 return true; 33478 } 33479 resetLastChars(); 33480 flushTextContentItem(); 33481 return true; 33482 } 33483 if (Math.abs(advanceX) > textContentItem.width) { 33484 appendEOL(); 33485 return true; 33486 } 33487 if (advanceY <= textOrientation * textContentItem.notASpace) { 33488 resetLastChars(); 33489 } 33490 if (advanceY <= textOrientation * textContentItem.trackingSpaceMin) { 33491 if (shouldAddWhitepsace()) { 33492 resetLastChars(); 33493 flushTextContentItem(); 33494 pushWhitespace({ 33495 height: Math.abs(advanceY) 33496 }); 33497 } else { 33498 textContentItem.height += advanceY; 33499 } 33500 } else if (!addFakeSpaces(advanceY, textContentItem.prevTransform, textOrientation)) { 33501 if (textContentItem.str.length === 0) { 33502 resetLastChars(); 33503 pushWhitespace({ 33504 height: Math.abs(advanceY) 33505 }); 33506 } else { 33507 textContentItem.height += advanceY; 33508 } 33509 } 33510 if (Math.abs(advanceX) > textContentItem.width * VERTICAL_SHIFT_RATIO) { 33511 flushTextContentItem(); 33512 } 33513 return true; 33514 } 33515 const advanceX = (posX - lastPosX) / textContentItem.textAdvanceScale; 33516 const advanceY = posY - lastPosY; 33517 const textOrientation = Math.sign(textContentItem.width); 33518 if (advanceX < textOrientation * textContentItem.negativeSpaceMax) { 33519 if (Math.abs(advanceY) > 0.5 * textContentItem.height) { 33520 appendEOL(); 33521 return true; 33522 } 33523 resetLastChars(); 33524 flushTextContentItem(); 33525 return true; 33526 } 33527 if (Math.abs(advanceY) > textContentItem.height) { 33528 appendEOL(); 33529 return true; 33530 } 33531 if (advanceX <= textOrientation * textContentItem.notASpace) { 33532 resetLastChars(); 33533 } 33534 if (advanceX <= textOrientation * textContentItem.trackingSpaceMin) { 33535 if (shouldAddWhitepsace()) { 33536 resetLastChars(); 33537 flushTextContentItem(); 33538 pushWhitespace({ 33539 width: Math.abs(advanceX) 33540 }); 33541 } else { 33542 textContentItem.width += advanceX; 33543 } 33544 } else if (!addFakeSpaces(advanceX, textContentItem.prevTransform, textOrientation)) { 33545 if (textContentItem.str.length === 0) { 33546 resetLastChars(); 33547 pushWhitespace({ 33548 width: Math.abs(advanceX) 33549 }); 33550 } else { 33551 textContentItem.width += advanceX; 33552 } 33553 } 33554 if (Math.abs(advanceY) > textContentItem.height * VERTICAL_SHIFT_RATIO) { 33555 flushTextContentItem(); 33556 } 33557 return true; 33558 } 33559 function buildTextContentItem({ 33560 chars, 33561 extraSpacing 33562 }) { 33563 const font = textState.font; 33564 if (!chars) { 33565 const charSpacing = textState.charSpacing + extraSpacing; 33566 if (charSpacing) { 33567 if (!font.vertical) { 33568 textState.translateTextMatrix(charSpacing * textState.textHScale, 0); 33569 } else { 33570 textState.translateTextMatrix(0, -charSpacing); 33571 } 33572 } 33573 if (keepWhiteSpace) { 33574 compareWithLastPosition(0); 33575 } 33576 return; 33577 } 33578 const glyphs = font.charsToGlyphs(chars); 33579 const scale = textState.fontMatrix[0] * textState.fontSize; 33580 for (let i = 0, ii = glyphs.length; i < ii; i++) { 33581 const glyph = glyphs[i]; 33582 const { 33583 category, 33584 originalCharCode 33585 } = glyph; 33586 if (category.isInvisibleFormatMark) { 33587 continue; 33588 } 33589 let charSpacing = textState.charSpacing + (i + 1 === ii ? extraSpacing : 0); 33590 let glyphWidth = glyph.width; 33591 if (font.vertical) { 33592 glyphWidth = glyph.vmetric ? glyph.vmetric[0] : -glyphWidth; 33593 } 33594 let scaledDim = glyphWidth * scale; 33595 if (originalCharCode === 0x20) { 33596 charSpacing += textState.wordSpacing; 33597 } 33598 if (!keepWhiteSpace && category.isWhitespace) { 33599 if (!font.vertical) { 33600 charSpacing += scaledDim; 33601 textState.translateTextMatrix(charSpacing * textState.textHScale, 0); 33602 } else { 33603 charSpacing += -scaledDim; 33604 textState.translateTextMatrix(0, -charSpacing); 33605 } 33606 saveLastChar(" "); 33607 continue; 33608 } 33609 if (!category.isZeroWidthDiacritic && !compareWithLastPosition(scaledDim)) { 33610 if (!font.vertical) { 33611 textState.translateTextMatrix(scaledDim * textState.textHScale, 0); 33612 } else { 33613 textState.translateTextMatrix(0, scaledDim); 33614 } 33615 continue; 33616 } 33617 const textChunk = ensureTextContentItem(); 33618 if (category.isZeroWidthDiacritic) { 33619 scaledDim = 0; 33620 } 33621 if (!font.vertical) { 33622 scaledDim *= textState.textHScale; 33623 intersector?.addGlyph(getCurrentTextTransform(), scaledDim, 0, glyph.unicode); 33624 textState.translateTextMatrix(scaledDim, 0); 33625 textChunk.width += scaledDim; 33626 } else { 33627 intersector?.addGlyph(getCurrentTextTransform(), 0, scaledDim, glyph.unicode); 33628 textState.translateTextMatrix(0, scaledDim); 33629 scaledDim = Math.abs(scaledDim); 33630 textChunk.height += scaledDim; 33631 } 33632 if (scaledDim) { 33633 textChunk.prevTransform = getCurrentTextTransform(); 33634 } 33635 const glyphUnicode = glyph.unicode; 33636 if (saveLastChar(glyphUnicode)) { 33637 textChunk.str.push(" "); 33638 intersector?.addExtraChar(" "); 33639 } 33640 if (!intersector) { 33641 textChunk.str.push(glyphUnicode); 33642 } 33643 if (charSpacing) { 33644 if (!font.vertical) { 33645 textState.translateTextMatrix(charSpacing * textState.textHScale, 0); 33646 } else { 33647 textState.translateTextMatrix(0, -charSpacing); 33648 } 33649 } 33650 } 33651 } 33652 function appendEOL() { 33653 intersector?.addExtraChar("\n"); 33654 resetLastChars(); 33655 if (textContentItem.initialized) { 33656 textContentItem.hasEOL = true; 33657 flushTextContentItem(); 33658 } else { 33659 textContent.items.push({ 33660 str: "", 33661 dir: "ltr", 33662 width: 0, 33663 height: 0, 33664 transform: getCurrentTextTransform(), 33665 fontName: textState.loadedName, 33666 hasEOL: true 33667 }); 33668 } 33669 } 33670 function addFakeSpaces(width, transf, textOrientation) { 33671 if (textOrientation * textContentItem.spaceInFlowMin <= width && width <= textOrientation * textContentItem.spaceInFlowMax) { 33672 if (textContentItem.initialized) { 33673 resetLastChars(); 33674 textContentItem.str.push(" "); 33675 intersector?.addExtraChar(" "); 33676 } 33677 return false; 33678 } 33679 const fontName = textContentItem.fontName; 33680 let height = 0; 33681 if (textContentItem.vertical) { 33682 height = width; 33683 width = 0; 33684 } 33685 flushTextContentItem(); 33686 resetLastChars(); 33687 pushWhitespace({ 33688 width: Math.abs(width), 33689 height: Math.abs(height), 33690 transform: transf || getCurrentTextTransform(), 33691 fontName 33692 }); 33693 return true; 33694 } 33695 function flushTextContentItem() { 33696 if (!textContentItem.initialized || !textContentItem.str) { 33697 return; 33698 } 33699 if (!textContentItem.vertical) { 33700 textContentItem.totalWidth += textContentItem.width * textContentItem.textAdvanceScale; 33701 } else { 33702 textContentItem.totalHeight += textContentItem.height * textContentItem.textAdvanceScale; 33703 } 33704 textContent.items.push(runBidiTransform(textContentItem)); 33705 textContentItem.initialized = false; 33706 textContentItem.str.length = 0; 33707 } 33708 function enqueueChunk(batch = false) { 33709 const length = textContent.items.length; 33710 if (length === 0) { 33711 return; 33712 } 33713 if (batch && length < TEXT_CHUNK_BATCH_SIZE) { 33714 return; 33715 } 33716 sink?.enqueue(textContent, length); 33717 textContent.items = []; 33718 textContent.styles = Object.create(null); 33719 } 33720 const timeSlotManager = new TimeSlotManager(); 33721 return new Promise(function promiseBody(resolve, reject) { 33722 const next = function (promise) { 33723 enqueueChunk(true); 33724 Promise.all([promise, sink?.ready]).then(function () { 33725 try { 33726 promiseBody(resolve, reject); 33727 } catch (ex) { 33728 reject(ex); 33729 } 33730 }, reject); 33731 }; 33732 task.ensureNotTerminated(); 33733 timeSlotManager.reset(); 33734 const operation = {}; 33735 let stop, 33736 name, 33737 isValidName, 33738 args = []; 33739 while (!(stop = timeSlotManager.check())) { 33740 args.length = 0; 33741 operation.args = args; 33742 if (!preprocessor.read(operation)) { 33743 break; 33744 } 33745 const previousState = textState; 33746 textState = stateManager.state; 33747 const fn = operation.fn; 33748 args = operation.args; 33749 switch (fn | 0) { 33750 case OPS.setFont: 33751 const fontNameArg = args[0].name, 33752 fontSizeArg = args[1]; 33753 if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) { 33754 break; 33755 } 33756 flushTextContentItem(); 33757 textState.fontName = fontNameArg; 33758 textState.fontSize = fontSizeArg; 33759 next(handleSetFont(fontNameArg, null)); 33760 return; 33761 case OPS.setTextRise: 33762 textState.textRise = args[0]; 33763 break; 33764 case OPS.setHScale: 33765 textState.textHScale = args[0] / 100; 33766 break; 33767 case OPS.setLeading: 33768 textState.leading = args[0]; 33769 break; 33770 case OPS.moveText: 33771 textState.translateTextLineMatrix(args[0], args[1]); 33772 textState.textMatrix = textState.textLineMatrix.slice(); 33773 break; 33774 case OPS.setLeadingMoveText: 33775 textState.leading = -args[1]; 33776 textState.translateTextLineMatrix(args[0], args[1]); 33777 textState.textMatrix = textState.textLineMatrix.slice(); 33778 break; 33779 case OPS.nextLine: 33780 textState.carriageReturn(); 33781 break; 33782 case OPS.setTextMatrix: 33783 textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]); 33784 textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]); 33785 updateAdvanceScale(); 33786 break; 33787 case OPS.setCharSpacing: 33788 textState.charSpacing = args[0]; 33789 break; 33790 case OPS.setWordSpacing: 33791 textState.wordSpacing = args[0]; 33792 break; 33793 case OPS.beginText: 33794 textState.textMatrix = IDENTITY_MATRIX.slice(); 33795 textState.textLineMatrix = IDENTITY_MATRIX.slice(); 33796 break; 33797 case OPS.showSpacedText: 33798 if (!stateManager.state.font) { 33799 self.ensureStateFont(stateManager.state); 33800 continue; 33801 } 33802 const spaceFactor = (textState.font.vertical ? 1 : -1) * textState.fontSize / 1000; 33803 const elements = args[0]; 33804 for (let i = 0, ii = elements.length; i < ii; i++) { 33805 const item = elements[i]; 33806 if (typeof item === "string") { 33807 showSpacedTextBuffer.push(item); 33808 } else if (typeof item === "number" && item !== 0) { 33809 const str = showSpacedTextBuffer.join(""); 33810 showSpacedTextBuffer.length = 0; 33811 buildTextContentItem({ 33812 chars: str, 33813 extraSpacing: item * spaceFactor 33814 }); 33815 } 33816 } 33817 if (showSpacedTextBuffer.length > 0) { 33818 const str = showSpacedTextBuffer.join(""); 33819 showSpacedTextBuffer.length = 0; 33820 buildTextContentItem({ 33821 chars: str, 33822 extraSpacing: 0 33823 }); 33824 } 33825 break; 33826 case OPS.showText: 33827 if (!stateManager.state.font) { 33828 self.ensureStateFont(stateManager.state); 33829 continue; 33830 } 33831 buildTextContentItem({ 33832 chars: args[0], 33833 extraSpacing: 0 33834 }); 33835 break; 33836 case OPS.nextLineShowText: 33837 if (!stateManager.state.font) { 33838 self.ensureStateFont(stateManager.state); 33839 continue; 33840 } 33841 textState.carriageReturn(); 33842 buildTextContentItem({ 33843 chars: args[0], 33844 extraSpacing: 0 33845 }); 33846 break; 33847 case OPS.nextLineSetSpacingShowText: 33848 if (!stateManager.state.font) { 33849 self.ensureStateFont(stateManager.state); 33850 continue; 33851 } 33852 textState.wordSpacing = args[0]; 33853 textState.charSpacing = args[1]; 33854 textState.carriageReturn(); 33855 buildTextContentItem({ 33856 chars: args[2], 33857 extraSpacing: 0 33858 }); 33859 break; 33860 case OPS.paintXObject: 33861 flushTextContentItem(); 33862 xobjs ??= resources.get("XObject") || Dict.empty; 33863 isValidName = args[0] instanceof Name; 33864 name = args[0].name; 33865 if (isValidName && emptyXObjectCache.getByName(name)) { 33866 break; 33867 } 33868 next(new Promise(function (resolveXObject, rejectXObject) { 33869 if (!isValidName) { 33870 throw new FormatError("XObject must be referred to by name."); 33871 } 33872 let xobj = xobjs.getRaw(name); 33873 if (xobj instanceof Ref) { 33874 if (emptyXObjectCache.getByRef(xobj)) { 33875 resolveXObject(); 33876 return; 33877 } 33878 const globalImage = self.globalImageCache.getData(xobj, self.pageIndex); 33879 if (globalImage) { 33880 resolveXObject(); 33881 return; 33882 } 33883 xobj = xref.fetch(xobj); 33884 } 33885 if (!(xobj instanceof BaseStream)) { 33886 throw new FormatError("XObject should be a stream"); 33887 } 33888 const { 33889 dict 33890 } = xobj; 33891 const type = dict.get("Subtype"); 33892 if (!(type instanceof Name)) { 33893 throw new FormatError("XObject should have a Name subtype"); 33894 } 33895 if (type.name !== "Form") { 33896 emptyXObjectCache.set(name, dict.objId, true); 33897 resolveXObject(); 33898 return; 33899 } 33900 const currentState = stateManager.state.clone(); 33901 const xObjStateManager = new StateManager(currentState); 33902 const matrix = lookupMatrix(dict.getArray("Matrix"), null); 33903 if (matrix) { 33904 xObjStateManager.transform(matrix); 33905 } 33906 const localResources = dict.get("Resources"); 33907 enqueueChunk(); 33908 const sinkWrapper = { 33909 enqueueInvoked: false, 33910 enqueue(chunk, size) { 33911 this.enqueueInvoked = true; 33912 sink.enqueue(chunk, size); 33913 }, 33914 get desiredSize() { 33915 return sink.desiredSize ?? 0; 33916 }, 33917 get ready() { 33918 return sink.ready; 33919 } 33920 }; 33921 self.getTextContent({ 33922 stream: xobj, 33923 task, 33924 resources: localResources instanceof Dict ? localResources : resources, 33925 stateManager: xObjStateManager, 33926 includeMarkedContent, 33927 sink: sink && sinkWrapper, 33928 seenStyles, 33929 viewBox, 33930 lang, 33931 markedContentData, 33932 disableNormalization, 33933 keepWhiteSpace, 33934 prevRefs: seenRefs 33935 }).then(function () { 33936 if (!sinkWrapper.enqueueInvoked) { 33937 emptyXObjectCache.set(name, dict.objId, true); 33938 } 33939 resolveXObject(); 33940 }, rejectXObject); 33941 }).catch(function (reason) { 33942 if (reason instanceof AbortException) { 33943 return; 33944 } 33945 if (self.options.ignoreErrors) { 33946 warn(`getTextContent - ignoring XObject: "${reason}".`); 33947 return; 33948 } 33949 throw reason; 33950 })); 33951 return; 33952 case OPS.setGState: 33953 isValidName = args[0] instanceof Name; 33954 name = args[0].name; 33955 if (isValidName && emptyGStateCache.getByName(name)) { 33956 break; 33957 } 33958 next(new Promise(function (resolveGState, rejectGState) { 33959 if (!isValidName) { 33960 throw new FormatError("GState must be referred to by name."); 33961 } 33962 const extGState = resources.get("ExtGState"); 33963 if (!(extGState instanceof Dict)) { 33964 throw new FormatError("ExtGState should be a dictionary."); 33965 } 33966 const gState = extGState.get(name); 33967 if (!(gState instanceof Dict)) { 33968 throw new FormatError("GState should be a dictionary."); 33969 } 33970 const gStateFont = gState.get("Font"); 33971 if (!gStateFont) { 33972 emptyGStateCache.set(name, gState.objId, true); 33973 resolveGState(); 33974 return; 33975 } 33976 flushTextContentItem(); 33977 textState.fontName = null; 33978 textState.fontSize = gStateFont[1]; 33979 handleSetFont(null, gStateFont[0]).then(resolveGState, rejectGState); 33980 }).catch(function (reason) { 33981 if (reason instanceof AbortException) { 33982 return; 33983 } 33984 if (self.options.ignoreErrors) { 33985 warn(`getTextContent - ignoring ExtGState: "${reason}".`); 33986 return; 33987 } 33988 throw reason; 33989 })); 33990 return; 33991 case OPS.beginMarkedContent: 33992 flushTextContentItem(); 33993 if (includeMarkedContent) { 33994 markedContentData.level++; 33995 textContent.items.push({ 33996 type: "beginMarkedContent", 33997 tag: args[0] instanceof Name ? args[0].name : null 33998 }); 33999 } 34000 break; 34001 case OPS.beginMarkedContentProps: 34002 flushTextContentItem(); 34003 if (includeMarkedContent) { 34004 markedContentData.level++; 34005 let mcid = null; 34006 if (args[1] instanceof Dict) { 34007 mcid = args[1].get("MCID"); 34008 } 34009 textContent.items.push({ 34010 type: "beginMarkedContentProps", 34011 id: Number.isInteger(mcid) ? `${self.idFactory.getPageObjId()}_mc${mcid}` : null, 34012 tag: args[0] instanceof Name ? args[0].name : null 34013 }); 34014 } 34015 break; 34016 case OPS.endMarkedContent: 34017 flushTextContentItem(); 34018 if (includeMarkedContent) { 34019 if (markedContentData.level === 0) { 34020 break; 34021 } 34022 markedContentData.level--; 34023 textContent.items.push({ 34024 type: "endMarkedContent" 34025 }); 34026 } 34027 break; 34028 case OPS.restore: 34029 if (previousState && (previousState.font !== textState.font || previousState.fontSize !== textState.fontSize || previousState.fontName !== textState.fontName)) { 34030 flushTextContentItem(); 34031 } 34032 break; 34033 } 34034 if (textContent.items.length >= (sink?.desiredSize ?? 1)) { 34035 stop = true; 34036 break; 34037 } 34038 } 34039 if (stop) { 34040 next(deferred); 34041 return; 34042 } 34043 flushTextContentItem(); 34044 enqueueChunk(); 34045 resolve(); 34046 }).catch(reason => { 34047 if (reason instanceof AbortException) { 34048 return; 34049 } 34050 if (this.options.ignoreErrors) { 34051 warn(`getTextContent - ignoring errors during "${task.name}" ` + `task: "${reason}".`); 34052 flushTextContentItem(); 34053 enqueueChunk(); 34054 return; 34055 } 34056 throw reason; 34057 }); 34058 } 34059 async extractDataStructures(dict, properties) { 34060 const xref = this.xref; 34061 let cidToGidBytes; 34062 const toUnicodePromise = this.readToUnicode(properties.toUnicode); 34063 if (properties.composite) { 34064 const cidSystemInfo = dict.get("CIDSystemInfo"); 34065 if (cidSystemInfo instanceof Dict) { 34066 properties.cidSystemInfo = { 34067 registry: stringToPDFString(cidSystemInfo.get("Registry")), 34068 ordering: stringToPDFString(cidSystemInfo.get("Ordering")), 34069 supplement: cidSystemInfo.get("Supplement") 34070 }; 34071 } 34072 try { 34073 const cidToGidMap = dict.get("CIDToGIDMap"); 34074 if (cidToGidMap instanceof BaseStream) { 34075 cidToGidBytes = cidToGidMap.getBytes(); 34076 } 34077 } catch (ex) { 34078 if (!this.options.ignoreErrors) { 34079 throw ex; 34080 } 34081 warn(`extractDataStructures - ignoring CIDToGIDMap data: "${ex}".`); 34082 } 34083 } 34084 const differences = []; 34085 let baseEncodingName = null; 34086 let encoding; 34087 if (dict.has("Encoding")) { 34088 encoding = dict.get("Encoding"); 34089 if (encoding instanceof Dict) { 34090 baseEncodingName = encoding.get("BaseEncoding"); 34091 baseEncodingName = baseEncodingName instanceof Name ? baseEncodingName.name : null; 34092 if (encoding.has("Differences")) { 34093 const diffEncoding = encoding.get("Differences"); 34094 let index = 0; 34095 for (const entry of diffEncoding) { 34096 const data = xref.fetchIfRef(entry); 34097 if (typeof data === "number") { 34098 index = data; 34099 } else if (data instanceof Name) { 34100 differences[index++] = data.name; 34101 } else { 34102 throw new FormatError(`Invalid entry in 'Differences' array: ${data}`); 34103 } 34104 } 34105 } 34106 } else if (encoding instanceof Name) { 34107 baseEncodingName = encoding.name; 34108 } else { 34109 const msg = "Encoding is not a Name nor a Dict"; 34110 if (!this.options.ignoreErrors) { 34111 throw new FormatError(msg); 34112 } 34113 warn(msg); 34114 } 34115 if (baseEncodingName !== "MacRomanEncoding" && baseEncodingName !== "MacExpertEncoding" && baseEncodingName !== "WinAnsiEncoding") { 34116 baseEncodingName = null; 34117 } 34118 } 34119 const nonEmbeddedFont = !properties.file || properties.isInternalFont, 34120 isSymbolsFontName = getSymbolsFonts()[properties.name]; 34121 if (baseEncodingName && nonEmbeddedFont && isSymbolsFontName) { 34122 baseEncodingName = null; 34123 } 34124 if (baseEncodingName) { 34125 properties.defaultEncoding = getEncoding(baseEncodingName); 34126 } else { 34127 let isSymbolicFont = !!(properties.flags & FontFlags.Symbolic); 34128 const isNonsymbolicFont = !!(properties.flags & FontFlags.Nonsymbolic); 34129 if (properties.type === "TrueType" && isSymbolicFont && isNonsymbolicFont && differences.length !== 0) { 34130 properties.flags &= ~FontFlags.Symbolic; 34131 isSymbolicFont = false; 34132 } 34133 encoding = StandardEncoding; 34134 if (properties.type === "TrueType" && !isNonsymbolicFont) { 34135 encoding = WinAnsiEncoding; 34136 } 34137 if (isSymbolicFont || isSymbolsFontName) { 34138 encoding = MacRomanEncoding; 34139 if (nonEmbeddedFont) { 34140 if (/Symbol/i.test(properties.name)) { 34141 encoding = SymbolSetEncoding; 34142 } else if (/Dingbats/i.test(properties.name)) { 34143 encoding = ZapfDingbatsEncoding; 34144 } else if (/Wingdings/i.test(properties.name)) { 34145 encoding = WinAnsiEncoding; 34146 } 34147 } 34148 } 34149 properties.defaultEncoding = encoding; 34150 } 34151 properties.differences = differences; 34152 properties.baseEncodingName = baseEncodingName; 34153 properties.hasEncoding = !!baseEncodingName || differences.length > 0; 34154 properties.dict = dict; 34155 properties.toUnicode = await toUnicodePromise; 34156 const builtToUnicode = await this.buildToUnicode(properties); 34157 properties.toUnicode = builtToUnicode; 34158 if (cidToGidBytes) { 34159 properties.cidToGidMap = this.readCidToGidMap(cidToGidBytes, builtToUnicode); 34160 } 34161 return properties; 34162 } 34163 _simpleFontToUnicode(properties, forceGlyphs = false) { 34164 assert(!properties.composite, "Must be a simple font."); 34165 const toUnicode = []; 34166 const encoding = properties.defaultEncoding.slice(); 34167 const baseEncodingName = properties.baseEncodingName; 34168 const differences = properties.differences; 34169 for (const charcode in differences) { 34170 const glyphName = differences[charcode]; 34171 if (glyphName === ".notdef") { 34172 continue; 34173 } 34174 encoding[charcode] = glyphName; 34175 } 34176 const glyphsUnicodeMap = getGlyphsUnicode(); 34177 for (const charcode in encoding) { 34178 let glyphName = encoding[charcode]; 34179 if (glyphName === "") { 34180 continue; 34181 } 34182 let unicode = glyphsUnicodeMap[glyphName]; 34183 if (unicode !== undefined) { 34184 toUnicode[charcode] = String.fromCharCode(unicode); 34185 continue; 34186 } 34187 let code = 0; 34188 switch (glyphName[0]) { 34189 case "G": 34190 if (glyphName.length === 3) { 34191 code = parseInt(glyphName.substring(1), 16); 34192 } 34193 break; 34194 case "g": 34195 if (glyphName.length === 5) { 34196 code = parseInt(glyphName.substring(1), 16); 34197 } 34198 break; 34199 case "C": 34200 case "c": 34201 if (glyphName.length >= 3 && glyphName.length <= 4) { 34202 const codeStr = glyphName.substring(1); 34203 if (forceGlyphs) { 34204 code = parseInt(codeStr, 16); 34205 break; 34206 } 34207 code = +codeStr; 34208 if (Number.isNaN(code) && Number.isInteger(parseInt(codeStr, 16))) { 34209 return this._simpleFontToUnicode(properties, true); 34210 } 34211 } 34212 break; 34213 case "u": 34214 unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap); 34215 if (unicode !== -1) { 34216 code = unicode; 34217 } 34218 break; 34219 default: 34220 switch (glyphName) { 34221 case "f_h": 34222 case "f_t": 34223 case "T_h": 34224 toUnicode[charcode] = glyphName.replaceAll("_", ""); 34225 continue; 34226 } 34227 break; 34228 } 34229 if (code > 0 && code <= 0x10ffff && Number.isInteger(code)) { 34230 if (baseEncodingName && code === +charcode) { 34231 const baseEncoding = getEncoding(baseEncodingName); 34232 if (baseEncoding && (glyphName = baseEncoding[charcode])) { 34233 toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]); 34234 continue; 34235 } 34236 } 34237 toUnicode[charcode] = String.fromCodePoint(code); 34238 } 34239 } 34240 return toUnicode; 34241 } 34242 async buildToUnicode(properties) { 34243 properties.hasIncludedToUnicodeMap = properties.toUnicode?.length > 0; 34244 if (properties.hasIncludedToUnicodeMap) { 34245 if (!properties.composite && properties.hasEncoding) { 34246 properties.fallbackToUnicode = this._simpleFontToUnicode(properties); 34247 } 34248 return properties.toUnicode; 34249 } 34250 if (!properties.composite) { 34251 return new ToUnicodeMap(this._simpleFontToUnicode(properties)); 34252 } 34253 if (properties.composite && (properties.cMap.builtInCMap && !(properties.cMap instanceof IdentityCMap) || properties.cidSystemInfo?.registry === "Adobe" && (properties.cidSystemInfo.ordering === "GB1" || properties.cidSystemInfo.ordering === "CNS1" || properties.cidSystemInfo.ordering === "Japan1" || properties.cidSystemInfo.ordering === "Korea1"))) { 34254 const { 34255 registry, 34256 ordering 34257 } = properties.cidSystemInfo; 34258 const ucs2CMapName = Name.get(`${registry}-${ordering}-UCS2`); 34259 const ucs2CMap = await CMapFactory.create({ 34260 encoding: ucs2CMapName, 34261 fetchBuiltInCMap: this._fetchBuiltInCMapBound, 34262 useCMap: null 34263 }); 34264 const toUnicode = [], 34265 buf = [];
vendor: 6,667 bytes, lines 34266-34462
34266 properties.cMap.forEach(function (charcode, cid) { 34267 if (cid > 0xffff) { 34268 throw new FormatError("Max size of CID is 65,535"); 34269 } 34270 const ucs2 = ucs2CMap.lookup(cid); 34271 if (ucs2) { 34272 buf.length = 0; 34273 for (let i = 0, ii = ucs2.length; i < ii; i += 2) { 34274 buf.push((ucs2.charCodeAt(i) << 8) + ucs2.charCodeAt(i + 1)); 34275 } 34276 toUnicode[charcode] = String.fromCharCode(...buf); 34277 } 34278 }); 34279 return new ToUnicodeMap(toUnicode); 34280 } 34281 return new IdentityToUnicodeMap(properties.firstChar, properties.lastChar); 34282 } 34283 async readToUnicode(cmapObj) { 34284 if (!cmapObj) { 34285 return null; 34286 } 34287 if (cmapObj instanceof Name) { 34288 const cmap = await CMapFactory.create({ 34289 encoding: cmapObj, 34290 fetchBuiltInCMap: this._fetchBuiltInCMapBound, 34291 useCMap: null 34292 }); 34293 if (cmap instanceof IdentityCMap) { 34294 return new IdentityToUnicodeMap(0, 0xffff); 34295 } 34296 return new ToUnicodeMap(cmap.getMap()); 34297 } 34298 if (cmapObj instanceof BaseStream) { 34299 try { 34300 const cmap = await CMapFactory.create({ 34301 encoding: cmapObj, 34302 fetchBuiltInCMap: this._fetchBuiltInCMapBound, 34303 useCMap: null 34304 }); 34305 if (cmap instanceof IdentityCMap) { 34306 return new IdentityToUnicodeMap(0, 0xffff); 34307 } 34308 const map = new Array(cmap.length); 34309 cmap.forEach(function (charCode, token) { 34310 if (typeof token === "number") { 34311 map[charCode] = String.fromCodePoint(token); 34312 return; 34313 } 34314 if (token.length % 2 !== 0) { 34315 token = "\u0000" + token; 34316 } 34317 const str = []; 34318 for (let k = 0; k < token.length; k += 2) { 34319 const w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1); 34320 if ((w1 & 0xf800) !== 0xd800) { 34321 str.push(w1); 34322 continue; 34323 } 34324 k += 2; 34325 const w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1); 34326 str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000); 34327 } 34328 map[charCode] = String.fromCodePoint(...str); 34329 }); 34330 return new ToUnicodeMap(map); 34331 } catch (reason) { 34332 if (reason instanceof AbortException) { 34333 return null; 34334 } 34335 if (this.options.ignoreErrors) { 34336 warn(`readToUnicode - ignoring ToUnicode data: "${reason}".`); 34337 return null; 34338 } 34339 throw reason; 34340 } 34341 } 34342 return null; 34343 } 34344 readCidToGidMap(glyphsData, toUnicode) { 34345 const result = []; 34346 for (let j = 0, jj = glyphsData.length; j < jj; j++) { 34347 const glyphID = glyphsData[j++] << 8 | glyphsData[j]; 34348 const code = j >> 1; 34349 if (glyphID === 0 && !toUnicode.has(code)) { 34350 continue; 34351 } 34352 result[code] = glyphID; 34353 } 34354 return result; 34355 } 34356 extractWidths(dict, descriptor, properties) { 34357 const xref = this.xref; 34358 let glyphsWidths = []; 34359 let defaultWidth = 0; 34360 const glyphsVMetrics = []; 34361 let defaultVMetrics; 34362 if (properties.composite) { 34363 const dw = dict.get("DW"); 34364 defaultWidth = typeof dw === "number" ? Math.ceil(dw) : 1000; 34365 const widths = dict.get("W"); 34366 if (Array.isArray(widths)) { 34367 for (let i = 0, ii = widths.length; i < ii; i++) { 34368 let start = xref.fetchIfRef(widths[i++]); 34369 if (!Number.isInteger(start)) { 34370 break; 34371 } 34372 const code = xref.fetchIfRef(widths[i]); 34373 if (Array.isArray(code)) { 34374 for (const c of code) { 34375 const width = xref.fetchIfRef(c); 34376 if (typeof width === "number") { 34377 glyphsWidths[start] = width; 34378 } 34379 start++; 34380 } 34381 } else if (Number.isInteger(code)) { 34382 const width = xref.fetchIfRef(widths[++i]); 34383 if (typeof width !== "number") { 34384 continue; 34385 } 34386 for (let j = start; j <= code; j++) { 34387 glyphsWidths[j] = width; 34388 } 34389 } else { 34390 break; 34391 } 34392 } 34393 } 34394 if (properties.vertical) { 34395 const dw2 = dict.getArray("DW2"); 34396 let vmetrics = isNumberArray(dw2, 2) ? dw2 : [880, -1000]; 34397 defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]]; 34398 vmetrics = dict.get("W2"); 34399 if (Array.isArray(vmetrics)) { 34400 for (let i = 0, ii = vmetrics.length; i < ii; i++) { 34401 let start = xref.fetchIfRef(vmetrics[i++]); 34402 if (!Number.isInteger(start)) { 34403 break; 34404 } 34405 const code = xref.fetchIfRef(vmetrics[i]); 34406 if (Array.isArray(code)) { 34407 for (let j = 0, jj = code.length; j < jj; j++) { 34408 const vmetric = [xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j])]; 34409 if (isNumberArray(vmetric, null)) { 34410 glyphsVMetrics[start] = vmetric; 34411 } 34412 start++; 34413 } 34414 } else if (Number.isInteger(code)) { 34415 const vmetric = [xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i])]; 34416 if (!isNumberArray(vmetric, null)) { 34417 continue; 34418 } 34419 for (let j = start; j <= code; j++) { 34420 glyphsVMetrics[j] = vmetric; 34421 } 34422 } else { 34423 break; 34424 } 34425 } 34426 } 34427 } 34428 } else { 34429 const widths = dict.get("Widths"); 34430 if (Array.isArray(widths)) { 34431 let j = properties.firstChar; 34432 for (const w of widths) { 34433 const width = xref.fetchIfRef(w); 34434 if (typeof width === "number") { 34435 glyphsWidths[j] = width; 34436 } 34437 j++; 34438 } 34439 const missingWidth = descriptor.get("MissingWidth"); 34440 defaultWidth = typeof missingWidth === "number" ? missingWidth : 0; 34441 } else { 34442 const baseFontName = dict.get("BaseFont"); 34443 if (baseFontName instanceof Name) { 34444 const metrics = this.getBaseFontMetrics(baseFontName.name); 34445 glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties); 34446 defaultWidth = metrics.defaultWidth; 34447 } 34448 } 34449 } 34450 let isMonospace = true; 34451 let firstWidth = defaultWidth; 34452 for (const glyph in glyphsWidths) { 34453 const glyphWidth = glyphsWidths[glyph]; 34454 if (!glyphWidth) { 34455 continue; 34456 } 34457 if (!firstWidth) { 34458 firstWidth = glyphWidth; 34459 continue; 34460 } 34461 if (firstWidth !== glyphWidth) { 34462 isMonospace = false;
vendor: 46,853 bytes, lines 34463-36042
34463 break; 34464 } 34465 } 34466 if (isMonospace) { 34467 properties.flags |= FontFlags.FixedPitch; 34468 } else { 34469 properties.flags &= ~FontFlags.FixedPitch; 34470 } 34471 properties.defaultWidth = defaultWidth; 34472 properties.widths = glyphsWidths; 34473 properties.defaultVMetrics = defaultVMetrics; 34474 properties.vmetrics = glyphsVMetrics; 34475 } 34476 isSerifFont(baseFontName) { 34477 const fontNameWoStyle = baseFontName.split("-", 1)[0]; 34478 return fontNameWoStyle in getSerifFonts() || /serif/gi.test(fontNameWoStyle); 34479 } 34480 getBaseFontMetrics(name) { 34481 let defaultWidth = 0; 34482 let widths = Object.create(null); 34483 let monospace = false; 34484 const stdFontMap = getStdFontMap(); 34485 let lookupName = stdFontMap[name] || name; 34486 const Metrics = getMetrics(); 34487 if (!(lookupName in Metrics)) { 34488 lookupName = this.isSerifFont(name) ? "Times-Roman" : "Helvetica"; 34489 } 34490 const glyphWidths = Metrics[lookupName]; 34491 if (typeof glyphWidths === "number") { 34492 defaultWidth = glyphWidths; 34493 monospace = true; 34494 } else { 34495 widths = glyphWidths(); 34496 } 34497 return { 34498 defaultWidth, 34499 monospace, 34500 widths 34501 }; 34502 } 34503 buildCharCodeToWidth(widthsByGlyphName, properties) { 34504 const widths = Object.create(null); 34505 const differences = properties.differences; 34506 const encoding = properties.defaultEncoding; 34507 for (let charCode = 0; charCode < 256; charCode++) { 34508 if (charCode in differences && widthsByGlyphName[differences[charCode]]) { 34509 widths[charCode] = widthsByGlyphName[differences[charCode]]; 34510 continue; 34511 } 34512 if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) { 34513 widths[charCode] = widthsByGlyphName[encoding[charCode]]; 34514 continue; 34515 } 34516 } 34517 return widths; 34518 } 34519 preEvaluateFont(dict) { 34520 const baseDict = dict; 34521 let type = dict.get("Subtype"); 34522 if (!(type instanceof Name)) { 34523 throw new FormatError("invalid font Subtype"); 34524 } 34525 let composite = false; 34526 let hash; 34527 if (type.name === "Type0") { 34528 const df = dict.get("DescendantFonts"); 34529 if (!df) { 34530 throw new FormatError("Descendant fonts are not specified"); 34531 } 34532 dict = Array.isArray(df) ? this.xref.fetchIfRef(df[0]) : df; 34533 if (!(dict instanceof Dict)) { 34534 throw new FormatError("Descendant font is not a dictionary."); 34535 } 34536 type = dict.get("Subtype"); 34537 if (!(type instanceof Name)) { 34538 throw new FormatError("invalid font Subtype"); 34539 } 34540 composite = true; 34541 } 34542 let firstChar = dict.get("FirstChar"); 34543 if (!Number.isInteger(firstChar)) { 34544 firstChar = 0; 34545 } 34546 let lastChar = dict.get("LastChar"); 34547 if (!Number.isInteger(lastChar)) { 34548 lastChar = composite ? 0xffff : 0xff; 34549 } 34550 const descriptor = dict.get("FontDescriptor"); 34551 const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode"); 34552 if (descriptor) { 34553 hash = new MurmurHash3_64(); 34554 const encoding = baseDict.getRaw("Encoding"); 34555 if (encoding instanceof Name) { 34556 hash.update(encoding.name); 34557 } else if (encoding instanceof Ref) { 34558 hash.update(encoding.toString()); 34559 } else if (encoding instanceof Dict) { 34560 for (const entry of encoding.getRawValues()) { 34561 if (entry instanceof Name) { 34562 hash.update(entry.name); 34563 } else if (entry instanceof Ref) { 34564 hash.update(entry.toString()); 34565 } else if (Array.isArray(entry)) { 34566 const diffLength = entry.length, 34567 diffBuf = new Array(diffLength); 34568 for (let j = 0; j < diffLength; j++) { 34569 const diffEntry = entry[j]; 34570 if (diffEntry instanceof Name) { 34571 diffBuf[j] = diffEntry.name; 34572 } else if (typeof diffEntry === "number" || diffEntry instanceof Ref) { 34573 diffBuf[j] = diffEntry.toString(); 34574 } 34575 } 34576 hash.update(diffBuf.join()); 34577 } 34578 } 34579 } 34580 hash.update(`${firstChar}-${lastChar}`); 34581 if (toUnicode instanceof BaseStream) { 34582 const stream = toUnicode.str || toUnicode; 34583 const uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start); 34584 hash.update(uint8array); 34585 } else if (toUnicode instanceof Name) { 34586 hash.update(toUnicode.name); 34587 } 34588 const widths = dict.get("Widths") || baseDict.get("Widths"); 34589 if (Array.isArray(widths)) { 34590 const widthsBuf = []; 34591 for (const entry of widths) { 34592 if (typeof entry === "number" || entry instanceof Ref) { 34593 widthsBuf.push(entry.toString()); 34594 } 34595 } 34596 hash.update(widthsBuf.join()); 34597 } 34598 if (composite) { 34599 hash.update("compositeFont"); 34600 const compositeWidths = dict.get("W") || baseDict.get("W"); 34601 if (Array.isArray(compositeWidths)) { 34602 const widthsBuf = []; 34603 for (const entry of compositeWidths) { 34604 if (typeof entry === "number" || entry instanceof Ref) { 34605 widthsBuf.push(entry.toString()); 34606 } else if (Array.isArray(entry)) { 34607 const subWidthsBuf = []; 34608 for (const element of entry) { 34609 if (typeof element === "number" || element instanceof Ref) { 34610 subWidthsBuf.push(element.toString()); 34611 } 34612 } 34613 widthsBuf.push(`[${subWidthsBuf.join()}]`); 34614 } 34615 } 34616 hash.update(widthsBuf.join()); 34617 } 34618 const cidToGidMap = dict.getRaw("CIDToGIDMap") || baseDict.getRaw("CIDToGIDMap"); 34619 if (cidToGidMap instanceof Name) { 34620 hash.update(cidToGidMap.name); 34621 } else if (cidToGidMap instanceof Ref) { 34622 hash.update(cidToGidMap.toString()); 34623 } else if (cidToGidMap instanceof BaseStream) { 34624 hash.update(cidToGidMap.peekBytes()); 34625 } 34626 } 34627 } 34628 return { 34629 descriptor, 34630 dict, 34631 baseDict, 34632 composite, 34633 type: type.name, 34634 firstChar, 34635 lastChar, 34636 toUnicode, 34637 hash: hash ? hash.hexdigest() : "" 34638 }; 34639 } 34640 async translateFont({ 34641 descriptor, 34642 dict, 34643 baseDict, 34644 composite, 34645 type, 34646 firstChar, 34647 lastChar, 34648 toUnicode, 34649 cssFontInfo 34650 }) { 34651 const isType3Font = type === "Type3"; 34652 if (!descriptor) { 34653 if (isType3Font) { 34654 descriptor = Dict.empty; 34655 } else { 34656 let baseFontName = dict.get("BaseFont"); 34657 if (!(baseFontName instanceof Name)) { 34658 throw new FormatError("Base font is not specified"); 34659 } 34660 baseFontName = baseFontName.name.replaceAll(/[,_]/g, "-"); 34661 const metrics = this.getBaseFontMetrics(baseFontName); 34662 const fontNameWoStyle = baseFontName.split("-", 1)[0]; 34663 const flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic); 34664 const properties = { 34665 type, 34666 name: baseFontName, 34667 loadedName: baseDict.loadedName, 34668 systemFontInfo: null, 34669 widths: metrics.widths, 34670 defaultWidth: metrics.defaultWidth, 34671 isSimulatedFlags: true, 34672 flags, 34673 firstChar, 34674 lastChar, 34675 toUnicode, 34676 xHeight: 0, 34677 capHeight: 0, 34678 italicAngle: 0, 34679 isType3Font 34680 }; 34681 const widths = dict.get("Widths"); 34682 const standardFontName = getStandardFontName(baseFontName); 34683 let file = null; 34684 if (standardFontName) { 34685 file = await this.fetchStandardFontData(standardFontName); 34686 properties.isInternalFont = !!file; 34687 } 34688 if (!properties.isInternalFont && this.options.useSystemFonts) { 34689 properties.systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, baseFontName, standardFontName, type); 34690 } 34691 const newProperties = await this.extractDataStructures(dict, properties); 34692 if (Array.isArray(widths)) { 34693 const glyphWidths = []; 34694 let j = firstChar; 34695 for (const w of widths) { 34696 const width = this.xref.fetchIfRef(w); 34697 if (typeof width === "number") { 34698 glyphWidths[j] = width; 34699 } 34700 j++; 34701 } 34702 newProperties.widths = glyphWidths; 34703 } else { 34704 newProperties.widths = this.buildCharCodeToWidth(metrics.widths, newProperties); 34705 } 34706 return new Font(baseFontName, file, newProperties, this.options); 34707 } 34708 } 34709 let fontName = descriptor.get("FontName"); 34710 let baseFont = dict.get("BaseFont"); 34711 if (typeof fontName === "string") { 34712 fontName = Name.get(fontName); 34713 } 34714 if (typeof baseFont === "string") { 34715 baseFont = Name.get(baseFont); 34716 } 34717 const fontNameStr = fontName?.name; 34718 const baseFontStr = baseFont?.name; 34719 if (isType3Font) { 34720 if (!fontNameStr) { 34721 fontName = Name.get(type); 34722 } 34723 } else if (fontNameStr !== baseFontStr) { 34724 info(`The FontDescriptor's FontName is "${fontNameStr}" but ` + `should be the same as the Font's BaseFont "${baseFontStr}".`); 34725 if (fontNameStr && baseFontStr && (baseFontStr.startsWith(fontNameStr) || !isKnownFontName(fontNameStr) && isKnownFontName(baseFontStr))) { 34726 fontName = null; 34727 } 34728 fontName ||= baseFont; 34729 } 34730 if (!(fontName instanceof Name)) { 34731 throw new FormatError("invalid font name"); 34732 } 34733 let fontFile, subtype, length1, length2, length3; 34734 try { 34735 fontFile = descriptor.get("FontFile", "FontFile2", "FontFile3"); 34736 if (fontFile) { 34737 if (!(fontFile instanceof BaseStream)) { 34738 throw new FormatError("FontFile should be a stream"); 34739 } else if (fontFile.isEmpty) { 34740 throw new FormatError("FontFile is empty"); 34741 } 34742 } 34743 } catch (ex) { 34744 if (!this.options.ignoreErrors) { 34745 throw ex; 34746 } 34747 warn(`translateFont - fetching "${fontName.name}" font file: "${ex}".`); 34748 fontFile = null; 34749 } 34750 let isInternalFont = false; 34751 let glyphScaleFactors = null; 34752 let systemFontInfo = null; 34753 if (fontFile) { 34754 if (fontFile.dict) { 34755 const subtypeEntry = fontFile.dict.get("Subtype"); 34756 if (subtypeEntry instanceof Name) { 34757 subtype = subtypeEntry.name; 34758 } 34759 length1 = fontFile.dict.get("Length1"); 34760 length2 = fontFile.dict.get("Length2"); 34761 length3 = fontFile.dict.get("Length3"); 34762 } 34763 } else if (cssFontInfo) { 34764 const standardFontName = getXfaFontName(fontName.name); 34765 if (standardFontName) { 34766 cssFontInfo.fontFamily = `${cssFontInfo.fontFamily}-PdfJS-XFA`; 34767 cssFontInfo.metrics = standardFontName.metrics || null; 34768 glyphScaleFactors = standardFontName.factors || null; 34769 fontFile = await this.fetchStandardFontData(standardFontName.name); 34770 isInternalFont = !!fontFile; 34771 baseDict = dict = getXfaFontDict(fontName.name); 34772 composite = true; 34773 } 34774 } else if (!isType3Font) { 34775 const standardFontName = getStandardFontName(fontName.name); 34776 if (standardFontName) { 34777 fontFile = await this.fetchStandardFontData(standardFontName); 34778 isInternalFont = !!fontFile; 34779 } 34780 if (!isInternalFont && this.options.useSystemFonts) { 34781 systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName, type); 34782 } 34783 } 34784 const fontMatrix = lookupMatrix(dict.getArray("FontMatrix"), FONT_IDENTITY_MATRIX); 34785 const bbox = lookupNormalRect(descriptor.getArray("FontBBox") || dict.getArray("FontBBox"), isType3Font ? [0, 0, 0, 0] : undefined); 34786 let ascent = descriptor.get("Ascent"); 34787 if (typeof ascent !== "number") { 34788 ascent = undefined; 34789 } 34790 let descent = descriptor.get("Descent"); 34791 if (typeof descent !== "number") { 34792 descent = undefined; 34793 } 34794 let xHeight = descriptor.get("XHeight"); 34795 if (typeof xHeight !== "number") { 34796 xHeight = 0; 34797 } 34798 let capHeight = descriptor.get("CapHeight"); 34799 if (typeof capHeight !== "number") { 34800 capHeight = 0; 34801 } 34802 let flags = descriptor.get("Flags"); 34803 if (!Number.isInteger(flags)) { 34804 flags = 0; 34805 } 34806 let italicAngle = descriptor.get("ItalicAngle"); 34807 if (typeof italicAngle !== "number") { 34808 italicAngle = 0; 34809 } 34810 const properties = { 34811 type, 34812 name: fontName.name, 34813 subtype, 34814 file: fontFile, 34815 length1, 34816 length2, 34817 length3, 34818 isInternalFont, 34819 loadedName: baseDict.loadedName, 34820 composite, 34821 fixedPitch: false, 34822 fontMatrix, 34823 firstChar, 34824 lastChar, 34825 toUnicode, 34826 bbox, 34827 ascent, 34828 descent, 34829 xHeight, 34830 capHeight, 34831 flags, 34832 italicAngle, 34833 isType3Font, 34834 cssFontInfo, 34835 scaleFactors: glyphScaleFactors, 34836 systemFontInfo 34837 }; 34838 if (composite) { 34839 const cidEncoding = baseDict.get("Encoding"); 34840 if (cidEncoding instanceof Name) { 34841 properties.cidEncoding = cidEncoding.name; 34842 } 34843 const cMap = await CMapFactory.create({ 34844 encoding: cidEncoding, 34845 fetchBuiltInCMap: this._fetchBuiltInCMapBound, 34846 useCMap: null 34847 }); 34848 properties.cMap = cMap; 34849 properties.vertical = properties.cMap.vertical; 34850 } 34851 const newProperties = await this.extractDataStructures(dict, properties); 34852 this.extractWidths(dict, descriptor, newProperties); 34853 return new Font(fontName.name, fontFile, newProperties, this.options); 34854 } 34855 static buildFontPaths(font, glyphs, handler, evaluatorOptions) { 34856 function buildPath(fontChar) { 34857 const glyphName = `${font.loadedName}_path_${fontChar}`; 34858 try { 34859 if (font.renderer.hasBuiltPath(fontChar)) { 34860 return; 34861 } 34862 handler.send("commonobj", [glyphName, "FontPath", font.renderer.getPathJs(fontChar)]); 34863 } catch (reason) { 34864 if (evaluatorOptions.ignoreErrors) { 34865 warn(`buildFontPaths - ignoring ${glyphName} glyph: "${reason}".`); 34866 return; 34867 } 34868 throw reason; 34869 } 34870 } 34871 for (const glyph of glyphs) { 34872 buildPath(glyph.fontChar); 34873 const accent = glyph.accent; 34874 if (accent?.fontChar) { 34875 buildPath(accent.fontChar); 34876 } 34877 } 34878 } 34879 static get fallbackFontDict() { 34880 const dict = new Dict(); 34881 dict.set("BaseFont", Name.get("Helvetica")); 34882 dict.set("Type", Name.get("FallbackType")); 34883 dict.set("Subtype", Name.get("FallbackType")); 34884 dict.set("Encoding", Name.get("WinAnsiEncoding")); 34885 return shadow(this, "fallbackFontDict", dict); 34886 } 34887} 34888class TranslatedFont { 34889 #sent = false; 34890 #type3Loaded = null; 34891 constructor({ 34892 loadedName, 34893 font, 34894 dict 34895 }) { 34896 this.loadedName = loadedName; 34897 this.font = font; 34898 this.dict = dict; 34899 this.type3Dependencies = font.isType3Font ? new Set() : null; 34900 } 34901 send(handler) { 34902 if (this.#sent) { 34903 return; 34904 } 34905 this.#sent = true; 34906 const fontData = this.font.exportData(); 34907 const transfer = []; 34908 if (fontData.data) { 34909 if (fontData.data.charProcOperatorList) { 34910 fontData.charProcOperatorList = fontData.data.charProcOperatorList; 34911 } 34912 fontData.data = FontInfo.write(fontData.data); 34913 transfer.push(fontData.data); 34914 } 34915 handler.send("commonobj", [this.loadedName, "Font", fontData], transfer); 34916 } 34917 fallback(handler, evaluatorOptions) { 34918 if (!this.font.data) { 34919 return; 34920 } 34921 this.font.disableFontFace = true; 34922 PartialEvaluator.buildFontPaths(this.font, this.font.glyphCacheValues, handler, evaluatorOptions); 34923 } 34924 loadType3Data(evaluator, resources, task) { 34925 if (this.#type3Loaded) { 34926 return this.#type3Loaded; 34927 } 34928 const { 34929 font, 34930 type3Dependencies 34931 } = this; 34932 assert(font.isType3Font, "Must be a Type3 font."); 34933 const type3Evaluator = evaluator.clone({ 34934 ignoreErrors: false 34935 }); 34936 const type3FontRefs = new RefSet(evaluator.type3FontRefs); 34937 if (this.dict.objId && !type3FontRefs.has(this.dict.objId)) { 34938 type3FontRefs.put(this.dict.objId); 34939 } 34940 type3Evaluator.type3FontRefs = type3FontRefs; 34941 let loadCharProcsPromise = Promise.resolve(); 34942 const charProcs = this.dict.get("CharProcs"); 34943 const fontResources = this.dict.get("Resources") || resources; 34944 const charProcOperatorList = Object.create(null); 34945 const [x0, y0, x1, y1] = font.bbox, 34946 width = x1 - x0, 34947 height = y1 - y0; 34948 const fontBBoxSize = Math.hypot(width, height); 34949 for (const key of charProcs.getKeys()) { 34950 loadCharProcsPromise = loadCharProcsPromise.then(() => { 34951 const glyphStream = charProcs.get(key); 34952 const operatorList = new OperatorList(); 34953 return type3Evaluator.getOperatorList({ 34954 stream: glyphStream, 34955 task, 34956 resources: fontResources, 34957 operatorList 34958 }).then(() => { 34959 switch (operatorList.fnArray[0]) { 34960 case OPS.setCharWidthAndBounds: 34961 this.#removeType3ColorOperators(operatorList, fontBBoxSize); 34962 break; 34963 case OPS.setCharWidth: 34964 if (!fontBBoxSize) { 34965 this.#guessType3FontBBox(operatorList); 34966 } 34967 break; 34968 } 34969 charProcOperatorList[key] = operatorList.getIR(); 34970 for (const dependency of operatorList.dependencies) { 34971 type3Dependencies.add(dependency); 34972 } 34973 }).catch(function (reason) { 34974 warn(`Type3 font resource "${key}" is not available.`); 34975 const dummyOperatorList = new OperatorList(); 34976 charProcOperatorList[key] = dummyOperatorList.getIR(); 34977 }); 34978 }); 34979 } 34980 this.#type3Loaded = loadCharProcsPromise.then(() => { 34981 font.charProcOperatorList = charProcOperatorList; 34982 if (this._bbox) { 34983 font.isCharBBox = true; 34984 font.bbox = this._bbox; 34985 } 34986 }); 34987 return this.#type3Loaded; 34988 } 34989 #removeType3ColorOperators(operatorList, fontBBoxSize = NaN) { 34990 const charBBox = Util.normalizeRect(operatorList.argsArray[0].slice(2)), 34991 width = charBBox[2] - charBBox[0], 34992 height = charBBox[3] - charBBox[1]; 34993 const charBBoxSize = Math.hypot(width, height); 34994 if (width === 0 || height === 0) { 34995 operatorList.fnArray.splice(0, 1); 34996 operatorList.argsArray.splice(0, 1); 34997 } else if (fontBBoxSize === 0 || Math.round(charBBoxSize / fontBBoxSize) >= 10) { 34998 this._bbox ??= [Infinity, Infinity, -Infinity, -Infinity]; 34999 Util.rectBoundingBox(...charBBox, this._bbox); 35000 } 35001 let i = 0, 35002 ii = operatorList.length; 35003 while (i < ii) { 35004 switch (operatorList.fnArray[i]) { 35005 case OPS.setCharWidthAndBounds: 35006 break; 35007 case OPS.setStrokeColorSpace: 35008 case OPS.setFillColorSpace: 35009 case OPS.setStrokeColor: 35010 case OPS.setStrokeColorN: 35011 case OPS.setFillColor: 35012 case OPS.setFillColorN: 35013 case OPS.setStrokeGray: 35014 case OPS.setFillGray: 35015 case OPS.setStrokeRGBColor: 35016 case OPS.setFillRGBColor: 35017 case OPS.setStrokeCMYKColor: 35018 case OPS.setFillCMYKColor: 35019 case OPS.shadingFill: 35020 case OPS.setRenderingIntent: 35021 operatorList.fnArray.splice(i, 1); 35022 operatorList.argsArray.splice(i, 1); 35023 ii--; 35024 continue; 35025 case OPS.setGState: 35026 const [gStateObj] = operatorList.argsArray[i]; 35027 let j = 0, 35028 jj = gStateObj.length; 35029 while (j < jj) { 35030 const [gStateKey] = gStateObj[j]; 35031 switch (gStateKey) { 35032 case "TR": 35033 case "TR2": 35034 case "HT": 35035 case "BG": 35036 case "BG2": 35037 case "UCR": 35038 case "UCR2": 35039 gStateObj.splice(j, 1); 35040 jj--; 35041 continue; 35042 } 35043 j++; 35044 } 35045 break; 35046 } 35047 i++; 35048 } 35049 } 35050 #guessType3FontBBox(operatorList) { 35051 let i = 1; 35052 const ii = operatorList.length; 35053 while (i < ii) { 35054 switch (operatorList.fnArray[i]) { 35055 case OPS.constructPath: 35056 const minMax = operatorList.argsArray[i][2]; 35057 this._bbox ??= [Infinity, Infinity, -Infinity, -Infinity]; 35058 Util.rectBoundingBox(...minMax, this._bbox); 35059 break; 35060 } 35061 i++; 35062 } 35063 } 35064} 35065class StateManager { 35066 constructor(initialState = new EvalState()) { 35067 this.state = initialState; 35068 this.stateStack = []; 35069 } 35070 save() { 35071 const old = this.state; 35072 this.stateStack.push(this.state); 35073 this.state = old.clone(); 35074 } 35075 restore() { 35076 const prev = this.stateStack.pop(); 35077 if (prev) { 35078 this.state = prev; 35079 } 35080 } 35081 transform(args) { 35082 this.state.ctm = Util.transform(this.state.ctm, args); 35083 } 35084} 35085class TextState { 35086 constructor() { 35087 this.ctm = new Float32Array(IDENTITY_MATRIX); 35088 this.fontName = null; 35089 this.fontSize = 0; 35090 this.loadedName = null; 35091 this.font = null; 35092 this.fontMatrix = FONT_IDENTITY_MATRIX; 35093 this.textMatrix = IDENTITY_MATRIX.slice(); 35094 this.textLineMatrix = IDENTITY_MATRIX.slice(); 35095 this.charSpacing = 0; 35096 this.wordSpacing = 0; 35097 this.leading = 0; 35098 this.textHScale = 1; 35099 this.textRise = 0; 35100 } 35101 setTextMatrix(a, b, c, d, e, f) { 35102 const m = this.textMatrix; 35103 m[0] = a; 35104 m[1] = b; 35105 m[2] = c; 35106 m[3] = d; 35107 m[4] = e; 35108 m[5] = f; 35109 } 35110 setTextLineMatrix(a, b, c, d, e, f) { 35111 const m = this.textLineMatrix; 35112 m[0] = a; 35113 m[1] = b; 35114 m[2] = c; 35115 m[3] = d; 35116 m[4] = e; 35117 m[5] = f; 35118 } 35119 translateTextMatrix(x, y) { 35120 const m = this.textMatrix; 35121 m[4] = m[0] * x + m[2] * y + m[4]; 35122 m[5] = m[1] * x + m[3] * y + m[5]; 35123 } 35124 translateTextLineMatrix(x, y) { 35125 const m = this.textLineMatrix; 35126 m[4] = m[0] * x + m[2] * y + m[4]; 35127 m[5] = m[1] * x + m[3] * y + m[5]; 35128 } 35129 carriageReturn() { 35130 this.translateTextLineMatrix(0, -this.leading); 35131 this.textMatrix = this.textLineMatrix.slice(); 35132 } 35133 clone() { 35134 const clone = Object.create(this); 35135 clone.textMatrix = this.textMatrix.slice(); 35136 clone.textLineMatrix = this.textLineMatrix.slice(); 35137 clone.fontMatrix = this.fontMatrix.slice(); 35138 return clone; 35139 } 35140} 35141class EvalState { 35142 constructor() { 35143 this.ctm = new Float32Array(IDENTITY_MATRIX); 35144 this.font = null; 35145 this.textRenderingMode = TextRenderingMode.FILL; 35146 this._fillColorSpace = this._strokeColorSpace = ColorSpaceUtils.gray; 35147 this.patternFillColorSpace = null; 35148 this.patternStrokeColorSpace = null; 35149 this.currentPointX = this.currentPointY = 0; 35150 this.pathMinMax = new Float32Array([Infinity, Infinity, -Infinity, -Infinity]); 35151 this.pathBuffer = []; 35152 } 35153 get fillColorSpace() { 35154 return this._fillColorSpace; 35155 } 35156 set fillColorSpace(colorSpace) { 35157 this._fillColorSpace = this.patternFillColorSpace = colorSpace; 35158 } 35159 get strokeColorSpace() { 35160 return this._strokeColorSpace; 35161 } 35162 set strokeColorSpace(colorSpace) { 35163 this._strokeColorSpace = this.patternStrokeColorSpace = colorSpace; 35164 } 35165 clone({ 35166 newPath = false 35167 } = {}) { 35168 const clone = Object.create(this); 35169 if (newPath) { 35170 clone.pathBuffer = []; 35171 clone.pathMinMax = new Float32Array([Infinity, Infinity, -Infinity, -Infinity]); 35172 } 35173 return clone; 35174 } 35175} 35176class EvaluatorPreprocessor { 35177 static get opMap() { 35178 return shadow(this, "opMap", Object.assign(Object.create(null), { 35179 w: { 35180 id: OPS.setLineWidth, 35181 numArgs: 1, 35182 variableArgs: false 35183 }, 35184 J: { 35185 id: OPS.setLineCap, 35186 numArgs: 1, 35187 variableArgs: false 35188 }, 35189 j: { 35190 id: OPS.setLineJoin, 35191 numArgs: 1, 35192 variableArgs: false 35193 }, 35194 M: { 35195 id: OPS.setMiterLimit, 35196 numArgs: 1, 35197 variableArgs: false 35198 }, 35199 d: { 35200 id: OPS.setDash, 35201 numArgs: 2, 35202 variableArgs: false 35203 }, 35204 ri: { 35205 id: OPS.setRenderingIntent, 35206 numArgs: 1, 35207 variableArgs: false 35208 }, 35209 i: { 35210 id: OPS.setFlatness, 35211 numArgs: 1, 35212 variableArgs: false 35213 }, 35214 gs: { 35215 id: OPS.setGState, 35216 numArgs: 1, 35217 variableArgs: false 35218 }, 35219 q: { 35220 id: OPS.save, 35221 numArgs: 0, 35222 variableArgs: false 35223 }, 35224 Q: { 35225 id: OPS.restore, 35226 numArgs: 0, 35227 variableArgs: false 35228 }, 35229 cm: { 35230 id: OPS.transform, 35231 numArgs: 6, 35232 variableArgs: false 35233 }, 35234 m: { 35235 id: OPS.moveTo, 35236 numArgs: 2, 35237 variableArgs: false 35238 }, 35239 l: { 35240 id: OPS.lineTo, 35241 numArgs: 2, 35242 variableArgs: false 35243 }, 35244 c: { 35245 id: OPS.curveTo, 35246 numArgs: 6, 35247 variableArgs: false 35248 }, 35249 v: { 35250 id: OPS.curveTo2, 35251 numArgs: 4, 35252 variableArgs: false 35253 }, 35254 y: { 35255 id: OPS.curveTo3, 35256 numArgs: 4, 35257 variableArgs: false 35258 }, 35259 h: { 35260 id: OPS.closePath, 35261 numArgs: 0, 35262 variableArgs: false 35263 }, 35264 re: { 35265 id: OPS.rectangle, 35266 numArgs: 4, 35267 variableArgs: false 35268 }, 35269 S: { 35270 id: OPS.stroke, 35271 numArgs: 0, 35272 variableArgs: false 35273 }, 35274 s: { 35275 id: OPS.closeStroke, 35276 numArgs: 0, 35277 variableArgs: false 35278 }, 35279 f: { 35280 id: OPS.fill, 35281 numArgs: 0, 35282 variableArgs: false 35283 }, 35284 F: { 35285 id: OPS.fill, 35286 numArgs: 0, 35287 variableArgs: false 35288 }, 35289 "f*": { 35290 id: OPS.eoFill, 35291 numArgs: 0, 35292 variableArgs: false 35293 }, 35294 B: { 35295 id: OPS.fillStroke, 35296 numArgs: 0, 35297 variableArgs: false 35298 }, 35299 "B*": { 35300 id: OPS.eoFillStroke, 35301 numArgs: 0, 35302 variableArgs: false 35303 }, 35304 b: { 35305 id: OPS.closeFillStroke, 35306 numArgs: 0, 35307 variableArgs: false 35308 }, 35309 "b*": { 35310 id: OPS.closeEOFillStroke, 35311 numArgs: 0, 35312 variableArgs: false 35313 }, 35314 n: { 35315 id: OPS.endPath, 35316 numArgs: 0, 35317 variableArgs: false 35318 }, 35319 W: { 35320 id: OPS.clip, 35321 numArgs: 0, 35322 variableArgs: false 35323 }, 35324 "W*": { 35325 id: OPS.eoClip, 35326 numArgs: 0, 35327 variableArgs: false 35328 }, 35329 BT: { 35330 id: OPS.beginText, 35331 numArgs: 0, 35332 variableArgs: false 35333 }, 35334 ET: { 35335 id: OPS.endText, 35336 numArgs: 0, 35337 variableArgs: false 35338 }, 35339 Tc: { 35340 id: OPS.setCharSpacing, 35341 numArgs: 1, 35342 variableArgs: false 35343 }, 35344 Tw: { 35345 id: OPS.setWordSpacing, 35346 numArgs: 1, 35347 variableArgs: false 35348 }, 35349 Tz: { 35350 id: OPS.setHScale, 35351 numArgs: 1, 35352 variableArgs: false 35353 }, 35354 TL: { 35355 id: OPS.setLeading, 35356 numArgs: 1, 35357 variableArgs: false 35358 }, 35359 Tf: { 35360 id: OPS.setFont, 35361 numArgs: 2, 35362 variableArgs: false 35363 }, 35364 Tr: { 35365 id: OPS.setTextRenderingMode, 35366 numArgs: 1, 35367 variableArgs: false 35368 }, 35369 Ts: { 35370 id: OPS.setTextRise, 35371 numArgs: 1, 35372 variableArgs: false 35373 }, 35374 Td: { 35375 id: OPS.moveText, 35376 numArgs: 2, 35377 variableArgs: false 35378 }, 35379 TD: { 35380 id: OPS.setLeadingMoveText, 35381 numArgs: 2, 35382 variableArgs: false 35383 }, 35384 Tm: { 35385 id: OPS.setTextMatrix, 35386 numArgs: 6, 35387 variableArgs: false 35388 }, 35389 "T*": { 35390 id: OPS.nextLine, 35391 numArgs: 0, 35392 variableArgs: false 35393 }, 35394 Tj: { 35395 id: OPS.showText, 35396 numArgs: 1, 35397 variableArgs: false 35398 }, 35399 TJ: { 35400 id: OPS.showSpacedText, 35401 numArgs: 1, 35402 variableArgs: false 35403 }, 35404 "'": { 35405 id: OPS.nextLineShowText, 35406 numArgs: 1, 35407 variableArgs: false 35408 }, 35409 '"': { 35410 id: OPS.nextLineSetSpacingShowText, 35411 numArgs: 3, 35412 variableArgs: false 35413 }, 35414 d0: { 35415 id: OPS.setCharWidth, 35416 numArgs: 2, 35417 variableArgs: false 35418 }, 35419 d1: { 35420 id: OPS.setCharWidthAndBounds, 35421 numArgs: 6, 35422 variableArgs: false 35423 }, 35424 CS: { 35425 id: OPS.setStrokeColorSpace, 35426 numArgs: 1, 35427 variableArgs: false 35428 }, 35429 cs: { 35430 id: OPS.setFillColorSpace, 35431 numArgs: 1, 35432 variableArgs: false 35433 }, 35434 SC: { 35435 id: OPS.setStrokeColor, 35436 numArgs: 4, 35437 variableArgs: true 35438 }, 35439 SCN: { 35440 id: OPS.setStrokeColorN, 35441 numArgs: 33, 35442 variableArgs: true 35443 }, 35444 sc: { 35445 id: OPS.setFillColor, 35446 numArgs: 4, 35447 variableArgs: true 35448 }, 35449 scn: { 35450 id: OPS.setFillColorN, 35451 numArgs: 33, 35452 variableArgs: true 35453 }, 35454 G: { 35455 id: OPS.setStrokeGray, 35456 numArgs: 1, 35457 variableArgs: false 35458 }, 35459 g: { 35460 id: OPS.setFillGray, 35461 numArgs: 1, 35462 variableArgs: false 35463 }, 35464 RG: { 35465 id: OPS.setStrokeRGBColor, 35466 numArgs: 3, 35467 variableArgs: false 35468 }, 35469 rg: { 35470 id: OPS.setFillRGBColor, 35471 numArgs: 3, 35472 variableArgs: false 35473 }, 35474 K: { 35475 id: OPS.setStrokeCMYKColor, 35476 numArgs: 4, 35477 variableArgs: false 35478 }, 35479 k: { 35480 id: OPS.setFillCMYKColor, 35481 numArgs: 4, 35482 variableArgs: false 35483 }, 35484 sh: { 35485 id: OPS.shadingFill, 35486 numArgs: 1, 35487 variableArgs: false 35488 }, 35489 BI: { 35490 id: OPS.beginInlineImage, 35491 numArgs: 0, 35492 variableArgs: false 35493 }, 35494 ID: { 35495 id: OPS.beginImageData, 35496 numArgs: 0, 35497 variableArgs: false 35498 }, 35499 EI: { 35500 id: OPS.endInlineImage, 35501 numArgs: 1, 35502 variableArgs: false 35503 }, 35504 Do: { 35505 id: OPS.paintXObject, 35506 numArgs: 1, 35507 variableArgs: false 35508 }, 35509 MP: { 35510 id: OPS.markPoint, 35511 numArgs: 1, 35512 variableArgs: false 35513 }, 35514 DP: { 35515 id: OPS.markPointProps, 35516 numArgs: 2, 35517 variableArgs: false 35518 }, 35519 BMC: { 35520 id: OPS.beginMarkedContent, 35521 numArgs: 1, 35522 variableArgs: false 35523 }, 35524 BDC: { 35525 id: OPS.beginMarkedContentProps, 35526 numArgs: 2, 35527 variableArgs: false 35528 }, 35529 EMC: { 35530 id: OPS.endMarkedContent, 35531 numArgs: 0, 35532 variableArgs: false 35533 }, 35534 BX: { 35535 id: OPS.beginCompat, 35536 numArgs: 0, 35537 variableArgs: false 35538 }, 35539 EX: { 35540 id: OPS.endCompat, 35541 numArgs: 0, 35542 variableArgs: false 35543 }, 35544 BM: null, 35545 BD: null, 35546 true: null, 35547 fa: null, 35548 fal: null, 35549 fals: null, 35550 false: null, 35551 nu: null, 35552 nul: null, 35553 null: null 35554 })); 35555 } 35556 static MAX_INVALID_PATH_OPS = 10; 35557 constructor(stream, xref, stateManager = new StateManager()) { 35558 this.parser = new Parser({ 35559 lexer: new Lexer(stream, EvaluatorPreprocessor.opMap), 35560 xref 35561 }); 35562 this.stateManager = stateManager; 35563 this.nonProcessedArgs = []; 35564 this._isPathOp = false; 35565 this._numInvalidPathOPS = 0; 35566 } 35567 get savedStatesDepth() { 35568 return this.stateManager.stateStack.length; 35569 } 35570 read(operation) { 35571 let args = operation.args; 35572 while (true) { 35573 const obj = this.parser.getObj(); 35574 if (obj instanceof Cmd) { 35575 const cmd = obj.cmd; 35576 const opSpec = EvaluatorPreprocessor.opMap[cmd]; 35577 if (!opSpec) { 35578 warn(`Unknown command "${cmd}".`); 35579 continue; 35580 } 35581 const fn = opSpec.id; 35582 const numArgs = opSpec.numArgs; 35583 let argsLength = args !== null ? args.length : 0; 35584 if (!this._isPathOp) { 35585 this._numInvalidPathOPS = 0; 35586 } 35587 this._isPathOp = fn >= OPS.moveTo && fn <= OPS.endPath; 35588 if (!opSpec.variableArgs) { 35589 if (argsLength !== numArgs) { 35590 const nonProcessedArgs = this.nonProcessedArgs; 35591 while (argsLength > numArgs) { 35592 nonProcessedArgs.push(args.shift()); 35593 argsLength--; 35594 } 35595 while (argsLength < numArgs && nonProcessedArgs.length !== 0) { 35596 if (args === null) { 35597 args = []; 35598 } 35599 args.unshift(nonProcessedArgs.pop()); 35600 argsLength++; 35601 } 35602 } 35603 if (argsLength < numArgs) { 35604 const partialMsg = `command ${cmd}: expected ${numArgs} args, ` + `but received ${argsLength} args.`; 35605 if (this._isPathOp && ++this._numInvalidPathOPS > EvaluatorPreprocessor.MAX_INVALID_PATH_OPS) { 35606 throw new FormatError(`Invalid ${partialMsg}`); 35607 } 35608 warn(`Skipping ${partialMsg}`); 35609 if (args !== null) { 35610 args.length = 0; 35611 } 35612 continue; 35613 } 35614 } else if (argsLength > numArgs) { 35615 info(`Command ${cmd}: expected [0, ${numArgs}] args, ` + `but received ${argsLength} args.`); 35616 } 35617 this.preprocessCommand(fn, args); 35618 operation.fn = fn; 35619 operation.args = args; 35620 return true; 35621 } 35622 if (obj === EOF) { 35623 return false; 35624 } 35625 if (obj !== null) { 35626 if (args === null) { 35627 args = []; 35628 } 35629 args.push(obj); 35630 if (args.length > 33) { 35631 throw new FormatError("Too many arguments"); 35632 } 35633 } 35634 } 35635 } 35636 preprocessCommand(fn, args) { 35637 switch (fn | 0) { 35638 case OPS.save: 35639 this.stateManager.save(); 35640 break; 35641 case OPS.restore: 35642 this.stateManager.restore(); 35643 break; 35644 case OPS.transform: 35645 this.stateManager.transform(args); 35646 break; 35647 } 35648 } 35649} 35650 35651;// ./src/core/default_appearance.js 35652 35653 35654 35655 35656 35657 35658 35659 35660class DefaultAppearanceEvaluator extends EvaluatorPreprocessor { 35661 constructor(str) { 35662 super(new StringStream(str)); 35663 } 35664 parse() { 35665 const operation = { 35666 fn: 0, 35667 args: [] 35668 }; 35669 const result = { 35670 fontSize: 0, 35671 fontName: "", 35672 fontColor: new Uint8ClampedArray(3) 35673 }; 35674 try { 35675 while (true) { 35676 operation.args.length = 0; 35677 if (!this.read(operation)) { 35678 break; 35679 } 35680 if (this.savedStatesDepth !== 0) { 35681 continue; 35682 } 35683 const { 35684 fn, 35685 args 35686 } = operation; 35687 switch (fn | 0) { 35688 case OPS.setFont: 35689 const [fontName, fontSize] = args; 35690 if (fontName instanceof Name) { 35691 result.fontName = fontName.name; 35692 } 35693 if (typeof fontSize === "number" && fontSize > 0) { 35694 result.fontSize = fontSize; 35695 } 35696 break; 35697 case OPS.setFillRGBColor: 35698 ColorSpaceUtils.rgb.getRgbItem(args, 0, result.fontColor, 0); 35699 break; 35700 case OPS.setFillGray: 35701 ColorSpaceUtils.gray.getRgbItem(args, 0, result.fontColor, 0); 35702 break; 35703 case OPS.setFillCMYKColor: 35704 ColorSpaceUtils.cmyk.getRgbItem(args, 0, result.fontColor, 0); 35705 break; 35706 } 35707 } 35708 } catch (reason) { 35709 warn(`parseDefaultAppearance - ignoring errors: "${reason}".`); 35710 } 35711 return result; 35712 } 35713} 35714function parseDefaultAppearance(str) { 35715 return new DefaultAppearanceEvaluator(str).parse(); 35716} 35717class AppearanceStreamEvaluator extends EvaluatorPreprocessor { 35718 constructor(stream, evaluatorOptions, xref, globalColorSpaceCache) { 35719 super(stream); 35720 this.stream = stream; 35721 this.evaluatorOptions = evaluatorOptions; 35722 this.xref = xref; 35723 this.globalColorSpaceCache = globalColorSpaceCache; 35724 this.resources = stream.dict?.get("Resources"); 35725 } 35726 parse() { 35727 const operation = { 35728 fn: 0, 35729 args: [] 35730 }; 35731 let result = { 35732 scaleFactor: 1, 35733 fontSize: 0, 35734 fontName: "", 35735 fontColor: new Uint8ClampedArray(3), 35736 fillColorSpace: ColorSpaceUtils.gray 35737 }; 35738 let breakLoop = false; 35739 const stack = []; 35740 try { 35741 while (true) { 35742 operation.args.length = 0; 35743 if (breakLoop || !this.read(operation)) { 35744 break; 35745 } 35746 const { 35747 fn, 35748 args 35749 } = operation; 35750 switch (fn | 0) { 35751 case OPS.save: 35752 stack.push({ 35753 scaleFactor: result.scaleFactor, 35754 fontSize: result.fontSize, 35755 fontName: result.fontName, 35756 fontColor: result.fontColor.slice(), 35757 fillColorSpace: result.fillColorSpace 35758 }); 35759 break; 35760 case OPS.restore: 35761 result = stack.pop() || result; 35762 break; 35763 case OPS.setTextMatrix: 35764 result.scaleFactor *= Math.hypot(args[0], args[1]); 35765 break; 35766 case OPS.setFont: 35767 const [fontName, fontSize] = args; 35768 if (fontName instanceof Name) { 35769 result.fontName = fontName.name; 35770 } 35771 if (typeof fontSize === "number" && fontSize > 0) { 35772 result.fontSize = fontSize * result.scaleFactor; 35773 } 35774 break; 35775 case OPS.setFillColorSpace: 35776 result.fillColorSpace = ColorSpaceUtils.parse({ 35777 cs: args[0], 35778 xref: this.xref, 35779 resources: this.resources, 35780 pdfFunctionFactory: this._pdfFunctionFactory, 35781 globalColorSpaceCache: this.globalColorSpaceCache, 35782 localColorSpaceCache: this._localColorSpaceCache 35783 }); 35784 break; 35785 case OPS.setFillColor: 35786 const cs = result.fillColorSpace; 35787 cs.getRgbItem(args, 0, result.fontColor, 0); 35788 break; 35789 case OPS.setFillRGBColor: 35790 ColorSpaceUtils.rgb.getRgbItem(args, 0, result.fontColor, 0); 35791 break; 35792 case OPS.setFillGray: 35793 ColorSpaceUtils.gray.getRgbItem(args, 0, result.fontColor, 0); 35794 break; 35795 case OPS.setFillCMYKColor: 35796 ColorSpaceUtils.cmyk.getRgbItem(args, 0, result.fontColor, 0); 35797 break; 35798 case OPS.showText: 35799 case OPS.showSpacedText: 35800 case OPS.nextLineShowText: 35801 case OPS.nextLineSetSpacingShowText: 35802 breakLoop = true; 35803 break; 35804 } 35805 } 35806 } catch (reason) { 35807 warn(`parseAppearanceStream - ignoring errors: "${reason}".`); 35808 } 35809 this.stream.reset(); 35810 delete result.scaleFactor; 35811 delete result.fillColorSpace; 35812 return result; 35813 } 35814 get _localColorSpaceCache() { 35815 return shadow(this, "_localColorSpaceCache", new LocalColorSpaceCache()); 35816 } 35817 get _pdfFunctionFactory() { 35818 const pdfFunctionFactory = new PDFFunctionFactory({ 35819 xref: this.xref, 35820 isEvalSupported: this.evaluatorOptions.isEvalSupported 35821 }); 35822 return shadow(this, "_pdfFunctionFactory", pdfFunctionFactory); 35823 } 35824} 35825function parseAppearanceStream(stream, evaluatorOptions, xref, globalColorSpaceCache) { 35826 return new AppearanceStreamEvaluator(stream, evaluatorOptions, xref, globalColorSpaceCache).parse(); 35827} 35828function getPdfColor(color, isFill) { 35829 if (color[0] === color[1] && color[1] === color[2]) { 35830 const gray = color[0] / 255; 35831 return `${numberToString(gray)} ${isFill ? "g" : "G"}`; 35832 } 35833 return Array.from(color, c => numberToString(c / 255)).join(" ") + ` ${isFill ? "rg" : "RG"}`; 35834} 35835function createDefaultAppearance({ 35836 fontSize, 35837 fontName, 35838 fontColor 35839}) { 35840 return `/${escapePDFName(fontName)} ${fontSize} Tf ${getPdfColor(fontColor, true)}`; 35841} 35842class FakeUnicodeFont { 35843 constructor(xref, fontFamily) { 35844 this.xref = xref; 35845 this.widths = null; 35846 this.firstChar = Infinity; 35847 this.lastChar = -Infinity; 35848 this.fontFamily = fontFamily; 35849 const canvas = new OffscreenCanvas(1, 1); 35850 this.ctxMeasure = canvas.getContext("2d", { 35851 willReadFrequently: true 35852 }); 35853 if (!FakeUnicodeFont._fontNameId) { 35854 FakeUnicodeFont._fontNameId = 1; 35855 } 35856 this.fontName = Name.get(`InvalidPDFjsFont_${fontFamily}_${FakeUnicodeFont._fontNameId++}`); 35857 } 35858 get fontDescriptorRef() { 35859 if (!FakeUnicodeFont._fontDescriptorRef) { 35860 const fontDescriptor = new Dict(this.xref); 35861 fontDescriptor.setIfName("Type", "FontDescriptor"); 35862 fontDescriptor.set("FontName", this.fontName); 35863 fontDescriptor.set("FontFamily", "MyriadPro Regular"); 35864 fontDescriptor.set("FontBBox", [0, 0, 0, 0]); 35865 fontDescriptor.setIfName("FontStretch", "Normal"); 35866 fontDescriptor.set("FontWeight", 400); 35867 fontDescriptor.set("ItalicAngle", 0); 35868 FakeUnicodeFont._fontDescriptorRef = this.xref.getNewPersistentRef(fontDescriptor); 35869 } 35870 return FakeUnicodeFont._fontDescriptorRef; 35871 } 35872 get descendantFontRef() { 35873 const descendantFont = new Dict(this.xref); 35874 descendantFont.set("BaseFont", this.fontName); 35875 descendantFont.setIfName("Type", "Font"); 35876 descendantFont.setIfName("Subtype", "CIDFontType0"); 35877 descendantFont.setIfName("CIDToGIDMap", "Identity"); 35878 descendantFont.set("FirstChar", this.firstChar); 35879 descendantFont.set("LastChar", this.lastChar); 35880 descendantFont.set("FontDescriptor", this.fontDescriptorRef); 35881 descendantFont.set("DW", 1000); 35882 const widths = []; 35883 const chars = [...this.widths.entries()].sort(); 35884 let currentChar = null; 35885 let currentWidths = null; 35886 for (const [char, width] of chars) { 35887 if (!currentChar) { 35888 currentChar = char; 35889 currentWidths = [width]; 35890 continue; 35891 } 35892 if (char === currentChar + currentWidths.length) { 35893 currentWidths.push(width); 35894 } else { 35895 widths.push(currentChar, currentWidths); 35896 currentChar = char; 35897 currentWidths = [width]; 35898 } 35899 } 35900 if (currentChar) { 35901 widths.push(currentChar, currentWidths); 35902 } 35903 descendantFont.set("W", widths); 35904 const cidSystemInfo = new Dict(this.xref); 35905 cidSystemInfo.set("Ordering", "Identity"); 35906 cidSystemInfo.set("Registry", "Adobe"); 35907 cidSystemInfo.set("Supplement", 0); 35908 descendantFont.set("CIDSystemInfo", cidSystemInfo); 35909 return this.xref.getNewPersistentRef(descendantFont); 35910 } 35911 get baseFontRef() { 35912 const baseFont = new Dict(this.xref); 35913 baseFont.set("BaseFont", this.fontName); 35914 baseFont.setIfName("Type", "Font"); 35915 baseFont.setIfName("Subtype", "Type0"); 35916 baseFont.setIfName("Encoding", "Identity-H"); 35917 baseFont.set("DescendantFonts", [this.descendantFontRef]); 35918 baseFont.setIfName("ToUnicode", "Identity-H"); 35919 return this.xref.getNewPersistentRef(baseFont); 35920 } 35921 get resources() { 35922 const resources = new Dict(this.xref); 35923 const font = new Dict(this.xref); 35924 font.set(this.fontName.name, this.baseFontRef); 35925 resources.set("Font", font); 35926 return resources; 35927 } 35928 _createContext() { 35929 this.widths = new Map(); 35930 this.ctxMeasure.font = `1000px ${this.fontFamily}`; 35931 return this.ctxMeasure; 35932 } 35933 createFontResources(text) { 35934 const ctx = this._createContext(); 35935 for (const line of text.split(/\r\n?|\n/)) { 35936 for (const char of line.split("")) { 35937 const code = char.charCodeAt(0); 35938 if (this.widths.has(code)) { 35939 continue; 35940 } 35941 const metrics = ctx.measureText(char); 35942 const width = Math.ceil(metrics.width); 35943 this.widths.set(code, width); 35944 this.firstChar = Math.min(code, this.firstChar); 35945 this.lastChar = Math.max(code, this.lastChar); 35946 } 35947 } 35948 return this.resources; 35949 } 35950 static getFirstPositionInfo(rect, rotation, fontSize) { 35951 const [x1, y1, x2, y2] = rect; 35952 let w = x2 - x1; 35953 let h = y2 - y1; 35954 if (rotation % 180 !== 0) { 35955 [w, h] = [h, w]; 35956 } 35957 const lineHeight = LINE_FACTOR * fontSize; 35958 const lineDescent = LINE_DESCENT_FACTOR * fontSize; 35959 return { 35960 coords: [0, h + lineDescent - lineHeight], 35961 bbox: [0, 0, w, h], 35962 matrix: rotation !== 0 ? getRotationMatrix(rotation, h, lineHeight) : undefined 35963 }; 35964 } 35965 createAppearance(text, rect, rotation, fontSize, bgColor, strokeAlpha) { 35966 const ctx = this._createContext(); 35967 const lines = []; 35968 let maxWidth = -Infinity; 35969 for (const line of text.split(/\r\n?|\n/)) { 35970 lines.push(line); 35971 const lineWidth = ctx.measureText(line).width; 35972 maxWidth = Math.max(maxWidth, lineWidth); 35973 for (const code of codePointIter(line)) { 35974 const char = String.fromCodePoint(code); 35975 let width = this.widths.get(code); 35976 if (width === undefined) { 35977 const metrics = ctx.measureText(char); 35978 width = Math.ceil(metrics.width); 35979 this.widths.set(code, width); 35980 this.firstChar = Math.min(code, this.firstChar); 35981 this.lastChar = Math.max(code, this.lastChar); 35982 } 35983 } 35984 } 35985 maxWidth *= fontSize / 1000; 35986 const [x1, y1, x2, y2] = rect; 35987 let w = x2 - x1; 35988 let h = y2 - y1; 35989 if (rotation % 180 !== 0) { 35990 [w, h] = [h, w]; 35991 } 35992 let hscale = 1; 35993 if (maxWidth > w) { 35994 hscale = w / maxWidth; 35995 } 35996 let vscale = 1; 35997 const lineHeight = LINE_FACTOR * fontSize; 35998 const lineDescent = LINE_DESCENT_FACTOR * fontSize; 35999 const maxHeight = lineHeight * lines.length; 36000 if (maxHeight > h) { 36001 vscale = h / maxHeight; 36002 } 36003 const fscale = Math.min(hscale, vscale); 36004 const newFontSize = fontSize * fscale; 36005 const buffer = ["q", `0 0 ${numberToString(w)} ${numberToString(h)} re W n`, `BT`, `1 0 0 1 0 ${numberToString(h + lineDescent)} Tm 0 Tc ${getPdfColor(bgColor, true)}`, `/${this.fontName.name} ${numberToString(newFontSize)} Tf`]; 36006 const { 36007 resources 36008 } = this; 36009 strokeAlpha = typeof strokeAlpha === "number" && strokeAlpha >= 0 && strokeAlpha <= 1 ? strokeAlpha : 1; 36010 if (strokeAlpha !== 1) { 36011 buffer.push("/R0 gs"); 36012 const extGState = new Dict(this.xref); 36013 const r0 = new Dict(this.xref); 36014 r0.set("ca", strokeAlpha); 36015 r0.set("CA", strokeAlpha); 36016 r0.setIfName("Type", "ExtGState"); 36017 extGState.set("R0", r0); 36018 resources.set("ExtGState", extGState); 36019 } 36020 const vShift = numberToString(lineHeight); 36021 for (const line of lines) { 36022 buffer.push(`0 -${vShift} Td <${stringToUTF16HexString(line)}> Tj`); 36023 } 36024 buffer.push("ET", "Q"); 36025 const appearance = buffer.join("\n"); 36026 const appearanceStreamDict = new Dict(this.xref); 36027 appearanceStreamDict.setIfName("Subtype", "Form"); 36028 appearanceStreamDict.setIfName("Type", "XObject"); 36029 appearanceStreamDict.set("BBox", [0, 0, w, h]); 36030 appearanceStreamDict.set("Length", appearance.length); 36031 appearanceStreamDict.set("Resources", resources); 36032 if (rotation) { 36033 const matrix = getRotationMatrix(rotation, w, h); 36034 appearanceStreamDict.set("Matrix", matrix); 36035 } 36036 const ap = new StringStream(appearance); 36037 ap.dict = appearanceStreamDict; 36038 return ap; 36039 } 36040} 36041 36042;// ./src/shared/scripting_utils.js
vendor: 7,230 bytes, lines 36043-36322
36043function makeColorComp(n) { 36044 return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0"); 36045} 36046function scaleAndClamp(x) { 36047 return Math.max(0, Math.min(255, 255 * x)); 36048} 36049class ColorConverters { 36050 static CMYK_G([c, y, m, k]) { 36051 return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)]; 36052 } 36053 static G_CMYK([g]) { 36054 return ["CMYK", 0, 0, 0, 1 - g]; 36055 } 36056 static G_RGB([g]) { 36057 return ["RGB", g, g, g]; 36058 } 36059 static G_rgb([g]) { 36060 g = scaleAndClamp(g); 36061 return [g, g, g]; 36062 } 36063 static G_HTML([g]) { 36064 const G = makeColorComp(g); 36065 return `#${G}${G}${G}`; 36066 } 36067 static RGB_G([r, g, b]) { 36068 return ["G", 0.3 * r + 0.59 * g + 0.11 * b]; 36069 } 36070 static RGB_rgb(color) { 36071 return color.map(scaleAndClamp); 36072 } 36073 static RGB_HTML(color) { 36074 return `#${color.map(makeColorComp).join("")}`; 36075 } 36076 static T_HTML() { 36077 return "#00000000"; 36078 } 36079 static T_rgb() { 36080 return [null]; 36081 } 36082 static CMYK_RGB([c, y, m, k]) { 36083 return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)]; 36084 } 36085 static CMYK_rgb([c, y, m, k]) { 36086 return [scaleAndClamp(1 - Math.min(1, c + k)), scaleAndClamp(1 - Math.min(1, m + k)), scaleAndClamp(1 - Math.min(1, y + k))]; 36087 } 36088 static CMYK_HTML(components) { 36089 const rgb = this.CMYK_RGB(components).slice(1); 36090 return this.RGB_HTML(rgb); 36091 } 36092 static RGB_CMYK([r, g, b]) { 36093 const c = 1 - r; 36094 const m = 1 - g; 36095 const y = 1 - b; 36096 const k = Math.min(c, m, y); 36097 return ["CMYK", c, m, y, k]; 36098 } 36099} 36100const DateFormats = ["m/d", "m/d/yy", "mm/dd/yy", "mm/yy", "d-mmm", "d-mmm-yy", "dd-mmm-yy", "yy-mm-dd", "mmm-yy", "mmmm-yy", "mmm d, yyyy", "mmmm d, yyyy", "m/d/yy h:MM tt", "m/d/yy HH:MM"]; 36101const TimeFormats = ["HH:MM", "h:MM tt", "HH:MM:ss", "h:MM:ss tt"]; 36102 36103;// ./src/core/name_number_tree.js 36104 36105 36106class NameOrNumberTree { 36107 constructor(root, xref, type) { 36108 this.root = root; 36109 this.xref = xref; 36110 this._type = type; 36111 } 36112 getAll() { 36113 const map = new Map(); 36114 if (!this.root) { 36115 return map; 36116 } 36117 const xref = this.xref; 36118 const processed = new RefSet(); 36119 processed.put(this.root); 36120 const queue = [this.root]; 36121 while (queue.length > 0) { 36122 const obj = xref.fetchIfRef(queue.shift()); 36123 if (!(obj instanceof Dict)) { 36124 continue; 36125 } 36126 if (obj.has("Kids")) { 36127 const kids = obj.get("Kids"); 36128 if (!Array.isArray(kids)) { 36129 continue; 36130 } 36131 for (const kid of kids) { 36132 if (processed.has(kid)) { 36133 throw new FormatError(`Duplicate entry in "${this._type}" tree.`); 36134 } 36135 queue.push(kid); 36136 processed.put(kid); 36137 } 36138 continue; 36139 } 36140 const entries = obj.get(this._type); 36141 if (!Array.isArray(entries)) { 36142 continue; 36143 } 36144 for (let i = 0, ii = entries.length; i < ii; i += 2) { 36145 map.set(xref.fetchIfRef(entries[i]), xref.fetchIfRef(entries[i + 1])); 36146 } 36147 } 36148 return map; 36149 } 36150 getRaw(key) { 36151 if (!this.root) { 36152 return null; 36153 } 36154 const xref = this.xref; 36155 let kidsOrEntries = xref.fetchIfRef(this.root); 36156 let loopCount = 0; 36157 const MAX_LEVELS = 10; 36158 while (kidsOrEntries.has("Kids")) { 36159 if (++loopCount > MAX_LEVELS) { 36160 warn(`Search depth limit reached for "${this._type}" tree.`); 36161 return null; 36162 } 36163 const kids = kidsOrEntries.get("Kids"); 36164 if (!Array.isArray(kids)) { 36165 return null; 36166 } 36167 let l = 0, 36168 r = kids.length - 1; 36169 while (l <= r) { 36170 const m = l + r >> 1; 36171 const kid = xref.fetchIfRef(kids[m]); 36172 const limits = kid.get("Limits"); 36173 if (key < xref.fetchIfRef(limits[0])) { 36174 r = m - 1; 36175 } else if (key > xref.fetchIfRef(limits[1])) { 36176 l = m + 1; 36177 } else { 36178 kidsOrEntries = kid; 36179 break; 36180 } 36181 } 36182 if (l > r) { 36183 return null; 36184 } 36185 } 36186 const entries = kidsOrEntries.get(this._type); 36187 if (Array.isArray(entries)) { 36188 let l = 0, 36189 r = entries.length - 2; 36190 while (l <= r) { 36191 const tmp = l + r >> 1, 36192 m = tmp + (tmp & 1); 36193 const currentKey = xref.fetchIfRef(entries[m]); 36194 if (key < currentKey) { 36195 r = m - 2; 36196 } else if (key > currentKey) { 36197 l = m + 2; 36198 } else { 36199 return entries[m + 1]; 36200 } 36201 } 36202 } 36203 return null; 36204 } 36205 get(key) { 36206 return this.xref.fetchIfRef(this.getRaw(key)); 36207 } 36208} 36209class NameTree extends NameOrNumberTree { 36210 constructor(root, xref) { 36211 super(root, xref, "Names"); 36212 } 36213} 36214class NumberTree extends NameOrNumberTree { 36215 constructor(root, xref) { 36216 super(root, xref, "Nums"); 36217 } 36218} 36219 36220;// ./src/core/cleanup_helper.js 36221 36222 36223 36224 36225function clearGlobalCaches() { 36226 clearPatternCaches(); 36227 clearPrimitiveCaches(); 36228 clearUnicodeCaches(); 36229 JpxImage.cleanup(); 36230} 36231 36232;// ./src/core/file_spec.js 36233 36234 36235 36236function pickPlatformItem(dict) { 36237 if (!(dict instanceof Dict)) { 36238 return null; 36239 } 36240 if (dict.has("UF")) { 36241 return dict.get("UF"); 36242 } else if (dict.has("F")) { 36243 return dict.get("F"); 36244 } else if (dict.has("Unix")) { 36245 return dict.get("Unix"); 36246 } else if (dict.has("Mac")) { 36247 return dict.get("Mac"); 36248 } else if (dict.has("DOS")) { 36249 return dict.get("DOS"); 36250 } 36251 return null; 36252} 36253function stripPath(str) { 36254 return str.substring(str.lastIndexOf("/") + 1); 36255} 36256class FileSpec { 36257 #contentAvailable = false; 36258 constructor(root, xref, skipContent = false) { 36259 if (!(root instanceof Dict)) { 36260 return; 36261 } 36262 this.xref = xref; 36263 this.root = root; 36264 if (root.has("FS")) { 36265 this.fs = root.get("FS"); 36266 } 36267 if (root.has("RF")) { 36268 warn("Related file specifications are not supported"); 36269 } 36270 if (!skipContent) { 36271 if (root.has("EF")) { 36272 this.#contentAvailable = true; 36273 } else { 36274 warn("Non-embedded file specifications are not supported"); 36275 } 36276 } 36277 } 36278 get filename() { 36279 let filename = ""; 36280 const item = pickPlatformItem(this.root); 36281 if (item && typeof item === "string") { 36282 filename = stringToPDFString(item, true).replaceAll("\\\\", "\\").replaceAll("\\/", "/").replaceAll("\\", "/"); 36283 } 36284 return shadow(this, "filename", filename || "unnamed"); 36285 } 36286 get content() { 36287 if (!this.#contentAvailable) { 36288 return null; 36289 } 36290 this._contentRef ||= pickPlatformItem(this.root?.get("EF")); 36291 let content = null; 36292 if (this._contentRef) { 36293 const fileObj = this.xref.fetchIfRef(this._contentRef); 36294 if (fileObj instanceof BaseStream) { 36295 content = fileObj.getBytes(); 36296 } else { 36297 warn("Embedded file specification points to non-existing/invalid content"); 36298 } 36299 } else { 36300 warn("Embedded file specification does not have any content"); 36301 } 36302 return content; 36303 } 36304 get description() { 36305 let description = ""; 36306 const desc = this.root?.get("Desc"); 36307 if (desc && typeof desc === "string") { 36308 description = stringToPDFString(desc); 36309 } 36310 return shadow(this, "description", description); 36311 } 36312 get serializable() { 36313 return { 36314 rawFilename: this.filename, 36315 filename: stripPath(this.filename), 36316 content: this.content, 36317 description: this.description 36318 }; 36319 } 36320} 36321 36322;// ./src/core/xml_parser.js
vendor: 11,669 bytes, lines 36322-36739
36322 36323 36324const XMLParserErrorCode = { 36325 NoError: 0, 36326 EndOfDocument: -1, 36327 UnterminatedCdat: -2, 36328 UnterminatedXmlDeclaration: -3, 36329 UnterminatedDoctypeDeclaration: -4, 36330 UnterminatedComment: -5, 36331 MalformedElement: -6, 36332 OutOfMemory: -7, 36333 UnterminatedAttributeValue: -8, 36334 UnterminatedElement: -9, 36335 ElementNeverBegun: -10 36336}; 36337function isWhitespace(s, index) { 36338 const ch = s[index]; 36339 return ch === " " || ch === "\n" || ch === "\r" || ch === "\t"; 36340} 36341function isWhitespaceString(s) { 36342 for (let i = 0, ii = s.length; i < ii; i++) { 36343 if (!isWhitespace(s, i)) { 36344 return false; 36345 } 36346 } 36347 return true; 36348} 36349class XMLParserBase { 36350 _resolveEntities(s) { 36351 return s.replaceAll(/&([^;]+);/g, (all, entity) => { 36352 if (entity.substring(0, 2) === "#x") { 36353 return String.fromCodePoint(parseInt(entity.substring(2), 16)); 36354 } else if (entity.substring(0, 1) === "#") { 36355 return String.fromCodePoint(parseInt(entity.substring(1), 10)); 36356 } 36357 switch (entity) { 36358 case "lt": 36359 return "<"; 36360 case "gt": 36361 return ">"; 36362 case "amp": 36363 return "&"; 36364 case "quot": 36365 return '"'; 36366 case "apos": 36367 return "'"; 36368 } 36369 return this.onResolveEntity(entity); 36370 }); 36371 } 36372 _parseContent(s, start) { 36373 const attributes = []; 36374 let pos = start; 36375 function skipWs() { 36376 while (pos < s.length && isWhitespace(s, pos)) { 36377 ++pos; 36378 } 36379 } 36380 while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") { 36381 ++pos; 36382 } 36383 const name = s.substring(start, pos); 36384 skipWs(); 36385 while (pos < s.length && s[pos] !== ">" && s[pos] !== "/" && s[pos] !== "?") { 36386 skipWs(); 36387 let attrName = "", 36388 attrValue = ""; 36389 while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== "=") { 36390 attrName += s[pos]; 36391 ++pos; 36392 } 36393 skipWs(); 36394 if (s[pos] !== "=") { 36395 return null; 36396 } 36397 ++pos; 36398 skipWs(); 36399 const attrEndChar = s[pos]; 36400 if (attrEndChar !== '"' && attrEndChar !== "'") { 36401 return null; 36402 } 36403 const attrEndIndex = s.indexOf(attrEndChar, ++pos); 36404 if (attrEndIndex < 0) { 36405 return null; 36406 } 36407 attrValue = s.substring(pos, attrEndIndex); 36408 attributes.push({ 36409 name: attrName, 36410 value: this._resolveEntities(attrValue) 36411 }); 36412 pos = attrEndIndex + 1; 36413 skipWs(); 36414 } 36415 return { 36416 name, 36417 attributes, 36418 parsed: pos - start 36419 }; 36420 } 36421 _parseProcessingInstruction(s, start) { 36422 let pos = start; 36423 function skipWs() { 36424 while (pos < s.length && isWhitespace(s, pos)) { 36425 ++pos; 36426 } 36427 } 36428 while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "?" && s[pos] !== "/") { 36429 ++pos; 36430 } 36431 const name = s.substring(start, pos); 36432 skipWs(); 36433 const attrStart = pos; 36434 while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) { 36435 ++pos; 36436 } 36437 const value = s.substring(attrStart, pos); 36438 return { 36439 name, 36440 value, 36441 parsed: pos - start 36442 }; 36443 } 36444 parseXml(s) { 36445 let i = 0; 36446 while (i < s.length) { 36447 const ch = s[i]; 36448 let j = i; 36449 if (ch === "<") { 36450 ++j; 36451 const ch2 = s[j]; 36452 let q; 36453 switch (ch2) { 36454 case "/": 36455 ++j; 36456 q = s.indexOf(">", j); 36457 if (q < 0) { 36458 this.onError(XMLParserErrorCode.UnterminatedElement); 36459 return; 36460 } 36461 this.onEndElement(s.substring(j, q)); 36462 j = q + 1; 36463 break; 36464 case "?": 36465 ++j; 36466 const pi = this._parseProcessingInstruction(s, j); 36467 if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== "?>") { 36468 this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration); 36469 return; 36470 } 36471 this.onPi(pi.name, pi.value); 36472 j += pi.parsed + 2; 36473 break; 36474 case "!": 36475 if (s.substring(j + 1, j + 3) === "--") { 36476 q = s.indexOf("-->", j + 3); 36477 if (q < 0) { 36478 this.onError(XMLParserErrorCode.UnterminatedComment); 36479 return; 36480 } 36481 this.onComment(s.substring(j + 3, q)); 36482 j = q + 3; 36483 } else if (s.substring(j + 1, j + 8) === "[CDATA[") { 36484 q = s.indexOf("]]>", j + 8); 36485 if (q < 0) { 36486 this.onError(XMLParserErrorCode.UnterminatedCdat); 36487 return; 36488 } 36489 this.onCdata(s.substring(j + 8, q)); 36490 j = q + 3; 36491 } else if (s.substring(j + 1, j + 8) === "DOCTYPE") { 36492 const q2 = s.indexOf("[", j + 8); 36493 let complexDoctype = false; 36494 q = s.indexOf(">", j + 8); 36495 if (q < 0) { 36496 this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration); 36497 return; 36498 } 36499 if (q2 > 0 && q > q2) { 36500 q = s.indexOf("]>", j + 8); 36501 if (q < 0) { 36502 this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration); 36503 return; 36504 } 36505 complexDoctype = true; 36506 } 36507 const doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0)); 36508 this.onDoctype(doctypeContent); 36509 j = q + (complexDoctype ? 2 : 1); 36510 } else { 36511 this.onError(XMLParserErrorCode.MalformedElement); 36512 return; 36513 } 36514 break; 36515 default: 36516 const content = this._parseContent(s, j); 36517 if (content === null) { 36518 this.onError(XMLParserErrorCode.MalformedElement); 36519 return; 36520 } 36521 let isClosed = false; 36522 if (s.substring(j + content.parsed, j + content.parsed + 2) === "/>") { 36523 isClosed = true; 36524 } else if (s.substring(j + content.parsed, j + content.parsed + 1) !== ">") { 36525 this.onError(XMLParserErrorCode.UnterminatedElement); 36526 return; 36527 } 36528 this.onBeginElement(content.name, content.attributes, isClosed); 36529 j += content.parsed + (isClosed ? 2 : 1); 36530 break; 36531 } 36532 } else { 36533 while (j < s.length && s[j] !== "<") { 36534 j++; 36535 } 36536 const text = s.substring(i, j); 36537 this.onText(this._resolveEntities(text)); 36538 } 36539 i = j; 36540 } 36541 } 36542 onResolveEntity(name) { 36543 return `&${name};`; 36544 } 36545 onPi(name, value) {} 36546 onComment(text) {} 36547 onCdata(text) {} 36548 onDoctype(doctypeContent) {} 36549 onText(text) {} 36550 onBeginElement(name, attributes, isEmpty) {} 36551 onEndElement(name) {} 36552 onError(code) {} 36553} 36554class SimpleDOMNode { 36555 constructor(nodeName, nodeValue) { 36556 this.nodeName = nodeName; 36557 this.nodeValue = nodeValue; 36558 Object.defineProperty(this, "parentNode", { 36559 value: null, 36560 writable: true 36561 }); 36562 } 36563 get firstChild() { 36564 return this.childNodes?.[0]; 36565 } 36566 get nextSibling() { 36567 const childNodes = this.parentNode.childNodes; 36568 if (!childNodes) { 36569 return undefined; 36570 } 36571 const index = childNodes.indexOf(this); 36572 if (index === -1) { 36573 return undefined; 36574 } 36575 return childNodes[index + 1]; 36576 } 36577 get textContent() { 36578 if (!this.childNodes) { 36579 return this.nodeValue || ""; 36580 } 36581 return this.childNodes.map(child => child.textContent).join(""); 36582 } 36583 get children() { 36584 return this.childNodes || []; 36585 } 36586 hasChildNodes() { 36587 return this.childNodes?.length > 0; 36588 } 36589 searchNode(paths, pos) { 36590 if (pos >= paths.length) { 36591 return this; 36592 } 36593 const component = paths[pos]; 36594 if (component.name.startsWith("#") && pos < paths.length - 1) { 36595 return this.searchNode(paths, pos + 1); 36596 } 36597 const stack = []; 36598 let node = this; 36599 while (true) { 36600 if (component.name === node.nodeName) { 36601 if (component.pos === 0) { 36602 const res = node.searchNode(paths, pos + 1); 36603 if (res !== null) { 36604 return res; 36605 } 36606 } else if (stack.length === 0) { 36607 return null; 36608 } else { 36609 const [parent] = stack.pop(); 36610 let siblingPos = 0; 36611 for (const child of parent.childNodes) { 36612 if (component.name === child.nodeName) { 36613 if (siblingPos === component.pos) { 36614 return child.searchNode(paths, pos + 1); 36615 } 36616 siblingPos++; 36617 } 36618 } 36619 return node.searchNode(paths, pos + 1); 36620 } 36621 } 36622 if (node.childNodes?.length > 0) { 36623 stack.push([node, 0]); 36624 node = node.childNodes[0]; 36625 } else if (stack.length === 0) { 36626 return null; 36627 } else { 36628 while (stack.length !== 0) { 36629 const [parent, currentPos] = stack.pop(); 36630 const newPos = currentPos + 1; 36631 if (newPos < parent.childNodes.length) { 36632 stack.push([parent, newPos]); 36633 node = parent.childNodes[newPos]; 36634 break; 36635 } 36636 } 36637 if (stack.length === 0) { 36638 return null; 36639 } 36640 } 36641 } 36642 } 36643 dump(buffer) { 36644 if (this.nodeName === "#text") { 36645 buffer.push(encodeToXmlString(this.nodeValue)); 36646 return; 36647 } 36648 buffer.push(`<${this.nodeName}`); 36649 if (this.attributes) { 36650 for (const attribute of this.attributes) { 36651 buffer.push(` ${attribute.name}="${encodeToXmlString(attribute.value)}"`); 36652 } 36653 } 36654 if (this.hasChildNodes()) { 36655 buffer.push(">"); 36656 for (const child of this.childNodes) { 36657 child.dump(buffer); 36658 } 36659 buffer.push(`</${this.nodeName}>`); 36660 } else if (this.nodeValue) { 36661 buffer.push(`>${encodeToXmlString(this.nodeValue)}</${this.nodeName}>`); 36662 } else { 36663 buffer.push("/>"); 36664 } 36665 } 36666} 36667class SimpleXMLParser extends XMLParserBase { 36668 constructor({ 36669 hasAttributes = false, 36670 lowerCaseName = false 36671 }) { 36672 super(); 36673 this._currentFragment = null; 36674 this._stack = null; 36675 this._errorCode = XMLParserErrorCode.NoError; 36676 this._hasAttributes = hasAttributes; 36677 this._lowerCaseName = lowerCaseName; 36678 } 36679 parseFromString(data) { 36680 this._currentFragment = []; 36681 this._stack = []; 36682 this._errorCode = XMLParserErrorCode.NoError; 36683 this.parseXml(data); 36684 if (this._errorCode !== XMLParserErrorCode.NoError) { 36685 return undefined; 36686 } 36687 const [documentElement] = this._currentFragment; 36688 if (!documentElement) { 36689 return undefined; 36690 } 36691 return { 36692 documentElement 36693 }; 36694 } 36695 onText(text) { 36696 if (isWhitespaceString(text)) { 36697 return; 36698 } 36699 const node = new SimpleDOMNode("#text", text); 36700 this._currentFragment.push(node); 36701 } 36702 onCdata(text) { 36703 const node = new SimpleDOMNode("#text", text); 36704 this._currentFragment.push(node); 36705 } 36706 onBeginElement(name, attributes, isEmpty) { 36707 if (this._lowerCaseName) { 36708 name = name.toLowerCase(); 36709 } 36710 const node = new SimpleDOMNode(name); 36711 node.childNodes = []; 36712 if (this._hasAttributes) { 36713 node.attributes = attributes; 36714 } 36715 this._currentFragment.push(node); 36716 if (isEmpty) { 36717 return; 36718 } 36719 this._stack.push(this._currentFragment); 36720 this._currentFragment = node.childNodes; 36721 } 36722 onEndElement(name) { 36723 this._currentFragment = this._stack.pop() || []; 36724 const lastElement = this._currentFragment.at(-1); 36725 if (!lastElement) { 36726 return null; 36727 } 36728 for (const childNode of lastElement.childNodes) { 36729 childNode.parentNode = lastElement; 36730 } 36731 return lastElement; 36732 } 36733 onError(code) { 36734 this._errorCode = code; 36735 } 36736} 36737 36738;// ./src/core/metadata_parser.js 36739
vendor: 2,897 bytes, lines 36740-36836
36740class MetadataParser { 36741 constructor(data) { 36742 data = this._repair(data); 36743 const parser = new SimpleXMLParser({ 36744 lowerCaseName: true 36745 }); 36746 const xmlDocument = parser.parseFromString(data); 36747 this._metadataMap = new Map(); 36748 this._data = data; 36749 if (xmlDocument) { 36750 this._parse(xmlDocument); 36751 } 36752 } 36753 _repair(data) { 36754 return data.replace(/^[^<]+/, "").replaceAll(/>\\376\\377([^<]+)/g, function (all, codes) { 36755 const bytes = codes.replaceAll(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) { 36756 return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1); 36757 }).replaceAll(/&(amp|apos|gt|lt|quot);/g, function (str, name) { 36758 switch (name) { 36759 case "amp": 36760 return "&"; 36761 case "apos": 36762 return "'"; 36763 case "gt": 36764 return ">"; 36765 case "lt": 36766 return "<"; 36767 case "quot": 36768 return '"'; 36769 } 36770 throw new Error(`_repair: ${name} isn't defined.`); 36771 }); 36772 const charBuf = [">"]; 36773 for (let i = 0, ii = bytes.length; i < ii; i += 2) { 36774 const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1); 36775 if (code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38) { 36776 charBuf.push(String.fromCharCode(code)); 36777 } else { 36778 charBuf.push("&#x" + (0x10000 + code).toString(16).substring(1) + ";"); 36779 } 36780 } 36781 return charBuf.join(""); 36782 }); 36783 } 36784 _getSequence(entry) { 36785 const name = entry.nodeName; 36786 if (name !== "rdf:bag" && name !== "rdf:seq" && name !== "rdf:alt") { 36787 return null; 36788 } 36789 return entry.childNodes.filter(node => node.nodeName === "rdf:li"); 36790 } 36791 _parseArray(entry) { 36792 if (!entry.hasChildNodes()) { 36793 return; 36794 } 36795 const [seqNode] = entry.childNodes; 36796 const sequence = this._getSequence(seqNode) || []; 36797 this._metadataMap.set(entry.nodeName, sequence.map(node => node.textContent.trim())); 36798 } 36799 _parse(xmlDocument) { 36800 let rdf = xmlDocument.documentElement; 36801 if (rdf.nodeName !== "rdf:rdf") { 36802 rdf = rdf.firstChild; 36803 while (rdf && rdf.nodeName !== "rdf:rdf") { 36804 rdf = rdf.nextSibling; 36805 } 36806 } 36807 if (!rdf || rdf.nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) { 36808 return; 36809 } 36810 for (const desc of rdf.childNodes) { 36811 if (desc.nodeName !== "rdf:description") { 36812 continue; 36813 } 36814 for (const entry of desc.childNodes) { 36815 const name = entry.nodeName; 36816 switch (name) { 36817 case "#text": 36818 continue; 36819 case "dc:creator": 36820 case "dc:subject": 36821 this._parseArray(entry); 36822 continue; 36823 } 36824 this._metadataMap.set(name, entry.textContent.trim()); 36825 } 36826 } 36827 } 36828 get serializable() { 36829 return { 36830 parsedData: this._metadataMap, 36831 rawData: this._data 36832 }; 36833 } 36834} 36835 36836;// ./src/core/struct_tree.js
vendor: 63,454 bytes, lines 36836-39005
36836 36837 36838 36839 36840 36841const MAX_DEPTH = 40; 36842const StructElementType = { 36843 PAGE_CONTENT: 1, 36844 STREAM_CONTENT: 2, 36845 OBJECT: 3, 36846 ANNOTATION: 4, 36847 ELEMENT: 5 36848}; 36849class StructTreeRoot { 36850 constructor(xref, rootDict, rootRef) { 36851 this.xref = xref; 36852 this.dict = rootDict; 36853 this.ref = rootRef instanceof Ref ? rootRef : null; 36854 this.roleMap = new Map(); 36855 this.structParentIds = null; 36856 } 36857 init() { 36858 this.readRoleMap(); 36859 } 36860 #addIdToPage(pageRef, id, type) { 36861 if (!(pageRef instanceof Ref) || id < 0) { 36862 return; 36863 } 36864 this.structParentIds ||= new RefSetCache(); 36865 let ids = this.structParentIds.get(pageRef); 36866 if (!ids) { 36867 ids = []; 36868 this.structParentIds.put(pageRef, ids); 36869 } 36870 ids.push([id, type]); 36871 } 36872 addAnnotationIdToPage(pageRef, id) { 36873 this.#addIdToPage(pageRef, id, StructElementType.ANNOTATION); 36874 } 36875 readRoleMap() { 36876 const roleMapDict = this.dict.get("RoleMap"); 36877 if (!(roleMapDict instanceof Dict)) { 36878 return; 36879 } 36880 for (const [key, value] of roleMapDict) { 36881 if (value instanceof Name) { 36882 this.roleMap.set(key, value.name); 36883 } 36884 } 36885 } 36886 static async canCreateStructureTree({ 36887 catalogRef, 36888 pdfManager, 36889 newAnnotationsByPage 36890 }) { 36891 if (!(catalogRef instanceof Ref)) { 36892 warn("Cannot save the struct tree: no catalog reference."); 36893 return false; 36894 } 36895 let nextKey = 0; 36896 let hasNothingToUpdate = true; 36897 for (const [pageIndex, elements] of newAnnotationsByPage) { 36898 const { 36899 ref: pageRef 36900 } = await pdfManager.getPage(pageIndex); 36901 if (!(pageRef instanceof Ref)) { 36902 warn(`Cannot save the struct tree: page ${pageIndex} has no ref.`); 36903 hasNothingToUpdate = true; 36904 break; 36905 } 36906 for (const element of elements) { 36907 if (element.accessibilityData?.type) { 36908 element.parentTreeId = nextKey++; 36909 hasNothingToUpdate = false; 36910 } 36911 } 36912 } 36913 if (hasNothingToUpdate) { 36914 for (const elements of newAnnotationsByPage.values()) { 36915 for (const element of elements) { 36916 delete element.parentTreeId; 36917 } 36918 } 36919 return false; 36920 } 36921 return true; 36922 } 36923 static async createStructureTree({ 36924 newAnnotationsByPage, 36925 xref, 36926 catalogRef, 36927 pdfManager, 36928 changes 36929 }) { 36930 const root = await pdfManager.ensureCatalog("cloneDict"); 36931 const cache = new RefSetCache(); 36932 cache.put(catalogRef, root); 36933 const structTreeRootRef = xref.getNewTemporaryRef(); 36934 root.set("StructTreeRoot", structTreeRootRef); 36935 const structTreeRoot = new Dict(xref); 36936 structTreeRoot.set("Type", Name.get("StructTreeRoot")); 36937 const parentTreeRef = xref.getNewTemporaryRef(); 36938 structTreeRoot.set("ParentTree", parentTreeRef); 36939 const kids = []; 36940 structTreeRoot.set("K", kids); 36941 cache.put(structTreeRootRef, structTreeRoot); 36942 const parentTree = new Dict(xref); 36943 const nums = []; 36944 parentTree.set("Nums", nums); 36945 const nextKey = await this.#writeKids({ 36946 newAnnotationsByPage, 36947 structTreeRootRef, 36948 structTreeRoot: null, 36949 kids, 36950 nums, 36951 xref, 36952 pdfManager, 36953 changes, 36954 cache 36955 }); 36956 structTreeRoot.set("ParentTreeNextKey", nextKey); 36957 cache.put(parentTreeRef, parentTree); 36958 for (const [ref, obj] of cache.items()) { 36959 changes.put(ref, { 36960 data: obj 36961 }); 36962 } 36963 } 36964 async canUpdateStructTree({ 36965 pdfManager, 36966 newAnnotationsByPage 36967 }) { 36968 if (!this.ref) { 36969 warn("Cannot update the struct tree: no root reference."); 36970 return false; 36971 } 36972 let nextKey = this.dict.get("ParentTreeNextKey"); 36973 if (!Number.isInteger(nextKey) || nextKey < 0) { 36974 warn("Cannot update the struct tree: invalid next key."); 36975 return false; 36976 } 36977 const parentTree = this.dict.get("ParentTree"); 36978 if (!(parentTree instanceof Dict)) { 36979 warn("Cannot update the struct tree: ParentTree isn't a dict."); 36980 return false; 36981 } 36982 const nums = parentTree.get("Nums"); 36983 if (!Array.isArray(nums)) { 36984 warn("Cannot update the struct tree: nums isn't an array."); 36985 return false; 36986 } 36987 const numberTree = new NumberTree(parentTree, this.xref); 36988 for (const pageIndex of newAnnotationsByPage.keys()) { 36989 const { 36990 pageDict 36991 } = await pdfManager.getPage(pageIndex); 36992 if (!pageDict.has("StructParents")) { 36993 continue; 36994 } 36995 const id = pageDict.get("StructParents"); 36996 if (!Number.isInteger(id) || !Array.isArray(numberTree.get(id))) { 36997 warn(`Cannot save the struct tree: page ${pageIndex} has a wrong id.`); 36998 return false; 36999 } 37000 } 37001 let hasNothingToUpdate = true; 37002 for (const [pageIndex, elements] of newAnnotationsByPage) { 37003 const { 37004 pageDict 37005 } = await pdfManager.getPage(pageIndex); 37006 StructTreeRoot.#collectParents({ 37007 elements, 37008 xref: this.xref, 37009 pageDict, 37010 numberTree 37011 }); 37012 for (const element of elements) { 37013 if (element.accessibilityData?.type) { 37014 if (!(element.accessibilityData.structParent >= 0)) { 37015 element.parentTreeId = nextKey++; 37016 } 37017 hasNothingToUpdate = false; 37018 } 37019 } 37020 } 37021 if (hasNothingToUpdate) { 37022 for (const elements of newAnnotationsByPage.values()) { 37023 for (const element of elements) { 37024 delete element.parentTreeId; 37025 delete element.structTreeParent; 37026 } 37027 } 37028 return false; 37029 } 37030 return true; 37031 } 37032 async updateStructureTree({ 37033 newAnnotationsByPage, 37034 pdfManager, 37035 changes 37036 }) { 37037 const { 37038 ref: structTreeRootRef, 37039 xref 37040 } = this; 37041 const structTreeRoot = this.dict.clone(); 37042 const cache = new RefSetCache(); 37043 cache.put(structTreeRootRef, structTreeRoot); 37044 let parentTreeRef = structTreeRoot.getRaw("ParentTree"); 37045 let parentTree; 37046 if (parentTreeRef instanceof Ref) { 37047 parentTree = xref.fetch(parentTreeRef); 37048 } else { 37049 parentTree = parentTreeRef; 37050 parentTreeRef = xref.getNewTemporaryRef(); 37051 structTreeRoot.set("ParentTree", parentTreeRef); 37052 } 37053 parentTree = parentTree.clone(); 37054 cache.put(parentTreeRef, parentTree); 37055 let nums = parentTree.getRaw("Nums"); 37056 let numsRef = null; 37057 if (nums instanceof Ref) { 37058 numsRef = nums; 37059 nums = xref.fetch(numsRef); 37060 } 37061 nums = nums.slice(); 37062 if (!numsRef) { 37063 parentTree.set("Nums", nums); 37064 } 37065 const newNextKey = await StructTreeRoot.#writeKids({ 37066 newAnnotationsByPage, 37067 structTreeRootRef, 37068 structTreeRoot: this, 37069 kids: null, 37070 nums, 37071 xref, 37072 pdfManager, 37073 changes, 37074 cache 37075 }); 37076 if (newNextKey === -1) { 37077 return; 37078 } 37079 structTreeRoot.set("ParentTreeNextKey", newNextKey); 37080 if (numsRef) { 37081 cache.put(numsRef, nums); 37082 } 37083 for (const [ref, obj] of cache.items()) { 37084 changes.put(ref, { 37085 data: obj 37086 }); 37087 } 37088 } 37089 static async #writeKids({ 37090 newAnnotationsByPage, 37091 structTreeRootRef, 37092 structTreeRoot, 37093 kids, 37094 nums, 37095 xref, 37096 pdfManager, 37097 changes, 37098 cache 37099 }) { 37100 const objr = Name.get("OBJR"); 37101 let nextKey = -1; 37102 let structTreePageObjs; 37103 for (const [pageIndex, elements] of newAnnotationsByPage) { 37104 const page = await pdfManager.getPage(pageIndex); 37105 const { 37106 ref: pageRef 37107 } = page; 37108 const isPageRef = pageRef instanceof Ref; 37109 for (const { 37110 accessibilityData, 37111 ref, 37112 parentTreeId, 37113 structTreeParent 37114 } of elements) { 37115 if (!accessibilityData?.type) { 37116 continue; 37117 } 37118 const { 37119 structParent 37120 } = accessibilityData; 37121 if (structTreeRoot && Number.isInteger(structParent) && structParent >= 0) { 37122 let objs = (structTreePageObjs ||= new Map()).get(pageIndex); 37123 if (objs === undefined) { 37124 const structTreePage = new StructTreePage(structTreeRoot, page.pageDict); 37125 objs = structTreePage.collectObjects(pageRef); 37126 structTreePageObjs.set(pageIndex, objs); 37127 } 37128 const objRef = objs?.get(structParent); 37129 if (objRef) { 37130 const tagDict = xref.fetch(objRef).clone(); 37131 StructTreeRoot.#writeProperties(tagDict, accessibilityData); 37132 changes.put(objRef, { 37133 data: tagDict 37134 }); 37135 continue; 37136 } 37137 } 37138 nextKey = Math.max(nextKey, parentTreeId); 37139 const tagRef = xref.getNewTemporaryRef(); 37140 const tagDict = new Dict(xref); 37141 StructTreeRoot.#writeProperties(tagDict, accessibilityData); 37142 await this.#updateParentTag({ 37143 structTreeParent, 37144 tagDict, 37145 newTagRef: tagRef, 37146 structTreeRootRef, 37147 fallbackKids: kids, 37148 xref, 37149 cache 37150 }); 37151 const objDict = new Dict(xref); 37152 tagDict.set("K", objDict); 37153 objDict.set("Type", objr); 37154 if (isPageRef) { 37155 objDict.set("Pg", pageRef); 37156 } 37157 objDict.set("Obj", ref); 37158 cache.put(tagRef, tagDict); 37159 nums.push(parentTreeId, tagRef); 37160 } 37161 } 37162 return nextKey + 1; 37163 } 37164 static #writeProperties(tagDict, { 37165 type, 37166 title, 37167 lang, 37168 alt, 37169 expanded, 37170 actualText 37171 }) { 37172 tagDict.set("S", Name.get(type)); 37173 if (title) { 37174 tagDict.set("T", stringToAsciiOrUTF16BE(title)); 37175 } 37176 if (lang) { 37177 tagDict.set("Lang", stringToAsciiOrUTF16BE(lang)); 37178 } 37179 if (alt) { 37180 tagDict.set("Alt", stringToAsciiOrUTF16BE(alt)); 37181 } 37182 if (expanded) { 37183 tagDict.set("E", stringToAsciiOrUTF16BE(expanded)); 37184 } 37185 if (actualText) { 37186 tagDict.set("ActualText", stringToAsciiOrUTF16BE(actualText)); 37187 } 37188 } 37189 static #collectParents({ 37190 elements, 37191 xref, 37192 pageDict, 37193 numberTree 37194 }) { 37195 const idToElements = new Map(); 37196 for (const element of elements) { 37197 if (element.structTreeParentId) { 37198 const id = parseInt(element.structTreeParentId.split("_mc")[1], 10); 37199 let elems = idToElements.get(id); 37200 if (!elems) { 37201 elems = []; 37202 idToElements.set(id, elems); 37203 } 37204 elems.push(element); 37205 } 37206 } 37207 const id = pageDict.get("StructParents"); 37208 if (!Number.isInteger(id)) { 37209 return; 37210 } 37211 const parentArray = numberTree.get(id); 37212 const updateElement = (kid, pageKid, kidRef) => { 37213 const elems = idToElements.get(kid); 37214 if (elems) { 37215 const parentRef = pageKid.getRaw("P"); 37216 const parentDict = xref.fetchIfRef(parentRef); 37217 if (parentRef instanceof Ref && parentDict instanceof Dict) { 37218 const params = { 37219 ref: kidRef, 37220 dict: pageKid 37221 }; 37222 for (const element of elems) { 37223 element.structTreeParent = params; 37224 } 37225 } 37226 return true; 37227 } 37228 return false; 37229 }; 37230 for (const kidRef of parentArray) { 37231 if (!(kidRef instanceof Ref)) { 37232 continue; 37233 } 37234 const pageKid = xref.fetch(kidRef); 37235 const k = pageKid.get("K"); 37236 if (Number.isInteger(k)) { 37237 updateElement(k, pageKid, kidRef); 37238 continue; 37239 } 37240 if (!Array.isArray(k)) { 37241 continue; 37242 } 37243 for (let kid of k) { 37244 kid = xref.fetchIfRef(kid); 37245 if (Number.isInteger(kid) && updateElement(kid, pageKid, kidRef)) { 37246 break; 37247 } 37248 if (!(kid instanceof Dict)) { 37249 continue; 37250 } 37251 if (!isName(kid.get("Type"), "MCR")) { 37252 break; 37253 } 37254 const mcid = kid.get("MCID"); 37255 if (Number.isInteger(mcid) && updateElement(mcid, pageKid, kidRef)) { 37256 break; 37257 } 37258 } 37259 } 37260 } 37261 static async #updateParentTag({ 37262 structTreeParent, 37263 tagDict, 37264 newTagRef, 37265 structTreeRootRef, 37266 fallbackKids, 37267 xref, 37268 cache 37269 }) { 37270 let ref = null; 37271 let parentRef; 37272 if (structTreeParent) { 37273 ({ 37274 ref 37275 } = structTreeParent); 37276 parentRef = structTreeParent.dict.getRaw("P") || structTreeRootRef; 37277 } else { 37278 parentRef = structTreeRootRef; 37279 } 37280 tagDict.set("P", parentRef); 37281 const parentDict = xref.fetchIfRef(parentRef); 37282 if (!parentDict) { 37283 fallbackKids.push(newTagRef); 37284 return; 37285 } 37286 let cachedParentDict = cache.get(parentRef); 37287 if (!cachedParentDict) { 37288 cachedParentDict = parentDict.clone(); 37289 cache.put(parentRef, cachedParentDict); 37290 } 37291 const parentKidsRaw = cachedParentDict.getRaw("K"); 37292 let cachedParentKids = parentKidsRaw instanceof Ref ? cache.get(parentKidsRaw) : null; 37293 if (!cachedParentKids) { 37294 cachedParentKids = xref.fetchIfRef(parentKidsRaw); 37295 cachedParentKids = Array.isArray(cachedParentKids) ? cachedParentKids.slice() : [parentKidsRaw]; 37296 const parentKidsRef = xref.getNewTemporaryRef(); 37297 cachedParentDict.set("K", parentKidsRef); 37298 cache.put(parentKidsRef, cachedParentKids); 37299 } 37300 const index = cachedParentKids.indexOf(ref); 37301 cachedParentKids.splice(index >= 0 ? index + 1 : cachedParentKids.length, 0, newTagRef); 37302 } 37303} 37304class StructElementNode { 37305 constructor(tree, dict) { 37306 this.tree = tree; 37307 this.xref = tree.xref; 37308 this.dict = dict; 37309 this.kids = []; 37310 this.parseKids(); 37311 } 37312 get role() { 37313 const nameObj = this.dict.get("S"); 37314 const name = nameObj instanceof Name ? nameObj.name : ""; 37315 const { 37316 root 37317 } = this.tree; 37318 return root.roleMap.get(name) ?? name; 37319 } 37320 parseKids() { 37321 let pageObjId = null; 37322 const objRef = this.dict.getRaw("Pg"); 37323 if (objRef instanceof Ref) { 37324 pageObjId = objRef.toString(); 37325 } 37326 const kids = this.dict.get("K"); 37327 if (Array.isArray(kids)) { 37328 for (const kid of kids) { 37329 const element = this.parseKid(pageObjId, this.xref.fetchIfRef(kid)); 37330 if (element) { 37331 this.kids.push(element); 37332 } 37333 } 37334 } else { 37335 const element = this.parseKid(pageObjId, kids); 37336 if (element) { 37337 this.kids.push(element); 37338 } 37339 } 37340 } 37341 parseKid(pageObjId, kid) { 37342 if (Number.isInteger(kid)) { 37343 if (this.tree.pageDict.objId !== pageObjId) { 37344 return null; 37345 } 37346 return new StructElement({ 37347 type: StructElementType.PAGE_CONTENT, 37348 mcid: kid, 37349 pageObjId 37350 }); 37351 } 37352 if (!(kid instanceof Dict)) { 37353 return null; 37354 } 37355 const pageRef = kid.getRaw("Pg"); 37356 if (pageRef instanceof Ref) { 37357 pageObjId = pageRef.toString(); 37358 } 37359 const type = kid.get("Type") instanceof Name ? kid.get("Type").name : null; 37360 if (type === "MCR") { 37361 if (this.tree.pageDict.objId !== pageObjId) { 37362 return null; 37363 } 37364 const kidRef = kid.getRaw("Stm"); 37365 return new StructElement({ 37366 type: StructElementType.STREAM_CONTENT, 37367 refObjId: kidRef instanceof Ref ? kidRef.toString() : null, 37368 pageObjId, 37369 mcid: kid.get("MCID") 37370 }); 37371 } 37372 if (type === "OBJR") { 37373 if (this.tree.pageDict.objId !== pageObjId) { 37374 return null; 37375 } 37376 const kidRef = kid.getRaw("Obj"); 37377 return new StructElement({ 37378 type: StructElementType.OBJECT, 37379 refObjId: kidRef instanceof Ref ? kidRef.toString() : null, 37380 pageObjId 37381 }); 37382 } 37383 return new StructElement({ 37384 type: StructElementType.ELEMENT, 37385 dict: kid 37386 }); 37387 } 37388} 37389class StructElement { 37390 constructor({ 37391 type, 37392 dict = null, 37393 mcid = null, 37394 pageObjId = null, 37395 refObjId = null 37396 }) { 37397 this.type = type; 37398 this.dict = dict; 37399 this.mcid = mcid; 37400 this.pageObjId = pageObjId; 37401 this.refObjId = refObjId; 37402 this.parentNode = null; 37403 } 37404} 37405class StructTreePage { 37406 constructor(structTreeRoot, pageDict) { 37407 this.root = structTreeRoot; 37408 this.xref = structTreeRoot?.xref ?? null; 37409 this.rootDict = structTreeRoot?.dict ?? null; 37410 this.pageDict = pageDict; 37411 this.nodes = []; 37412 } 37413 collectObjects(pageRef) { 37414 if (!this.root || !this.rootDict || !(pageRef instanceof Ref)) { 37415 return null; 37416 } 37417 const parentTree = this.rootDict.get("ParentTree"); 37418 if (!parentTree) { 37419 return null; 37420 } 37421 const ids = this.root.structParentIds?.get(pageRef); 37422 if (!ids) { 37423 return null; 37424 } 37425 const map = new Map(); 37426 const numberTree = new NumberTree(parentTree, this.xref); 37427 for (const [elemId] of ids) { 37428 const obj = numberTree.getRaw(elemId); 37429 if (obj instanceof Ref) { 37430 map.set(elemId, obj); 37431 } 37432 } 37433 return map; 37434 } 37435 parse(pageRef) { 37436 if (!this.root || !this.rootDict || !(pageRef instanceof Ref)) { 37437 return; 37438 } 37439 const parentTree = this.rootDict.get("ParentTree"); 37440 if (!parentTree) { 37441 return; 37442 } 37443 const id = this.pageDict.get("StructParents"); 37444 const ids = this.root.structParentIds?.get(pageRef); 37445 if (!Number.isInteger(id) && !ids) { 37446 return; 37447 } 37448 const map = new Map(); 37449 const numberTree = new NumberTree(parentTree, this.xref); 37450 if (Number.isInteger(id)) { 37451 const parentArray = numberTree.get(id); 37452 if (Array.isArray(parentArray)) { 37453 for (const ref of parentArray) { 37454 if (ref instanceof Ref) { 37455 this.addNode(this.xref.fetch(ref), map); 37456 } 37457 } 37458 } 37459 } 37460 if (!ids) { 37461 return; 37462 } 37463 for (const [elemId, type] of ids) { 37464 const obj = numberTree.get(elemId); 37465 if (obj) { 37466 const elem = this.addNode(this.xref.fetchIfRef(obj), map); 37467 if (elem?.kids?.length === 1 && elem.kids[0].type === StructElementType.OBJECT) { 37468 elem.kids[0].type = type; 37469 } 37470 } 37471 } 37472 } 37473 addNode(dict, map, level = 0) { 37474 if (level > MAX_DEPTH) { 37475 warn("StructTree MAX_DEPTH reached."); 37476 return null; 37477 } 37478 if (!(dict instanceof Dict)) { 37479 return null; 37480 } 37481 if (map.has(dict)) { 37482 return map.get(dict); 37483 } 37484 const element = new StructElementNode(this, dict); 37485 map.set(dict, element); 37486 const parent = dict.get("P"); 37487 if (!(parent instanceof Dict) || isName(parent.get("Type"), "StructTreeRoot")) { 37488 if (!this.addTopLevelNode(dict, element)) { 37489 map.delete(dict); 37490 } 37491 return element; 37492 } 37493 const parentNode = this.addNode(parent, map, level + 1); 37494 if (!parentNode) { 37495 return element; 37496 } 37497 let save = false; 37498 for (const kid of parentNode.kids) { 37499 if (kid.type === StructElementType.ELEMENT && kid.dict === dict) { 37500 kid.parentNode = element; 37501 save = true; 37502 } 37503 } 37504 if (!save) { 37505 map.delete(dict); 37506 } 37507 return element; 37508 } 37509 addTopLevelNode(dict, element) { 37510 const obj = this.rootDict.get("K"); 37511 if (!obj) { 37512 return false; 37513 } 37514 if (obj instanceof Dict) { 37515 if (obj.objId !== dict.objId) { 37516 return false; 37517 } 37518 this.nodes[0] = element; 37519 return true; 37520 } 37521 if (!Array.isArray(obj)) { 37522 return true; 37523 } 37524 let save = false; 37525 for (let i = 0; i < obj.length; i++) { 37526 const kidRef = obj[i]; 37527 if (kidRef?.toString() === dict.objId) { 37528 this.nodes[i] = element; 37529 save = true; 37530 } 37531 } 37532 return save; 37533 } 37534 get serializable() { 37535 function nodeToSerializable(node, parent, level = 0) { 37536 if (level > MAX_DEPTH) { 37537 warn("StructTree too deep to be fully serialized."); 37538 return; 37539 } 37540 const obj = Object.create(null); 37541 obj.role = node.role; 37542 obj.children = []; 37543 parent.children.push(obj); 37544 let alt = node.dict.get("Alt"); 37545 if (typeof alt !== "string") { 37546 alt = node.dict.get("ActualText"); 37547 } 37548 if (typeof alt === "string") { 37549 obj.alt = stringToPDFString(alt); 37550 } 37551 const a = node.dict.get("A"); 37552 if (a instanceof Dict) { 37553 const bbox = lookupNormalRect(a.getArray("BBox"), null); 37554 if (bbox) { 37555 obj.bbox = bbox; 37556 } else { 37557 const width = a.get("Width"); 37558 const height = a.get("Height"); 37559 if (typeof width === "number" && width > 0 && typeof height === "number" && height > 0) { 37560 obj.bbox = [0, 0, width, height]; 37561 } 37562 } 37563 } 37564 const lang = node.dict.get("Lang"); 37565 if (typeof lang === "string") { 37566 obj.lang = stringToPDFString(lang); 37567 } 37568 for (const kid of node.kids) { 37569 const kidElement = kid.type === StructElementType.ELEMENT ? kid.parentNode : null; 37570 if (kidElement) { 37571 nodeToSerializable(kidElement, obj, level + 1); 37572 continue; 37573 } else if (kid.type === StructElementType.PAGE_CONTENT || kid.type === StructElementType.STREAM_CONTENT) { 37574 obj.children.push({ 37575 type: "content", 37576 id: `p${kid.pageObjId}_mc${kid.mcid}` 37577 }); 37578 } else if (kid.type === StructElementType.OBJECT) { 37579 obj.children.push({ 37580 type: "object", 37581 id: kid.refObjId 37582 }); 37583 } else if (kid.type === StructElementType.ANNOTATION) { 37584 obj.children.push({ 37585 type: "annotation", 37586 id: `${AnnotationPrefix}${kid.refObjId}` 37587 }); 37588 } 37589 } 37590 } 37591 const root = Object.create(null); 37592 root.children = []; 37593 root.role = "Root"; 37594 for (const child of this.nodes) { 37595 if (!child) { 37596 continue; 37597 } 37598 nodeToSerializable(child, root); 37599 } 37600 return root; 37601 } 37602} 37603 37604;// ./src/core/catalog.js 37605 37606 37607 37608 37609 37610 37611 37612 37613 37614 37615 37616const isRef = v => v instanceof Ref; 37617const isValidExplicitDest = _isValidExplicitDest.bind(null, isRef, isName); 37618function fetchDest(dest) { 37619 if (dest instanceof Dict) { 37620 dest = dest.get("D"); 37621 } 37622 return isValidExplicitDest(dest) ? dest : null; 37623} 37624function fetchRemoteDest(action) { 37625 let dest = action.get("D"); 37626 if (dest) { 37627 if (dest instanceof Name) { 37628 dest = dest.name; 37629 } 37630 if (typeof dest === "string") { 37631 return stringToPDFString(dest, true); 37632 } else if (isValidExplicitDest(dest)) { 37633 return JSON.stringify(dest); 37634 } 37635 } 37636 return null; 37637} 37638class Catalog { 37639 #actualNumPages = null; 37640 #catDict = null; 37641 builtInCMapCache = new Map(); 37642 fontCache = new RefSetCache(); 37643 globalColorSpaceCache = new GlobalColorSpaceCache(); 37644 globalImageCache = new GlobalImageCache(); 37645 nonBlendModesSet = new RefSet(); 37646 pageDictCache = new RefSetCache(); 37647 pageIndexCache = new RefSetCache(); 37648 pageKidsCountCache = new RefSetCache(); 37649 standardFontDataCache = new Map(); 37650 systemFontCache = new Map(); 37651 constructor(pdfManager, xref) { 37652 this.pdfManager = pdfManager; 37653 this.xref = xref; 37654 this.#catDict = xref.getCatalogObj(); 37655 if (!(this.#catDict instanceof Dict)) { 37656 throw new FormatError("Catalog object is not a dictionary."); 37657 } 37658 this.toplevelPagesDict; 37659 } 37660 cloneDict() { 37661 return this.#catDict.clone(); 37662 } 37663 get version() { 37664 const version = this.#catDict.get("Version"); 37665 if (version instanceof Name) { 37666 if (PDF_VERSION_REGEXP.test(version.name)) { 37667 return shadow(this, "version", version.name); 37668 } 37669 warn(`Invalid PDF catalog version: ${version.name}`); 37670 } 37671 return shadow(this, "version", null); 37672 } 37673 get lang() { 37674 const lang = this.#catDict.get("Lang"); 37675 return shadow(this, "lang", lang && typeof lang === "string" ? stringToPDFString(lang) : null); 37676 } 37677 get needsRendering() { 37678 const needsRendering = this.#catDict.get("NeedsRendering"); 37679 return shadow(this, "needsRendering", typeof needsRendering === "boolean" ? needsRendering : false); 37680 } 37681 get collection() { 37682 let collection = null; 37683 try { 37684 const obj = this.#catDict.get("Collection"); 37685 if (obj instanceof Dict && obj.size > 0) { 37686 collection = obj; 37687 } 37688 } catch (ex) { 37689 if (ex instanceof MissingDataException) { 37690 throw ex; 37691 } 37692 info("Cannot fetch Collection entry; assuming no collection is present."); 37693 } 37694 return shadow(this, "collection", collection); 37695 } 37696 get acroForm() { 37697 let acroForm = null; 37698 try { 37699 const obj = this.#catDict.get("AcroForm"); 37700 if (obj instanceof Dict && obj.size > 0) { 37701 acroForm = obj; 37702 } 37703 } catch (ex) { 37704 if (ex instanceof MissingDataException) { 37705 throw ex; 37706 } 37707 info("Cannot fetch AcroForm entry; assuming no forms are present."); 37708 } 37709 return shadow(this, "acroForm", acroForm); 37710 } 37711 get acroFormRef() { 37712 const value = this.#catDict.getRaw("AcroForm"); 37713 return shadow(this, "acroFormRef", value instanceof Ref ? value : null); 37714 } 37715 get metadata() { 37716 const streamRef = this.#catDict.getRaw("Metadata"); 37717 if (!(streamRef instanceof Ref)) { 37718 return shadow(this, "metadata", null); 37719 } 37720 let metadata = null; 37721 try { 37722 const stream = this.xref.fetch(streamRef, !this.xref.encrypt?.encryptMetadata); 37723 if (stream instanceof BaseStream && stream.dict instanceof Dict) { 37724 const type = stream.dict.get("Type"); 37725 const subtype = stream.dict.get("Subtype"); 37726 if (isName(type, "Metadata") && isName(subtype, "XML")) { 37727 const data = stringToUTF8String(stream.getString()); 37728 if (data) { 37729 metadata = new MetadataParser(data).serializable; 37730 } 37731 } 37732 } 37733 } catch (ex) { 37734 if (ex instanceof MissingDataException) { 37735 throw ex; 37736 } 37737 info(`Skipping invalid Metadata: "${ex}".`); 37738 } 37739 return shadow(this, "metadata", metadata); 37740 } 37741 get markInfo() { 37742 let markInfo = null; 37743 try { 37744 markInfo = this.#readMarkInfo(); 37745 } catch (ex) { 37746 if (ex instanceof MissingDataException) { 37747 throw ex; 37748 } 37749 warn("Unable to read mark info."); 37750 } 37751 return shadow(this, "markInfo", markInfo); 37752 } 37753 #readMarkInfo() { 37754 const obj = this.#catDict.get("MarkInfo"); 37755 if (!(obj instanceof Dict)) { 37756 return null; 37757 } 37758 const markInfo = { 37759 Marked: false, 37760 UserProperties: false, 37761 Suspects: false 37762 }; 37763 for (const key in markInfo) { 37764 const value = obj.get(key); 37765 if (typeof value === "boolean") { 37766 markInfo[key] = value; 37767 } 37768 } 37769 return markInfo; 37770 } 37771 get structTreeRoot() { 37772 let structTree = null; 37773 try { 37774 structTree = this.#readStructTreeRoot(); 37775 } catch (ex) { 37776 if (ex instanceof MissingDataException) { 37777 throw ex; 37778 } 37779 warn("Unable read to structTreeRoot info."); 37780 } 37781 return shadow(this, "structTreeRoot", structTree); 37782 } 37783 #readStructTreeRoot() { 37784 const rawObj = this.#catDict.getRaw("StructTreeRoot"); 37785 const obj = this.xref.fetchIfRef(rawObj); 37786 if (!(obj instanceof Dict)) { 37787 return null; 37788 } 37789 const root = new StructTreeRoot(this.xref, obj, rawObj); 37790 root.init(); 37791 return root; 37792 } 37793 get toplevelPagesDict() { 37794 const pagesObj = this.#catDict.get("Pages"); 37795 if (!(pagesObj instanceof Dict)) { 37796 throw new FormatError("Invalid top-level pages dictionary."); 37797 } 37798 return shadow(this, "toplevelPagesDict", pagesObj); 37799 } 37800 get documentOutline() { 37801 let obj = null; 37802 try { 37803 obj = this.#readDocumentOutline(); 37804 } catch (ex) { 37805 if (ex instanceof MissingDataException) { 37806 throw ex; 37807 } 37808 warn("Unable to read document outline."); 37809 } 37810 return shadow(this, "documentOutline", obj); 37811 } 37812 #readDocumentOutline() { 37813 let obj = this.#catDict.get("Outlines"); 37814 if (!(obj instanceof Dict)) { 37815 return null; 37816 } 37817 obj = obj.getRaw("First"); 37818 if (!(obj instanceof Ref)) { 37819 return null; 37820 } 37821 const root = { 37822 items: [] 37823 }; 37824 const queue = [{ 37825 obj, 37826 parent: root 37827 }]; 37828 const processed = new RefSet(); 37829 processed.put(obj); 37830 const xref = this.xref, 37831 blackColor = new Uint8ClampedArray(3); 37832 while (queue.length > 0) { 37833 const i = queue.shift(); 37834 const outlineDict = xref.fetchIfRef(i.obj); 37835 if (outlineDict === null) { 37836 continue; 37837 } 37838 if (!outlineDict.has("Title")) { 37839 warn("Invalid outline item encountered."); 37840 } 37841 const data = { 37842 url: null, 37843 dest: null, 37844 action: null 37845 }; 37846 Catalog.parseDestDictionary({ 37847 destDict: outlineDict, 37848 resultObj: data, 37849 docBaseUrl: this.baseUrl, 37850 docAttachments: this.attachments 37851 }); 37852 const title = outlineDict.get("Title"); 37853 const flags = outlineDict.get("F") || 0; 37854 const color = outlineDict.getArray("C"); 37855 const count = outlineDict.get("Count"); 37856 let rgbColor = blackColor; 37857 if (isNumberArray(color, 3) && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) { 37858 rgbColor = ColorSpaceUtils.rgb.getRgb(color, 0); 37859 } 37860 const outlineItem = { 37861 action: data.action, 37862 attachment: data.attachment, 37863 dest: data.dest, 37864 url: data.url, 37865 unsafeUrl: data.unsafeUrl, 37866 newWindow: data.newWindow, 37867 setOCGState: data.setOCGState, 37868 title: typeof title === "string" ? stringToPDFString(title) : "", 37869 color: rgbColor, 37870 count: Number.isInteger(count) ? count : undefined, 37871 bold: !!(flags & 2), 37872 italic: !!(flags & 1), 37873 items: [] 37874 }; 37875 i.parent.items.push(outlineItem); 37876 obj = outlineDict.getRaw("First"); 37877 if (obj instanceof Ref && !processed.has(obj)) { 37878 queue.push({ 37879 obj, 37880 parent: outlineItem 37881 }); 37882 processed.put(obj); 37883 } 37884 obj = outlineDict.getRaw("Next"); 37885 if (obj instanceof Ref && !processed.has(obj)) { 37886 queue.push({ 37887 obj, 37888 parent: i.parent 37889 }); 37890 processed.put(obj); 37891 } 37892 } 37893 return root.items.length > 0 ? root.items : null; 37894 } 37895 get permissions() { 37896 let permissions = null; 37897 try { 37898 permissions = this.#readPermissions(); 37899 } catch (ex) { 37900 if (ex instanceof MissingDataException) { 37901 throw ex; 37902 } 37903 warn("Unable to read permissions."); 37904 } 37905 return shadow(this, "permissions", permissions); 37906 } 37907 #readPermissions() { 37908 const encrypt = this.xref.trailer.get("Encrypt"); 37909 if (!(encrypt instanceof Dict)) { 37910 return null; 37911 } 37912 let flags = encrypt.get("P"); 37913 if (typeof flags !== "number") { 37914 return null; 37915 } 37916 flags += 2 ** 32; 37917 const permissions = []; 37918 for (const key in PermissionFlag) { 37919 const value = PermissionFlag[key]; 37920 if (flags & value) { 37921 permissions.push(value); 37922 } 37923 } 37924 return permissions; 37925 } 37926 get optionalContentConfig() { 37927 let config = null; 37928 try { 37929 const properties = this.#catDict.get("OCProperties"); 37930 if (!properties) { 37931 return shadow(this, "optionalContentConfig", null); 37932 } 37933 const defaultConfig = properties.get("D"); 37934 if (!defaultConfig) { 37935 return shadow(this, "optionalContentConfig", null); 37936 } 37937 const groupsData = properties.get("OCGs"); 37938 if (!Array.isArray(groupsData)) { 37939 return shadow(this, "optionalContentConfig", null); 37940 } 37941 const groupRefCache = new RefSetCache(); 37942 for (const groupRef of groupsData) { 37943 if (!(groupRef instanceof Ref) || groupRefCache.has(groupRef)) { 37944 continue; 37945 } 37946 groupRefCache.put(groupRef, this.#readOptionalContentGroup(groupRef)); 37947 } 37948 config = this.#readOptionalContentConfig(defaultConfig, groupRefCache); 37949 } catch (ex) { 37950 if (ex instanceof MissingDataException) { 37951 throw ex; 37952 } 37953 warn(`Unable to read optional content config: ${ex}`); 37954 } 37955 return shadow(this, "optionalContentConfig", config); 37956 } 37957 #readOptionalContentGroup(groupRef) { 37958 const group = this.xref.fetch(groupRef); 37959 const obj = { 37960 id: groupRef.toString(), 37961 name: null, 37962 intent: null, 37963 usage: { 37964 print: null, 37965 view: null 37966 }, 37967 rbGroups: [] 37968 }; 37969 const name = group.get("Name"); 37970 if (typeof name === "string") { 37971 obj.name = stringToPDFString(name); 37972 } 37973 let intent = group.getArray("Intent"); 37974 if (!Array.isArray(intent)) { 37975 intent = [intent]; 37976 } 37977 if (intent.every(i => i instanceof Name)) { 37978 obj.intent = intent.map(i => i.name); 37979 } 37980 const usage = group.get("Usage"); 37981 if (!(usage instanceof Dict)) { 37982 return obj; 37983 } 37984 const usageObj = obj.usage; 37985 const print = usage.get("Print"); 37986 if (print instanceof Dict) { 37987 const printState = print.get("PrintState"); 37988 if (printState instanceof Name) { 37989 switch (printState.name) { 37990 case "ON": 37991 case "OFF": 37992 usageObj.print = { 37993 printState: printState.name 37994 }; 37995 } 37996 } 37997 } 37998 const view = usage.get("View"); 37999 if (view instanceof Dict) { 38000 const viewState = view.get("ViewState"); 38001 if (viewState instanceof Name) { 38002 switch (viewState.name) { 38003 case "ON": 38004 case "OFF": 38005 usageObj.view = { 38006 viewState: viewState.name 38007 }; 38008 } 38009 } 38010 } 38011 return obj; 38012 } 38013 #readOptionalContentConfig(config, groupRefCache) { 38014 function parseOnOff(refs) { 38015 const onParsed = []; 38016 if (Array.isArray(refs)) { 38017 for (const value of refs) { 38018 if (value instanceof Ref && groupRefCache.has(value)) { 38019 onParsed.push(value.toString()); 38020 } 38021 } 38022 } 38023 return onParsed; 38024 } 38025 function parseOrder(refs, nestedLevels = 0) { 38026 if (!Array.isArray(refs)) { 38027 return null; 38028 } 38029 const order = []; 38030 for (const value of refs) { 38031 if (value instanceof Ref && groupRefCache.has(value)) { 38032 parsedOrderRefs.put(value); 38033 order.push(value.toString()); 38034 continue; 38035 } 38036 const nestedOrder = parseNestedOrder(value, nestedLevels); 38037 if (nestedOrder) { 38038 order.push(nestedOrder); 38039 } 38040 } 38041 if (nestedLevels > 0) { 38042 return order; 38043 } 38044 const hiddenGroups = []; 38045 for (const [groupRef] of groupRefCache.items()) { 38046 if (parsedOrderRefs.has(groupRef)) { 38047 continue; 38048 } 38049 hiddenGroups.push(groupRef.toString()); 38050 } 38051 if (hiddenGroups.length) { 38052 order.push({ 38053 name: null, 38054 order: hiddenGroups 38055 }); 38056 } 38057 return order; 38058 } 38059 function parseNestedOrder(ref, nestedLevels) { 38060 if (++nestedLevels > MAX_NESTED_LEVELS) { 38061 warn("parseNestedOrder - reached MAX_NESTED_LEVELS."); 38062 return null; 38063 } 38064 const value = xref.fetchIfRef(ref); 38065 if (!Array.isArray(value)) { 38066 return null; 38067 } 38068 const nestedName = xref.fetchIfRef(value[0]); 38069 if (typeof nestedName !== "string") { 38070 return null; 38071 } 38072 const nestedOrder = parseOrder(value.slice(1), nestedLevels); 38073 if (!nestedOrder?.length) { 38074 return null; 38075 } 38076 return { 38077 name: stringToPDFString(nestedName), 38078 order: nestedOrder 38079 }; 38080 } 38081 function parseRBGroups(rbGroups) { 38082 if (!Array.isArray(rbGroups)) { 38083 return; 38084 } 38085 for (const value of rbGroups) { 38086 const rbGroup = xref.fetchIfRef(value); 38087 if (!Array.isArray(rbGroup) || !rbGroup.length) { 38088 continue; 38089 } 38090 const parsedRbGroup = new Set(); 38091 for (const ref of rbGroup) { 38092 if (ref instanceof Ref && groupRefCache.has(ref) && !parsedRbGroup.has(ref.toString())) { 38093 parsedRbGroup.add(ref.toString()); 38094 groupRefCache.get(ref).rbGroups.push(parsedRbGroup); 38095 } 38096 } 38097 } 38098 } 38099 const xref = this.xref, 38100 parsedOrderRefs = new RefSet(), 38101 MAX_NESTED_LEVELS = 10; 38102 parseRBGroups(config.get("RBGroups")); 38103 return { 38104 name: typeof config.get("Name") === "string" ? stringToPDFString(config.get("Name")) : null, 38105 creator: typeof config.get("Creator") === "string" ? stringToPDFString(config.get("Creator")) : null, 38106 baseState: config.get("BaseState") instanceof Name ? config.get("BaseState").name : null, 38107 on: parseOnOff(config.get("ON")), 38108 off: parseOnOff(config.get("OFF")), 38109 order: parseOrder(config.get("Order")), 38110 groups: [...groupRefCache] 38111 }; 38112 } 38113 setActualNumPages(num = null) { 38114 this.#actualNumPages = num; 38115 } 38116 get hasActualNumPages() { 38117 return this.#actualNumPages !== null; 38118 } 38119 get _pagesCount() { 38120 const obj = this.toplevelPagesDict.get("Count"); 38121 if (!Number.isInteger(obj)) { 38122 throw new FormatError("Page count in top-level pages dictionary is not an integer."); 38123 } 38124 return shadow(this, "_pagesCount", obj); 38125 } 38126 get numPages() { 38127 return this.#actualNumPages ?? this._pagesCount; 38128 } 38129 get destinations() { 38130 const rawDests = this.#readDests(), 38131 dests = Object.create(null); 38132 for (const obj of rawDests) { 38133 if (obj instanceof NameTree) { 38134 for (const [key, value] of obj.getAll()) { 38135 const dest = fetchDest(value); 38136 if (dest) { 38137 dests[stringToPDFString(key, true)] = dest; 38138 } 38139 } 38140 } else if (obj instanceof Dict) { 38141 for (const [key, value] of obj) { 38142 const dest = fetchDest(value); 38143 if (dest) { 38144 dests[stringToPDFString(key, true)] ||= dest; 38145 } 38146 } 38147 } 38148 } 38149 return shadow(this, "destinations", dests); 38150 } 38151 getDestination(id) { 38152 if (this.hasOwnProperty("destinations")) { 38153 return this.destinations[id] ?? null; 38154 } 38155 const rawDests = this.#readDests(); 38156 for (const obj of rawDests) { 38157 if (obj instanceof NameTree || obj instanceof Dict) { 38158 const dest = fetchDest(obj.get(id)); 38159 if (dest) { 38160 return dest; 38161 } 38162 } 38163 } 38164 if (rawDests.length) { 38165 const dest = this.destinations[id]; 38166 if (dest) { 38167 return dest; 38168 } 38169 } 38170 return null; 38171 } 38172 #readDests() { 38173 const obj = this.#catDict.get("Names"); 38174 const rawDests = []; 38175 if (obj?.has("Dests")) { 38176 rawDests.push(new NameTree(obj.getRaw("Dests"), this.xref)); 38177 } 38178 if (this.#catDict.has("Dests")) { 38179 rawDests.push(this.#catDict.get("Dests")); 38180 } 38181 return rawDests; 38182 } 38183 get pageLabels() { 38184 let obj = null; 38185 try { 38186 obj = this.#readPageLabels(); 38187 } catch (ex) { 38188 if (ex instanceof MissingDataException) { 38189 throw ex; 38190 } 38191 warn("Unable to read page labels."); 38192 } 38193 return shadow(this, "pageLabels", obj); 38194 } 38195 #readPageLabels() { 38196 const obj = this.#catDict.getRaw("PageLabels"); 38197 if (!obj) { 38198 return null; 38199 } 38200 const pageLabels = new Array(this.numPages); 38201 let style = null, 38202 prefix = ""; 38203 const numberTree = new NumberTree(obj, this.xref); 38204 const nums = numberTree.getAll(); 38205 let currentLabel = "", 38206 currentIndex = 1; 38207 for (let i = 0, ii = this.numPages; i < ii; i++) { 38208 const labelDict = nums.get(i); 38209 if (labelDict !== undefined) { 38210 if (!(labelDict instanceof Dict)) { 38211 throw new FormatError("PageLabel is not a dictionary."); 38212 } 38213 if (labelDict.has("Type") && !isName(labelDict.get("Type"), "PageLabel")) { 38214 throw new FormatError("Invalid type in PageLabel dictionary."); 38215 } 38216 if (labelDict.has("S")) { 38217 const s = labelDict.get("S"); 38218 if (!(s instanceof Name)) { 38219 throw new FormatError("Invalid style in PageLabel dictionary."); 38220 } 38221 style = s.name; 38222 } else { 38223 style = null; 38224 } 38225 if (labelDict.has("P")) { 38226 const p = labelDict.get("P"); 38227 if (typeof p !== "string") { 38228 throw new FormatError("Invalid prefix in PageLabel dictionary."); 38229 } 38230 prefix = stringToPDFString(p); 38231 } else { 38232 prefix = ""; 38233 } 38234 if (labelDict.has("St")) { 38235 const st = labelDict.get("St"); 38236 if (!(Number.isInteger(st) && st >= 1)) { 38237 throw new FormatError("Invalid start in PageLabel dictionary."); 38238 } 38239 currentIndex = st; 38240 } else { 38241 currentIndex = 1; 38242 } 38243 } 38244 switch (style) { 38245 case "D": 38246 currentLabel = currentIndex; 38247 break; 38248 case "R": 38249 case "r": 38250 currentLabel = toRomanNumerals(currentIndex, style === "r"); 38251 break; 38252 case "A": 38253 case "a": 38254 const LIMIT = 26; 38255 const A_UPPER_CASE = 0x41, 38256 A_LOWER_CASE = 0x61; 38257 const baseCharCode = style === "a" ? A_LOWER_CASE : A_UPPER_CASE; 38258 const letterIndex = currentIndex - 1; 38259 const character = String.fromCharCode(baseCharCode + letterIndex % LIMIT); 38260 currentLabel = character.repeat(Math.floor(letterIndex / LIMIT) + 1); 38261 break; 38262 default: 38263 if (style) { 38264 throw new FormatError(`Invalid style "${style}" in PageLabel dictionary.`); 38265 } 38266 currentLabel = ""; 38267 } 38268 pageLabels[i] = prefix + currentLabel; 38269 currentIndex++; 38270 } 38271 return pageLabels; 38272 } 38273 get pageLayout() { 38274 const obj = this.#catDict.get("PageLayout"); 38275 let pageLayout = ""; 38276 if (obj instanceof Name) { 38277 switch (obj.name) { 38278 case "SinglePage": 38279 case "OneColumn": 38280 case "TwoColumnLeft": 38281 case "TwoColumnRight": 38282 case "TwoPageLeft": 38283 case "TwoPageRight": 38284 pageLayout = obj.name; 38285 } 38286 } 38287 return shadow(this, "pageLayout", pageLayout); 38288 } 38289 get pageMode() { 38290 const obj = this.#catDict.get("PageMode"); 38291 let pageMode = "UseNone"; 38292 if (obj instanceof Name) { 38293 switch (obj.name) { 38294 case "UseNone": 38295 case "UseOutlines": 38296 case "UseThumbs": 38297 case "FullScreen": 38298 case "UseOC": 38299 case "UseAttachments": 38300 pageMode = obj.name; 38301 } 38302 } 38303 return shadow(this, "pageMode", pageMode); 38304 } 38305 get viewerPreferences() { 38306 const obj = this.#catDict.get("ViewerPreferences"); 38307 if (!(obj instanceof Dict)) { 38308 return shadow(this, "viewerPreferences", null); 38309 } 38310 let prefs = null; 38311 for (const [key, value] of obj) { 38312 let prefValue; 38313 switch (key) { 38314 case "HideToolbar": 38315 case "HideMenubar": 38316 case "HideWindowUI": 38317 case "FitWindow": 38318 case "CenterWindow": 38319 case "DisplayDocTitle": 38320 case "PickTrayByPDFSize": 38321 if (typeof value === "boolean") { 38322 prefValue = value; 38323 } 38324 break; 38325 case "NonFullScreenPageMode": 38326 if (value instanceof Name) { 38327 switch (value.name) { 38328 case "UseNone": 38329 case "UseOutlines": 38330 case "UseThumbs": 38331 case "UseOC": 38332 prefValue = value.name; 38333 break; 38334 default: 38335 prefValue = "UseNone"; 38336 } 38337 } 38338 break; 38339 case "Direction": 38340 if (value instanceof Name) { 38341 switch (value.name) { 38342 case "L2R": 38343 case "R2L": 38344 prefValue = value.name; 38345 break; 38346 default: 38347 prefValue = "L2R"; 38348 } 38349 } 38350 break; 38351 case "ViewArea": 38352 case "ViewClip": 38353 case "PrintArea": 38354 case "PrintClip": 38355 if (value instanceof Name) { 38356 switch (value.name) { 38357 case "MediaBox": 38358 case "CropBox": 38359 case "BleedBox": 38360 case "TrimBox": 38361 case "ArtBox": 38362 prefValue = value.name; 38363 break; 38364 default: 38365 prefValue = "CropBox"; 38366 } 38367 } 38368 break; 38369 case "PrintScaling": 38370 if (value instanceof Name) { 38371 switch (value.name) { 38372 case "None": 38373 case "AppDefault": 38374 prefValue = value.name; 38375 break; 38376 default: 38377 prefValue = "AppDefault"; 38378 } 38379 } 38380 break; 38381 case "Duplex": 38382 if (value instanceof Name) { 38383 switch (value.name) { 38384 case "Simplex": 38385 case "DuplexFlipShortEdge": 38386 case "DuplexFlipLongEdge": 38387 prefValue = value.name; 38388 break; 38389 default: 38390 prefValue = "None"; 38391 } 38392 } 38393 break; 38394 case "PrintPageRange": 38395 if (Array.isArray(value) && value.length % 2 === 0) { 38396 const isValid = value.every((page, i, arr) => Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= this.numPages); 38397 if (isValid) { 38398 prefValue = value; 38399 } 38400 } 38401 break; 38402 case "NumCopies": 38403 if (Number.isInteger(value) && value > 0) { 38404 prefValue = value; 38405 } 38406 break; 38407 default: 38408 warn(`Ignoring non-standard key in ViewerPreferences: ${key}.`); 38409 continue; 38410 } 38411 if (prefValue === undefined) { 38412 warn(`Bad value, for key "${key}", in ViewerPreferences: ${value}.`); 38413 continue; 38414 } 38415 prefs ??= Object.create(null); 38416 prefs[key] = prefValue; 38417 } 38418 return shadow(this, "viewerPreferences", prefs); 38419 } 38420 get openAction() { 38421 const obj = this.#catDict.get("OpenAction"); 38422 const openAction = Object.create(null); 38423 if (obj instanceof Dict) { 38424 const destDict = new Dict(this.xref); 38425 destDict.set("A", obj); 38426 const resultObj = { 38427 url: null, 38428 dest: null, 38429 action: null 38430 }; 38431 Catalog.parseDestDictionary({ 38432 destDict, 38433 resultObj 38434 }); 38435 if (Array.isArray(resultObj.dest)) { 38436 openAction.dest = resultObj.dest; 38437 } else if (resultObj.action) { 38438 openAction.action = resultObj.action; 38439 } 38440 } else if (isValidExplicitDest(obj)) { 38441 openAction.dest = obj; 38442 } 38443 return shadow(this, "openAction", objectSize(openAction) > 0 ? openAction : null); 38444 } 38445 get attachments() { 38446 const obj = this.#catDict.get("Names"); 38447 let attachments = null; 38448 if (obj instanceof Dict && obj.has("EmbeddedFiles")) { 38449 const nameTree = new NameTree(obj.getRaw("EmbeddedFiles"), this.xref); 38450 for (const [key, value] of nameTree.getAll()) { 38451 const fs = new FileSpec(value, this.xref); 38452 attachments ??= Object.create(null); 38453 attachments[stringToPDFString(key, true)] = fs.serializable; 38454 } 38455 } 38456 return shadow(this, "attachments", attachments); 38457 } 38458 get xfaImages() { 38459 const obj = this.#catDict.get("Names"); 38460 let xfaImages = null; 38461 if (obj instanceof Dict && obj.has("XFAImages")) { 38462 const nameTree = new NameTree(obj.getRaw("XFAImages"), this.xref); 38463 for (const [key, value] of nameTree.getAll()) { 38464 if (value instanceof BaseStream) { 38465 xfaImages ??= new Map(); 38466 xfaImages.set(stringToPDFString(key, true), value.getBytes()); 38467 } 38468 } 38469 } 38470 return shadow(this, "xfaImages", xfaImages); 38471 } 38472 #collectJavaScript() { 38473 const obj = this.#catDict.get("Names"); 38474 let javaScript = null; 38475 function appendIfJavaScriptDict(name, jsDict) { 38476 if (!(jsDict instanceof Dict)) { 38477 return; 38478 } 38479 if (!isName(jsDict.get("S"), "JavaScript")) { 38480 return; 38481 } 38482 let js = jsDict.get("JS"); 38483 if (js instanceof BaseStream) { 38484 js = js.getString(); 38485 } else if (typeof js !== "string") { 38486 return; 38487 } 38488 js = stringToPDFString(js, true).replaceAll("\x00", ""); 38489 if (js) { 38490 (javaScript ||= new Map()).set(name, js); 38491 } 38492 } 38493 if (obj instanceof Dict && obj.has("JavaScript")) { 38494 const nameTree = new NameTree(obj.getRaw("JavaScript"), this.xref); 38495 for (const [key, value] of nameTree.getAll()) { 38496 appendIfJavaScriptDict(stringToPDFString(key, true), value); 38497 } 38498 } 38499 const openAction = this.#catDict.get("OpenAction"); 38500 if (openAction) { 38501 appendIfJavaScriptDict("OpenAction", openAction); 38502 } 38503 return javaScript; 38504 } 38505 get jsActions() { 38506 const javaScript = this.#collectJavaScript(); 38507 let actions = collectActions(this.xref, this.#catDict, DocumentActionEventType); 38508 if (javaScript) { 38509 actions ||= Object.create(null); 38510 for (const [key, val] of javaScript) { 38511 if (key in actions) { 38512 actions[key].push(val); 38513 } else { 38514 actions[key] = [val]; 38515 } 38516 } 38517 } 38518 return shadow(this, "jsActions", actions); 38519 } 38520 async cleanup(manuallyTriggered = false) { 38521 clearGlobalCaches(); 38522 this.globalColorSpaceCache.clear(); 38523 this.globalImageCache.clear(manuallyTriggered); 38524 this.pageKidsCountCache.clear(); 38525 this.pageIndexCache.clear(); 38526 this.pageDictCache.clear(); 38527 this.nonBlendModesSet.clear(); 38528 for (const { 38529 dict 38530 } of await Promise.all(this.fontCache)) { 38531 delete dict.cacheKey; 38532 } 38533 this.fontCache.clear(); 38534 this.builtInCMapCache.clear(); 38535 this.standardFontDataCache.clear(); 38536 this.systemFontCache.clear(); 38537 } 38538 async getPageDict(pageIndex) { 38539 const nodesToVisit = [this.toplevelPagesDict]; 38540 const visitedNodes = new RefSet(); 38541 const pagesRef = this.#catDict.getRaw("Pages"); 38542 if (pagesRef instanceof Ref) { 38543 visitedNodes.put(pagesRef); 38544 } 38545 const xref = this.xref, 38546 pageKidsCountCache = this.pageKidsCountCache, 38547 pageIndexCache = this.pageIndexCache, 38548 pageDictCache = this.pageDictCache; 38549 let currentPageIndex = 0; 38550 while (nodesToVisit.length) { 38551 const currentNode = nodesToVisit.pop(); 38552 if (currentNode instanceof Ref) { 38553 const count = pageKidsCountCache.get(currentNode); 38554 if (count >= 0 && currentPageIndex + count <= pageIndex) { 38555 currentPageIndex += count; 38556 continue; 38557 } 38558 if (visitedNodes.has(currentNode)) { 38559 throw new FormatError("Pages tree contains circular reference."); 38560 } 38561 visitedNodes.put(currentNode); 38562 const obj = await (pageDictCache.get(currentNode) || xref.fetchAsync(currentNode)); 38563 if (obj instanceof Dict) { 38564 let type = obj.getRaw("Type"); 38565 if (type instanceof Ref) { 38566 type = await xref.fetchAsync(type); 38567 } 38568 if (isName(type, "Page") || !obj.has("Kids")) { 38569 if (!pageKidsCountCache.has(currentNode)) { 38570 pageKidsCountCache.put(currentNode, 1); 38571 } 38572 if (!pageIndexCache.has(currentNode)) { 38573 pageIndexCache.put(currentNode, currentPageIndex); 38574 } 38575 if (currentPageIndex === pageIndex) { 38576 return [obj, currentNode]; 38577 } 38578 currentPageIndex++; 38579 continue; 38580 } 38581 } 38582 nodesToVisit.push(obj); 38583 continue; 38584 } 38585 if (!(currentNode instanceof Dict)) { 38586 throw new FormatError("Page dictionary kid reference points to wrong type of object."); 38587 } 38588 const { 38589 objId 38590 } = currentNode; 38591 let count = currentNode.getRaw("Count"); 38592 if (count instanceof Ref) { 38593 count = await xref.fetchAsync(count); 38594 } 38595 if (Number.isInteger(count) && count >= 0) { 38596 if (objId && !pageKidsCountCache.has(objId)) { 38597 pageKidsCountCache.put(objId, count); 38598 } 38599 if (currentPageIndex + count <= pageIndex) { 38600 currentPageIndex += count; 38601 continue; 38602 } 38603 } 38604 let kids = currentNode.getRaw("Kids"); 38605 if (kids instanceof Ref) { 38606 kids = await xref.fetchAsync(kids); 38607 } 38608 if (!Array.isArray(kids)) { 38609 let type = currentNode.getRaw("Type"); 38610 if (type instanceof Ref) { 38611 type = await xref.fetchAsync(type); 38612 } 38613 if (isName(type, "Page") || !currentNode.has("Kids")) { 38614 if (currentPageIndex === pageIndex) { 38615 return [currentNode, null]; 38616 } 38617 currentPageIndex++; 38618 continue; 38619 } 38620 throw new FormatError("Page dictionary kids object is not an array."); 38621 } 38622 for (let last = kids.length - 1; last >= 0; last--) { 38623 const lastKid = kids[last]; 38624 nodesToVisit.push(lastKid); 38625 if (currentNode === this.toplevelPagesDict && lastKid instanceof Ref && !pageDictCache.has(lastKid)) { 38626 pageDictCache.put(lastKid, xref.fetchAsync(lastKid)); 38627 } 38628 } 38629 } 38630 throw new Error(`Page index ${pageIndex} not found.`); 38631 } 38632 async getAllPageDicts(recoveryMode = false) { 38633 const { 38634 ignoreErrors 38635 } = this.pdfManager.evaluatorOptions; 38636 const queue = [{ 38637 currentNode: this.toplevelPagesDict, 38638 posInKids: 0 38639 }]; 38640 const visitedNodes = new RefSet(); 38641 const pagesRef = this.#catDict.getRaw("Pages"); 38642 if (pagesRef instanceof Ref) { 38643 visitedNodes.put(pagesRef); 38644 } 38645 const map = new Map(), 38646 xref = this.xref, 38647 pageIndexCache = this.pageIndexCache; 38648 let pageIndex = 0; 38649 function addPageDict(pageDict, pageRef) { 38650 if (pageRef && !pageIndexCache.has(pageRef)) { 38651 pageIndexCache.put(pageRef, pageIndex); 38652 } 38653 map.set(pageIndex++, [pageDict, pageRef]); 38654 } 38655 function addPageError(error) { 38656 if (error instanceof XRefEntryException && !recoveryMode) { 38657 throw error; 38658 } 38659 if (recoveryMode && ignoreErrors && pageIndex === 0) { 38660 warn(`getAllPageDicts - Skipping invalid first page: "${error}".`); 38661 error = Dict.empty; 38662 } 38663 map.set(pageIndex++, [error, null]); 38664 } 38665 while (queue.length > 0) { 38666 const queueItem = queue.at(-1); 38667 const { 38668 currentNode, 38669 posInKids 38670 } = queueItem; 38671 let kids = currentNode.getRaw("Kids"); 38672 if (kids instanceof Ref) { 38673 try { 38674 kids = await xref.fetchAsync(kids); 38675 } catch (ex) { 38676 addPageError(ex); 38677 break; 38678 } 38679 } 38680 if (!Array.isArray(kids)) { 38681 addPageError(new FormatError("Page dictionary kids object is not an array.")); 38682 break; 38683 } 38684 if (posInKids >= kids.length) { 38685 queue.pop(); 38686 continue; 38687 } 38688 const kidObj = kids[posInKids]; 38689 let obj; 38690 if (kidObj instanceof Ref) { 38691 if (visitedNodes.has(kidObj)) { 38692 addPageError(new FormatError("Pages tree contains circular reference.")); 38693 break; 38694 } 38695 visitedNodes.put(kidObj); 38696 try { 38697 obj = await xref.fetchAsync(kidObj); 38698 } catch (ex) { 38699 addPageError(ex); 38700 break; 38701 } 38702 } else { 38703 obj = kidObj; 38704 } 38705 if (!(obj instanceof Dict)) { 38706 addPageError(new FormatError("Page dictionary kid reference points to wrong type of object.")); 38707 break; 38708 } 38709 let type = obj.getRaw("Type"); 38710 if (type instanceof Ref) { 38711 try { 38712 type = await xref.fetchAsync(type); 38713 } catch (ex) { 38714 addPageError(ex); 38715 break; 38716 } 38717 } 38718 if (isName(type, "Page") || !obj.has("Kids")) { 38719 addPageDict(obj, kidObj instanceof Ref ? kidObj : null); 38720 } else { 38721 queue.push({ 38722 currentNode: obj, 38723 posInKids: 0 38724 }); 38725 } 38726 queueItem.posInKids++; 38727 } 38728 return map; 38729 } 38730 getPageIndex(pageRef) { 38731 const cachedPageIndex = this.pageIndexCache.get(pageRef); 38732 if (cachedPageIndex !== undefined) { 38733 return Promise.resolve(cachedPageIndex); 38734 } 38735 const xref = this.xref; 38736 function pagesBeforeRef(kidRef) { 38737 let total = 0, 38738 parentRef; 38739 return xref.fetchAsync(kidRef).then(function (node) { 38740 if (isRefsEqual(kidRef, pageRef) && !isDict(node, "Page") && !(node instanceof Dict && !node.has("Type") && node.has("Contents"))) { 38741 throw new FormatError("The reference does not point to a /Page dictionary."); 38742 } 38743 if (!node) { 38744 return null; 38745 } 38746 if (!(node instanceof Dict)) { 38747 throw new FormatError("Node must be a dictionary."); 38748 } 38749 parentRef = node.getRaw("Parent"); 38750 return node.getAsync("Parent"); 38751 }).then(function (parent) { 38752 if (!parent) { 38753 return null; 38754 } 38755 if (!(parent instanceof Dict)) { 38756 throw new FormatError("Parent must be a dictionary."); 38757 } 38758 return parent.getAsync("Kids"); 38759 }).then(function (kids) { 38760 if (!kids) { 38761 return null; 38762 } 38763 const kidPromises = []; 38764 let found = false; 38765 for (const kid of kids) { 38766 if (!(kid instanceof Ref)) { 38767 throw new FormatError("Kid must be a reference."); 38768 } 38769 if (isRefsEqual(kid, kidRef)) { 38770 found = true; 38771 break; 38772 } 38773 kidPromises.push(xref.fetchAsync(kid).then(function (obj) { 38774 if (!(obj instanceof Dict)) { 38775 throw new FormatError("Kid node must be a dictionary."); 38776 } 38777 if (obj.has("Count")) { 38778 total += obj.get("Count"); 38779 } else { 38780 total++; 38781 } 38782 })); 38783 } 38784 if (!found) { 38785 throw new FormatError("Kid reference not found in parent's kids."); 38786 } 38787 return Promise.all(kidPromises).then(() => [total, parentRef]); 38788 }); 38789 } 38790 let total = 0; 38791 const next = ref => pagesBeforeRef(ref).then(args => { 38792 if (!args) { 38793 this.pageIndexCache.put(pageRef, total); 38794 return total; 38795 } 38796 const [count, parentRef] = args; 38797 total += count; 38798 return next(parentRef); 38799 }); 38800 return next(pageRef); 38801 } 38802 get baseUrl() { 38803 const uri = this.#catDict.get("URI"); 38804 if (uri instanceof Dict) { 38805 const base = uri.get("Base"); 38806 if (typeof base === "string") { 38807 const absoluteUrl = createValidAbsoluteUrl(base, null, { 38808 tryConvertEncoding: true 38809 }); 38810 if (absoluteUrl) { 38811 return shadow(this, "baseUrl", absoluteUrl.href); 38812 } 38813 } 38814 } 38815 return shadow(this, "baseUrl", this.pdfManager.docBaseUrl); 38816 } 38817 static parseDestDictionary({ 38818 destDict, 38819 resultObj, 38820 docBaseUrl = null, 38821 docAttachments = null 38822 }) { 38823 if (!(destDict instanceof Dict)) { 38824 warn("parseDestDictionary: `destDict` must be a dictionary."); 38825 return; 38826 } 38827 let action = destDict.get("A"), 38828 url, 38829 dest; 38830 if (!(action instanceof Dict)) { 38831 if (destDict.has("Dest")) { 38832 action = destDict.get("Dest"); 38833 } else { 38834 action = destDict.get("AA"); 38835 if (action instanceof Dict) { 38836 if (action.has("D")) { 38837 action = action.get("D"); 38838 } else if (action.has("U")) { 38839 action = action.get("U"); 38840 } 38841 } 38842 } 38843 } 38844 if (action instanceof Dict) { 38845 const actionType = action.get("S"); 38846 if (!(actionType instanceof Name)) { 38847 warn("parseDestDictionary: Invalid type in Action dictionary."); 38848 return; 38849 } 38850 const actionName = actionType.name; 38851 switch (actionName) { 38852 case "ResetForm": 38853 const flags = action.get("Flags"); 38854 const include = ((typeof flags === "number" ? flags : 0) & 1) === 0; 38855 const fields = []; 38856 const refs = []; 38857 for (const obj of action.get("Fields") || []) { 38858 if (obj instanceof Ref) { 38859 refs.push(obj.toString()); 38860 } else if (typeof obj === "string") { 38861 fields.push(stringToPDFString(obj)); 38862 } 38863 } 38864 resultObj.resetForm = { 38865 fields, 38866 refs, 38867 include 38868 }; 38869 break; 38870 case "URI": 38871 url = action.get("URI"); 38872 if (url instanceof Name) { 38873 url = "/" + url.name; 38874 } 38875 break; 38876 case "GoTo": 38877 dest = action.get("D"); 38878 break; 38879 case "Launch": 38880 case "GoToR": 38881 const urlDict = action.get("F"); 38882 if (urlDict instanceof Dict) { 38883 const fs = new FileSpec(urlDict, null, true); 38884 const { 38885 rawFilename 38886 } = fs.serializable; 38887 url = rawFilename; 38888 } else if (typeof urlDict === "string") { 38889 url = urlDict; 38890 } 38891 const remoteDest = fetchRemoteDest(action); 38892 if (remoteDest && typeof url === "string") { 38893 url = url.split("#", 1)[0] + "#" + remoteDest; 38894 } 38895 const newWindow = action.get("NewWindow"); 38896 if (typeof newWindow === "boolean") { 38897 resultObj.newWindow = newWindow; 38898 } 38899 break; 38900 case "GoToE": 38901 const target = action.get("T"); 38902 let attachment; 38903 if (docAttachments && target instanceof Dict) { 38904 const relationship = target.get("R"); 38905 const name = target.get("N"); 38906 if (isName(relationship, "C") && typeof name === "string") { 38907 attachment = docAttachments[stringToPDFString(name, true)]; 38908 } 38909 } 38910 if (attachment) { 38911 resultObj.attachment = attachment; 38912 const attachmentDest = fetchRemoteDest(action); 38913 if (attachmentDest) { 38914 resultObj.attachmentDest = attachmentDest; 38915 } 38916 } else { 38917 warn(`parseDestDictionary - unimplemented "GoToE" action.`); 38918 } 38919 break; 38920 case "Named": 38921 const namedAction = action.get("N"); 38922 if (namedAction instanceof Name) { 38923 resultObj.action = namedAction.name; 38924 } 38925 break; 38926 case "SetOCGState": 38927 const state = action.get("State"); 38928 const preserveRB = action.get("PreserveRB"); 38929 if (!Array.isArray(state) || state.length === 0) { 38930 break; 38931 } 38932 const stateArr = []; 38933 for (const elem of state) { 38934 if (elem instanceof Name) { 38935 switch (elem.name) { 38936 case "ON": 38937 case "OFF": 38938 case "Toggle": 38939 stateArr.push(elem.name); 38940 break; 38941 } 38942 } else if (elem instanceof Ref) { 38943 stateArr.push(elem.toString()); 38944 } 38945 } 38946 if (stateArr.length !== state.length) { 38947 break; 38948 } 38949 resultObj.setOCGState = { 38950 state: stateArr, 38951 preserveRB: typeof preserveRB === "boolean" ? preserveRB : true 38952 }; 38953 break; 38954 case "JavaScript": 38955 const jsAction = action.get("JS"); 38956 let js; 38957 if (jsAction instanceof BaseStream) { 38958 js = jsAction.getString(); 38959 } else if (typeof jsAction === "string") { 38960 js = jsAction; 38961 } 38962 const jsURL = js && recoverJsURL(stringToPDFString(js, true)); 38963 if (jsURL) { 38964 url = jsURL.url; 38965 resultObj.newWindow = jsURL.newWindow; 38966 break; 38967 } 38968 default: 38969 if (actionName === "JavaScript" || actionName === "SubmitForm") { 38970 break; 38971 } 38972 warn(`parseDestDictionary - unsupported action: "${actionName}".`); 38973 break; 38974 } 38975 } else if (destDict.has("Dest")) { 38976 dest = destDict.get("Dest"); 38977 } 38978 if (typeof url === "string") { 38979 const absoluteUrl = createValidAbsoluteUrl(url, docBaseUrl, { 38980 addDefaultProtocol: true, 38981 tryConvertEncoding: true 38982 }); 38983 if (absoluteUrl) { 38984 resultObj.url = absoluteUrl.href; 38985 } 38986 resultObj.unsafeUrl = url; 38987 } 38988 if (dest) { 38989 if (dest instanceof Name) { 38990 dest = dest.name; 38991 } 38992 if (typeof dest === "string") { 38993 resultObj.dest = stringToPDFString(dest, true); 38994 } else if (isValidExplicitDest(dest)) { 38995 resultObj.dest = dest; 38996 } 38997 } 38998 } 38999} 39000 39001;// ./src/core/object_loader.js 39002 39003 39004 39005
vendor: 6,129 bytes, lines 39006-39225
39006function mayHaveChildren(value) { 39007 return value instanceof Ref || value instanceof Dict || value instanceof BaseStream || Array.isArray(value); 39008} 39009function addChildren(node, nodesToVisit) { 39010 if (node instanceof Dict) { 39011 node = node.getRawValues(); 39012 } else if (node instanceof BaseStream) { 39013 node = node.dict.getRawValues(); 39014 } else if (!Array.isArray(node)) { 39015 return; 39016 } 39017 for (const rawValue of node) { 39018 if (mayHaveChildren(rawValue)) { 39019 nodesToVisit.push(rawValue); 39020 } 39021 } 39022} 39023class ObjectLoader { 39024 refSet = new RefSet(); 39025 constructor(dict, keys, xref) { 39026 this.dict = dict; 39027 this.keys = keys; 39028 this.xref = xref; 39029 } 39030 async load() { 39031 const { 39032 keys, 39033 dict 39034 } = this; 39035 const nodesToVisit = []; 39036 for (const key of keys) { 39037 const rawValue = dict.getRaw(key); 39038 if (rawValue !== undefined) { 39039 nodesToVisit.push(rawValue); 39040 } 39041 } 39042 await this.#walk(nodesToVisit); 39043 this.refSet = null; 39044 } 39045 async #walk(nodesToVisit) { 39046 const nodesToRevisit = []; 39047 const pendingRequests = []; 39048 while (nodesToVisit.length) { 39049 let currentNode = nodesToVisit.pop(); 39050 if (currentNode instanceof Ref) { 39051 if (this.refSet.has(currentNode)) { 39052 continue; 39053 } 39054 try { 39055 this.refSet.put(currentNode); 39056 currentNode = this.xref.fetch(currentNode); 39057 } catch (ex) { 39058 if (!(ex instanceof MissingDataException)) { 39059 warn(`ObjectLoader.#walk - requesting all data: "${ex}".`); 39060 await this.xref.stream.manager.requestAllChunks(); 39061 return; 39062 } 39063 nodesToRevisit.push(currentNode); 39064 pendingRequests.push({ 39065 begin: ex.begin, 39066 end: ex.end 39067 }); 39068 } 39069 } 39070 if (currentNode instanceof BaseStream) { 39071 const baseStreams = currentNode.getBaseStreams(); 39072 if (baseStreams) { 39073 let foundMissingData = false; 39074 for (const stream of baseStreams) { 39075 if (stream.isDataLoaded) { 39076 continue; 39077 } 39078 foundMissingData = true; 39079 pendingRequests.push({ 39080 begin: stream.start, 39081 end: stream.end 39082 }); 39083 } 39084 if (foundMissingData) { 39085 nodesToRevisit.push(currentNode); 39086 } 39087 } 39088 } 39089 addChildren(currentNode, nodesToVisit); 39090 } 39091 if (pendingRequests.length) { 39092 await this.xref.stream.manager.requestRanges(pendingRequests); 39093 for (const node of nodesToRevisit) { 39094 if (node instanceof Ref) { 39095 this.refSet.remove(node); 39096 } 39097 } 39098 await this.#walk(nodesToRevisit); 39099 } 39100 } 39101 static async load(obj, keys, xref) { 39102 if (xref.stream.isDataLoaded) { 39103 return; 39104 } 39105 const objLoader = new ObjectLoader(obj, keys, xref); 39106 await objLoader.load(); 39107 } 39108} 39109 39110;// ./src/core/xfa/symbol_utils.js 39111const $acceptWhitespace = Symbol(); 39112const $addHTML = Symbol(); 39113const $appendChild = Symbol(); 39114const $childrenToHTML = Symbol(); 39115const $clean = Symbol(); 39116const $cleanPage = Symbol(); 39117const $cleanup = Symbol(); 39118const $clone = Symbol(); 39119const $consumed = Symbol(); 39120const $content = Symbol("content"); 39121const $data = Symbol("data"); 39122const $dump = Symbol(); 39123const $extra = Symbol("extra"); 39124const $finalize = Symbol(); 39125const $flushHTML = Symbol(); 39126const $getAttributeIt = Symbol(); 39127const $getAttributes = Symbol(); 39128const $getAvailableSpace = Symbol(); 39129const $getChildrenByClass = Symbol(); 39130const $getChildrenByName = Symbol(); 39131const $getChildrenByNameIt = Symbol(); 39132const $getDataValue = Symbol(); 39133const $getExtra = Symbol(); 39134const $getRealChildrenByNameIt = Symbol(); 39135const $getChildren = Symbol(); 39136const $getContainedChildren = Symbol(); 39137const $getNextPage = Symbol(); 39138const $getSubformParent = Symbol(); 39139const $getParent = Symbol(); 39140const $getTemplateRoot = Symbol(); 39141const $globalData = Symbol(); 39142const $hasSettableValue = Symbol(); 39143const $ids = Symbol(); 39144const $indexOf = Symbol(); 39145const $insertAt = Symbol(); 39146const $isCDATAXml = Symbol(); 39147const $isBindable = Symbol(); 39148const $isDataValue = Symbol(); 39149const $isDescendent = Symbol(); 39150const $isNsAgnostic = Symbol(); 39151const $isSplittable = Symbol(); 39152const $isThereMoreWidth = Symbol(); 39153const $isTransparent = Symbol(); 39154const $isUsable = Symbol(); 39155const $lastAttribute = Symbol(); 39156const $namespaceId = Symbol("namespaceId"); 39157const $nodeName = Symbol("nodeName"); 39158const $nsAttributes = Symbol(); 39159const $onChild = Symbol(); 39160const $onChildCheck = Symbol(); 39161const $onText = Symbol(); 39162const $pushGlyphs = Symbol(); 39163const $popPara = Symbol(); 39164const $pushPara = Symbol(); 39165const $removeChild = Symbol(); 39166const $root = Symbol("root"); 39167const $resolvePrototypes = Symbol(); 39168const $searchNode = Symbol(); 39169const $setId = Symbol(); 39170const $setSetAttributes = Symbol(); 39171const $setValue = Symbol(); 39172const $tabIndex = Symbol(); 39173const $text = Symbol(); 39174const $toPages = Symbol(); 39175const $toHTML = Symbol(); 39176const $toString = Symbol(); 39177const $toStyle = Symbol(); 39178const $uid = Symbol("uid"); 39179 39180;// ./src/core/xfa/namespaces.js 39181const $buildXFAObject = Symbol(); 39182const NamespaceIds = { 39183 config: { 39184 id: 0, 39185 check: ns => ns.startsWith("http://www.xfa.org/schema/xci/") 39186 }, 39187 connectionSet: { 39188 id: 1, 39189 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-connection-set/") 39190 }, 39191 datasets: { 39192 id: 2, 39193 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-data/") 39194 }, 39195 form: { 39196 id: 3, 39197 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-form/") 39198 }, 39199 localeSet: { 39200 id: 4, 39201 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-locale-set/") 39202 }, 39203 pdf: { 39204 id: 5, 39205 check: ns => ns === "http://ns.adobe.com/xdp/pdf/" 39206 }, 39207 signature: { 39208 id: 6, 39209 check: ns => ns === "http://www.w3.org/2000/09/xmldsig#" 39210 }, 39211 sourceSet: { 39212 id: 7, 39213 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-source-set/") 39214 }, 39215 stylesheet: { 39216 id: 8, 39217 check: ns => ns === "http://www.w3.org/1999/XSL/Transform" 39218 }, 39219 template: { 39220 id: 9, 39221 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-template/") 39222 }, 39223 xdc: { 39224 id: 10, 39225 check: ns =>
vendor: 8,554 bytes, lines 39225-39595
39225 ns.startsWith("http://www.xfa.org/schema/xdc/") 39226 }, 39227 xdp: { 39228 id: 11, 39229 check: ns => ns === "http://ns.adobe.com/xdp/" 39230 }, 39231 xfdf: { 39232 id: 12, 39233 check: ns => ns === "http://ns.adobe.com/xfdf/" 39234 }, 39235 xhtml: { 39236 id: 13, 39237 check: ns => ns === "http://www.w3.org/1999/xhtml" 39238 }, 39239 xmpmeta: { 39240 id: 14, 39241 check: ns => ns === "http://ns.adobe.com/xmpmeta/" 39242 } 39243}; 39244 39245;// ./src/core/xfa/utils.js 39246 39247const dimConverters = { 39248 pt: x => x, 39249 cm: x => x / 2.54 * 72, 39250 mm: x => x / (10 * 2.54) * 72, 39251 in: x => x * 72, 39252 px: x => x 39253}; 39254const measurementPattern = /([+-]?\d+\.?\d*)(.*)/; 39255function stripQuotes(str) { 39256 if (str.startsWith("'") || str.startsWith('"')) { 39257 return str.slice(1, -1); 39258 } 39259 return str; 39260} 39261function getInteger({ 39262 data, 39263 defaultValue, 39264 validate 39265}) { 39266 if (!data) { 39267 return defaultValue; 39268 } 39269 data = data.trim(); 39270 const n = parseInt(data, 10); 39271 if (!isNaN(n) && validate(n)) { 39272 return n; 39273 } 39274 return defaultValue; 39275} 39276function getFloat({ 39277 data, 39278 defaultValue, 39279 validate 39280}) { 39281 if (!data) { 39282 return defaultValue; 39283 } 39284 data = data.trim(); 39285 const n = parseFloat(data); 39286 if (!isNaN(n) && validate(n)) { 39287 return n; 39288 } 39289 return defaultValue; 39290} 39291function getKeyword({ 39292 data, 39293 defaultValue, 39294 validate 39295}) { 39296 if (!data) { 39297 return defaultValue; 39298 } 39299 data = data.trim(); 39300 if (validate(data)) { 39301 return data; 39302 } 39303 return defaultValue; 39304} 39305function getStringOption(data, options) { 39306 return getKeyword({ 39307 data, 39308 defaultValue: options[0], 39309 validate: k => options.includes(k) 39310 }); 39311} 39312function getMeasurement(str, def = "0") { 39313 def ||= "0"; 39314 if (!str) { 39315 return getMeasurement(def); 39316 } 39317 const match = str.trim().match(measurementPattern); 39318 if (!match) { 39319 return getMeasurement(def); 39320 } 39321 const [, valueStr, unit] = match; 39322 const value = parseFloat(valueStr); 39323 if (isNaN(value)) { 39324 return getMeasurement(def); 39325 } 39326 if (value === 0) { 39327 return 0; 39328 } 39329 const conv = dimConverters[unit]; 39330 if (conv) { 39331 return conv(value); 39332 } 39333 return value; 39334} 39335function getRatio(data) { 39336 if (!data) { 39337 return { 39338 num: 1, 39339 den: 1 39340 }; 39341 } 39342 const ratio = data.split(":", 2).map(x => parseFloat(x.trim())).filter(x => !isNaN(x)); 39343 if (ratio.length === 1) { 39344 ratio.push(1); 39345 } 39346 if (ratio.length === 0) { 39347 return { 39348 num: 1, 39349 den: 1 39350 }; 39351 } 39352 const [num, den] = ratio; 39353 return { 39354 num, 39355 den 39356 }; 39357} 39358function getRelevant(data) { 39359 if (!data) { 39360 return []; 39361 } 39362 return data.trim().split(/\s+/).map(e => ({ 39363 excluded: e[0] === "-", 39364 viewname: e.substring(1) 39365 })); 39366} 39367function getColor(data, def = [0, 0, 0]) { 39368 let [r, g, b] = def; 39369 if (!data) { 39370 return { 39371 r, 39372 g, 39373 b 39374 }; 39375 } 39376 const color = data.split(",", 3).map(c => MathClamp(parseInt(c.trim(), 10), 0, 255)).map(c => isNaN(c) ? 0 : c); 39377 if (color.length < 3) { 39378 return { 39379 r, 39380 g, 39381 b 39382 }; 39383 } 39384 [r, g, b] = color; 39385 return { 39386 r, 39387 g, 39388 b 39389 }; 39390} 39391function getBBox(data) { 39392 const def = -1; 39393 if (!data) { 39394 return { 39395 x: def, 39396 y: def, 39397 width: def, 39398 height: def 39399 }; 39400 } 39401 const bbox = data.split(",", 4).map(m => getMeasurement(m.trim(), "-1")); 39402 if (bbox.length < 4 || bbox[2] < 0 || bbox[3] < 0) { 39403 return { 39404 x: def, 39405 y: def, 39406 width: def, 39407 height: def 39408 }; 39409 } 39410 const [x, y, width, height] = bbox; 39411 return { 39412 x, 39413 y, 39414 width, 39415 height 39416 }; 39417} 39418class HTMLResult { 39419 static get FAILURE() { 39420 return shadow(this, "FAILURE", new HTMLResult(false, null, null, null)); 39421 } 39422 static get EMPTY() { 39423 return shadow(this, "EMPTY", new HTMLResult(true, null, null, null)); 39424 } 39425 constructor(success, html, bbox, breakNode) { 39426 this.success = success; 39427 this.html = html; 39428 this.bbox = bbox; 39429 this.breakNode = breakNode; 39430 } 39431 isBreak() { 39432 return !!this.breakNode; 39433 } 39434 static breakNode(node) { 39435 return new HTMLResult(false, null, null, node); 39436 } 39437 static success(html, bbox = null) { 39438 return new HTMLResult(true, html, bbox, null); 39439 } 39440} 39441 39442;// ./src/core/xfa/fonts.js 39443 39444 39445 39446class FontFinder { 39447 constructor(pdfFonts) { 39448 this.fonts = new Map(); 39449 this.cache = new Map(); 39450 this.warned = new Set(); 39451 this.defaultFont = null; 39452 this.add(pdfFonts); 39453 } 39454 add(pdfFonts, reallyMissingFonts = null) { 39455 for (const pdfFont of pdfFonts) { 39456 this.addPdfFont(pdfFont); 39457 } 39458 for (const pdfFont of this.fonts.values()) { 39459 if (!pdfFont.regular) { 39460 pdfFont.regular = pdfFont.italic || pdfFont.bold || pdfFont.bolditalic; 39461 } 39462 } 39463 if (!reallyMissingFonts || reallyMissingFonts.size === 0) { 39464 return; 39465 } 39466 const myriad = this.fonts.get("PdfJS-Fallback-PdfJS-XFA"); 39467 for (const missing of reallyMissingFonts) { 39468 this.fonts.set(missing, myriad); 39469 } 39470 } 39471 addPdfFont(pdfFont) { 39472 const cssFontInfo = pdfFont.cssFontInfo; 39473 const name = cssFontInfo.fontFamily; 39474 let font = this.fonts.get(name); 39475 if (!font) { 39476 font = Object.create(null); 39477 this.fonts.set(name, font); 39478 if (!this.defaultFont) { 39479 this.defaultFont = font; 39480 } 39481 } 39482 let property = ""; 39483 const fontWeight = parseFloat(cssFontInfo.fontWeight); 39484 if (parseFloat(cssFontInfo.italicAngle) !== 0) { 39485 property = fontWeight >= 700 ? "bolditalic" : "italic"; 39486 } else if (fontWeight >= 700) { 39487 property = "bold"; 39488 } 39489 if (!property) { 39490 if (pdfFont.name.includes("Bold") || pdfFont.psName?.includes("Bold")) { 39491 property = "bold"; 39492 } 39493 if (pdfFont.name.includes("Italic") || pdfFont.name.endsWith("It") || pdfFont.psName?.includes("Italic") || pdfFont.psName?.endsWith("It")) { 39494 property += "italic"; 39495 } 39496 } 39497 if (!property) { 39498 property = "regular"; 39499 } 39500 font[property] = pdfFont; 39501 } 39502 getDefault() { 39503 return this.defaultFont; 39504 } 39505 find(fontName, mustWarn = true) { 39506 let font = this.fonts.get(fontName) || this.cache.get(fontName); 39507 if (font) { 39508 return font; 39509 } 39510 const pattern = /,|-|_| |bolditalic|bold|italic|regular|it/gi; 39511 let name = fontName.replaceAll(pattern, ""); 39512 font = this.fonts.get(name); 39513 if (font) { 39514 this.cache.set(fontName, font); 39515 return font; 39516 } 39517 name = name.toLowerCase(); 39518 const maybe = []; 39519 for (const [family, pdfFont] of this.fonts.entries()) { 39520 if (family.replaceAll(pattern, "").toLowerCase().startsWith(name)) { 39521 maybe.push(pdfFont); 39522 } 39523 } 39524 if (maybe.length === 0) { 39525 for (const [, pdfFont] of this.fonts.entries()) { 39526 if (pdfFont.regular.name?.replaceAll(pattern, "").toLowerCase().startsWith(name)) { 39527 maybe.push(pdfFont); 39528 } 39529 } 39530 } 39531 if (maybe.length === 0) { 39532 name = name.replaceAll(/psmt|mt/gi, ""); 39533 for (const [family, pdfFont] of this.fonts.entries()) { 39534 if (family.replaceAll(pattern, "").toLowerCase().startsWith(name)) { 39535 maybe.push(pdfFont); 39536 } 39537 } 39538 } 39539 if (maybe.length === 0) { 39540 for (const pdfFont of this.fonts.values()) { 39541 if (pdfFont.regular.name?.replaceAll(pattern, "").toLowerCase().startsWith(name)) { 39542 maybe.push(pdfFont); 39543 } 39544 } 39545 } 39546 if (maybe.length >= 1) { 39547 if (maybe.length !== 1 && mustWarn) { 39548 warn(`XFA - Too many choices to guess the correct font: ${fontName}`); 39549 } 39550 this.cache.set(fontName, maybe[0]); 39551 return maybe[0]; 39552 } 39553 if (mustWarn && !this.warned.has(fontName)) { 39554 this.warned.add(fontName); 39555 warn(`XFA - Cannot find the font: ${fontName}`); 39556 } 39557 return null; 39558 } 39559} 39560function selectFont(xfaFont, typeface) { 39561 if (xfaFont.posture === "italic") { 39562 if (xfaFont.weight === "bold") { 39563 return typeface.bolditalic; 39564 } 39565 return typeface.italic; 39566 } else if (xfaFont.weight === "bold") { 39567 return typeface.bold; 39568 } 39569 return typeface.regular; 39570} 39571function fonts_getMetrics(xfaFont, real = false) { 39572 let pdfFont = null; 39573 if (xfaFont) { 39574 const name = stripQuotes(xfaFont.typeface); 39575 const typeface = xfaFont[$globalData].fontFinder.find(name); 39576 pdfFont = selectFont(xfaFont, typeface); 39577 } 39578 if (!pdfFont) { 39579 return { 39580 lineHeight: 12, 39581 lineGap: 2, 39582 lineNoGap: 10 39583 }; 39584 } 39585 const size = xfaFont.size || 10; 39586 const lineHeight = pdfFont.lineHeight ? Math.max(real ? 0 : 1.2, pdfFont.lineHeight) : 1.2; 39587 const lineGap = pdfFont.lineGap === undefined ? 0.2 : pdfFont.lineGap; 39588 return { 39589 lineHeight: lineHeight * size, 39590 lineGap: lineGap * size, 39591 lineNoGap: Math.max(1, lineHeight - lineGap) * size 39592 }; 39593} 39594 39595;// ./src/core/xfa/text.js
vendor: 4,744 bytes, lines 39595-39741
39595 39596 39597const WIDTH_FACTOR = 1.02; 39598class text_FontInfo { 39599 constructor(xfaFont, margin, lineHeight, fontFinder) { 39600 this.lineHeight = lineHeight; 39601 this.paraMargin = margin || { 39602 top: 0, 39603 bottom: 0, 39604 left: 0, 39605 right: 0 39606 }; 39607 if (!xfaFont) { 39608 [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder); 39609 return; 39610 } 39611 this.xfaFont = { 39612 typeface: xfaFont.typeface, 39613 posture: xfaFont.posture, 39614 weight: xfaFont.weight, 39615 size: xfaFont.size, 39616 letterSpacing: xfaFont.letterSpacing 39617 }; 39618 const typeface = fontFinder.find(xfaFont.typeface); 39619 if (!typeface) { 39620 [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder); 39621 return; 39622 } 39623 this.pdfFont = selectFont(xfaFont, typeface); 39624 if (!this.pdfFont) { 39625 [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder); 39626 } 39627 } 39628 defaultFont(fontFinder) { 39629 const font = fontFinder.find("Helvetica", false) || fontFinder.find("Myriad Pro", false) || fontFinder.find("Arial", false) || fontFinder.getDefault(); 39630 if (font?.regular) { 39631 const pdfFont = font.regular; 39632 const info = pdfFont.cssFontInfo; 39633 const xfaFont = { 39634 typeface: info.fontFamily, 39635 posture: "normal", 39636 weight: "normal", 39637 size: 10, 39638 letterSpacing: 0 39639 }; 39640 return [pdfFont, xfaFont]; 39641 } 39642 const xfaFont = { 39643 typeface: "Courier", 39644 posture: "normal", 39645 weight: "normal", 39646 size: 10, 39647 letterSpacing: 0 39648 }; 39649 return [null, xfaFont]; 39650 } 39651} 39652class FontSelector { 39653 constructor(defaultXfaFont, defaultParaMargin, defaultLineHeight, fontFinder) { 39654 this.fontFinder = fontFinder; 39655 this.stack = [new text_FontInfo(defaultXfaFont, defaultParaMargin, defaultLineHeight, fontFinder)]; 39656 } 39657 pushData(xfaFont, margin, lineHeight) { 39658 const lastFont = this.stack.at(-1); 39659 for (const name of ["typeface", "posture", "weight", "size", "letterSpacing"]) { 39660 if (!xfaFont[name]) { 39661 xfaFont[name] = lastFont.xfaFont[name]; 39662 } 39663 } 39664 for (const name of ["top", "bottom", "left", "right"]) { 39665 if (isNaN(margin[name])) { 39666 margin[name] = lastFont.paraMargin[name]; 39667 } 39668 } 39669 const fontInfo = new text_FontInfo(xfaFont, margin, lineHeight || lastFont.lineHeight, this.fontFinder); 39670 if (!fontInfo.pdfFont) { 39671 fontInfo.pdfFont = lastFont.pdfFont; 39672 } 39673 this.stack.push(fontInfo); 39674 } 39675 popFont() { 39676 this.stack.pop(); 39677 } 39678 topFont() { 39679 return this.stack.at(-1); 39680 } 39681} 39682class TextMeasure { 39683 constructor(defaultXfaFont, defaultParaMargin, defaultLineHeight, fonts) { 39684 this.glyphs = []; 39685 this.fontSelector = new FontSelector(defaultXfaFont, defaultParaMargin, defaultLineHeight, fonts); 39686 this.extraHeight = 0; 39687 } 39688 pushData(xfaFont, margin, lineHeight) { 39689 this.fontSelector.pushData(xfaFont, margin, lineHeight); 39690 } 39691 popFont(xfaFont) { 39692 return this.fontSelector.popFont(); 39693 } 39694 addPara() { 39695 const lastFont = this.fontSelector.topFont(); 39696 this.extraHeight += lastFont.paraMargin.top + lastFont.paraMargin.bottom; 39697 } 39698 addString(str) { 39699 if (!str) { 39700 return; 39701 } 39702 const lastFont = this.fontSelector.topFont(); 39703 const fontSize = lastFont.xfaFont.size; 39704 if (lastFont.pdfFont) { 39705 const letterSpacing = lastFont.xfaFont.letterSpacing; 39706 const pdfFont = lastFont.pdfFont; 39707 const fontLineHeight = pdfFont.lineHeight || 1.2; 39708 const lineHeight = lastFont.lineHeight || Math.max(1.2, fontLineHeight) * fontSize; 39709 const lineGap = pdfFont.lineGap === undefined ? 0.2 : pdfFont.lineGap; 39710 const noGap = fontLineHeight - lineGap; 39711 const firstLineHeight = Math.max(1, noGap) * fontSize; 39712 const scale = fontSize / 1000; 39713 const fallbackWidth = pdfFont.defaultWidth || pdfFont.charsToGlyphs(" ")[0].width; 39714 for (const line of str.split(/[\u2029\n]/)) { 39715 const encodedLine = pdfFont.encodeString(line).join(""); 39716 const glyphs = pdfFont.charsToGlyphs(encodedLine); 39717 for (const glyph of glyphs) { 39718 const width = glyph.width || fallbackWidth; 39719 this.glyphs.push([width * scale + letterSpacing, lineHeight, firstLineHeight, glyph.unicode, false]); 39720 } 39721 this.glyphs.push([0, 0, 0, "\n", true]); 39722 } 39723 this.glyphs.pop(); 39724 return; 39725 } 39726 for (const line of str.split(/[\u2029\n]/)) { 39727 for (const char of line.split("")) { 39728 this.glyphs.push([fontSize, 1.2 * fontSize, fontSize, char, false]); 39729 } 39730 this.glyphs.push([0, 0, 0, "\n", true]); 39731 } 39732 this.glyphs.pop(); 39733 } 39734 compute(maxWidth) { 39735 let lastSpacePos = -1, 39736 lastSpaceWidth = 0, 39737 width = 0, 39738 height = 0, 39739 currentLineWidth = 0, 39740 currentLineHeight = 0; 39741 let isBroken = false;
vendor: 5,590 bytes, lines 39742-39932
39742 let isFirstLine = true; 39743 for (let i = 0, ii = this.glyphs.length; i < ii; i++) { 39744 const [glyphWidth, lineHeight, firstLineHeight, char, isEOL] = this.glyphs[i]; 39745 const isSpace = char === " "; 39746 const glyphHeight = isFirstLine ? firstLineHeight : lineHeight; 39747 if (isEOL) { 39748 width = Math.max(width, currentLineWidth); 39749 currentLineWidth = 0; 39750 height += currentLineHeight; 39751 currentLineHeight = glyphHeight; 39752 lastSpacePos = -1; 39753 lastSpaceWidth = 0; 39754 isFirstLine = false; 39755 continue; 39756 } 39757 if (isSpace) { 39758 if (currentLineWidth + glyphWidth > maxWidth) { 39759 width = Math.max(width, currentLineWidth); 39760 currentLineWidth = 0; 39761 height += currentLineHeight; 39762 currentLineHeight = glyphHeight; 39763 lastSpacePos = -1; 39764 lastSpaceWidth = 0; 39765 isBroken = true; 39766 isFirstLine = false; 39767 } else { 39768 currentLineHeight = Math.max(glyphHeight, currentLineHeight); 39769 lastSpaceWidth = currentLineWidth; 39770 currentLineWidth += glyphWidth; 39771 lastSpacePos = i; 39772 } 39773 continue; 39774 } 39775 if (currentLineWidth + glyphWidth > maxWidth) { 39776 height += currentLineHeight; 39777 currentLineHeight = glyphHeight; 39778 if (lastSpacePos !== -1) { 39779 i = lastSpacePos; 39780 width = Math.max(width, lastSpaceWidth); 39781 currentLineWidth = 0; 39782 lastSpacePos = -1; 39783 lastSpaceWidth = 0; 39784 } else { 39785 width = Math.max(width, currentLineWidth); 39786 currentLineWidth = glyphWidth; 39787 } 39788 isBroken = true; 39789 isFirstLine = false; 39790 continue; 39791 } 39792 currentLineWidth += glyphWidth; 39793 currentLineHeight = Math.max(glyphHeight, currentLineHeight); 39794 } 39795 width = Math.max(width, currentLineWidth); 39796 height += currentLineHeight + this.extraHeight; 39797 return { 39798 width: WIDTH_FACTOR * width, 39799 height, 39800 isBroken 39801 }; 39802 } 39803} 39804 39805;// ./src/core/xfa/som.js 39806 39807 39808const namePattern = /^[^.[]+/; 39809const indexPattern = /^[^\]]+/; 39810const operators = { 39811 dot: 0, 39812 dotDot: 1, 39813 dotHash: 2, 39814 dotBracket: 3, 39815 dotParen: 4 39816}; 39817const shortcuts = new Map([["$data", (root, current) => root.datasets ? root.datasets.data : root], ["$record", (root, current) => (root.datasets ? root.datasets.data : root)[$getChildren]()[0]], ["$template", (root, current) => root.template], ["$connectionSet", (root, current) => root.connectionSet], ["$form", (root, current) => root.form], ["$layout", (root, current) => root.layout], ["$host", (root, current) => root.host], ["$dataWindow", (root, current) => root.dataWindow], ["$event", (root, current) => root.event], ["!", (root, current) => root.datasets], ["$xfa", (root, current) => root], ["xfa", (root, current) => root], ["$", (root, current) => current]]); 39818const somCache = new WeakMap(); 39819function parseIndex(index) { 39820 index = index.trim(); 39821 if (index === "*") { 39822 return Infinity; 39823 } 39824 return parseInt(index, 10) || 0; 39825} 39826function parseExpression(expr, dotDotAllowed, noExpr = true) { 39827 let match = expr.match(namePattern); 39828 if (!match) { 39829 return null; 39830 } 39831 let [name] = match; 39832 const parsed = [{ 39833 name, 39834 cacheName: "." + name, 39835 index: 0, 39836 js: null, 39837 formCalc: null, 39838 operator: operators.dot 39839 }]; 39840 let pos = name.length; 39841 while (pos < expr.length) { 39842 const spos = pos; 39843 const char = expr.charAt(pos++); 39844 if (char === "[") { 39845 match = expr.slice(pos).match(indexPattern); 39846 if (!match) { 39847 warn("XFA - Invalid index in SOM expression"); 39848 return null; 39849 } 39850 parsed.at(-1).index = parseIndex(match[0]); 39851 pos += match[0].length + 1; 39852 continue; 39853 } 39854 let operator; 39855 switch (expr.charAt(pos)) { 39856 case ".": 39857 if (!dotDotAllowed) { 39858 return null; 39859 } 39860 pos++; 39861 operator = operators.dotDot; 39862 break; 39863 case "#": 39864 pos++; 39865 operator = operators.dotHash; 39866 break; 39867 case "[": 39868 if (noExpr) { 39869 warn("XFA - SOM expression contains a FormCalc subexpression which is not supported for now."); 39870 return null; 39871 } 39872 operator = operators.dotBracket; 39873 break; 39874 case "(": 39875 if (noExpr) { 39876 warn("XFA - SOM expression contains a JavaScript subexpression which is not supported for now."); 39877 return null; 39878 } 39879 operator = operators.dotParen; 39880 break; 39881 default: 39882 operator = operators.dot; 39883 break; 39884 } 39885 match = expr.slice(pos).match(namePattern); 39886 if (!match) { 39887 break; 39888 } 39889 [name] = match; 39890 pos += name.length; 39891 parsed.push({ 39892 name, 39893 cacheName: expr.slice(spos, pos), 39894 operator, 39895 index: 0, 39896 js: null, 39897 formCalc: null 39898 }); 39899 } 39900 return parsed; 39901} 39902function searchNode(root, container, expr, dotDotAllowed = true, useCache = true) { 39903 const parsed = parseExpression(expr, dotDotAllowed); 39904 if (!parsed) { 39905 return null; 39906 } 39907 const fn = shortcuts.get(parsed[0].name); 39908 let i = 0; 39909 let isQualified; 39910 if (fn) { 39911 isQualified = true; 39912 root = [fn(root, container)]; 39913 i = 1; 39914 } else { 39915 isQualified = container === null; 39916 root = [container || root]; 39917 } 39918 for (let ii = parsed.length; i < ii; i++) { 39919 const { 39920 name, 39921 cacheName, 39922 operator, 39923 index 39924 } = parsed[i]; 39925 const nodes = []; 39926 for (const node of root) { 39927 if (!node.isXFAObject) { 39928 continue; 39929 } 39930 let children, cached; 39931 if (useCache) { 39932 cached = somCache.get
vendor: 2,760 bytes, lines 39932-40038
39932(node); 39933 if (!cached) { 39934 cached = new Map(); 39935 somCache.set(node, cached); 39936 } 39937 children = cached.get(cacheName); 39938 } 39939 if (!children) { 39940 switch (operator) { 39941 case operators.dot: 39942 children = node[$getChildrenByName](name, false); 39943 break; 39944 case operators.dotDot: 39945 children = node[$getChildrenByName](name, true); 39946 break; 39947 case operators.dotHash: 39948 children = node[$getChildrenByClass](name); 39949 children = children.isXFAObjectArray ? children.children : [children]; 39950 break; 39951 default: 39952 break; 39953 } 39954 if (useCache) { 39955 cached.set(cacheName, children); 39956 } 39957 } 39958 if (children.length > 0) { 39959 nodes.push(children); 39960 } 39961 } 39962 if (nodes.length === 0 && !isQualified && i === 0) { 39963 const parent = container[$getParent](); 39964 container = parent; 39965 if (!container) { 39966 return null; 39967 } 39968 i = -1; 39969 root = [container]; 39970 continue; 39971 } 39972 root = isFinite(index) ? nodes.filter(node => index < node.length).map(node => node[index]) : nodes.flat(); 39973 } 39974 if (root.length === 0) { 39975 return null; 39976 } 39977 return root; 39978} 39979function createDataNode(root, container, expr) { 39980 const parsed = parseExpression(expr); 39981 if (!parsed) { 39982 return null; 39983 } 39984 if (parsed.some(x => x.operator === operators.dotDot)) { 39985 return null; 39986 } 39987 const fn = shortcuts.get(parsed[0].name); 39988 let i = 0; 39989 if (fn) { 39990 root = fn(root, container); 39991 i = 1; 39992 } else { 39993 root = container || root; 39994 } 39995 for (let ii = parsed.length; i < ii; i++) { 39996 const { 39997 name, 39998 operator, 39999 index 40000 } = parsed[i]; 40001 if (!isFinite(index)) { 40002 parsed[i].index = 0; 40003 return root.createNodes(parsed.slice(i)); 40004 } 40005 let children; 40006 switch (operator) { 40007 case operators.dot: 40008 children = root[$getChildrenByName](name, false); 40009 break; 40010 case operators.dotDot: 40011 children = root[$getChildrenByName](name, true); 40012 break; 40013 case operators.dotHash: 40014 children = root[$getChildrenByClass](name); 40015 children = children.isXFAObjectArray ? children.children : [children]; 40016 break; 40017 default: 40018 break; 40019 } 40020 if (children.length === 0) { 40021 return root.createNodes(parsed.slice(i)); 40022 } 40023 if (index < children.length) { 40024 const child = children[index]; 40025 if (!child.isXFAObject) { 40026 warn(`XFA - Cannot create a node.`); 40027 return null; 40028 } 40029 root = child; 40030 } else { 40031 parsed[i].index = index - children.length; 40032 return root.createNodes(parsed.slice(i)); 40033 } 40034 } 40035 return null; 40036} 40037 40038;// ./src/core/xfa/xfa_object.js
vendor: 35,782 bytes, lines 40038-41352
40038 40039 40040 40041 40042 40043 40044 40045const _applyPrototype = Symbol(); 40046const _attributes = Symbol(); 40047const _attributeNames = Symbol(); 40048const _children = Symbol("_children"); 40049const _cloneAttribute = Symbol(); 40050const _dataValue = Symbol(); 40051const _defaultValue = Symbol(); 40052const _filteredChildrenGenerator = Symbol(); 40053const _getPrototype = Symbol(); 40054const _getUnsetAttributes = Symbol(); 40055const _hasChildren = Symbol(); 40056const _max = Symbol(); 40057const _options = Symbol(); 40058const _parent = Symbol("parent"); 40059const _resolvePrototypesHelper = Symbol(); 40060const _setAttributes = Symbol(); 40061const _validator = Symbol(); 40062let uid = 0; 40063const NS_DATASETS = NamespaceIds.datasets.id; 40064class XFAObject { 40065 constructor(nsId, name, hasChildren = false) { 40066 this[$namespaceId] = nsId; 40067 this[$nodeName] = name; 40068 this[_hasChildren] = hasChildren; 40069 this[_parent] = null; 40070 this[_children] = []; 40071 this[$uid] = `${name}${uid++}`; 40072 this[$globalData] = null; 40073 } 40074 get isXFAObject() { 40075 return true; 40076 } 40077 get isXFAObjectArray() { 40078 return false; 40079 } 40080 createNodes(path) { 40081 let root = this, 40082 node = null; 40083 for (const { 40084 name, 40085 index 40086 } of path) { 40087 for (let i = 0, ii = isFinite(index) ? index : 0; i <= ii; i++) { 40088 const nsId = root[$namespaceId] === NS_DATASETS ? -1 : root[$namespaceId]; 40089 node = new XmlObject(nsId, name); 40090 root[$appendChild](node); 40091 } 40092 root = node; 40093 } 40094 return node; 40095 } 40096 [$onChild](child) { 40097 if (!this[_hasChildren] || !this[$onChildCheck](child)) { 40098 return false; 40099 } 40100 const name = child[$nodeName]; 40101 const node = this[name]; 40102 if (node instanceof XFAObjectArray) { 40103 if (node.push(child)) { 40104 this[$appendChild](child); 40105 return true; 40106 } 40107 } else { 40108 if (node !== null) { 40109 this[$removeChild](node); 40110 } 40111 this[name] = child; 40112 this[$appendChild](child); 40113 return true; 40114 } 40115 let id = ""; 40116 if (this.id) { 40117 id = ` (id: ${this.id})`; 40118 } else if (this.name) { 40119 id = ` (name: ${this.name} ${this.h.value})`; 40120 } 40121 warn(`XFA - node "${this[$nodeName]}"${id} has already enough "${name}"!`); 40122 return false; 40123 } 40124 [$onChildCheck](child) { 40125 return this.hasOwnProperty(child[$nodeName]) && child[$namespaceId] === this[$namespaceId]; 40126 } 40127 [$isNsAgnostic]() { 40128 return false; 40129 } 40130 [$acceptWhitespace]() { 40131 return false; 40132 } 40133 [$isCDATAXml]() { 40134 return false; 40135 } 40136 [$isBindable]() { 40137 return false; 40138 } 40139 [$popPara]() { 40140 if (this.para) { 40141 this[$getTemplateRoot]()[$extra].paraStack.pop(); 40142 } 40143 } 40144 [$pushPara]() { 40145 this[$getTemplateRoot]()[$extra].paraStack.push(this.para); 40146 } 40147 [$setId](ids) { 40148 if (this.id && this[$namespaceId] === NamespaceIds.template.id) { 40149 ids.set(this.id, this); 40150 } 40151 } 40152 [$getTemplateRoot]() { 40153 return this[$globalData].template; 40154 } 40155 [$isSplittable]() { 40156 return false; 40157 } 40158 [$isThereMoreWidth]() { 40159 return false; 40160 } 40161 [$appendChild](child) { 40162 child[_parent] = this; 40163 this[_children].push(child); 40164 if (!child[$globalData] && this[$globalData]) { 40165 child[$globalData] = this[$globalData]; 40166 } 40167 } 40168 [$removeChild](child) { 40169 const i = this[_children].indexOf(child); 40170 this[_children].splice(i, 1); 40171 } 40172 [$hasSettableValue]() { 40173 return this.hasOwnProperty("value"); 40174 } 40175 [$setValue](_) {} 40176 [$onText](_) {} 40177 [$finalize]() {} 40178 [$clean](builder) { 40179 delete this[_hasChildren]; 40180 if (this[$cleanup]) { 40181 builder.clean(this[$cleanup]); 40182 delete this[$cleanup]; 40183 } 40184 } 40185 [$indexOf](child) { 40186 return this[_children].indexOf(child); 40187 } 40188 [$insertAt](i, child) { 40189 child[_parent] = this; 40190 this[_children].splice(i, 0, child); 40191 if (!child[$globalData] && this[$globalData]) { 40192 child[$globalData] = this[$globalData]; 40193 } 40194 } 40195 [$isTransparent]() { 40196 return !this.name; 40197 } 40198 [$lastAttribute]() { 40199 return ""; 40200 } 40201 [$text]() { 40202 if (this[_children].length === 0) { 40203 return this[$content]; 40204 } 40205 return this[_children].map(c => c[$text]()).join(""); 40206 } 40207 get [_attributeNames]() { 40208 const proto = Object.getPrototypeOf(this); 40209 if (!proto._attributes) { 40210 const attributes = proto._attributes = new Set(); 40211 for (const name of Object.getOwnPropertyNames(this)) { 40212 if (this[name] === null || this[name] instanceof XFAObject || this[name] instanceof XFAObjectArray) { 40213 break; 40214 } 40215 attributes.add(name); 40216 } 40217 } 40218 return shadow(this, _attributeNames, proto._attributes); 40219 } 40220 [$isDescendent](parent) { 40221 let node = this; 40222 while (node) { 40223 if (node === parent) { 40224 return true; 40225 } 40226 node = node[$getParent](); 40227 } 40228 return false; 40229 } 40230 [$getParent]() { 40231 return this[_parent]; 40232 } 40233 [$getSubformParent]() { 40234 return this[$getParent](); 40235 } 40236 [$getChildren](name = null) { 40237 if (!name) { 40238 return this[_children]; 40239 } 40240 return this[name]; 40241 } 40242 [$dump]() { 40243 const dumped = Object.create(null); 40244 if (this[$content]) { 40245 dumped.$content = this[$content]; 40246 } 40247 for (const name of Object.getOwnPropertyNames(this)) { 40248 const value = this[name]; 40249 if (value === null) { 40250 continue; 40251 } 40252 if (value instanceof XFAObject) { 40253 dumped[name] = value[$dump](); 40254 } else if (value instanceof XFAObjectArray) { 40255 if (!value.isEmpty()) { 40256 dumped[name] = value.dump(); 40257 } 40258 } else { 40259 dumped[name] = value; 40260 } 40261 } 40262 return dumped; 40263 } 40264 [$toStyle]() { 40265 return null; 40266 } 40267 [$toHTML]() { 40268 return HTMLResult.EMPTY; 40269 } 40270 *[$getContainedChildren]() { 40271 for (const node of this[$getChildren]()) { 40272 yield node; 40273 } 40274 } 40275 *[_filteredChildrenGenerator](filter, include) { 40276 for (const node of this[$getContainedChildren]()) { 40277 if (!filter || include === filter.has(node[$nodeName])) { 40278 const availableSpace = this[$getAvailableSpace](); 40279 const res = node[$toHTML](availableSpace); 40280 if (!res.success) { 40281 this[$extra].failingNode = node; 40282 } 40283 yield res; 40284 } 40285 } 40286 } 40287 [$flushHTML]() { 40288 return null; 40289 } 40290 [$addHTML](html, bbox) { 40291 this[$extra].children.push(html); 40292 } 40293 [$getAvailableSpace]() {} 40294 [$childrenToHTML]({ 40295 filter = null, 40296 include = true 40297 }) { 40298 if (!this[$extra].generator) { 40299 this[$extra].generator = this[_filteredChildrenGenerator](filter, include); 40300 } else { 40301 const availableSpace = this[$getAvailableSpace](); 40302 const res = this[$extra].failingNode[$toHTML](availableSpace); 40303 if (!res.success) { 40304 return res; 40305 } 40306 if (res.html) { 40307 this[$addHTML](res.html, res.bbox); 40308 } 40309 delete this[$extra].failingNode; 40310 } 40311 while (true) { 40312 const gen = this[$extra].generator.next(); 40313 if (gen.done) { 40314 break; 40315 } 40316 const res = gen.value; 40317 if (!res.success) { 40318 return res; 40319 } 40320 if (res.html) { 40321 this[$addHTML](res.html, res.bbox); 40322 } 40323 } 40324 this[$extra].generator = null; 40325 return HTMLResult.EMPTY; 40326 } 40327 [$setSetAttributes](attributes) { 40328 this[_setAttributes] = new Set(Object.keys(attributes)); 40329 } 40330 [_getUnsetAttributes](protoAttributes) { 40331 const allAttr = this[_attributeNames]; 40332 const setAttr = this[_setAttributes]; 40333 return [...protoAttributes].filter(x => allAttr.has(x) && !setAttr.has(x)); 40334 } 40335 [$resolvePrototypes](ids, ancestors = new Set()) { 40336 for (const child of this[_children]) { 40337 child[_resolvePrototypesHelper](ids, ancestors); 40338 } 40339 } 40340 [_resolvePrototypesHelper](ids, ancestors) { 40341 const proto = this[_getPrototype](ids, ancestors); 40342 if (proto) { 40343 this[_applyPrototype](proto, ids, ancestors); 40344 } else { 40345 this[$resolvePrototypes](ids, ancestors); 40346 } 40347 } 40348 [_getPrototype](ids, ancestors) { 40349 const { 40350 use, 40351 usehref 40352 } = this; 40353 if (!use && !usehref) { 40354 return null; 40355 } 40356 let proto = null; 40357 let somExpression = null; 40358 let id = null; 40359 let ref = use; 40360 if (usehref) { 40361 ref = usehref; 40362 if (usehref.startsWith("#som(") && usehref.endsWith(")")) { 40363 somExpression = usehref.slice("#som(".length, -1); 40364 } else if (usehref.startsWith(".#som(") && usehref.endsWith(")")) { 40365 somExpression = usehref.slice(".#som(".length, -1); 40366 } else if (usehref.startsWith("#")) { 40367 id = usehref.slice(1); 40368 } else if (usehref.startsWith(".#")) { 40369 id = usehref.slice(2); 40370 } 40371 } else if (use.startsWith("#")) { 40372 id = use.slice(1); 40373 } else { 40374 somExpression = use; 40375 } 40376 this.use = this.usehref = ""; 40377 if (id) { 40378 proto = ids.get(id); 40379 } else { 40380 proto = searchNode(ids.get($root), this, somExpression, true, false); 40381 if (proto) { 40382 proto = proto[0]; 40383 } 40384 } 40385 if (!proto) { 40386 warn(`XFA - Invalid prototype reference: ${ref}.`); 40387 return null; 40388 } 40389 if (proto[$nodeName] !== this[$nodeName]) { 40390 warn(`XFA - Incompatible prototype: ${proto[$nodeName]} !== ${this[$nodeName]}.`); 40391 return null; 40392 } 40393 if (ancestors.has(proto)) { 40394 warn(`XFA - Cycle detected in prototypes use.`); 40395 return null; 40396 } 40397 ancestors.add(proto); 40398 const protoProto = proto[_getPrototype](ids, ancestors); 40399 if (protoProto) { 40400 proto[_applyPrototype](protoProto, ids, ancestors); 40401 } 40402 proto[$resolvePrototypes](ids, ancestors); 40403 ancestors.delete(proto); 40404 return proto; 40405 } 40406 [_applyPrototype](proto, ids, ancestors) { 40407 if (ancestors.has(proto)) { 40408 warn(`XFA - Cycle detected in prototypes use.`); 40409 return; 40410 } 40411 if (!this[$content] && proto[$content]) { 40412 this[$content] = proto[$content]; 40413 } 40414 const newAncestors = new Set(ancestors); 40415 newAncestors.add(proto); 40416 for (const unsetAttrName of this[_getUnsetAttributes](proto[_setAttributes])) { 40417 this[unsetAttrName] = proto[unsetAttrName]; 40418 if (this[_setAttributes]) { 40419 this[_setAttributes].add(unsetAttrName); 40420 } 40421 } 40422 for (const name of Object.getOwnPropertyNames(this)) { 40423 if (this[_attributeNames].has(name)) { 40424 continue; 40425 } 40426 const value = this[name]; 40427 const protoValue = proto[name]; 40428 if (value instanceof XFAObjectArray) { 40429 for (const child of value[_children]) { 40430 child[_resolvePrototypesHelper](ids, ancestors); 40431 } 40432 for (let i = value[_children].length, ii = protoValue[_children].length; i < ii; i++) { 40433 const child = proto[_children][i][$clone](); 40434 if (value.push(child)) { 40435 child[_parent] = this; 40436 this[_children].push(child); 40437 child[_resolvePrototypesHelper](ids, ancestors); 40438 } else { 40439 break; 40440 } 40441 } 40442 continue; 40443 } 40444 if (value !== null) { 40445 value[$resolvePrototypes](ids, ancestors); 40446 if (protoValue) { 40447 value[_applyPrototype](protoValue, ids, ancestors); 40448 } 40449 continue; 40450 } 40451 if (protoValue !== null) { 40452 const child = protoValue[$clone](); 40453 child[_parent] = this; 40454 this[name] = child; 40455 this[_children].push(child); 40456 child[_resolvePrototypesHelper](ids, ancestors); 40457 } 40458 } 40459 } 40460 static [_cloneAttribute](obj) { 40461 if (Array.isArray(obj)) { 40462 return obj.map(x => XFAObject[_cloneAttribute](x)); 40463 } 40464 if (typeof obj === "object" && obj !== null) { 40465 return Object.assign({}, obj); 40466 } 40467 return obj; 40468 } 40469 [$clone]() { 40470 const clone = Object.create(Object.getPrototypeOf(this)); 40471 for (const $symbol of Object.getOwnPropertySymbols(this)) { 40472 try { 40473 clone[$symbol] = this[$symbol]; 40474 } catch { 40475 shadow(clone, $symbol, this[$symbol]); 40476 } 40477 } 40478 clone[$uid] = `${clone[$nodeName]}${uid++}`; 40479 clone[_children] = []; 40480 for (const name of Object.getOwnPropertyNames(this)) { 40481 if (this[_attributeNames].has(name)) { 40482 clone[name] = XFAObject[_cloneAttribute](this[name]); 40483 continue; 40484 } 40485 const value = this[name]; 40486 clone[name] = value instanceof XFAObjectArray ? new XFAObjectArray(value[_max]) : null; 40487 } 40488 for (const child of this[_children]) { 40489 const name = child[$nodeName]; 40490 const clonedChild = child[$clone](); 40491 clone[_children].push(clonedChild); 40492 clonedChild[_parent] = clone; 40493 if (clone[name] === null) { 40494 clone[name] = clonedChild; 40495 } else { 40496 clone[name][_children].push(clonedChild); 40497 } 40498 } 40499 return clone; 40500 } 40501 [$getChildren](name = null) { 40502 if (!name) { 40503 return this[_children]; 40504 } 40505 return this[_children].filter(c => c[$nodeName] === name); 40506 } 40507 [$getChildrenByClass](name) { 40508 return this[name]; 40509 } 40510 [$getChildrenByName](name, allTransparent, first = true) { 40511 return Array.from(this[$getChildrenByNameIt](name, allTransparent, first)); 40512 } 40513 *[$getChildrenByNameIt](name, allTransparent, first = true) { 40514 if (name === "parent") { 40515 yield this[_parent]; 40516 return; 40517 } 40518 for (const child of this[_children]) { 40519 if (child[$nodeName] === name) { 40520 yield child; 40521 } 40522 if (child.name === name) { 40523 yield child; 40524 } 40525 if (allTransparent || child[$isTransparent]()) { 40526 yield* child[$getChildrenByNameIt](name, allTransparent, false); 40527 } 40528 } 40529 if (first && this[_attributeNames].has(name)) { 40530 yield new XFAAttribute(this, name, this[name]); 40531 } 40532 } 40533} 40534class XFAObjectArray { 40535 constructor(max = Infinity) { 40536 this[_max] = max; 40537 this[_children] = []; 40538 } 40539 get isXFAObject() { 40540 return false; 40541 } 40542 get isXFAObjectArray() { 40543 return true; 40544 } 40545 push(child) { 40546 const len = this[_children].length; 40547 if (len <= this[_max]) { 40548 this[_children].push(child); 40549 return true; 40550 } 40551 warn(`XFA - node "${child[$nodeName]}" accepts no more than ${this[_max]} children`); 40552 return false; 40553 } 40554 isEmpty() { 40555 return this[_children].length === 0; 40556 } 40557 dump() { 40558 return this[_children].length === 1 ? this[_children][0][$dump]() : this[_children].map(x => x[$dump]()); 40559 } 40560 [$clone]() { 40561 const clone = new XFAObjectArray(this[_max]); 40562 clone[_children] = this[_children].map(c => c[$clone]()); 40563 return clone; 40564 } 40565 get children() { 40566 return this[_children]; 40567 } 40568 clear() { 40569 this[_children].length = 0; 40570 } 40571} 40572class XFAAttribute { 40573 constructor(node, name, value) { 40574 this[_parent] = node; 40575 this[$nodeName] = name; 40576 this[$content] = value; 40577 this[$consumed] = false; 40578 this[$uid] = `attribute${uid++}`; 40579 } 40580 [$getParent]() { 40581 return this[_parent]; 40582 } 40583 [$isDataValue]() { 40584 return true; 40585 } 40586 [$getDataValue]() { 40587 return this[$content].trim(); 40588 } 40589 [$setValue](value) { 40590 value = value.value || ""; 40591 this[$content] = value.toString(); 40592 } 40593 [$text]() { 40594 return this[$content]; 40595 } 40596 [$isDescendent](parent) { 40597 return this[_parent] === parent || this[_parent][$isDescendent](parent); 40598 } 40599} 40600class XmlObject extends XFAObject { 40601 constructor(nsId, name, attributes = {}) { 40602 super(nsId, name); 40603 this[$content] = ""; 40604 this[_dataValue] = null; 40605 if (name !== "#text") { 40606 const map = new Map(); 40607 this[_attributes] = map; 40608 for (const [attrName, value] of Object.entries(attributes)) { 40609 map.set(attrName, new XFAAttribute(this, attrName, value)); 40610 } 40611 if (attributes.hasOwnProperty($nsAttributes)) { 40612 const dataNode = attributes[$nsAttributes].xfa.dataNode; 40613 if (dataNode !== undefined) { 40614 if (dataNode === "dataGroup") { 40615 this[_dataValue] = false; 40616 } else if (dataNode === "dataValue") { 40617 this[_dataValue] = true; 40618 } 40619 } 40620 } 40621 } 40622 this[$consumed] = false; 40623 } 40624 [$toString](buf) { 40625 const tagName = this[$nodeName]; 40626 if (tagName === "#text") { 40627 buf.push(encodeToXmlString(this[$content])); 40628 return; 40629 } 40630 const utf8TagName = utf8StringToString(tagName); 40631 const prefix = this[$namespaceId] === NS_DATASETS ? "xfa:" : ""; 40632 buf.push(`<${prefix}${utf8TagName}`); 40633 for (const [name, value] of this[_attributes].entries()) { 40634 const utf8Name = utf8StringToString(name); 40635 buf.push(` ${utf8Name}="${encodeToXmlString(value[$content])}"`); 40636 } 40637 if (this[_dataValue] !== null) { 40638 if (this[_dataValue]) { 40639 buf.push(` xfa:dataNode="dataValue"`); 40640 } else { 40641 buf.push(` xfa:dataNode="dataGroup"`); 40642 } 40643 } 40644 if (!this[$content] && this[_children].length === 0) { 40645 buf.push("/>"); 40646 return; 40647 } 40648 buf.push(">"); 40649 if (this[$content]) { 40650 if (typeof this[$content] === "string") { 40651 buf.push(encodeToXmlString(this[$content])); 40652 } else { 40653 this[$content][$toString](buf); 40654 } 40655 } else { 40656 for (const child of this[_children]) { 40657 child[$toString](buf); 40658 } 40659 } 40660 buf.push(`</${prefix}${utf8TagName}>`); 40661 } 40662 [$onChild](child) { 40663 if (this[$content]) { 40664 const node = new XmlObject(this[$namespaceId], "#text"); 40665 this[$appendChild](node); 40666 node[$content] = this[$content]; 40667 this[$content] = ""; 40668 } 40669 this[$appendChild](child); 40670 return true; 40671 } 40672 [$onText](str) { 40673 this[$content] += str; 40674 } 40675 [$finalize]() { 40676 if (this[$content] && this[_children].length > 0) { 40677 const node = new XmlObject(this[$namespaceId], "#text"); 40678 this[$appendChild](node); 40679 node[$content] = this[$content]; 40680 delete this[$content]; 40681 } 40682 } 40683 [$toHTML]() { 40684 if (this[$nodeName] === "#text") { 40685 return HTMLResult.success({ 40686 name: "#text", 40687 value: this[$content] 40688 }); 40689 } 40690 return HTMLResult.EMPTY; 40691 } 40692 [$getChildren](name = null) { 40693 if (!name) { 40694 return this[_children]; 40695 } 40696 return this[_children].filter(c => c[$nodeName] === name); 40697 } 40698 [$getAttributes]() { 40699 return this[_attributes]; 40700 } 40701 [$getChildrenByClass](name) { 40702 const value = this[_attributes].get(name); 40703 if (value !== undefined) { 40704 return value; 40705 } 40706 return this[$getChildren](name); 40707 } 40708 *[$getChildrenByNameIt](name, allTransparent) { 40709 const value = this[_attributes].get(name); 40710 if (value) { 40711 yield value; 40712 } 40713 for (const child of this[_children]) { 40714 if (child[$nodeName] === name) { 40715 yield child; 40716 } 40717 if (allTransparent) { 40718 yield* child[$getChildrenByNameIt](name, allTransparent); 40719 } 40720 } 40721 } 40722 *[$getAttributeIt](name, skipConsumed) { 40723 const value = this[_attributes].get(name); 40724 if (value && (!skipConsumed || !value[$consumed])) { 40725 yield value; 40726 } 40727 for (const child of this[_children]) { 40728 yield* child[$getAttributeIt](name, skipConsumed); 40729 } 40730 } 40731 *[$getRealChildrenByNameIt](name, allTransparent, skipConsumed) { 40732 for (const child of this[_children]) { 40733 if (child[$nodeName] === name && (!skipConsumed || !child[$consumed])) { 40734 yield child; 40735 } 40736 if (allTransparent) { 40737 yield* child[$getRealChildrenByNameIt](name, allTransparent, skipConsumed); 40738 } 40739 } 40740 } 40741 [$isDataValue]() { 40742 if (this[_dataValue] === null) { 40743 return this[_children].length === 0 || this[_children][0][$namespaceId] === NamespaceIds.xhtml.id; 40744 } 40745 return this[_dataValue]; 40746 } 40747 [$getDataValue]() { 40748 if (this[_dataValue] === null) { 40749 if (this[_children].length === 0) { 40750 return this[$content].trim(); 40751 } 40752 if (this[_children][0][$namespaceId] === NamespaceIds.xhtml.id) { 40753 return this[_children][0][$text]().trim(); 40754 } 40755 return null; 40756 } 40757 return this[$content].trim(); 40758 } 40759 [$setValue](value) { 40760 value = value.value || ""; 40761 this[$content] = value.toString(); 40762 } 40763 [$dump](hasNS = false) { 40764 const dumped = Object.create(null); 40765 if (hasNS) { 40766 dumped.$ns = this[$namespaceId]; 40767 } 40768 if (this[$content]) { 40769 dumped.$content = this[$content]; 40770 } 40771 dumped.$name = this[$nodeName]; 40772 dumped.children = []; 40773 for (const child of this[_children]) { 40774 dumped.children.push(child[$dump](hasNS)); 40775 } 40776 dumped.attributes = Object.create(null); 40777 for (const [name, value] of this[_attributes]) { 40778 dumped.attributes[name] = value[$content]; 40779 } 40780 return dumped; 40781 } 40782} 40783class ContentObject extends XFAObject { 40784 constructor(nsId, name) { 40785 super(nsId, name); 40786 this[$content] = ""; 40787 } 40788 [$onText](text) { 40789 this[$content] += text; 40790 } 40791 [$finalize]() {} 40792} 40793class OptionObject extends ContentObject { 40794 constructor(nsId, name, options) { 40795 super(nsId, name); 40796 this[_options] = options; 40797 } 40798 [$finalize]() { 40799 this[$content] = getKeyword({ 40800 data: this[$content], 40801 defaultValue: this[_options][0], 40802 validate: k => this[_options].includes(k) 40803 }); 40804 } 40805 [$clean](builder) { 40806 super[$clean](builder); 40807 delete this[_options]; 40808 } 40809} 40810class StringObject extends ContentObject { 40811 [$finalize]() { 40812 this[$content] = this[$content].trim(); 40813 } 40814} 40815class IntegerObject extends ContentObject { 40816 constructor(nsId, name, defaultValue, validator) { 40817 super(nsId, name); 40818 this[_defaultValue] = defaultValue; 40819 this[_validator] = validator; 40820 } 40821 [$finalize]() { 40822 this[$content] = getInteger({ 40823 data: this[$content], 40824 defaultValue: this[_defaultValue], 40825 validate: this[_validator] 40826 }); 40827 } 40828 [$clean](builder) { 40829 super[$clean](builder); 40830 delete this[_defaultValue]; 40831 delete this[_validator]; 40832 } 40833} 40834class Option01 extends IntegerObject { 40835 constructor(nsId, name) { 40836 super(nsId, name, 0, n => n === 1); 40837 } 40838} 40839class Option10 extends IntegerObject { 40840 constructor(nsId, name) { 40841 super(nsId, name, 1, n => n === 0); 40842 } 40843} 40844 40845;// ./src/core/xfa/html_utils.js 40846 40847 40848 40849 40850 40851 40852function measureToString(m) { 40853 if (typeof m === "string") { 40854 return "0px"; 40855 } 40856 return Number.isInteger(m) ? `${m}px` : `${m.toFixed(2)}px`; 40857} 40858const converters = { 40859 anchorType(node, style) { 40860 const parent = node[$getSubformParent](); 40861 if (!parent || parent.layout && parent.layout !== "position") { 40862 return; 40863 } 40864 if (!("transform" in style)) { 40865 style.transform = ""; 40866 } 40867 switch (node.anchorType) { 40868 case "bottomCenter": 40869 style.transform += "translate(-50%, -100%)"; 40870 break; 40871 case "bottomLeft": 40872 style.transform += "translate(0,-100%)"; 40873 break; 40874 case "bottomRight": 40875 style.transform += "translate(-100%,-100%)"; 40876 break; 40877 case "middleCenter": 40878 style.transform += "translate(-50%,-50%)"; 40879 break; 40880 case "middleLeft": 40881 style.transform += "translate(0,-50%)"; 40882 break; 40883 case "middleRight": 40884 style.transform += "translate(-100%,-50%)"; 40885 break; 40886 case "topCenter": 40887 style.transform += "translate(-50%,0)"; 40888 break; 40889 case "topRight": 40890 style.transform += "translate(-100%,0)"; 40891 break; 40892 } 40893 }, 40894 dimensions(node, style) { 40895 const parent = node[$getSubformParent](); 40896 let width = node.w; 40897 const height = node.h; 40898 if (parent.layout?.includes("row")) { 40899 const extra = parent[$extra]; 40900 const colSpan = node.colSpan; 40901 let w; 40902 if (colSpan === -1) { 40903 w = Math.sumPrecise(extra.columnWidths.slice(extra.currentColumn)); 40904 extra.currentColumn = 0; 40905 } else { 40906 w = Math.sumPrecise(extra.columnWidths.slice(extra.currentColumn, extra.currentColumn + colSpan)); 40907 extra.currentColumn = (extra.currentColumn + node.colSpan) % extra.columnWidths.length; 40908 } 40909 if (!isNaN(w)) { 40910 width = node.w = w; 40911 } 40912 } 40913 style.width = width !== "" ? measureToString(width) : "auto"; 40914 style.height = height !== "" ? measureToString(height) : "auto"; 40915 }, 40916 position(node, style) { 40917 const parent = node[$getSubformParent](); 40918 if (parent?.layout && parent.layout !== "position") { 40919 return; 40920 } 40921 style.position = "absolute"; 40922 style.left = measureToString(node.x); 40923 style.top = measureToString(node.y); 40924 }, 40925 rotate(node, style) { 40926 if (node.rotate) { 40927 if (!("transform" in style)) { 40928 style.transform = ""; 40929 } 40930 style.transform += `rotate(-${node.rotate}deg)`; 40931 style.transformOrigin = "top left"; 40932 } 40933 }, 40934 presence(node, style) { 40935 switch (node.presence) { 40936 case "invisible": 40937 style.visibility = "hidden"; 40938 break; 40939 case "hidden": 40940 case "inactive": 40941 style.display = "none"; 40942 break; 40943 } 40944 }, 40945 hAlign(node, style) { 40946 if (node[$nodeName] === "para") { 40947 switch (node.hAlign) { 40948 case "justifyAll": 40949 style.textAlign = "justify-all"; 40950 break; 40951 case "radix": 40952 style.textAlign = "left"; 40953 break; 40954 default: 40955 style.textAlign = node.hAlign; 40956 } 40957 } else { 40958 switch (node.hAlign) { 40959 case "left": 40960 style.alignSelf = "start"; 40961 break; 40962 case "center": 40963 style.alignSelf = "center"; 40964 break; 40965 case "right": 40966 style.alignSelf = "end"; 40967 break; 40968 } 40969 } 40970 }, 40971 margin(node, style) { 40972 if (node.margin) { 40973 style.margin = node.margin[$toStyle]().margin; 40974 } 40975 } 40976}; 40977function setMinMaxDimensions(node, style) { 40978 const parent = node[$getSubformParent](); 40979 if (parent.layout === "position") { 40980 if (node.minW > 0) { 40981 style.minWidth = measureToString(node.minW); 40982 } 40983 if (node.maxW > 0) { 40984 style.maxWidth = measureToString(node.maxW); 40985 } 40986 if (node.minH > 0) { 40987 style.minHeight = measureToString(node.minH); 40988 } 40989 if (node.maxH > 0) { 40990 style.maxHeight = measureToString(node.maxH); 40991 } 40992 } 40993} 40994function layoutText(text, xfaFont, margin, lineHeight, fontFinder, width) { 40995 const measure = new TextMeasure(xfaFont, margin, lineHeight, fontFinder); 40996 if (typeof text === "string") { 40997 measure.addString(text); 40998 } else { 40999 text[$pushGlyphs](measure); 41000 } 41001 return measure.compute(width); 41002} 41003function layoutNode(node, availableSpace) { 41004 let height = null; 41005 let width = null; 41006 let isBroken = false; 41007 if ((!node.w || !node.h) && node.value) { 41008 let marginH = 0; 41009 let marginV = 0; 41010 if (node.margin) { 41011 marginH = node.margin.leftInset + node.margin.rightInset; 41012 marginV = node.margin.topInset + node.margin.bottomInset; 41013 } 41014 let lineHeight = null; 41015 let margin = null; 41016 if (node.para) { 41017 margin = Object.create(null); 41018 lineHeight = node.para.lineHeight === "" ? null : node.para.lineHeight; 41019 margin.top = node.para.spaceAbove === "" ? 0 : node.para.spaceAbove; 41020 margin.bottom = node.para.spaceBelow === "" ? 0 : node.para.spaceBelow; 41021 margin.left = node.para.marginLeft === "" ? 0 : node.para.marginLeft; 41022 margin.right = node.para.marginRight === "" ? 0 : node.para.marginRight; 41023 } 41024 let font = node.font; 41025 if (!font) { 41026 const root = node[$getTemplateRoot](); 41027 let parent = node[$getParent](); 41028 while (parent && parent !== root) { 41029 if (parent.font) { 41030 font = parent.font; 41031 break; 41032 } 41033 parent = parent[$getParent](); 41034 } 41035 } 41036 const maxWidth = (node.w || availableSpace.width) - marginH; 41037 const fontFinder = node[$globalData].fontFinder; 41038 if (node.value.exData && node.value.exData[$content] && node.value.exData.contentType === "text/html") { 41039 const res = layoutText(node.value.exData[$content], font, margin, lineHeight, fontFinder, maxWidth); 41040 width = res.width; 41041 height = res.height; 41042 isBroken = res.isBroken; 41043 } else { 41044 const text = node.value[$text](); 41045 if (text) { 41046 const res = layoutText(text, font, margin, lineHeight, fontFinder, maxWidth); 41047 width = res.width; 41048 height = res.height; 41049 isBroken = res.isBroken; 41050 } 41051 } 41052 if (width !== null && !node.w) { 41053 width += marginH; 41054 } 41055 if (height !== null && !node.h) { 41056 height += marginV; 41057 } 41058 } 41059 return { 41060 w: width, 41061 h: height, 41062 isBroken 41063 }; 41064} 41065function computeBbox(node, html, availableSpace) { 41066 let bbox; 41067 if (node.w !== "" && node.h !== "") { 41068 bbox = [node.x, node.y, node.w, node.h]; 41069 } else { 41070 if (!availableSpace) { 41071 return null; 41072 } 41073 let width = node.w; 41074 if (width === "") { 41075 if (node.maxW === 0) { 41076 const parent = node[$getSubformParent](); 41077 width = parent.layout === "position" && parent.w !== "" ? 0 : node.minW; 41078 } else { 41079 width = Math.min(node.maxW, availableSpace.width); 41080 } 41081 html.attributes.style.width = measureToString(width); 41082 } 41083 let height = node.h; 41084 if (height === "") { 41085 if (node.maxH === 0) { 41086 const parent = node[$getSubformParent](); 41087 height = parent.layout === "position" && parent.h !== "" ? 0 : node.minH; 41088 } else { 41089 height = Math.min(node.maxH, availableSpace.height); 41090 } 41091 html.attributes.style.height = measureToString(height); 41092 } 41093 bbox = [node.x, node.y, width, height]; 41094 } 41095 return bbox; 41096} 41097function fixDimensions(node) { 41098 const parent = node[$getSubformParent](); 41099 if (parent.layout?.includes("row")) { 41100 const extra = parent[$extra]; 41101 const colSpan = node.colSpan; 41102 let width; 41103 if (colSpan === -1) { 41104 width = Math.sumPrecise(extra.columnWidths.slice(extra.currentColumn)); 41105 } else { 41106 width = Math.sumPrecise(extra.columnWidths.slice(extra.currentColumn, extra.currentColumn + colSpan)); 41107 } 41108 if (!isNaN(width)) { 41109 node.w = width; 41110 } 41111 } 41112 if (parent.layout && parent.layout !== "position") { 41113 node.x = node.y = 0; 41114 } 41115 if (node.layout === "table") { 41116 if (node.w === "" && Array.isArray(node.columnWidths)) { 41117 node.w = Math.sumPrecise(node.columnWidths); 41118 } 41119 } 41120} 41121function layoutClass(node) { 41122 switch (node.layout) { 41123 case "position": 41124 return "xfaPosition"; 41125 case "lr-tb": 41126 return "xfaLrTb"; 41127 case "rl-row": 41128 return "xfaRlRow"; 41129 case "rl-tb": 41130 return "xfaRlTb"; 41131 case "row": 41132 return "xfaRow"; 41133 case "table": 41134 return "xfaTable"; 41135 case "tb": 41136 return "xfaTb"; 41137 default: 41138 return "xfaPosition"; 41139 } 41140} 41141function toStyle(node, ...names) { 41142 const style = Object.create(null); 41143 for (const name of names) { 41144 const value = node[name]; 41145 if (value === null) { 41146 continue; 41147 } 41148 if (converters.hasOwnProperty(name)) { 41149 converters[name](node, style); 41150 continue; 41151 } 41152 if (value instanceof XFAObject) { 41153 const newStyle = value[$toStyle](); 41154 if (newStyle) { 41155 Object.assign(style, newStyle); 41156 } else { 41157 warn(`(DEBUG) - XFA - style for ${name} not implemented yet`); 41158 } 41159 } 41160 } 41161 return style; 41162} 41163function createWrapper(node, html) { 41164 const { 41165 attributes 41166 } = html; 41167 const { 41168 style 41169 } = attributes; 41170 const wrapper = { 41171 name: "div", 41172 attributes: { 41173 class: ["xfaWrapper"], 41174 style: Object.create(null) 41175 }, 41176 children: [] 41177 }; 41178 attributes.class.push("xfaWrapped"); 41179 if (node.border) { 41180 const { 41181 widths, 41182 insets 41183 } = node.border[$extra]; 41184 let width, height; 41185 let top = insets[0]; 41186 let left = insets[3]; 41187 const insetsH = insets[0] + insets[2]; 41188 const insetsW = insets[1] + insets[3]; 41189 switch (node.border.hand) { 41190 case "even": 41191 top -= widths[0] / 2; 41192 left -= widths[3] / 2; 41193 width = `calc(100% + ${(widths[1] + widths[3]) / 2 - insetsW}px)`; 41194 height = `calc(100% + ${(widths[0] + widths[2]) / 2 - insetsH}px)`; 41195 break; 41196 case "left": 41197 top -= widths[0]; 41198 left -= widths[3]; 41199 width = `calc(100% + ${widths[1] + widths[3] - insetsW}px)`; 41200 height = `calc(100% + ${widths[0] + widths[2] - insetsH}px)`; 41201 break; 41202 case "right": 41203 width = insetsW ? `calc(100% - ${insetsW}px)` : "100%"; 41204 height = insetsH ? `calc(100% - ${insetsH}px)` : "100%"; 41205 break; 41206 } 41207 const classNames = ["xfaBorder"]; 41208 if (isPrintOnly(node.border)) { 41209 classNames.push("xfaPrintOnly"); 41210 } 41211 const border = { 41212 name: "div", 41213 attributes: { 41214 class: classNames, 41215 style: { 41216 top: `${top}px`, 41217 left: `${left}px`, 41218 width, 41219 height 41220 } 41221 }, 41222 children: [] 41223 }; 41224 for (const key of ["border", "borderWidth", "borderColor", "borderRadius", "borderStyle"]) { 41225 if (style[key] !== undefined) { 41226 border.attributes.style[key] = style[key]; 41227 delete style[key]; 41228 } 41229 } 41230 wrapper.children.push(border, html); 41231 } else { 41232 wrapper.children.push(html); 41233 } 41234 for (const key of ["background", "backgroundClip", "top", "left", "width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight", "transform", "transformOrigin", "visibility"]) { 41235 if (style[key] !== undefined) { 41236 wrapper.attributes.style[key] = style[key]; 41237 delete style[key]; 41238 } 41239 } 41240 wrapper.attributes.style.position = style.position === "absolute" ? "absolute" : "relative"; 41241 delete style.position; 41242 if (style.alignSelf) { 41243 wrapper.attributes.style.alignSelf = style.alignSelf; 41244 delete style.alignSelf; 41245 } 41246 return wrapper; 41247} 41248function fixTextIndent(styles) { 41249 const indent = getMeasurement(styles.textIndent, "0px"); 41250 if (indent >= 0) { 41251 return; 41252 } 41253 const align = styles.textAlign === "right" ? "right" : "left"; 41254 const name = "padding" + (align === "left" ? "Left" : "Right"); 41255 const padding = getMeasurement(styles[name], "0px"); 41256 styles[name] = `${padding - indent}px`; 41257} 41258function setAccess(node, classNames) { 41259 switch (node.access) { 41260 case "nonInteractive": 41261 classNames.push("xfaNonInteractive"); 41262 break; 41263 case "readOnly": 41264 classNames.push("xfaReadOnly"); 41265 break; 41266 case "protected": 41267 classNames.push("xfaDisabled"); 41268 break; 41269 } 41270} 41271function isPrintOnly(node) { 41272 return node.relevant.length > 0 && !node.relevant[0].excluded && node.relevant[0].viewname === "print"; 41273} 41274function getCurrentPara(node) { 41275 const stack = node[$getTemplateRoot]()[$extra].paraStack; 41276 return stack.length ? stack.at(-1) : null; 41277} 41278function setPara(node, nodeStyle, value) { 41279 if (value.attributes.class?.includes("xfaRich")) { 41280 if (nodeStyle) { 41281 if (node.h === "") { 41282 nodeStyle.height = "auto"; 41283 } 41284 if (node.w === "") { 41285 nodeStyle.width = "auto"; 41286 } 41287 } 41288 const para = getCurrentPara(node); 41289 if (para) { 41290 const valueStyle = value.attributes.style; 41291 valueStyle.display = "flex"; 41292 valueStyle.flexDirection = "column"; 41293 switch (para.vAlign) { 41294 case "top": 41295 valueStyle.justifyContent = "start"; 41296 break; 41297 case "bottom": 41298 valueStyle.justifyContent = "end"; 41299 break; 41300 case "middle": 41301 valueStyle.justifyContent = "center"; 41302 break; 41303 } 41304 const paraStyle = para[$toStyle](); 41305 for (const [key, val] of Object.entries(paraStyle)) { 41306 if (!(key in valueStyle)) { 41307 valueStyle[key] = val; 41308 } 41309 } 41310 } 41311 } 41312} 41313function setFontFamily(xfaFont, node, fontFinder, style) { 41314 if (!fontFinder) { 41315 delete style.fontFamily; 41316 return; 41317 } 41318 const name = stripQuotes(xfaFont.typeface); 41319 style.fontFamily = `"${name}"`; 41320 const typeface = fontFinder.find(name); 41321 if (typeface) { 41322 const { 41323 fontFamily 41324 } = typeface.regular.cssFontInfo; 41325 if (fontFamily !== name) { 41326 style.fontFamily = `"${fontFamily}"`; 41327 } 41328 const para = getCurrentPara(node); 41329 if (para && para.lineHeight !== "") { 41330 return; 41331 } 41332 if (style.lineHeight) { 41333 return; 41334 } 41335 const pdfFont = selectFont(xfaFont, typeface); 41336 if (pdfFont) { 41337 style.lineHeight = Math.max(1.2, pdfFont.lineHeight); 41338 } 41339 } 41340} 41341function fixURL(str) { 41342 const absoluteUrl = createValidAbsoluteUrl(str, null, { 41343 addDefaultProtocol: true, 41344 tryConvertEncoding: true 41345 }); 41346 return absoluteUrl ? absoluteUrl.href : null; 41347} 41348 41349;// ./src/core/xfa/layout.js 41350 41351 41352
vendor: 7,526 bytes, lines 41353-41630
41353function createLine(node, children) { 41354 return { 41355 name: "div", 41356 attributes: { 41357 class: [node.layout === "lr-tb" ? "xfaLr" : "xfaRl"] 41358 }, 41359 children 41360 }; 41361} 41362function flushHTML(node) { 41363 if (!node[$extra]) { 41364 return null; 41365 } 41366 const attributes = node[$extra].attributes; 41367 const html = { 41368 name: "div", 41369 attributes, 41370 children: node[$extra].children 41371 }; 41372 if (node[$extra].failingNode) { 41373 const htmlFromFailing = node[$extra].failingNode[$flushHTML](); 41374 if (htmlFromFailing) { 41375 if (node.layout.endsWith("-tb")) { 41376 html.children.push(createLine(node, [htmlFromFailing])); 41377 } else { 41378 html.children.push(htmlFromFailing); 41379 } 41380 } 41381 } 41382 if (html.children.length === 0) { 41383 return null; 41384 } 41385 return html; 41386} 41387function addHTML(node, html, bbox) { 41388 const extra = node[$extra]; 41389 const availableSpace = extra.availableSpace; 41390 const [x, y, w, h] = bbox; 41391 switch (node.layout) { 41392 case "position": 41393 { 41394 extra.width = Math.max(extra.width, x + w); 41395 extra.height = Math.max(extra.height, y + h); 41396 extra.children.push(html); 41397 break; 41398 } 41399 case "lr-tb": 41400 case "rl-tb": 41401 if (!extra.line || extra.attempt === 1) { 41402 extra.line = createLine(node, []); 41403 extra.children.push(extra.line); 41404 extra.numberInLine = 0; 41405 } 41406 extra.numberInLine += 1; 41407 extra.line.children.push(html); 41408 if (extra.attempt === 0) { 41409 extra.currentWidth += w; 41410 extra.height = Math.max(extra.height, extra.prevHeight + h); 41411 } else { 41412 extra.currentWidth = w; 41413 extra.prevHeight = extra.height; 41414 extra.height += h; 41415 extra.attempt = 0; 41416 } 41417 extra.width = Math.max(extra.width, extra.currentWidth); 41418 break; 41419 case "rl-row": 41420 case "row": 41421 { 41422 extra.children.push(html); 41423 extra.width += w; 41424 extra.height = Math.max(extra.height, h); 41425 const height = measureToString(extra.height); 41426 for (const child of extra.children) { 41427 child.attributes.style.height = height; 41428 } 41429 break; 41430 } 41431 case "table": 41432 { 41433 extra.width = MathClamp(w, extra.width, availableSpace.width); 41434 extra.height += h; 41435 extra.children.push(html); 41436 break; 41437 } 41438 case "tb": 41439 { 41440 extra.width = MathClamp(w, extra.width, availableSpace.width); 41441 extra.height += h; 41442 extra.children.push(html); 41443 break; 41444 } 41445 } 41446} 41447function getAvailableSpace(node) { 41448 const availableSpace = node[$extra].availableSpace; 41449 const marginV = node.margin ? node.margin.topInset + node.margin.bottomInset : 0; 41450 const marginH = node.margin ? node.margin.leftInset + node.margin.rightInset : 0; 41451 switch (node.layout) { 41452 case "lr-tb": 41453 case "rl-tb": 41454 if (node[$extra].attempt === 0) { 41455 return { 41456 width: availableSpace.width - marginH - node[$extra].currentWidth, 41457 height: availableSpace.height - marginV - node[$extra].prevHeight 41458 }; 41459 } 41460 return { 41461 width: availableSpace.width - marginH, 41462 height: availableSpace.height - marginV - node[$extra].height 41463 }; 41464 case "rl-row": 41465 case "row": 41466 const width = Math.sumPrecise(node[$extra].columnWidths.slice(node[$extra].currentColumn)); 41467 return { 41468 width, 41469 height: availableSpace.height - marginH 41470 }; 41471 case "table": 41472 case "tb": 41473 return { 41474 width: availableSpace.width - marginH, 41475 height: availableSpace.height - marginV - node[$extra].height 41476 }; 41477 case "position": 41478 default: 41479 return availableSpace; 41480 } 41481} 41482function getTransformedBBox(node) { 41483 let w = node.w === "" ? NaN : node.w; 41484 let h = node.h === "" ? NaN : node.h; 41485 let [centerX, centerY] = [0, 0]; 41486 switch (node.anchorType || "") { 41487 case "bottomCenter": 41488 [centerX, centerY] = [w / 2, h]; 41489 break; 41490 case "bottomLeft": 41491 [centerX, centerY] = [0, h]; 41492 break; 41493 case "bottomRight": 41494 [centerX, centerY] = [w, h]; 41495 break; 41496 case "middleCenter": 41497 [centerX, centerY] = [w / 2, h / 2]; 41498 break; 41499 case "middleLeft": 41500 [centerX, centerY] = [0, h / 2]; 41501 break; 41502 case "middleRight": 41503 [centerX, centerY] = [w, h / 2]; 41504 break; 41505 case "topCenter": 41506 [centerX, centerY] = [w / 2, 0]; 41507 break; 41508 case "topRight": 41509 [centerX, centerY] = [w, 0]; 41510 break; 41511 } 41512 let x, y; 41513 switch (node.rotate || 0) { 41514 case 0: 41515 [x, y] = [-centerX, -centerY]; 41516 break; 41517 case 90: 41518 [x, y] = [-centerY, centerX]; 41519 [w, h] = [h, -w]; 41520 break; 41521 case 180: 41522 [x, y] = [centerX, centerY]; 41523 [w, h] = [-w, -h]; 41524 break; 41525 case 270: 41526 [x, y] = [centerY, -centerX]; 41527 [w, h] = [-h, w]; 41528 break; 41529 } 41530 return [node.x + x + Math.min(0, w), node.y + y + Math.min(0, h), Math.abs(w), Math.abs(h)]; 41531} 41532function checkDimensions(node, space) { 41533 if (node[$getTemplateRoot]()[$extra].firstUnsplittable === null) { 41534 return true; 41535 } 41536 if (node.w === 0 || node.h === 0) { 41537 return true; 41538 } 41539 const ERROR = 2; 41540 const parent = node[$getSubformParent](); 41541 const attempt = parent[$extra]?.attempt || 0; 41542 const [, y, w, h] = getTransformedBBox(node); 41543 switch (parent.layout) { 41544 case "lr-tb": 41545 case "rl-tb": 41546 if (attempt === 0) { 41547 if (!node[$getTemplateRoot]()[$extra].noLayoutFailure) { 41548 if (node.h !== "" && Math.round(h - space.height) > ERROR) { 41549 return false; 41550 } 41551 if (node.w !== "") { 41552 if (Math.round(w - space.width) <= ERROR) { 41553 return true; 41554 } 41555 if (parent[$extra].numberInLine === 0) { 41556 return space.height > ERROR; 41557 } 41558 return false; 41559 } 41560 return space.width > ERROR; 41561 } 41562 if (node.w !== "") { 41563 return Math.round(w - space.width) <= ERROR; 41564 } 41565 return space.width > ERROR; 41566 } 41567 if (node[$getTemplateRoot]()[$extra].noLayoutFailure) { 41568 return true; 41569 } 41570 if (node.h !== "" && Math.round(h - space.height) > ERROR) { 41571 return false; 41572 } 41573 if (node.w === "" || Math.round(w - space.width) <= ERROR) { 41574 return space.height > ERROR; 41575 } 41576 if (parent[$isThereMoreWidth]()) { 41577 return false; 41578 } 41579 return space.height > ERROR; 41580 case "table": 41581 case "tb": 41582 if (node[$getTemplateRoot]()[$extra].noLayoutFailure) { 41583 return true; 41584 } 41585 if (node.h !== "" && !node[$isSplittable]()) { 41586 return Math.round(h - space.height) <= ERROR; 41587 } 41588 if (node.w === "" || Math.round(w - space.width) <= ERROR) { 41589 return space.height > ERROR; 41590 } 41591 if (parent[$isThereMoreWidth]()) { 41592 return false; 41593 } 41594 return space.height > ERROR; 41595 case "position": 41596 if (node[$getTemplateRoot]()[$extra].noLayoutFailure) { 41597 return true; 41598 } 41599 if (node.h === "" || Math.round(h + y - space.height) <= ERROR) { 41600 return true; 41601 } 41602 const area = node[$getTemplateRoot]()[$extra].currentContentArea; 41603 return h + y > area.h; 41604 case "rl-row": 41605 case "row": 41606 if (node[$getTemplateRoot]()[$extra].noLayoutFailure) { 41607 return true; 41608 } 41609 if (node.h !== "") { 41610 return Math.round(h - space.height) <= ERROR; 41611 } 41612 return true; 41613 default: 41614 return true; 41615 } 41616} 41617 41618;// ./src/core/xfa/template.js 41619 41620 41621 41622 41623 41624 41625 41626 41627 41628 41629const TEMPLATE_NS_ID = NamespaceIds.template.id; 41630const SVG_NS = "http://www.w3.org/2000/svg"
vendor: 61,840 bytes, lines 41630-43557
41630; 41631const MAX_ATTEMPTS_FOR_LRTB_LAYOUT = 2; 41632const MAX_EMPTY_PAGES = 3; 41633const DEFAULT_TAB_INDEX = 5000; 41634const HEADING_PATTERN = /^H(\d+)$/; 41635const MIMES = new Set(["image/gif", "image/jpeg", "image/jpg", "image/pjpeg", "image/png", "image/apng", "image/x-png", "image/bmp", "image/x-ms-bmp", "image/tiff", "image/tif", "application/octet-stream"]); 41636const IMAGES_HEADERS = [[[0x42, 0x4d], "image/bmp"], [[0xff, 0xd8, 0xff], "image/jpeg"], [[0x49, 0x49, 0x2a, 0x00], "image/tiff"], [[0x4d, 0x4d, 0x00, 0x2a], "image/tiff"], [[0x47, 0x49, 0x46, 0x38, 0x39, 0x61], "image/gif"], [[0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a], "image/png"]]; 41637function getBorderDims(node) { 41638 if (!node || !node.border) { 41639 return { 41640 w: 0, 41641 h: 0 41642 }; 41643 } 41644 const borderExtra = node.border[$getExtra](); 41645 if (!borderExtra) { 41646 return { 41647 w: 0, 41648 h: 0 41649 }; 41650 } 41651 return { 41652 w: borderExtra.widths[0] + borderExtra.widths[2] + borderExtra.insets[0] + borderExtra.insets[2], 41653 h: borderExtra.widths[1] + borderExtra.widths[3] + borderExtra.insets[1] + borderExtra.insets[3] 41654 }; 41655} 41656function hasMargin(node) { 41657 return node.margin && (node.margin.topInset || node.margin.rightInset || node.margin.bottomInset || node.margin.leftInset); 41658} 41659function _setValue(templateNode, value) { 41660 if (!templateNode.value) { 41661 const nodeValue = new Value({}); 41662 templateNode[$appendChild](nodeValue); 41663 templateNode.value = nodeValue; 41664 } 41665 templateNode.value[$setValue](value); 41666} 41667function* getContainedChildren(node) { 41668 for (const child of node[$getChildren]()) { 41669 if (child instanceof SubformSet) { 41670 yield* child[$getContainedChildren](); 41671 continue; 41672 } 41673 yield child; 41674 } 41675} 41676function isRequired(node) { 41677 return node.validate?.nullTest === "error"; 41678} 41679function setTabIndex(node) { 41680 while (node) { 41681 if (!node.traversal) { 41682 node[$tabIndex] = node[$getParent]()[$tabIndex]; 41683 return; 41684 } 41685 if (node[$tabIndex]) { 41686 return; 41687 } 41688 let next = null; 41689 for (const child of node.traversal[$getChildren]()) { 41690 if (child.operation === "next") { 41691 next = child; 41692 break; 41693 } 41694 } 41695 if (!next || !next.ref) { 41696 node[$tabIndex] = node[$getParent]()[$tabIndex]; 41697 return; 41698 } 41699 const root = node[$getTemplateRoot](); 41700 node[$tabIndex] = ++root[$tabIndex]; 41701 const ref = root[$searchNode](next.ref, node); 41702 if (!ref) { 41703 return; 41704 } 41705 node = ref[0]; 41706 } 41707} 41708function applyAssist(obj, attributes) { 41709 const assist = obj.assist; 41710 if (assist) { 41711 const assistTitle = assist[$toHTML](); 41712 if (assistTitle) { 41713 attributes.title = assistTitle; 41714 } 41715 const role = assist.role; 41716 const match = role.match(HEADING_PATTERN); 41717 if (match) { 41718 const ariaRole = "heading"; 41719 const ariaLevel = match[1]; 41720 attributes.role = ariaRole; 41721 attributes["aria-level"] = ariaLevel; 41722 } 41723 } 41724 if (obj.layout === "table") { 41725 attributes.role = "table"; 41726 } else if (obj.layout === "row") { 41727 attributes.role = "row"; 41728 } else { 41729 const parent = obj[$getParent](); 41730 if (parent.layout === "row") { 41731 attributes.role = parent.assist?.role === "TH" ? "columnheader" : "cell"; 41732 } 41733 } 41734} 41735function ariaLabel(obj) { 41736 if (!obj.assist) { 41737 return null; 41738 } 41739 const assist = obj.assist; 41740 if (assist.speak && assist.speak[$content] !== "") { 41741 return assist.speak[$content]; 41742 } 41743 if (assist.toolTip) { 41744 return assist.toolTip[$content]; 41745 } 41746 return null; 41747} 41748function valueToHtml(value) { 41749 return HTMLResult.success({ 41750 name: "div", 41751 attributes: { 41752 class: ["xfaRich"], 41753 style: Object.create(null) 41754 }, 41755 children: [{ 41756 name: "span", 41757 attributes: { 41758 style: Object.create(null) 41759 }, 41760 value 41761 }] 41762 }); 41763} 41764function setFirstUnsplittable(node) { 41765 const root = node[$getTemplateRoot](); 41766 if (root[$extra].firstUnsplittable === null) { 41767 root[$extra].firstUnsplittable = node; 41768 root[$extra].noLayoutFailure = true; 41769 } 41770} 41771function unsetFirstUnsplittable(node) { 41772 const root = node[$getTemplateRoot](); 41773 if (root[$extra].firstUnsplittable === node) { 41774 root[$extra].noLayoutFailure = false; 41775 } 41776} 41777function handleBreak(node) { 41778 if (node[$extra]) { 41779 return false; 41780 } 41781 node[$extra] = Object.create(null); 41782 if (node.targetType === "auto") { 41783 return false; 41784 } 41785 const root = node[$getTemplateRoot](); 41786 let target = null; 41787 if (node.target) { 41788 target = root[$searchNode](node.target, node[$getParent]()); 41789 if (!target) { 41790 return false; 41791 } 41792 target = target[0]; 41793 } 41794 const { 41795 currentPageArea, 41796 currentContentArea 41797 } = root[$extra]; 41798 if (node.targetType === "pageArea") { 41799 if (!(target instanceof PageArea)) { 41800 target = null; 41801 } 41802 if (node.startNew) { 41803 node[$extra].target = target || currentPageArea; 41804 return true; 41805 } else if (target && target !== currentPageArea) { 41806 node[$extra].target = target; 41807 return true; 41808 } 41809 return false; 41810 } 41811 if (!(target instanceof ContentArea)) { 41812 target = null; 41813 } 41814 const pageArea = target && target[$getParent](); 41815 let index; 41816 let nextPageArea = pageArea; 41817 if (node.startNew) { 41818 if (target) { 41819 const contentAreas = pageArea.contentArea.children; 41820 const indexForCurrent = contentAreas.indexOf(currentContentArea); 41821 const indexForTarget = contentAreas.indexOf(target); 41822 if (indexForCurrent !== -1 && indexForCurrent < indexForTarget) { 41823 nextPageArea = null; 41824 } 41825 index = indexForTarget - 1; 41826 } else { 41827 index = currentPageArea.contentArea.children.indexOf(currentContentArea); 41828 } 41829 } else if (target && target !== currentContentArea) { 41830 const contentAreas = pageArea.contentArea.children; 41831 index = contentAreas.indexOf(target) - 1; 41832 nextPageArea = pageArea === currentPageArea ? null : pageArea; 41833 } else { 41834 return false; 41835 } 41836 node[$extra].target = nextPageArea; 41837 node[$extra].index = index; 41838 return true; 41839} 41840function handleOverflow(node, extraNode, space) { 41841 const root = node[$getTemplateRoot](); 41842 const saved = root[$extra].noLayoutFailure; 41843 const savedMethod = extraNode[$getSubformParent]; 41844 extraNode[$getSubformParent] = () => node; 41845 root[$extra].noLayoutFailure = true; 41846 const res = extraNode[$toHTML](space); 41847 node[$addHTML](res.html, res.bbox); 41848 root[$extra].noLayoutFailure = saved; 41849 extraNode[$getSubformParent] = savedMethod; 41850} 41851class AppearanceFilter extends StringObject { 41852 constructor(attributes) { 41853 super(TEMPLATE_NS_ID, "appearanceFilter"); 41854 this.id = attributes.id || ""; 41855 this.type = getStringOption(attributes.type, ["optional", "required"]); 41856 this.use = attributes.use || ""; 41857 this.usehref = attributes.usehref || ""; 41858 } 41859} 41860class Arc extends XFAObject { 41861 constructor(attributes) { 41862 super(TEMPLATE_NS_ID, "arc", true); 41863 this.circular = getInteger({ 41864 data: attributes.circular, 41865 defaultValue: 0, 41866 validate: x => x === 1 41867 }); 41868 this.hand = getStringOption(attributes.hand, ["even", "left", "right"]); 41869 this.id = attributes.id || ""; 41870 this.startAngle = getFloat({ 41871 data: attributes.startAngle, 41872 defaultValue: 0, 41873 validate: x => true 41874 }); 41875 this.sweepAngle = getFloat({ 41876 data: attributes.sweepAngle, 41877 defaultValue: 360, 41878 validate: x => true 41879 }); 41880 this.use = attributes.use || ""; 41881 this.usehref = attributes.usehref || ""; 41882 this.edge = null; 41883 this.fill = null; 41884 } 41885 [$toHTML]() { 41886 const edge = this.edge || new Edge({}); 41887 const edgeStyle = edge[$toStyle](); 41888 const style = Object.create(null); 41889 if (this.fill?.presence === "visible") { 41890 Object.assign(style, this.fill[$toStyle]()); 41891 } else { 41892 style.fill = "transparent"; 41893 } 41894 style.strokeWidth = measureToString(edge.presence === "visible" ? edge.thickness : 0); 41895 style.stroke = edgeStyle.color; 41896 let arc; 41897 const attributes = { 41898 xmlns: SVG_NS, 41899 style: { 41900 width: "100%", 41901 height: "100%", 41902 overflow: "visible" 41903 } 41904 }; 41905 if (this.sweepAngle === 360) { 41906 arc = { 41907 name: "ellipse", 41908 attributes: { 41909 xmlns: SVG_NS, 41910 cx: "50%", 41911 cy: "50%", 41912 rx: "50%", 41913 ry: "50%", 41914 style 41915 } 41916 }; 41917 } else { 41918 const startAngle = this.startAngle * Math.PI / 180; 41919 const sweepAngle = this.sweepAngle * Math.PI / 180; 41920 const largeArc = this.sweepAngle > 180 ? 1 : 0; 41921 const [x1, y1, x2, y2] = [50 * (1 + Math.cos(startAngle)), 50 * (1 - Math.sin(startAngle)), 50 * (1 + Math.cos(startAngle + sweepAngle)), 50 * (1 - Math.sin(startAngle + sweepAngle))]; 41922 arc = { 41923 name: "path", 41924 attributes: { 41925 xmlns: SVG_NS, 41926 d: `M ${x1} ${y1} A 50 50 0 ${largeArc} 0 ${x2} ${y2}`, 41927 vectorEffect: "non-scaling-stroke", 41928 style 41929 } 41930 }; 41931 Object.assign(attributes, { 41932 viewBox: "0 0 100 100", 41933 preserveAspectRatio: "none" 41934 }); 41935 } 41936 const svg = { 41937 name: "svg", 41938 children: [arc], 41939 attributes 41940 }; 41941 const parent = this[$getParent]()[$getParent](); 41942 if (hasMargin(parent)) { 41943 return HTMLResult.success({ 41944 name: "div", 41945 attributes: { 41946 style: { 41947 display: "inline", 41948 width: "100%", 41949 height: "100%" 41950 } 41951 }, 41952 children: [svg] 41953 }); 41954 } 41955 svg.attributes.style.position = "absolute"; 41956 return HTMLResult.success(svg); 41957 } 41958} 41959class Area extends XFAObject { 41960 constructor(attributes) { 41961 super(TEMPLATE_NS_ID, "area", true); 41962 this.colSpan = getInteger({ 41963 data: attributes.colSpan, 41964 defaultValue: 1, 41965 validate: n => n >= 1 || n === -1 41966 }); 41967 this.id = attributes.id || ""; 41968 this.name = attributes.name || ""; 41969 this.relevant = getRelevant(attributes.relevant); 41970 this.use = attributes.use || ""; 41971 this.usehref = attributes.usehref || ""; 41972 this.x = getMeasurement(attributes.x, "0pt"); 41973 this.y = getMeasurement(attributes.y, "0pt"); 41974 this.desc = null; 41975 this.extras = null; 41976 this.area = new XFAObjectArray(); 41977 this.draw = new XFAObjectArray(); 41978 this.exObject = new XFAObjectArray(); 41979 this.exclGroup = new XFAObjectArray(); 41980 this.field = new XFAObjectArray(); 41981 this.subform = new XFAObjectArray(); 41982 this.subformSet = new XFAObjectArray(); 41983 } 41984 *[$getContainedChildren]() { 41985 yield* getContainedChildren(this); 41986 } 41987 [$isTransparent]() { 41988 return true; 41989 } 41990 [$isBindable]() { 41991 return true; 41992 } 41993 [$addHTML](html, bbox) { 41994 const [x, y, w, h] = bbox; 41995 this[$extra].width = Math.max(this[$extra].width, x + w); 41996 this[$extra].height = Math.max(this[$extra].height, y + h); 41997 this[$extra].children.push(html); 41998 } 41999 [$getAvailableSpace]() { 42000 return this[$extra].availableSpace; 42001 } 42002 [$toHTML](availableSpace) { 42003 const style = toStyle(this, "position"); 42004 const attributes = { 42005 style, 42006 id: this[$uid], 42007 class: ["xfaArea"] 42008 }; 42009 if (isPrintOnly(this)) { 42010 attributes.class.push("xfaPrintOnly"); 42011 } 42012 if (this.name) { 42013 attributes.xfaName = this.name; 42014 } 42015 const children = []; 42016 this[$extra] = { 42017 children, 42018 width: 0, 42019 height: 0, 42020 availableSpace 42021 }; 42022 const result = this[$childrenToHTML]({ 42023 filter: new Set(["area", "draw", "field", "exclGroup", "subform", "subformSet"]), 42024 include: true 42025 }); 42026 if (!result.success) { 42027 if (result.isBreak()) { 42028 return result; 42029 } 42030 delete this[$extra]; 42031 return HTMLResult.FAILURE; 42032 } 42033 style.width = measureToString(this[$extra].width); 42034 style.height = measureToString(this[$extra].height); 42035 const html = { 42036 name: "div", 42037 attributes, 42038 children 42039 }; 42040 const bbox = [this.x, this.y, this[$extra].width, this[$extra].height]; 42041 delete this[$extra]; 42042 return HTMLResult.success(html, bbox); 42043 } 42044} 42045class Assist extends XFAObject { 42046 constructor(attributes) { 42047 super(TEMPLATE_NS_ID, "assist", true); 42048 this.id = attributes.id || ""; 42049 this.role = attributes.role || ""; 42050 this.use = attributes.use || ""; 42051 this.usehref = attributes.usehref || ""; 42052 this.speak = null; 42053 this.toolTip = null; 42054 } 42055 [$toHTML]() { 42056 return this.toolTip?.[$content] || null; 42057 } 42058} 42059class Barcode extends XFAObject { 42060 constructor(attributes) { 42061 super(TEMPLATE_NS_ID, "barcode", true); 42062 this.charEncoding = getKeyword({ 42063 data: attributes.charEncoding ? attributes.charEncoding.toLowerCase() : "", 42064 defaultValue: "", 42065 validate: k => ["utf-8", "big-five", "fontspecific", "gbk", "gb-18030", "gb-2312", "ksc-5601", "none", "shift-jis", "ucs-2", "utf-16"].includes(k) || k.match(/iso-8859-\d{2}/) 42066 }); 42067 this.checksum = getStringOption(attributes.checksum, ["none", "1mod10", "1mod10_1mod11", "2mod10", "auto"]); 42068 this.dataColumnCount = getInteger({ 42069 data: attributes.dataColumnCount, 42070 defaultValue: -1, 42071 validate: x => x >= 0 42072 }); 42073 this.dataLength = getInteger({ 42074 data: attributes.dataLength, 42075 defaultValue: -1, 42076 validate: x => x >= 0 42077 }); 42078 this.dataPrep = getStringOption(attributes.dataPrep, ["none", "flateCompress"]); 42079 this.dataRowCount = getInteger({ 42080 data: attributes.dataRowCount, 42081 defaultValue: -1, 42082 validate: x => x >= 0 42083 }); 42084 this.endChar = attributes.endChar || ""; 42085 this.errorCorrectionLevel = getInteger({ 42086 data: attributes.errorCorrectionLevel, 42087 defaultValue: -1, 42088 validate: x => x >= 0 && x <= 8 42089 }); 42090 this.id = attributes.id || ""; 42091 this.moduleHeight = getMeasurement(attributes.moduleHeight, "5mm"); 42092 this.moduleWidth = getMeasurement(attributes.moduleWidth, "0.25mm"); 42093 this.printCheckDigit = getInteger({ 42094 data: attributes.printCheckDigit, 42095 defaultValue: 0, 42096 validate: x => x === 1 42097 }); 42098 this.rowColumnRatio = getRatio(attributes.rowColumnRatio); 42099 this.startChar = attributes.startChar || ""; 42100 this.textLocation = getStringOption(attributes.textLocation, ["below", "above", "aboveEmbedded", "belowEmbedded", "none"]); 42101 this.truncate = getInteger({ 42102 data: attributes.truncate, 42103 defaultValue: 0, 42104 validate: x => x === 1 42105 }); 42106 this.type = getStringOption(attributes.type ? attributes.type.toLowerCase() : "", ["aztec", "codabar", "code2of5industrial", "code2of5interleaved", "code2of5matrix", "code2of5standard", "code3of9", "code3of9extended", "code11", "code49", "code93", "code128", "code128a", "code128b", "code128c", "code128sscc", "datamatrix", "ean8", "ean8add2", "ean8add5", "ean13", "ean13add2", "ean13add5", "ean13pwcd", "fim", "logmars", "maxicode", "msi", "pdf417", "pdf417macro", "plessey", "postauscust2", "postauscust3", "postausreplypaid", "postausstandard", "postukrm4scc", "postusdpbc", "postusimb", "postusstandard", "postus5zip", "qrcode", "rfid", "rss14", "rss14expanded", "rss14limited", "rss14stacked", "rss14stackedomni", "rss14truncated", "telepen", "ucc128", "ucc128random", "ucc128sscc", "upca", "upcaadd2", "upcaadd5", "upcapwcd", "upce", "upceadd2", "upceadd5", "upcean2", "upcean5", "upsmaxicode"]); 42107 this.upsMode = getStringOption(attributes.upsMode, ["usCarrier", "internationalCarrier", "secureSymbol", "standardSymbol"]); 42108 this.use = attributes.use || ""; 42109 this.usehref = attributes.usehref || ""; 42110 this.wideNarrowRatio = getRatio(attributes.wideNarrowRatio); 42111 this.encrypt = null; 42112 this.extras = null; 42113 } 42114} 42115class Bind extends XFAObject { 42116 constructor(attributes) { 42117 super(TEMPLATE_NS_ID, "bind", true); 42118 this.match = getStringOption(attributes.match, ["once", "dataRef", "global", "none"]); 42119 this.ref = attributes.ref || ""; 42120 this.picture = null; 42121 } 42122} 42123class BindItems extends XFAObject { 42124 constructor(attributes) { 42125 super(TEMPLATE_NS_ID, "bindItems"); 42126 this.connection = attributes.connection || ""; 42127 this.labelRef = attributes.labelRef || ""; 42128 this.ref = attributes.ref || ""; 42129 this.valueRef = attributes.valueRef || ""; 42130 } 42131} 42132class Bookend extends XFAObject { 42133 constructor(attributes) { 42134 super(TEMPLATE_NS_ID, "bookend"); 42135 this.id = attributes.id || ""; 42136 this.leader = attributes.leader || ""; 42137 this.trailer = attributes.trailer || ""; 42138 this.use = attributes.use || ""; 42139 this.usehref = attributes.usehref || ""; 42140 } 42141} 42142class BooleanElement extends Option01 { 42143 constructor(attributes) { 42144 super(TEMPLATE_NS_ID, "boolean"); 42145 this.id = attributes.id || ""; 42146 this.name = attributes.name || ""; 42147 this.use = attributes.use || ""; 42148 this.usehref = attributes.usehref || ""; 42149 } 42150 [$toHTML](availableSpace) { 42151 return valueToHtml(this[$content] === 1 ? "1" : "0"); 42152 } 42153} 42154class Border extends XFAObject { 42155 constructor(attributes) { 42156 super(TEMPLATE_NS_ID, "border", true); 42157 this.break = getStringOption(attributes.break, ["close", "open"]); 42158 this.hand = getStringOption(attributes.hand, ["even", "left", "right"]); 42159 this.id = attributes.id || ""; 42160 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); 42161 this.relevant = getRelevant(attributes.relevant); 42162 this.use = attributes.use || ""; 42163 this.usehref = attributes.usehref || ""; 42164 this.corner = new XFAObjectArray(4); 42165 this.edge = new XFAObjectArray(4); 42166 this.extras = null; 42167 this.fill = null; 42168 this.margin = null; 42169 } 42170 [$getExtra]() { 42171 if (!this[$extra]) { 42172 const edges = this.edge.children.slice(); 42173 if (edges.length < 4) { 42174 const defaultEdge = edges.at(-1) || new Edge({}); 42175 for (let i = edges.length; i < 4; i++) { 42176 edges.push(defaultEdge); 42177 } 42178 } 42179 const widths = edges.map(edge => edge.thickness); 42180 const insets = [0, 0, 0, 0]; 42181 if (this.margin) { 42182 insets[0] = this.margin.topInset; 42183 insets[1] = this.margin.rightInset; 42184 insets[2] = this.margin.bottomInset; 42185 insets[3] = this.margin.leftInset; 42186 } 42187 this[$extra] = { 42188 widths, 42189 insets, 42190 edges 42191 }; 42192 } 42193 return this[$extra]; 42194 } 42195 [$toStyle]() { 42196 const { 42197 edges 42198 } = this[$getExtra](); 42199 const edgeStyles = edges.map(node => { 42200 const style = node[$toStyle](); 42201 style.color ||= "#000000"; 42202 return style; 42203 }); 42204 const style = Object.create(null); 42205 if (this.margin) { 42206 Object.assign(style, this.margin[$toStyle]()); 42207 } 42208 if (this.fill?.presence === "visible") { 42209 Object.assign(style, this.fill[$toStyle]()); 42210 } 42211 if (this.corner.children.some(node => node.radius !== 0)) { 42212 const cornerStyles = this.corner.children.map(node => node[$toStyle]()); 42213 if (cornerStyles.length === 2 || cornerStyles.length === 3) { 42214 const last = cornerStyles.at(-1); 42215 for (let i = cornerStyles.length; i < 4; i++) { 42216 cornerStyles.push(last); 42217 } 42218 } 42219 style.borderRadius = cornerStyles.map(s => s.radius).join(" "); 42220 } 42221 switch (this.presence) { 42222 case "invisible": 42223 case "hidden": 42224 style.borderStyle = ""; 42225 break; 42226 case "inactive": 42227 style.borderStyle = "none"; 42228 break; 42229 default: 42230 style.borderStyle = edgeStyles.map(s => s.style).join(" "); 42231 break; 42232 } 42233 style.borderWidth = edgeStyles.map(s => s.width).join(" "); 42234 style.borderColor = edgeStyles.map(s => s.color).join(" "); 42235 return style; 42236 } 42237} 42238class Break extends XFAObject { 42239 constructor(attributes) { 42240 super(TEMPLATE_NS_ID, "break", true); 42241 this.after = getStringOption(attributes.after, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]); 42242 this.afterTarget = attributes.afterTarget || ""; 42243 this.before = getStringOption(attributes.before, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]); 42244 this.beforeTarget = attributes.beforeTarget || ""; 42245 this.bookendLeader = attributes.bookendLeader || ""; 42246 this.bookendTrailer = attributes.bookendTrailer || ""; 42247 this.id = attributes.id || ""; 42248 this.overflowLeader = attributes.overflowLeader || ""; 42249 this.overflowTarget = attributes.overflowTarget || ""; 42250 this.overflowTrailer = attributes.overflowTrailer || ""; 42251 this.startNew = getInteger({ 42252 data: attributes.startNew, 42253 defaultValue: 0, 42254 validate: x => x === 1 42255 }); 42256 this.use = attributes.use || ""; 42257 this.usehref = attributes.usehref || ""; 42258 this.extras = null; 42259 } 42260} 42261class BreakAfter extends XFAObject { 42262 constructor(attributes) { 42263 super(TEMPLATE_NS_ID, "breakAfter", true); 42264 this.id = attributes.id || ""; 42265 this.leader = attributes.leader || ""; 42266 this.startNew = getInteger({ 42267 data: attributes.startNew, 42268 defaultValue: 0, 42269 validate: x => x === 1 42270 }); 42271 this.target = attributes.target || ""; 42272 this.targetType = getStringOption(attributes.targetType, ["auto", "contentArea", "pageArea"]); 42273 this.trailer = attributes.trailer || ""; 42274 this.use = attributes.use || ""; 42275 this.usehref = attributes.usehref || ""; 42276 this.script = null; 42277 } 42278} 42279class BreakBefore extends XFAObject { 42280 constructor(attributes) { 42281 super(TEMPLATE_NS_ID, "breakBefore", true); 42282 this.id = attributes.id || ""; 42283 this.leader = attributes.leader || ""; 42284 this.startNew = getInteger({ 42285 data: attributes.startNew, 42286 defaultValue: 0, 42287 validate: x => x === 1 42288 }); 42289 this.target = attributes.target || ""; 42290 this.targetType = getStringOption(attributes.targetType, ["auto", "contentArea", "pageArea"]); 42291 this.trailer = attributes.trailer || ""; 42292 this.use = attributes.use || ""; 42293 this.usehref = attributes.usehref || ""; 42294 this.script = null; 42295 } 42296 [$toHTML](availableSpace) { 42297 this[$extra] = {}; 42298 return HTMLResult.FAILURE; 42299 } 42300} 42301class Button extends XFAObject { 42302 constructor(attributes) { 42303 super(TEMPLATE_NS_ID, "button", true); 42304 this.highlight = getStringOption(attributes.highlight, ["inverted", "none", "outline", "push"]); 42305 this.id = attributes.id || ""; 42306 this.use = attributes.use || ""; 42307 this.usehref = attributes.usehref || ""; 42308 this.extras = null; 42309 } 42310 [$toHTML](availableSpace) { 42311 const parent = this[$getParent](); 42312 const grandpa = parent[$getParent](); 42313 const htmlButton = { 42314 name: "button", 42315 attributes: { 42316 id: this[$uid], 42317 class: ["xfaButton"], 42318 style: {} 42319 }, 42320 children: [] 42321 }; 42322 for (const event of grandpa.event.children) { 42323 if (event.activity !== "click" || !event.script) { 42324 continue; 42325 } 42326 const jsURL = recoverJsURL(event.script[$content]); 42327 if (!jsURL) { 42328 continue; 42329 } 42330 const href = fixURL(jsURL.url); 42331 if (!href) { 42332 continue; 42333 } 42334 htmlButton.children.push({ 42335 name: "a", 42336 attributes: { 42337 id: "link" + this[$uid], 42338 href, 42339 newWindow: jsURL.newWindow, 42340 class: ["xfaLink"], 42341 style: {} 42342 }, 42343 children: [] 42344 }); 42345 } 42346 return HTMLResult.success(htmlButton); 42347 } 42348} 42349class Calculate extends XFAObject { 42350 constructor(attributes) { 42351 super(TEMPLATE_NS_ID, "calculate", true); 42352 this.id = attributes.id || ""; 42353 this.override = getStringOption(attributes.override, ["disabled", "error", "ignore", "warning"]); 42354 this.use = attributes.use || ""; 42355 this.usehref = attributes.usehref || ""; 42356 this.extras = null; 42357 this.message = null; 42358 this.script = null; 42359 } 42360} 42361class Caption extends XFAObject { 42362 constructor(attributes) { 42363 super(TEMPLATE_NS_ID, "caption", true); 42364 this.id = attributes.id || ""; 42365 this.placement = getStringOption(attributes.placement, ["left", "bottom", "inline", "right", "top"]); 42366 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); 42367 this.reserve = Math.ceil(getMeasurement(attributes.reserve)); 42368 this.use = attributes.use || ""; 42369 this.usehref = attributes.usehref || ""; 42370 this.extras = null; 42371 this.font = null; 42372 this.margin = null; 42373 this.para = null; 42374 this.value = null; 42375 } 42376 [$setValue](value) { 42377 _setValue(this, value); 42378 } 42379 [$getExtra](availableSpace) { 42380 if (!this[$extra]) { 42381 let { 42382 width, 42383 height 42384 } = availableSpace; 42385 switch (this.placement) { 42386 case "left": 42387 case "right": 42388 case "inline": 42389 width = this.reserve <= 0 ? width : this.reserve; 42390 break; 42391 case "top": 42392 case "bottom": 42393 height = this.reserve <= 0 ? height : this.reserve; 42394 break; 42395 } 42396 this[$extra] = layoutNode(this, { 42397 width, 42398 height 42399 }); 42400 } 42401 return this[$extra]; 42402 } 42403 [$toHTML](availableSpace) { 42404 if (!this.value) { 42405 return HTMLResult.EMPTY; 42406 } 42407 this[$pushPara](); 42408 const value = this.value[$toHTML](availableSpace).html; 42409 if (!value) { 42410 this[$popPara](); 42411 return HTMLResult.EMPTY; 42412 } 42413 const savedReserve = this.reserve; 42414 if (this.reserve <= 0) { 42415 const { 42416 w, 42417 h 42418 } = this[$getExtra](availableSpace); 42419 switch (this.placement) { 42420 case "left": 42421 case "right": 42422 case "inline": 42423 this.reserve = w; 42424 break; 42425 case "top": 42426 case "bottom": 42427 this.reserve = h; 42428 break; 42429 } 42430 } 42431 const children = []; 42432 if (typeof value === "string") { 42433 children.push({ 42434 name: "#text", 42435 value 42436 }); 42437 } else { 42438 children.push(value); 42439 } 42440 const style = toStyle(this, "font", "margin", "visibility"); 42441 switch (this.placement) { 42442 case "left": 42443 case "right": 42444 if (this.reserve > 0) { 42445 style.width = measureToString(this.reserve); 42446 } 42447 break; 42448 case "top": 42449 case "bottom": 42450 if (this.reserve > 0) { 42451 style.height = measureToString(this.reserve); 42452 } 42453 break; 42454 } 42455 setPara(this, null, value); 42456 this[$popPara](); 42457 this.reserve = savedReserve; 42458 return HTMLResult.success({ 42459 name: "div", 42460 attributes: { 42461 style, 42462 class: ["xfaCaption"] 42463 }, 42464 children 42465 }); 42466 } 42467} 42468class Certificate extends StringObject { 42469 constructor(attributes) { 42470 super(TEMPLATE_NS_ID, "certificate"); 42471 this.id = attributes.id || ""; 42472 this.name = attributes.name || ""; 42473 this.use = attributes.use || ""; 42474 this.usehref = attributes.usehref || ""; 42475 } 42476} 42477class Certificates extends XFAObject { 42478 constructor(attributes) { 42479 super(TEMPLATE_NS_ID, "certificates", true); 42480 this.credentialServerPolicy = getStringOption(attributes.credentialServerPolicy, ["optional", "required"]); 42481 this.id = attributes.id || ""; 42482 this.url = attributes.url || ""; 42483 this.urlPolicy = attributes.urlPolicy || ""; 42484 this.use = attributes.use || ""; 42485 this.usehref = attributes.usehref || ""; 42486 this.encryption = null; 42487 this.issuers = null; 42488 this.keyUsage = null; 42489 this.oids = null; 42490 this.signing = null; 42491 this.subjectDNs = null; 42492 } 42493} 42494class CheckButton extends XFAObject { 42495 constructor(attributes) { 42496 super(TEMPLATE_NS_ID, "checkButton", true); 42497 this.id = attributes.id || ""; 42498 this.mark = getStringOption(attributes.mark, ["default", "check", "circle", "cross", "diamond", "square", "star"]); 42499 this.shape = getStringOption(attributes.shape, ["square", "round"]); 42500 this.size = getMeasurement(attributes.size, "10pt"); 42501 this.use = attributes.use || ""; 42502 this.usehref = attributes.usehref || ""; 42503 this.border = null; 42504 this.extras = null; 42505 this.margin = null; 42506 } 42507 [$toHTML](availableSpace) { 42508 const style = toStyle(this, "margin"); 42509 const size = measureToString(this.size); 42510 style.width = style.height = size; 42511 let type; 42512 let className; 42513 let groupId; 42514 const field = this[$getParent]()[$getParent](); 42515 const items = field.items.children.length && field.items.children[0][$toHTML]().html || []; 42516 const exportedValue = { 42517 on: (items[0] !== undefined ? items[0] : "on").toString(), 42518 off: (items[1] !== undefined ? items[1] : "off").toString() 42519 }; 42520 const value = field.value?.[$text]() || "off"; 42521 const checked = value === exportedValue.on || undefined; 42522 const container = field[$getSubformParent](); 42523 const fieldId = field[$uid]; 42524 let dataId; 42525 if (container instanceof ExclGroup) { 42526 groupId = container[$uid]; 42527 type = "radio"; 42528 className = "xfaRadio"; 42529 dataId = container[$data]?.[$uid] || container[$uid]; 42530 } else { 42531 type = "checkbox"; 42532 className = "xfaCheckbox"; 42533 dataId = field[$data]?.[$uid] || field[$uid]; 42534 } 42535 const input = { 42536 name: "input", 42537 attributes: { 42538 class: [className], 42539 style, 42540 fieldId, 42541 dataId, 42542 type, 42543 checked, 42544 xfaOn: exportedValue.on, 42545 xfaOff: exportedValue.off, 42546 "aria-label": ariaLabel(field), 42547 "aria-required": false 42548 } 42549 }; 42550 if (groupId) { 42551 input.attributes.name = groupId; 42552 } 42553 if (isRequired(field)) { 42554 input.attributes["aria-required"] = true; 42555 input.attributes.required = true; 42556 } 42557 return HTMLResult.success({ 42558 name: "label", 42559 attributes: { 42560 class: ["xfaLabel"] 42561 }, 42562 children: [input] 42563 }); 42564 } 42565} 42566class ChoiceList extends XFAObject { 42567 constructor(attributes) { 42568 super(TEMPLATE_NS_ID, "choiceList", true); 42569 this.commitOn = getStringOption(attributes.commitOn, ["select", "exit"]); 42570 this.id = attributes.id || ""; 42571 this.open = getStringOption(attributes.open, ["userControl", "always", "multiSelect", "onEntry"]); 42572 this.textEntry = getInteger({ 42573 data: attributes.textEntry, 42574 defaultValue: 0, 42575 validate: x => x === 1 42576 }); 42577 this.use = attributes.use || ""; 42578 this.usehref = attributes.usehref || ""; 42579 this.border = null; 42580 this.extras = null; 42581 this.margin = null; 42582 } 42583 [$toHTML](availableSpace) { 42584 const style = toStyle(this, "border", "margin"); 42585 const ui = this[$getParent](); 42586 const field = ui[$getParent](); 42587 const fontSize = field.font?.size || 10; 42588 const optionStyle = { 42589 fontSize: `calc(${fontSize}px * var(--total-scale-factor))` 42590 }; 42591 const children = []; 42592 if (field.items.children.length > 0) { 42593 const items = field.items; 42594 let displayedIndex = 0; 42595 let saveIndex = 0; 42596 if (items.children.length === 2) { 42597 displayedIndex = items.children[0].save; 42598 saveIndex = 1 - displayedIndex; 42599 } 42600 const displayed = items.children[displayedIndex][$toHTML]().html; 42601 const values = items.children[saveIndex][$toHTML]().html; 42602 let selected = false; 42603 const value = field.value?.[$text]() || ""; 42604 for (let i = 0, ii = displayed.length; i < ii; i++) { 42605 const option = { 42606 name: "option", 42607 attributes: { 42608 value: values[i] || displayed[i], 42609 style: optionStyle 42610 }, 42611 value: displayed[i] 42612 }; 42613 if (values[i] === value) { 42614 option.attributes.selected = selected = true; 42615 } 42616 children.push(option); 42617 } 42618 if (!selected) { 42619 children.splice(0, 0, { 42620 name: "option", 42621 attributes: { 42622 hidden: true, 42623 selected: true 42624 }, 42625 value: " " 42626 }); 42627 } 42628 } 42629 const selectAttributes = { 42630 class: ["xfaSelect"], 42631 fieldId: field[$uid], 42632 dataId: field[$data]?.[$uid] || field[$uid], 42633 style, 42634 "aria-label": ariaLabel(field), 42635 "aria-required": false 42636 }; 42637 if (isRequired(field)) { 42638 selectAttributes["aria-required"] = true; 42639 selectAttributes.required = true; 42640 } 42641 if (this.open === "multiSelect") { 42642 selectAttributes.multiple = true; 42643 } 42644 return HTMLResult.success({ 42645 name: "label", 42646 attributes: { 42647 class: ["xfaLabel"] 42648 }, 42649 children: [{ 42650 name: "select", 42651 children, 42652 attributes: selectAttributes 42653 }] 42654 }); 42655 } 42656} 42657class Color extends XFAObject { 42658 constructor(attributes) { 42659 super(TEMPLATE_NS_ID, "color", true); 42660 this.cSpace = getStringOption(attributes.cSpace, ["SRGB"]); 42661 this.id = attributes.id || ""; 42662 this.use = attributes.use || ""; 42663 this.usehref = attributes.usehref || ""; 42664 this.value = attributes.value ? getColor(attributes.value) : ""; 42665 this.extras = null; 42666 } 42667 [$hasSettableValue]() { 42668 return false; 42669 } 42670 [$toStyle]() { 42671 return this.value ? Util.makeHexColor(this.value.r, this.value.g, this.value.b) : null; 42672 } 42673} 42674class Comb extends XFAObject { 42675 constructor(attributes) { 42676 super(TEMPLATE_NS_ID, "comb"); 42677 this.id = attributes.id || ""; 42678 this.numberOfCells = getInteger({ 42679 data: attributes.numberOfCells, 42680 defaultValue: 0, 42681 validate: x => x >= 0 42682 }); 42683 this.use = attributes.use || ""; 42684 this.usehref = attributes.usehref || ""; 42685 } 42686} 42687class Connect extends XFAObject { 42688 constructor(attributes) { 42689 super(TEMPLATE_NS_ID, "connect", true); 42690 this.connection = attributes.connection || ""; 42691 this.id = attributes.id || ""; 42692 this.ref = attributes.ref || ""; 42693 this.usage = getStringOption(attributes.usage, ["exportAndImport", "exportOnly", "importOnly"]); 42694 this.use = attributes.use || ""; 42695 this.usehref = attributes.usehref || ""; 42696 this.picture = null; 42697 } 42698} 42699class ContentArea extends XFAObject { 42700 constructor(attributes) { 42701 super(TEMPLATE_NS_ID, "contentArea", true); 42702 this.h = getMeasurement(attributes.h); 42703 this.id = attributes.id || ""; 42704 this.name = attributes.name || ""; 42705 this.relevant = getRelevant(attributes.relevant); 42706 this.use = attributes.use || ""; 42707 this.usehref = attributes.usehref || ""; 42708 this.w = getMeasurement(attributes.w); 42709 this.x = getMeasurement(attributes.x, "0pt"); 42710 this.y = getMeasurement(attributes.y, "0pt"); 42711 this.desc = null; 42712 this.extras = null; 42713 } 42714 [$toHTML](availableSpace) { 42715 const left = measureToString(this.x); 42716 const top = measureToString(this.y); 42717 const style = { 42718 left, 42719 top, 42720 width: measureToString(this.w), 42721 height: measureToString(this.h) 42722 }; 42723 const classNames = ["xfaContentarea"]; 42724 if (isPrintOnly(this)) { 42725 classNames.push("xfaPrintOnly"); 42726 } 42727 return HTMLResult.success({ 42728 name: "div", 42729 children: [], 42730 attributes: { 42731 style, 42732 class: classNames, 42733 id: this[$uid] 42734 } 42735 }); 42736 } 42737} 42738class Corner extends XFAObject { 42739 constructor(attributes) { 42740 super(TEMPLATE_NS_ID, "corner", true); 42741 this.id = attributes.id || ""; 42742 this.inverted = getInteger({ 42743 data: attributes.inverted, 42744 defaultValue: 0, 42745 validate: x => x === 1 42746 }); 42747 this.join = getStringOption(attributes.join, ["square", "round"]); 42748 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); 42749 this.radius = getMeasurement(attributes.radius); 42750 this.stroke = getStringOption(attributes.stroke, ["solid", "dashDot", "dashDotDot", "dashed", "dotted", "embossed", "etched", "lowered", "raised"]); 42751 this.thickness = getMeasurement(attributes.thickness, "0.5pt"); 42752 this.use = attributes.use || ""; 42753 this.usehref = attributes.usehref || ""; 42754 this.color = null; 42755 this.extras = null; 42756 } 42757 [$toStyle]() { 42758 const style = toStyle(this, "visibility"); 42759 style.radius = measureToString(this.join === "square" ? 0 : this.radius); 42760 return style; 42761 } 42762} 42763class DateElement extends ContentObject { 42764 constructor(attributes) { 42765 super(TEMPLATE_NS_ID, "date"); 42766 this.id = attributes.id || ""; 42767 this.name = attributes.name || ""; 42768 this.use = attributes.use || ""; 42769 this.usehref = attributes.usehref || ""; 42770 } 42771 [$finalize]() { 42772 const date = this[$content].trim(); 42773 this[$content] = date ? new Date(date) : null; 42774 } 42775 [$toHTML](availableSpace) { 42776 return valueToHtml(this[$content] ? this[$content].toString() : ""); 42777 } 42778} 42779class DateTime extends ContentObject { 42780 constructor(attributes) { 42781 super(TEMPLATE_NS_ID, "dateTime"); 42782 this.id = attributes.id || ""; 42783 this.name = attributes.name || ""; 42784 this.use = attributes.use || ""; 42785 this.usehref = attributes.usehref || ""; 42786 } 42787 [$finalize]() { 42788 const date = this[$content].trim(); 42789 this[$content] = date ? new Date(date) : null; 42790 } 42791 [$toHTML](availableSpace) { 42792 return valueToHtml(this[$content] ? this[$content].toString() : ""); 42793 } 42794} 42795class DateTimeEdit extends XFAObject { 42796 constructor(attributes) { 42797 super(TEMPLATE_NS_ID, "dateTimeEdit", true); 42798 this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]); 42799 this.id = attributes.id || ""; 42800 this.picker = getStringOption(attributes.picker, ["host", "none"]); 42801 this.use = attributes.use || ""; 42802 this.usehref = attributes.usehref || ""; 42803 this.border = null; 42804 this.comb = null; 42805 this.extras = null; 42806 this.margin = null; 42807 } 42808 [$toHTML](availableSpace) { 42809 const style = toStyle(this, "border", "font", "margin"); 42810 const field = this[$getParent]()[$getParent](); 42811 const html = { 42812 name: "input", 42813 attributes: { 42814 type: "text", 42815 fieldId: field[$uid], 42816 dataId: field[$data]?.[$uid] || field[$uid], 42817 class: ["xfaTextfield"], 42818 style, 42819 "aria-label": ariaLabel(field), 42820 "aria-required": false 42821 } 42822 }; 42823 if (isRequired(field)) { 42824 html.attributes["aria-required"] = true; 42825 html.attributes.required = true; 42826 } 42827 return HTMLResult.success({ 42828 name: "label", 42829 attributes: { 42830 class: ["xfaLabel"] 42831 }, 42832 children: [html] 42833 }); 42834 } 42835} 42836class Decimal extends ContentObject { 42837 constructor(attributes) { 42838 super(TEMPLATE_NS_ID, "decimal"); 42839 this.fracDigits = getInteger({ 42840 data: attributes.fracDigits, 42841 defaultValue: 2, 42842 validate: x => true 42843 }); 42844 this.id = attributes.id || ""; 42845 this.leadDigits = getInteger({ 42846 data: attributes.leadDigits, 42847 defaultValue: -1, 42848 validate: x => true 42849 }); 42850 this.name = attributes.name || ""; 42851 this.use = attributes.use || ""; 42852 this.usehref = attributes.usehref || ""; 42853 } 42854 [$finalize]() { 42855 const number = parseFloat(this[$content].trim()); 42856 this[$content] = isNaN(number) ? null : number; 42857 } 42858 [$toHTML](availableSpace) { 42859 return valueToHtml(this[$content] !== null ? this[$content].toString() : ""); 42860 } 42861} 42862class DefaultUi extends XFAObject { 42863 constructor(attributes) { 42864 super(TEMPLATE_NS_ID, "defaultUi", true); 42865 this.id = attributes.id || ""; 42866 this.use = attributes.use || ""; 42867 this.usehref = attributes.usehref || ""; 42868 this.extras = null; 42869 } 42870} 42871class Desc extends XFAObject { 42872 constructor(attributes) { 42873 super(TEMPLATE_NS_ID, "desc", true); 42874 this.id = attributes.id || ""; 42875 this.use = attributes.use || ""; 42876 this.usehref = attributes.usehref || ""; 42877 this.boolean = new XFAObjectArray(); 42878 this.date = new XFAObjectArray(); 42879 this.dateTime = new XFAObjectArray(); 42880 this.decimal = new XFAObjectArray(); 42881 this.exData = new XFAObjectArray(); 42882 this.float = new XFAObjectArray(); 42883 this.image = new XFAObjectArray(); 42884 this.integer = new XFAObjectArray(); 42885 this.text = new XFAObjectArray(); 42886 this.time = new XFAObjectArray(); 42887 } 42888} 42889class DigestMethod extends OptionObject { 42890 constructor(attributes) { 42891 super(TEMPLATE_NS_ID, "digestMethod", ["", "SHA1", "SHA256", "SHA512", "RIPEMD160"]); 42892 this.id = attributes.id || ""; 42893 this.use = attributes.use || ""; 42894 this.usehref = attributes.usehref || ""; 42895 } 42896} 42897class DigestMethods extends XFAObject { 42898 constructor(attributes) { 42899 super(TEMPLATE_NS_ID, "digestMethods", true); 42900 this.id = attributes.id || ""; 42901 this.type = getStringOption(attributes.type, ["optional", "required"]); 42902 this.use = attributes.use || ""; 42903 this.usehref = attributes.usehref || ""; 42904 this.digestMethod = new XFAObjectArray(); 42905 } 42906} 42907class Draw extends XFAObject { 42908 constructor(attributes) { 42909 super(TEMPLATE_NS_ID, "draw", true); 42910 this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]); 42911 this.colSpan = getInteger({ 42912 data: attributes.colSpan, 42913 defaultValue: 1, 42914 validate: n => n >= 1 || n === -1 42915 }); 42916 this.h = attributes.h ? getMeasurement(attributes.h) : ""; 42917 this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]); 42918 this.id = attributes.id || ""; 42919 this.locale = attributes.locale || ""; 42920 this.maxH = getMeasurement(attributes.maxH, "0pt"); 42921 this.maxW = getMeasurement(attributes.maxW, "0pt"); 42922 this.minH = getMeasurement(attributes.minH, "0pt"); 42923 this.minW = getMeasurement(attributes.minW, "0pt"); 42924 this.name = attributes.name || ""; 42925 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); 42926 this.relevant = getRelevant(attributes.relevant); 42927 this.rotate = getInteger({ 42928 data: attributes.rotate, 42929 defaultValue: 0, 42930 validate: x => x % 90 === 0 42931 }); 42932 this.use = attributes.use || ""; 42933 this.usehref = attributes.usehref || ""; 42934 this.w = attributes.w ? getMeasurement(attributes.w) : ""; 42935 this.x = getMeasurement(attributes.x, "0pt"); 42936 this.y = getMeasurement(attributes.y, "0pt"); 42937 this.assist = null; 42938 this.border = null; 42939 this.caption = null; 42940 this.desc = null; 42941 this.extras = null; 42942 this.font = null; 42943 this.keep = null; 42944 this.margin = null; 42945 this.para = null; 42946 this.traversal = null; 42947 this.ui = null; 42948 this.value = null; 42949 this.setProperty = new XFAObjectArray(); 42950 } 42951 [$setValue](value) { 42952 _setValue(this, value); 42953 } 42954 [$toHTML](availableSpace) { 42955 setTabIndex(this); 42956 if (this.presence === "hidden" || this.presence === "inactive") { 42957 return HTMLResult.EMPTY; 42958 } 42959 fixDimensions(this); 42960 this[$pushPara](); 42961 const savedW = this.w; 42962 const savedH = this.h; 42963 const { 42964 w, 42965 h, 42966 isBroken 42967 } = layoutNode(this, availableSpace); 42968 if (w && this.w === "") { 42969 if (isBroken && this[$getSubformParent]()[$isThereMoreWidth]()) { 42970 this[$popPara](); 42971 return HTMLResult.FAILURE; 42972 } 42973 this.w = w; 42974 } 42975 if (h && this.h === "") { 42976 this.h = h; 42977 } 42978 setFirstUnsplittable(this); 42979 if (!checkDimensions(this, availableSpace)) { 42980 this.w = savedW; 42981 this.h = savedH; 42982 this[$popPara](); 42983 return HTMLResult.FAILURE; 42984 } 42985 unsetFirstUnsplittable(this); 42986 const style = toStyle(this, "font", "hAlign", "dimensions", "position", "presence", "rotate", "anchorType", "border", "margin"); 42987 setMinMaxDimensions(this, style); 42988 if (style.margin) { 42989 style.padding = style.margin; 42990 delete style.margin; 42991 } 42992 const classNames = ["xfaDraw"]; 42993 if (this.font) { 42994 classNames.push("xfaFont"); 42995 } 42996 if (isPrintOnly(this)) { 42997 classNames.push("xfaPrintOnly"); 42998 } 42999 const attributes = { 43000 style, 43001 id: this[$uid], 43002 class: classNames 43003 }; 43004 if (this.name) { 43005 attributes.xfaName = this.name; 43006 } 43007 const html = { 43008 name: "div", 43009 attributes, 43010 children: [] 43011 }; 43012 applyAssist(this, attributes); 43013 const bbox = computeBbox(this, html, availableSpace); 43014 const value = this.value ? this.value[$toHTML](availableSpace).html : null; 43015 if (value === null) { 43016 this.w = savedW; 43017 this.h = savedH; 43018 this[$popPara](); 43019 return HTMLResult.success(createWrapper(this, html), bbox); 43020 } 43021 html.children.push(value); 43022 setPara(this, style, value); 43023 this.w = savedW; 43024 this.h = savedH; 43025 this[$popPara](); 43026 return HTMLResult.success(createWrapper(this, html), bbox); 43027 } 43028} 43029class Edge extends XFAObject { 43030 constructor(attributes) { 43031 super(TEMPLATE_NS_ID, "edge", true); 43032 this.cap = getStringOption(attributes.cap, ["square", "butt", "round"]); 43033 this.id = attributes.id || ""; 43034 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); 43035 this.stroke = getStringOption(attributes.stroke, ["solid", "dashDot", "dashDotDot", "dashed", "dotted", "embossed", "etched", "lowered", "raised"]); 43036 this.thickness = getMeasurement(attributes.thickness, "0.5pt"); 43037 this.use = attributes.use || ""; 43038 this.usehref = attributes.usehref || ""; 43039 this.color = null; 43040 this.extras = null; 43041 } 43042 [$toStyle]() { 43043 const style = toStyle(this, "visibility"); 43044 Object.assign(style, { 43045 linecap: this.cap, 43046 width: measureToString(this.thickness), 43047 color: this.color ? this.color[$toStyle]() : "#000000", 43048 style: "" 43049 }); 43050 if (this.presence !== "visible") { 43051 style.style = "none"; 43052 } else { 43053 switch (this.stroke) { 43054 case "solid": 43055 style.style = "solid"; 43056 break; 43057 case "dashDot": 43058 style.style = "dashed"; 43059 break; 43060 case "dashDotDot": 43061 style.style = "dashed"; 43062 break; 43063 case "dashed": 43064 style.style = "dashed"; 43065 break; 43066 case "dotted": 43067 style.style = "dotted"; 43068 break; 43069 case "embossed": 43070 style.style = "ridge"; 43071 break; 43072 case "etched": 43073 style.style = "groove"; 43074 break; 43075 case "lowered": 43076 style.style = "inset"; 43077 break; 43078 case "raised": 43079 style.style = "outset"; 43080 break; 43081 } 43082 } 43083 return style; 43084 } 43085} 43086class Encoding extends OptionObject { 43087 constructor(attributes) { 43088 super(TEMPLATE_NS_ID, "encoding", ["adbe.x509.rsa_sha1", "adbe.pkcs7.detached", "adbe.pkcs7.sha1"]); 43089 this.id = attributes.id || ""; 43090 this.use = attributes.use || ""; 43091 this.usehref = attributes.usehref || ""; 43092 } 43093} 43094class Encodings extends XFAObject { 43095 constructor(attributes) { 43096 super(TEMPLATE_NS_ID, "encodings", true); 43097 this.id = attributes.id || ""; 43098 this.type = getStringOption(attributes.type, ["optional", "required"]); 43099 this.use = attributes.use || ""; 43100 this.usehref = attributes.usehref || ""; 43101 this.encoding = new XFAObjectArray(); 43102 } 43103} 43104class Encrypt extends XFAObject { 43105 constructor(attributes) { 43106 super(TEMPLATE_NS_ID, "encrypt", true); 43107 this.id = attributes.id || ""; 43108 this.use = attributes.use || ""; 43109 this.usehref = attributes.usehref || ""; 43110 this.certificate = null; 43111 } 43112} 43113class EncryptData extends XFAObject { 43114 constructor(attributes) { 43115 super(TEMPLATE_NS_ID, "encryptData", true); 43116 this.id = attributes.id || ""; 43117 this.operation = getStringOption(attributes.operation, ["encrypt", "decrypt"]); 43118 this.target = attributes.target || ""; 43119 this.use = attributes.use || ""; 43120 this.usehref = attributes.usehref || ""; 43121 this.filter = null; 43122 this.manifest = null; 43123 } 43124} 43125class Encryption extends XFAObject { 43126 constructor(attributes) { 43127 super(TEMPLATE_NS_ID, "encryption", true); 43128 this.id = attributes.id || ""; 43129 this.type = getStringOption(attributes.type, ["optional", "required"]); 43130 this.use = attributes.use || ""; 43131 this.usehref = attributes.usehref || ""; 43132 this.certificate = new XFAObjectArray(); 43133 } 43134} 43135class EncryptionMethod extends OptionObject { 43136 constructor(attributes) { 43137 super(TEMPLATE_NS_ID, "encryptionMethod", ["", "AES256-CBC", "TRIPLEDES-CBC", "AES128-CBC", "AES192-CBC"]); 43138 this.id = attributes.id || ""; 43139 this.use = attributes.use || ""; 43140 this.usehref = attributes.usehref || ""; 43141 } 43142} 43143class EncryptionMethods extends XFAObject { 43144 constructor(attributes) { 43145 super(TEMPLATE_NS_ID, "encryptionMethods", true); 43146 this.id = attributes.id || ""; 43147 this.type = getStringOption(attributes.type, ["optional", "required"]); 43148 this.use = attributes.use || ""; 43149 this.usehref = attributes.usehref || ""; 43150 this.encryptionMethod = new XFAObjectArray(); 43151 } 43152} 43153class Event extends XFAObject { 43154 constructor(attributes) { 43155 super(TEMPLATE_NS_ID, "event", true); 43156 this.activity = getStringOption(attributes.activity, ["click", "change", "docClose", "docReady", "enter", "exit", "full", "indexChange", "initialize", "mouseDown", "mouseEnter", "mouseExit", "mouseUp", "postExecute", "postOpen", "postPrint", "postSave", "postSign", "postSubmit", "preExecute", "preOpen", "prePrint", "preSave", "preSign", "preSubmit", "ready", "validationState"]); 43157 this.id = attributes.id || ""; 43158 this.listen = getStringOption(attributes.listen, ["refOnly", "refAndDescendents"]); 43159 this.name = attributes.name || ""; 43160 this.ref = attributes.ref || ""; 43161 this.use = attributes.use || ""; 43162 this.usehref = attributes.usehref || ""; 43163 this.extras = null; 43164 this.encryptData = null; 43165 this.execute = null; 43166 this.script = null; 43167 this.signData = null; 43168 this.submit = null; 43169 } 43170} 43171class ExData extends ContentObject { 43172 constructor(attributes) { 43173 super(TEMPLATE_NS_ID, "exData"); 43174 this.contentType = attributes.contentType || ""; 43175 this.href = attributes.href || ""; 43176 this.id = attributes.id || ""; 43177 this.maxLength = getInteger({ 43178 data: attributes.maxLength, 43179 defaultValue: -1, 43180 validate: x => x >= -1 43181 }); 43182 this.name = attributes.name || ""; 43183 this.rid = attributes.rid || ""; 43184 this.transferEncoding = getStringOption(attributes.transferEncoding, ["none", "base64", "package"]); 43185 this.use = attributes.use || ""; 43186 this.usehref = attributes.usehref || ""; 43187 } 43188 [$isCDATAXml]() { 43189 return this.contentType === "text/html"; 43190 } 43191 [$onChild](child) { 43192 if (this.contentType === "text/html" && child[$namespaceId] === NamespaceIds.xhtml.id) { 43193 this[$content] = child; 43194 return true; 43195 } 43196 if (this.contentType === "text/xml") { 43197 this[$content] = child; 43198 return true; 43199 } 43200 return false; 43201 } 43202 [$toHTML](availableSpace) { 43203 if (this.contentType !== "text/html" || !this[$content]) { 43204 return HTMLResult.EMPTY; 43205 } 43206 return this[$content][$toHTML](availableSpace); 43207 } 43208} 43209class ExObject extends XFAObject { 43210 constructor(attributes) { 43211 super(TEMPLATE_NS_ID, "exObject", true); 43212 this.archive = attributes.archive || ""; 43213 this.classId = attributes.classId || ""; 43214 this.codeBase = attributes.codeBase || ""; 43215 this.codeType = attributes.codeType || ""; 43216 this.id = attributes.id || ""; 43217 this.name = attributes.name || ""; 43218 this.use = attributes.use || ""; 43219 this.usehref = attributes.usehref || ""; 43220 this.extras = null; 43221 this.boolean = new XFAObjectArray(); 43222 this.date = new XFAObjectArray(); 43223 this.dateTime = new XFAObjectArray(); 43224 this.decimal = new XFAObjectArray(); 43225 this.exData = new XFAObjectArray(); 43226 this.exObject = new XFAObjectArray(); 43227 this.float = new XFAObjectArray(); 43228 this.image = new XFAObjectArray(); 43229 this.integer = new XFAObjectArray(); 43230 this.text = new XFAObjectArray(); 43231 this.time = new XFAObjectArray(); 43232 } 43233} 43234class ExclGroup extends XFAObject { 43235 constructor(attributes) { 43236 super(TEMPLATE_NS_ID, "exclGroup", true); 43237 this.access = getStringOption(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]); 43238 this.accessKey = attributes.accessKey || ""; 43239 this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]); 43240 this.colSpan = getInteger({ 43241 data: attributes.colSpan, 43242 defaultValue: 1, 43243 validate: n => n >= 1 || n === -1 43244 }); 43245 this.h = attributes.h ? getMeasurement(attributes.h) : ""; 43246 this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]); 43247 this.id = attributes.id || ""; 43248 this.layout = getStringOption(attributes.layout, ["position", "lr-tb", "rl-row", "rl-tb", "row", "table", "tb"]); 43249 this.maxH = getMeasurement(attributes.maxH, "0pt"); 43250 this.maxW = getMeasurement(attributes.maxW, "0pt"); 43251 this.minH = getMeasurement(attributes.minH, "0pt"); 43252 this.minW = getMeasurement(attributes.minW, "0pt"); 43253 this.name = attributes.name || ""; 43254 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); 43255 this.relevant = getRelevant(attributes.relevant); 43256 this.use = attributes.use || ""; 43257 this.usehref = attributes.usehref || ""; 43258 this.w = attributes.w ? getMeasurement(attributes.w) : ""; 43259 this.x = getMeasurement(attributes.x, "0pt"); 43260 this.y = getMeasurement(attributes.y, "0pt"); 43261 this.assist = null; 43262 this.bind = null; 43263 this.border = null; 43264 this.calculate = null; 43265 this.caption = null; 43266 this.desc = null; 43267 this.extras = null; 43268 this.margin = null; 43269 this.para = null; 43270 this.traversal = null; 43271 this.validate = null; 43272 this.connect = new XFAObjectArray(); 43273 this.event = new XFAObjectArray(); 43274 this.field = new XFAObjectArray(); 43275 this.setProperty = new XFAObjectArray(); 43276 } 43277 [$isBindable]() { 43278 return true; 43279 } 43280 [$hasSettableValue]() { 43281 return true; 43282 } 43283 [$setValue](value) { 43284 for (const field of this.field.children) { 43285 if (!field.value) { 43286 const nodeValue = new Value({}); 43287 field[$appendChild](nodeValue); 43288 field.value = nodeValue; 43289 } 43290 field.value[$setValue](value); 43291 } 43292 } 43293 [$isThereMoreWidth]() { 43294 return this.layout.endsWith("-tb") && this[$extra].attempt === 0 && this[$extra].numberInLine > 0 || this[$getParent]()[$isThereMoreWidth](); 43295 } 43296 [$isSplittable]() { 43297 const parent = this[$getSubformParent](); 43298 if (!parent[$isSplittable]()) { 43299 return false; 43300 } 43301 if (this[$extra]._isSplittable !== undefined) { 43302 return this[$extra]._isSplittable; 43303 } 43304 if (this.layout === "position" || this.layout.includes("row")) { 43305 this[$extra]._isSplittable = false; 43306 return false; 43307 } 43308 if (parent.layout?.endsWith("-tb") && parent[$extra].numberInLine !== 0) { 43309 return false; 43310 } 43311 this[$extra]._isSplittable = true; 43312 return true; 43313 } 43314 [$flushHTML]() { 43315 return flushHTML(this); 43316 } 43317 [$addHTML](html, bbox) { 43318 addHTML(this, html, bbox); 43319 } 43320 [$getAvailableSpace]() { 43321 return getAvailableSpace(this); 43322 } 43323 [$toHTML](availableSpace) { 43324 setTabIndex(this); 43325 if (this.presence === "hidden" || this.presence === "inactive" || this.h === 0 || this.w === 0) { 43326 return HTMLResult.EMPTY; 43327 } 43328 fixDimensions(this); 43329 const children = []; 43330 const attributes = { 43331 id: this[$uid], 43332 class: [] 43333 }; 43334 setAccess(this, attributes.class); 43335 this[$extra] ||= Object.create(null); 43336 Object.assign(this[$extra], { 43337 children, 43338 attributes, 43339 attempt: 0, 43340 line: null, 43341 numberInLine: 0, 43342 availableSpace: { 43343 width: Math.min(this.w || Infinity, availableSpace.width), 43344 height: Math.min(this.h || Infinity, availableSpace.height) 43345 }, 43346 width: 0, 43347 height: 0, 43348 prevHeight: 0, 43349 currentWidth: 0 43350 }); 43351 const isSplittable = this[$isSplittable](); 43352 if (!isSplittable) { 43353 setFirstUnsplittable(this); 43354 } 43355 if (!checkDimensions(this, availableSpace)) { 43356 return HTMLResult.FAILURE; 43357 } 43358 const filter = new Set(["field"]); 43359 if (this.layout.includes("row")) { 43360 const columnWidths = this[$getSubformParent]().columnWidths; 43361 if (Array.isArray(columnWidths) && columnWidths.length > 0) { 43362 this[$extra].columnWidths = columnWidths; 43363 this[$extra].currentColumn = 0; 43364 } 43365 } 43366 const style = toStyle(this, "anchorType", "dimensions", "position", "presence", "border", "margin", "hAlign"); 43367 const classNames = ["xfaExclgroup"]; 43368 const cl = layoutClass(this); 43369 if (cl) { 43370 classNames.push(cl); 43371 } 43372 if (isPrintOnly(this)) { 43373 classNames.push("xfaPrintOnly"); 43374 } 43375 attributes.style = style; 43376 attributes.class = classNames; 43377 if (this.name) { 43378 attributes.xfaName = this.name; 43379 } 43380 this[$pushPara](); 43381 const isLrTb = this.layout === "lr-tb" || this.layout === "rl-tb"; 43382 const maxRun = isLrTb ? MAX_ATTEMPTS_FOR_LRTB_LAYOUT : 1; 43383 for (; this[$extra].attempt < maxRun; this[$extra].attempt++) { 43384 if (isLrTb && this[$extra].attempt === MAX_ATTEMPTS_FOR_LRTB_LAYOUT - 1) { 43385 this[$extra].numberInLine = 0; 43386 } 43387 const result = this[$childrenToHTML]({ 43388 filter, 43389 include: true 43390 }); 43391 if (result.success) { 43392 break; 43393 } 43394 if (result.isBreak()) { 43395 this[$popPara](); 43396 return result; 43397 } 43398 if (isLrTb && this[$extra].attempt === 0 && this[$extra].numberInLine === 0 && !this[$getTemplateRoot]()[$extra].noLayoutFailure) { 43399 this[$extra].attempt = maxRun; 43400 break; 43401 } 43402 } 43403 this[$popPara](); 43404 if (!isSplittable) { 43405 unsetFirstUnsplittable(this); 43406 } 43407 if (this[$extra].attempt === maxRun) { 43408 if (!isSplittable) { 43409 delete this[$extra]; 43410 } 43411 return HTMLResult.FAILURE; 43412 } 43413 let marginH = 0; 43414 let marginV = 0; 43415 if (this.margin) { 43416 marginH = this.margin.leftInset + this.margin.rightInset; 43417 marginV = this.margin.topInset + this.margin.bottomInset; 43418 } 43419 const width = Math.max(this[$extra].width + marginH, this.w || 0); 43420 const height = Math.max(this[$extra].height + marginV, this.h || 0); 43421 const bbox = [this.x, this.y, width, height]; 43422 if (this.w === "") { 43423 style.width = measureToString(width); 43424 } 43425 if (this.h === "") { 43426 style.height = measureToString(height); 43427 } 43428 const html = { 43429 name: "div", 43430 attributes, 43431 children 43432 }; 43433 applyAssist(this, attributes); 43434 delete this[$extra]; 43435 return HTMLResult.success(createWrapper(this, html), bbox); 43436 } 43437} 43438class Execute extends XFAObject { 43439 constructor(attributes) { 43440 super(TEMPLATE_NS_ID, "execute"); 43441 this.connection = attributes.connection || ""; 43442 this.executeType = getStringOption(attributes.executeType, ["import", "remerge"]); 43443 this.id = attributes.id || ""; 43444 this.runAt = getStringOption(attributes.runAt, ["client", "both", "server"]); 43445 this.use = attributes.use || ""; 43446 this.usehref = attributes.usehref || ""; 43447 } 43448} 43449class Extras extends XFAObject { 43450 constructor(attributes) { 43451 super(TEMPLATE_NS_ID, "extras", true); 43452 this.id = attributes.id || ""; 43453 this.name = attributes.name || ""; 43454 this.use = attributes.use || ""; 43455 this.usehref = attributes.usehref || ""; 43456 this.boolean = new XFAObjectArray(); 43457 this.date = new XFAObjectArray(); 43458 this.dateTime = new XFAObjectArray(); 43459 this.decimal = new XFAObjectArray(); 43460 this.exData = new XFAObjectArray(); 43461 this.extras = new XFAObjectArray(); 43462 this.float = new XFAObjectArray(); 43463 this.image = new XFAObjectArray(); 43464 this.integer = new XFAObjectArray(); 43465 this.text = new XFAObjectArray(); 43466 this.time = new XFAObjectArray(); 43467 } 43468} 43469class Field extends XFAObject { 43470 constructor(attributes) { 43471 super(TEMPLATE_NS_ID, "field", true); 43472 this.access = getStringOption(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]); 43473 this.accessKey = attributes.accessKey || ""; 43474 this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]); 43475 this.colSpan = getInteger({ 43476 data: attributes.colSpan, 43477 defaultValue: 1, 43478 validate: n => n >= 1 || n === -1 43479 }); 43480 this.h = attributes.h ? getMeasurement(attributes.h) : ""; 43481 this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]); 43482 this.id = attributes.id || ""; 43483 this.locale = attributes.locale || ""; 43484 this.maxH = getMeasurement(attributes.maxH, "0pt"); 43485 this.maxW = getMeasurement(attributes.maxW, "0pt"); 43486 this.minH = getMeasurement(attributes.minH, "0pt"); 43487 this.minW = getMeasurement(attributes.minW, "0pt"); 43488 this.name = attributes.name || ""; 43489 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); 43490 this.relevant = getRelevant(attributes.relevant); 43491 this.rotate = getInteger({ 43492 data: attributes.rotate, 43493 defaultValue: 0, 43494 validate: x => x % 90 === 0 43495 }); 43496 this.use = attributes.use || ""; 43497 this.usehref = attributes.usehref || ""; 43498 this.w = attributes.w ? getMeasurement(attributes.w) : ""; 43499 this.x = getMeasurement(attributes.x, "0pt"); 43500 this.y = getMeasurement(attributes.y, "0pt"); 43501 this.assist = null; 43502 this.bind = null; 43503 this.border = null; 43504 this.calculate = null; 43505 this.caption = null; 43506 this.desc = null; 43507 this.extras = null; 43508 this.font = null; 43509 this.format = null; 43510 this.items = new XFAObjectArray(2); 43511 this.keep = null; 43512 this.margin = null; 43513 this.para = null; 43514 this.traversal = null; 43515 this.ui = null; 43516 this.validate = null; 43517 this.value = null; 43518 this.bindItems = new XFAObjectArray(); 43519 this.connect = new XFAObjectArray(); 43520 this.event = new XFAObjectArray(); 43521 this.setProperty = new XFAObjectArray(); 43522 } 43523 [$isBindable]() { 43524 return true; 43525 } 43526 [$setValue](value) { 43527 _setValue(this, value); 43528 } 43529 [$toHTML](availableSpace) { 43530 setTabIndex(this); 43531 if (!this.ui) { 43532 this.ui = new Ui({}); 43533 this.ui[$globalData] = this[$globalData]; 43534 this[$appendChild](this.ui); 43535 let node; 43536 switch (this.items.children.length) { 43537 case 0: 43538 node = new TextEdit({}); 43539 this.ui.textEdit = node; 43540 break; 43541 case 1: 43542 node = new CheckButton({}); 43543 this.ui.checkButton = node; 43544 break; 43545 case 2: 43546 node = new ChoiceList({}); 43547 this.ui.choiceList = node; 43548 break; 43549 } 43550 this.ui[$appendChild](node); 43551 } 43552 if (!this.ui || this.presence === "hidden" || this.presence === "inactive" || this.h === 0 || this.w === 0) { 43553 return HTMLResult.EMPTY; 43554 } 43555 if (this.caption) { 43556 delete this.caption[$extra]; 43557 }
vendor: 6,271 bytes, lines 43558-43761
43558 this[$pushPara](); 43559 const caption = this.caption ? this.caption[$toHTML](availableSpace).html : null; 43560 const savedW = this.w; 43561 const savedH = this.h; 43562 let marginH = 0; 43563 let marginV = 0; 43564 if (this.margin) { 43565 marginH = this.margin.leftInset + this.margin.rightInset; 43566 marginV = this.margin.topInset + this.margin.bottomInset; 43567 } 43568 let borderDims = null; 43569 if (this.w === "" || this.h === "") { 43570 let width = null; 43571 let height = null; 43572 let uiW = 0; 43573 let uiH = 0; 43574 if (this.ui.checkButton) { 43575 uiW = uiH = this.ui.checkButton.size; 43576 } else { 43577 const { 43578 w, 43579 h 43580 } = layoutNode(this, availableSpace); 43581 if (w !== null) { 43582 uiW = w; 43583 uiH = h; 43584 } else { 43585 uiH = fonts_getMetrics(this.font, true).lineNoGap; 43586 } 43587 } 43588 borderDims = getBorderDims(this.ui[$getExtra]()); 43589 uiW += borderDims.w; 43590 uiH += borderDims.h; 43591 if (this.caption) { 43592 const { 43593 w, 43594 h, 43595 isBroken 43596 } = this.caption[$getExtra](availableSpace); 43597 if (isBroken && this[$getSubformParent]()[$isThereMoreWidth]()) { 43598 this[$popPara](); 43599 return HTMLResult.FAILURE; 43600 } 43601 width = w; 43602 height = h; 43603 switch (this.caption.placement) { 43604 case "left": 43605 case "right": 43606 case "inline": 43607 width += uiW; 43608 break; 43609 case "top": 43610 case "bottom": 43611 height += uiH; 43612 break; 43613 } 43614 } else { 43615 width = uiW; 43616 height = uiH; 43617 } 43618 if (width && this.w === "") { 43619 width += marginH; 43620 this.w = Math.min(this.maxW <= 0 ? Infinity : this.maxW, this.minW + 1 < width ? width : this.minW); 43621 } 43622 if (height && this.h === "") { 43623 height += marginV; 43624 this.h = Math.min(this.maxH <= 0 ? Infinity : this.maxH, this.minH + 1 < height ? height : this.minH); 43625 } 43626 } 43627 this[$popPara](); 43628 fixDimensions(this); 43629 setFirstUnsplittable(this); 43630 if (!checkDimensions(this, availableSpace)) { 43631 this.w = savedW; 43632 this.h = savedH; 43633 this[$popPara](); 43634 return HTMLResult.FAILURE; 43635 } 43636 unsetFirstUnsplittable(this); 43637 const style = toStyle(this, "font", "dimensions", "position", "rotate", "anchorType", "presence", "margin", "hAlign"); 43638 setMinMaxDimensions(this, style); 43639 const classNames = ["xfaField"]; 43640 if (this.font) { 43641 classNames.push("xfaFont"); 43642 } 43643 if (isPrintOnly(this)) { 43644 classNames.push("xfaPrintOnly"); 43645 } 43646 const attributes = { 43647 style, 43648 id: this[$uid], 43649 class: classNames 43650 }; 43651 if (style.margin) { 43652 style.padding = style.margin; 43653 delete style.margin; 43654 } 43655 setAccess(this, classNames); 43656 if (this.name) { 43657 attributes.xfaName = this.name; 43658 } 43659 const children = []; 43660 const html = { 43661 name: "div", 43662 attributes, 43663 children 43664 }; 43665 applyAssist(this, attributes); 43666 const borderStyle = this.border ? this.border[$toStyle]() : null; 43667 const bbox = computeBbox(this, html, availableSpace); 43668 const ui = this.ui[$toHTML]().html; 43669 if (!ui) { 43670 Object.assign(style, borderStyle); 43671 return HTMLResult.success(createWrapper(this, html), bbox); 43672 } 43673 if (this[$tabIndex]) { 43674 if (ui.children?.[0]) { 43675 ui.children[0].attributes.tabindex = this[$tabIndex]; 43676 } else { 43677 ui.attributes.tabindex = this[$tabIndex]; 43678 } 43679 } 43680 ui.attributes.style ||= Object.create(null); 43681 let aElement = null; 43682 if (this.ui.button) { 43683 if (ui.children.length === 1) { 43684 [aElement] = ui.children.splice(0, 1); 43685 } 43686 Object.assign(ui.attributes.style, borderStyle); 43687 } else { 43688 Object.assign(style, borderStyle); 43689 } 43690 children.push(ui); 43691 if (this.value) { 43692 if (this.ui.imageEdit) { 43693 ui.children.push(this.value[$toHTML]().html); 43694 } else if (!this.ui.button) { 43695 let value = ""; 43696 if (this.value.exData) { 43697 value = this.value.exData[$text](); 43698 } else if (this.value.text) { 43699 value = this.value.text[$getExtra](); 43700 } else { 43701 const htmlValue = this.value[$toHTML]().html; 43702 if (htmlValue !== null) { 43703 value = htmlValue.children[0].value; 43704 } 43705 } 43706 if (this.ui.textEdit && this.value.text?.maxChars) { 43707 ui.children[0].attributes.maxLength = this.value.text.maxChars; 43708 } 43709 if (value) { 43710 if (this.ui.numericEdit) { 43711 value = parseFloat(value); 43712 value = isNaN(value) ? "" : value.toString(); 43713 } 43714 if (ui.children[0].name === "textarea") { 43715 ui.children[0].attributes.textContent = value; 43716 } else { 43717 ui.children[0].attributes.value = value; 43718 } 43719 } 43720 } 43721 } 43722 if (!this.ui.imageEdit && ui.children?.[0] && this.h) { 43723 borderDims = borderDims || getBorderDims(this.ui[$getExtra]()); 43724 let captionHeight = 0; 43725 if (this.caption && ["top", "bottom"].includes(this.caption.placement)) { 43726 captionHeight = this.caption.reserve; 43727 if (captionHeight <= 0) { 43728 captionHeight = this.caption[$getExtra](availableSpace).h; 43729 } 43730 const inputHeight = this.h - captionHeight - marginV - borderDims.h; 43731 ui.children[0].attributes.style.height = measureToString(inputHeight); 43732 } else { 43733 ui.children[0].attributes.style.height = "100%"; 43734 } 43735 } 43736 if (aElement) { 43737 ui.children.push(aElement); 43738 } 43739 if (!caption) { 43740 if (ui.attributes.class) { 43741 ui.attributes.class.push("xfaLeft"); 43742 } 43743 this.w = savedW; 43744 this.h = savedH; 43745 return HTMLResult.success(createWrapper(this, html), bbox); 43746 } 43747 if (this.ui.button) { 43748 if (style.padding) { 43749 delete style.padding; 43750 } 43751 if (caption.name === "div") { 43752 caption.name = "span"; 43753 } 43754 ui.children.push(caption); 43755 return HTMLResult.success(html, bbox); 43756 } else if (this.ui.checkButton) { 43757 caption.attributes.class[0] = "xfaCaptionForCheckButton"; 43758 } 43759 ui.attributes.class ||= []; 43760 ui.children.splice(0, 0, caption); 43761 switch (this.caption.placement) {
vendor: 5,632 bytes, lines 43762-43935
43762 case "left": 43763 ui.attributes.class.push("xfaLeft"); 43764 break; 43765 case "right": 43766 ui.attributes.class.push("xfaRight"); 43767 break; 43768 case "top": 43769 ui.attributes.class.push("xfaTop"); 43770 break; 43771 case "bottom": 43772 ui.attributes.class.push("xfaBottom"); 43773 break; 43774 case "inline": 43775 ui.attributes.class.push("xfaLeft"); 43776 break; 43777 } 43778 this.w = savedW; 43779 this.h = savedH; 43780 return HTMLResult.success(createWrapper(this, html), bbox); 43781 } 43782} 43783class Fill extends XFAObject { 43784 constructor(attributes) { 43785 super(TEMPLATE_NS_ID, "fill", true); 43786 this.id = attributes.id || ""; 43787 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); 43788 this.use = attributes.use || ""; 43789 this.usehref = attributes.usehref || ""; 43790 this.color = null; 43791 this.extras = null; 43792 this.linear = null; 43793 this.pattern = null; 43794 this.radial = null; 43795 this.solid = null; 43796 this.stipple = null; 43797 } 43798 [$toStyle]() { 43799 const parent = this[$getParent](); 43800 const grandpa = parent[$getParent](); 43801 const ggrandpa = grandpa[$getParent](); 43802 const style = Object.create(null); 43803 let propName = "color"; 43804 let altPropName = propName; 43805 if (parent instanceof Border) { 43806 propName = "background-color"; 43807 altPropName = "background"; 43808 if (ggrandpa instanceof Ui) { 43809 style.backgroundColor = "white"; 43810 } 43811 } 43812 if (parent instanceof Rectangle || parent instanceof Arc) { 43813 propName = altPropName = "fill"; 43814 style.fill = "white"; 43815 } 43816 for (const name of Object.getOwnPropertyNames(this)) { 43817 if (name === "extras" || name === "color") { 43818 continue; 43819 } 43820 const obj = this[name]; 43821 if (!(obj instanceof XFAObject)) { 43822 continue; 43823 } 43824 const color = obj[$toStyle](this.color); 43825 if (color) { 43826 style[color.startsWith("#") ? propName : altPropName] = color; 43827 } 43828 return style; 43829 } 43830 if (this.color?.value) { 43831 const color = this.color[$toStyle](); 43832 style[color.startsWith("#") ? propName : altPropName] = color; 43833 } 43834 return style; 43835 } 43836} 43837class Filter extends XFAObject { 43838 constructor(attributes) { 43839 super(TEMPLATE_NS_ID, "filter", true); 43840 this.addRevocationInfo = getStringOption(attributes.addRevocationInfo, ["", "required", "optional", "none"]); 43841 this.id = attributes.id || ""; 43842 this.name = attributes.name || ""; 43843 this.use = attributes.use || ""; 43844 this.usehref = attributes.usehref || ""; 43845 this.version = getInteger({ 43846 data: this.version, 43847 defaultValue: 5, 43848 validate: x => x >= 1 && x <= 5 43849 }); 43850 this.appearanceFilter = null; 43851 this.certificates = null; 43852 this.digestMethods = null; 43853 this.encodings = null; 43854 this.encryptionMethods = null; 43855 this.handler = null; 43856 this.lockDocument = null; 43857 this.mdp = null; 43858 this.reasons = null; 43859 this.timeStamp = null; 43860 } 43861} 43862class Float extends ContentObject { 43863 constructor(attributes) { 43864 super(TEMPLATE_NS_ID, "float"); 43865 this.id = attributes.id || ""; 43866 this.name = attributes.name || ""; 43867 this.use = attributes.use || ""; 43868 this.usehref = attributes.usehref || ""; 43869 } 43870 [$finalize]() { 43871 const number = parseFloat(this[$content].trim()); 43872 this[$content] = isNaN(number) ? null : number; 43873 } 43874 [$toHTML](availableSpace) { 43875 return valueToHtml(this[$content] !== null ? this[$content].toString() : ""); 43876 } 43877} 43878class template_Font extends XFAObject { 43879 constructor(attributes) { 43880 super(TEMPLATE_NS_ID, "font", true); 43881 this.baselineShift = getMeasurement(attributes.baselineShift); 43882 this.fontHorizontalScale = getFloat({ 43883 data: attributes.fontHorizontalScale, 43884 defaultValue: 100, 43885 validate: x => x >= 0 43886 }); 43887 this.fontVerticalScale = getFloat({ 43888 data: attributes.fontVerticalScale, 43889 defaultValue: 100, 43890 validate: x => x >= 0 43891 }); 43892 this.id = attributes.id || ""; 43893 this.kerningMode = getStringOption(attributes.kerningMode, ["none", "pair"]); 43894 this.letterSpacing = getMeasurement(attributes.letterSpacing, "0"); 43895 this.lineThrough = getInteger({ 43896 data: attributes.lineThrough, 43897 defaultValue: 0, 43898 validate: x => x === 1 || x === 2 43899 }); 43900 this.lineThroughPeriod = getStringOption(attributes.lineThroughPeriod, ["all", "word"]); 43901 this.overline = getInteger({ 43902 data: attributes.overline, 43903 defaultValue: 0, 43904 validate: x => x === 1 || x === 2 43905 }); 43906 this.overlinePeriod = getStringOption(attributes.overlinePeriod, ["all", "word"]); 43907 this.posture = getStringOption(attributes.posture, ["normal", "italic"]); 43908 this.size = getMeasurement(attributes.size, "10pt"); 43909 this.typeface = attributes.typeface || "Courier"; 43910 this.underline = getInteger({ 43911 data: attributes.underline, 43912 defaultValue: 0, 43913 validate: x => x === 1 || x === 2 43914 }); 43915 this.underlinePeriod = getStringOption(attributes.underlinePeriod, ["all", "word"]); 43916 this.use = attributes.use || ""; 43917 this.usehref = attributes.usehref || ""; 43918 this.weight = getStringOption(attributes.weight, ["normal", "bold"]); 43919 this.extras = null; 43920 this.fill = null; 43921 } 43922 [$clean](builder) { 43923 super[$clean](builder); 43924 this[$globalData].usedTypefaces.add(this.typeface); 43925 } 43926 [$toStyle]() { 43927 const style = toStyle(this, "fill"); 43928 const color = style.color; 43929 if (color) { 43930 if (color === "#000000") { 43931 delete style.color; 43932 } else if (!color.startsWith("#")) { 43933 style.background = color; 43934 style.backgroundClip = "text"; 43935 style.color = "transparent";
vendor: 21,765 bytes, lines 43936-44630
43936 } 43937 } 43938 if (this.baselineShift) { 43939 style.verticalAlign = measureToString(this.baselineShift); 43940 } 43941 style.fontKerning = this.kerningMode === "none" ? "none" : "normal"; 43942 style.letterSpacing = measureToString(this.letterSpacing); 43943 if (this.lineThrough !== 0) { 43944 style.textDecoration = "line-through"; 43945 if (this.lineThrough === 2) { 43946 style.textDecorationStyle = "double"; 43947 } 43948 } 43949 if (this.overline !== 0) { 43950 style.textDecoration = "overline"; 43951 if (this.overline === 2) { 43952 style.textDecorationStyle = "double"; 43953 } 43954 } 43955 style.fontStyle = this.posture; 43956 style.fontSize = measureToString(0.99 * this.size); 43957 setFontFamily(this, this, this[$globalData].fontFinder, style); 43958 if (this.underline !== 0) { 43959 style.textDecoration = "underline"; 43960 if (this.underline === 2) { 43961 style.textDecorationStyle = "double"; 43962 } 43963 } 43964 style.fontWeight = this.weight; 43965 return style; 43966 } 43967} 43968class Format extends XFAObject { 43969 constructor(attributes) { 43970 super(TEMPLATE_NS_ID, "format", true); 43971 this.id = attributes.id || ""; 43972 this.use = attributes.use || ""; 43973 this.usehref = attributes.usehref || ""; 43974 this.extras = null; 43975 this.picture = null; 43976 } 43977} 43978class Handler extends StringObject { 43979 constructor(attributes) { 43980 super(TEMPLATE_NS_ID, "handler"); 43981 this.id = attributes.id || ""; 43982 this.type = getStringOption(attributes.type, ["optional", "required"]); 43983 this.use = attributes.use || ""; 43984 this.usehref = attributes.usehref || ""; 43985 } 43986} 43987class Hyphenation extends XFAObject { 43988 constructor(attributes) { 43989 super(TEMPLATE_NS_ID, "hyphenation"); 43990 this.excludeAllCaps = getInteger({ 43991 data: attributes.excludeAllCaps, 43992 defaultValue: 0, 43993 validate: x => x === 1 43994 }); 43995 this.excludeInitialCap = getInteger({ 43996 data: attributes.excludeInitialCap, 43997 defaultValue: 0, 43998 validate: x => x === 1 43999 }); 44000 this.hyphenate = getInteger({ 44001 data: attributes.hyphenate, 44002 defaultValue: 0, 44003 validate: x => x === 1 44004 }); 44005 this.id = attributes.id || ""; 44006 this.pushCharacterCount = getInteger({ 44007 data: attributes.pushCharacterCount, 44008 defaultValue: 3, 44009 validate: x => x >= 0 44010 }); 44011 this.remainCharacterCount = getInteger({ 44012 data: attributes.remainCharacterCount, 44013 defaultValue: 3, 44014 validate: x => x >= 0 44015 }); 44016 this.use = attributes.use || ""; 44017 this.usehref = attributes.usehref || ""; 44018 this.wordCharacterCount = getInteger({ 44019 data: attributes.wordCharacterCount, 44020 defaultValue: 7, 44021 validate: x => x >= 0 44022 }); 44023 } 44024} 44025class Image extends StringObject { 44026 constructor(attributes) { 44027 super(TEMPLATE_NS_ID, "image"); 44028 this.aspect = getStringOption(attributes.aspect, ["fit", "actual", "height", "none", "width"]); 44029 this.contentType = attributes.contentType || ""; 44030 this.href = attributes.href || ""; 44031 this.id = attributes.id || ""; 44032 this.name = attributes.name || ""; 44033 this.transferEncoding = getStringOption(attributes.transferEncoding, ["base64", "none", "package"]); 44034 this.use = attributes.use || ""; 44035 this.usehref = attributes.usehref || ""; 44036 } 44037 [$toHTML]() { 44038 if (this.contentType && !MIMES.has(this.contentType.toLowerCase())) { 44039 return HTMLResult.EMPTY; 44040 } 44041 let buffer = this[$globalData].images?.get(this.href); 44042 if (!buffer && (this.href || !this[$content])) { 44043 return HTMLResult.EMPTY; 44044 } 44045 if (!buffer && this.transferEncoding === "base64") { 44046 buffer = fromBase64Util(this[$content]); 44047 } 44048 if (!buffer) { 44049 return HTMLResult.EMPTY; 44050 } 44051 if (!this.contentType) { 44052 for (const [header, type] of IMAGES_HEADERS) { 44053 if (buffer.length > header.length && header.every((x, i) => x === buffer[i])) { 44054 this.contentType = type; 44055 break; 44056 } 44057 } 44058 if (!this.contentType) { 44059 return HTMLResult.EMPTY; 44060 } 44061 } 44062 const blob = new Blob([buffer], { 44063 type: this.contentType 44064 }); 44065 let style; 44066 switch (this.aspect) { 44067 case "fit": 44068 case "actual": 44069 break; 44070 case "height": 44071 style = { 44072 height: "100%", 44073 objectFit: "fill" 44074 }; 44075 break; 44076 case "none": 44077 style = { 44078 width: "100%", 44079 height: "100%", 44080 objectFit: "fill" 44081 }; 44082 break; 44083 case "width": 44084 style = { 44085 width: "100%", 44086 objectFit: "fill" 44087 }; 44088 break; 44089 } 44090 const parent = this[$getParent](); 44091 return HTMLResult.success({ 44092 name: "img", 44093 attributes: { 44094 class: ["xfaImage"], 44095 style, 44096 src: URL.createObjectURL(blob), 44097 alt: parent ? ariaLabel(parent[$getParent]()) : null 44098 } 44099 }); 44100 } 44101} 44102class ImageEdit extends XFAObject { 44103 constructor(attributes) { 44104 super(TEMPLATE_NS_ID, "imageEdit", true); 44105 this.data = getStringOption(attributes.data, ["link", "embed"]); 44106 this.id = attributes.id || ""; 44107 this.use = attributes.use || ""; 44108 this.usehref = attributes.usehref || ""; 44109 this.border = null; 44110 this.extras = null; 44111 this.margin = null; 44112 } 44113 [$toHTML](availableSpace) { 44114 if (this.data === "embed") { 44115 return HTMLResult.success({ 44116 name: "div", 44117 children: [], 44118 attributes: {} 44119 }); 44120 } 44121 return HTMLResult.EMPTY; 44122 } 44123} 44124class Integer extends ContentObject { 44125 constructor(attributes) { 44126 super(TEMPLATE_NS_ID, "integer"); 44127 this.id = attributes.id || ""; 44128 this.name = attributes.name || ""; 44129 this.use = attributes.use || ""; 44130 this.usehref = attributes.usehref || ""; 44131 } 44132 [$finalize]() { 44133 const number = parseInt(this[$content].trim(), 10); 44134 this[$content] = isNaN(number) ? null : number; 44135 } 44136 [$toHTML](availableSpace) { 44137 return valueToHtml(this[$content] !== null ? this[$content].toString() : ""); 44138 } 44139} 44140class Issuers extends XFAObject { 44141 constructor(attributes) { 44142 super(TEMPLATE_NS_ID, "issuers", true); 44143 this.id = attributes.id || ""; 44144 this.type = getStringOption(attributes.type, ["optional", "required"]); 44145 this.use = attributes.use || ""; 44146 this.usehref = attributes.usehref || ""; 44147 this.certificate = new XFAObjectArray(); 44148 } 44149} 44150class Items extends XFAObject { 44151 constructor(attributes) { 44152 super(TEMPLATE_NS_ID, "items", true); 44153 this.id = attributes.id || ""; 44154 this.name = attributes.name || ""; 44155 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); 44156 this.ref = attributes.ref || ""; 44157 this.save = getInteger({ 44158 data: attributes.save, 44159 defaultValue: 0, 44160 validate: x => x === 1 44161 }); 44162 this.use = attributes.use || ""; 44163 this.usehref = attributes.usehref || ""; 44164 this.boolean = new XFAObjectArray(); 44165 this.date = new XFAObjectArray(); 44166 this.dateTime = new XFAObjectArray(); 44167 this.decimal = new XFAObjectArray(); 44168 this.exData = new XFAObjectArray(); 44169 this.float = new XFAObjectArray(); 44170 this.image = new XFAObjectArray(); 44171 this.integer = new XFAObjectArray(); 44172 this.text = new XFAObjectArray(); 44173 this.time = new XFAObjectArray(); 44174 } 44175 [$toHTML]() { 44176 const output = []; 44177 for (const child of this[$getChildren]()) { 44178 output.push(child[$text]()); 44179 } 44180 return HTMLResult.success(output); 44181 } 44182} 44183class Keep extends XFAObject { 44184 constructor(attributes) { 44185 super(TEMPLATE_NS_ID, "keep", true); 44186 this.id = attributes.id || ""; 44187 const options = ["none", "contentArea", "pageArea"]; 44188 this.intact = getStringOption(attributes.intact, options); 44189 this.next = getStringOption(attributes.next, options); 44190 this.previous = getStringOption(attributes.previous, options); 44191 this.use = attributes.use || ""; 44192 this.usehref = attributes.usehref || ""; 44193 this.extras = null; 44194 } 44195} 44196class KeyUsage extends XFAObject { 44197 constructor(attributes) { 44198 super(TEMPLATE_NS_ID, "keyUsage"); 44199 const options = ["", "yes", "no"]; 44200 this.crlSign = getStringOption(attributes.crlSign, options); 44201 this.dataEncipherment = getStringOption(attributes.dataEncipherment, options); 44202 this.decipherOnly = getStringOption(attributes.decipherOnly, options); 44203 this.digitalSignature = getStringOption(attributes.digitalSignature, options); 44204 this.encipherOnly = getStringOption(attributes.encipherOnly, options); 44205 this.id = attributes.id || ""; 44206 this.keyAgreement = getStringOption(attributes.keyAgreement, options); 44207 this.keyCertSign = getStringOption(attributes.keyCertSign, options); 44208 this.keyEncipherment = getStringOption(attributes.keyEncipherment, options); 44209 this.nonRepudiation = getStringOption(attributes.nonRepudiation, options); 44210 this.type = getStringOption(attributes.type, ["optional", "required"]); 44211 this.use = attributes.use || ""; 44212 this.usehref = attributes.usehref || ""; 44213 } 44214} 44215class Line extends XFAObject { 44216 constructor(attributes) { 44217 super(TEMPLATE_NS_ID, "line", true); 44218 this.hand = getStringOption(attributes.hand, ["even", "left", "right"]); 44219 this.id = attributes.id || ""; 44220 this.slope = getStringOption(attributes.slope, ["\\", "/"]); 44221 this.use = attributes.use || ""; 44222 this.usehref = attributes.usehref || ""; 44223 this.edge = null; 44224 } 44225 [$toHTML]() { 44226 const parent = this[$getParent]()[$getParent](); 44227 const edge = this.edge || new Edge({}); 44228 const edgeStyle = edge[$toStyle](); 44229 const style = Object.create(null); 44230 const thickness = edge.presence === "visible" ? edge.thickness : 0; 44231 style.strokeWidth = measureToString(thickness); 44232 style.stroke = edgeStyle.color; 44233 let x1, y1, x2, y2; 44234 let width = "100%"; 44235 let height = "100%"; 44236 if (parent.w <= thickness) { 44237 [x1, y1, x2, y2] = ["50%", 0, "50%", "100%"]; 44238 width = style.strokeWidth; 44239 } else if (parent.h <= thickness) { 44240 [x1, y1, x2, y2] = [0, "50%", "100%", "50%"]; 44241 height = style.strokeWidth; 44242 } else if (this.slope === "\\") { 44243 [x1, y1, x2, y2] = [0, 0, "100%", "100%"]; 44244 } else { 44245 [x1, y1, x2, y2] = [0, "100%", "100%", 0]; 44246 } 44247 const line = { 44248 name: "line", 44249 attributes: { 44250 xmlns: SVG_NS, 44251 x1, 44252 y1, 44253 x2, 44254 y2, 44255 style 44256 } 44257 }; 44258 const svg = { 44259 name: "svg", 44260 children: [line], 44261 attributes: { 44262 xmlns: SVG_NS, 44263 width, 44264 height, 44265 style: { 44266 overflow: "visible" 44267 } 44268 } 44269 }; 44270 if (hasMargin(parent)) { 44271 return HTMLResult.success({ 44272 name: "div", 44273 attributes: { 44274 style: { 44275 display: "inline", 44276 width: "100%", 44277 height: "100%" 44278 } 44279 }, 44280 children: [svg] 44281 }); 44282 } 44283 svg.attributes.style.position = "absolute"; 44284 return HTMLResult.success(svg); 44285 } 44286} 44287class Linear extends XFAObject { 44288 constructor(attributes) { 44289 super(TEMPLATE_NS_ID, "linear", true); 44290 this.id = attributes.id || ""; 44291 this.type = getStringOption(attributes.type, ["toRight", "toBottom", "toLeft", "toTop"]); 44292 this.use = attributes.use || ""; 44293 this.usehref = attributes.usehref || ""; 44294 this.color = null; 44295 this.extras = null; 44296 } 44297 [$toStyle](startColor) { 44298 startColor = startColor ? startColor[$toStyle]() : "#FFFFFF"; 44299 const transf = this.type.replace(/([RBLT])/, " $1").toLowerCase(); 44300 const endColor = this.color ? this.color[$toStyle]() : "#000000"; 44301 return `linear-gradient(${transf}, ${startColor}, ${endColor})`; 44302 } 44303} 44304class LockDocument extends ContentObject { 44305 constructor(attributes) { 44306 super(TEMPLATE_NS_ID, "lockDocument"); 44307 this.id = attributes.id || ""; 44308 this.type = getStringOption(attributes.type, ["optional", "required"]); 44309 this.use = attributes.use || ""; 44310 this.usehref = attributes.usehref || ""; 44311 } 44312 [$finalize]() { 44313 this[$content] = getStringOption(this[$content], ["auto", "0", "1"]); 44314 } 44315} 44316class Manifest extends XFAObject { 44317 constructor(attributes) { 44318 super(TEMPLATE_NS_ID, "manifest", true); 44319 this.action = getStringOption(attributes.action, ["include", "all", "exclude"]); 44320 this.id = attributes.id || ""; 44321 this.name = attributes.name || ""; 44322 this.use = attributes.use || ""; 44323 this.usehref = attributes.usehref || ""; 44324 this.extras = null; 44325 this.ref = new XFAObjectArray(); 44326 } 44327} 44328class Margin extends XFAObject { 44329 constructor(attributes) { 44330 super(TEMPLATE_NS_ID, "margin", true); 44331 this.bottomInset = getMeasurement(attributes.bottomInset, "0"); 44332 this.id = attributes.id || ""; 44333 this.leftInset = getMeasurement(attributes.leftInset, "0"); 44334 this.rightInset = getMeasurement(attributes.rightInset, "0"); 44335 this.topInset = getMeasurement(attributes.topInset, "0"); 44336 this.use = attributes.use || ""; 44337 this.usehref = attributes.usehref || ""; 44338 this.extras = null; 44339 } 44340 [$toStyle]() { 44341 return { 44342 margin: measureToString(this.topInset) + " " + measureToString(this.rightInset) + " " + measureToString(this.bottomInset) + " " + measureToString(this.leftInset) 44343 }; 44344 } 44345} 44346class Mdp extends XFAObject { 44347 constructor(attributes) { 44348 super(TEMPLATE_NS_ID, "mdp"); 44349 this.id = attributes.id || ""; 44350 this.permissions = getInteger({ 44351 data: attributes.permissions, 44352 defaultValue: 2, 44353 validate: x => x === 1 || x === 3 44354 }); 44355 this.signatureType = getStringOption(attributes.signatureType, ["filler", "author"]); 44356 this.use = attributes.use || ""; 44357 this.usehref = attributes.usehref || ""; 44358 } 44359} 44360class Medium extends XFAObject { 44361 constructor(attributes) { 44362 super(TEMPLATE_NS_ID, "medium"); 44363 this.id = attributes.id || ""; 44364 this.imagingBBox = getBBox(attributes.imagingBBox); 44365 this.long = getMeasurement(attributes.long); 44366 this.orientation = getStringOption(attributes.orientation, ["portrait", "landscape"]); 44367 this.short = getMeasurement(attributes.short); 44368 this.stock = attributes.stock || ""; 44369 this.trayIn = getStringOption(attributes.trayIn, ["auto", "delegate", "pageFront"]); 44370 this.trayOut = getStringOption(attributes.trayOut, ["auto", "delegate"]); 44371 this.use = attributes.use || ""; 44372 this.usehref = attributes.usehref || ""; 44373 } 44374} 44375class Message extends XFAObject { 44376 constructor(attributes) { 44377 super(TEMPLATE_NS_ID, "message", true); 44378 this.id = attributes.id || ""; 44379 this.use = attributes.use || ""; 44380 this.usehref = attributes.usehref || ""; 44381 this.text = new XFAObjectArray(); 44382 } 44383} 44384class NumericEdit extends XFAObject { 44385 constructor(attributes) { 44386 super(TEMPLATE_NS_ID, "numericEdit", true); 44387 this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]); 44388 this.id = attributes.id || ""; 44389 this.use = attributes.use || ""; 44390 this.usehref = attributes.usehref || ""; 44391 this.border = null; 44392 this.comb = null; 44393 this.extras = null; 44394 this.margin = null; 44395 } 44396 [$toHTML](availableSpace) { 44397 const style = toStyle(this, "border", "font", "margin"); 44398 const field = this[$getParent]()[$getParent](); 44399 const html = { 44400 name: "input", 44401 attributes: { 44402 type: "text", 44403 fieldId: field[$uid], 44404 dataId: field[$data]?.[$uid] || field[$uid], 44405 class: ["xfaTextfield"], 44406 style, 44407 "aria-label": ariaLabel(field), 44408 "aria-required": false 44409 } 44410 }; 44411 if (isRequired(field)) { 44412 html.attributes["aria-required"] = true; 44413 html.attributes.required = true; 44414 } 44415 return HTMLResult.success({ 44416 name: "label", 44417 attributes: { 44418 class: ["xfaLabel"] 44419 }, 44420 children: [html] 44421 }); 44422 } 44423} 44424class Occur extends XFAObject { 44425 constructor(attributes) { 44426 super(TEMPLATE_NS_ID, "occur", true); 44427 this.id = attributes.id || ""; 44428 this.initial = attributes.initial !== "" ? getInteger({ 44429 data: attributes.initial, 44430 defaultValue: "", 44431 validate: x => true 44432 }) : ""; 44433 this.max = attributes.max !== "" ? getInteger({ 44434 data: attributes.max, 44435 defaultValue: 1, 44436 validate: x => true 44437 }) : ""; 44438 this.min = attributes.min !== "" ? getInteger({ 44439 data: attributes.min, 44440 defaultValue: 1, 44441 validate: x => true 44442 }) : ""; 44443 this.use = attributes.use || ""; 44444 this.usehref = attributes.usehref || ""; 44445 this.extras = null; 44446 } 44447 [$clean]() { 44448 const parent = this[$getParent](); 44449 const originalMin = this.min; 44450 if (this.min === "") { 44451 this.min = parent instanceof PageArea || parent instanceof PageSet ? 0 : 1; 44452 } 44453 if (this.max === "") { 44454 if (originalMin === "") { 44455 this.max = parent instanceof PageArea || parent instanceof PageSet ? -1 : 1; 44456 } else { 44457 this.max = this.min; 44458 } 44459 } 44460 if (this.max !== -1 && this.max < this.min) { 44461 this.max = this.min; 44462 } 44463 if (this.initial === "") { 44464 this.initial = parent instanceof Template ? 1 : this.min; 44465 } 44466 } 44467} 44468class Oid extends StringObject { 44469 constructor(attributes) { 44470 super(TEMPLATE_NS_ID, "oid"); 44471 this.id = attributes.id || ""; 44472 this.name = attributes.name || ""; 44473 this.use = attributes.use || ""; 44474 this.usehref = attributes.usehref || ""; 44475 } 44476} 44477class Oids extends XFAObject { 44478 constructor(attributes) { 44479 super(TEMPLATE_NS_ID, "oids", true); 44480 this.id = attributes.id || ""; 44481 this.type = getStringOption(attributes.type, ["optional", "required"]); 44482 this.use = attributes.use || ""; 44483 this.usehref = attributes.usehref || ""; 44484 this.oid = new XFAObjectArray(); 44485 } 44486} 44487class Overflow extends XFAObject { 44488 constructor(attributes) { 44489 super(TEMPLATE_NS_ID, "overflow"); 44490 this.id = attributes.id || ""; 44491 this.leader = attributes.leader || ""; 44492 this.target = attributes.target || ""; 44493 this.trailer = attributes.trailer || ""; 44494 this.use = attributes.use || ""; 44495 this.usehref = attributes.usehref || ""; 44496 } 44497 [$getExtra]() { 44498 if (!this[$extra]) { 44499 const parent = this[$getParent](); 44500 const root = this[$getTemplateRoot](); 44501 const target = root[$searchNode](this.target, parent); 44502 const leader = root[$searchNode](this.leader, parent); 44503 const trailer = root[$searchNode](this.trailer, parent); 44504 this[$extra] = { 44505 target: target?.[0] || null, 44506 leader: leader?.[0] || null, 44507 trailer: trailer?.[0] || null, 44508 addLeader: false, 44509 addTrailer: false 44510 }; 44511 } 44512 return this[$extra]; 44513 } 44514} 44515class PageArea extends XFAObject { 44516 constructor(attributes) { 44517 super(TEMPLATE_NS_ID, "pageArea", true); 44518 this.blankOrNotBlank = getStringOption(attributes.blankOrNotBlank, ["any", "blank", "notBlank"]); 44519 this.id = attributes.id || ""; 44520 this.initialNumber = getInteger({ 44521 data: attributes.initialNumber, 44522 defaultValue: 1, 44523 validate: x => true 44524 }); 44525 this.name = attributes.name || ""; 44526 this.numbered = getInteger({ 44527 data: attributes.numbered, 44528 defaultValue: 1, 44529 validate: x => true 44530 }); 44531 this.oddOrEven = getStringOption(attributes.oddOrEven, ["any", "even", "odd"]); 44532 this.pagePosition = getStringOption(attributes.pagePosition, ["any", "first", "last", "only", "rest"]); 44533 this.relevant = getRelevant(attributes.relevant); 44534 this.use = attributes.use || ""; 44535 this.usehref = attributes.usehref || ""; 44536 this.desc = null; 44537 this.extras = null; 44538 this.medium = null; 44539 this.occur = null; 44540 this.area = new XFAObjectArray(); 44541 this.contentArea = new XFAObjectArray(); 44542 this.draw = new XFAObjectArray(); 44543 this.exclGroup = new XFAObjectArray(); 44544 this.field = new XFAObjectArray(); 44545 this.subform = new XFAObjectArray(); 44546 } 44547 [$isUsable]() { 44548 if (!this[$extra]) { 44549 this[$extra] = { 44550 numberOfUse: 0 44551 }; 44552 return true; 44553 } 44554 return !this.occur || this.occur.max === -1 || this[$extra].numberOfUse < this.occur.max; 44555 } 44556 [$cleanPage]() { 44557 delete this[$extra]; 44558 } 44559 [$getNextPage]() { 44560 this[$extra] ||= { 44561 numberOfUse: 0 44562 }; 44563 const parent = this[$getParent](); 44564 if (parent.relation === "orderedOccurrence") { 44565 if (this[$isUsable]()) { 44566 this[$extra].numberOfUse += 1; 44567 return this; 44568 } 44569 } 44570 return parent[$getNextPage](); 44571 } 44572 [$getAvailableSpace]() { 44573 return this[$extra].space || { 44574 width: 0, 44575 height: 0 44576 }; 44577 } 44578 [$toHTML]() { 44579 this[$extra] ||= { 44580 numberOfUse: 1 44581 }; 44582 const children = []; 44583 this[$extra].children = children; 44584 const style = Object.create(null); 44585 if (this.medium && this.medium.short && this.medium.long) { 44586 style.width = measureToString(this.medium.short); 44587 style.height = measureToString(this.medium.long); 44588 this[$extra].space = { 44589 width: this.medium.short, 44590 height: this.medium.long 44591 }; 44592 if (this.medium.orientation === "landscape") { 44593 const x = style.width; 44594 style.width = style.height; 44595 style.height = x; 44596 this[$extra].space = { 44597 width: this.medium.long, 44598 height: this.medium.short 44599 }; 44600 } 44601 } else { 44602 warn("XFA - No medium specified in pageArea: please file a bug."); 44603 } 44604 this[$childrenToHTML]({ 44605 filter: new Set(["area", "draw", "field", "subform"]), 44606 include: true 44607 }); 44608 this[$childrenToHTML]({ 44609 filter: new Set(["contentArea"]), 44610 include: true 44611 }); 44612 return HTMLResult.success({ 44613 name: "div", 44614 children, 44615 attributes: { 44616 class: ["xfaPage"], 44617 id: this[$uid], 44618 style, 44619 xfaName: this.name 44620 } 44621 }); 44622 } 44623} 44624class PageSet extends XFAObject { 44625 constructor(attributes) { 44626 super(TEMPLATE_NS_ID, "pageSet", true); 44627 this.duplexImposition = getStringOption(attributes.duplexImposition, ["longEdge", "shortEdge"]); 44628 this.id = attributes.id || ""; 44629 this.name = attributes.name || ""; 44630 this.relation = getStringOption(attributes.relation, ["orderedO
vendor: 39,839 bytes, lines 44630-45771
44630ccurrence", "duplexPaginated", "simplexPaginated"]); 44631 this.relevant = getRelevant(attributes.relevant); 44632 this.use = attributes.use || ""; 44633 this.usehref = attributes.usehref || ""; 44634 this.extras = null; 44635 this.occur = null; 44636 this.pageArea = new XFAObjectArray(); 44637 this.pageSet = new XFAObjectArray(); 44638 } 44639 [$cleanPage]() { 44640 for (const page of this.pageArea.children) { 44641 page[$cleanPage](); 44642 } 44643 for (const page of this.pageSet.children) { 44644 page[$cleanPage](); 44645 } 44646 } 44647 [$isUsable]() { 44648 return !this.occur || this.occur.max === -1 || this[$extra].numberOfUse < this.occur.max; 44649 } 44650 [$getNextPage]() { 44651 this[$extra] ||= { 44652 numberOfUse: 1, 44653 pageIndex: -1, 44654 pageSetIndex: -1 44655 }; 44656 if (this.relation === "orderedOccurrence") { 44657 if (this[$extra].pageIndex + 1 < this.pageArea.children.length) { 44658 this[$extra].pageIndex += 1; 44659 const pageArea = this.pageArea.children[this[$extra].pageIndex]; 44660 return pageArea[$getNextPage](); 44661 } 44662 if (this[$extra].pageSetIndex + 1 < this.pageSet.children.length) { 44663 this[$extra].pageSetIndex += 1; 44664 return this.pageSet.children[this[$extra].pageSetIndex][$getNextPage](); 44665 } 44666 if (this[$isUsable]()) { 44667 this[$extra].numberOfUse += 1; 44668 this[$extra].pageIndex = -1; 44669 this[$extra].pageSetIndex = -1; 44670 return this[$getNextPage](); 44671 } 44672 const parent = this[$getParent](); 44673 if (parent instanceof PageSet) { 44674 return parent[$getNextPage](); 44675 } 44676 this[$cleanPage](); 44677 return this[$getNextPage](); 44678 } 44679 const pageNumber = this[$getTemplateRoot]()[$extra].pageNumber; 44680 const parity = pageNumber % 2 === 0 ? "even" : "odd"; 44681 const position = pageNumber === 0 ? "first" : "rest"; 44682 let page = this.pageArea.children.find(p => p.oddOrEven === parity && p.pagePosition === position); 44683 if (page) { 44684 return page; 44685 } 44686 page = this.pageArea.children.find(p => p.oddOrEven === "any" && p.pagePosition === position); 44687 if (page) { 44688 return page; 44689 } 44690 page = this.pageArea.children.find(p => p.oddOrEven === "any" && p.pagePosition === "any"); 44691 if (page) { 44692 return page; 44693 } 44694 return this.pageArea.children[0]; 44695 } 44696} 44697class Para extends XFAObject { 44698 constructor(attributes) { 44699 super(TEMPLATE_NS_ID, "para", true); 44700 this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]); 44701 this.id = attributes.id || ""; 44702 this.lineHeight = attributes.lineHeight ? getMeasurement(attributes.lineHeight, "0pt") : ""; 44703 this.marginLeft = attributes.marginLeft ? getMeasurement(attributes.marginLeft, "0pt") : ""; 44704 this.marginRight = attributes.marginRight ? getMeasurement(attributes.marginRight, "0pt") : ""; 44705 this.orphans = getInteger({ 44706 data: attributes.orphans, 44707 defaultValue: 0, 44708 validate: x => x >= 0 44709 }); 44710 this.preserve = attributes.preserve || ""; 44711 this.radixOffset = attributes.radixOffset ? getMeasurement(attributes.radixOffset, "0pt") : ""; 44712 this.spaceAbove = attributes.spaceAbove ? getMeasurement(attributes.spaceAbove, "0pt") : ""; 44713 this.spaceBelow = attributes.spaceBelow ? getMeasurement(attributes.spaceBelow, "0pt") : ""; 44714 this.tabDefault = attributes.tabDefault ? getMeasurement(this.tabDefault) : ""; 44715 this.tabStops = (attributes.tabStops || "").trim().split(/\s+/).map((x, i) => i % 2 === 1 ? getMeasurement(x) : x); 44716 this.textIndent = attributes.textIndent ? getMeasurement(attributes.textIndent, "0pt") : ""; 44717 this.use = attributes.use || ""; 44718 this.usehref = attributes.usehref || ""; 44719 this.vAlign = getStringOption(attributes.vAlign, ["top", "bottom", "middle"]); 44720 this.widows = getInteger({ 44721 data: attributes.widows, 44722 defaultValue: 0, 44723 validate: x => x >= 0 44724 }); 44725 this.hyphenation = null; 44726 } 44727 [$toStyle]() { 44728 const style = toStyle(this, "hAlign"); 44729 if (this.marginLeft !== "") { 44730 style.paddingLeft = measureToString(this.marginLeft); 44731 } 44732 if (this.marginRight !== "") { 44733 style.paddingRight = measureToString(this.marginRight); 44734 } 44735 if (this.spaceAbove !== "") { 44736 style.paddingTop = measureToString(this.spaceAbove); 44737 } 44738 if (this.spaceBelow !== "") { 44739 style.paddingBottom = measureToString(this.spaceBelow); 44740 } 44741 if (this.textIndent !== "") { 44742 style.textIndent = measureToString(this.textIndent); 44743 fixTextIndent(style); 44744 } 44745 if (this.lineHeight > 0) { 44746 style.lineHeight = measureToString(this.lineHeight); 44747 } 44748 if (this.tabDefault !== "") { 44749 style.tabSize = measureToString(this.tabDefault); 44750 } 44751 if (this.tabStops.length > 0) {} 44752 if (this.hyphenatation) { 44753 Object.assign(style, this.hyphenatation[$toStyle]()); 44754 } 44755 return style; 44756 } 44757} 44758class PasswordEdit extends XFAObject { 44759 constructor(attributes) { 44760 super(TEMPLATE_NS_ID, "passwordEdit", true); 44761 this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]); 44762 this.id = attributes.id || ""; 44763 this.passwordChar = attributes.passwordChar || "*"; 44764 this.use = attributes.use || ""; 44765 this.usehref = attributes.usehref || ""; 44766 this.border = null; 44767 this.extras = null; 44768 this.margin = null; 44769 } 44770} 44771class template_Pattern extends XFAObject { 44772 constructor(attributes) { 44773 super(TEMPLATE_NS_ID, "pattern", true); 44774 this.id = attributes.id || ""; 44775 this.type = getStringOption(attributes.type, ["crossHatch", "crossDiagonal", "diagonalLeft", "diagonalRight", "horizontal", "vertical"]); 44776 this.use = attributes.use || ""; 44777 this.usehref = attributes.usehref || ""; 44778 this.color = null; 44779 this.extras = null; 44780 } 44781 [$toStyle](startColor) { 44782 startColor = startColor ? startColor[$toStyle]() : "#FFFFFF"; 44783 const endColor = this.color ? this.color[$toStyle]() : "#000000"; 44784 const width = 5; 44785 const cmd = "repeating-linear-gradient"; 44786 const colors = `${startColor},${startColor} ${width}px,${endColor} ${width}px,${endColor} ${2 * width}px`; 44787 switch (this.type) { 44788 case "crossHatch": 44789 return `${cmd}(to top,${colors}) ${cmd}(to right,${colors})`; 44790 case "crossDiagonal": 44791 return `${cmd}(45deg,${colors}) ${cmd}(-45deg,${colors})`; 44792 case "diagonalLeft": 44793 return `${cmd}(45deg,${colors})`; 44794 case "diagonalRight": 44795 return `${cmd}(-45deg,${colors})`; 44796 case "horizontal": 44797 return `${cmd}(to top,${colors})`; 44798 case "vertical": 44799 return `${cmd}(to right,${colors})`; 44800 } 44801 return ""; 44802 } 44803} 44804class Picture extends StringObject { 44805 constructor(attributes) { 44806 super(TEMPLATE_NS_ID, "picture"); 44807 this.id = attributes.id || ""; 44808 this.use = attributes.use || ""; 44809 this.usehref = attributes.usehref || ""; 44810 } 44811} 44812class Proto extends XFAObject { 44813 constructor(attributes) { 44814 super(TEMPLATE_NS_ID, "proto", true); 44815 this.appearanceFilter = new XFAObjectArray(); 44816 this.arc = new XFAObjectArray(); 44817 this.area = new XFAObjectArray(); 44818 this.assist = new XFAObjectArray(); 44819 this.barcode = new XFAObjectArray(); 44820 this.bindItems = new XFAObjectArray(); 44821 this.bookend = new XFAObjectArray(); 44822 this.boolean = new XFAObjectArray(); 44823 this.border = new XFAObjectArray(); 44824 this.break = new XFAObjectArray(); 44825 this.breakAfter = new XFAObjectArray(); 44826 this.breakBefore = new XFAObjectArray(); 44827 this.button = new XFAObjectArray(); 44828 this.calculate = new XFAObjectArray(); 44829 this.caption = new XFAObjectArray(); 44830 this.certificate = new XFAObjectArray(); 44831 this.certificates = new XFAObjectArray(); 44832 this.checkButton = new XFAObjectArray(); 44833 this.choiceList = new XFAObjectArray(); 44834 this.color = new XFAObjectArray(); 44835 this.comb = new XFAObjectArray(); 44836 this.connect = new XFAObjectArray(); 44837 this.contentArea = new XFAObjectArray(); 44838 this.corner = new XFAObjectArray(); 44839 this.date = new XFAObjectArray(); 44840 this.dateTime = new XFAObjectArray(); 44841 this.dateTimeEdit = new XFAObjectArray(); 44842 this.decimal = new XFAObjectArray(); 44843 this.defaultUi = new XFAObjectArray(); 44844 this.desc = new XFAObjectArray(); 44845 this.digestMethod = new XFAObjectArray(); 44846 this.digestMethods = new XFAObjectArray(); 44847 this.draw = new XFAObjectArray(); 44848 this.edge = new XFAObjectArray(); 44849 this.encoding = new XFAObjectArray(); 44850 this.encodings = new XFAObjectArray(); 44851 this.encrypt = new XFAObjectArray(); 44852 this.encryptData = new XFAObjectArray(); 44853 this.encryption = new XFAObjectArray(); 44854 this.encryptionMethod = new XFAObjectArray(); 44855 this.encryptionMethods = new XFAObjectArray(); 44856 this.event = new XFAObjectArray(); 44857 this.exData = new XFAObjectArray(); 44858 this.exObject = new XFAObjectArray(); 44859 this.exclGroup = new XFAObjectArray(); 44860 this.execute = new XFAObjectArray(); 44861 this.extras = new XFAObjectArray(); 44862 this.field = new XFAObjectArray(); 44863 this.fill = new XFAObjectArray(); 44864 this.filter = new XFAObjectArray(); 44865 this.float = new XFAObjectArray(); 44866 this.font = new XFAObjectArray(); 44867 this.format = new XFAObjectArray(); 44868 this.handler = new XFAObjectArray(); 44869 this.hyphenation = new XFAObjectArray(); 44870 this.image = new XFAObjectArray(); 44871 this.imageEdit = new XFAObjectArray(); 44872 this.integer = new XFAObjectArray(); 44873 this.issuers = new XFAObjectArray(); 44874 this.items = new XFAObjectArray(); 44875 this.keep = new XFAObjectArray(); 44876 this.keyUsage = new XFAObjectArray(); 44877 this.line = new XFAObjectArray(); 44878 this.linear = new XFAObjectArray(); 44879 this.lockDocument = new XFAObjectArray(); 44880 this.manifest = new XFAObjectArray(); 44881 this.margin = new XFAObjectArray(); 44882 this.mdp = new XFAObjectArray(); 44883 this.medium = new XFAObjectArray(); 44884 this.message = new XFAObjectArray(); 44885 this.numericEdit = new XFAObjectArray(); 44886 this.occur = new XFAObjectArray(); 44887 this.oid = new XFAObjectArray(); 44888 this.oids = new XFAObjectArray(); 44889 this.overflow = new XFAObjectArray(); 44890 this.pageArea = new XFAObjectArray(); 44891 this.pageSet = new XFAObjectArray(); 44892 this.para = new XFAObjectArray(); 44893 this.passwordEdit = new XFAObjectArray(); 44894 this.pattern = new XFAObjectArray(); 44895 this.picture = new XFAObjectArray(); 44896 this.radial = new XFAObjectArray(); 44897 this.reason = new XFAObjectArray(); 44898 this.reasons = new XFAObjectArray(); 44899 this.rectangle = new XFAObjectArray(); 44900 this.ref = new XFAObjectArray(); 44901 this.script = new XFAObjectArray(); 44902 this.setProperty = new XFAObjectArray(); 44903 this.signData = new XFAObjectArray(); 44904 this.signature = new XFAObjectArray(); 44905 this.signing = new XFAObjectArray(); 44906 this.solid = new XFAObjectArray(); 44907 this.speak = new XFAObjectArray(); 44908 this.stipple = new XFAObjectArray(); 44909 this.subform = new XFAObjectArray(); 44910 this.subformSet = new XFAObjectArray(); 44911 this.subjectDN = new XFAObjectArray(); 44912 this.subjectDNs = new XFAObjectArray(); 44913 this.submit = new XFAObjectArray(); 44914 this.text = new XFAObjectArray(); 44915 this.textEdit = new XFAObjectArray(); 44916 this.time = new XFAObjectArray(); 44917 this.timeStamp = new XFAObjectArray(); 44918 this.toolTip = new XFAObjectArray(); 44919 this.traversal = new XFAObjectArray(); 44920 this.traverse = new XFAObjectArray(); 44921 this.ui = new XFAObjectArray(); 44922 this.validate = new XFAObjectArray(); 44923 this.value = new XFAObjectArray(); 44924 this.variables = new XFAObjectArray(); 44925 } 44926} 44927class Radial extends XFAObject { 44928 constructor(attributes) { 44929 super(TEMPLATE_NS_ID, "radial", true); 44930 this.id = attributes.id || ""; 44931 this.type = getStringOption(attributes.type, ["toEdge", "toCenter"]); 44932 this.use = attributes.use || ""; 44933 this.usehref = attributes.usehref || ""; 44934 this.color = null; 44935 this.extras = null; 44936 } 44937 [$toStyle](startColor) { 44938 startColor = startColor ? startColor[$toStyle]() : "#FFFFFF"; 44939 const endColor = this.color ? this.color[$toStyle]() : "#000000"; 44940 const colors = this.type === "toEdge" ? `${startColor},${endColor}` : `${endColor},${startColor}`; 44941 return `radial-gradient(circle at center, ${colors})`; 44942 } 44943} 44944class Reason extends StringObject { 44945 constructor(attributes) { 44946 super(TEMPLATE_NS_ID, "reason"); 44947 this.id = attributes.id || ""; 44948 this.name = attributes.name || ""; 44949 this.use = attributes.use || ""; 44950 this.usehref = attributes.usehref || ""; 44951 } 44952} 44953class Reasons extends XFAObject { 44954 constructor(attributes) { 44955 super(TEMPLATE_NS_ID, "reasons", true); 44956 this.id = attributes.id || ""; 44957 this.type = getStringOption(attributes.type, ["optional", "required"]); 44958 this.use = attributes.use || ""; 44959 this.usehref = attributes.usehref || ""; 44960 this.reason = new XFAObjectArray(); 44961 } 44962} 44963class Rectangle extends XFAObject { 44964 constructor(attributes) { 44965 super(TEMPLATE_NS_ID, "rectangle", true); 44966 this.hand = getStringOption(attributes.hand, ["even", "left", "right"]); 44967 this.id = attributes.id || ""; 44968 this.use = attributes.use || ""; 44969 this.usehref = attributes.usehref || ""; 44970 this.corner = new XFAObjectArray(4); 44971 this.edge = new XFAObjectArray(4); 44972 this.fill = null; 44973 } 44974 [$toHTML]() { 44975 const edge = this.edge.children.length ? this.edge.children[0] : new Edge({}); 44976 const edgeStyle = edge[$toStyle](); 44977 const style = Object.create(null); 44978 if (this.fill?.presence === "visible") { 44979 Object.assign(style, this.fill[$toStyle]()); 44980 } else { 44981 style.fill = "transparent"; 44982 } 44983 style.strokeWidth = measureToString(edge.presence === "visible" ? edge.thickness : 0); 44984 style.stroke = edgeStyle.color; 44985 const corner = this.corner.children.length ? this.corner.children[0] : new Corner({}); 44986 const cornerStyle = corner[$toStyle](); 44987 const rect = { 44988 name: "rect", 44989 attributes: { 44990 xmlns: SVG_NS, 44991 width: "100%", 44992 height: "100%", 44993 x: 0, 44994 y: 0, 44995 rx: cornerStyle.radius, 44996 ry: cornerStyle.radius, 44997 style 44998 } 44999 }; 45000 const svg = { 45001 name: "svg", 45002 children: [rect], 45003 attributes: { 45004 xmlns: SVG_NS, 45005 style: { 45006 overflow: "visible" 45007 }, 45008 width: "100%", 45009 height: "100%" 45010 } 45011 }; 45012 const parent = this[$getParent]()[$getParent](); 45013 if (hasMargin(parent)) { 45014 return HTMLResult.success({ 45015 name: "div", 45016 attributes: { 45017 style: { 45018 display: "inline", 45019 width: "100%", 45020 height: "100%" 45021 } 45022 }, 45023 children: [svg] 45024 }); 45025 } 45026 svg.attributes.style.position = "absolute"; 45027 return HTMLResult.success(svg); 45028 } 45029} 45030class RefElement extends StringObject { 45031 constructor(attributes) { 45032 super(TEMPLATE_NS_ID, "ref"); 45033 this.id = attributes.id || ""; 45034 this.use = attributes.use || ""; 45035 this.usehref = attributes.usehref || ""; 45036 } 45037} 45038class Script extends StringObject { 45039 constructor(attributes) { 45040 super(TEMPLATE_NS_ID, "script"); 45041 this.binding = attributes.binding || ""; 45042 this.contentType = attributes.contentType || ""; 45043 this.id = attributes.id || ""; 45044 this.name = attributes.name || ""; 45045 this.runAt = getStringOption(attributes.runAt, ["client", "both", "server"]); 45046 this.use = attributes.use || ""; 45047 this.usehref = attributes.usehref || ""; 45048 } 45049} 45050class SetProperty extends XFAObject { 45051 constructor(attributes) { 45052 super(TEMPLATE_NS_ID, "setProperty"); 45053 this.connection = attributes.connection || ""; 45054 this.ref = attributes.ref || ""; 45055 this.target = attributes.target || ""; 45056 } 45057} 45058class SignData extends XFAObject { 45059 constructor(attributes) { 45060 super(TEMPLATE_NS_ID, "signData", true); 45061 this.id = attributes.id || ""; 45062 this.operation = getStringOption(attributes.operation, ["sign", "clear", "verify"]); 45063 this.ref = attributes.ref || ""; 45064 this.target = attributes.target || ""; 45065 this.use = attributes.use || ""; 45066 this.usehref = attributes.usehref || ""; 45067 this.filter = null; 45068 this.manifest = null; 45069 } 45070} 45071class Signature extends XFAObject { 45072 constructor(attributes) { 45073 super(TEMPLATE_NS_ID, "signature", true); 45074 this.id = attributes.id || ""; 45075 this.type = getStringOption(attributes.type, ["PDF1.3", "PDF1.6"]); 45076 this.use = attributes.use || ""; 45077 this.usehref = attributes.usehref || ""; 45078 this.border = null; 45079 this.extras = null; 45080 this.filter = null; 45081 this.manifest = null; 45082 this.margin = null; 45083 } 45084} 45085class Signing extends XFAObject { 45086 constructor(attributes) { 45087 super(TEMPLATE_NS_ID, "signing", true); 45088 this.id = attributes.id || ""; 45089 this.type = getStringOption(attributes.type, ["optional", "required"]); 45090 this.use = attributes.use || ""; 45091 this.usehref = attributes.usehref || ""; 45092 this.certificate = new XFAObjectArray(); 45093 } 45094} 45095class Solid extends XFAObject { 45096 constructor(attributes) { 45097 super(TEMPLATE_NS_ID, "solid", true); 45098 this.id = attributes.id || ""; 45099 this.use = attributes.use || ""; 45100 this.usehref = attributes.usehref || ""; 45101 this.extras = null; 45102 } 45103 [$toStyle](startColor) { 45104 return startColor ? startColor[$toStyle]() : "#FFFFFF"; 45105 } 45106} 45107class Speak extends StringObject { 45108 constructor(attributes) { 45109 super(TEMPLATE_NS_ID, "speak"); 45110 this.disable = getInteger({ 45111 data: attributes.disable, 45112 defaultValue: 0, 45113 validate: x => x === 1 45114 }); 45115 this.id = attributes.id || ""; 45116 this.priority = getStringOption(attributes.priority, ["custom", "caption", "name", "toolTip"]); 45117 this.rid = attributes.rid || ""; 45118 this.use = attributes.use || ""; 45119 this.usehref = attributes.usehref || ""; 45120 } 45121} 45122class Stipple extends XFAObject { 45123 constructor(attributes) { 45124 super(TEMPLATE_NS_ID, "stipple", true); 45125 this.id = attributes.id || ""; 45126 this.rate = getInteger({ 45127 data: attributes.rate, 45128 defaultValue: 50, 45129 validate: x => x >= 0 && x <= 100 45130 }); 45131 this.use = attributes.use || ""; 45132 this.usehref = attributes.usehref || ""; 45133 this.color = null; 45134 this.extras = null; 45135 } 45136 [$toStyle](bgColor) { 45137 const alpha = this.rate / 100; 45138 return Util.makeHexColor(Math.round(bgColor.value.r * (1 - alpha) + this.value.r * alpha), Math.round(bgColor.value.g * (1 - alpha) + this.value.g * alpha), Math.round(bgColor.value.b * (1 - alpha) + this.value.b * alpha)); 45139 } 45140} 45141class Subform extends XFAObject { 45142 constructor(attributes) { 45143 super(TEMPLATE_NS_ID, "subform", true); 45144 this.access = getStringOption(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]); 45145 this.allowMacro = getInteger({ 45146 data: attributes.allowMacro, 45147 defaultValue: 0, 45148 validate: x => x === 1 45149 }); 45150 this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]); 45151 this.colSpan = getInteger({ 45152 data: attributes.colSpan, 45153 defaultValue: 1, 45154 validate: n => n >= 1 || n === -1 45155 }); 45156 this.columnWidths = (attributes.columnWidths || "").trim().split(/\s+/).map(x => x === "-1" ? -1 : getMeasurement(x)); 45157 this.h = attributes.h ? getMeasurement(attributes.h) : ""; 45158 this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]); 45159 this.id = attributes.id || ""; 45160 this.layout = getStringOption(attributes.layout, ["position", "lr-tb", "rl-row", "rl-tb", "row", "table", "tb"]); 45161 this.locale = attributes.locale || ""; 45162 this.maxH = getMeasurement(attributes.maxH, "0pt"); 45163 this.maxW = getMeasurement(attributes.maxW, "0pt"); 45164 this.mergeMode = getStringOption(attributes.mergeMode, ["consumeData", "matchTemplate"]); 45165 this.minH = getMeasurement(attributes.minH, "0pt"); 45166 this.minW = getMeasurement(attributes.minW, "0pt"); 45167 this.name = attributes.name || ""; 45168 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); 45169 this.relevant = getRelevant(attributes.relevant); 45170 this.restoreState = getStringOption(attributes.restoreState, ["manual", "auto"]); 45171 this.scope = getStringOption(attributes.scope, ["name", "none"]); 45172 this.use = attributes.use || ""; 45173 this.usehref = attributes.usehref || ""; 45174 this.w = attributes.w ? getMeasurement(attributes.w) : ""; 45175 this.x = getMeasurement(attributes.x, "0pt"); 45176 this.y = getMeasurement(attributes.y, "0pt"); 45177 this.assist = null; 45178 this.bind = null; 45179 this.bookend = null; 45180 this.border = null; 45181 this.break = null; 45182 this.calculate = null; 45183 this.desc = null; 45184 this.extras = null; 45185 this.keep = null; 45186 this.margin = null; 45187 this.occur = null; 45188 this.overflow = null; 45189 this.pageSet = null; 45190 this.para = null; 45191 this.traversal = null; 45192 this.validate = null; 45193 this.variables = null; 45194 this.area = new XFAObjectArray(); 45195 this.breakAfter = new XFAObjectArray(); 45196 this.breakBefore = new XFAObjectArray(); 45197 this.connect = new XFAObjectArray(); 45198 this.draw = new XFAObjectArray(); 45199 this.event = new XFAObjectArray(); 45200 this.exObject = new XFAObjectArray(); 45201 this.exclGroup = new XFAObjectArray(); 45202 this.field = new XFAObjectArray(); 45203 this.proto = new XFAObjectArray(); 45204 this.setProperty = new XFAObjectArray(); 45205 this.subform = new XFAObjectArray(); 45206 this.subformSet = new XFAObjectArray(); 45207 } 45208 [$getSubformParent]() { 45209 const parent = this[$getParent](); 45210 if (parent instanceof SubformSet) { 45211 return parent[$getSubformParent](); 45212 } 45213 return parent; 45214 } 45215 [$isBindable]() { 45216 return true; 45217 } 45218 [$isThereMoreWidth]() { 45219 return this.layout.endsWith("-tb") && this[$extra].attempt === 0 && this[$extra].numberInLine > 0 || this[$getParent]()[$isThereMoreWidth](); 45220 } 45221 *[$getContainedChildren]() { 45222 yield* getContainedChildren(this); 45223 } 45224 [$flushHTML]() { 45225 return flushHTML(this); 45226 } 45227 [$addHTML](html, bbox) { 45228 addHTML(this, html, bbox); 45229 } 45230 [$getAvailableSpace]() { 45231 return getAvailableSpace(this); 45232 } 45233 [$isSplittable]() { 45234 const parent = this[$getSubformParent](); 45235 if (!parent[$isSplittable]()) { 45236 return false; 45237 } 45238 if (this[$extra]._isSplittable !== undefined) { 45239 return this[$extra]._isSplittable; 45240 } 45241 if (this.layout === "position" || this.layout.includes("row")) { 45242 this[$extra]._isSplittable = false; 45243 return false; 45244 } 45245 if (this.keep && this.keep.intact !== "none") { 45246 this[$extra]._isSplittable = false; 45247 return false; 45248 } 45249 if (parent.layout?.endsWith("-tb") && parent[$extra].numberInLine !== 0) { 45250 return false; 45251 } 45252 this[$extra]._isSplittable = true; 45253 return true; 45254 } 45255 [$toHTML](availableSpace) { 45256 setTabIndex(this); 45257 if (this.break) { 45258 if (this.break.after !== "auto" || this.break.afterTarget !== "") { 45259 const node = new BreakAfter({ 45260 targetType: this.break.after, 45261 target: this.break.afterTarget, 45262 startNew: this.break.startNew.toString() 45263 }); 45264 node[$globalData] = this[$globalData]; 45265 this[$appendChild](node); 45266 this.breakAfter.push(node); 45267 } 45268 if (this.break.before !== "auto" || this.break.beforeTarget !== "") { 45269 const node = new BreakBefore({ 45270 targetType: this.break.before, 45271 target: this.break.beforeTarget, 45272 startNew: this.break.startNew.toString() 45273 }); 45274 node[$globalData] = this[$globalData]; 45275 this[$appendChild](node); 45276 this.breakBefore.push(node); 45277 } 45278 if (this.break.overflowTarget !== "") { 45279 const node = new Overflow({ 45280 target: this.break.overflowTarget, 45281 leader: this.break.overflowLeader, 45282 trailer: this.break.overflowTrailer 45283 }); 45284 node[$globalData] = this[$globalData]; 45285 this[$appendChild](node); 45286 this.overflow.push(node); 45287 } 45288 this[$removeChild](this.break); 45289 this.break = null; 45290 } 45291 if (this.presence === "hidden" || this.presence === "inactive") { 45292 return HTMLResult.EMPTY; 45293 } 45294 if (this.breakBefore.children.length > 1 || this.breakAfter.children.length > 1) { 45295 warn("XFA - Several breakBefore or breakAfter in subforms: please file a bug."); 45296 } 45297 if (this.breakBefore.children.length >= 1) { 45298 const breakBefore = this.breakBefore.children[0]; 45299 if (handleBreak(breakBefore)) { 45300 return HTMLResult.breakNode(breakBefore); 45301 } 45302 } 45303 if (this[$extra]?.afterBreakAfter) { 45304 return HTMLResult.EMPTY; 45305 } 45306 fixDimensions(this); 45307 const children = []; 45308 const attributes = { 45309 id: this[$uid], 45310 class: [] 45311 }; 45312 setAccess(this, attributes.class); 45313 this[$extra] ||= Object.create(null); 45314 Object.assign(this[$extra], { 45315 children, 45316 line: null, 45317 attributes, 45318 attempt: 0, 45319 numberInLine: 0, 45320 availableSpace: { 45321 width: Math.min(this.w || Infinity, availableSpace.width), 45322 height: Math.min(this.h || Infinity, availableSpace.height) 45323 }, 45324 width: 0, 45325 height: 0, 45326 prevHeight: 0, 45327 currentWidth: 0 45328 }); 45329 const root = this[$getTemplateRoot](); 45330 const savedNoLayoutFailure = root[$extra].noLayoutFailure; 45331 const isSplittable = this[$isSplittable](); 45332 if (!isSplittable) { 45333 setFirstUnsplittable(this); 45334 } 45335 if (!checkDimensions(this, availableSpace)) { 45336 return HTMLResult.FAILURE; 45337 } 45338 const filter = new Set(["area", "draw", "exclGroup", "field", "subform", "subformSet"]); 45339 if (this.layout.includes("row")) { 45340 const columnWidths = this[$getSubformParent]().columnWidths; 45341 if (Array.isArray(columnWidths) && columnWidths.length > 0) { 45342 this[$extra].columnWidths = columnWidths; 45343 this[$extra].currentColumn = 0; 45344 } 45345 } 45346 const style = toStyle(this, "anchorType", "dimensions", "position", "presence", "border", "margin", "hAlign"); 45347 const classNames = ["xfaSubform"]; 45348 const cl = layoutClass(this); 45349 if (cl) { 45350 classNames.push(cl); 45351 } 45352 attributes.style = style; 45353 attributes.class = classNames; 45354 if (this.name) { 45355 attributes.xfaName = this.name; 45356 } 45357 if (this.overflow) { 45358 const overflowExtra = this.overflow[$getExtra](); 45359 if (overflowExtra.addLeader) { 45360 overflowExtra.addLeader = false; 45361 handleOverflow(this, overflowExtra.leader, availableSpace); 45362 } 45363 } 45364 this[$pushPara](); 45365 const isLrTb = this.layout === "lr-tb" || this.layout === "rl-tb"; 45366 const maxRun = isLrTb ? MAX_ATTEMPTS_FOR_LRTB_LAYOUT : 1; 45367 for (; this[$extra].attempt < maxRun; this[$extra].attempt++) { 45368 if (isLrTb && this[$extra].attempt === MAX_ATTEMPTS_FOR_LRTB_LAYOUT - 1) { 45369 this[$extra].numberInLine = 0; 45370 } 45371 const result = this[$childrenToHTML]({ 45372 filter, 45373 include: true 45374 }); 45375 if (result.success) { 45376 break; 45377 } 45378 if (result.isBreak()) { 45379 this[$popPara](); 45380 return result; 45381 } 45382 if (isLrTb && this[$extra].attempt === 0 && this[$extra].numberInLine === 0 && !root[$extra].noLayoutFailure) { 45383 this[$extra].attempt = maxRun; 45384 break; 45385 } 45386 } 45387 this[$popPara](); 45388 if (!isSplittable) { 45389 unsetFirstUnsplittable(this); 45390 } 45391 root[$extra].noLayoutFailure = savedNoLayoutFailure; 45392 if (this[$extra].attempt === maxRun) { 45393 if (this.overflow) { 45394 this[$getTemplateRoot]()[$extra].overflowNode = this.overflow; 45395 } 45396 if (!isSplittable) { 45397 delete this[$extra]; 45398 } 45399 return HTMLResult.FAILURE; 45400 } 45401 if (this.overflow) { 45402 const overflowExtra = this.overflow[$getExtra](); 45403 if (overflowExtra.addTrailer) { 45404 overflowExtra.addTrailer = false; 45405 handleOverflow(this, overflowExtra.trailer, availableSpace); 45406 } 45407 } 45408 let marginH = 0; 45409 let marginV = 0; 45410 if (this.margin) { 45411 marginH = this.margin.leftInset + this.margin.rightInset; 45412 marginV = this.margin.topInset + this.margin.bottomInset; 45413 } 45414 const width = Math.max(this[$extra].width + marginH, this.w || 0); 45415 const height = Math.max(this[$extra].height + marginV, this.h || 0); 45416 const bbox = [this.x, this.y, width, height]; 45417 if (this.w === "") { 45418 style.width = measureToString(width); 45419 } 45420 if (this.h === "") { 45421 style.height = measureToString(height); 45422 } 45423 if ((style.width === "0px" || style.height === "0px") && children.length === 0) { 45424 return HTMLResult.EMPTY; 45425 } 45426 const html = { 45427 name: "div", 45428 attributes, 45429 children 45430 }; 45431 applyAssist(this, attributes); 45432 const result = HTMLResult.success(createWrapper(this, html), bbox); 45433 if (this.breakAfter.children.length >= 1) { 45434 const breakAfter = this.breakAfter.children[0]; 45435 if (handleBreak(breakAfter)) { 45436 this[$extra].afterBreakAfter = result; 45437 return HTMLResult.breakNode(breakAfter); 45438 } 45439 } 45440 delete this[$extra]; 45441 return result; 45442 } 45443} 45444class SubformSet extends XFAObject { 45445 constructor(attributes) { 45446 super(TEMPLATE_NS_ID, "subformSet", true); 45447 this.id = attributes.id || ""; 45448 this.name = attributes.name || ""; 45449 this.relation = getStringOption(attributes.relation, ["ordered", "choice", "unordered"]); 45450 this.relevant = getRelevant(attributes.relevant); 45451 this.use = attributes.use || ""; 45452 this.usehref = attributes.usehref || ""; 45453 this.bookend = null; 45454 this.break = null; 45455 this.desc = null; 45456 this.extras = null; 45457 this.occur = null; 45458 this.overflow = null; 45459 this.breakAfter = new XFAObjectArray(); 45460 this.breakBefore = new XFAObjectArray(); 45461 this.subform = new XFAObjectArray(); 45462 this.subformSet = new XFAObjectArray(); 45463 } 45464 *[$getContainedChildren]() { 45465 yield* getContainedChildren(this); 45466 } 45467 [$getSubformParent]() { 45468 let parent = this[$getParent](); 45469 while (!(parent instanceof Subform)) { 45470 parent = parent[$getParent](); 45471 } 45472 return parent; 45473 } 45474 [$isBindable]() { 45475 return true; 45476 } 45477} 45478class SubjectDN extends ContentObject { 45479 constructor(attributes) { 45480 super(TEMPLATE_NS_ID, "subjectDN"); 45481 this.delimiter = attributes.delimiter || ","; 45482 this.id = attributes.id || ""; 45483 this.name = attributes.name || ""; 45484 this.use = attributes.use || ""; 45485 this.usehref = attributes.usehref || ""; 45486 } 45487 [$finalize]() { 45488 this[$content] = new Map(this[$content].split(this.delimiter).map(kv => { 45489 kv = kv.split("=", 2); 45490 kv[0] = kv[0].trim(); 45491 return kv; 45492 })); 45493 } 45494} 45495class SubjectDNs extends XFAObject { 45496 constructor(attributes) { 45497 super(TEMPLATE_NS_ID, "subjectDNs", true); 45498 this.id = attributes.id || ""; 45499 this.type = getStringOption(attributes.type, ["optional", "required"]); 45500 this.use = attributes.use || ""; 45501 this.usehref = attributes.usehref || ""; 45502 this.subjectDN = new XFAObjectArray(); 45503 } 45504} 45505class Submit extends XFAObject { 45506 constructor(attributes) { 45507 super(TEMPLATE_NS_ID, "submit", true); 45508 this.embedPDF = getInteger({ 45509 data: attributes.embedPDF, 45510 defaultValue: 0, 45511 validate: x => x === 1 45512 }); 45513 this.format = getStringOption(attributes.format, ["xdp", "formdata", "pdf", "urlencoded", "xfd", "xml"]); 45514 this.id = attributes.id || ""; 45515 this.target = attributes.target || ""; 45516 this.textEncoding = getKeyword({ 45517 data: attributes.textEncoding ? attributes.textEncoding.toLowerCase() : "", 45518 defaultValue: "", 45519 validate: k => ["utf-8", "big-five", "fontspecific", "gbk", "gb-18030", "gb-2312", "ksc-5601", "none", "shift-jis", "ucs-2", "utf-16"].includes(k) || k.match(/iso-8859-\d{2}/) 45520 }); 45521 this.use = attributes.use || ""; 45522 this.usehref = attributes.usehref || ""; 45523 this.xdpContent = attributes.xdpContent || ""; 45524 this.encrypt = null; 45525 this.encryptData = new XFAObjectArray(); 45526 this.signData = new XFAObjectArray(); 45527 } 45528} 45529class Template extends XFAObject { 45530 constructor(attributes) { 45531 super(TEMPLATE_NS_ID, "template", true); 45532 this.baseProfile = getStringOption(attributes.baseProfile, ["full", "interactiveForms"]); 45533 this.extras = null; 45534 this.subform = new XFAObjectArray(); 45535 } 45536 [$finalize]() { 45537 if (this.subform.children.length === 0) { 45538 warn("XFA - No subforms in template node."); 45539 } 45540 if (this.subform.children.length >= 2) { 45541 warn("XFA - Several subforms in template node: please file a bug."); 45542 } 45543 this[$tabIndex] = DEFAULT_TAB_INDEX; 45544 } 45545 [$isSplittable]() { 45546 return true; 45547 } 45548 [$searchNode](expr, container) { 45549 if (expr.startsWith("#")) { 45550 return [this[$ids].get(expr.slice(1))]; 45551 } 45552 return searchNode(this, container, expr, true, true); 45553 } 45554 *[$toPages]() { 45555 if (!this.subform.children.length) { 45556 return HTMLResult.success({ 45557 name: "div", 45558 children: [] 45559 }); 45560 } 45561 this[$extra] = { 45562 overflowNode: null, 45563 firstUnsplittable: null, 45564 currentContentArea: null, 45565 currentPageArea: null, 45566 noLayoutFailure: false, 45567 pageNumber: 1, 45568 pagePosition: "first", 45569 oddOrEven: "odd", 45570 blankOrNotBlank: "nonBlank", 45571 paraStack: [] 45572 }; 45573 const root = this.subform.children[0]; 45574 root.pageSet[$cleanPage](); 45575 const pageAreas = root.pageSet.pageArea.children; 45576 const mainHtml = { 45577 name: "div", 45578 children: [] 45579 }; 45580 let pageArea = null; 45581 let breakBefore = null; 45582 let breakBeforeTarget = null; 45583 if (root.breakBefore.children.length >= 1) { 45584 breakBefore = root.breakBefore.children[0]; 45585 breakBeforeTarget = breakBefore.target; 45586 } else if (root.subform.children.length >= 1 && root.subform.children[0].breakBefore.children.length >= 1) { 45587 breakBefore = root.subform.children[0].breakBefore.children[0]; 45588 breakBeforeTarget = breakBefore.target; 45589 } else if (root.break?.beforeTarget) { 45590 breakBefore = root.break; 45591 breakBeforeTarget = breakBefore.beforeTarget; 45592 } else if (root.subform.children.length >= 1 && root.subform.children[0].break?.beforeTarget) { 45593 breakBefore = root.subform.children[0].break; 45594 breakBeforeTarget = breakBefore.beforeTarget; 45595 } 45596 if (breakBefore) { 45597 const target = this[$searchNode](breakBeforeTarget, breakBefore[$getParent]()); 45598 if (target instanceof PageArea) { 45599 pageArea = target; 45600 breakBefore[$extra] = {}; 45601 } 45602 } 45603 pageArea ||= pageAreas[0]; 45604 pageArea[$extra] = { 45605 numberOfUse: 1 45606 }; 45607 const pageAreaParent = pageArea[$getParent](); 45608 pageAreaParent[$extra] = { 45609 numberOfUse: 1, 45610 pageIndex: pageAreaParent.pageArea.children.indexOf(pageArea), 45611 pageSetIndex: 0 45612 }; 45613 let targetPageArea; 45614 let leader = null; 45615 let trailer = null; 45616 let hasSomething = true; 45617 let hasSomethingCounter = 0; 45618 let startIndex = 0; 45619 while (true) { 45620 if (!hasSomething) { 45621 mainHtml.children.pop(); 45622 if (++hasSomethingCounter === MAX_EMPTY_PAGES) { 45623 warn("XFA - Something goes wrong: please file a bug."); 45624 return mainHtml; 45625 } 45626 } else { 45627 hasSomethingCounter = 0; 45628 } 45629 targetPageArea = null; 45630 this[$extra].currentPageArea = pageArea; 45631 const page = pageArea[$toHTML]().html; 45632 mainHtml.children.push(page); 45633 if (leader) { 45634 this[$extra].noLayoutFailure = true; 45635 page.children.push(leader[$toHTML](pageArea[$extra].space).html); 45636 leader = null; 45637 } 45638 if (trailer) { 45639 this[$extra].noLayoutFailure = true; 45640 page.children.push(trailer[$toHTML](pageArea[$extra].space).html); 45641 trailer = null; 45642 } 45643 const contentAreas = pageArea.contentArea.children; 45644 const htmlContentAreas = page.children.filter(node => node.attributes.class.includes("xfaContentarea")); 45645 hasSomething = false; 45646 this[$extra].firstUnsplittable = null; 45647 this[$extra].noLayoutFailure = false; 45648 const flush = index => { 45649 const html = root[$flushHTML](); 45650 if (html) { 45651 hasSomething ||= html.children?.length > 0; 45652 htmlContentAreas[index].children.push(html); 45653 } 45654 }; 45655 for (let i = startIndex, ii = contentAreas.length; i < ii; i++) { 45656 const contentArea = this[$extra].currentContentArea = contentAreas[i]; 45657 const space = { 45658 width: contentArea.w, 45659 height: contentArea.h 45660 }; 45661 startIndex = 0; 45662 if (leader) { 45663 htmlContentAreas[i].children.push(leader[$toHTML](space).html); 45664 leader = null; 45665 } 45666 if (trailer) { 45667 htmlContentAreas[i].children.push(trailer[$toHTML](space).html); 45668 trailer = null; 45669 } 45670 const html = root[$toHTML](space); 45671 if (html.success) { 45672 if (html.html) { 45673 hasSomething ||= html.html.children?.length > 0; 45674 htmlContentAreas[i].children.push(html.html); 45675 } else if (!hasSomething && mainHtml.children.length > 1) { 45676 mainHtml.children.pop(); 45677 } 45678 return mainHtml; 45679 } 45680 if (html.isBreak()) { 45681 const node = html.breakNode; 45682 flush(i); 45683 if (node.targetType === "auto") { 45684 continue; 45685 } 45686 if (node.leader) { 45687 leader = this[$searchNode](node.leader, node[$getParent]()); 45688 leader = leader ? leader[0] : null; 45689 } 45690 if (node.trailer) { 45691 trailer = this[$searchNode](node.trailer, node[$getParent]()); 45692 trailer = trailer ? trailer[0] : null; 45693 } 45694 if (node.targetType === "pageArea") { 45695 targetPageArea = node[$extra].target; 45696 i = Infinity; 45697 } else if (!node[$extra].target) { 45698 i = node[$extra].index; 45699 } else { 45700 targetPageArea = node[$extra].target; 45701 startIndex = node[$extra].index + 1; 45702 i = Infinity; 45703 } 45704 continue; 45705 } 45706 if (this[$extra].overflowNode) { 45707 const node = this[$extra].overflowNode; 45708 this[$extra].overflowNode = null; 45709 const overflowExtra = node[$getExtra](); 45710 const target = overflowExtra.target; 45711 overflowExtra.addLeader = overflowExtra.leader !== null; 45712 overflowExtra.addTrailer = overflowExtra.trailer !== null; 45713 flush(i); 45714 const currentIndex = i; 45715 i = Infinity; 45716 if (target instanceof PageArea) { 45717 targetPageArea = target; 45718 } else if (target instanceof ContentArea) { 45719 const index = contentAreas.indexOf(target); 45720 if (index !== -1) { 45721 if (index > currentIndex) { 45722 i = index - 1; 45723 } else { 45724 startIndex = index; 45725 } 45726 } else { 45727 targetPageArea = target[$getParent](); 45728 startIndex = targetPageArea.contentArea.children.indexOf(target); 45729 } 45730 } 45731 continue; 45732 } 45733 flush(i); 45734 } 45735 this[$extra].pageNumber += 1; 45736 if (targetPageArea) { 45737 if (targetPageArea[$isUsable]()) { 45738 targetPageArea[$extra].numberOfUse += 1; 45739 } else { 45740 targetPageArea = null; 45741 } 45742 } 45743 pageArea = targetPageArea || pageArea[$getNextPage](); 45744 yield null; 45745 } 45746 } 45747} 45748class Text extends ContentObject { 45749 constructor(attributes) { 45750 super(TEMPLATE_NS_ID, "text"); 45751 this.id = attributes.id || ""; 45752 this.maxChars = getInteger({ 45753 data: attributes.maxChars, 45754 defaultValue: 0, 45755 validate: x => x >= 0 45756 }); 45757 this.name = attributes.name || ""; 45758 this.rid = attributes.rid || ""; 45759 this.use = attributes.use || ""; 45760 this.usehref = attributes.usehref || ""; 45761 } 45762 [$acceptWhitespace]() { 45763 return true; 45764 } 45765 [$onChild](child) { 45766 if (child[$namespaceId] === NamespaceIds.xhtml.id) { 45767 this[$content] = child; 45768 return true; 45769 } 45770 warn(`XFA - Invalid content in Text: ${child[$nodeName]}.`); 45771 return false;
vendor: 25,164 bytes, lines 45772-46726
45772 } 45773 [$onText](str) { 45774 if (this[$content] instanceof XFAObject) { 45775 return; 45776 } 45777 super[$onText](str); 45778 } 45779 [$finalize]() { 45780 if (typeof this[$content] === "string") { 45781 this[$content] = this[$content].replaceAll("\r\n", "\n"); 45782 } 45783 } 45784 [$getExtra]() { 45785 if (typeof this[$content] === "string") { 45786 return this[$content].split(/[\u2029\u2028\n]/).filter(line => !!line).join("\n"); 45787 } 45788 return this[$content][$text](); 45789 } 45790 [$toHTML](availableSpace) { 45791 if (typeof this[$content] === "string") { 45792 const html = valueToHtml(this[$content]).html; 45793 if (this[$content].includes("\u2029")) { 45794 html.name = "div"; 45795 html.children = []; 45796 this[$content].split("\u2029").map(para => para.split(/[\u2028\n]/).flatMap(line => [{ 45797 name: "span", 45798 value: line 45799 }, { 45800 name: "br" 45801 }])).forEach(lines => { 45802 html.children.push({ 45803 name: "p", 45804 children: lines 45805 }); 45806 }); 45807 } else if (/[\u2028\n]/.test(this[$content])) { 45808 html.name = "div"; 45809 html.children = []; 45810 this[$content].split(/[\u2028\n]/).forEach(line => { 45811 html.children.push({ 45812 name: "span", 45813 value: line 45814 }, { 45815 name: "br" 45816 }); 45817 }); 45818 } 45819 return HTMLResult.success(html); 45820 } 45821 return this[$content][$toHTML](availableSpace); 45822 } 45823} 45824class TextEdit extends XFAObject { 45825 constructor(attributes) { 45826 super(TEMPLATE_NS_ID, "textEdit", true); 45827 this.allowRichText = getInteger({ 45828 data: attributes.allowRichText, 45829 defaultValue: 0, 45830 validate: x => x === 1 45831 }); 45832 this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]); 45833 this.id = attributes.id || ""; 45834 this.multiLine = getInteger({ 45835 data: attributes.multiLine, 45836 defaultValue: "", 45837 validate: x => x === 0 || x === 1 45838 }); 45839 this.use = attributes.use || ""; 45840 this.usehref = attributes.usehref || ""; 45841 this.vScrollPolicy = getStringOption(attributes.vScrollPolicy, ["auto", "off", "on"]); 45842 this.border = null; 45843 this.comb = null; 45844 this.extras = null; 45845 this.margin = null; 45846 } 45847 [$toHTML](availableSpace) { 45848 const style = toStyle(this, "border", "font", "margin"); 45849 let html; 45850 const field = this[$getParent]()[$getParent](); 45851 if (this.multiLine === "") { 45852 this.multiLine = field instanceof Draw ? 1 : 0; 45853 } 45854 if (this.multiLine === 1) { 45855 html = { 45856 name: "textarea", 45857 attributes: { 45858 dataId: field[$data]?.[$uid] || field[$uid], 45859 fieldId: field[$uid], 45860 class: ["xfaTextfield"], 45861 style, 45862 "aria-label": ariaLabel(field), 45863 "aria-required": false 45864 } 45865 }; 45866 } else { 45867 html = { 45868 name: "input", 45869 attributes: { 45870 type: "text", 45871 dataId: field[$data]?.[$uid] || field[$uid], 45872 fieldId: field[$uid], 45873 class: ["xfaTextfield"], 45874 style, 45875 "aria-label": ariaLabel(field), 45876 "aria-required": false 45877 } 45878 }; 45879 } 45880 if (isRequired(field)) { 45881 html.attributes["aria-required"] = true; 45882 html.attributes.required = true; 45883 } 45884 return HTMLResult.success({ 45885 name: "label", 45886 attributes: { 45887 class: ["xfaLabel"] 45888 }, 45889 children: [html] 45890 }); 45891 } 45892} 45893class Time extends StringObject { 45894 constructor(attributes) { 45895 super(TEMPLATE_NS_ID, "time"); 45896 this.id = attributes.id || ""; 45897 this.name = attributes.name || ""; 45898 this.use = attributes.use || ""; 45899 this.usehref = attributes.usehref || ""; 45900 } 45901 [$finalize]() { 45902 const date = this[$content].trim(); 45903 this[$content] = date ? new Date(date) : null; 45904 } 45905 [$toHTML](availableSpace) { 45906 return valueToHtml(this[$content] ? this[$content].toString() : ""); 45907 } 45908} 45909class TimeStamp extends XFAObject { 45910 constructor(attributes) { 45911 super(TEMPLATE_NS_ID, "timeStamp"); 45912 this.id = attributes.id || ""; 45913 this.server = attributes.server || ""; 45914 this.type = getStringOption(attributes.type, ["optional", "required"]); 45915 this.use = attributes.use || ""; 45916 this.usehref = attributes.usehref || ""; 45917 } 45918} 45919class ToolTip extends StringObject { 45920 constructor(attributes) { 45921 super(TEMPLATE_NS_ID, "toolTip"); 45922 this.id = attributes.id || ""; 45923 this.rid = attributes.rid || ""; 45924 this.use = attributes.use || ""; 45925 this.usehref = attributes.usehref || ""; 45926 } 45927} 45928class Traversal extends XFAObject { 45929 constructor(attributes) { 45930 super(TEMPLATE_NS_ID, "traversal", true); 45931 this.id = attributes.id || ""; 45932 this.use = attributes.use || ""; 45933 this.usehref = attributes.usehref || ""; 45934 this.extras = null; 45935 this.traverse = new XFAObjectArray(); 45936 } 45937} 45938class Traverse extends XFAObject { 45939 constructor(attributes) { 45940 super(TEMPLATE_NS_ID, "traverse", true); 45941 this.id = attributes.id || ""; 45942 this.operation = getStringOption(attributes.operation, ["next", "back", "down", "first", "left", "right", "up"]); 45943 this.ref = attributes.ref || ""; 45944 this.use = attributes.use || ""; 45945 this.usehref = attributes.usehref || ""; 45946 this.extras = null; 45947 this.script = null; 45948 } 45949 get name() { 45950 return this.operation; 45951 } 45952 [$isTransparent]() { 45953 return false; 45954 } 45955} 45956class Ui extends XFAObject { 45957 constructor(attributes) { 45958 super(TEMPLATE_NS_ID, "ui", true); 45959 this.id = attributes.id || ""; 45960 this.use = attributes.use || ""; 45961 this.usehref = attributes.usehref || ""; 45962 this.extras = null; 45963 this.picture = null; 45964 this.barcode = null; 45965 this.button = null; 45966 this.checkButton = null; 45967 this.choiceList = null; 45968 this.dateTimeEdit = null; 45969 this.defaultUi = null; 45970 this.imageEdit = null; 45971 this.numericEdit = null; 45972 this.passwordEdit = null; 45973 this.signature = null; 45974 this.textEdit = null; 45975 } 45976 [$getExtra]() { 45977 if (this[$extra] === undefined) { 45978 for (const name of Object.getOwnPropertyNames(this)) { 45979 if (name === "extras" || name === "picture") { 45980 continue; 45981 } 45982 const obj = this[name]; 45983 if (!(obj instanceof XFAObject)) { 45984 continue; 45985 } 45986 this[$extra] = obj; 45987 return obj; 45988 } 45989 this[$extra] = null; 45990 } 45991 return this[$extra]; 45992 } 45993 [$toHTML](availableSpace) { 45994 const obj = this[$getExtra](); 45995 if (obj) { 45996 return obj[$toHTML](availableSpace); 45997 } 45998 return HTMLResult.EMPTY; 45999 } 46000} 46001class Validate extends XFAObject { 46002 constructor(attributes) { 46003 super(TEMPLATE_NS_ID, "validate", true); 46004 this.formatTest = getStringOption(attributes.formatTest, ["warning", "disabled", "error"]); 46005 this.id = attributes.id || ""; 46006 this.nullTest = getStringOption(attributes.nullTest, ["disabled", "error", "warning"]); 46007 this.scriptTest = getStringOption(attributes.scriptTest, ["error", "disabled", "warning"]); 46008 this.use = attributes.use || ""; 46009 this.usehref = attributes.usehref || ""; 46010 this.extras = null; 46011 this.message = null; 46012 this.picture = null; 46013 this.script = null; 46014 } 46015} 46016class Value extends XFAObject { 46017 constructor(attributes) { 46018 super(TEMPLATE_NS_ID, "value", true); 46019 this.id = attributes.id || ""; 46020 this.override = getInteger({ 46021 data: attributes.override, 46022 defaultValue: 0, 46023 validate: x => x === 1 46024 }); 46025 this.relevant = getRelevant(attributes.relevant); 46026 this.use = attributes.use || ""; 46027 this.usehref = attributes.usehref || ""; 46028 this.arc = null; 46029 this.boolean = null; 46030 this.date = null; 46031 this.dateTime = null; 46032 this.decimal = null; 46033 this.exData = null; 46034 this.float = null; 46035 this.image = null; 46036 this.integer = null; 46037 this.line = null; 46038 this.rectangle = null; 46039 this.text = null; 46040 this.time = null; 46041 } 46042 [$setValue](value) { 46043 const parent = this[$getParent](); 46044 if (parent instanceof Field) { 46045 if (parent.ui?.imageEdit) { 46046 if (!this.image) { 46047 this.image = new Image({}); 46048 this[$appendChild](this.image); 46049 } 46050 this.image[$content] = value[$content]; 46051 return; 46052 } 46053 } 46054 const valueName = value[$nodeName]; 46055 if (this[valueName] !== null) { 46056 this[valueName][$content] = value[$content]; 46057 return; 46058 } 46059 for (const name of Object.getOwnPropertyNames(this)) { 46060 const obj = this[name]; 46061 if (obj instanceof XFAObject) { 46062 this[name] = null; 46063 this[$removeChild](obj); 46064 } 46065 } 46066 this[value[$nodeName]] = value; 46067 this[$appendChild](value); 46068 } 46069 [$text]() { 46070 if (this.exData) { 46071 if (typeof this.exData[$content] === "string") { 46072 return this.exData[$content].trim(); 46073 } 46074 return this.exData[$content][$text]().trim(); 46075 } 46076 for (const name of Object.getOwnPropertyNames(this)) { 46077 if (name === "image") { 46078 continue; 46079 } 46080 const obj = this[name]; 46081 if (obj instanceof XFAObject) { 46082 return (obj[$content] || "").toString().trim(); 46083 } 46084 } 46085 return null; 46086 } 46087 [$toHTML](availableSpace) { 46088 for (const name of Object.getOwnPropertyNames(this)) { 46089 const obj = this[name]; 46090 if (!(obj instanceof XFAObject)) { 46091 continue; 46092 } 46093 return obj[$toHTML](availableSpace); 46094 } 46095 return HTMLResult.EMPTY; 46096 } 46097} 46098class Variables extends XFAObject { 46099 constructor(attributes) { 46100 super(TEMPLATE_NS_ID, "variables", true); 46101 this.id = attributes.id || ""; 46102 this.use = attributes.use || ""; 46103 this.usehref = attributes.usehref || ""; 46104 this.boolean = new XFAObjectArray(); 46105 this.date = new XFAObjectArray(); 46106 this.dateTime = new XFAObjectArray(); 46107 this.decimal = new XFAObjectArray(); 46108 this.exData = new XFAObjectArray(); 46109 this.float = new XFAObjectArray(); 46110 this.image = new XFAObjectArray(); 46111 this.integer = new XFAObjectArray(); 46112 this.manifest = new XFAObjectArray(); 46113 this.script = new XFAObjectArray(); 46114 this.text = new XFAObjectArray(); 46115 this.time = new XFAObjectArray(); 46116 } 46117 [$isTransparent]() { 46118 return true; 46119 } 46120} 46121class TemplateNamespace { 46122 static [$buildXFAObject](name, attributes) { 46123 if (TemplateNamespace.hasOwnProperty(name)) { 46124 const node = TemplateNamespace[name](attributes); 46125 node[$setSetAttributes](attributes); 46126 return node; 46127 } 46128 return undefined; 46129 } 46130 static appearanceFilter(attrs) { 46131 return new AppearanceFilter(attrs); 46132 } 46133 static arc(attrs) { 46134 return new Arc(attrs); 46135 } 46136 static area(attrs) { 46137 return new Area(attrs); 46138 } 46139 static assist(attrs) { 46140 return new Assist(attrs); 46141 } 46142 static barcode(attrs) { 46143 return new Barcode(attrs); 46144 } 46145 static bind(attrs) { 46146 return new Bind(attrs); 46147 } 46148 static bindItems(attrs) { 46149 return new BindItems(attrs); 46150 } 46151 static bookend(attrs) { 46152 return new Bookend(attrs); 46153 } 46154 static boolean(attrs) { 46155 return new BooleanElement(attrs); 46156 } 46157 static border(attrs) { 46158 return new Border(attrs); 46159 } 46160 static break(attrs) { 46161 return new Break(attrs); 46162 } 46163 static breakAfter(attrs) { 46164 return new BreakAfter(attrs); 46165 } 46166 static breakBefore(attrs) { 46167 return new BreakBefore(attrs); 46168 } 46169 static button(attrs) { 46170 return new Button(attrs); 46171 } 46172 static calculate(attrs) { 46173 return new Calculate(attrs); 46174 } 46175 static caption(attrs) { 46176 return new Caption(attrs); 46177 } 46178 static certificate(attrs) { 46179 return new Certificate(attrs); 46180 } 46181 static certificates(attrs) { 46182 return new Certificates(attrs); 46183 } 46184 static checkButton(attrs) { 46185 return new CheckButton(attrs); 46186 } 46187 static choiceList(attrs) { 46188 return new ChoiceList(attrs); 46189 } 46190 static color(attrs) { 46191 return new Color(attrs); 46192 } 46193 static comb(attrs) { 46194 return new Comb(attrs); 46195 } 46196 static connect(attrs) { 46197 return new Connect(attrs); 46198 } 46199 static contentArea(attrs) { 46200 return new ContentArea(attrs); 46201 } 46202 static corner(attrs) { 46203 return new Corner(attrs); 46204 } 46205 static date(attrs) { 46206 return new DateElement(attrs); 46207 } 46208 static dateTime(attrs) { 46209 return new DateTime(attrs); 46210 } 46211 static dateTimeEdit(attrs) { 46212 return new DateTimeEdit(attrs); 46213 } 46214 static decimal(attrs) { 46215 return new Decimal(attrs); 46216 } 46217 static defaultUi(attrs) { 46218 return new DefaultUi(attrs); 46219 } 46220 static desc(attrs) { 46221 return new Desc(attrs); 46222 } 46223 static digestMethod(attrs) { 46224 return new DigestMethod(attrs); 46225 } 46226 static digestMethods(attrs) { 46227 return new DigestMethods(attrs); 46228 } 46229 static draw(attrs) { 46230 return new Draw(attrs); 46231 } 46232 static edge(attrs) { 46233 return new Edge(attrs); 46234 } 46235 static encoding(attrs) { 46236 return new Encoding(attrs); 46237 } 46238 static encodings(attrs) { 46239 return new Encodings(attrs); 46240 } 46241 static encrypt(attrs) { 46242 return new Encrypt(attrs); 46243 } 46244 static encryptData(attrs) { 46245 return new EncryptData(attrs); 46246 } 46247 static encryption(attrs) { 46248 return new Encryption(attrs); 46249 } 46250 static encryptionMethod(attrs) { 46251 return new EncryptionMethod(attrs); 46252 } 46253 static encryptionMethods(attrs) { 46254 return new EncryptionMethods(attrs); 46255 } 46256 static event(attrs) { 46257 return new Event(attrs); 46258 } 46259 static exData(attrs) { 46260 return new ExData(attrs); 46261 } 46262 static exObject(attrs) { 46263 return new ExObject(attrs); 46264 } 46265 static exclGroup(attrs) { 46266 return new ExclGroup(attrs); 46267 } 46268 static execute(attrs) { 46269 return new Execute(attrs); 46270 } 46271 static extras(attrs) { 46272 return new Extras(attrs); 46273 } 46274 static field(attrs) { 46275 return new Field(attrs); 46276 } 46277 static fill(attrs) { 46278 return new Fill(attrs); 46279 } 46280 static filter(attrs) { 46281 return new Filter(attrs); 46282 } 46283 static float(attrs) { 46284 return new Float(attrs); 46285 } 46286 static font(attrs) { 46287 return new template_Font(attrs); 46288 } 46289 static format(attrs) { 46290 return new Format(attrs); 46291 } 46292 static handler(attrs) { 46293 return new Handler(attrs); 46294 } 46295 static hyphenation(attrs) { 46296 return new Hyphenation(attrs); 46297 } 46298 static image(attrs) { 46299 return new Image(attrs); 46300 } 46301 static imageEdit(attrs) { 46302 return new ImageEdit(attrs); 46303 } 46304 static integer(attrs) { 46305 return new Integer(attrs); 46306 } 46307 static issuers(attrs) { 46308 return new Issuers(attrs); 46309 } 46310 static items(attrs) { 46311 return new Items(attrs); 46312 } 46313 static keep(attrs) { 46314 return new Keep(attrs); 46315 } 46316 static keyUsage(attrs) { 46317 return new KeyUsage(attrs); 46318 } 46319 static line(attrs) { 46320 return new Line(attrs); 46321 } 46322 static linear(attrs) { 46323 return new Linear(attrs); 46324 } 46325 static lockDocument(attrs) { 46326 return new LockDocument(attrs); 46327 } 46328 static manifest(attrs) { 46329 return new Manifest(attrs); 46330 } 46331 static margin(attrs) { 46332 return new Margin(attrs); 46333 } 46334 static mdp(attrs) { 46335 return new Mdp(attrs); 46336 } 46337 static medium(attrs) { 46338 return new Medium(attrs); 46339 } 46340 static message(attrs) { 46341 return new Message(attrs); 46342 } 46343 static numericEdit(attrs) { 46344 return new NumericEdit(attrs); 46345 } 46346 static occur(attrs) { 46347 return new Occur(attrs); 46348 } 46349 static oid(attrs) { 46350 return new Oid(attrs); 46351 } 46352 static oids(attrs) { 46353 return new Oids(attrs); 46354 } 46355 static overflow(attrs) { 46356 return new Overflow(attrs); 46357 } 46358 static pageArea(attrs) { 46359 return new PageArea(attrs); 46360 } 46361 static pageSet(attrs) { 46362 return new PageSet(attrs); 46363 } 46364 static para(attrs) { 46365 return new Para(attrs); 46366 } 46367 static passwordEdit(attrs) { 46368 return new PasswordEdit(attrs); 46369 } 46370 static pattern(attrs) { 46371 return new template_Pattern(attrs); 46372 } 46373 static picture(attrs) { 46374 return new Picture(attrs); 46375 } 46376 static proto(attrs) { 46377 return new Proto(attrs); 46378 } 46379 static radial(attrs) { 46380 return new Radial(attrs); 46381 } 46382 static reason(attrs) { 46383 return new Reason(attrs); 46384 } 46385 static reasons(attrs) { 46386 return new Reasons(attrs); 46387 } 46388 static rectangle(attrs) { 46389 return new Rectangle(attrs); 46390 } 46391 static ref(attrs) { 46392 return new RefElement(attrs); 46393 } 46394 static script(attrs) { 46395 return new Script(attrs); 46396 } 46397 static setProperty(attrs) { 46398 return new SetProperty(attrs); 46399 } 46400 static signData(attrs) { 46401 return new SignData(attrs); 46402 } 46403 static signature(attrs) { 46404 return new Signature(attrs); 46405 } 46406 static signing(attrs) { 46407 return new Signing(attrs); 46408 } 46409 static solid(attrs) { 46410 return new Solid(attrs); 46411 } 46412 static speak(attrs) { 46413 return new Speak(attrs); 46414 } 46415 static stipple(attrs) { 46416 return new Stipple(attrs); 46417 } 46418 static subform(attrs) { 46419 return new Subform(attrs); 46420 } 46421 static subformSet(attrs) { 46422 return new SubformSet(attrs); 46423 } 46424 static subjectDN(attrs) { 46425 return new SubjectDN(attrs); 46426 } 46427 static subjectDNs(attrs) { 46428 return new SubjectDNs(attrs); 46429 } 46430 static submit(attrs) { 46431 return new Submit(attrs); 46432 } 46433 static template(attrs) { 46434 return new Template(attrs); 46435 } 46436 static text(attrs) { 46437 return new Text(attrs); 46438 } 46439 static textEdit(attrs) { 46440 return new TextEdit(attrs); 46441 } 46442 static time(attrs) { 46443 return new Time(attrs); 46444 } 46445 static timeStamp(attrs) { 46446 return new TimeStamp(attrs); 46447 } 46448 static toolTip(attrs) { 46449 return new ToolTip(attrs); 46450 } 46451 static traversal(attrs) { 46452 return new Traversal(attrs); 46453 } 46454 static traverse(attrs) { 46455 return new Traverse(attrs); 46456 } 46457 static ui(attrs) { 46458 return new Ui(attrs); 46459 } 46460 static validate(attrs) { 46461 return new Validate(attrs); 46462 } 46463 static value(attrs) { 46464 return new Value(attrs); 46465 } 46466 static variables(attrs) { 46467 return new Variables(attrs); 46468 } 46469} 46470 46471;// ./src/core/xfa/bind.js 46472 46473 46474 46475 46476 46477 46478const bind_NS_DATASETS = NamespaceIds.datasets.id; 46479function createText(content) { 46480 const node = new Text({}); 46481 node[$content] = content; 46482 return node; 46483} 46484class Binder { 46485 constructor(root) { 46486 this.root = root; 46487 this.datasets = root.datasets; 46488 this.data = root.datasets?.data || new XmlObject(NamespaceIds.datasets.id, "data"); 46489 this.emptyMerge = this.data[$getChildren]().length === 0; 46490 this.root.form = this.form = root.template[$clone](); 46491 } 46492 _isConsumeData() { 46493 return !this.emptyMerge && this._mergeMode; 46494 } 46495 _isMatchTemplate() { 46496 return !this._isConsumeData(); 46497 } 46498 bind() { 46499 this._bindElement(this.form, this.data); 46500 return this.form; 46501 } 46502 getData() { 46503 return this.data; 46504 } 46505 _bindValue(formNode, data, picture) { 46506 formNode[$data] = data; 46507 if (formNode[$hasSettableValue]()) { 46508 if (data[$isDataValue]()) { 46509 const value = data[$getDataValue](); 46510 formNode[$setValue](createText(value)); 46511 } else if (formNode instanceof Field && formNode.ui?.choiceList?.open === "multiSelect") { 46512 const value = data[$getChildren]().map(child => child[$content].trim()).join("\n"); 46513 formNode[$setValue](createText(value)); 46514 } else if (this._isConsumeData()) { 46515 warn(`XFA - Nodes haven't the same type.`); 46516 } 46517 } else if (!data[$isDataValue]() || this._isMatchTemplate()) { 46518 this._bindElement(formNode, data); 46519 } else { 46520 warn(`XFA - Nodes haven't the same type.`); 46521 } 46522 } 46523 _findDataByNameToConsume(name, isValue, dataNode, global) { 46524 if (!name) { 46525 return null; 46526 } 46527 let generator, match; 46528 for (let i = 0; i < 3; i++) { 46529 generator = dataNode[$getRealChildrenByNameIt](name, false, true); 46530 while (true) { 46531 match = generator.next().value; 46532 if (!match) { 46533 break; 46534 } 46535 if (isValue === match[$isDataValue]()) { 46536 return match; 46537 } 46538 } 46539 if (dataNode[$namespaceId] === NamespaceIds.datasets.id && dataNode[$nodeName] === "data") { 46540 break; 46541 } 46542 dataNode = dataNode[$getParent](); 46543 } 46544 if (!global) { 46545 return null; 46546 } 46547 generator = this.data[$getRealChildrenByNameIt](name, true, false); 46548 match = generator.next().value; 46549 if (match) { 46550 return match; 46551 } 46552 generator = this.data[$getAttributeIt](name, true); 46553 match = generator.next().value; 46554 if (match?.[$isDataValue]()) { 46555 return match; 46556 } 46557 return null; 46558 } 46559 _setProperties(formNode, dataNode) { 46560 if (!formNode.hasOwnProperty("setProperty")) { 46561 return; 46562 } 46563 for (const { 46564 ref, 46565 target, 46566 connection 46567 } of formNode.setProperty.children) { 46568 if (connection) { 46569 continue; 46570 } 46571 if (!ref) { 46572 continue; 46573 } 46574 const nodes = searchNode(this.root, dataNode, ref, false, false); 46575 if (!nodes) { 46576 warn(`XFA - Invalid reference: ${ref}.`); 46577 continue; 46578 } 46579 const [node] = nodes; 46580 if (!node[$isDescendent](this.data)) { 46581 warn(`XFA - Invalid node: must be a data node.`); 46582 continue; 46583 } 46584 const targetNodes = searchNode(this.root, formNode, target, false, false); 46585 if (!targetNodes) { 46586 warn(`XFA - Invalid target: ${target}.`); 46587 continue; 46588 } 46589 const [targetNode] = targetNodes; 46590 if (!targetNode[$isDescendent](formNode)) { 46591 warn(`XFA - Invalid target: must be a property or subproperty.`); 46592 continue; 46593 } 46594 const targetParent = targetNode[$getParent](); 46595 if (targetNode instanceof SetProperty || targetParent instanceof SetProperty) { 46596 warn(`XFA - Invalid target: cannot be a setProperty or one of its properties.`); 46597 continue; 46598 } 46599 if (targetNode instanceof BindItems || targetParent instanceof BindItems) { 46600 warn(`XFA - Invalid target: cannot be a bindItems or one of its properties.`); 46601 continue; 46602 } 46603 const content = node[$text](); 46604 const name = targetNode[$nodeName]; 46605 if (targetNode instanceof XFAAttribute) { 46606 const attrs = Object.create(null); 46607 attrs[name] = content; 46608 const obj = Reflect.construct(Object.getPrototypeOf(targetParent).constructor, [attrs]); 46609 targetParent[name] = obj[name]; 46610 continue; 46611 } 46612 if (!targetNode.hasOwnProperty($content)) { 46613 warn(`XFA - Invalid node to use in setProperty`); 46614 continue; 46615 } 46616 targetNode[$data] = node; 46617 targetNode[$content] = content; 46618 targetNode[$finalize](); 46619 } 46620 } 46621 _bindItems(formNode, dataNode) { 46622 if (!formNode.hasOwnProperty("items") || !formNode.hasOwnProperty("bindItems") || formNode.bindItems.isEmpty()) { 46623 return; 46624 } 46625 for (const item of formNode.items.children) { 46626 formNode[$removeChild](item); 46627 } 46628 formNode.items.clear(); 46629 const labels = new Items({}); 46630 const values = new Items({}); 46631 formNode[$appendChild](labels); 46632 formNode.items.push(labels); 46633 formNode[$appendChild](values); 46634 formNode.items.push(values); 46635 for (const { 46636 ref, 46637 labelRef, 46638 valueRef, 46639 connection 46640 } of formNode.bindItems.children) { 46641 if (connection) { 46642 continue; 46643 } 46644 if (!ref) { 46645 continue; 46646 } 46647 const nodes = searchNode(this.root, dataNode, ref, false, false); 46648 if (!nodes) { 46649 warn(`XFA - Invalid reference: ${ref}.`); 46650 continue; 46651 } 46652 for (const node of nodes) { 46653 if (!node[$isDescendent](this.datasets)) { 46654 warn(`XFA - Invalid ref (${ref}): must be a datasets child.`); 46655 continue; 46656 } 46657 const labelNodes = searchNode(this.root, node, labelRef, true, false); 46658 if (!labelNodes) { 46659 warn(`XFA - Invalid label: ${labelRef}.`); 46660 continue; 46661 } 46662 const [labelNode] = labelNodes; 46663 if (!labelNode[$isDescendent](this.datasets)) { 46664 warn(`XFA - Invalid label: must be a datasets child.`); 46665 continue; 46666 } 46667 const valueNodes = searchNode(this.root, node, valueRef, true, false); 46668 if (!valueNodes) { 46669 warn(`XFA - Invalid value: ${valueRef}.`); 46670 continue; 46671 } 46672 const [valueNode] = valueNodes; 46673 if (!valueNode[$isDescendent](this.datasets)) { 46674 warn(`XFA - Invalid value: must be a datasets child.`); 46675 continue; 46676 } 46677 const label = createText(labelNode[$text]()); 46678 const value = createText(valueNode[$text]()); 46679 labels[$appendChild](label); 46680 labels.text.push(label); 46681 values[$appendChild](value); 46682 values.text.push(value); 46683 } 46684 } 46685 } 46686 _bindOccurrences(formNode, matches, picture) { 46687 let baseClone; 46688 if (matches.length > 1) { 46689 baseClone = formNode[$clone](); 46690 baseClone[$removeChild](baseClone.occur); 46691 baseClone.occur = null; 46692 } 46693 this._bindValue(formNode, matches[0], picture); 46694 this._setProperties(formNode, matches[0]); 46695 this._bindItems(formNode, matches[0]); 46696 if (matches.length === 1) { 46697 return; 46698 } 46699 const parent = formNode[$getParent](); 46700 const name = formNode[$nodeName]; 46701 const pos = parent[$indexOf](formNode); 46702 for (let i = 1, ii = matches.length; i < ii; i++) { 46703 const match = matches[i]; 46704 const clone = baseClone[$clone](); 46705 parent[name].push(clone); 46706 parent[$insertAt](pos + i, clone); 46707 this._bindValue(clone, match, picture); 46708 this._setProperties(clone, match); 46709 this._bindItems(clone, match); 46710 } 46711 } 46712 _createOccurrences(formNode) { 46713 if (!this.emptyMerge) { 46714 return; 46715 } 46716 const { 46717 occur 46718 } = formNode; 46719 if (!occur || occur.initial <= 1) { 46720 return; 46721 } 46722 const parent = formNode[$getParent](); 46723 const name = formNode[$nodeName]; 46724 if (!(parent[name] instanceof XFAObjectArray)) { 46725 return; 46726 }
vendor: 14,872 bytes, lines 46727-47244
46727 let currentNumber; 46728 if (formNode.name) { 46729 currentNumber = parent[name].children.filter(e => e.name === formNode.name).length; 46730 } else { 46731 currentNumber = parent[name].children.length; 46732 } 46733 const pos = parent[$indexOf](formNode) + 1; 46734 const ii = occur.initial - currentNumber; 46735 if (ii) { 46736 const nodeClone = formNode[$clone](); 46737 nodeClone[$removeChild](nodeClone.occur); 46738 nodeClone.occur = null; 46739 parent[name].push(nodeClone); 46740 parent[$insertAt](pos, nodeClone); 46741 for (let i = 1; i < ii; i++) { 46742 const clone = nodeClone[$clone](); 46743 parent[name].push(clone); 46744 parent[$insertAt](pos + i, clone); 46745 } 46746 } 46747 } 46748 _getOccurInfo(formNode) { 46749 const { 46750 name, 46751 occur 46752 } = formNode; 46753 if (!occur || !name) { 46754 return [1, 1]; 46755 } 46756 const max = occur.max === -1 ? Infinity : occur.max; 46757 return [occur.min, max]; 46758 } 46759 _setAndBind(formNode, dataNode) { 46760 this._setProperties(formNode, dataNode); 46761 this._bindItems(formNode, dataNode); 46762 this._bindElement(formNode, dataNode); 46763 } 46764 _bindElement(formNode, dataNode) { 46765 const uselessNodes = []; 46766 this._createOccurrences(formNode); 46767 for (const child of formNode[$getChildren]()) { 46768 if (child[$data]) { 46769 continue; 46770 } 46771 if (this._mergeMode === undefined && child[$nodeName] === "subform") { 46772 this._mergeMode = child.mergeMode === "consumeData"; 46773 const dataChildren = dataNode[$getChildren](); 46774 if (dataChildren.length > 0) { 46775 this._bindOccurrences(child, [dataChildren[0]], null); 46776 } else if (this.emptyMerge) { 46777 const nsId = dataNode[$namespaceId] === bind_NS_DATASETS ? -1 : dataNode[$namespaceId]; 46778 const dataChild = child[$data] = new XmlObject(nsId, child.name || "root"); 46779 dataNode[$appendChild](dataChild); 46780 this._bindElement(child, dataChild); 46781 } 46782 continue; 46783 } 46784 if (!child[$isBindable]()) { 46785 continue; 46786 } 46787 let global = false; 46788 let picture = null; 46789 let ref = null; 46790 let match = null; 46791 if (child.bind) { 46792 switch (child.bind.match) { 46793 case "none": 46794 this._setAndBind(child, dataNode); 46795 continue; 46796 case "global": 46797 global = true; 46798 break; 46799 case "dataRef": 46800 if (!child.bind.ref) { 46801 warn(`XFA - ref is empty in node ${child[$nodeName]}.`); 46802 this._setAndBind(child, dataNode); 46803 continue; 46804 } 46805 ref = child.bind.ref; 46806 break; 46807 default: 46808 break; 46809 } 46810 if (child.bind.picture) { 46811 picture = child.bind.picture[$content]; 46812 } 46813 } 46814 const [min, max] = this._getOccurInfo(child); 46815 if (ref) { 46816 match = searchNode(this.root, dataNode, ref, true, false); 46817 if (match === null) { 46818 match = createDataNode(this.data, dataNode, ref); 46819 if (!match) { 46820 continue; 46821 } 46822 if (this._isConsumeData()) { 46823 match[$consumed] = true; 46824 } 46825 this._setAndBind(child, match); 46826 continue; 46827 } else { 46828 if (this._isConsumeData()) { 46829 match = match.filter(node => !node[$consumed]); 46830 } 46831 if (match.length > max) { 46832 match = match.slice(0, max); 46833 } else if (match.length === 0) { 46834 match = null; 46835 } 46836 if (match && this._isConsumeData()) { 46837 match.forEach(node => { 46838 node[$consumed] = true; 46839 }); 46840 } 46841 } 46842 } else { 46843 if (!child.name) { 46844 this._setAndBind(child, dataNode); 46845 continue; 46846 } 46847 if (this._isConsumeData()) { 46848 const matches = []; 46849 while (matches.length < max) { 46850 const found = this._findDataByNameToConsume(child.name, child[$hasSettableValue](), dataNode, global); 46851 if (!found) { 46852 break; 46853 } 46854 found[$consumed] = true; 46855 matches.push(found); 46856 } 46857 match = matches.length > 0 ? matches : null; 46858 } else { 46859 match = dataNode[$getRealChildrenByNameIt](child.name, false, this.emptyMerge).next().value; 46860 if (!match) { 46861 if (min === 0) { 46862 uselessNodes.push(child); 46863 continue; 46864 } 46865 const nsId = dataNode[$namespaceId] === bind_NS_DATASETS ? -1 : dataNode[$namespaceId]; 46866 match = child[$data] = new XmlObject(nsId, child.name); 46867 if (this.emptyMerge) { 46868 match[$consumed] = true; 46869 } 46870 dataNode[$appendChild](match); 46871 this._setAndBind(child, match); 46872 continue; 46873 } 46874 if (this.emptyMerge) { 46875 match[$consumed] = true; 46876 } 46877 match = [match]; 46878 } 46879 } 46880 if (match) { 46881 this._bindOccurrences(child, match, picture); 46882 } else if (min > 0) { 46883 this._setAndBind(child, dataNode); 46884 } else { 46885 uselessNodes.push(child); 46886 } 46887 } 46888 uselessNodes.forEach(node => node[$getParent]()[$removeChild](node)); 46889 } 46890} 46891 46892;// ./src/core/xfa/data.js 46893 46894class DataHandler { 46895 constructor(root, data) { 46896 this.data = data; 46897 this.dataset = root.datasets || null; 46898 } 46899 serialize(storage) { 46900 const stack = [[-1, this.data[$getChildren]()]]; 46901 while (stack.length > 0) { 46902 const last = stack.at(-1); 46903 const [i, children] = last; 46904 if (i + 1 === children.length) { 46905 stack.pop(); 46906 continue; 46907 } 46908 const child = children[++last[0]]; 46909 const storageEntry = storage.get(child[$uid]); 46910 if (storageEntry) { 46911 child[$setValue](storageEntry); 46912 } else { 46913 const attributes = child[$getAttributes](); 46914 for (const value of attributes.values()) { 46915 const entry = storage.get(value[$uid]); 46916 if (entry) { 46917 value[$setValue](entry); 46918 break; 46919 } 46920 } 46921 } 46922 const nodes = child[$getChildren](); 46923 if (nodes.length > 0) { 46924 stack.push([-1, nodes]); 46925 } 46926 } 46927 const buf = [`<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">`]; 46928 if (this.dataset) { 46929 for (const child of this.dataset[$getChildren]()) { 46930 if (child[$nodeName] !== "data") { 46931 child[$toString](buf); 46932 } 46933 } 46934 } 46935 this.data[$toString](buf); 46936 buf.push("</xfa:datasets>"); 46937 return buf.join(""); 46938 } 46939} 46940 46941;// ./src/core/xfa/config.js 46942 46943 46944 46945 46946 46947const CONFIG_NS_ID = NamespaceIds.config.id; 46948class Acrobat extends XFAObject { 46949 constructor(attributes) { 46950 super(CONFIG_NS_ID, "acrobat", true); 46951 this.acrobat7 = null; 46952 this.autoSave = null; 46953 this.common = null; 46954 this.validate = null; 46955 this.validateApprovalSignatures = null; 46956 this.submitUrl = new XFAObjectArray(); 46957 } 46958} 46959class Acrobat7 extends XFAObject { 46960 constructor(attributes) { 46961 super(CONFIG_NS_ID, "acrobat7", true); 46962 this.dynamicRender = null; 46963 } 46964} 46965class ADBE_JSConsole extends OptionObject { 46966 constructor(attributes) { 46967 super(CONFIG_NS_ID, "ADBE_JSConsole", ["delegate", "Enable", "Disable"]); 46968 } 46969} 46970class ADBE_JSDebugger extends OptionObject { 46971 constructor(attributes) { 46972 super(CONFIG_NS_ID, "ADBE_JSDebugger", ["delegate", "Enable", "Disable"]); 46973 } 46974} 46975class AddSilentPrint extends Option01 { 46976 constructor(attributes) { 46977 super(CONFIG_NS_ID, "addSilentPrint"); 46978 } 46979} 46980class AddViewerPreferences extends Option01 { 46981 constructor(attributes) { 46982 super(CONFIG_NS_ID, "addViewerPreferences"); 46983 } 46984} 46985class AdjustData extends Option10 { 46986 constructor(attributes) { 46987 super(CONFIG_NS_ID, "adjustData"); 46988 } 46989} 46990class AdobeExtensionLevel extends IntegerObject { 46991 constructor(attributes) { 46992 super(CONFIG_NS_ID, "adobeExtensionLevel", 0, n => n >= 1 && n <= 8); 46993 } 46994} 46995class Agent extends XFAObject { 46996 constructor(attributes) { 46997 super(CONFIG_NS_ID, "agent", true); 46998 this.name = attributes.name ? attributes.name.trim() : ""; 46999 this.common = new XFAObjectArray(); 47000 } 47001} 47002class AlwaysEmbed extends ContentObject { 47003 constructor(attributes) { 47004 super(CONFIG_NS_ID, "alwaysEmbed"); 47005 } 47006} 47007class Amd extends StringObject { 47008 constructor(attributes) { 47009 super(CONFIG_NS_ID, "amd"); 47010 } 47011} 47012class config_Area extends XFAObject { 47013 constructor(attributes) { 47014 super(CONFIG_NS_ID, "area"); 47015 this.level = getInteger({ 47016 data: attributes.level, 47017 defaultValue: 0, 47018 validate: n => n >= 1 && n <= 3 47019 }); 47020 this.name = getStringOption(attributes.name, ["", "barcode", "coreinit", "deviceDriver", "font", "general", "layout", "merge", "script", "signature", "sourceSet", "templateCache"]); 47021 } 47022} 47023class Attributes extends OptionObject { 47024 constructor(attributes) { 47025 super(CONFIG_NS_ID, "attributes", ["preserve", "delegate", "ignore"]); 47026 } 47027} 47028class AutoSave extends OptionObject { 47029 constructor(attributes) { 47030 super(CONFIG_NS_ID, "autoSave", ["disabled", "enabled"]); 47031 } 47032} 47033class Base extends StringObject { 47034 constructor(attributes) { 47035 super(CONFIG_NS_ID, "base"); 47036 } 47037} 47038class BatchOutput extends XFAObject { 47039 constructor(attributes) { 47040 super(CONFIG_NS_ID, "batchOutput"); 47041 this.format = getStringOption(attributes.format, ["none", "concat", "zip", "zipCompress"]); 47042 } 47043} 47044class BehaviorOverride extends ContentObject { 47045 constructor(attributes) { 47046 super(CONFIG_NS_ID, "behaviorOverride"); 47047 } 47048 [$finalize]() { 47049 this[$content] = new Map(this[$content].trim().split(/\s+/).filter(x => x.includes(":")).map(x => x.split(":", 2))); 47050 } 47051} 47052class Cache extends XFAObject { 47053 constructor(attributes) { 47054 super(CONFIG_NS_ID, "cache", true); 47055 this.templateCache = null; 47056 } 47057} 47058class Change extends Option01 { 47059 constructor(attributes) { 47060 super(CONFIG_NS_ID, "change"); 47061 } 47062} 47063class Common extends XFAObject { 47064 constructor(attributes) { 47065 super(CONFIG_NS_ID, "common", true); 47066 this.data = null; 47067 this.locale = null; 47068 this.localeSet = null; 47069 this.messaging = null; 47070 this.suppressBanner = null; 47071 this.template = null; 47072 this.validationMessaging = null; 47073 this.versionControl = null; 47074 this.log = new XFAObjectArray(); 47075 } 47076} 47077class Compress extends XFAObject { 47078 constructor(attributes) { 47079 super(CONFIG_NS_ID, "compress"); 47080 this.scope = getStringOption(attributes.scope, ["imageOnly", "document"]); 47081 } 47082} 47083class CompressLogicalStructure extends Option01 { 47084 constructor(attributes) { 47085 super(CONFIG_NS_ID, "compressLogicalStructure"); 47086 } 47087} 47088class CompressObjectStream extends Option10 { 47089 constructor(attributes) { 47090 super(CONFIG_NS_ID, "compressObjectStream"); 47091 } 47092} 47093class Compression extends XFAObject { 47094 constructor(attributes) { 47095 super(CONFIG_NS_ID, "compression", true); 47096 this.compressLogicalStructure = null; 47097 this.compressObjectStream = null; 47098 this.level = null; 47099 this.type = null; 47100 } 47101} 47102class Config extends XFAObject { 47103 constructor(attributes) { 47104 super(CONFIG_NS_ID, "config", true); 47105 this.acrobat = null; 47106 this.present = null; 47107 this.trace = null; 47108 this.agent = new XFAObjectArray(); 47109 } 47110} 47111class Conformance extends OptionObject { 47112 constructor(attributes) { 47113 super(CONFIG_NS_ID, "conformance", ["A", "B"]); 47114 } 47115} 47116class ContentCopy extends Option01 { 47117 constructor(attributes) { 47118 super(CONFIG_NS_ID, "contentCopy"); 47119 } 47120} 47121class Copies extends IntegerObject { 47122 constructor(attributes) { 47123 super(CONFIG_NS_ID, "copies", 1, n => n >= 1); 47124 } 47125} 47126class Creator extends StringObject { 47127 constructor(attributes) { 47128 super(CONFIG_NS_ID, "creator"); 47129 } 47130} 47131class CurrentPage extends IntegerObject { 47132 constructor(attributes) { 47133 super(CONFIG_NS_ID, "currentPage", 0, n => n >= 0); 47134 } 47135} 47136class Data extends XFAObject { 47137 constructor(attributes) { 47138 super(CONFIG_NS_ID, "data", true); 47139 this.adjustData = null; 47140 this.attributes = null; 47141 this.incrementalLoad = null; 47142 this.outputXSL = null; 47143 this.range = null; 47144 this.record = null; 47145 this.startNode = null; 47146 this.uri = null; 47147 this.window = null; 47148 this.xsl = null; 47149 this.excludeNS = new XFAObjectArray(); 47150 this.transform = new XFAObjectArray(); 47151 } 47152} 47153class Debug extends XFAObject { 47154 constructor(attributes) { 47155 super(CONFIG_NS_ID, "debug", true); 47156 this.uri = null; 47157 } 47158} 47159class DefaultTypeface extends ContentObject { 47160 constructor(attributes) { 47161 super(CONFIG_NS_ID, "defaultTypeface"); 47162 this.writingScript = getStringOption(attributes.writingScript, ["*", "Arabic", "Cyrillic", "EastEuropeanRoman", "Greek", "Hebrew", "Japanese", "Korean", "Roman", "SimplifiedChinese", "Thai", "TraditionalChinese", "Vietnamese"]); 47163 } 47164} 47165class Destination extends OptionObject { 47166 constructor(attributes) { 47167 super(CONFIG_NS_ID, "destination", ["pdf", "pcl", "ps", "webClient", "zpl"]); 47168 } 47169} 47170class DocumentAssembly extends Option01 { 47171 constructor(attributes) { 47172 super(CONFIG_NS_ID, "documentAssembly"); 47173 } 47174} 47175class Driver extends XFAObject { 47176 constructor(attributes) { 47177 super(CONFIG_NS_ID, "driver", true); 47178 this.name = attributes.name ? attributes.name.trim() : ""; 47179 this.fontInfo = null; 47180 this.xdc = null; 47181 } 47182} 47183class DuplexOption extends OptionObject { 47184 constructor(attributes) { 47185 super(CONFIG_NS_ID, "duplexOption", ["simplex", "duplexFlipLongEdge", "duplexFlipShortEdge"]); 47186 } 47187} 47188class DynamicRender extends OptionObject { 47189 constructor(attributes) { 47190 super(CONFIG_NS_ID, "dynamicRender", ["forbidden", "required"]); 47191 } 47192} 47193class Embed extends Option01 { 47194 constructor(attributes) { 47195 super(CONFIG_NS_ID, "embed"); 47196 } 47197} 47198class config_Encrypt extends Option01 { 47199 constructor(attributes) { 47200 super(CONFIG_NS_ID, "encrypt"); 47201 } 47202} 47203class config_Encryption extends XFAObject { 47204 constructor(attributes) { 47205 super(CONFIG_NS_ID, "encryption", true); 47206 this.encrypt = null; 47207 this.encryptionLevel = null; 47208 this.permissions = null; 47209 } 47210} 47211class EncryptionLevel extends OptionObject { 47212 constructor(attributes) { 47213 super(CONFIG_NS_ID, "encryptionLevel", ["40bit", "128bit"]); 47214 } 47215} 47216class Enforce extends StringObject { 47217 constructor(attributes) { 47218 super(CONFIG_NS_ID, "enforce"); 47219 } 47220} 47221class Equate extends XFAObject { 47222 constructor(attributes) { 47223 super(CONFIG_NS_ID, "equate"); 47224 this.force = getInteger({ 47225 data: attributes.force, 47226 defaultValue: 1, 47227 validate: n => n === 0 47228 }); 47229 this.from = attributes.from || ""; 47230 this.to = attributes.to || ""; 47231 } 47232} 47233class EquateRange extends XFAObject { 47234 constructor(attributes) { 47235 super(CONFIG_NS_ID, "equateRange"); 47236 this.from = attributes.from || ""; 47237 this.to = attributes.to || ""; 47238 this._unicodeRange = attributes.unicodeRange || ""; 47239 } 47240 get unicodeRange() { 47241 const ranges = []; 47242 const unicodeRegex = /U\+([0-9a-fA-F]+)/; 47243 const unicodeRange = this._unicodeRange; 47244 for (let range of unicodeRange.split(",").map(x => x.trim()).filter(
vendor: 22,273 bytes, lines 47244-48096
47244x => !!x)) { 47245 range = range.split("-", 2).map(x => { 47246 const found = x.match(unicodeRegex); 47247 if (!found) { 47248 return 0; 47249 } 47250 return parseInt(found[1], 16); 47251 }); 47252 if (range.length === 1) { 47253 range.push(range[0]); 47254 } 47255 ranges.push(range); 47256 } 47257 return shadow(this, "unicodeRange", ranges); 47258 } 47259} 47260class Exclude extends ContentObject { 47261 constructor(attributes) { 47262 super(CONFIG_NS_ID, "exclude"); 47263 } 47264 [$finalize]() { 47265 this[$content] = this[$content].trim().split(/\s+/).filter(x => x && ["calculate", "close", "enter", "exit", "initialize", "ready", "validate"].includes(x)); 47266 } 47267} 47268class ExcludeNS extends StringObject { 47269 constructor(attributes) { 47270 super(CONFIG_NS_ID, "excludeNS"); 47271 } 47272} 47273class FlipLabel extends OptionObject { 47274 constructor(attributes) { 47275 super(CONFIG_NS_ID, "flipLabel", ["usePrinterSetting", "on", "off"]); 47276 } 47277} 47278class config_FontInfo extends XFAObject { 47279 constructor(attributes) { 47280 super(CONFIG_NS_ID, "fontInfo", true); 47281 this.embed = null; 47282 this.map = null; 47283 this.subsetBelow = null; 47284 this.alwaysEmbed = new XFAObjectArray(); 47285 this.defaultTypeface = new XFAObjectArray(); 47286 this.neverEmbed = new XFAObjectArray(); 47287 } 47288} 47289class FormFieldFilling extends Option01 { 47290 constructor(attributes) { 47291 super(CONFIG_NS_ID, "formFieldFilling"); 47292 } 47293} 47294class GroupParent extends StringObject { 47295 constructor(attributes) { 47296 super(CONFIG_NS_ID, "groupParent"); 47297 } 47298} 47299class IfEmpty extends OptionObject { 47300 constructor(attributes) { 47301 super(CONFIG_NS_ID, "ifEmpty", ["dataValue", "dataGroup", "ignore", "remove"]); 47302 } 47303} 47304class IncludeXDPContent extends StringObject { 47305 constructor(attributes) { 47306 super(CONFIG_NS_ID, "includeXDPContent"); 47307 } 47308} 47309class IncrementalLoad extends OptionObject { 47310 constructor(attributes) { 47311 super(CONFIG_NS_ID, "incrementalLoad", ["none", "forwardOnly"]); 47312 } 47313} 47314class IncrementalMerge extends Option01 { 47315 constructor(attributes) { 47316 super(CONFIG_NS_ID, "incrementalMerge"); 47317 } 47318} 47319class Interactive extends Option01 { 47320 constructor(attributes) { 47321 super(CONFIG_NS_ID, "interactive"); 47322 } 47323} 47324class Jog extends OptionObject { 47325 constructor(attributes) { 47326 super(CONFIG_NS_ID, "jog", ["usePrinterSetting", "none", "pageSet"]); 47327 } 47328} 47329class LabelPrinter extends XFAObject { 47330 constructor(attributes) { 47331 super(CONFIG_NS_ID, "labelPrinter", true); 47332 this.name = getStringOption(attributes.name, ["zpl", "dpl", "ipl", "tcpl"]); 47333 this.batchOutput = null; 47334 this.flipLabel = null; 47335 this.fontInfo = null; 47336 this.xdc = null; 47337 } 47338} 47339class Layout extends OptionObject { 47340 constructor(attributes) { 47341 super(CONFIG_NS_ID, "layout", ["paginate", "panel"]); 47342 } 47343} 47344class Level extends IntegerObject { 47345 constructor(attributes) { 47346 super(CONFIG_NS_ID, "level", 0, n => n > 0); 47347 } 47348} 47349class Linearized extends Option01 { 47350 constructor(attributes) { 47351 super(CONFIG_NS_ID, "linearized"); 47352 } 47353} 47354class Locale extends StringObject { 47355 constructor(attributes) { 47356 super(CONFIG_NS_ID, "locale"); 47357 } 47358} 47359class LocaleSet extends StringObject { 47360 constructor(attributes) { 47361 super(CONFIG_NS_ID, "localeSet"); 47362 } 47363} 47364class Log extends XFAObject { 47365 constructor(attributes) { 47366 super(CONFIG_NS_ID, "log", true); 47367 this.mode = null; 47368 this.threshold = null; 47369 this.to = null; 47370 this.uri = null; 47371 } 47372} 47373class MapElement extends XFAObject { 47374 constructor(attributes) { 47375 super(CONFIG_NS_ID, "map", true); 47376 this.equate = new XFAObjectArray(); 47377 this.equateRange = new XFAObjectArray(); 47378 } 47379} 47380class MediumInfo extends XFAObject { 47381 constructor(attributes) { 47382 super(CONFIG_NS_ID, "mediumInfo", true); 47383 this.map = null; 47384 } 47385} 47386class config_Message extends XFAObject { 47387 constructor(attributes) { 47388 super(CONFIG_NS_ID, "message", true); 47389 this.msgId = null; 47390 this.severity = null; 47391 } 47392} 47393class Messaging extends XFAObject { 47394 constructor(attributes) { 47395 super(CONFIG_NS_ID, "messaging", true); 47396 this.message = new XFAObjectArray(); 47397 } 47398} 47399class Mode extends OptionObject { 47400 constructor(attributes) { 47401 super(CONFIG_NS_ID, "mode", ["append", "overwrite"]); 47402 } 47403} 47404class ModifyAnnots extends Option01 { 47405 constructor(attributes) { 47406 super(CONFIG_NS_ID, "modifyAnnots"); 47407 } 47408} 47409class MsgId extends IntegerObject { 47410 constructor(attributes) { 47411 super(CONFIG_NS_ID, "msgId", 1, n => n >= 1); 47412 } 47413} 47414class NameAttr extends StringObject { 47415 constructor(attributes) { 47416 super(CONFIG_NS_ID, "nameAttr"); 47417 } 47418} 47419class NeverEmbed extends ContentObject { 47420 constructor(attributes) { 47421 super(CONFIG_NS_ID, "neverEmbed"); 47422 } 47423} 47424class NumberOfCopies extends IntegerObject { 47425 constructor(attributes) { 47426 super(CONFIG_NS_ID, "numberOfCopies", null, n => n >= 2 && n <= 5); 47427 } 47428} 47429class OpenAction extends XFAObject { 47430 constructor(attributes) { 47431 super(CONFIG_NS_ID, "openAction", true); 47432 this.destination = null; 47433 } 47434} 47435class Output extends XFAObject { 47436 constructor(attributes) { 47437 super(CONFIG_NS_ID, "output", true); 47438 this.to = null; 47439 this.type = null; 47440 this.uri = null; 47441 } 47442} 47443class OutputBin extends StringObject { 47444 constructor(attributes) { 47445 super(CONFIG_NS_ID, "outputBin"); 47446 } 47447} 47448class OutputXSL extends XFAObject { 47449 constructor(attributes) { 47450 super(CONFIG_NS_ID, "outputXSL", true); 47451 this.uri = null; 47452 } 47453} 47454class Overprint extends OptionObject { 47455 constructor(attributes) { 47456 super(CONFIG_NS_ID, "overprint", ["none", "both", "draw", "field"]); 47457 } 47458} 47459class Packets extends StringObject { 47460 constructor(attributes) { 47461 super(CONFIG_NS_ID, "packets"); 47462 } 47463 [$finalize]() { 47464 if (this[$content] === "*") { 47465 return; 47466 } 47467 this[$content] = this[$content].trim().split(/\s+/).filter(x => ["config", "datasets", "template", "xfdf", "xslt"].includes(x)); 47468 } 47469} 47470class PageOffset extends XFAObject { 47471 constructor(attributes) { 47472 super(CONFIG_NS_ID, "pageOffset"); 47473 this.x = getInteger({ 47474 data: attributes.x, 47475 defaultValue: "useXDCSetting", 47476 validate: n => true 47477 }); 47478 this.y = getInteger({ 47479 data: attributes.y, 47480 defaultValue: "useXDCSetting", 47481 validate: n => true 47482 }); 47483 } 47484} 47485class PageRange extends StringObject { 47486 constructor(attributes) { 47487 super(CONFIG_NS_ID, "pageRange"); 47488 } 47489 [$finalize]() { 47490 const numbers = this[$content].trim().split(/\s+/).map(x => parseInt(x, 10)); 47491 const ranges = []; 47492 for (let i = 0, ii = numbers.length; i < ii; i += 2) { 47493 ranges.push(numbers.slice(i, i + 2)); 47494 } 47495 this[$content] = ranges; 47496 } 47497} 47498class Pagination extends OptionObject { 47499 constructor(attributes) { 47500 super(CONFIG_NS_ID, "pagination", ["simplex", "duplexShortEdge", "duplexLongEdge"]); 47501 } 47502} 47503class PaginationOverride extends OptionObject { 47504 constructor(attributes) { 47505 super(CONFIG_NS_ID, "paginationOverride", ["none", "forceDuplex", "forceDuplexLongEdge", "forceDuplexShortEdge", "forceSimplex"]); 47506 } 47507} 47508class Part extends IntegerObject { 47509 constructor(attributes) { 47510 super(CONFIG_NS_ID, "part", 1, n => false); 47511 } 47512} 47513class Pcl extends XFAObject { 47514 constructor(attributes) { 47515 super(CONFIG_NS_ID, "pcl", true); 47516 this.name = attributes.name || ""; 47517 this.batchOutput = null; 47518 this.fontInfo = null; 47519 this.jog = null; 47520 this.mediumInfo = null; 47521 this.outputBin = null; 47522 this.pageOffset = null; 47523 this.staple = null; 47524 this.xdc = null; 47525 } 47526} 47527class Pdf extends XFAObject { 47528 constructor(attributes) { 47529 super(CONFIG_NS_ID, "pdf", true); 47530 this.name = attributes.name || ""; 47531 this.adobeExtensionLevel = null; 47532 this.batchOutput = null; 47533 this.compression = null; 47534 this.creator = null; 47535 this.encryption = null; 47536 this.fontInfo = null; 47537 this.interactive = null; 47538 this.linearized = null; 47539 this.openAction = null; 47540 this.pdfa = null; 47541 this.producer = null; 47542 this.renderPolicy = null; 47543 this.scriptModel = null; 47544 this.silentPrint = null; 47545 this.submitFormat = null; 47546 this.tagged = null; 47547 this.version = null; 47548 this.viewerPreferences = null; 47549 this.xdc = null; 47550 } 47551} 47552class Pdfa extends XFAObject { 47553 constructor(attributes) { 47554 super(CONFIG_NS_ID, "pdfa", true); 47555 this.amd = null; 47556 this.conformance = null; 47557 this.includeXDPContent = null; 47558 this.part = null; 47559 } 47560} 47561class Permissions extends XFAObject { 47562 constructor(attributes) { 47563 super(CONFIG_NS_ID, "permissions", true); 47564 this.accessibleContent = null; 47565 this.change = null; 47566 this.contentCopy = null; 47567 this.documentAssembly = null; 47568 this.formFieldFilling = null; 47569 this.modifyAnnots = null; 47570 this.plaintextMetadata = null; 47571 this.print = null; 47572 this.printHighQuality = null; 47573 } 47574} 47575class PickTrayByPDFSize extends Option01 { 47576 constructor(attributes) { 47577 super(CONFIG_NS_ID, "pickTrayByPDFSize"); 47578 } 47579} 47580class config_Picture extends StringObject { 47581 constructor(attributes) { 47582 super(CONFIG_NS_ID, "picture"); 47583 } 47584} 47585class PlaintextMetadata extends Option01 { 47586 constructor(attributes) { 47587 super(CONFIG_NS_ID, "plaintextMetadata"); 47588 } 47589} 47590class Presence extends OptionObject { 47591 constructor(attributes) { 47592 super(CONFIG_NS_ID, "presence", ["preserve", "dissolve", "dissolveStructure", "ignore", "remove"]); 47593 } 47594} 47595class Present extends XFAObject { 47596 constructor(attributes) { 47597 super(CONFIG_NS_ID, "present", true); 47598 this.behaviorOverride = null; 47599 this.cache = null; 47600 this.common = null; 47601 this.copies = null; 47602 this.destination = null; 47603 this.incrementalMerge = null; 47604 this.layout = null; 47605 this.output = null; 47606 this.overprint = null; 47607 this.pagination = null; 47608 this.paginationOverride = null; 47609 this.script = null; 47610 this.validate = null; 47611 this.xdp = null; 47612 this.driver = new XFAObjectArray(); 47613 this.labelPrinter = new XFAObjectArray(); 47614 this.pcl = new XFAObjectArray(); 47615 this.pdf = new XFAObjectArray(); 47616 this.ps = new XFAObjectArray(); 47617 this.submitUrl = new XFAObjectArray(); 47618 this.webClient = new XFAObjectArray(); 47619 this.zpl = new XFAObjectArray(); 47620 } 47621} 47622class Print extends Option01 { 47623 constructor(attributes) { 47624 super(CONFIG_NS_ID, "print"); 47625 } 47626} 47627class PrintHighQuality extends Option01 { 47628 constructor(attributes) { 47629 super(CONFIG_NS_ID, "printHighQuality"); 47630 } 47631} 47632class PrintScaling extends OptionObject { 47633 constructor(attributes) { 47634 super(CONFIG_NS_ID, "printScaling", ["appdefault", "noScaling"]); 47635 } 47636} 47637class PrinterName extends StringObject { 47638 constructor(attributes) { 47639 super(CONFIG_NS_ID, "printerName"); 47640 } 47641} 47642class Producer extends StringObject { 47643 constructor(attributes) { 47644 super(CONFIG_NS_ID, "producer"); 47645 } 47646} 47647class Ps extends XFAObject { 47648 constructor(attributes) { 47649 super(CONFIG_NS_ID, "ps", true); 47650 this.name = attributes.name || ""; 47651 this.batchOutput = null; 47652 this.fontInfo = null; 47653 this.jog = null; 47654 this.mediumInfo = null; 47655 this.outputBin = null; 47656 this.staple = null; 47657 this.xdc = null; 47658 } 47659} 47660class Range extends ContentObject { 47661 constructor(attributes) { 47662 super(CONFIG_NS_ID, "range"); 47663 } 47664 [$finalize]() { 47665 this[$content] = this[$content].split(",", 2).map(range => range.split("-").map(x => parseInt(x.trim(), 10))).filter(range => range.every(x => !isNaN(x))).map(range => { 47666 if (range.length === 1) { 47667 range.push(range[0]); 47668 } 47669 return range; 47670 }); 47671 } 47672} 47673class Record extends ContentObject { 47674 constructor(attributes) { 47675 super(CONFIG_NS_ID, "record"); 47676 } 47677 [$finalize]() { 47678 this[$content] = this[$content].trim(); 47679 const n = parseInt(this[$content], 10); 47680 if (!isNaN(n) && n >= 0) { 47681 this[$content] = n; 47682 } 47683 } 47684} 47685class Relevant extends ContentObject { 47686 constructor(attributes) { 47687 super(CONFIG_NS_ID, "relevant"); 47688 } 47689 [$finalize]() { 47690 this[$content] = this[$content].trim().split(/\s+/); 47691 } 47692} 47693class Rename extends ContentObject { 47694 constructor(attributes) { 47695 super(CONFIG_NS_ID, "rename"); 47696 } 47697 [$finalize]() { 47698 this[$content] = this[$content].trim(); 47699 if (this[$content].toLowerCase().startsWith("xml") || new RegExp("[\\p{L}_][\\p{L}\\d._\\p{M}-]*", "u").test(this[$content])) { 47700 warn("XFA - Rename: invalid XFA name"); 47701 } 47702 } 47703} 47704class RenderPolicy extends OptionObject { 47705 constructor(attributes) { 47706 super(CONFIG_NS_ID, "renderPolicy", ["server", "client"]); 47707 } 47708} 47709class RunScripts extends OptionObject { 47710 constructor(attributes) { 47711 super(CONFIG_NS_ID, "runScripts", ["both", "client", "none", "server"]); 47712 } 47713} 47714class config_Script extends XFAObject { 47715 constructor(attributes) { 47716 super(CONFIG_NS_ID, "script", true); 47717 this.currentPage = null; 47718 this.exclude = null; 47719 this.runScripts = null; 47720 } 47721} 47722class ScriptModel extends OptionObject { 47723 constructor(attributes) { 47724 super(CONFIG_NS_ID, "scriptModel", ["XFA", "none"]); 47725 } 47726} 47727class Severity extends OptionObject { 47728 constructor(attributes) { 47729 super(CONFIG_NS_ID, "severity", ["ignore", "error", "information", "trace", "warning"]); 47730 } 47731} 47732class SilentPrint extends XFAObject { 47733 constructor(attributes) { 47734 super(CONFIG_NS_ID, "silentPrint", true); 47735 this.addSilentPrint = null; 47736 this.printerName = null; 47737 } 47738} 47739class Staple extends XFAObject { 47740 constructor(attributes) { 47741 super(CONFIG_NS_ID, "staple"); 47742 this.mode = getStringOption(attributes.mode, ["usePrinterSetting", "on", "off"]); 47743 } 47744} 47745class StartNode extends StringObject { 47746 constructor(attributes) { 47747 super(CONFIG_NS_ID, "startNode"); 47748 } 47749} 47750class StartPage extends IntegerObject { 47751 constructor(attributes) { 47752 super(CONFIG_NS_ID, "startPage", 0, n => true); 47753 } 47754} 47755class SubmitFormat extends OptionObject { 47756 constructor(attributes) { 47757 super(CONFIG_NS_ID, "submitFormat", ["html", "delegate", "fdf", "xml", "pdf"]); 47758 } 47759} 47760class SubmitUrl extends StringObject { 47761 constructor(attributes) { 47762 super(CONFIG_NS_ID, "submitUrl"); 47763 } 47764} 47765class SubsetBelow extends IntegerObject { 47766 constructor(attributes) { 47767 super(CONFIG_NS_ID, "subsetBelow", 100, n => n >= 0 && n <= 100); 47768 } 47769} 47770class SuppressBanner extends Option01 { 47771 constructor(attributes) { 47772 super(CONFIG_NS_ID, "suppressBanner"); 47773 } 47774} 47775class Tagged extends Option01 { 47776 constructor(attributes) { 47777 super(CONFIG_NS_ID, "tagged"); 47778 } 47779} 47780class config_Template extends XFAObject { 47781 constructor(attributes) { 47782 super(CONFIG_NS_ID, "template", true); 47783 this.base = null; 47784 this.relevant = null; 47785 this.startPage = null; 47786 this.uri = null; 47787 this.xsl = null; 47788 } 47789} 47790class Threshold extends OptionObject { 47791 constructor(attributes) { 47792 super(CONFIG_NS_ID, "threshold", ["trace", "error", "information", "warning"]); 47793 } 47794} 47795class To extends OptionObject { 47796 constructor(attributes) { 47797 super(CONFIG_NS_ID, "to", ["null", "memory", "stderr", "stdout", "system", "uri"]); 47798 } 47799} 47800class TemplateCache extends XFAObject { 47801 constructor(attributes) { 47802 super(CONFIG_NS_ID, "templateCache"); 47803 this.maxEntries = getInteger({ 47804 data: attributes.maxEntries, 47805 defaultValue: 5, 47806 validate: n => n >= 0 47807 }); 47808 } 47809} 47810class Trace extends XFAObject { 47811 constructor(attributes) { 47812 super(CONFIG_NS_ID, "trace", true); 47813 this.area = new XFAObjectArray(); 47814 } 47815} 47816class Transform extends XFAObject { 47817 constructor(attributes) { 47818 super(CONFIG_NS_ID, "transform", true); 47819 this.groupParent = null; 47820 this.ifEmpty = null; 47821 this.nameAttr = null; 47822 this.picture = null; 47823 this.presence = null; 47824 this.rename = null; 47825 this.whitespace = null; 47826 } 47827} 47828class Type extends OptionObject { 47829 constructor(attributes) { 47830 super(CONFIG_NS_ID, "type", ["none", "ascii85", "asciiHex", "ccittfax", "flate", "lzw", "runLength", "native", "xdp", "mergedXDP"]); 47831 } 47832} 47833class Uri extends StringObject { 47834 constructor(attributes) { 47835 super(CONFIG_NS_ID, "uri"); 47836 } 47837} 47838class config_Validate extends OptionObject { 47839 constructor(attributes) { 47840 super(CONFIG_NS_ID, "validate", ["preSubmit", "prePrint", "preExecute", "preSave"]); 47841 } 47842} 47843class ValidateApprovalSignatures extends ContentObject { 47844 constructor(attributes) { 47845 super(CONFIG_NS_ID, "validateApprovalSignatures"); 47846 } 47847 [$finalize]() { 47848 this[$content] = this[$content].trim().split(/\s+/).filter(x => ["docReady", "postSign"].includes(x)); 47849 } 47850} 47851class ValidationMessaging extends OptionObject { 47852 constructor(attributes) { 47853 super(CONFIG_NS_ID, "validationMessaging", ["allMessagesIndividually", "allMessagesTogether", "firstMessageOnly", "noMessages"]); 47854 } 47855} 47856class Version extends OptionObject { 47857 constructor(attributes) { 47858 super(CONFIG_NS_ID, "version", ["1.7", "1.6", "1.5", "1.4", "1.3", "1.2"]); 47859 } 47860} 47861class VersionControl extends XFAObject { 47862 constructor(attributes) { 47863 super(CONFIG_NS_ID, "VersionControl"); 47864 this.outputBelow = getStringOption(attributes.outputBelow, ["warn", "error", "update"]); 47865 this.sourceAbove = getStringOption(attributes.sourceAbove, ["warn", "error"]); 47866 this.sourceBelow = getStringOption(attributes.sourceBelow, ["update", "maintain"]); 47867 } 47868} 47869class ViewerPreferences extends XFAObject { 47870 constructor(attributes) { 47871 super(CONFIG_NS_ID, "viewerPreferences", true); 47872 this.ADBE_JSConsole = null; 47873 this.ADBE_JSDebugger = null; 47874 this.addViewerPreferences = null; 47875 this.duplexOption = null; 47876 this.enforce = null; 47877 this.numberOfCopies = null; 47878 this.pageRange = null; 47879 this.pickTrayByPDFSize = null; 47880 this.printScaling = null; 47881 } 47882} 47883class WebClient extends XFAObject { 47884 constructor(attributes) { 47885 super(CONFIG_NS_ID, "webClient", true); 47886 this.name = attributes.name ? attributes.name.trim() : ""; 47887 this.fontInfo = null; 47888 this.xdc = null; 47889 } 47890} 47891class Whitespace extends OptionObject { 47892 constructor(attributes) { 47893 super(CONFIG_NS_ID, "whitespace", ["preserve", "ltrim", "normalize", "rtrim", "trim"]); 47894 } 47895} 47896class Window extends ContentObject { 47897 constructor(attributes) { 47898 super(CONFIG_NS_ID, "window"); 47899 } 47900 [$finalize]() { 47901 const pair = this[$content].split(",", 2).map(x => parseInt(x.trim(), 10)); 47902 if (pair.some(x => isNaN(x))) { 47903 this[$content] = [0, 0]; 47904 return; 47905 } 47906 if (pair.length === 1) { 47907 pair.push(pair[0]); 47908 } 47909 this[$content] = pair; 47910 } 47911} 47912class Xdc extends XFAObject { 47913 constructor(attributes) { 47914 super(CONFIG_NS_ID, "xdc", true); 47915 this.uri = new XFAObjectArray(); 47916 this.xsl = new XFAObjectArray(); 47917 } 47918} 47919class Xdp extends XFAObject { 47920 constructor(attributes) { 47921 super(CONFIG_NS_ID, "xdp", true); 47922 this.packets = null; 47923 } 47924} 47925class Xsl extends XFAObject { 47926 constructor(attributes) { 47927 super(CONFIG_NS_ID, "xsl", true); 47928 this.debug = null; 47929 this.uri = null; 47930 } 47931} 47932class Zpl extends XFAObject { 47933 constructor(attributes) { 47934 super(CONFIG_NS_ID, "zpl", true); 47935 this.name = attributes.name ? attributes.name.trim() : ""; 47936 this.batchOutput = null; 47937 this.flipLabel = null; 47938 this.fontInfo = null; 47939 this.xdc = null; 47940 } 47941} 47942class ConfigNamespace { 47943 static [$buildXFAObject](name, attributes) { 47944 if (ConfigNamespace.hasOwnProperty(name)) { 47945 return ConfigNamespace[name](attributes); 47946 } 47947 return undefined; 47948 } 47949 static acrobat(attrs) { 47950 return new Acrobat(attrs); 47951 } 47952 static acrobat7(attrs) { 47953 return new Acrobat7(attrs); 47954 } 47955 static ADBE_JSConsole(attrs) { 47956 return new ADBE_JSConsole(attrs); 47957 } 47958 static ADBE_JSDebugger(attrs) { 47959 return new ADBE_JSDebugger(attrs); 47960 } 47961 static addSilentPrint(attrs) { 47962 return new AddSilentPrint(attrs); 47963 } 47964 static addViewerPreferences(attrs) { 47965 return new AddViewerPreferences(attrs); 47966 } 47967 static adjustData(attrs) { 47968 return new AdjustData(attrs); 47969 } 47970 static adobeExtensionLevel(attrs) { 47971 return new AdobeExtensionLevel(attrs); 47972 } 47973 static agent(attrs) { 47974 return new Agent(attrs); 47975 } 47976 static alwaysEmbed(attrs) { 47977 return new AlwaysEmbed(attrs); 47978 } 47979 static amd(attrs) { 47980 return new Amd(attrs); 47981 } 47982 static area(attrs) { 47983 return new config_Area(attrs); 47984 } 47985 static attributes(attrs) { 47986 return new Attributes(attrs); 47987 } 47988 static autoSave(attrs) { 47989 return new AutoSave(attrs); 47990 } 47991 static base(attrs) { 47992 return new Base(attrs); 47993 } 47994 static batchOutput(attrs) { 47995 return new BatchOutput(attrs); 47996 } 47997 static behaviorOverride(attrs) { 47998 return new BehaviorOverride(attrs); 47999 } 48000 static cache(attrs) { 48001 return new Cache(attrs); 48002 } 48003 static change(attrs) { 48004 return new Change(attrs); 48005 } 48006 static common(attrs) { 48007 return new Common(attrs); 48008 } 48009 static compress(attrs) { 48010 return new Compress(attrs); 48011 } 48012 static compressLogicalStructure(attrs) { 48013 return new CompressLogicalStructure(attrs); 48014 } 48015 static compressObjectStream(attrs) { 48016 return new CompressObjectStream(attrs); 48017 } 48018 static compression(attrs) { 48019 return new Compression(attrs); 48020 } 48021 static config(attrs) { 48022 return new Config(attrs); 48023 } 48024 static conformance(attrs) { 48025 return new Conformance(attrs); 48026 } 48027 static contentCopy(attrs) { 48028 return new ContentCopy(attrs); 48029 } 48030 static copies(attrs) { 48031 return new Copies(attrs); 48032 } 48033 static creator(attrs) { 48034 return new Creator(attrs); 48035 } 48036 static currentPage(attrs) { 48037 return new CurrentPage(attrs); 48038 } 48039 static data(attrs) { 48040 return new Data(attrs); 48041 } 48042 static debug(attrs) { 48043 return new Debug(attrs); 48044 } 48045 static defaultTypeface(attrs) { 48046 return new DefaultTypeface(attrs); 48047 } 48048 static destination(attrs) { 48049 return new Destination(attrs); 48050 } 48051 static documentAssembly(attrs) { 48052 return new DocumentAssembly(attrs); 48053 } 48054 static driver(attrs) { 48055 return new Driver(attrs); 48056 } 48057 static duplexOption(attrs) { 48058 return new DuplexOption(attrs); 48059 } 48060 static dynamicRender(attrs) { 48061 return new DynamicRender(attrs); 48062 } 48063 static embed(attrs) { 48064 return new Embed(attrs); 48065 } 48066 static encrypt(attrs) { 48067 return new config_Encrypt(attrs); 48068 } 48069 static encryption(attrs) { 48070 return new config_Encryption(attrs); 48071 } 48072 static encryptionLevel(attrs) { 48073 return new EncryptionLevel(attrs); 48074 } 48075 static enforce(attrs) { 48076 return new Enforce(attrs); 48077 } 48078 static equate(attrs) { 48079 return new Equate(attrs); 48080 } 48081 static equateRange(attrs) { 48082 return new EquateRange(attrs); 48083 } 48084 static exclude(attrs) { 48085 return new Exclude(attrs); 48086 } 48087 static excludeNS(attrs) { 48088 return new ExcludeNS(attrs); 48089 } 48090 static flipLabel(attrs) { 48091 return new FlipLabel(attrs); 48092 } 48093 static fontInfo(attrs) { 48094 return new config_FontInfo(attrs); 48095 } 48096 static formFieldFilling(attrs) {
vendor: 4,992 bytes, lines 48097-48327
48097 return new FormFieldFilling(attrs); 48098 } 48099 static groupParent(attrs) { 48100 return new GroupParent(attrs); 48101 } 48102 static ifEmpty(attrs) { 48103 return new IfEmpty(attrs); 48104 } 48105 static includeXDPContent(attrs) { 48106 return new IncludeXDPContent(attrs); 48107 } 48108 static incrementalLoad(attrs) { 48109 return new IncrementalLoad(attrs); 48110 } 48111 static incrementalMerge(attrs) { 48112 return new IncrementalMerge(attrs); 48113 } 48114 static interactive(attrs) { 48115 return new Interactive(attrs); 48116 } 48117 static jog(attrs) { 48118 return new Jog(attrs); 48119 } 48120 static labelPrinter(attrs) { 48121 return new LabelPrinter(attrs); 48122 } 48123 static layout(attrs) { 48124 return new Layout(attrs); 48125 } 48126 static level(attrs) { 48127 return new Level(attrs); 48128 } 48129 static linearized(attrs) { 48130 return new Linearized(attrs); 48131 } 48132 static locale(attrs) { 48133 return new Locale(attrs); 48134 } 48135 static localeSet(attrs) { 48136 return new LocaleSet(attrs); 48137 } 48138 static log(attrs) { 48139 return new Log(attrs); 48140 } 48141 static map(attrs) { 48142 return new MapElement(attrs); 48143 } 48144 static mediumInfo(attrs) { 48145 return new MediumInfo(attrs); 48146 } 48147 static message(attrs) { 48148 return new config_Message(attrs); 48149 } 48150 static messaging(attrs) { 48151 return new Messaging(attrs); 48152 } 48153 static mode(attrs) { 48154 return new Mode(attrs); 48155 } 48156 static modifyAnnots(attrs) { 48157 return new ModifyAnnots(attrs); 48158 } 48159 static msgId(attrs) { 48160 return new MsgId(attrs); 48161 } 48162 static nameAttr(attrs) { 48163 return new NameAttr(attrs); 48164 } 48165 static neverEmbed(attrs) { 48166 return new NeverEmbed(attrs); 48167 } 48168 static numberOfCopies(attrs) { 48169 return new NumberOfCopies(attrs); 48170 } 48171 static openAction(attrs) { 48172 return new OpenAction(attrs); 48173 } 48174 static output(attrs) { 48175 return new Output(attrs); 48176 } 48177 static outputBin(attrs) { 48178 return new OutputBin(attrs); 48179 } 48180 static outputXSL(attrs) { 48181 return new OutputXSL(attrs); 48182 } 48183 static overprint(attrs) { 48184 return new Overprint(attrs); 48185 } 48186 static packets(attrs) { 48187 return new Packets(attrs); 48188 } 48189 static pageOffset(attrs) { 48190 return new PageOffset(attrs); 48191 } 48192 static pageRange(attrs) { 48193 return new PageRange(attrs); 48194 } 48195 static pagination(attrs) { 48196 return new Pagination(attrs); 48197 } 48198 static paginationOverride(attrs) { 48199 return new PaginationOverride(attrs); 48200 } 48201 static part(attrs) { 48202 return new Part(attrs); 48203 } 48204 static pcl(attrs) { 48205 return new Pcl(attrs); 48206 } 48207 static pdf(attrs) { 48208 return new Pdf(attrs); 48209 } 48210 static pdfa(attrs) { 48211 return new Pdfa(attrs); 48212 } 48213 static permissions(attrs) { 48214 return new Permissions(attrs); 48215 } 48216 static pickTrayByPDFSize(attrs) { 48217 return new PickTrayByPDFSize(attrs); 48218 } 48219 static picture(attrs) { 48220 return new config_Picture(attrs); 48221 } 48222 static plaintextMetadata(attrs) { 48223 return new PlaintextMetadata(attrs); 48224 } 48225 static presence(attrs) { 48226 return new Presence(attrs); 48227 } 48228 static present(attrs) { 48229 return new Present(attrs); 48230 } 48231 static print(attrs) { 48232 return new Print(attrs); 48233 } 48234 static printHighQuality(attrs) { 48235 return new PrintHighQuality(attrs); 48236 } 48237 static printScaling(attrs) { 48238 return new PrintScaling(attrs); 48239 } 48240 static printerName(attrs) { 48241 return new PrinterName(attrs); 48242 } 48243 static producer(attrs) { 48244 return new Producer(attrs); 48245 } 48246 static ps(attrs) { 48247 return new Ps(attrs); 48248 } 48249 static range(attrs) { 48250 return new Range(attrs); 48251 } 48252 static record(attrs) { 48253 return new Record(attrs); 48254 } 48255 static relevant(attrs) { 48256 return new Relevant(attrs); 48257 } 48258 static rename(attrs) { 48259 return new Rename(attrs); 48260 } 48261 static renderPolicy(attrs) { 48262 return new RenderPolicy(attrs); 48263 } 48264 static runScripts(attrs) { 48265 return new RunScripts(attrs); 48266 } 48267 static script(attrs) { 48268 return new config_Script(attrs); 48269 } 48270 static scriptModel(attrs) { 48271 return new ScriptModel(attrs); 48272 } 48273 static severity(attrs) { 48274 return new Severity(attrs); 48275 } 48276 static silentPrint(attrs) { 48277 return new SilentPrint(attrs); 48278 } 48279 static staple(attrs) { 48280 return new Staple(attrs); 48281 } 48282 static startNode(attrs) { 48283 return new StartNode(attrs); 48284 } 48285 static startPage(attrs) { 48286 return new StartPage(attrs); 48287 } 48288 static submitFormat(attrs) { 48289 return new SubmitFormat(attrs); 48290 } 48291 static submitUrl(attrs) { 48292 return new SubmitUrl(attrs); 48293 } 48294 static subsetBelow(attrs) { 48295 return new SubsetBelow(attrs); 48296 } 48297 static suppressBanner(attrs) { 48298 return new SuppressBanner(attrs); 48299 } 48300 static tagged(attrs) { 48301 return new Tagged(attrs); 48302 } 48303 static template(attrs) { 48304 return new config_Template(attrs); 48305 } 48306 static templateCache(attrs) { 48307 return new TemplateCache(attrs); 48308 } 48309 static threshold(attrs) { 48310 return new Threshold(attrs); 48311 } 48312 static to(attrs) { 48313 return new To(attrs); 48314 } 48315 static trace(attrs) { 48316 return new Trace(attrs); 48317 } 48318 static transform(attrs) { 48319 return new Transform(attrs); 48320 } 48321 static type(attrs) { 48322 return new Type(attrs); 48323 } 48324 static uri(attrs) { 48325 return new Uri(attrs); 48326 } 48327 static validate(attrs) {
vendor: 27,200 bytes, lines 48328-49335
48328 return new config_Validate(attrs); 48329 } 48330 static validateApprovalSignatures(attrs) { 48331 return new ValidateApprovalSignatures(attrs); 48332 } 48333 static validationMessaging(attrs) { 48334 return new ValidationMessaging(attrs); 48335 } 48336 static version(attrs) { 48337 return new Version(attrs); 48338 } 48339 static versionControl(attrs) { 48340 return new VersionControl(attrs); 48341 } 48342 static viewerPreferences(attrs) { 48343 return new ViewerPreferences(attrs); 48344 } 48345 static webClient(attrs) { 48346 return new WebClient(attrs); 48347 } 48348 static whitespace(attrs) { 48349 return new Whitespace(attrs); 48350 } 48351 static window(attrs) { 48352 return new Window(attrs); 48353 } 48354 static xdc(attrs) { 48355 return new Xdc(attrs); 48356 } 48357 static xdp(attrs) { 48358 return new Xdp(attrs); 48359 } 48360 static xsl(attrs) { 48361 return new Xsl(attrs); 48362 } 48363 static zpl(attrs) { 48364 return new Zpl(attrs); 48365 } 48366} 48367 48368;// ./src/core/xfa/connection_set.js 48369 48370 48371const CONNECTION_SET_NS_ID = NamespaceIds.connectionSet.id; 48372class ConnectionSet extends XFAObject { 48373 constructor(attributes) { 48374 super(CONNECTION_SET_NS_ID, "connectionSet", true); 48375 this.wsdlConnection = new XFAObjectArray(); 48376 this.xmlConnection = new XFAObjectArray(); 48377 this.xsdConnection = new XFAObjectArray(); 48378 } 48379} 48380class EffectiveInputPolicy extends XFAObject { 48381 constructor(attributes) { 48382 super(CONNECTION_SET_NS_ID, "effectiveInputPolicy"); 48383 this.id = attributes.id || ""; 48384 this.name = attributes.name || ""; 48385 this.use = attributes.use || ""; 48386 this.usehref = attributes.usehref || ""; 48387 } 48388} 48389class EffectiveOutputPolicy extends XFAObject { 48390 constructor(attributes) { 48391 super(CONNECTION_SET_NS_ID, "effectiveOutputPolicy"); 48392 this.id = attributes.id || ""; 48393 this.name = attributes.name || ""; 48394 this.use = attributes.use || ""; 48395 this.usehref = attributes.usehref || ""; 48396 } 48397} 48398class Operation extends StringObject { 48399 constructor(attributes) { 48400 super(CONNECTION_SET_NS_ID, "operation"); 48401 this.id = attributes.id || ""; 48402 this.input = attributes.input || ""; 48403 this.name = attributes.name || ""; 48404 this.output = attributes.output || ""; 48405 this.use = attributes.use || ""; 48406 this.usehref = attributes.usehref || ""; 48407 } 48408} 48409class RootElement extends StringObject { 48410 constructor(attributes) { 48411 super(CONNECTION_SET_NS_ID, "rootElement"); 48412 this.id = attributes.id || ""; 48413 this.name = attributes.name || ""; 48414 this.use = attributes.use || ""; 48415 this.usehref = attributes.usehref || ""; 48416 } 48417} 48418class SoapAction extends StringObject { 48419 constructor(attributes) { 48420 super(CONNECTION_SET_NS_ID, "soapAction"); 48421 this.id = attributes.id || ""; 48422 this.name = attributes.name || ""; 48423 this.use = attributes.use || ""; 48424 this.usehref = attributes.usehref || ""; 48425 } 48426} 48427class SoapAddress extends StringObject { 48428 constructor(attributes) { 48429 super(CONNECTION_SET_NS_ID, "soapAddress"); 48430 this.id = attributes.id || ""; 48431 this.name = attributes.name || ""; 48432 this.use = attributes.use || ""; 48433 this.usehref = attributes.usehref || ""; 48434 } 48435} 48436class connection_set_Uri extends StringObject { 48437 constructor(attributes) { 48438 super(CONNECTION_SET_NS_ID, "uri"); 48439 this.id = attributes.id || ""; 48440 this.name = attributes.name || ""; 48441 this.use = attributes.use || ""; 48442 this.usehref = attributes.usehref || ""; 48443 } 48444} 48445class WsdlAddress extends StringObject { 48446 constructor(attributes) { 48447 super(CONNECTION_SET_NS_ID, "wsdlAddress"); 48448 this.id = attributes.id || ""; 48449 this.name = attributes.name || ""; 48450 this.use = attributes.use || ""; 48451 this.usehref = attributes.usehref || ""; 48452 } 48453} 48454class WsdlConnection extends XFAObject { 48455 constructor(attributes) { 48456 super(CONNECTION_SET_NS_ID, "wsdlConnection", true); 48457 this.dataDescription = attributes.dataDescription || ""; 48458 this.name = attributes.name || ""; 48459 this.effectiveInputPolicy = null; 48460 this.effectiveOutputPolicy = null; 48461 this.operation = null; 48462 this.soapAction = null; 48463 this.soapAddress = null; 48464 this.wsdlAddress = null; 48465 } 48466} 48467class XmlConnection extends XFAObject { 48468 constructor(attributes) { 48469 super(CONNECTION_SET_NS_ID, "xmlConnection", true); 48470 this.dataDescription = attributes.dataDescription || ""; 48471 this.name = attributes.name || ""; 48472 this.uri = null; 48473 } 48474} 48475class XsdConnection extends XFAObject { 48476 constructor(attributes) { 48477 super(CONNECTION_SET_NS_ID, "xsdConnection", true); 48478 this.dataDescription = attributes.dataDescription || ""; 48479 this.name = attributes.name || ""; 48480 this.rootElement = null; 48481 this.uri = null; 48482 } 48483} 48484class ConnectionSetNamespace { 48485 static [$buildXFAObject](name, attributes) { 48486 if (ConnectionSetNamespace.hasOwnProperty(name)) { 48487 return ConnectionSetNamespace[name](attributes); 48488 } 48489 return undefined; 48490 } 48491 static connectionSet(attrs) { 48492 return new ConnectionSet(attrs); 48493 } 48494 static effectiveInputPolicy(attrs) { 48495 return new EffectiveInputPolicy(attrs); 48496 } 48497 static effectiveOutputPolicy(attrs) { 48498 return new EffectiveOutputPolicy(attrs); 48499 } 48500 static operation(attrs) { 48501 return new Operation(attrs); 48502 } 48503 static rootElement(attrs) { 48504 return new RootElement(attrs); 48505 } 48506 static soapAction(attrs) { 48507 return new SoapAction(attrs); 48508 } 48509 static soapAddress(attrs) { 48510 return new SoapAddress(attrs); 48511 } 48512 static uri(attrs) { 48513 return new connection_set_Uri(attrs); 48514 } 48515 static wsdlAddress(attrs) { 48516 return new WsdlAddress(attrs); 48517 } 48518 static wsdlConnection(attrs) { 48519 return new WsdlConnection(attrs); 48520 } 48521 static xmlConnection(attrs) { 48522 return new XmlConnection(attrs); 48523 } 48524 static xsdConnection(attrs) { 48525 return new XsdConnection(attrs); 48526 } 48527} 48528 48529;// ./src/core/xfa/datasets.js 48530 48531 48532 48533const DATASETS_NS_ID = NamespaceIds.datasets.id; 48534class datasets_Data extends XmlObject { 48535 constructor(attributes) { 48536 super(DATASETS_NS_ID, "data", attributes); 48537 } 48538 [$isNsAgnostic]() { 48539 return true; 48540 } 48541} 48542class Datasets extends XFAObject { 48543 constructor(attributes) { 48544 super(DATASETS_NS_ID, "datasets", true); 48545 this.data = null; 48546 this.Signature = null; 48547 } 48548 [$onChild](child) { 48549 const name = child[$nodeName]; 48550 if (name === "data" && child[$namespaceId] === DATASETS_NS_ID || name === "Signature" && child[$namespaceId] === NamespaceIds.signature.id) { 48551 this[name] = child; 48552 } 48553 this[$appendChild](child); 48554 } 48555} 48556class DatasetsNamespace { 48557 static [$buildXFAObject](name, attributes) { 48558 if (DatasetsNamespace.hasOwnProperty(name)) { 48559 return DatasetsNamespace[name](attributes); 48560 } 48561 return undefined; 48562 } 48563 static datasets(attributes) { 48564 return new Datasets(attributes); 48565 } 48566 static data(attributes) { 48567 return new datasets_Data(attributes); 48568 } 48569} 48570 48571;// ./src/core/xfa/locale_set.js 48572 48573 48574 48575const LOCALE_SET_NS_ID = NamespaceIds.localeSet.id; 48576class CalendarSymbols extends XFAObject { 48577 constructor(attributes) { 48578 super(LOCALE_SET_NS_ID, "calendarSymbols", true); 48579 this.name = "gregorian"; 48580 this.dayNames = new XFAObjectArray(2); 48581 this.eraNames = null; 48582 this.meridiemNames = null; 48583 this.monthNames = new XFAObjectArray(2); 48584 } 48585} 48586class CurrencySymbol extends StringObject { 48587 constructor(attributes) { 48588 super(LOCALE_SET_NS_ID, "currencySymbol"); 48589 this.name = getStringOption(attributes.name, ["symbol", "isoname", "decimal"]); 48590 } 48591} 48592class CurrencySymbols extends XFAObject { 48593 constructor(attributes) { 48594 super(LOCALE_SET_NS_ID, "currencySymbols", true); 48595 this.currencySymbol = new XFAObjectArray(3); 48596 } 48597} 48598class DatePattern extends StringObject { 48599 constructor(attributes) { 48600 super(LOCALE_SET_NS_ID, "datePattern"); 48601 this.name = getStringOption(attributes.name, ["full", "long", "med", "short"]); 48602 } 48603} 48604class DatePatterns extends XFAObject { 48605 constructor(attributes) { 48606 super(LOCALE_SET_NS_ID, "datePatterns", true); 48607 this.datePattern = new XFAObjectArray(4); 48608 } 48609} 48610class DateTimeSymbols extends ContentObject { 48611 constructor(attributes) { 48612 super(LOCALE_SET_NS_ID, "dateTimeSymbols"); 48613 } 48614} 48615class Day extends StringObject { 48616 constructor(attributes) { 48617 super(LOCALE_SET_NS_ID, "day"); 48618 } 48619} 48620class DayNames extends XFAObject { 48621 constructor(attributes) { 48622 super(LOCALE_SET_NS_ID, "dayNames", true); 48623 this.abbr = getInteger({ 48624 data: attributes.abbr, 48625 defaultValue: 0, 48626 validate: x => x === 1 48627 }); 48628 this.day = new XFAObjectArray(7); 48629 } 48630} 48631class Era extends StringObject { 48632 constructor(attributes) { 48633 super(LOCALE_SET_NS_ID, "era"); 48634 } 48635} 48636class EraNames extends XFAObject { 48637 constructor(attributes) { 48638 super(LOCALE_SET_NS_ID, "eraNames", true); 48639 this.era = new XFAObjectArray(2); 48640 } 48641} 48642class locale_set_Locale extends XFAObject { 48643 constructor(attributes) { 48644 super(LOCALE_SET_NS_ID, "locale", true); 48645 this.desc = attributes.desc || ""; 48646 this.name = "isoname"; 48647 this.calendarSymbols = null; 48648 this.currencySymbols = null; 48649 this.datePatterns = null; 48650 this.dateTimeSymbols = null; 48651 this.numberPatterns = null; 48652 this.numberSymbols = null; 48653 this.timePatterns = null; 48654 this.typeFaces = null; 48655 } 48656} 48657class locale_set_LocaleSet extends XFAObject { 48658 constructor(attributes) { 48659 super(LOCALE_SET_NS_ID, "localeSet", true); 48660 this.locale = new XFAObjectArray(); 48661 } 48662} 48663class Meridiem extends StringObject { 48664 constructor(attributes) { 48665 super(LOCALE_SET_NS_ID, "meridiem"); 48666 } 48667} 48668class MeridiemNames extends XFAObject { 48669 constructor(attributes) { 48670 super(LOCALE_SET_NS_ID, "meridiemNames", true); 48671 this.meridiem = new XFAObjectArray(2); 48672 } 48673} 48674class Month extends StringObject { 48675 constructor(attributes) { 48676 super(LOCALE_SET_NS_ID, "month"); 48677 } 48678} 48679class MonthNames extends XFAObject { 48680 constructor(attributes) { 48681 super(LOCALE_SET_NS_ID, "monthNames", true); 48682 this.abbr = getInteger({ 48683 data: attributes.abbr, 48684 defaultValue: 0, 48685 validate: x => x === 1 48686 }); 48687 this.month = new XFAObjectArray(12); 48688 } 48689} 48690class NumberPattern extends StringObject { 48691 constructor(attributes) { 48692 super(LOCALE_SET_NS_ID, "numberPattern"); 48693 this.name = getStringOption(attributes.name, ["full", "long", "med", "short"]); 48694 } 48695} 48696class NumberPatterns extends XFAObject { 48697 constructor(attributes) { 48698 super(LOCALE_SET_NS_ID, "numberPatterns", true); 48699 this.numberPattern = new XFAObjectArray(4); 48700 } 48701} 48702class NumberSymbol extends StringObject { 48703 constructor(attributes) { 48704 super(LOCALE_SET_NS_ID, "numberSymbol"); 48705 this.name = getStringOption(attributes.name, ["decimal", "grouping", "percent", "minus", "zero"]); 48706 } 48707} 48708class NumberSymbols extends XFAObject { 48709 constructor(attributes) { 48710 super(LOCALE_SET_NS_ID, "numberSymbols", true); 48711 this.numberSymbol = new XFAObjectArray(5); 48712 } 48713} 48714class TimePattern extends StringObject { 48715 constructor(attributes) { 48716 super(LOCALE_SET_NS_ID, "timePattern"); 48717 this.name = getStringOption(attributes.name, ["full", "long", "med", "short"]); 48718 } 48719} 48720class TimePatterns extends XFAObject { 48721 constructor(attributes) { 48722 super(LOCALE_SET_NS_ID, "timePatterns", true); 48723 this.timePattern = new XFAObjectArray(4); 48724 } 48725} 48726class TypeFace extends XFAObject { 48727 constructor(attributes) { 48728 super(LOCALE_SET_NS_ID, "typeFace", true); 48729 this.name = attributes.name | ""; 48730 } 48731} 48732class TypeFaces extends XFAObject { 48733 constructor(attributes) { 48734 super(LOCALE_SET_NS_ID, "typeFaces", true); 48735 this.typeFace = new XFAObjectArray(); 48736 } 48737} 48738class LocaleSetNamespace { 48739 static [$buildXFAObject](name, attributes) { 48740 if (LocaleSetNamespace.hasOwnProperty(name)) { 48741 return LocaleSetNamespace[name](attributes); 48742 } 48743 return undefined; 48744 } 48745 static calendarSymbols(attrs) { 48746 return new CalendarSymbols(attrs); 48747 } 48748 static currencySymbol(attrs) { 48749 return new CurrencySymbol(attrs); 48750 } 48751 static currencySymbols(attrs) { 48752 return new CurrencySymbols(attrs); 48753 } 48754 static datePattern(attrs) { 48755 return new DatePattern(attrs); 48756 } 48757 static datePatterns(attrs) { 48758 return new DatePatterns(attrs); 48759 } 48760 static dateTimeSymbols(attrs) { 48761 return new DateTimeSymbols(attrs); 48762 } 48763 static day(attrs) { 48764 return new Day(attrs); 48765 } 48766 static dayNames(attrs) { 48767 return new DayNames(attrs); 48768 } 48769 static era(attrs) { 48770 return new Era(attrs); 48771 } 48772 static eraNames(attrs) { 48773 return new EraNames(attrs); 48774 } 48775 static locale(attrs) { 48776 return new locale_set_Locale(attrs); 48777 } 48778 static localeSet(attrs) { 48779 return new locale_set_LocaleSet(attrs); 48780 } 48781 static meridiem(attrs) { 48782 return new Meridiem(attrs); 48783 } 48784 static meridiemNames(attrs) { 48785 return new MeridiemNames(attrs); 48786 } 48787 static month(attrs) { 48788 return new Month(attrs); 48789 } 48790 static monthNames(attrs) { 48791 return new MonthNames(attrs); 48792 } 48793 static numberPattern(attrs) { 48794 return new NumberPattern(attrs); 48795 } 48796 static numberPatterns(attrs) { 48797 return new NumberPatterns(attrs); 48798 } 48799 static numberSymbol(attrs) { 48800 return new NumberSymbol(attrs); 48801 } 48802 static numberSymbols(attrs) { 48803 return new NumberSymbols(attrs); 48804 } 48805 static timePattern(attrs) { 48806 return new TimePattern(attrs); 48807 } 48808 static timePatterns(attrs) { 48809 return new TimePatterns(attrs); 48810 } 48811 static typeFace(attrs) { 48812 return new TypeFace(attrs); 48813 } 48814 static typeFaces(attrs) { 48815 return new TypeFaces(attrs); 48816 } 48817} 48818 48819;// ./src/core/xfa/signature.js 48820 48821 48822const SIGNATURE_NS_ID = NamespaceIds.signature.id; 48823class signature_Signature extends XFAObject { 48824 constructor(attributes) { 48825 super(SIGNATURE_NS_ID, "signature", true); 48826 } 48827} 48828class SignatureNamespace { 48829 static [$buildXFAObject](name, attributes) { 48830 if (SignatureNamespace.hasOwnProperty(name)) { 48831 return SignatureNamespace[name](attributes); 48832 } 48833 return undefined; 48834 } 48835 static signature(attributes) { 48836 return new signature_Signature(attributes); 48837 } 48838} 48839 48840;// ./src/core/xfa/stylesheet.js 48841 48842 48843const STYLESHEET_NS_ID = NamespaceIds.stylesheet.id; 48844class Stylesheet extends XFAObject { 48845 constructor(attributes) { 48846 super(STYLESHEET_NS_ID, "stylesheet", true); 48847 } 48848} 48849class StylesheetNamespace { 48850 static [$buildXFAObject](name, attributes) { 48851 if (StylesheetNamespace.hasOwnProperty(name)) { 48852 return StylesheetNamespace[name](attributes); 48853 } 48854 return undefined; 48855 } 48856 static stylesheet(attributes) { 48857 return new Stylesheet(attributes); 48858 } 48859} 48860 48861;// ./src/core/xfa/xdp.js 48862 48863 48864 48865const XDP_NS_ID = NamespaceIds.xdp.id; 48866class xdp_Xdp extends XFAObject { 48867 constructor(attributes) { 48868 super(XDP_NS_ID, "xdp", true); 48869 this.uuid = attributes.uuid || ""; 48870 this.timeStamp = attributes.timeStamp || ""; 48871 this.config = null; 48872 this.connectionSet = null; 48873 this.datasets = null; 48874 this.localeSet = null; 48875 this.stylesheet = new XFAObjectArray(); 48876 this.template = null; 48877 } 48878 [$onChildCheck](child) { 48879 const ns = NamespaceIds[child[$nodeName]]; 48880 return ns && child[$namespaceId] === ns.id; 48881 } 48882} 48883class XdpNamespace { 48884 static [$buildXFAObject](name, attributes) { 48885 if (XdpNamespace.hasOwnProperty(name)) { 48886 return XdpNamespace[name](attributes); 48887 } 48888 return undefined; 48889 } 48890 static xdp(attributes) { 48891 return new xdp_Xdp(attributes); 48892 } 48893} 48894 48895;// ./src/core/xfa/xhtml.js 48896 48897 48898 48899 48900 48901const XHTML_NS_ID = NamespaceIds.xhtml.id; 48902const $richText = Symbol(); 48903const VALID_STYLES = new Set(["color", "font", "font-family", "font-size", "font-stretch", "font-style", "font-weight", "margin", "margin-bottom", "margin-left", "margin-right", "margin-top", "letter-spacing", "line-height", "orphans", "page-break-after", "page-break-before", "page-break-inside", "tab-interval", "tab-stop", "text-align", "text-decoration", "text-indent", "vertical-align", "widows", "kerning-mode", "xfa-font-horizontal-scale", "xfa-font-vertical-scale", "xfa-spacerun", "xfa-tab-stops"]); 48904const StyleMapping = new Map([["page-break-after", "breakAfter"], ["page-break-before", "breakBefore"], ["page-break-inside", "breakInside"], ["kerning-mode", value => value === "none" ? "none" : "normal"], ["xfa-font-horizontal-scale", value => `scaleX(${Math.max(0, parseInt(value) / 100).toFixed(2)})`], ["xfa-font-vertical-scale", value => `scaleY(${Math.max(0, parseInt(value) / 100).toFixed(2)})`], ["xfa-spacerun", ""], ["xfa-tab-stops", ""], ["font-size", (value, original) => { 48905 value = original.fontSize = Math.abs(getMeasurement(value)); 48906 return measureToString(0.99 * value); 48907}], ["letter-spacing", value => measureToString(getMeasurement(value))], ["line-height", value => measureToString(getMeasurement(value))], ["margin", value => measureToString(getMeasurement(value))], ["margin-bottom", value => measureToString(getMeasurement(value))], ["margin-left", value => measureToString(getMeasurement(value))], ["margin-right", value => measureToString(getMeasurement(value))], ["margin-top", value => measureToString(getMeasurement(value))], ["text-indent", value => measureToString(getMeasurement(value))], ["font-family", value => value], ["vertical-align", value => measureToString(getMeasurement(value))]]); 48908const spacesRegExp = /\s+/g; 48909const crlfRegExp = /[\r\n]+/g; 48910const crlfForRichTextRegExp = /\r\n?/g; 48911function mapStyle(styleStr, node, richText) { 48912 const style = Object.create(null); 48913 if (!styleStr) { 48914 return style; 48915 } 48916 const original = Object.create(null); 48917 for (const [key, value] of styleStr.split(";").map(s => s.split(":", 2))) { 48918 const mapping = StyleMapping.get(key); 48919 if (mapping === "") { 48920 continue; 48921 } 48922 let newValue = value; 48923 if (mapping) { 48924 newValue = typeof mapping === "string" ? mapping : mapping(value, original); 48925 } 48926 if (key.endsWith("scale")) { 48927 style.transform = style.transform ? `${style[key]} ${newValue}` : newValue; 48928 } else { 48929 style[key.replaceAll(/-([a-zA-Z])/g, (_, x) => x.toUpperCase())] = newValue; 48930 } 48931 } 48932 if (style.fontFamily) { 48933 setFontFamily({ 48934 typeface: style.fontFamily, 48935 weight: style.fontWeight || "normal", 48936 posture: style.fontStyle || "normal", 48937 size: original.fontSize || 0 48938 }, node, node[$globalData].fontFinder, style); 48939 } 48940 if (richText && style.verticalAlign && style.verticalAlign !== "0px" && style.fontSize) { 48941 const SUB_SUPER_SCRIPT_FACTOR = 0.583; 48942 const VERTICAL_FACTOR = 0.333; 48943 const fontSize = getMeasurement(style.fontSize); 48944 style.fontSize = measureToString(fontSize * SUB_SUPER_SCRIPT_FACTOR); 48945 style.verticalAlign = measureToString(Math.sign(getMeasurement(style.verticalAlign)) * fontSize * VERTICAL_FACTOR); 48946 } 48947 if (richText && style.fontSize) { 48948 style.fontSize = `calc(${style.fontSize} * var(--total-scale-factor))`; 48949 } 48950 fixTextIndent(style); 48951 return style; 48952} 48953function checkStyle(node) { 48954 if (!node.style) { 48955 return ""; 48956 } 48957 return node.style.split(";").filter(s => !!s.trim()).map(s => s.split(":", 2).map(t => t.trim())).filter(([key, value]) => { 48958 if (key === "font-family") { 48959 node[$globalData].usedTypefaces.add(value); 48960 } 48961 return VALID_STYLES.has(key); 48962 }).map(kv => kv.join(":")).join(";"); 48963} 48964const NoWhites = new Set(["body", "html"]); 48965class XhtmlObject extends XmlObject { 48966 constructor(attributes, name) { 48967 super(XHTML_NS_ID, name); 48968 this[$richText] = false; 48969 this.style = attributes.style || ""; 48970 } 48971 [$clean](builder) { 48972 super[$clean](builder); 48973 this.style = checkStyle(this); 48974 } 48975 [$acceptWhitespace]() { 48976 return !NoWhites.has(this[$nodeName]); 48977 } 48978 [$onText](str, richText = false) { 48979 if (!richText) { 48980 str = str.replaceAll(crlfRegExp, ""); 48981 if (!this.style.includes("xfa-spacerun:yes")) { 48982 str = str.replaceAll(spacesRegExp, " "); 48983 } 48984 } else { 48985 this[$richText] = true; 48986 } 48987 if (str) { 48988 this[$content] += str; 48989 } 48990 } 48991 [$pushGlyphs](measure, mustPop = true) { 48992 const xfaFont = Object.create(null); 48993 const margin = { 48994 top: NaN, 48995 bottom: NaN, 48996 left: NaN, 48997 right: NaN 48998 }; 48999 let lineHeight = null; 49000 for (const [key, value] of this.style.split(";").map(s => s.split(":", 2))) { 49001 switch (key) { 49002 case "font-family": 49003 xfaFont.typeface = stripQuotes(value); 49004 break; 49005 case "font-size": 49006 xfaFont.size = getMeasurement(value); 49007 break; 49008 case "font-weight": 49009 xfaFont.weight = value; 49010 break; 49011 case "font-style": 49012 xfaFont.posture = value; 49013 break; 49014 case "letter-spacing": 49015 xfaFont.letterSpacing = getMeasurement(value); 49016 break; 49017 case "margin": 49018 const values = value.split(/ \t/).map(x => getMeasurement(x)); 49019 switch (values.length) { 49020 case 1: 49021 margin.top = margin.bottom = margin.left = margin.right = values[0]; 49022 break; 49023 case 2: 49024 margin.top = margin.bottom = values[0]; 49025 margin.left = margin.right = values[1]; 49026 break; 49027 case 3: 49028 margin.top = values[0]; 49029 margin.bottom = values[2]; 49030 margin.left = margin.right = values[1]; 49031 break; 49032 case 4: 49033 margin.top = values[0]; 49034 margin.left = values[1]; 49035 margin.bottom = values[2]; 49036 margin.right = values[3]; 49037 break; 49038 } 49039 break; 49040 case "margin-top": 49041 margin.top = getMeasurement(value); 49042 break; 49043 case "margin-bottom": 49044 margin.bottom = getMeasurement(value); 49045 break; 49046 case "margin-left": 49047 margin.left = getMeasurement(value); 49048 break; 49049 case "margin-right": 49050 margin.right = getMeasurement(value); 49051 break; 49052 case "line-height": 49053 lineHeight = getMeasurement(value); 49054 break; 49055 } 49056 } 49057 measure.pushData(xfaFont, margin, lineHeight); 49058 if (this[$content]) { 49059 measure.addString(this[$content]); 49060 } else { 49061 for (const child of this[$getChildren]()) { 49062 if (child[$nodeName] === "#text") { 49063 measure.addString(child[$content]); 49064 continue; 49065 } 49066 child[$pushGlyphs](measure); 49067 } 49068 } 49069 if (mustPop) { 49070 measure.popFont(); 49071 } 49072 } 49073 [$toHTML](availableSpace) { 49074 const children = []; 49075 this[$extra] = { 49076 children 49077 }; 49078 this[$childrenToHTML]({}); 49079 if (children.length === 0 && !this[$content]) { 49080 return HTMLResult.EMPTY; 49081 } 49082 let value; 49083 if (this[$richText]) { 49084 value = this[$content] ? this[$content].replaceAll(crlfForRichTextRegExp, "\n") : undefined; 49085 } else { 49086 value = this[$content] || undefined; 49087 } 49088 return HTMLResult.success({ 49089 name: this[$nodeName], 49090 attributes: { 49091 href: this.href, 49092 style: mapStyle(this.style, this, this[$richText]) 49093 }, 49094 children, 49095 value 49096 }); 49097 } 49098} 49099class A extends XhtmlObject { 49100 constructor(attributes) { 49101 super(attributes, "a"); 49102 this.href = fixURL(attributes.href) || ""; 49103 } 49104} 49105class B extends XhtmlObject { 49106 constructor(attributes) { 49107 super(attributes, "b"); 49108 } 49109 [$pushGlyphs](measure) { 49110 measure.pushFont({ 49111 weight: "bold" 49112 }); 49113 super[$pushGlyphs](measure); 49114 measure.popFont(); 49115 } 49116} 49117class Body extends XhtmlObject { 49118 constructor(attributes) { 49119 super(attributes, "body"); 49120 } 49121 [$toHTML](availableSpace) { 49122 const res = super[$toHTML](availableSpace); 49123 const { 49124 html 49125 } = res; 49126 if (!html) { 49127 return HTMLResult.EMPTY; 49128 } 49129 html.name = "div"; 49130 html.attributes.class = ["xfaRich"]; 49131 return res; 49132 } 49133} 49134class Br extends XhtmlObject { 49135 constructor(attributes) { 49136 super(attributes, "br"); 49137 } 49138 [$text]() { 49139 return "\n"; 49140 } 49141 [$pushGlyphs](measure) { 49142 measure.addString("\n"); 49143 } 49144 [$toHTML](availableSpace) { 49145 return HTMLResult.success({ 49146 name: "br" 49147 }); 49148 } 49149} 49150class Html extends XhtmlObject { 49151 constructor(attributes) { 49152 super(attributes, "html"); 49153 } 49154 [$toHTML](availableSpace) { 49155 const children = []; 49156 this[$extra] = { 49157 children 49158 }; 49159 this[$childrenToHTML]({}); 49160 if (children.length === 0) { 49161 return HTMLResult.success({ 49162 name: "div", 49163 attributes: { 49164 class: ["xfaRich"], 49165 style: {} 49166 }, 49167 value: this[$content] || "" 49168 }); 49169 } 49170 if (children.length === 1) { 49171 const child = children[0]; 49172 if (child.attributes?.class.includes("xfaRich")) { 49173 return HTMLResult.success(child); 49174 } 49175 } 49176 return HTMLResult.success({ 49177 name: "div", 49178 attributes: { 49179 class: ["xfaRich"], 49180 style: {} 49181 }, 49182 children 49183 }); 49184 } 49185} 49186class I extends XhtmlObject { 49187 constructor(attributes) { 49188 super(attributes, "i"); 49189 } 49190 [$pushGlyphs](measure) { 49191 measure.pushFont({ 49192 posture: "italic" 49193 }); 49194 super[$pushGlyphs](measure); 49195 measure.popFont(); 49196 } 49197} 49198class Li extends XhtmlObject { 49199 constructor(attributes) { 49200 super(attributes, "li"); 49201 } 49202} 49203class Ol extends XhtmlObject { 49204 constructor(attributes) { 49205 super(attributes, "ol"); 49206 } 49207} 49208class P extends XhtmlObject { 49209 constructor(attributes) { 49210 super(attributes, "p"); 49211 } 49212 [$pushGlyphs](measure) { 49213 super[$pushGlyphs](measure, false); 49214 measure.addString("\n"); 49215 measure.addPara(); 49216 measure.popFont(); 49217 } 49218 [$text]() { 49219 const siblings = this[$getParent]()[$getChildren](); 49220 if (siblings.at(-1) === this) { 49221 return super[$text](); 49222 } 49223 return super[$text]() + "\n"; 49224 } 49225} 49226class Span extends XhtmlObject { 49227 constructor(attributes) { 49228 super(attributes, "span"); 49229 } 49230} 49231class Sub extends XhtmlObject { 49232 constructor(attributes) { 49233 super(attributes, "sub"); 49234 } 49235} 49236class Sup extends XhtmlObject { 49237 constructor(attributes) { 49238 super(attributes, "sup"); 49239 } 49240} 49241class Ul extends XhtmlObject { 49242 constructor(attributes) { 49243 super(attributes, "ul"); 49244 } 49245} 49246class XhtmlNamespace { 49247 static [$buildXFAObject](name, attributes) { 49248 if (XhtmlNamespace.hasOwnProperty(name)) { 49249 return XhtmlNamespace[name](attributes); 49250 } 49251 return undefined; 49252 } 49253 static a(attributes) { 49254 return new A(attributes); 49255 } 49256 static b(attributes) { 49257 return new B(attributes); 49258 } 49259 static body(attributes) { 49260 return new Body(attributes); 49261 } 49262 static br(attributes) { 49263 return new Br(attributes); 49264 } 49265 static html(attributes) { 49266 return new Html(attributes); 49267 } 49268 static i(attributes) { 49269 return new I(attributes); 49270 } 49271 static li(attributes) { 49272 return new Li(attributes); 49273 } 49274 static ol(attributes) { 49275 return new Ol(attributes); 49276 } 49277 static p(attributes) { 49278 return new P(attributes); 49279 } 49280 static span(attributes) { 49281 return new Span(attributes); 49282 } 49283 static sub(attributes) { 49284 return new Sub(attributes); 49285 } 49286 static sup(attributes) { 49287 return new Sup(attributes); 49288 } 49289 static ul(attributes) { 49290 return new Ul(attributes); 49291 } 49292} 49293 49294;// ./src/core/xfa/setup.js 49295 49296 49297 49298 49299 49300 49301 49302 49303 49304const NamespaceSetUp = { 49305 config: ConfigNamespace, 49306 connection: ConnectionSetNamespace, 49307 datasets: DatasetsNamespace, 49308 localeSet: LocaleSetNamespace, 49309 signature: SignatureNamespace, 49310 stylesheet: StylesheetNamespace, 49311 template: TemplateNamespace, 49312 xdp: XdpNamespace, 49313 xhtml: XhtmlNamespace 49314}; 49315 49316;// ./src/core/xfa/unknown.js 49317 49318 49319class UnknownNamespace { 49320 constructor(nsId) { 49321 this.namespaceId = nsId; 49322 } 49323 [$buildXFAObject](name, attributes) { 49324 return new XmlObject(this.namespaceId, name, attributes); 49325 } 49326} 49327 49328;// ./src/core/xfa/builder.js 49329 49330 49331 49332 49333 49334 49335
vendor: 605 bytes, lines 49336-49360
49336class Root extends XFAObject { 49337 constructor(ids) { 49338 super(-1, "root", Object.create(null)); 49339 this.element = null; 49340 this[$ids] = ids; 49341 } 49342 [$onChild](child) { 49343 this.element = child; 49344 return true; 49345 } 49346 [$finalize]() { 49347 super[$finalize](); 49348 if (this.element.template instanceof Template) { 49349 this[$ids].set($root, this.element); 49350 this.element.template[$resolvePrototypes](this[$ids]); 49351 this.element.template[$ids] = this[$ids]; 49352 } 49353 } 49354} 49355class Empty extends XFAObject { 49356 constructor() { 49357 super(-1, "", Object.create(null)); 49358 } 49359 [$onChild](_) { 49360 return false;
vendor: 10,419 bytes, lines 49361-49764
49361 } 49362} 49363class Builder { 49364 constructor(rootNameSpace = null) { 49365 this._namespaceStack = []; 49366 this._nsAgnosticLevel = 0; 49367 this._namespacePrefixes = new Map(); 49368 this._namespaces = new Map(); 49369 this._nextNsId = Math.max(...Object.values(NamespaceIds).map(({ 49370 id 49371 }) => id)); 49372 this._currentNamespace = rootNameSpace || new UnknownNamespace(++this._nextNsId); 49373 } 49374 buildRoot(ids) { 49375 return new Root(ids); 49376 } 49377 build({ 49378 nsPrefix, 49379 name, 49380 attributes, 49381 namespace, 49382 prefixes 49383 }) { 49384 const hasNamespaceDef = namespace !== null; 49385 if (hasNamespaceDef) { 49386 this._namespaceStack.push(this._currentNamespace); 49387 this._currentNamespace = this._searchNamespace(namespace); 49388 } 49389 if (prefixes) { 49390 this._addNamespacePrefix(prefixes); 49391 } 49392 if (attributes.hasOwnProperty($nsAttributes)) { 49393 const dataTemplate = NamespaceSetUp.datasets; 49394 const nsAttrs = attributes[$nsAttributes]; 49395 let xfaAttrs = null; 49396 for (const [ns, attrs] of Object.entries(nsAttrs)) { 49397 const nsToUse = this._getNamespaceToUse(ns); 49398 if (nsToUse === dataTemplate) { 49399 xfaAttrs = { 49400 xfa: attrs 49401 }; 49402 break; 49403 } 49404 } 49405 if (xfaAttrs) { 49406 attributes[$nsAttributes] = xfaAttrs; 49407 } else { 49408 delete attributes[$nsAttributes]; 49409 } 49410 } 49411 const namespaceToUse = this._getNamespaceToUse(nsPrefix); 49412 const node = namespaceToUse?.[$buildXFAObject](name, attributes) || new Empty(); 49413 if (node[$isNsAgnostic]()) { 49414 this._nsAgnosticLevel++; 49415 } 49416 if (hasNamespaceDef || prefixes || node[$isNsAgnostic]()) { 49417 node[$cleanup] = { 49418 hasNamespace: hasNamespaceDef, 49419 prefixes, 49420 nsAgnostic: node[$isNsAgnostic]() 49421 }; 49422 } 49423 return node; 49424 } 49425 isNsAgnostic() { 49426 return this._nsAgnosticLevel > 0; 49427 } 49428 _searchNamespace(nsName) { 49429 let ns = this._namespaces.get(nsName); 49430 if (ns) { 49431 return ns; 49432 } 49433 for (const [name, { 49434 check 49435 }] of Object.entries(NamespaceIds)) { 49436 if (check(nsName)) { 49437 ns = NamespaceSetUp[name]; 49438 if (ns) { 49439 this._namespaces.set(nsName, ns); 49440 return ns; 49441 } 49442 break; 49443 } 49444 } 49445 ns = new UnknownNamespace(++this._nextNsId); 49446 this._namespaces.set(nsName, ns); 49447 return ns; 49448 } 49449 _addNamespacePrefix(prefixes) { 49450 for (const { 49451 prefix, 49452 value 49453 } of prefixes) { 49454 const namespace = this._searchNamespace(value); 49455 let prefixStack = this._namespacePrefixes.get(prefix); 49456 if (!prefixStack) { 49457 prefixStack = []; 49458 this._namespacePrefixes.set(prefix, prefixStack); 49459 } 49460 prefixStack.push(namespace); 49461 } 49462 } 49463 _getNamespaceToUse(prefix) { 49464 if (!prefix) { 49465 return this._currentNamespace; 49466 } 49467 const prefixStack = this._namespacePrefixes.get(prefix); 49468 if (prefixStack?.length > 0) { 49469 return prefixStack.at(-1); 49470 } 49471 warn(`Unknown namespace prefix: ${prefix}.`); 49472 return null; 49473 } 49474 clean(data) { 49475 const { 49476 hasNamespace, 49477 prefixes, 49478 nsAgnostic 49479 } = data; 49480 if (hasNamespace) { 49481 this._currentNamespace = this._namespaceStack.pop(); 49482 } 49483 if (prefixes) { 49484 prefixes.forEach(({ 49485 prefix 49486 }) => { 49487 this._namespacePrefixes.get(prefix).pop(); 49488 }); 49489 } 49490 if (nsAgnostic) { 49491 this._nsAgnosticLevel--; 49492 } 49493 } 49494} 49495 49496;// ./src/core/xfa/parser.js 49497 49498 49499 49500 49501class XFAParser extends XMLParserBase { 49502 constructor(rootNameSpace = null, richText = false) { 49503 super(); 49504 this._builder = new Builder(rootNameSpace); 49505 this._stack = []; 49506 this._globalData = { 49507 usedTypefaces: new Set() 49508 }; 49509 this._ids = new Map(); 49510 this._current = this._builder.buildRoot(this._ids); 49511 this._errorCode = XMLParserErrorCode.NoError; 49512 this._whiteRegex = /^\s+$/; 49513 this._nbsps = /\xa0+/g; 49514 this._richText = richText; 49515 } 49516 parse(data) { 49517 this.parseXml(data); 49518 if (this._errorCode !== XMLParserErrorCode.NoError) { 49519 return undefined; 49520 } 49521 this._current[$finalize](); 49522 return this._current.element; 49523 } 49524 onText(text) { 49525 text = text.replace(this._nbsps, match => match.slice(1) + " "); 49526 if (this._richText || this._current[$acceptWhitespace]()) { 49527 this._current[$onText](text, this._richText); 49528 return; 49529 } 49530 if (this._whiteRegex.test(text)) { 49531 return; 49532 } 49533 this._current[$onText](text.trim()); 49534 } 49535 onCdata(text) { 49536 this._current[$onText](text); 49537 } 49538 _mkAttributes(attributes, tagName) { 49539 let namespace = null; 49540 let prefixes = null; 49541 const attributeObj = Object.create({}); 49542 for (const { 49543 name, 49544 value 49545 } of attributes) { 49546 if (name === "xmlns") { 49547 if (!namespace) { 49548 namespace = value; 49549 } else { 49550 warn(`XFA - multiple namespace definition in <${tagName}>`); 49551 } 49552 } else if (name.startsWith("xmlns:")) { 49553 const prefix = name.substring("xmlns:".length); 49554 prefixes ??= []; 49555 prefixes.push({ 49556 prefix, 49557 value 49558 }); 49559 } else { 49560 const i = name.indexOf(":"); 49561 if (i === -1) { 49562 attributeObj[name] = value; 49563 } else { 49564 const nsAttrs = attributeObj[$nsAttributes] ??= Object.create(null); 49565 const [ns, attrName] = [name.slice(0, i), name.slice(i + 1)]; 49566 const attrs = nsAttrs[ns] ||= Object.create(null); 49567 attrs[attrName] = value; 49568 } 49569 } 49570 } 49571 return [namespace, prefixes, attributeObj]; 49572 } 49573 _getNameAndPrefix(name, nsAgnostic) { 49574 const i = name.indexOf(":"); 49575 if (i === -1) { 49576 return [name, null]; 49577 } 49578 return [name.substring(i + 1), nsAgnostic ? "" : name.substring(0, i)]; 49579 } 49580 onBeginElement(tagName, attributes, isEmpty) { 49581 const [namespace, prefixes, attributesObj] = this._mkAttributes(attributes, tagName); 49582 const [name, nsPrefix] = this._getNameAndPrefix(tagName, this._builder.isNsAgnostic()); 49583 const node = this._builder.build({ 49584 nsPrefix, 49585 name, 49586 attributes: attributesObj, 49587 namespace, 49588 prefixes 49589 }); 49590 node[$globalData] = this._globalData; 49591 if (isEmpty) { 49592 node[$finalize](); 49593 if (this._current[$onChild](node)) { 49594 node[$setId](this._ids); 49595 } 49596 node[$clean](this._builder); 49597 return; 49598 } 49599 this._stack.push(this._current); 49600 this._current = node; 49601 } 49602 onEndElement(name) { 49603 const node = this._current; 49604 if (node[$isCDATAXml]() && typeof node[$content] === "string") { 49605 const parser = new XFAParser(); 49606 parser._globalData = this._globalData; 49607 const root = parser.parse(node[$content]); 49608 node[$content] = null; 49609 node[$onChild](root); 49610 } 49611 node[$finalize](); 49612 this._current = this._stack.pop(); 49613 if (this._current[$onChild](node)) { 49614 node[$setId](this._ids); 49615 } 49616 node[$clean](this._builder); 49617 } 49618 onError(code) { 49619 this._errorCode = code; 49620 } 49621} 49622 49623;// ./src/core/xfa/factory.js 49624 49625 49626 49627 49628 49629 49630 49631 49632class XFAFactory { 49633 constructor(data) { 49634 try { 49635 this.root = new XFAParser().parse(XFAFactory._createDocument(data)); 49636 const binder = new Binder(this.root); 49637 this.form = binder.bind(); 49638 this.dataHandler = new DataHandler(this.root, binder.getData()); 49639 this.form[$globalData].template = this.form; 49640 } catch (e) { 49641 warn(`XFA - an error occurred during parsing and binding: ${e}`); 49642 } 49643 } 49644 isValid() { 49645 return !!(this.root && this.form); 49646 } 49647 _createPagesHelper() { 49648 const iterator = this.form[$toPages](); 49649 return new Promise((resolve, reject) => { 49650 const nextIteration = () => { 49651 try { 49652 const value = iterator.next(); 49653 if (value.done) { 49654 resolve(value.value); 49655 } else { 49656 setTimeout(nextIteration, 0); 49657 } 49658 } catch (e) { 49659 reject(e); 49660 } 49661 }; 49662 setTimeout(nextIteration, 0); 49663 }); 49664 } 49665 async _createPages() { 49666 try { 49667 this.pages = await this._createPagesHelper(); 49668 this.dims = this.pages.children.map(c => { 49669 const { 49670 width, 49671 height 49672 } = c.attributes.style; 49673 return [0, 0, parseInt(width), parseInt(height)]; 49674 }); 49675 } catch (e) { 49676 warn(`XFA - an error occurred during layout: ${e}`); 49677 } 49678 } 49679 getBoundingBox(pageIndex) { 49680 return this.dims[pageIndex]; 49681 } 49682 async getNumPages() { 49683 if (!this.pages) { 49684 await this._createPages(); 49685 } 49686 return this.dims.length; 49687 } 49688 setImages(images) { 49689 this.form[$globalData].images = images; 49690 } 49691 setFonts(fonts) { 49692 this.form[$globalData].fontFinder = new FontFinder(fonts); 49693 const missingFonts = []; 49694 for (let typeface of this.form[$globalData].usedTypefaces) { 49695 typeface = stripQuotes(typeface); 49696 const font = this.form[$globalData].fontFinder.find(typeface); 49697 if (!font) { 49698 missingFonts.push(typeface); 49699 } 49700 } 49701 if (missingFonts.length > 0) { 49702 return missingFonts; 49703 } 49704 return null; 49705 } 49706 appendFonts(fonts, reallyMissingFonts) { 49707 this.form[$globalData].fontFinder.add(fonts, reallyMissingFonts); 49708 } 49709 async getPages() { 49710 if (!this.pages) { 49711 await this._createPages(); 49712 } 49713 const pages = this.pages; 49714 this.pages = null; 49715 return pages; 49716 } 49717 serializeData(storage) { 49718 return this.dataHandler.serialize(storage); 49719 } 49720 static _createDocument(data) { 49721 if (!data["/xdp:xdp"]) { 49722 return data["xdp:xdp"]; 49723 } 49724 return Object.values(data).join(""); 49725 } 49726 static getRichTextAsHtml(rc) { 49727 if (!rc || typeof rc !== "string") { 49728 return null; 49729 } 49730 try { 49731 let root = new XFAParser(XhtmlNamespace, true).parse(rc); 49732 if (!["body", "xhtml"].includes(root[$nodeName])) { 49733 const newRoot = XhtmlNamespace.body({}); 49734 newRoot[$appendChild](root); 49735 root = newRoot; 49736 } 49737 const result = root[$toHTML](); 49738 if (!result.success) { 49739 return null; 49740 } 49741 const { 49742 html 49743 } = result; 49744 const { 49745 attributes 49746 } = html; 49747 if (attributes) { 49748 if (attributes.class) { 49749 attributes.class = attributes.class.filter(attr => !attr.startsWith("xfa")); 49750 } 49751 attributes.dir = "auto"; 49752 } 49753 return { 49754 html, 49755 str: root[$text]() 49756 }; 49757 } catch (e) { 49758 warn(`XFA - an error occurred during parsing of rich text: ${e}`); 49759 } 49760 return null; 49761 } 49762} 49763 49764;// ./src/core/annotation.js
vendor: 122,643 bytes, lines 49764-53378
49764 49765 49766 49767 49768 49769 49770 49771 49772 49773 49774 49775 49776 49777 49778 49779 49780class AnnotationFactory { 49781 static createGlobals(pdfManager) { 49782 return Promise.all([pdfManager.ensureCatalog("acroForm"), pdfManager.ensureDoc("xfaDatasets"), pdfManager.ensureCatalog("structTreeRoot"), pdfManager.ensureCatalog("baseUrl"), pdfManager.ensureCatalog("attachments"), pdfManager.ensureCatalog("globalColorSpaceCache")]).then(([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments, globalColorSpaceCache]) => ({ 49783 pdfManager, 49784 acroForm: acroForm instanceof Dict ? acroForm : Dict.empty, 49785 xfaDatasets, 49786 structTreeRoot, 49787 baseUrl, 49788 attachments, 49789 globalColorSpaceCache 49790 }), reason => { 49791 warn(`createGlobals: "${reason}".`); 49792 return null; 49793 }); 49794 } 49795 static async create(xref, ref, annotationGlobals, idFactory, collectFields, orphanFields, collectByType, pageRef) { 49796 const pageIndex = collectFields ? await this._getPageIndex(xref, ref, annotationGlobals.pdfManager) : null; 49797 return annotationGlobals.pdfManager.ensure(this, "_create", [xref, ref, annotationGlobals, idFactory, collectFields, orphanFields, collectByType, pageIndex, pageRef]); 49798 } 49799 static _create(xref, ref, annotationGlobals, idFactory, collectFields = false, orphanFields = null, collectByType = null, pageIndex = null, pageRef = null) { 49800 const dict = xref.fetchIfRef(ref); 49801 if (!(dict instanceof Dict)) { 49802 return undefined; 49803 } 49804 let subtype = dict.get("Subtype"); 49805 subtype = subtype instanceof Name ? subtype.name : null; 49806 if (collectByType && !collectByType.has(AnnotationType[subtype.toUpperCase()])) { 49807 return null; 49808 } 49809 const { 49810 acroForm, 49811 pdfManager 49812 } = annotationGlobals; 49813 const id = ref instanceof Ref ? ref.toString() : `annot_${idFactory.createObjId()}`; 49814 const parameters = { 49815 xref, 49816 ref, 49817 dict, 49818 subtype, 49819 id, 49820 annotationGlobals, 49821 collectFields, 49822 orphanFields, 49823 needAppearances: !collectFields && acroForm.get("NeedAppearances") === true, 49824 pageIndex, 49825 evaluatorOptions: pdfManager.evaluatorOptions, 49826 pageRef 49827 }; 49828 switch (subtype) { 49829 case "Link": 49830 return new LinkAnnotation(parameters); 49831 case "Text": 49832 return new TextAnnotation(parameters); 49833 case "Widget": 49834 let fieldType = getInheritableProperty({ 49835 dict, 49836 key: "FT" 49837 }); 49838 fieldType = fieldType instanceof Name ? fieldType.name : null; 49839 switch (fieldType) { 49840 case "Tx": 49841 return new TextWidgetAnnotation(parameters); 49842 case "Btn": 49843 return new ButtonWidgetAnnotation(parameters); 49844 case "Ch": 49845 return new ChoiceWidgetAnnotation(parameters); 49846 case "Sig": 49847 return new SignatureWidgetAnnotation(parameters); 49848 } 49849 warn(`Unimplemented widget field type "${fieldType}", ` + "falling back to base field type."); 49850 return new WidgetAnnotation(parameters); 49851 case "Popup": 49852 return new PopupAnnotation(parameters); 49853 case "FreeText": 49854 return new FreeTextAnnotation(parameters); 49855 case "Line": 49856 return new LineAnnotation(parameters); 49857 case "Square": 49858 return new SquareAnnotation(parameters); 49859 case "Circle": 49860 return new CircleAnnotation(parameters); 49861 case "PolyLine": 49862 return new PolylineAnnotation(parameters); 49863 case "Polygon": 49864 return new PolygonAnnotation(parameters); 49865 case "Caret": 49866 return new CaretAnnotation(parameters); 49867 case "Ink": 49868 return new InkAnnotation(parameters); 49869 case "Highlight": 49870 return new HighlightAnnotation(parameters); 49871 case "Underline": 49872 return new UnderlineAnnotation(parameters); 49873 case "Squiggly": 49874 return new SquigglyAnnotation(parameters); 49875 case "StrikeOut": 49876 return new StrikeOutAnnotation(parameters); 49877 case "Stamp": 49878 return new StampAnnotation(parameters); 49879 case "FileAttachment": 49880 return new FileAttachmentAnnotation(parameters); 49881 default: 49882 if (!collectFields) { 49883 if (!subtype) { 49884 warn("Annotation is missing the required /Subtype."); 49885 } else { 49886 warn(`Unimplemented annotation type "${subtype}", ` + "falling back to base annotation."); 49887 } 49888 } 49889 return new Annotation(parameters); 49890 } 49891 } 49892 static async _getPageIndex(xref, ref, pdfManager) { 49893 try { 49894 const annotDict = await xref.fetchIfRefAsync(ref); 49895 if (!(annotDict instanceof Dict)) { 49896 return -1; 49897 } 49898 const pageRef = annotDict.getRaw("P"); 49899 if (pageRef instanceof Ref) { 49900 try { 49901 const pageIndex = await pdfManager.ensureCatalog("getPageIndex", [pageRef]); 49902 return pageIndex; 49903 } catch (ex) { 49904 info(`_getPageIndex -- not a valid page reference: "${ex}".`); 49905 } 49906 } 49907 if (annotDict.has("Kids")) { 49908 return -1; 49909 } 49910 const numPages = await pdfManager.ensureDoc("numPages"); 49911 for (let pageIndex = 0; pageIndex < numPages; pageIndex++) { 49912 const page = await pdfManager.getPage(pageIndex); 49913 const annotations = await pdfManager.ensure(page, "annotations"); 49914 for (const annotRef of annotations) { 49915 if (annotRef instanceof Ref && isRefsEqual(annotRef, ref)) { 49916 return pageIndex; 49917 } 49918 } 49919 } 49920 } catch (ex) { 49921 warn(`_getPageIndex: "${ex}".`); 49922 } 49923 return -1; 49924 } 49925 static generateImages(annotations, xref, isOffscreenCanvasSupported) { 49926 if (!isOffscreenCanvasSupported) { 49927 warn("generateImages: OffscreenCanvas is not supported, cannot save or print some annotations with images."); 49928 return null; 49929 } 49930 let imagePromises; 49931 for (const { 49932 bitmapId, 49933 bitmap 49934 } of annotations) { 49935 if (!bitmap) { 49936 continue; 49937 } 49938 imagePromises ||= new Map(); 49939 imagePromises.set(bitmapId, StampAnnotation.createImage(bitmap, xref)); 49940 } 49941 return imagePromises; 49942 } 49943 static async saveNewAnnotations(evaluator, task, annotations, imagePromises, changes) { 49944 const xref = evaluator.xref; 49945 let baseFontRef; 49946 const promises = []; 49947 const { 49948 isOffscreenCanvasSupported 49949 } = evaluator.options; 49950 for (const annotation of annotations) { 49951 if (annotation.deleted) { 49952 continue; 49953 } 49954 switch (annotation.annotationType) { 49955 case AnnotationEditorType.FREETEXT: 49956 if (!baseFontRef) { 49957 const baseFont = new Dict(xref); 49958 baseFont.setIfName("BaseFont", "Helvetica"); 49959 baseFont.setIfName("Type", "Font"); 49960 baseFont.setIfName("Subtype", "Type1"); 49961 baseFont.setIfName("Encoding", "WinAnsiEncoding"); 49962 baseFontRef = xref.getNewTemporaryRef(); 49963 changes.put(baseFontRef, { 49964 data: baseFont 49965 }); 49966 } 49967 promises.push(FreeTextAnnotation.createNewAnnotation(xref, annotation, changes, { 49968 evaluator, 49969 task, 49970 baseFontRef 49971 })); 49972 break; 49973 case AnnotationEditorType.HIGHLIGHT: 49974 if (annotation.quadPoints) { 49975 promises.push(HighlightAnnotation.createNewAnnotation(xref, annotation, changes)); 49976 } else { 49977 promises.push(InkAnnotation.createNewAnnotation(xref, annotation, changes)); 49978 } 49979 break; 49980 case AnnotationEditorType.INK: 49981 promises.push(InkAnnotation.createNewAnnotation(xref, annotation, changes)); 49982 break; 49983 case AnnotationEditorType.STAMP: 49984 const image = isOffscreenCanvasSupported ? await imagePromises?.get(annotation.bitmapId) : null; 49985 if (image?.imageStream) { 49986 const { 49987 imageStream, 49988 smaskStream 49989 } = image; 49990 if (smaskStream) { 49991 const smaskRef = xref.getNewTemporaryRef(); 49992 changes.put(smaskRef, { 49993 data: smaskStream 49994 }); 49995 imageStream.dict.set("SMask", smaskRef); 49996 } 49997 const imageRef = image.imageRef = xref.getNewTemporaryRef(); 49998 changes.put(imageRef, { 49999 data: imageStream 50000 }); 50001 image.imageStream = image.smaskStream = null; 50002 } 50003 promises.push(StampAnnotation.createNewAnnotation(xref, annotation, changes, { 50004 image 50005 })); 50006 break; 50007 case AnnotationEditorType.SIGNATURE: 50008 promises.push(StampAnnotation.createNewAnnotation(xref, annotation, changes, {})); 50009 break; 50010 } 50011 } 50012 return { 50013 annotations: (await Promise.all(promises)).flat() 50014 }; 50015 } 50016 static async printNewAnnotations(annotationGlobals, evaluator, task, annotations, imagePromises) { 50017 if (!annotations) { 50018 return null; 50019 } 50020 const { 50021 options, 50022 xref 50023 } = evaluator; 50024 const promises = []; 50025 for (const annotation of annotations) { 50026 if (annotation.deleted) { 50027 continue; 50028 } 50029 switch (annotation.annotationType) { 50030 case AnnotationEditorType.FREETEXT: 50031 promises.push(FreeTextAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, { 50032 evaluator, 50033 task, 50034 evaluatorOptions: options 50035 })); 50036 break; 50037 case AnnotationEditorType.HIGHLIGHT: 50038 if (annotation.quadPoints) { 50039 promises.push(HighlightAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, { 50040 evaluatorOptions: options 50041 })); 50042 } else { 50043 promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, { 50044 evaluatorOptions: options 50045 })); 50046 } 50047 break; 50048 case AnnotationEditorType.INK: 50049 promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, { 50050 evaluatorOptions: options 50051 })); 50052 break; 50053 case AnnotationEditorType.STAMP: 50054 const image = options.isOffscreenCanvasSupported ? await imagePromises?.get(annotation.bitmapId) : null; 50055 if (image?.imageStream) { 50056 const { 50057 imageStream, 50058 smaskStream 50059 } = image; 50060 if (smaskStream) { 50061 imageStream.dict.set("SMask", smaskStream); 50062 } 50063 image.imageRef = new JpegStream(imageStream, imageStream.length); 50064 image.imageStream = image.smaskStream = null; 50065 } 50066 promises.push(StampAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, { 50067 image, 50068 evaluatorOptions: options 50069 })); 50070 break; 50071 case AnnotationEditorType.SIGNATURE: 50072 promises.push(StampAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, { 50073 evaluatorOptions: options 50074 })); 50075 break; 50076 } 50077 } 50078 return Promise.all(promises); 50079 } 50080} 50081function getRgbColor(color, defaultColor = new Uint8ClampedArray(3)) { 50082 if (!Array.isArray(color)) { 50083 return defaultColor; 50084 } 50085 const rgbColor = defaultColor || new Uint8ClampedArray(3); 50086 switch (color.length) { 50087 case 0: 50088 return null; 50089 case 1: 50090 ColorSpaceUtils.gray.getRgbItem(color, 0, rgbColor, 0); 50091 return rgbColor; 50092 case 3: 50093 ColorSpaceUtils.rgb.getRgbItem(color, 0, rgbColor, 0); 50094 return rgbColor; 50095 case 4: 50096 ColorSpaceUtils.cmyk.getRgbItem(color, 0, rgbColor, 0); 50097 return rgbColor; 50098 default: 50099 return defaultColor; 50100 } 50101} 50102function getPdfColorArray(color, defaultValue = null) { 50103 return color && Array.from(color, c => c / 255) || defaultValue; 50104} 50105function getQuadPoints(dict, rect) { 50106 const quadPoints = dict.getArray("QuadPoints"); 50107 if (!isNumberArray(quadPoints, null) || quadPoints.length === 0 || quadPoints.length % 8 > 0) { 50108 return null; 50109 } 50110 const newQuadPoints = new Float32Array(quadPoints.length); 50111 for (let i = 0, ii = quadPoints.length; i < ii; i += 8) { 50112 const [x1, y1, x2, y2, x3, y3, x4, y4] = quadPoints.slice(i, i + 8); 50113 const minX = Math.min(x1, x2, x3, x4); 50114 const maxX = Math.max(x1, x2, x3, x4); 50115 const minY = Math.min(y1, y2, y3, y4); 50116 const maxY = Math.max(y1, y2, y3, y4); 50117 if (rect !== null && (minX < rect[0] || maxX > rect[2] || minY < rect[1] || maxY > rect[3])) { 50118 return null; 50119 } 50120 newQuadPoints.set([minX, maxY, maxX, maxY, minX, minY, maxX, minY], i); 50121 } 50122 return newQuadPoints; 50123} 50124function getTransformMatrix(rect, bbox, matrix) { 50125 const minMax = new Float32Array([Infinity, Infinity, -Infinity, -Infinity]); 50126 Util.axialAlignedBoundingBox(bbox, matrix, minMax); 50127 const [minX, minY, maxX, maxY] = minMax; 50128 if (minX === maxX || minY === maxY) { 50129 return [1, 0, 0, 1, rect[0], rect[1]]; 50130 } 50131 const xRatio = (rect[2] - rect[0]) / (maxX - minX); 50132 const yRatio = (rect[3] - rect[1]) / (maxY - minY); 50133 return [xRatio, 0, 0, yRatio, rect[0] - minX * xRatio, rect[1] - minY * yRatio]; 50134} 50135class Annotation { 50136 constructor(params) { 50137 const { 50138 dict, 50139 xref, 50140 annotationGlobals, 50141 ref, 50142 orphanFields 50143 } = params; 50144 const parentRef = orphanFields?.get(ref); 50145 if (parentRef) { 50146 dict.set("Parent", parentRef); 50147 } 50148 this.setTitle(dict.get("T")); 50149 this.setContents(dict.get("Contents")); 50150 this.setModificationDate(dict.get("M")); 50151 this.setFlags(dict.get("F")); 50152 this.setRectangle(dict.getArray("Rect")); 50153 this.setColor(dict.getArray("C")); 50154 this.setBorderStyle(dict); 50155 this.setAppearance(dict); 50156 this.setOptionalContent(dict); 50157 const MK = dict.get("MK"); 50158 this.setBorderAndBackgroundColors(MK); 50159 this.setRotation(MK, dict); 50160 this.ref = params.ref instanceof Ref ? params.ref : null; 50161 this._streams = []; 50162 if (this.appearance) { 50163 this._streams.push(this.appearance); 50164 } 50165 const isLocked = !!(this.flags & AnnotationFlag.LOCKED); 50166 const isContentLocked = !!(this.flags & AnnotationFlag.LOCKEDCONTENTS); 50167 this.data = { 50168 annotationFlags: this.flags, 50169 borderStyle: this.borderStyle, 50170 color: this.color, 50171 backgroundColor: this.backgroundColor, 50172 borderColor: this.borderColor, 50173 rotation: this.rotation, 50174 contentsObj: this._contents, 50175 hasAppearance: !!this.appearance, 50176 id: params.id, 50177 modificationDate: this.modificationDate, 50178 rect: this.rectangle, 50179 subtype: params.subtype, 50180 hasOwnCanvas: false, 50181 noRotate: !!(this.flags & AnnotationFlag.NOROTATE), 50182 noHTML: isLocked && isContentLocked, 50183 isEditable: false, 50184 structParent: -1 50185 }; 50186 if (annotationGlobals.structTreeRoot) { 50187 let structParent = dict.get("StructParent"); 50188 this.data.structParent = structParent = Number.isInteger(structParent) && structParent >= 0 ? structParent : -1; 50189 annotationGlobals.structTreeRoot.addAnnotationIdToPage(params.pageRef, structParent); 50190 } 50191 if (params.collectFields) { 50192 const kids = dict.get("Kids"); 50193 if (Array.isArray(kids)) { 50194 const kidIds = []; 50195 for (const kid of kids) { 50196 if (kid instanceof Ref) { 50197 kidIds.push(kid.toString()); 50198 } 50199 } 50200 if (kidIds.length !== 0) { 50201 this.data.kidIds = kidIds; 50202 } 50203 } 50204 this.data.actions = collectActions(xref, dict, AnnotationActionEventType); 50205 this.data.fieldName = this._constructFieldName(dict); 50206 this.data.pageIndex = params.pageIndex; 50207 } 50208 const it = dict.get("IT"); 50209 if (it instanceof Name) { 50210 this.data.it = it.name; 50211 } 50212 this._isOffscreenCanvasSupported = params.evaluatorOptions.isOffscreenCanvasSupported; 50213 this._fallbackFontDict = null; 50214 this._needAppearances = false; 50215 } 50216 _hasFlag(flags, flag) { 50217 return !!(flags & flag); 50218 } 50219 _buildFlags(noView, noPrint) { 50220 let { 50221 flags 50222 } = this; 50223 if (noView === undefined) { 50224 if (noPrint === undefined) { 50225 return undefined; 50226 } 50227 if (noPrint) { 50228 return flags & ~AnnotationFlag.PRINT; 50229 } 50230 return flags & ~AnnotationFlag.HIDDEN | AnnotationFlag.PRINT; 50231 } 50232 if (noView) { 50233 flags |= AnnotationFlag.PRINT; 50234 if (noPrint) { 50235 return flags & ~AnnotationFlag.NOVIEW | AnnotationFlag.HIDDEN; 50236 } 50237 return flags & ~AnnotationFlag.HIDDEN | AnnotationFlag.NOVIEW; 50238 } 50239 flags &= ~(AnnotationFlag.HIDDEN | AnnotationFlag.NOVIEW); 50240 if (noPrint) { 50241 return flags & ~AnnotationFlag.PRINT; 50242 } 50243 return flags | AnnotationFlag.PRINT; 50244 } 50245 _isViewable(flags) { 50246 return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.NOVIEW); 50247 } 50248 _isPrintable(flags) { 50249 return this._hasFlag(flags, AnnotationFlag.PRINT) && !this._hasFlag(flags, AnnotationFlag.HIDDEN) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE); 50250 } 50251 mustBeViewed(annotationStorage, _renderForms) { 50252 const noView = annotationStorage?.get(this.data.id)?.noView; 50253 if (noView !== undefined) { 50254 return !noView; 50255 } 50256 return this.viewable && !this._hasFlag(this.flags, AnnotationFlag.HIDDEN); 50257 } 50258 mustBePrinted(annotationStorage) { 50259 const noPrint = annotationStorage?.get(this.data.id)?.noPrint; 50260 if (noPrint !== undefined) { 50261 return !noPrint; 50262 } 50263 return this.printable; 50264 } 50265 mustBeViewedWhenEditing(isEditing, modifiedIds = null) { 50266 return isEditing ? !this.data.isEditable : !modifiedIds?.has(this.data.id); 50267 } 50268 get viewable() { 50269 if (this.data.quadPoints === null) { 50270 return false; 50271 } 50272 if (this.flags === 0) { 50273 return true; 50274 } 50275 return this._isViewable(this.flags); 50276 } 50277 get printable() { 50278 if (this.data.quadPoints === null) { 50279 return false; 50280 } 50281 if (this.flags === 0) { 50282 return false; 50283 } 50284 return this._isPrintable(this.flags); 50285 } 50286 _parseStringHelper(data) { 50287 const str = typeof data === "string" ? stringToPDFString(data) : ""; 50288 const dir = str && bidi(str).dir === "rtl" ? "rtl" : "ltr"; 50289 return { 50290 str, 50291 dir 50292 }; 50293 } 50294 setDefaultAppearance(params) { 50295 const { 50296 dict, 50297 annotationGlobals 50298 } = params; 50299 const defaultAppearance = getInheritableProperty({ 50300 dict, 50301 key: "DA" 50302 }) || annotationGlobals.acroForm.get("DA"); 50303 this._defaultAppearance = typeof defaultAppearance === "string" ? defaultAppearance : ""; 50304 this.data.defaultAppearanceData = parseDefaultAppearance(this._defaultAppearance); 50305 } 50306 setTitle(title) { 50307 this._title = this._parseStringHelper(title); 50308 } 50309 setContents(contents) { 50310 this._contents = this._parseStringHelper(contents); 50311 } 50312 setModificationDate(modificationDate) { 50313 this.modificationDate = typeof modificationDate === "string" ? modificationDate : null; 50314 } 50315 setFlags(flags) { 50316 this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0; 50317 if (this.flags & AnnotationFlag.INVISIBLE && this.constructor.name !== "Annotation") { 50318 this.flags ^= AnnotationFlag.INVISIBLE; 50319 } 50320 } 50321 hasFlag(flag) { 50322 return this._hasFlag(this.flags, flag); 50323 } 50324 setRectangle(rectangle) { 50325 this.rectangle = lookupNormalRect(rectangle, [0, 0, 0, 0]); 50326 } 50327 setColor(color) { 50328 this.color = getRgbColor(color); 50329 } 50330 setLineEndings(lineEndings) { 50331 this.lineEndings = ["None", "None"]; 50332 if (Array.isArray(lineEndings) && lineEndings.length === 2) { 50333 for (let i = 0; i < 2; i++) { 50334 const obj = lineEndings[i]; 50335 if (obj instanceof Name) { 50336 switch (obj.name) { 50337 case "None": 50338 continue; 50339 case "Square": 50340 case "Circle": 50341 case "Diamond": 50342 case "OpenArrow": 50343 case "ClosedArrow": 50344 case "Butt": 50345 case "ROpenArrow": 50346 case "RClosedArrow": 50347 case "Slash": 50348 this.lineEndings[i] = obj.name; 50349 continue; 50350 } 50351 } 50352 warn(`Ignoring invalid lineEnding: ${obj}`); 50353 } 50354 } 50355 } 50356 setRotation(mk, dict) { 50357 this.rotation = 0; 50358 let angle = mk instanceof Dict ? mk.get("R") || 0 : dict.get("Rotate") || 0; 50359 if (Number.isInteger(angle) && angle !== 0) { 50360 angle %= 360; 50361 if (angle < 0) { 50362 angle += 360; 50363 } 50364 if (angle % 90 === 0) { 50365 this.rotation = angle; 50366 } 50367 } 50368 } 50369 setBorderAndBackgroundColors(mk) { 50370 if (mk instanceof Dict) { 50371 this.borderColor = getRgbColor(mk.getArray("BC"), null); 50372 this.backgroundColor = getRgbColor(mk.getArray("BG"), null); 50373 } else { 50374 this.borderColor = this.backgroundColor = null; 50375 } 50376 } 50377 setBorderStyle(borderStyle) { 50378 this.borderStyle = new AnnotationBorderStyle(); 50379 if (!(borderStyle instanceof Dict)) { 50380 return; 50381 } 50382 if (borderStyle.has("BS")) { 50383 const dict = borderStyle.get("BS"); 50384 if (dict instanceof Dict) { 50385 const dictType = dict.get("Type"); 50386 if (!dictType || isName(dictType, "Border")) { 50387 this.borderStyle.setWidth(dict.get("W"), this.rectangle); 50388 this.borderStyle.setStyle(dict.get("S")); 50389 this.borderStyle.setDashArray(dict.getArray("D")); 50390 } 50391 } 50392 } else if (borderStyle.has("Border")) { 50393 const array = borderStyle.getArray("Border"); 50394 if (Array.isArray(array) && array.length >= 3) { 50395 this.borderStyle.setHorizontalCornerRadius(array[0]); 50396 this.borderStyle.setVerticalCornerRadius(array[1]); 50397 this.borderStyle.setWidth(array[2], this.rectangle); 50398 if (array.length === 4) { 50399 this.borderStyle.setDashArray(array[3], true); 50400 } 50401 } 50402 } else { 50403 this.borderStyle.setWidth(0); 50404 } 50405 } 50406 setAppearance(dict) { 50407 this.appearance = null; 50408 const appearanceStates = dict.get("AP"); 50409 if (!(appearanceStates instanceof Dict)) { 50410 return; 50411 } 50412 const normalAppearanceState = appearanceStates.get("N"); 50413 if (normalAppearanceState instanceof BaseStream) { 50414 this.appearance = normalAppearanceState; 50415 return; 50416 } 50417 if (!(normalAppearanceState instanceof Dict)) { 50418 return; 50419 } 50420 const as = dict.get("AS"); 50421 if (!(as instanceof Name) || !normalAppearanceState.has(as.name)) { 50422 return; 50423 } 50424 const appearance = normalAppearanceState.get(as.name); 50425 if (appearance instanceof BaseStream) { 50426 this.appearance = appearance; 50427 } 50428 } 50429 setOptionalContent(dict) { 50430 this.oc = null; 50431 const oc = dict.get("OC"); 50432 if (oc instanceof Name) { 50433 warn("setOptionalContent: Support for /Name-entry is not implemented."); 50434 } else if (oc instanceof Dict) { 50435 this.oc = oc; 50436 } 50437 } 50438 async loadResources(keys, appearance) { 50439 const resources = await appearance.dict.getAsync("Resources"); 50440 if (resources) { 50441 await ObjectLoader.load(resources, keys, resources.xref); 50442 } 50443 return resources; 50444 } 50445 async getOperatorList(evaluator, task, intent, annotationStorage) { 50446 const { 50447 hasOwnCanvas, 50448 id, 50449 rect 50450 } = this.data; 50451 let appearance = this.appearance; 50452 const isUsingOwnCanvas = !!(hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY); 50453 if (isUsingOwnCanvas && (this.width === 0 || this.height === 0)) { 50454 this.data.hasOwnCanvas = false; 50455 return { 50456 opList: new OperatorList(), 50457 separateForm: false, 50458 separateCanvas: false 50459 }; 50460 } 50461 if (!appearance) { 50462 if (!isUsingOwnCanvas) { 50463 return { 50464 opList: new OperatorList(), 50465 separateForm: false, 50466 separateCanvas: false 50467 }; 50468 } 50469 appearance = new StringStream(""); 50470 appearance.dict = new Dict(); 50471 } 50472 const appearanceDict = appearance.dict; 50473 const resources = await this.loadResources(RESOURCES_KEYS_OPERATOR_LIST, appearance); 50474 const bbox = lookupRect(appearanceDict.getArray("BBox"), [0, 0, 1, 1]); 50475 const matrix = lookupMatrix(appearanceDict.getArray("Matrix"), IDENTITY_MATRIX); 50476 const transform = getTransformMatrix(rect, bbox, matrix); 50477 const opList = new OperatorList(); 50478 let optionalContent; 50479 if (this.oc) { 50480 optionalContent = await evaluator.parseMarkedContentProps(this.oc, null); 50481 } 50482 if (optionalContent !== undefined) { 50483 opList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]); 50484 } 50485 opList.addOp(OPS.beginAnnotation, [id, rect, transform, matrix, isUsingOwnCanvas]); 50486 await evaluator.getOperatorList({ 50487 stream: appearance, 50488 task, 50489 resources, 50490 operatorList: opList, 50491 fallbackFontDict: this._fallbackFontDict 50492 }); 50493 opList.addOp(OPS.endAnnotation, []); 50494 if (optionalContent !== undefined) { 50495 opList.addOp(OPS.endMarkedContent, []); 50496 } 50497 this.reset(); 50498 return { 50499 opList, 50500 separateForm: false, 50501 separateCanvas: isUsingOwnCanvas 50502 }; 50503 } 50504 async save(evaluator, task, annotationStorage, changes) { 50505 return null; 50506 } 50507 get overlaysTextContent() { 50508 return false; 50509 } 50510 get hasTextContent() { 50511 return false; 50512 } 50513 async extractTextContent(evaluator, task, viewBox) { 50514 if (!this.appearance) { 50515 return; 50516 } 50517 const resources = await this.loadResources(RESOURCES_KEYS_TEXT_CONTENT, this.appearance); 50518 const text = []; 50519 const buffer = []; 50520 let firstPosition = null; 50521 const sink = { 50522 desiredSize: Math.Infinity, 50523 ready: true, 50524 enqueue(chunk, size) { 50525 for (const item of chunk.items) { 50526 if (item.str === undefined) { 50527 continue; 50528 } 50529 firstPosition ||= item.transform.slice(-2); 50530 buffer.push(item.str); 50531 if (item.hasEOL) { 50532 text.push(buffer.join("").trimEnd()); 50533 buffer.length = 0; 50534 } 50535 } 50536 } 50537 }; 50538 await evaluator.getTextContent({ 50539 stream: this.appearance, 50540 task, 50541 resources, 50542 includeMarkedContent: true, 50543 keepWhiteSpace: true, 50544 sink, 50545 viewBox 50546 }); 50547 this.reset(); 50548 if (buffer.length) { 50549 text.push(buffer.join("").trimEnd()); 50550 } 50551 if (text.length > 1 || text[0]) { 50552 const appearanceDict = this.appearance.dict; 50553 const bbox = lookupRect(appearanceDict.getArray("BBox"), null); 50554 const matrix = lookupMatrix(appearanceDict.getArray("Matrix"), null); 50555 this.data.textPosition = this._transformPoint(firstPosition, bbox, matrix); 50556 this.data.textContent = text; 50557 } 50558 } 50559 _transformPoint(coords, bbox, matrix) { 50560 const { 50561 rect 50562 } = this.data; 50563 bbox ||= [0, 0, 1, 1]; 50564 matrix ||= [1, 0, 0, 1, 0, 0]; 50565 const transform = getTransformMatrix(rect, bbox, matrix); 50566 transform[4] -= rect[0]; 50567 transform[5] -= rect[1]; 50568 const p = coords.slice(); 50569 Util.applyTransform(p, transform); 50570 Util.applyTransform(p, matrix); 50571 return p; 50572 } 50573 getFieldObject() { 50574 if (this.data.kidIds) { 50575 return { 50576 id: this.data.id, 50577 actions: this.data.actions, 50578 name: this.data.fieldName, 50579 strokeColor: this.data.borderColor, 50580 fillColor: this.data.backgroundColor, 50581 type: "", 50582 kidIds: this.data.kidIds, 50583 page: this.data.pageIndex, 50584 rotation: this.rotation 50585 }; 50586 } 50587 return null; 50588 } 50589 reset() { 50590 for (const stream of this._streams) { 50591 stream.reset(); 50592 } 50593 } 50594 _constructFieldName(dict) { 50595 if (!dict.has("T") && !dict.has("Parent")) { 50596 warn("Unknown field name, falling back to empty field name."); 50597 return ""; 50598 } 50599 if (!dict.has("Parent")) { 50600 return stringToPDFString(dict.get("T")); 50601 } 50602 const fieldName = []; 50603 if (dict.has("T")) { 50604 fieldName.unshift(stringToPDFString(dict.get("T"))); 50605 } 50606 let loopDict = dict; 50607 const visited = new RefSet(); 50608 if (dict.objId) { 50609 visited.put(dict.objId); 50610 } 50611 while (loopDict.has("Parent")) { 50612 loopDict = loopDict.get("Parent"); 50613 if (!(loopDict instanceof Dict) || loopDict.objId && visited.has(loopDict.objId)) { 50614 break; 50615 } 50616 if (loopDict.objId) { 50617 visited.put(loopDict.objId); 50618 } 50619 if (loopDict.has("T")) { 50620 fieldName.unshift(stringToPDFString(loopDict.get("T"))); 50621 } 50622 } 50623 return fieldName.join("."); 50624 } 50625 get width() { 50626 return this.data.rect[2] - this.data.rect[0]; 50627 } 50628 get height() { 50629 return this.data.rect[3] - this.data.rect[1]; 50630 } 50631} 50632class AnnotationBorderStyle { 50633 constructor() { 50634 this.width = 1; 50635 this.rawWidth = 1; 50636 this.style = AnnotationBorderStyleType.SOLID; 50637 this.dashArray = [3]; 50638 this.horizontalCornerRadius = 0; 50639 this.verticalCornerRadius = 0; 50640 } 50641 setWidth(width, rect = [0, 0, 0, 0]) { 50642 if (width instanceof Name) { 50643 this.width = 0; 50644 return; 50645 } 50646 if (typeof width === "number") { 50647 if (width > 0) { 50648 this.rawWidth = width; 50649 const maxWidth = (rect[2] - rect[0]) / 2; 50650 const maxHeight = (rect[3] - rect[1]) / 2; 50651 if (maxWidth > 0 && maxHeight > 0 && (width > maxWidth || width > maxHeight)) { 50652 warn(`AnnotationBorderStyle.setWidth - ignoring width: ${width}`); 50653 width = 1; 50654 } 50655 } 50656 this.width = width; 50657 } 50658 } 50659 setStyle(style) { 50660 if (!(style instanceof Name)) { 50661 return; 50662 } 50663 switch (style.name) { 50664 case "S": 50665 this.style = AnnotationBorderStyleType.SOLID; 50666 break; 50667 case "D": 50668 this.style = AnnotationBorderStyleType.DASHED; 50669 break; 50670 case "B": 50671 this.style = AnnotationBorderStyleType.BEVELED; 50672 break; 50673 case "I": 50674 this.style = AnnotationBorderStyleType.INSET; 50675 break; 50676 case "U": 50677 this.style = AnnotationBorderStyleType.UNDERLINE; 50678 break; 50679 default: 50680 break; 50681 } 50682 } 50683 setDashArray(dashArray, forceStyle = false) { 50684 if (Array.isArray(dashArray)) { 50685 let isValid = true; 50686 let allZeros = true; 50687 for (const element of dashArray) { 50688 const validNumber = +element >= 0; 50689 if (!validNumber) { 50690 isValid = false; 50691 break; 50692 } else if (element > 0) { 50693 allZeros = false; 50694 } 50695 } 50696 if (dashArray.length === 0 || isValid && !allZeros) { 50697 this.dashArray = dashArray; 50698 if (forceStyle) { 50699 this.setStyle(Name.get("D")); 50700 } 50701 } else { 50702 this.width = 0; 50703 } 50704 } else if (dashArray) { 50705 this.width = 0; 50706 } 50707 } 50708 setHorizontalCornerRadius(radius) { 50709 if (Number.isInteger(radius)) { 50710 this.horizontalCornerRadius = radius; 50711 } 50712 } 50713 setVerticalCornerRadius(radius) { 50714 if (Number.isInteger(radius)) { 50715 this.verticalCornerRadius = radius; 50716 } 50717 } 50718} 50719class MarkupAnnotation extends Annotation { 50720 constructor(params) { 50721 super(params); 50722 const { 50723 dict 50724 } = params; 50725 if (dict.has("IRT")) { 50726 const rawIRT = dict.getRaw("IRT"); 50727 this.data.inReplyTo = rawIRT instanceof Ref ? rawIRT.toString() : null; 50728 const rt = dict.get("RT"); 50729 this.data.replyType = rt instanceof Name ? rt.name : AnnotationReplyType.REPLY; 50730 } 50731 let popupRef = null; 50732 if (this.data.replyType === AnnotationReplyType.GROUP) { 50733 const parent = dict.get("IRT"); 50734 this.setTitle(parent.get("T")); 50735 this.data.titleObj = this._title; 50736 this.setContents(parent.get("Contents")); 50737 this.data.contentsObj = this._contents; 50738 if (!parent.has("CreationDate")) { 50739 this.data.creationDate = null; 50740 } else { 50741 this.setCreationDate(parent.get("CreationDate")); 50742 this.data.creationDate = this.creationDate; 50743 } 50744 if (!parent.has("M")) { 50745 this.data.modificationDate = null; 50746 } else { 50747 this.setModificationDate(parent.get("M")); 50748 this.data.modificationDate = this.modificationDate; 50749 } 50750 popupRef = parent.getRaw("Popup"); 50751 if (!parent.has("C")) { 50752 this.data.color = null; 50753 } else { 50754 this.setColor(parent.getArray("C")); 50755 this.data.color = this.color; 50756 } 50757 } else { 50758 this.data.titleObj = this._title; 50759 this.setCreationDate(dict.get("CreationDate")); 50760 this.data.creationDate = this.creationDate; 50761 popupRef = dict.getRaw("Popup"); 50762 if (!dict.has("C")) { 50763 this.data.color = null; 50764 } 50765 } 50766 this.data.popupRef = popupRef instanceof Ref ? popupRef.toString() : null; 50767 if (dict.has("RC")) { 50768 this.data.richText = XFAFactory.getRichTextAsHtml(dict.get("RC")); 50769 } 50770 } 50771 setCreationDate(creationDate) { 50772 this.creationDate = typeof creationDate === "string" ? creationDate : null; 50773 } 50774 _setDefaultAppearance({ 50775 xref, 50776 extra, 50777 strokeColor, 50778 fillColor, 50779 blendMode, 50780 strokeAlpha, 50781 fillAlpha, 50782 pointsCallback 50783 }) { 50784 const bbox = this.data.rect = [Infinity, Infinity, -Infinity, -Infinity]; 50785 const buffer = ["q"]; 50786 if (extra) { 50787 buffer.push(extra); 50788 } 50789 if (strokeColor) { 50790 buffer.push(`${strokeColor[0]} ${strokeColor[1]} ${strokeColor[2]} RG`); 50791 } 50792 if (fillColor) { 50793 buffer.push(`${fillColor[0]} ${fillColor[1]} ${fillColor[2]} rg`); 50794 } 50795 const pointsArray = this.data.quadPoints || Float32Array.from([this.rectangle[0], this.rectangle[3], this.rectangle[2], this.rectangle[3], this.rectangle[0], this.rectangle[1], this.rectangle[2], this.rectangle[1]]); 50796 for (let i = 0, ii = pointsArray.length; i < ii; i += 8) { 50797 const points = pointsCallback(buffer, pointsArray.subarray(i, i + 8)); 50798 Util.rectBoundingBox(...points, bbox); 50799 } 50800 buffer.push("Q"); 50801 const formDict = new Dict(xref); 50802 const appearanceStreamDict = new Dict(xref); 50803 appearanceStreamDict.setIfName("Subtype", "Form"); 50804 const appearanceStream = new StringStream(buffer.join(" ")); 50805 appearanceStream.dict = appearanceStreamDict; 50806 formDict.set("Fm0", appearanceStream); 50807 const gsDict = new Dict(xref); 50808 if (blendMode) { 50809 gsDict.setIfName("BM", blendMode); 50810 } 50811 gsDict.setIfNumber("CA", strokeAlpha); 50812 gsDict.setIfNumber("ca", fillAlpha); 50813 const stateDict = new Dict(xref); 50814 stateDict.set("GS0", gsDict); 50815 const resources = new Dict(xref); 50816 resources.set("ExtGState", stateDict); 50817 resources.set("XObject", formDict); 50818 const appearanceDict = new Dict(xref); 50819 appearanceDict.set("Resources", resources); 50820 appearanceDict.set("BBox", bbox); 50821 this.appearance = new StringStream("/GS0 gs /Fm0 Do"); 50822 this.appearance.dict = appearanceDict; 50823 this._streams.push(this.appearance, appearanceStream); 50824 } 50825 static async createNewAnnotation(xref, annotation, changes, params) { 50826 const annotationRef = annotation.ref ||= xref.getNewTemporaryRef(); 50827 const ap = await this.createNewAppearanceStream(annotation, xref, params); 50828 let annotationDict; 50829 if (ap) { 50830 const apRef = xref.getNewTemporaryRef(); 50831 annotationDict = this.createNewDict(annotation, xref, { 50832 apRef 50833 }); 50834 changes.put(apRef, { 50835 data: ap 50836 }); 50837 } else { 50838 annotationDict = this.createNewDict(annotation, xref, {}); 50839 } 50840 if (Number.isInteger(annotation.parentTreeId)) { 50841 annotationDict.set("StructParent", annotation.parentTreeId); 50842 } 50843 changes.put(annotationRef, { 50844 data: annotationDict 50845 }); 50846 const retRef = { 50847 ref: annotationRef 50848 }; 50849 const { 50850 popup 50851 } = annotation; 50852 if (popup) { 50853 if (popup.deleted) { 50854 annotationDict.delete("Popup"); 50855 annotationDict.delete("Contents"); 50856 annotationDict.delete("RC"); 50857 return retRef; 50858 } 50859 const popupRef = popup.ref ||= xref.getNewTemporaryRef(); 50860 popup.parent = annotationRef; 50861 const popupDict = PopupAnnotation.createNewDict(popup, xref); 50862 changes.put(popupRef, { 50863 data: popupDict 50864 }); 50865 annotationDict.setIfDefined("Contents", stringToAsciiOrUTF16BE(popup.contents)); 50866 annotationDict.set("Popup", popupRef); 50867 return [retRef, { 50868 ref: popupRef 50869 }]; 50870 } 50871 return retRef; 50872 } 50873 static async createNewPrintAnnotation(annotationGlobals, xref, annotation, params) { 50874 const ap = await this.createNewAppearanceStream(annotation, xref, params); 50875 const annotationDict = this.createNewDict(annotation, xref, ap ? { 50876 ap 50877 } : {}); 50878 const newAnnotation = new this.prototype.constructor({ 50879 dict: annotationDict, 50880 xref, 50881 annotationGlobals, 50882 evaluatorOptions: params.evaluatorOptions 50883 }); 50884 if (annotation.ref) { 50885 newAnnotation.ref = newAnnotation.refToReplace = annotation.ref; 50886 } 50887 return newAnnotation; 50888 } 50889} 50890class WidgetAnnotation extends Annotation { 50891 constructor(params) { 50892 super(params); 50893 const { 50894 dict, 50895 xref, 50896 annotationGlobals 50897 } = params; 50898 const data = this.data; 50899 this._needAppearances = params.needAppearances; 50900 data.annotationType = AnnotationType.WIDGET; 50901 if (data.fieldName === undefined) { 50902 data.fieldName = this._constructFieldName(dict); 50903 } 50904 if (data.actions === undefined) { 50905 data.actions = collectActions(xref, dict, AnnotationActionEventType); 50906 } 50907 let fieldValue = getInheritableProperty({ 50908 dict, 50909 key: "V", 50910 getArray: true 50911 }); 50912 data.fieldValue = this._decodeFormValue(fieldValue); 50913 const defaultFieldValue = getInheritableProperty({ 50914 dict, 50915 key: "DV", 50916 getArray: true 50917 }); 50918 data.defaultFieldValue = this._decodeFormValue(defaultFieldValue); 50919 if (fieldValue === undefined && annotationGlobals.xfaDatasets) { 50920 const path = this._title.str; 50921 if (path) { 50922 this._hasValueFromXFA = true; 50923 data.fieldValue = fieldValue = annotationGlobals.xfaDatasets.getValue(path); 50924 } 50925 } 50926 if (fieldValue === undefined && data.defaultFieldValue !== null) { 50927 data.fieldValue = data.defaultFieldValue; 50928 } 50929 data.alternativeText = stringToPDFString(dict.get("TU") || ""); 50930 this.setDefaultAppearance(params); 50931 data.hasAppearance ||= this._needAppearances && data.fieldValue !== undefined && data.fieldValue !== null; 50932 const fieldType = getInheritableProperty({ 50933 dict, 50934 key: "FT" 50935 }); 50936 data.fieldType = fieldType instanceof Name ? fieldType.name : null; 50937 const localResources = getInheritableProperty({ 50938 dict, 50939 key: "DR" 50940 }); 50941 const acroFormResources = annotationGlobals.acroForm.get("DR"); 50942 const appearanceResources = this.appearance?.dict.get("Resources"); 50943 this._fieldResources = { 50944 localResources, 50945 acroFormResources, 50946 appearanceResources, 50947 mergedResources: Dict.merge({ 50948 xref, 50949 dictArray: [localResources, appearanceResources, acroFormResources], 50950 mergeSubDicts: true 50951 }) 50952 }; 50953 data.fieldFlags = getInheritableProperty({ 50954 dict, 50955 key: "Ff" 50956 }); 50957 if (!Number.isInteger(data.fieldFlags) || data.fieldFlags < 0) { 50958 data.fieldFlags = 0; 50959 } 50960 data.password = this.hasFieldFlag(AnnotationFieldFlag.PASSWORD); 50961 data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY); 50962 data.required = this.hasFieldFlag(AnnotationFieldFlag.REQUIRED); 50963 data.hidden = this._hasFlag(data.annotationFlags, AnnotationFlag.HIDDEN) || this._hasFlag(data.annotationFlags, AnnotationFlag.NOVIEW); 50964 } 50965 _decodeFormValue(formValue) { 50966 if (Array.isArray(formValue)) { 50967 return formValue.filter(item => typeof item === "string").map(item => stringToPDFString(item)); 50968 } else if (formValue instanceof Name) { 50969 return stringToPDFString(formValue.name); 50970 } else if (typeof formValue === "string") { 50971 return stringToPDFString(formValue); 50972 } 50973 return null; 50974 } 50975 hasFieldFlag(flag) { 50976 return !!(this.data.fieldFlags & flag); 50977 } 50978 _isViewable(flags) { 50979 return true; 50980 } 50981 mustBeViewed(annotationStorage, renderForms) { 50982 if (renderForms) { 50983 return this.viewable; 50984 } 50985 return super.mustBeViewed(annotationStorage, renderForms) && !this._hasFlag(this.flags, AnnotationFlag.NOVIEW); 50986 } 50987 getRotationMatrix(annotationStorage) { 50988 let rotation = annotationStorage?.get(this.data.id)?.rotation; 50989 if (rotation === undefined) { 50990 rotation = this.rotation; 50991 } 50992 return rotation === 0 ? IDENTITY_MATRIX : getRotationMatrix(rotation, this.width, this.height); 50993 } 50994 getBorderAndBackgroundAppearances(annotationStorage) { 50995 let rotation = annotationStorage?.get(this.data.id)?.rotation; 50996 if (rotation === undefined) { 50997 rotation = this.rotation; 50998 } 50999 if (!this.backgroundColor && !this.borderColor) { 51000 return ""; 51001 } 51002 const rect = rotation === 0 || rotation === 180 ? `0 0 ${this.width} ${this.height} re` : `0 0 ${this.height} ${this.width} re`; 51003 let str = ""; 51004 if (this.backgroundColor) { 51005 str = `${getPdfColor(this.backgroundColor, true)} ${rect} f `; 51006 } 51007 if (this.borderColor) { 51008 const borderWidth = this.borderStyle.width || 1; 51009 str += `${borderWidth} w ${getPdfColor(this.borderColor, false)} ${rect} S `; 51010 } 51011 return str; 51012 } 51013 async getOperatorList(evaluator, task, intent, annotationStorage) { 51014 if (intent & RenderingIntentFlag.ANNOTATIONS_FORMS && !(this instanceof SignatureWidgetAnnotation) && !this.data.noHTML && !this.data.hasOwnCanvas) { 51015 return { 51016 opList: new OperatorList(), 51017 separateForm: true, 51018 separateCanvas: false 51019 }; 51020 } 51021 if (!this._hasText) { 51022 return super.getOperatorList(evaluator, task, intent, annotationStorage); 51023 } 51024 const content = await this._getAppearance(evaluator, task, intent, annotationStorage); 51025 if (this.appearance && content === null) { 51026 return super.getOperatorList(evaluator, task, intent, annotationStorage); 51027 } 51028 const opList = new OperatorList(); 51029 if (!this._defaultAppearance || content === null) { 51030 return { 51031 opList, 51032 separateForm: false, 51033 separateCanvas: false 51034 }; 51035 } 51036 const isUsingOwnCanvas = !!(this.data.hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY); 51037 const matrix = [1, 0, 0, 1, 0, 0]; 51038 const bbox = [0, 0, this.width, this.height]; 51039 const transform = getTransformMatrix(this.data.rect, bbox, matrix); 51040 let optionalContent; 51041 if (this.oc) { 51042 optionalContent = await evaluator.parseMarkedContentProps(this.oc, null); 51043 } 51044 if (optionalContent !== undefined) { 51045 opList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]); 51046 } 51047 opList.addOp(OPS.beginAnnotation, [this.data.id, this.data.rect, transform, this.getRotationMatrix(annotationStorage), isUsingOwnCanvas]); 51048 const stream = new StringStream(content); 51049 await evaluator.getOperatorList({ 51050 stream, 51051 task, 51052 resources: this._fieldResources.mergedResources, 51053 operatorList: opList 51054 }); 51055 opList.addOp(OPS.endAnnotation, []); 51056 if (optionalContent !== undefined) { 51057 opList.addOp(OPS.endMarkedContent, []); 51058 } 51059 return { 51060 opList, 51061 separateForm: false, 51062 separateCanvas: isUsingOwnCanvas 51063 }; 51064 } 51065 _getMKDict(rotation) { 51066 const mk = new Dict(null); 51067 if (rotation) { 51068 mk.set("R", rotation); 51069 } 51070 mk.setIfArray("BC", getPdfColorArray(this.borderColor)); 51071 mk.setIfArray("BG", getPdfColorArray(this.backgroundColor)); 51072 return mk.size > 0 ? mk : null; 51073 } 51074 amendSavedDict(annotationStorage, dict) {} 51075 setValue(dict, value, xref, changes) { 51076 const { 51077 dict: parentDict, 51078 ref: parentRef 51079 } = getParentToUpdate(dict, this.ref, xref); 51080 if (!parentDict) { 51081 dict.set("V", value); 51082 } else if (!changes.has(parentRef)) { 51083 const newParentDict = parentDict.clone(); 51084 newParentDict.set("V", value); 51085 changes.put(parentRef, { 51086 data: newParentDict 51087 }); 51088 return newParentDict; 51089 } 51090 return null; 51091 } 51092 async save(evaluator, task, annotationStorage, changes) { 51093 const storageEntry = annotationStorage?.get(this.data.id); 51094 const flags = this._buildFlags(storageEntry?.noView, storageEntry?.noPrint); 51095 let value = storageEntry?.value, 51096 rotation = storageEntry?.rotation; 51097 if (value === this.data.fieldValue || value === undefined) { 51098 if (!this._hasValueFromXFA && rotation === undefined && flags === undefined) { 51099 return; 51100 } 51101 value ||= this.data.fieldValue; 51102 } 51103 if (rotation === undefined && !this._hasValueFromXFA && Array.isArray(value) && Array.isArray(this.data.fieldValue) && isArrayEqual(value, this.data.fieldValue) && flags === undefined) { 51104 return; 51105 } 51106 if (rotation === undefined) { 51107 rotation = this.rotation; 51108 } 51109 let appearance = null; 51110 if (!this._needAppearances) { 51111 appearance = await this._getAppearance(evaluator, task, RenderingIntentFlag.SAVE, annotationStorage); 51112 if (appearance === null && flags === undefined) { 51113 return; 51114 } 51115 } else {} 51116 let needAppearances = false; 51117 if (appearance?.needAppearances) { 51118 needAppearances = true; 51119 appearance = null; 51120 } 51121 const { 51122 xref 51123 } = evaluator; 51124 const originalDict = xref.fetchIfRef(this.ref); 51125 if (!(originalDict instanceof Dict)) { 51126 return; 51127 } 51128 const dict = new Dict(xref); 51129 for (const key of originalDict.getKeys()) { 51130 if (key !== "AP") { 51131 dict.set(key, originalDict.getRaw(key)); 51132 } 51133 } 51134 if (flags !== undefined) { 51135 dict.set("F", flags); 51136 if (appearance === null && !needAppearances) { 51137 const ap = originalDict.getRaw("AP"); 51138 if (ap) { 51139 dict.set("AP", ap); 51140 } 51141 } 51142 } 51143 const xfa = { 51144 path: this.data.fieldName, 51145 value 51146 }; 51147 const newParentDict = this.setValue(dict, Array.isArray(value) ? value.map(stringToAsciiOrUTF16BE) : stringToAsciiOrUTF16BE(value), xref, changes); 51148 this.amendSavedDict(annotationStorage, newParentDict || dict); 51149 const maybeMK = this._getMKDict(rotation); 51150 if (maybeMK) { 51151 dict.set("MK", maybeMK); 51152 } 51153 changes.put(this.ref, { 51154 data: dict, 51155 xfa, 51156 needAppearances 51157 }); 51158 if (appearance !== null) { 51159 const newRef = xref.getNewTemporaryRef(); 51160 const AP = new Dict(xref); 51161 dict.set("AP", AP); 51162 AP.set("N", newRef); 51163 const resources = this._getSaveFieldResources(xref); 51164 const appearanceStream = new StringStream(appearance); 51165 const appearanceDict = appearanceStream.dict = new Dict(xref); 51166 appearanceDict.setIfName("Subtype", "Form"); 51167 appearanceDict.set("Resources", resources); 51168 const bbox = rotation % 180 === 0 ? [0, 0, this.width, this.height] : [0, 0, this.height, this.width]; 51169 appearanceDict.set("BBox", bbox); 51170 const rotationMatrix = this.getRotationMatrix(annotationStorage); 51171 if (rotationMatrix !== IDENTITY_MATRIX) { 51172 appearanceDict.set("Matrix", rotationMatrix); 51173 } 51174 changes.put(newRef, { 51175 data: appearanceStream, 51176 xfa: null, 51177 needAppearances: false 51178 }); 51179 } 51180 dict.set("M", `D:${getModificationDate()}`); 51181 } 51182 async _getAppearance(evaluator, task, intent, annotationStorage) { 51183 if (this.data.password) { 51184 return null; 51185 } 51186 const storageEntry = annotationStorage?.get(this.data.id); 51187 let value, rotation; 51188 if (storageEntry) { 51189 value = storageEntry.formattedValue || storageEntry.value; 51190 rotation = storageEntry.rotation; 51191 } 51192 if (rotation === undefined && value === undefined && !this._needAppearances) { 51193 if (!this._hasValueFromXFA || this.appearance) { 51194 return null; 51195 } 51196 } 51197 const colors = this.getBorderAndBackgroundAppearances(annotationStorage); 51198 if (value === undefined) { 51199 value = this.data.fieldValue; 51200 if (!value) { 51201 return `/Tx BMC q ${colors}Q EMC`; 51202 } 51203 } 51204 if (Array.isArray(value) && value.length === 1) { 51205 value = value[0]; 51206 } 51207 assert(typeof value === "string", "Expected `value` to be a string."); 51208 value = value.trimEnd(); 51209 if (this.data.combo) { 51210 const option = this.data.options.find(({ 51211 exportValue 51212 }) => value === exportValue); 51213 value = option?.displayValue || value; 51214 } 51215 if (value === "") { 51216 return `/Tx BMC q ${colors}Q EMC`; 51217 } 51218 if (rotation === undefined) { 51219 rotation = this.rotation; 51220 } 51221 let lineCount = -1; 51222 let lines; 51223 if (this.data.multiLine) { 51224 lines = value.split(/\r\n?|\n/).map(line => line.normalize("NFC")); 51225 lineCount = lines.length; 51226 } else { 51227 lines = [value.replace(/\r\n?|\n/, "").normalize("NFC")]; 51228 } 51229 const defaultPadding = 1; 51230 const defaultHPadding = 2; 51231 let { 51232 width: totalWidth, 51233 height: totalHeight 51234 } = this; 51235 if (rotation === 90 || rotation === 270) { 51236 [totalWidth, totalHeight] = [totalHeight, totalWidth]; 51237 } 51238 if (!this._defaultAppearance) { 51239 this.data.defaultAppearanceData = parseDefaultAppearance(this._defaultAppearance = "/Helvetica 0 Tf 0 g"); 51240 } 51241 let font = await WidgetAnnotation._getFontData(evaluator, task, this.data.defaultAppearanceData, this._fieldResources.mergedResources); 51242 let defaultAppearance, fontSize, lineHeight; 51243 const encodedLines = []; 51244 let encodingError = false; 51245 for (const line of lines) { 51246 const encodedString = font.encodeString(line); 51247 if (encodedString.length > 1) { 51248 encodingError = true; 51249 } 51250 encodedLines.push(encodedString.join("")); 51251 } 51252 if (encodingError && intent & RenderingIntentFlag.SAVE) { 51253 return { 51254 needAppearances: true 51255 }; 51256 } 51257 if (encodingError && this._isOffscreenCanvasSupported) { 51258 const fontFamily = this.data.comb ? "monospace" : "sans-serif"; 51259 const fakeUnicodeFont = new FakeUnicodeFont(evaluator.xref, fontFamily); 51260 const resources = fakeUnicodeFont.createFontResources(lines.join("")); 51261 const newFont = resources.getRaw("Font"); 51262 if (this._fieldResources.mergedResources.has("Font")) { 51263 const oldFont = this._fieldResources.mergedResources.get("Font"); 51264 for (const key of newFont.getKeys()) { 51265 oldFont.set(key, newFont.getRaw(key)); 51266 } 51267 } else { 51268 this._fieldResources.mergedResources.set("Font", newFont); 51269 } 51270 const fontName = fakeUnicodeFont.fontName.name; 51271 font = await WidgetAnnotation._getFontData(evaluator, task, { 51272 fontName, 51273 fontSize: 0 51274 }, resources); 51275 for (let i = 0, ii = encodedLines.length; i < ii; i++) { 51276 encodedLines[i] = stringToUTF16String(lines[i]); 51277 } 51278 const savedDefaultAppearance = Object.assign(Object.create(null), this.data.defaultAppearanceData); 51279 this.data.defaultAppearanceData.fontSize = 0; 51280 this.data.defaultAppearanceData.fontName = fontName; 51281 [defaultAppearance, fontSize, lineHeight] = this._computeFontSize(totalHeight - 2 * defaultPadding, totalWidth - 2 * defaultHPadding, value, font, lineCount); 51282 this.data.defaultAppearanceData = savedDefaultAppearance; 51283 } else { 51284 if (!this._isOffscreenCanvasSupported) { 51285 warn("_getAppearance: OffscreenCanvas is not supported, annotation may not render correctly."); 51286 } 51287 [defaultAppearance, fontSize, lineHeight] = this._computeFontSize(totalHeight - 2 * defaultPadding, totalWidth - 2 * defaultHPadding, value, font, lineCount); 51288 } 51289 let descent = font.descent; 51290 if (isNaN(descent)) { 51291 descent = BASELINE_FACTOR * lineHeight; 51292 } else { 51293 descent = Math.max(BASELINE_FACTOR * lineHeight, Math.abs(descent) * fontSize); 51294 } 51295 const defaultVPadding = Math.min(Math.floor((totalHeight - fontSize) / 2), defaultPadding); 51296 const alignment = this.data.textAlignment; 51297 if (this.data.multiLine) { 51298 return this._getMultilineAppearance(defaultAppearance, encodedLines, font, fontSize, totalWidth, totalHeight, alignment, defaultHPadding, defaultVPadding, descent, lineHeight, annotationStorage); 51299 } 51300 if (this.data.comb) { 51301 return this._getCombAppearance(defaultAppearance, font, encodedLines[0], fontSize, totalWidth, totalHeight, defaultHPadding, defaultVPadding, descent, lineHeight, annotationStorage); 51302 } 51303 const bottomPadding = defaultVPadding + descent; 51304 if (alignment === 0 || alignment > 2) { 51305 return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 ${numberToString(defaultHPadding)} ${numberToString(bottomPadding)} Tm (${escapeString(encodedLines[0])}) Tj` + " ET Q EMC"; 51306 } 51307 const prevInfo = { 51308 shift: 0 51309 }; 51310 const renderedText = this._renderText(encodedLines[0], font, fontSize, totalWidth, alignment, prevInfo, defaultHPadding, bottomPadding); 51311 return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 0 0 Tm ${renderedText}` + " ET Q EMC"; 51312 } 51313 static async _getFontData(evaluator, task, appearanceData, resources) { 51314 const operatorList = new OperatorList(); 51315 const initialState = { 51316 font: null, 51317 clone() { 51318 return this; 51319 } 51320 }; 51321 const { 51322 fontName, 51323 fontSize 51324 } = appearanceData; 51325 await evaluator.handleSetFont(resources, [fontName && Name.get(fontName), fontSize], null, operatorList, task, initialState, null); 51326 return initialState.font; 51327 } 51328 _getTextWidth(text, font) { 51329 return Math.sumPrecise(font.charsToGlyphs(text).map(g => g.width)) / 1000; 51330 } 51331 _computeFontSize(height, width, text, font, lineCount) { 51332 let { 51333 fontSize 51334 } = this.data.defaultAppearanceData; 51335 let lineHeight = (fontSize || 12) * LINE_FACTOR, 51336 numberOfLines = Math.round(height / lineHeight); 51337 if (!fontSize) { 51338 const roundWithTwoDigits = x => Math.floor(x * 100) / 100; 51339 if (lineCount === -1) { 51340 const textWidth = this._getTextWidth(text, font); 51341 fontSize = roundWithTwoDigits(Math.min(height / LINE_FACTOR, width / textWidth)); 51342 numberOfLines = 1; 51343 } else { 51344 const lines = text.split(/\r\n?|\n/); 51345 const cachedLines = []; 51346 for (const line of lines) { 51347 const encoded = font.encodeString(line).join(""); 51348 const glyphs = font.charsToGlyphs(encoded); 51349 const positions = font.getCharPositions(encoded); 51350 cachedLines.push({ 51351 line: encoded, 51352 glyphs, 51353 positions 51354 }); 51355 } 51356 const isTooBig = fsize => { 51357 let totalHeight = 0; 51358 for (const cache of cachedLines) { 51359 const chunks = this._splitLine(null, font, fsize, width, cache); 51360 totalHeight += chunks.length * fsize; 51361 if (totalHeight > height) { 51362 return true; 51363 } 51364 } 51365 return false; 51366 }; 51367 numberOfLines = Math.max(numberOfLines, lineCount); 51368 while (true) { 51369 lineHeight = height / numberOfLines; 51370 fontSize = roundWithTwoDigits(lineHeight / LINE_FACTOR); 51371 if (isTooBig(fontSize)) { 51372 numberOfLines++; 51373 continue; 51374 } 51375 break; 51376 } 51377 } 51378 const { 51379 fontName, 51380 fontColor 51381 } = this.data.defaultAppearanceData; 51382 this._defaultAppearance = createDefaultAppearance({ 51383 fontSize, 51384 fontName, 51385 fontColor 51386 }); 51387 } 51388 return [this._defaultAppearance, fontSize, height / numberOfLines]; 51389 } 51390 _renderText(text, font, fontSize, totalWidth, alignment, prevInfo, hPadding, vPadding) { 51391 let shift; 51392 if (alignment === 1) { 51393 const width = this._getTextWidth(text, font) * fontSize; 51394 shift = (totalWidth - width) / 2; 51395 } else if (alignment === 2) { 51396 const width = this._getTextWidth(text, font) * fontSize; 51397 shift = totalWidth - width - hPadding; 51398 } else { 51399 shift = hPadding; 51400 } 51401 const shiftStr = numberToString(shift - prevInfo.shift); 51402 prevInfo.shift = shift; 51403 vPadding = numberToString(vPadding); 51404 return `${shiftStr} ${vPadding} Td (${escapeString(text)}) Tj`; 51405 } 51406 _getSaveFieldResources(xref) { 51407 const { 51408 localResources, 51409 appearanceResources, 51410 acroFormResources 51411 } = this._fieldResources; 51412 const fontName = this.data.defaultAppearanceData?.fontName; 51413 if (!fontName) { 51414 return localResources || Dict.empty; 51415 } 51416 for (const resources of [localResources, appearanceResources]) { 51417 if (resources instanceof Dict) { 51418 const localFont = resources.get("Font"); 51419 if (localFont instanceof Dict && localFont.has(fontName)) { 51420 return resources; 51421 } 51422 } 51423 } 51424 if (acroFormResources instanceof Dict) { 51425 const acroFormFont = acroFormResources.get("Font"); 51426 if (acroFormFont instanceof Dict && acroFormFont.has(fontName)) { 51427 const subFontDict = new Dict(xref); 51428 subFontDict.set(fontName, acroFormFont.getRaw(fontName)); 51429 const subResourcesDict = new Dict(xref); 51430 subResourcesDict.set("Font", subFontDict); 51431 return Dict.merge({ 51432 xref, 51433 dictArray: [subResourcesDict, localResources], 51434 mergeSubDicts: true 51435 }); 51436 } 51437 } 51438 return localResources || Dict.empty; 51439 } 51440 getFieldObject() { 51441 return null; 51442 } 51443} 51444class TextWidgetAnnotation extends WidgetAnnotation { 51445 constructor(params) { 51446 super(params); 51447 const { 51448 dict 51449 } = params; 51450 if (dict.has("PMD")) { 51451 this.flags |= AnnotationFlag.HIDDEN; 51452 this.data.hidden = true; 51453 warn("Barcodes are not supported"); 51454 } 51455 this.data.hasOwnCanvas = this.data.readOnly && !this.data.noHTML; 51456 this._hasText = true; 51457 if (typeof this.data.fieldValue !== "string") { 51458 this.data.fieldValue = ""; 51459 } 51460 let alignment = getInheritableProperty({ 51461 dict, 51462 key: "Q" 51463 }); 51464 if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) { 51465 alignment = null; 51466 } 51467 this.data.textAlignment = alignment; 51468 let maximumLength = getInheritableProperty({ 51469 dict, 51470 key: "MaxLen" 51471 }); 51472 if (!Number.isInteger(maximumLength) || maximumLength < 0) { 51473 maximumLength = 0; 51474 } 51475 this.data.maxLen = maximumLength; 51476 this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE); 51477 this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.data.multiLine && !this.data.password && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== 0; 51478 this.data.doNotScroll = this.hasFieldFlag(AnnotationFieldFlag.DONOTSCROLL); 51479 const { 51480 data: { 51481 actions 51482 } 51483 } = this; 51484 if (!actions) { 51485 return; 51486 } 51487 const AFDateTime = /^AF(Date|Time)_(?:Keystroke|Format)(?:Ex)?\(['"]?([^'"]+)['"]?\);$/; 51488 let canUseHTMLDateTime = false; 51489 if (actions.Format?.length === 1 && actions.Keystroke?.length === 1 && AFDateTime.test(actions.Format[0]) && AFDateTime.test(actions.Keystroke[0]) || actions.Format?.length === 0 && actions.Keystroke?.length === 1 && AFDateTime.test(actions.Keystroke[0]) || actions.Keystroke?.length === 0 && actions.Format?.length === 1 && AFDateTime.test(actions.Format[0])) { 51490 canUseHTMLDateTime = true; 51491 } 51492 const actionsToVisit = []; 51493 if (actions.Format) { 51494 actionsToVisit.push(...actions.Format); 51495 } 51496 if (actions.Keystroke) { 51497 actionsToVisit.push(...actions.Keystroke); 51498 } 51499 if (canUseHTMLDateTime) { 51500 delete actions.Keystroke; 51501 actions.Format = actionsToVisit; 51502 } 51503 for (const formatAction of actionsToVisit) { 51504 const m = formatAction.match(AFDateTime); 51505 if (!m) { 51506 continue; 51507 } 51508 const isDate = m[1] === "Date"; 51509 let format = m[2]; 51510 const num = parseInt(format, 10); 51511 if (!isNaN(num) && Math.floor(Math.log10(num)) + 1 === m[2].length) { 51512 format = (isDate ? DateFormats : TimeFormats)[num] ?? format; 51513 } 51514 this.data.datetimeFormat = format; 51515 if (!canUseHTMLDateTime) { 51516 break; 51517 } 51518 if (isDate) { 51519 if (/HH|MM|ss|h/.test(format)) { 51520 this.data.datetimeType = "datetime-local"; 51521 this.data.timeStep = /ss/.test(format) ? 1 : 60; 51522 } else { 51523 this.data.datetimeType = "date"; 51524 } 51525 break; 51526 } 51527 this.data.datetimeType = "time"; 51528 this.data.timeStep = /ss/.test(format) ? 1 : 60; 51529 break; 51530 } 51531 } 51532 get hasTextContent() { 51533 return !!this.appearance && !this._needAppearances; 51534 } 51535 _getCombAppearance(defaultAppearance, font, text, fontSize, width, height, hPadding, vPadding, descent, lineHeight, annotationStorage) { 51536 const combWidth = width / this.data.maxLen; 51537 const colors = this.getBorderAndBackgroundAppearances(annotationStorage); 51538 const buf = []; 51539 const positions = font.getCharPositions(text); 51540 for (const [start, end] of positions) { 51541 buf.push(`(${escapeString(text.substring(start, end))}) Tj`); 51542 } 51543 const renderedComb = buf.join(` ${numberToString(combWidth)} 0 Td `); 51544 return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 ${numberToString(hPadding)} ${numberToString(vPadding + descent)} Tm ${renderedComb}` + " ET Q EMC"; 51545 } 51546 _getMultilineAppearance(defaultAppearance, lines, font, fontSize, width, height, alignment, hPadding, vPadding, descent, lineHeight, annotationStorage) { 51547 const buf = []; 51548 const totalWidth = width - 2 * hPadding; 51549 const prevInfo = { 51550 shift: 0 51551 }; 51552 for (let i = 0, ii = lines.length; i < ii; i++) { 51553 const line = lines[i]; 51554 const chunks = this._splitLine(line, font, fontSize, totalWidth); 51555 for (let j = 0, jj = chunks.length; j < jj; j++) { 51556 const chunk = chunks[j]; 51557 const vShift = i === 0 && j === 0 ? -vPadding - (lineHeight - descent) : -lineHeight; 51558 buf.push(this._renderText(chunk, font, fontSize, width, alignment, prevInfo, hPadding, vShift)); 51559 } 51560 } 51561 const colors = this.getBorderAndBackgroundAppearances(annotationStorage); 51562 const renderedText = buf.join("\n"); 51563 return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 0 ${numberToString(height)} Tm ${renderedText}` + " ET Q EMC"; 51564 } 51565 _splitLine(line, font, fontSize, width, cache = {}) { 51566 line = cache.line || line; 51567 const glyphs = cache.glyphs || font.charsToGlyphs(line); 51568 if (glyphs.length <= 1) { 51569 return [line]; 51570 } 51571 const positions = cache.positions || font.getCharPositions(line); 51572 const scale = fontSize / 1000; 51573 const chunks = []; 51574 let lastSpacePosInStringStart = -1, 51575 lastSpacePosInStringEnd = -1, 51576 lastSpacePos = -1, 51577 startChunk = 0, 51578 currentWidth = 0; 51579 for (let i = 0, ii = glyphs.length; i < ii; i++) { 51580 const [start, end] = positions[i]; 51581 const glyph = glyphs[i]; 51582 const glyphWidth = glyph.width * scale; 51583 if (glyph.unicode === " ") { 51584 if (currentWidth + glyphWidth > width) { 51585 chunks.push(line.substring(startChunk, start)); 51586 startChunk = start; 51587 currentWidth = glyphWidth; 51588 lastSpacePosInStringStart = -1; 51589 lastSpacePos = -1; 51590 } else { 51591 currentWidth += glyphWidth; 51592 lastSpacePosInStringStart = start; 51593 lastSpacePosInStringEnd = end; 51594 lastSpacePos = i; 51595 } 51596 } else if (currentWidth + glyphWidth > width) { 51597 if (lastSpacePosInStringStart !== -1) { 51598 chunks.push(line.substring(startChunk, lastSpacePosInStringEnd)); 51599 startChunk = lastSpacePosInStringEnd; 51600 i = lastSpacePos + 1; 51601 lastSpacePosInStringStart = -1; 51602 currentWidth = 0; 51603 } else { 51604 chunks.push(line.substring(startChunk, start)); 51605 startChunk = start; 51606 currentWidth = glyphWidth; 51607 } 51608 } else { 51609 currentWidth += glyphWidth; 51610 } 51611 } 51612 if (startChunk < line.length) { 51613 chunks.push(line.substring(startChunk, line.length)); 51614 } 51615 return chunks; 51616 } 51617 async extractTextContent(evaluator, task, viewBox) { 51618 await super.extractTextContent(evaluator, task, viewBox); 51619 const text = this.data.textContent; 51620 if (!text) { 51621 return; 51622 } 51623 const allText = text.join("\n"); 51624 if (allText === this.data.fieldValue) { 51625 return; 51626 } 51627 const regex = allText.replaceAll(/([.*+?^${}()|[\]\\])|(\s+)/g, (_m, p1) => p1 ? `\\${p1}` : "\\s+"); 51628 if (new RegExp(`^\\s*${regex}\\s*$`).test(this.data.fieldValue)) { 51629 this.data.textContent = this.data.fieldValue.split("\n"); 51630 } 51631 } 51632 getFieldObject() { 51633 return { 51634 id: this.data.id, 51635 value: this.data.fieldValue, 51636 defaultValue: this.data.defaultFieldValue || "", 51637 multiline: this.data.multiLine, 51638 password: this.data.password, 51639 charLimit: this.data.maxLen, 51640 comb: this.data.comb, 51641 editable: !this.data.readOnly, 51642 hidden: this.data.hidden, 51643 name: this.data.fieldName, 51644 rect: this.data.rect, 51645 actions: this.data.actions, 51646 page: this.data.pageIndex, 51647 strokeColor: this.data.borderColor, 51648 fillColor: this.data.backgroundColor, 51649 rotation: this.rotation, 51650 datetimeFormat: this.data.datetimeFormat, 51651 hasDatetimeHTML: !!this.data.datetimeType, 51652 type: "text" 51653 }; 51654 } 51655} 51656class ButtonWidgetAnnotation extends WidgetAnnotation { 51657 constructor(params) { 51658 super(params); 51659 this.checkedAppearance = null; 51660 this.uncheckedAppearance = null; 51661 const isRadio = this.hasFieldFlag(AnnotationFieldFlag.RADIO), 51662 isPushButton = this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON); 51663 this.data.checkBox = !isRadio && !isPushButton; 51664 this.data.radioButton = isRadio && !isPushButton; 51665 this.data.pushButton = isPushButton; 51666 this.data.isTooltipOnly = false; 51667 if (this.data.checkBox) { 51668 this._processCheckBox(params); 51669 } else if (this.data.radioButton) { 51670 this._processRadioButton(params); 51671 } else if (this.data.pushButton) { 51672 this.data.hasOwnCanvas = true; 51673 this.data.noHTML = false; 51674 this._processPushButton(params); 51675 } else { 51676 warn("Invalid field flags for button widget annotation"); 51677 } 51678 } 51679 async getOperatorList(evaluator, task, intent, annotationStorage) { 51680 if (this.data.pushButton) { 51681 return super.getOperatorList(evaluator, task, intent, false, annotationStorage); 51682 } 51683 let value = null; 51684 let rotation = null; 51685 if (annotationStorage) { 51686 const storageEntry = annotationStorage.get(this.data.id); 51687 value = storageEntry ? storageEntry.value : null; 51688 rotation = storageEntry ? storageEntry.rotation : null; 51689 } 51690 if (value === null && this.appearance) { 51691 return super.getOperatorList(evaluator, task, intent, annotationStorage); 51692 } 51693 if (value === null || value === undefined) { 51694 value = this.data.checkBox ? this.data.fieldValue === this.data.exportValue : this.data.fieldValue === this.data.buttonValue; 51695 } 51696 const appearance = value ? this.checkedAppearance : this.uncheckedAppearance; 51697 if (appearance) { 51698 const savedAppearance = this.appearance; 51699 const savedMatrix = lookupMatrix(appearance.dict.getArray("Matrix"), IDENTITY_MATRIX); 51700 if (rotation) { 51701 appearance.dict.set("Matrix", this.getRotationMatrix(annotationStorage)); 51702 } 51703 this.appearance = appearance; 51704 const operatorList = super.getOperatorList(evaluator, task, intent, annotationStorage); 51705 this.appearance = savedAppearance; 51706 appearance.dict.set("Matrix", savedMatrix); 51707 return operatorList; 51708 } 51709 return { 51710 opList: new OperatorList(), 51711 separateForm: false, 51712 separateCanvas: false 51713 }; 51714 } 51715 async save(evaluator, task, annotationStorage, changes) { 51716 if (this.data.checkBox) { 51717 this._saveCheckbox(evaluator, task, annotationStorage, changes); 51718 return; 51719 } 51720 if (this.data.radioButton) { 51721 this._saveRadioButton(evaluator, task, annotationStorage, changes); 51722 } 51723 } 51724 async _saveCheckbox(evaluator, task, annotationStorage, changes) { 51725 if (!annotationStorage) { 51726 return; 51727 } 51728 const storageEntry = annotationStorage.get(this.data.id); 51729 const flags = this._buildFlags(storageEntry?.noView, storageEntry?.noPrint); 51730 let rotation = storageEntry?.rotation, 51731 value = storageEntry?.value; 51732 if (rotation === undefined && flags === undefined) { 51733 if (value === undefined) { 51734 return; 51735 } 51736 const defaultValue = this.data.fieldValue === this.data.exportValue; 51737 if (defaultValue === value) { 51738 return; 51739 } 51740 } 51741 let dict = evaluator.xref.fetchIfRef(this.ref); 51742 if (!(dict instanceof Dict)) { 51743 return; 51744 } 51745 dict = dict.clone(); 51746 if (rotation === undefined) { 51747 rotation = this.rotation; 51748 } 51749 if (value === undefined) { 51750 value = this.data.fieldValue === this.data.exportValue; 51751 } 51752 const xfa = { 51753 path: this.data.fieldName, 51754 value: value ? this.data.exportValue : "" 51755 }; 51756 const name = Name.get(value ? this.data.exportValue : "Off"); 51757 this.setValue(dict, name, evaluator.xref, changes); 51758 dict.set("AS", name); 51759 dict.set("M", `D:${getModificationDate()}`); 51760 if (flags !== undefined) { 51761 dict.set("F", flags); 51762 } 51763 const maybeMK = this._getMKDict(rotation); 51764 if (maybeMK) { 51765 dict.set("MK", maybeMK); 51766 } 51767 changes.put(this.ref, { 51768 data: dict, 51769 xfa, 51770 needAppearances: false 51771 }); 51772 } 51773 async _saveRadioButton(evaluator, task, annotationStorage, changes) { 51774 if (!annotationStorage) { 51775 return; 51776 } 51777 const storageEntry = annotationStorage.get(this.data.id); 51778 const flags = this._buildFlags(storageEntry?.noView, storageEntry?.noPrint); 51779 let rotation = storageEntry?.rotation, 51780 value = storageEntry?.value; 51781 if (rotation === undefined && flags === undefined) { 51782 if (value === undefined) { 51783 return; 51784 } 51785 const defaultValue = this.data.fieldValue === this.data.buttonValue; 51786 if (defaultValue === value) { 51787 return; 51788 } 51789 } 51790 let dict = evaluator.xref.fetchIfRef(this.ref); 51791 if (!(dict instanceof Dict)) { 51792 return; 51793 } 51794 dict = dict.clone(); 51795 if (value === undefined) { 51796 value = this.data.fieldValue === this.data.buttonValue; 51797 } 51798 if (rotation === undefined) { 51799 rotation = this.rotation; 51800 } 51801 const xfa = { 51802 path: this.data.fieldName, 51803 value: value ? this.data.buttonValue : "" 51804 }; 51805 const name = Name.get(value ? this.data.buttonValue : "Off"); 51806 if (value) { 51807 this.setValue(dict, name, evaluator.xref, changes); 51808 } 51809 dict.set("AS", name); 51810 dict.set("M", `D:${getModificationDate()}`); 51811 if (flags !== undefined) { 51812 dict.set("F", flags); 51813 } 51814 const maybeMK = this._getMKDict(rotation); 51815 if (maybeMK) { 51816 dict.set("MK", maybeMK); 51817 } 51818 changes.put(this.ref, { 51819 data: dict, 51820 xfa, 51821 needAppearances: false 51822 }); 51823 } 51824 _getDefaultCheckedAppearance(params, type) { 51825 const { 51826 width, 51827 height 51828 } = this; 51829 const bbox = [0, 0, width, height]; 51830 const FONT_RATIO = 0.8; 51831 const fontSize = Math.min(width, height) * FONT_RATIO; 51832 let metrics, char; 51833 if (type === "check") { 51834 metrics = { 51835 width: 0.755 * fontSize, 51836 height: 0.705 * fontSize 51837 }; 51838 char = "\x33"; 51839 } else if (type === "disc") { 51840 metrics = { 51841 width: 0.791 * fontSize, 51842 height: 0.705 * fontSize 51843 }; 51844 char = "\x6C"; 51845 } else { 51846 unreachable(`_getDefaultCheckedAppearance - unsupported type: ${type}`); 51847 } 51848 const xShift = numberToString((width - metrics.width) / 2); 51849 const yShift = numberToString((height - metrics.height) / 2); 51850 const appearance = `q BT /PdfJsZaDb ${fontSize} Tf 0 g ${xShift} ${yShift} Td (${char}) Tj ET Q`; 51851 const appearanceStreamDict = new Dict(params.xref); 51852 appearanceStreamDict.set("FormType", 1); 51853 appearanceStreamDict.setIfName("Subtype", "Form"); 51854 appearanceStreamDict.setIfName("Type", "XObject"); 51855 appearanceStreamDict.set("BBox", bbox); 51856 appearanceStreamDict.set("Matrix", [1, 0, 0, 1, 0, 0]); 51857 appearanceStreamDict.set("Length", appearance.length); 51858 const resources = new Dict(params.xref); 51859 const font = new Dict(params.xref); 51860 font.set("PdfJsZaDb", this.fallbackFontDict); 51861 resources.set("Font", font); 51862 appearanceStreamDict.set("Resources", resources); 51863 this.checkedAppearance = new StringStream(appearance); 51864 this.checkedAppearance.dict = appearanceStreamDict; 51865 this._streams.push(this.checkedAppearance); 51866 } 51867 _processCheckBox(params) { 51868 const customAppearance = params.dict.get("AP"); 51869 if (!(customAppearance instanceof Dict)) { 51870 return; 51871 } 51872 const normalAppearance = customAppearance.get("N"); 51873 if (!(normalAppearance instanceof Dict)) { 51874 return; 51875 } 51876 const asValue = this._decodeFormValue(params.dict.get("AS")); 51877 if (typeof asValue === "string") { 51878 this.data.fieldValue = asValue; 51879 } 51880 const yes = this.data.fieldValue !== null && this.data.fieldValue !== "Off" ? this.data.fieldValue : "Yes"; 51881 const exportValues = this._decodeFormValue(normalAppearance.getKeys()); 51882 if (exportValues.length === 0) { 51883 exportValues.push("Off", yes); 51884 } else if (exportValues.length === 1) { 51885 if (exportValues[0] === "Off") { 51886 exportValues.push(yes); 51887 } else { 51888 exportValues.unshift("Off"); 51889 } 51890 } else if (exportValues.includes(yes)) { 51891 exportValues.length = 0; 51892 exportValues.push("Off", yes); 51893 } else { 51894 const otherYes = exportValues.find(v => v !== "Off"); 51895 exportValues.length = 0; 51896 exportValues.push("Off", otherYes); 51897 } 51898 if (!exportValues.includes(this.data.fieldValue)) { 51899 this.data.fieldValue = "Off"; 51900 } 51901 this.data.exportValue = exportValues[1]; 51902 const checkedAppearance = normalAppearance.get(this.data.exportValue); 51903 this.checkedAppearance = checkedAppearance instanceof BaseStream ? checkedAppearance : null; 51904 const uncheckedAppearance = normalAppearance.get("Off"); 51905 this.uncheckedAppearance = uncheckedAppearance instanceof BaseStream ? uncheckedAppearance : null; 51906 if (this.checkedAppearance) { 51907 this._streams.push(this.checkedAppearance); 51908 } else { 51909 this._getDefaultCheckedAppearance(params, "check"); 51910 } 51911 if (this.uncheckedAppearance) { 51912 this._streams.push(this.uncheckedAppearance); 51913 } 51914 this._fallbackFontDict = this.fallbackFontDict; 51915 if (this.data.defaultFieldValue === null) { 51916 this.data.defaultFieldValue = "Off"; 51917 } 51918 } 51919 _processRadioButton(params) { 51920 this.data.buttonValue = null; 51921 const fieldParent = params.dict.get("Parent"); 51922 if (fieldParent instanceof Dict) { 51923 this.parent = params.dict.getRaw("Parent"); 51924 const fieldParentValue = fieldParent.get("V"); 51925 if (fieldParentValue instanceof Name) { 51926 this.data.fieldValue = this._decodeFormValue(fieldParentValue); 51927 } 51928 } 51929 const appearanceStates = params.dict.get("AP"); 51930 if (!(appearanceStates instanceof Dict)) { 51931 return; 51932 } 51933 const normalAppearance = appearanceStates.get("N"); 51934 if (!(normalAppearance instanceof Dict)) { 51935 return; 51936 } 51937 for (const key of normalAppearance.getKeys()) { 51938 if (key !== "Off") { 51939 this.data.buttonValue = this._decodeFormValue(key); 51940 break; 51941 } 51942 } 51943 const checkedAppearance = normalAppearance.get(this.data.buttonValue); 51944 this.checkedAppearance = checkedAppearance instanceof BaseStream ? checkedAppearance : null; 51945 const uncheckedAppearance = normalAppearance.get("Off"); 51946 this.uncheckedAppearance = uncheckedAppearance instanceof BaseStream ? uncheckedAppearance : null; 51947 if (this.checkedAppearance) { 51948 this._streams.push(this.checkedAppearance); 51949 } else { 51950 this._getDefaultCheckedAppearance(params, "disc"); 51951 } 51952 if (this.uncheckedAppearance) { 51953 this._streams.push(this.uncheckedAppearance); 51954 } 51955 this._fallbackFontDict = this.fallbackFontDict; 51956 if (this.data.defaultFieldValue === null) { 51957 this.data.defaultFieldValue = "Off"; 51958 } 51959 } 51960 _processPushButton(params) { 51961 const { 51962 dict, 51963 annotationGlobals 51964 } = params; 51965 if (!dict.has("A") && !dict.has("AA") && !this.data.alternativeText) { 51966 warn("Push buttons without action dictionaries are not supported"); 51967 return; 51968 } 51969 this.data.isTooltipOnly = !dict.has("A") && !dict.has("AA"); 51970 Catalog.parseDestDictionary({ 51971 destDict: dict, 51972 resultObj: this.data, 51973 docBaseUrl: annotationGlobals.baseUrl, 51974 docAttachments: annotationGlobals.attachments 51975 }); 51976 } 51977 getFieldObject() { 51978 let type = "button"; 51979 let exportValues; 51980 if (this.data.checkBox) { 51981 type = "checkbox"; 51982 exportValues = this.data.exportValue; 51983 } else if (this.data.radioButton) { 51984 type = "radiobutton"; 51985 exportValues = this.data.buttonValue; 51986 } 51987 return { 51988 id: this.data.id, 51989 value: this.data.fieldValue || "Off", 51990 defaultValue: this.data.defaultFieldValue, 51991 exportValues, 51992 editable: !this.data.readOnly, 51993 name: this.data.fieldName, 51994 rect: this.data.rect, 51995 hidden: this.data.hidden, 51996 actions: this.data.actions, 51997 page: this.data.pageIndex, 51998 strokeColor: this.data.borderColor, 51999 fillColor: this.data.backgroundColor, 52000 rotation: this.rotation, 52001 type 52002 }; 52003 } 52004 get fallbackFontDict() { 52005 const dict = new Dict(); 52006 dict.setIfName("BaseFont", "ZapfDingbats"); 52007 dict.setIfName("Type", "FallbackType"); 52008 dict.setIfName("Subtype", "FallbackType"); 52009 dict.setIfName("Encoding", "ZapfDingbatsEncoding"); 52010 return shadow(this, "fallbackFontDict", dict); 52011 } 52012} 52013class ChoiceWidgetAnnotation extends WidgetAnnotation { 52014 constructor(params) { 52015 super(params); 52016 const { 52017 dict, 52018 xref 52019 } = params; 52020 this.indices = dict.getArray("I"); 52021 this.hasIndices = Array.isArray(this.indices) && this.indices.length > 0; 52022 this.data.options = []; 52023 const options = getInheritableProperty({ 52024 dict, 52025 key: "Opt" 52026 }); 52027 if (Array.isArray(options)) { 52028 for (let i = 0, ii = options.length; i < ii; i++) { 52029 const option = xref.fetchIfRef(options[i]); 52030 const isOptionArray = Array.isArray(option); 52031 this.data.options[i] = { 52032 exportValue: this._decodeFormValue(isOptionArray ? xref.fetchIfRef(option[0]) : option), 52033 displayValue: this._decodeFormValue(isOptionArray ? xref.fetchIfRef(option[1]) : option) 52034 }; 52035 } 52036 } 52037 if (!this.hasIndices) { 52038 if (typeof this.data.fieldValue === "string") { 52039 this.data.fieldValue = [this.data.fieldValue]; 52040 } else { 52041 this.data.fieldValue ||= []; 52042 } 52043 } else { 52044 this.data.fieldValue = []; 52045 const ii = this.data.options.length; 52046 for (const i of this.indices) { 52047 if (Number.isInteger(i) && i >= 0 && i < ii) { 52048 this.data.fieldValue.push(this.data.options[i].exportValue); 52049 } 52050 } 52051 } 52052 if (this.data.options.length === 0 && this.data.fieldValue.length > 0) { 52053 this.data.options = this.data.fieldValue.map(value => ({ 52054 exportValue: value, 52055 displayValue: value 52056 })); 52057 } 52058 this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO); 52059 this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT); 52060 this._hasText = true; 52061 } 52062 getFieldObject() { 52063 const type = this.data.combo ? "combobox" : "listbox"; 52064 const value = this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : null; 52065 return { 52066 id: this.data.id, 52067 value, 52068 defaultValue: this.data.defaultFieldValue, 52069 editable: !this.data.readOnly, 52070 name: this.data.fieldName, 52071 rect: this.data.rect, 52072 numItems: this.data.fieldValue.length, 52073 multipleSelection: this.data.multiSelect, 52074 hidden: this.data.hidden, 52075 actions: this.data.actions, 52076 items: this.data.options, 52077 page: this.data.pageIndex, 52078 strokeColor: this.data.borderColor, 52079 fillColor: this.data.backgroundColor, 52080 rotation: this.rotation, 52081 type 52082 }; 52083 } 52084 amendSavedDict(annotationStorage, dict) { 52085 if (!this.hasIndices) { 52086 return; 52087 } 52088 let values = annotationStorage?.get(this.data.id)?.value; 52089 if (!Array.isArray(values)) { 52090 values = [values]; 52091 } 52092 const indices = []; 52093 const { 52094 options 52095 } = this.data; 52096 for (let i = 0, j = 0, ii = options.length; i < ii; i++) { 52097 if (options[i].exportValue === values[j]) { 52098 indices.push(i); 52099 j += 1; 52100 } 52101 } 52102 dict.set("I", indices); 52103 } 52104 async _getAppearance(evaluator, task, intent, annotationStorage) { 52105 if (this.data.combo) { 52106 return super._getAppearance(evaluator, task, intent, annotationStorage); 52107 } 52108 let exportedValue, rotation; 52109 const storageEntry = annotationStorage?.get(this.data.id); 52110 if (storageEntry) { 52111 rotation = storageEntry.rotation; 52112 exportedValue = storageEntry.value; 52113 } 52114 if (rotation === undefined && exportedValue === undefined && !this._needAppearances) { 52115 return null; 52116 } 52117 if (exportedValue === undefined) { 52118 exportedValue = this.data.fieldValue; 52119 } else if (!Array.isArray(exportedValue)) { 52120 exportedValue = [exportedValue]; 52121 } 52122 const defaultPadding = 1; 52123 const defaultHPadding = 2; 52124 let { 52125 width: totalWidth, 52126 height: totalHeight 52127 } = this; 52128 if (rotation === 90 || rotation === 270) { 52129 [totalWidth, totalHeight] = [totalHeight, totalWidth]; 52130 } 52131 const lineCount = this.data.options.length; 52132 const valueIndices = []; 52133 for (let i = 0; i < lineCount; i++) { 52134 const { 52135 exportValue 52136 } = this.data.options[i]; 52137 if (exportedValue.includes(exportValue)) { 52138 valueIndices.push(i); 52139 } 52140 } 52141 if (!this._defaultAppearance) { 52142 this.data.defaultAppearanceData = parseDefaultAppearance(this._defaultAppearance = "/Helvetica 0 Tf 0 g"); 52143 } 52144 const font = await WidgetAnnotation._getFontData(evaluator, task, this.data.defaultAppearanceData, this._fieldResources.mergedResources); 52145 let defaultAppearance; 52146 let { 52147 fontSize 52148 } = this.data.defaultAppearanceData; 52149 if (!fontSize) { 52150 const lineHeight = (totalHeight - defaultPadding) / lineCount; 52151 let lineWidth = -1; 52152 let value; 52153 for (const { 52154 displayValue 52155 } of this.data.options) { 52156 const width = this._getTextWidth(displayValue, font); 52157 if (width > lineWidth) { 52158 lineWidth = width; 52159 value = displayValue; 52160 } 52161 } 52162 [defaultAppearance, fontSize] = this._computeFontSize(lineHeight, totalWidth - 2 * defaultHPadding, value, font, -1); 52163 } else { 52164 defaultAppearance = this._defaultAppearance; 52165 } 52166 const lineHeight = fontSize * LINE_FACTOR; 52167 const vPadding = (lineHeight - fontSize) / 2; 52168 const numberOfVisibleLines = Math.floor(totalHeight / lineHeight); 52169 let firstIndex = 0; 52170 if (valueIndices.length > 0) { 52171 const minIndex = Math.min(...valueIndices); 52172 const maxIndex = Math.max(...valueIndices); 52173 firstIndex = Math.max(0, maxIndex - numberOfVisibleLines + 1); 52174 if (firstIndex > minIndex) { 52175 firstIndex = minIndex; 52176 } 52177 } 52178 const end = Math.min(firstIndex + numberOfVisibleLines + 1, lineCount); 52179 const buf = ["/Tx BMC q", `1 1 ${totalWidth} ${totalHeight} re W n`]; 52180 if (valueIndices.length) { 52181 buf.push("0.600006 0.756866 0.854904 rg"); 52182 for (const index of valueIndices) { 52183 if (firstIndex <= index && index < end) { 52184 buf.push(`1 ${totalHeight - (index - firstIndex + 1) * lineHeight} ${totalWidth} ${lineHeight} re f`); 52185 } 52186 } 52187 } 52188 buf.push("BT", defaultAppearance, `1 0 0 1 0 ${totalHeight} Tm`); 52189 const prevInfo = { 52190 shift: 0 52191 }; 52192 for (let i = firstIndex; i < end; i++) { 52193 const { 52194 displayValue 52195 } = this.data.options[i]; 52196 const vpadding = i === firstIndex ? vPadding : 0; 52197 buf.push(this._renderText(displayValue, font, fontSize, totalWidth, 0, prevInfo, defaultHPadding, -lineHeight + vpadding)); 52198 } 52199 buf.push("ET Q EMC"); 52200 return buf.join("\n"); 52201 } 52202} 52203class SignatureWidgetAnnotation extends WidgetAnnotation { 52204 constructor(params) { 52205 super(params); 52206 this.data.fieldValue = null; 52207 this.data.hasOwnCanvas = this.data.noRotate; 52208 this.data.noHTML = !this.data.hasOwnCanvas; 52209 } 52210 getFieldObject() { 52211 return { 52212 id: this.data.id, 52213 value: null, 52214 page: this.data.pageIndex, 52215 type: "signature" 52216 }; 52217 } 52218} 52219class TextAnnotation extends MarkupAnnotation { 52220 constructor(params) { 52221 const DEFAULT_ICON_SIZE = 22; 52222 super(params); 52223 this.data.noRotate = true; 52224 this.data.hasOwnCanvas = this.data.noRotate; 52225 this.data.noHTML = false; 52226 const { 52227 dict 52228 } = params; 52229 this.data.annotationType = AnnotationType.TEXT; 52230 if (this.data.hasAppearance) { 52231 this.data.name = "NoIcon"; 52232 } else { 52233 this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE; 52234 this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE; 52235 this.data.name = dict.has("Name") ? dict.get("Name").name : "Note"; 52236 } 52237 if (dict.has("State")) { 52238 this.data.state = dict.get("State") || null; 52239 this.data.stateModel = dict.get("StateModel") || null; 52240 } else { 52241 this.data.state = null; 52242 this.data.stateModel = null; 52243 } 52244 } 52245} 52246class LinkAnnotation extends Annotation { 52247 constructor(params) { 52248 super(params); 52249 const { 52250 dict, 52251 annotationGlobals 52252 } = params; 52253 this.data.annotationType = AnnotationType.LINK; 52254 this.data.noHTML = false; 52255 const quadPoints = getQuadPoints(dict, this.rectangle); 52256 if (quadPoints) { 52257 this.data.quadPoints = quadPoints; 52258 } 52259 this.data.borderColor ||= this.data.color; 52260 Catalog.parseDestDictionary({ 52261 destDict: dict, 52262 resultObj: this.data, 52263 docBaseUrl: annotationGlobals.baseUrl, 52264 docAttachments: annotationGlobals.attachments 52265 }); 52266 } 52267 get overlaysTextContent() { 52268 return true; 52269 } 52270} 52271class PopupAnnotation extends Annotation { 52272 constructor(params) { 52273 super(params); 52274 const { 52275 dict 52276 } = params; 52277 this.data.annotationType = AnnotationType.POPUP; 52278 this.data.noHTML = false; 52279 if (this.width === 0 || this.height === 0) { 52280 this.data.rect = null; 52281 } 52282 let parentItem = dict.get("Parent"); 52283 if (!parentItem) { 52284 warn("Popup annotation has a missing or invalid parent annotation."); 52285 return; 52286 } 52287 this.data.parentRect = lookupNormalRect(parentItem.getArray("Rect"), null); 52288 this.data.creationDate = parentItem.get("CreationDate") || ""; 52289 const rt = parentItem.get("RT"); 52290 if (isName(rt, AnnotationReplyType.GROUP)) { 52291 parentItem = parentItem.get("IRT"); 52292 } 52293 if (!parentItem.has("M")) { 52294 this.data.modificationDate = null; 52295 } else { 52296 this.setModificationDate(parentItem.get("M")); 52297 this.data.modificationDate = this.modificationDate; 52298 } 52299 if (!parentItem.has("C")) { 52300 this.data.color = null; 52301 } else { 52302 this.setColor(parentItem.getArray("C")); 52303 this.data.color = this.color; 52304 } 52305 if (!this.viewable) { 52306 const parentFlags = parentItem.get("F"); 52307 if (this._isViewable(parentFlags)) { 52308 this.setFlags(parentFlags); 52309 } 52310 } 52311 this.setTitle(parentItem.get("T")); 52312 this.data.titleObj = this._title; 52313 this.setContents(parentItem.get("Contents")); 52314 this.data.contentsObj = this._contents; 52315 if (parentItem.has("RC")) { 52316 this.data.richText = XFAFactory.getRichTextAsHtml(parentItem.get("RC")); 52317 } 52318 this.data.open = !!dict.get("Open"); 52319 } 52320 static createNewDict(annotation, xref, _params) { 52321 const { 52322 oldAnnotation, 52323 rect, 52324 parent 52325 } = annotation; 52326 const popup = oldAnnotation || new Dict(xref); 52327 popup.setIfNotExists("Type", Name.get("Annot")); 52328 popup.setIfNotExists("Subtype", Name.get("Popup")); 52329 popup.setIfNotExists("Open", false); 52330 popup.setIfArray("Rect", rect); 52331 popup.set("Parent", parent); 52332 return popup; 52333 } 52334 static async createNewAppearanceStream(annotation, xref, params) { 52335 return null; 52336 } 52337} 52338class FreeTextAnnotation extends MarkupAnnotation { 52339 constructor(params) { 52340 super(params); 52341 this.data.hasOwnCanvas = this.data.noRotate; 52342 this.data.isEditable = !this.data.noHTML; 52343 this.data.noHTML = false; 52344 const { 52345 annotationGlobals, 52346 evaluatorOptions, 52347 xref 52348 } = params; 52349 this.data.annotationType = AnnotationType.FREETEXT; 52350 this.setDefaultAppearance(params); 52351 this._hasAppearance = !!this.appearance; 52352 if (this._hasAppearance) { 52353 const { 52354 fontColor, 52355 fontSize 52356 } = parseAppearanceStream(this.appearance, evaluatorOptions, xref, annotationGlobals.globalColorSpaceCache); 52357 this.data.defaultAppearanceData.fontColor = fontColor; 52358 this.data.defaultAppearanceData.fontSize = fontSize || 10; 52359 } else { 52360 this.data.defaultAppearanceData.fontSize ||= 10; 52361 const { 52362 fontColor, 52363 fontSize 52364 } = this.data.defaultAppearanceData; 52365 if (this._contents.str) { 52366 this.data.textContent = this._contents.str.split(/\r\n?|\n/).map(line => line.trimEnd()); 52367 const { 52368 coords, 52369 bbox, 52370 matrix 52371 } = FakeUnicodeFont.getFirstPositionInfo(this.rectangle, this.rotation, fontSize); 52372 this.data.textPosition = this._transformPoint(coords, bbox, matrix); 52373 } 52374 if (this._isOffscreenCanvasSupported) { 52375 const strokeAlpha = params.dict.get("CA"); 52376 const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif"); 52377 this.appearance = fakeUnicodeFont.createAppearance(this._contents.str, this.rectangle, this.rotation, fontSize, fontColor, strokeAlpha); 52378 this._streams.push(this.appearance); 52379 } else { 52380 warn("FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly."); 52381 } 52382 } 52383 } 52384 get hasTextContent() { 52385 return this._hasAppearance; 52386 } 52387 static createNewDict(annotation, xref, { 52388 apRef, 52389 ap 52390 }) { 52391 const { 52392 color, 52393 date, 52394 fontSize, 52395 oldAnnotation, 52396 rect, 52397 rotation, 52398 user, 52399 value 52400 } = annotation; 52401 const freetext = oldAnnotation || new Dict(xref); 52402 freetext.setIfNotExists("Type", Name.get("Annot")); 52403 freetext.setIfNotExists("Subtype", Name.get("FreeText")); 52404 freetext.set(oldAnnotation ? "M" : "CreationDate", `D:${getModificationDate(date)}`); 52405 if (oldAnnotation) { 52406 freetext.delete("RC"); 52407 } 52408 freetext.setIfArray("Rect", rect); 52409 const da = `/Helv ${fontSize} Tf ${getPdfColor(color, true)}`; 52410 freetext.set("DA", da); 52411 freetext.setIfDefined("Contents", stringToAsciiOrUTF16BE(value)); 52412 freetext.setIfNotExists("F", 4); 52413 freetext.setIfNotExists("Border", [0, 0, 0]); 52414 freetext.setIfNumber("Rotate", rotation); 52415 freetext.setIfDefined("T", stringToAsciiOrUTF16BE(user)); 52416 if (apRef || ap) { 52417 const n = new Dict(xref); 52418 freetext.set("AP", n); 52419 n.set("N", apRef || ap); 52420 } 52421 return freetext; 52422 } 52423 static async createNewAppearanceStream(annotation, xref, params) { 52424 const { 52425 baseFontRef, 52426 evaluator, 52427 task 52428 } = params; 52429 const { 52430 color, 52431 fontSize, 52432 rect, 52433 rotation, 52434 value 52435 } = annotation; 52436 if (!color) { 52437 return null; 52438 } 52439 const resources = new Dict(xref); 52440 const font = new Dict(xref); 52441 if (baseFontRef) { 52442 font.set("Helv", baseFontRef); 52443 } else { 52444 const baseFont = new Dict(xref); 52445 baseFont.setIfName("BaseFont", "Helvetica"); 52446 baseFont.setIfName("Type", "Font"); 52447 baseFont.setIfName("Subtype", "Type1"); 52448 baseFont.setIfName("Encoding", "WinAnsiEncoding"); 52449 font.set("Helv", baseFont); 52450 } 52451 resources.set("Font", font); 52452 const helv = await WidgetAnnotation._getFontData(evaluator, task, { 52453 fontName: "Helv", 52454 fontSize 52455 }, resources); 52456 const [x1, y1, x2, y2] = rect; 52457 let w = x2 - x1; 52458 let h = y2 - y1; 52459 if (rotation % 180 !== 0) { 52460 [w, h] = [h, w]; 52461 } 52462 const lines = value.split("\n"); 52463 const scale = fontSize / 1000; 52464 let totalWidth = -Infinity; 52465 const encodedLines = []; 52466 for (let line of lines) { 52467 const encoded = helv.encodeString(line); 52468 if (encoded.length > 1) { 52469 return null; 52470 } 52471 line = encoded.join(""); 52472 encodedLines.push(line); 52473 let lineWidth = 0; 52474 const glyphs = helv.charsToGlyphs(line); 52475 for (const glyph of glyphs) { 52476 lineWidth += glyph.width * scale; 52477 } 52478 totalWidth = Math.max(totalWidth, lineWidth); 52479 } 52480 let hscale = 1; 52481 if (totalWidth > w) { 52482 hscale = w / totalWidth; 52483 } 52484 let vscale = 1; 52485 const lineHeight = LINE_FACTOR * fontSize; 52486 const lineAscent = (LINE_FACTOR - LINE_DESCENT_FACTOR) * fontSize; 52487 const totalHeight = lineHeight * lines.length; 52488 if (totalHeight > h) { 52489 vscale = h / totalHeight; 52490 } 52491 const fscale = Math.min(hscale, vscale); 52492 const newFontSize = fontSize * fscale; 52493 let firstPoint, clipBox, matrix; 52494 switch (rotation) { 52495 case 0: 52496 matrix = [1, 0, 0, 1]; 52497 clipBox = [rect[0], rect[1], w, h]; 52498 firstPoint = [rect[0], rect[3] - lineAscent]; 52499 break; 52500 case 90: 52501 matrix = [0, 1, -1, 0]; 52502 clipBox = [rect[1], -rect[2], w, h]; 52503 firstPoint = [rect[1], -rect[0] - lineAscent]; 52504 break; 52505 case 180: 52506 matrix = [-1, 0, 0, -1]; 52507 clipBox = [-rect[2], -rect[3], w, h]; 52508 firstPoint = [-rect[2], -rect[1] - lineAscent]; 52509 break; 52510 case 270: 52511 matrix = [0, -1, 1, 0]; 52512 clipBox = [-rect[3], rect[0], w, h]; 52513 firstPoint = [-rect[3], rect[2] - lineAscent]; 52514 break; 52515 } 52516 const buffer = ["q", `${matrix.join(" ")} 0 0 cm`, `${clipBox.join(" ")} re W n`, `BT`, `${getPdfColor(color, true)}`, `0 Tc /Helv ${numberToString(newFontSize)} Tf`]; 52517 buffer.push(`${firstPoint.join(" ")} Td (${escapeString(encodedLines[0])}) Tj`); 52518 const vShift = numberToString(lineHeight); 52519 for (let i = 1, ii = encodedLines.length; i < ii; i++) { 52520 const line = encodedLines[i]; 52521 buffer.push(`0 -${vShift} Td (${escapeString(line)}) Tj`); 52522 } 52523 buffer.push("ET", "Q"); 52524 const appearance = buffer.join("\n"); 52525 const appearanceStreamDict = new Dict(xref); 52526 appearanceStreamDict.set("FormType", 1); 52527 appearanceStreamDict.setIfName("Subtype", "Form"); 52528 appearanceStreamDict.setIfName("Type", "XObject"); 52529 appearanceStreamDict.set("BBox", rect); 52530 appearanceStreamDict.set("Resources", resources); 52531 appearanceStreamDict.set("Matrix", [1, 0, 0, 1, -rect[0], -rect[1]]); 52532 const ap = new StringStream(appearance); 52533 ap.dict = appearanceStreamDict; 52534 return ap; 52535 } 52536} 52537class LineAnnotation extends MarkupAnnotation { 52538 constructor(params) { 52539 super(params); 52540 const { 52541 dict, 52542 xref 52543 } = params; 52544 this.data.annotationType = AnnotationType.LINE; 52545 this.data.hasOwnCanvas = this.data.noRotate; 52546 this.data.noHTML = false; 52547 const lineCoordinates = lookupRect(dict.getArray("L"), [0, 0, 0, 0]); 52548 this.data.lineCoordinates = Util.normalizeRect(lineCoordinates); 52549 this.setLineEndings(dict.getArray("LE")); 52550 this.data.lineEndings = this.lineEndings; 52551 if (!this.appearance) { 52552 const strokeColor = getPdfColorArray(this.color, [0, 0, 0]); 52553 const strokeAlpha = dict.get("CA"); 52554 const interiorColor = getRgbColor(dict.getArray("IC"), null); 52555 const fillColor = getPdfColorArray(interiorColor); 52556 const fillAlpha = fillColor ? strokeAlpha : null; 52557 const borderWidth = this.borderStyle.width || 1, 52558 borderAdjust = 2 * borderWidth; 52559 const bbox = [this.data.lineCoordinates[0] - borderAdjust, this.data.lineCoordinates[1] - borderAdjust, this.data.lineCoordinates[2] + borderAdjust, this.data.lineCoordinates[3] + borderAdjust]; 52560 if (!Util.intersect(this.rectangle, bbox)) { 52561 this.rectangle = bbox; 52562 } 52563 this._setDefaultAppearance({ 52564 xref, 52565 extra: `${borderWidth} w`, 52566 strokeColor, 52567 fillColor, 52568 strokeAlpha, 52569 fillAlpha, 52570 pointsCallback: (buffer, points) => { 52571 buffer.push(`${lineCoordinates[0]} ${lineCoordinates[1]} m`, `${lineCoordinates[2]} ${lineCoordinates[3]} l`, "S"); 52572 return [points[0] - borderWidth, points[7] - borderWidth, points[2] + borderWidth, points[3] + borderWidth]; 52573 } 52574 }); 52575 } 52576 } 52577} 52578class SquareAnnotation extends MarkupAnnotation { 52579 constructor(params) { 52580 super(params); 52581 const { 52582 dict, 52583 xref 52584 } = params; 52585 this.data.annotationType = AnnotationType.SQUARE; 52586 this.data.hasOwnCanvas = this.data.noRotate; 52587 this.data.noHTML = false; 52588 if (!this.appearance) { 52589 const strokeColor = getPdfColorArray(this.color, [0, 0, 0]); 52590 const strokeAlpha = dict.get("CA"); 52591 const interiorColor = getRgbColor(dict.getArray("IC"), null); 52592 const fillColor = getPdfColorArray(interiorColor); 52593 const fillAlpha = fillColor ? strokeAlpha : null; 52594 if (this.borderStyle.width === 0 && !fillColor) { 52595 return; 52596 } 52597 this._setDefaultAppearance({ 52598 xref, 52599 extra: `${this.borderStyle.width} w`, 52600 strokeColor, 52601 fillColor, 52602 strokeAlpha, 52603 fillAlpha, 52604 pointsCallback: (buffer, points) => { 52605 const x = points[4] + this.borderStyle.width / 2; 52606 const y = points[5] + this.borderStyle.width / 2; 52607 const width = points[6] - points[4] - this.borderStyle.width; 52608 const height = points[3] - points[7] - this.borderStyle.width; 52609 buffer.push(`${x} ${y} ${width} ${height} re`); 52610 if (fillColor) { 52611 buffer.push("B"); 52612 } else { 52613 buffer.push("S"); 52614 } 52615 return [points[0], points[7], points[2], points[3]]; 52616 } 52617 }); 52618 } 52619 } 52620} 52621class CircleAnnotation extends MarkupAnnotation { 52622 constructor(params) { 52623 super(params); 52624 const { 52625 dict, 52626 xref 52627 } = params; 52628 this.data.annotationType = AnnotationType.CIRCLE; 52629 if (!this.appearance) { 52630 const strokeColor = getPdfColorArray(this.color, [0, 0, 0]); 52631 const strokeAlpha = dict.get("CA"); 52632 const interiorColor = getRgbColor(dict.getArray("IC"), null); 52633 const fillColor = getPdfColorArray(interiorColor); 52634 const fillAlpha = fillColor ? strokeAlpha : null; 52635 if (this.borderStyle.width === 0 && !fillColor) { 52636 return; 52637 } 52638 const controlPointsDistance = 4 / 3 * Math.tan(Math.PI / (2 * 4)); 52639 this._setDefaultAppearance({ 52640 xref, 52641 extra: `${this.borderStyle.width} w`, 52642 strokeColor, 52643 fillColor, 52644 strokeAlpha, 52645 fillAlpha, 52646 pointsCallback: (buffer, points) => { 52647 const x0 = points[0] + this.borderStyle.width / 2; 52648 const y0 = points[1] - this.borderStyle.width / 2; 52649 const x1 = points[6] - this.borderStyle.width / 2; 52650 const y1 = points[7] + this.borderStyle.width / 2; 52651 const xMid = x0 + (x1 - x0) / 2; 52652 const yMid = y0 + (y1 - y0) / 2; 52653 const xOffset = (x1 - x0) / 2 * controlPointsDistance; 52654 const yOffset = (y1 - y0) / 2 * controlPointsDistance; 52655 buffer.push(`${xMid} ${y1} m`, `${xMid + xOffset} ${y1} ${x1} ${yMid + yOffset} ${x1} ${yMid} c`, `${x1} ${yMid - yOffset} ${xMid + xOffset} ${y0} ${xMid} ${y0} c`, `${xMid - xOffset} ${y0} ${x0} ${yMid - yOffset} ${x0} ${yMid} c`, `${x0} ${yMid + yOffset} ${xMid - xOffset} ${y1} ${xMid} ${y1} c`, "h"); 52656 if (fillColor) { 52657 buffer.push("B"); 52658 } else { 52659 buffer.push("S"); 52660 } 52661 return [points[0], points[7], points[2], points[3]]; 52662 } 52663 }); 52664 } 52665 } 52666} 52667class PolylineAnnotation extends MarkupAnnotation { 52668 constructor(params) { 52669 super(params); 52670 const { 52671 dict, 52672 xref 52673 } = params; 52674 this.data.annotationType = AnnotationType.POLYLINE; 52675 this.data.hasOwnCanvas = this.data.noRotate; 52676 this.data.noHTML = false; 52677 this.data.vertices = null; 52678 if (!(this instanceof PolygonAnnotation)) { 52679 this.setLineEndings(dict.getArray("LE")); 52680 this.data.lineEndings = this.lineEndings; 52681 } 52682 const rawVertices = dict.getArray("Vertices"); 52683 if (!isNumberArray(rawVertices, null)) { 52684 return; 52685 } 52686 const vertices = this.data.vertices = Float32Array.from(rawVertices); 52687 if (!this.appearance) { 52688 const strokeColor = getPdfColorArray(this.color, [0, 0, 0]); 52689 const strokeAlpha = dict.get("CA"); 52690 let fillColor = getRgbColor(dict.getArray("IC"), null); 52691 if (fillColor) { 52692 fillColor = getPdfColorArray(fillColor); 52693 } 52694 let operator; 52695 if (fillColor) { 52696 if (this.color) { 52697 operator = fillColor.every((c, i) => c === strokeColor[i]) ? "f" : "B"; 52698 } else { 52699 operator = "f"; 52700 } 52701 } else { 52702 operator = "S"; 52703 } 52704 const borderWidth = this.borderStyle.width || 1, 52705 borderAdjust = 2 * borderWidth; 52706 const bbox = [Infinity, Infinity, -Infinity, -Infinity]; 52707 for (let i = 0, ii = vertices.length; i < ii; i += 2) { 52708 Util.rectBoundingBox(vertices[i] - borderAdjust, vertices[i + 1] - borderAdjust, vertices[i] + borderAdjust, vertices[i + 1] + borderAdjust, bbox); 52709 } 52710 if (!Util.intersect(this.rectangle, bbox)) { 52711 this.rectangle = bbox; 52712 } 52713 this._setDefaultAppearance({ 52714 xref, 52715 extra: `${borderWidth} w`, 52716 strokeColor, 52717 strokeAlpha, 52718 fillColor, 52719 fillAlpha: fillColor ? strokeAlpha : null, 52720 pointsCallback: (buffer, points) => { 52721 for (let i = 0, ii = vertices.length; i < ii; i += 2) { 52722 buffer.push(`${vertices[i]} ${vertices[i + 1]} ${i === 0 ? "m" : "l"}`); 52723 } 52724 buffer.push(operator); 52725 return [points[0], points[7], points[2], points[3]]; 52726 } 52727 }); 52728 } 52729 } 52730} 52731class PolygonAnnotation extends PolylineAnnotation { 52732 constructor(params) { 52733 super(params); 52734 this.data.annotationType = AnnotationType.POLYGON; 52735 } 52736} 52737class CaretAnnotation extends MarkupAnnotation { 52738 constructor(params) { 52739 super(params); 52740 this.data.annotationType = AnnotationType.CARET; 52741 } 52742} 52743class InkAnnotation extends MarkupAnnotation { 52744 constructor(params) { 52745 super(params); 52746 this.data.hasOwnCanvas = this.data.noRotate; 52747 this.data.noHTML = false; 52748 const { 52749 dict, 52750 xref 52751 } = params; 52752 this.data.annotationType = AnnotationType.INK; 52753 this.data.inkLists = []; 52754 this.data.isEditable = !this.data.noHTML; 52755 this.data.noHTML = false; 52756 this.data.opacity = dict.get("CA") || 1; 52757 const rawInkLists = dict.getArray("InkList"); 52758 if (!Array.isArray(rawInkLists)) { 52759 return; 52760 } 52761 for (let i = 0, ii = rawInkLists.length; i < ii; ++i) { 52762 if (!Array.isArray(rawInkLists[i])) { 52763 continue; 52764 } 52765 const inkList = new Float32Array(rawInkLists[i].length); 52766 this.data.inkLists.push(inkList); 52767 for (let j = 0, jj = rawInkLists[i].length; j < jj; j += 2) { 52768 const x = xref.fetchIfRef(rawInkLists[i][j]), 52769 y = xref.fetchIfRef(rawInkLists[i][j + 1]); 52770 if (typeof x === "number" && typeof y === "number") { 52771 inkList[j] = x; 52772 inkList[j + 1] = y; 52773 } 52774 } 52775 } 52776 if (!this.appearance) { 52777 const strokeColor = getPdfColorArray(this.color, [0, 0, 0]); 52778 const strokeAlpha = dict.get("CA"); 52779 const borderWidth = this.borderStyle.width || 1, 52780 borderAdjust = 2 * borderWidth; 52781 const bbox = [Infinity, Infinity, -Infinity, -Infinity]; 52782 for (const inkList of this.data.inkLists) { 52783 for (let i = 0, ii = inkList.length; i < ii; i += 2) { 52784 Util.rectBoundingBox(inkList[i] - borderAdjust, inkList[i + 1] - borderAdjust, inkList[i] + borderAdjust, inkList[i + 1] + borderAdjust, bbox); 52785 } 52786 } 52787 if (!Util.intersect(this.rectangle, bbox)) { 52788 this.rectangle = bbox; 52789 } 52790 this._setDefaultAppearance({ 52791 xref, 52792 extra: `${borderWidth} w`, 52793 strokeColor, 52794 strokeAlpha, 52795 pointsCallback: (buffer, points) => { 52796 for (const inkList of this.data.inkLists) { 52797 for (let i = 0, ii = inkList.length; i < ii; i += 2) { 52798 buffer.push(`${inkList[i]} ${inkList[i + 1]} ${i === 0 ? "m" : "l"}`); 52799 } 52800 buffer.push("S"); 52801 } 52802 return [points[0], points[7], points[2], points[3]]; 52803 } 52804 }); 52805 } 52806 } 52807 static createNewDict(annotation, xref, { 52808 apRef, 52809 ap 52810 }) { 52811 const { 52812 oldAnnotation, 52813 color, 52814 date, 52815 opacity, 52816 paths, 52817 outlines, 52818 rect, 52819 rotation, 52820 thickness, 52821 user 52822 } = annotation; 52823 const ink = oldAnnotation || new Dict(xref); 52824 ink.setIfNotExists("Type", Name.get("Annot")); 52825 ink.setIfNotExists("Subtype", Name.get("Ink")); 52826 ink.set(oldAnnotation ? "M" : "CreationDate", `D:${getModificationDate(date)}`); 52827 ink.setIfArray("Rect", rect); 52828 ink.setIfArray("InkList", outlines?.points || paths?.points); 52829 ink.setIfNotExists("F", 4); 52830 ink.setIfNumber("Rotate", rotation); 52831 ink.setIfDefined("T", stringToAsciiOrUTF16BE(user)); 52832 if (outlines) { 52833 ink.setIfName("IT", "InkHighlight"); 52834 } 52835 if (thickness > 0) { 52836 const bs = new Dict(xref); 52837 ink.set("BS", bs); 52838 bs.set("W", thickness); 52839 } 52840 ink.setIfArray("C", getPdfColorArray(color)); 52841 ink.setIfNumber("CA", opacity); 52842 if (ap || apRef) { 52843 const n = new Dict(xref); 52844 ink.set("AP", n); 52845 n.set("N", apRef || ap); 52846 } 52847 return ink; 52848 } 52849 static async createNewAppearanceStream(annotation, xref, params) { 52850 if (annotation.outlines) { 52851 return this.createNewAppearanceStreamForHighlight(annotation, xref, params); 52852 } 52853 const { 52854 color, 52855 rect, 52856 paths, 52857 thickness, 52858 opacity 52859 } = annotation; 52860 if (!color) { 52861 return null; 52862 } 52863 const appearanceBuffer = [`${thickness} w 1 J 1 j`, `${getPdfColor(color, false)}`]; 52864 if (opacity !== 1) { 52865 appearanceBuffer.push("/R0 gs"); 52866 } 52867 for (const outline of paths.lines) { 52868 appearanceBuffer.push(`${numberToString(outline[4])} ${numberToString(outline[5])} m`); 52869 for (let i = 6, ii = outline.length; i < ii; i += 6) { 52870 if (isNaN(outline[i])) { 52871 appearanceBuffer.push(`${numberToString(outline[i + 4])} ${numberToString(outline[i + 5])} l`); 52872 } else { 52873 const [c1x, c1y, c2x, c2y, x, y] = outline.slice(i, i + 6); 52874 appearanceBuffer.push([c1x, c1y, c2x, c2y, x, y].map(numberToString).join(" ") + " c"); 52875 } 52876 } 52877 if (outline.length === 6) { 52878 appearanceBuffer.push(`${numberToString(outline[4])} ${numberToString(outline[5])} l`); 52879 } 52880 } 52881 appearanceBuffer.push("S"); 52882 const appearance = appearanceBuffer.join("\n"); 52883 const appearanceStreamDict = new Dict(xref); 52884 appearanceStreamDict.set("FormType", 1); 52885 appearanceStreamDict.setIfName("Subtype", "Form"); 52886 appearanceStreamDict.setIfName("Type", "XObject"); 52887 appearanceStreamDict.set("BBox", rect); 52888 appearanceStreamDict.set("Length", appearance.length); 52889 if (opacity !== 1) { 52890 const resources = new Dict(xref); 52891 const extGState = new Dict(xref); 52892 const r0 = new Dict(xref); 52893 r0.set("CA", opacity); 52894 r0.setIfName("Type", "ExtGState"); 52895 extGState.set("R0", r0); 52896 resources.set("ExtGState", extGState); 52897 appearanceStreamDict.set("Resources", resources); 52898 } 52899 const ap = new StringStream(appearance); 52900 ap.dict = appearanceStreamDict; 52901 return ap; 52902 } 52903 static async createNewAppearanceStreamForHighlight(annotation, xref, params) { 52904 const { 52905 color, 52906 rect, 52907 outlines: { 52908 outline 52909 }, 52910 opacity 52911 } = annotation; 52912 if (!color) { 52913 return null; 52914 } 52915 const appearanceBuffer = [`${getPdfColor(color, true)}`, "/R0 gs"]; 52916 appearanceBuffer.push(`${numberToString(outline[4])} ${numberToString(outline[5])} m`); 52917 for (let i = 6, ii = outline.length; i < ii; i += 6) { 52918 if (isNaN(outline[i])) { 52919 appearanceBuffer.push(`${numberToString(outline[i + 4])} ${numberToString(outline[i + 5])} l`); 52920 } else { 52921 const [c1x, c1y, c2x, c2y, x, y] = outline.slice(i, i + 6); 52922 appearanceBuffer.push([c1x, c1y, c2x, c2y, x, y].map(numberToString).join(" ") + " c"); 52923 } 52924 } 52925 appearanceBuffer.push("h f"); 52926 const appearance = appearanceBuffer.join("\n"); 52927 const appearanceStreamDict = new Dict(xref); 52928 appearanceStreamDict.set("FormType", 1); 52929 appearanceStreamDict.setIfName("Subtype", "Form"); 52930 appearanceStreamDict.setIfName("Type", "XObject"); 52931 appearanceStreamDict.set("BBox", rect); 52932 appearanceStreamDict.set("Length", appearance.length); 52933 const resources = new Dict(xref); 52934 const extGState = new Dict(xref); 52935 resources.set("ExtGState", extGState); 52936 appearanceStreamDict.set("Resources", resources); 52937 const r0 = new Dict(xref); 52938 extGState.set("R0", r0); 52939 r0.setIfName("BM", "Multiply"); 52940 if (opacity !== 1) { 52941 r0.set("ca", opacity); 52942 r0.setIfName("Type", "ExtGState"); 52943 } 52944 const ap = new StringStream(appearance); 52945 ap.dict = appearanceStreamDict; 52946 return ap; 52947 } 52948} 52949class HighlightAnnotation extends MarkupAnnotation { 52950 constructor(params) { 52951 super(params); 52952 const { 52953 dict, 52954 xref 52955 } = params; 52956 this.data.annotationType = AnnotationType.HIGHLIGHT; 52957 this.data.isEditable = !this.data.noHTML; 52958 this.data.noHTML = false; 52959 this.data.opacity = dict.get("CA") || 1; 52960 const quadPoints = this.data.quadPoints = getQuadPoints(dict, null); 52961 if (quadPoints) { 52962 const resources = this.appearance?.dict.get("Resources"); 52963 if (!this.appearance || !resources?.has("ExtGState")) { 52964 if (this.appearance) { 52965 warn("HighlightAnnotation - ignoring built-in appearance stream."); 52966 } 52967 const fillColor = getPdfColorArray(this.color, [1, 1, 0]); 52968 const fillAlpha = dict.get("CA"); 52969 this._setDefaultAppearance({ 52970 xref, 52971 fillColor, 52972 blendMode: "Multiply", 52973 fillAlpha, 52974 pointsCallback: (buffer, points) => { 52975 buffer.push(`${points[0]} ${points[1]} m`, `${points[2]} ${points[3]} l`, `${points[6]} ${points[7]} l`, `${points[4]} ${points[5]} l`, "f"); 52976 return [points[0], points[7], points[2], points[3]]; 52977 } 52978 }); 52979 } 52980 } else { 52981 this.data.popupRef = null; 52982 } 52983 } 52984 get overlaysTextContent() { 52985 return true; 52986 } 52987 static createNewDict(annotation, xref, { 52988 apRef, 52989 ap 52990 }) { 52991 const { 52992 color, 52993 date, 52994 oldAnnotation, 52995 opacity, 52996 rect, 52997 rotation, 52998 user, 52999 quadPoints 53000 } = annotation; 53001 const highlight = oldAnnotation || new Dict(xref); 53002 highlight.setIfNotExists("Type", Name.get("Annot")); 53003 highlight.setIfNotExists("Subtype", Name.get("Highlight")); 53004 highlight.set(oldAnnotation ? "M" : "CreationDate", `D:${getModificationDate(date)}`); 53005 highlight.setIfArray("Rect", rect); 53006 highlight.setIfNotExists("F", 4); 53007 highlight.setIfNotExists("Border", [0, 0, 0]); 53008 highlight.setIfNumber("Rotate", rotation); 53009 highlight.setIfArray("QuadPoints", quadPoints); 53010 highlight.setIfArray("C", getPdfColorArray(color)); 53011 highlight.setIfNumber("CA", opacity); 53012 highlight.setIfDefined("T", stringToAsciiOrUTF16BE(user)); 53013 if (apRef || ap) { 53014 const n = new Dict(xref); 53015 highlight.set("AP", n); 53016 n.set("N", apRef || ap); 53017 } 53018 return highlight; 53019 } 53020 static async createNewAppearanceStream(annotation, xref, params) { 53021 const { 53022 color, 53023 rect, 53024 outlines, 53025 opacity 53026 } = annotation; 53027 if (!color) { 53028 return null; 53029 } 53030 const appearanceBuffer = [`${getPdfColor(color, true)}`, "/R0 gs"]; 53031 const buffer = []; 53032 for (const outline of outlines) { 53033 buffer.length = 0; 53034 buffer.push(`${numberToString(outline[0])} ${numberToString(outline[1])} m`); 53035 for (let i = 2, ii = outline.length; i < ii; i += 2) { 53036 buffer.push(`${numberToString(outline[i])} ${numberToString(outline[i + 1])} l`); 53037 } 53038 buffer.push("h"); 53039 appearanceBuffer.push(buffer.join("\n")); 53040 } 53041 appearanceBuffer.push("f*"); 53042 const appearance = appearanceBuffer.join("\n"); 53043 const appearanceStreamDict = new Dict(xref); 53044 appearanceStreamDict.set("FormType", 1); 53045 appearanceStreamDict.setIfName("Subtype", "Form"); 53046 appearanceStreamDict.setIfName("Type", "XObject"); 53047 appearanceStreamDict.set("BBox", rect); 53048 appearanceStreamDict.set("Length", appearance.length); 53049 const resources = new Dict(xref); 53050 const extGState = new Dict(xref); 53051 resources.set("ExtGState", extGState); 53052 appearanceStreamDict.set("Resources", resources); 53053 const r0 = new Dict(xref); 53054 extGState.set("R0", r0); 53055 r0.setIfName("BM", "Multiply"); 53056 if (opacity !== 1) { 53057 r0.set("ca", opacity); 53058 r0.setIfName("Type", "ExtGState"); 53059 } 53060 const ap = new StringStream(appearance); 53061 ap.dict = appearanceStreamDict; 53062 return ap; 53063 } 53064} 53065class UnderlineAnnotation extends MarkupAnnotation { 53066 constructor(params) { 53067 super(params); 53068 const { 53069 dict, 53070 xref 53071 } = params; 53072 this.data.annotationType = AnnotationType.UNDERLINE; 53073 const quadPoints = this.data.quadPoints = getQuadPoints(dict, null); 53074 if (quadPoints) { 53075 if (!this.appearance) { 53076 const strokeColor = getPdfColorArray(this.color, [0, 0, 0]); 53077 const strokeAlpha = dict.get("CA"); 53078 this._setDefaultAppearance({ 53079 xref, 53080 extra: "[] 0 d 0.571 w", 53081 strokeColor, 53082 strokeAlpha, 53083 pointsCallback: (buffer, points) => { 53084 buffer.push(`${points[4]} ${points[5] + 1.3} m`, `${points[6]} ${points[7] + 1.3} l`, "S"); 53085 return [points[0], points[7], points[2], points[3]]; 53086 } 53087 }); 53088 } 53089 } else { 53090 this.data.popupRef = null; 53091 } 53092 } 53093 get overlaysTextContent() { 53094 return true; 53095 } 53096} 53097class SquigglyAnnotation extends MarkupAnnotation { 53098 constructor(params) { 53099 super(params); 53100 const { 53101 dict, 53102 xref 53103 } = params; 53104 this.data.annotationType = AnnotationType.SQUIGGLY; 53105 const quadPoints = this.data.quadPoints = getQuadPoints(dict, null); 53106 if (quadPoints) { 53107 if (!this.appearance) { 53108 const strokeColor = getPdfColorArray(this.color, [0, 0, 0]); 53109 const strokeAlpha = dict.get("CA"); 53110 this._setDefaultAppearance({ 53111 xref, 53112 extra: "[] 0 d 1 w", 53113 strokeColor, 53114 strokeAlpha, 53115 pointsCallback: (buffer, points) => { 53116 const dy = (points[1] - points[5]) / 6; 53117 let shift = dy; 53118 let x = points[4]; 53119 const y = points[5]; 53120 const xEnd = points[6]; 53121 buffer.push(`${x} ${y + shift} m`); 53122 do { 53123 x += 2; 53124 shift = shift === 0 ? dy : 0; 53125 buffer.push(`${x} ${y + shift} l`); 53126 } while (x < xEnd); 53127 buffer.push("S"); 53128 return [points[4], y - 2 * dy, xEnd, y + 2 * dy]; 53129 } 53130 }); 53131 } 53132 } else { 53133 this.data.popupRef = null; 53134 } 53135 } 53136 get overlaysTextContent() { 53137 return true; 53138 } 53139} 53140class StrikeOutAnnotation extends MarkupAnnotation { 53141 constructor(params) { 53142 super(params); 53143 const { 53144 dict, 53145 xref 53146 } = params; 53147 this.data.annotationType = AnnotationType.STRIKEOUT; 53148 const quadPoints = this.data.quadPoints = getQuadPoints(dict, null); 53149 if (quadPoints) { 53150 if (!this.appearance) { 53151 const strokeColor = getPdfColorArray(this.color, [0, 0, 0]); 53152 const strokeAlpha = dict.get("CA"); 53153 this._setDefaultAppearance({ 53154 xref, 53155 extra: "[] 0 d 1 w", 53156 strokeColor, 53157 strokeAlpha, 53158 pointsCallback: (buffer, points) => { 53159 buffer.push(`${(points[0] + points[4]) / 2} ` + `${(points[1] + points[5]) / 2} m`, `${(points[2] + points[6]) / 2} ` + `${(points[3] + points[7]) / 2} l`, "S"); 53160 return [points[0], points[7], points[2], points[3]]; 53161 } 53162 }); 53163 } 53164 } else { 53165 this.data.popupRef = null; 53166 } 53167 } 53168 get overlaysTextContent() { 53169 return true; 53170 } 53171} 53172class StampAnnotation extends MarkupAnnotation { 53173 #savedHasOwnCanvas = null; 53174 constructor(params) { 53175 super(params); 53176 this.data.annotationType = AnnotationType.STAMP; 53177 this.data.hasOwnCanvas = this.data.noRotate; 53178 this.data.isEditable = !this.data.noHTML; 53179 this.data.noHTML = false; 53180 } 53181 mustBeViewedWhenEditing(isEditing, modifiedIds = null) { 53182 if (isEditing) { 53183 if (!this.data.isEditable) { 53184 return true; 53185 } 53186 this.#savedHasOwnCanvas ??= this.data.hasOwnCanvas; 53187 this.data.hasOwnCanvas = true; 53188 return true; 53189 } 53190 if (this.#savedHasOwnCanvas !== null) { 53191 this.data.hasOwnCanvas = this.#savedHasOwnCanvas; 53192 this.#savedHasOwnCanvas = null; 53193 } 53194 return !modifiedIds?.has(this.data.id); 53195 } 53196 static async createImage(bitmap, xref) { 53197 const { 53198 width, 53199 height 53200 } = bitmap; 53201 const canvas = new OffscreenCanvas(width, height); 53202 const ctx = canvas.getContext("2d", { 53203 alpha: true 53204 }); 53205 ctx.drawImage(bitmap, 0, 0); 53206 const data = ctx.getImageData(0, 0, width, height).data; 53207 const buf32 = new Uint32Array(data.buffer); 53208 const hasAlpha = buf32.some(FeatureTest.isLittleEndian ? x => x >>> 24 !== 0xff : x => (x & 0xff) !== 0xff); 53209 if (hasAlpha) { 53210 ctx.fillStyle = "white"; 53211 ctx.fillRect(0, 0, width, height); 53212 ctx.drawImage(bitmap, 0, 0); 53213 } 53214 const jpegBufferPromise = canvas.convertToBlob({ 53215 type: "image/jpeg", 53216 quality: 1 53217 }).then(blob => blob.arrayBuffer()); 53218 const xobjectName = Name.get("XObject"); 53219 const imageName = Name.get("Image"); 53220 const image = new Dict(xref); 53221 image.set("Type", xobjectName); 53222 image.set("Subtype", imageName); 53223 image.set("BitsPerComponent", 8); 53224 image.setIfName("ColorSpace", "DeviceRGB"); 53225 image.setIfName("Filter", "DCTDecode"); 53226 image.set("BBox", [0, 0, width, height]); 53227 image.set("Width", width); 53228 image.set("Height", height); 53229 let smaskStream = null; 53230 if (hasAlpha) { 53231 const alphaBuffer = new Uint8Array(buf32.length); 53232 if (FeatureTest.isLittleEndian) { 53233 for (let i = 0, ii = buf32.length; i < ii; i++) { 53234 alphaBuffer[i] = buf32[i] >>> 24; 53235 } 53236 } else { 53237 for (let i = 0, ii = buf32.length; i < ii; i++) { 53238 alphaBuffer[i] = buf32[i] & 0xff; 53239 } 53240 } 53241 const smask = new Dict(xref); 53242 smask.set("Type", xobjectName); 53243 smask.set("Subtype", imageName); 53244 smask.set("BitsPerComponent", 8); 53245 smask.setIfName("ColorSpace", "DeviceGray"); 53246 smask.set("Width", width); 53247 smask.set("Height", height); 53248 smaskStream = new Stream(alphaBuffer, 0, 0, smask); 53249 } 53250 const imageStream = new Stream(await jpegBufferPromise, 0, 0, image); 53251 return { 53252 imageStream, 53253 smaskStream, 53254 width, 53255 height 53256 }; 53257 } 53258 static createNewDict(annotation, xref, { 53259 apRef, 53260 ap 53261 }) { 53262 const { 53263 date, 53264 oldAnnotation, 53265 rect, 53266 rotation, 53267 user 53268 } = annotation; 53269 const stamp = oldAnnotation || new Dict(xref); 53270 stamp.setIfNotExists("Type", Name.get("Annot")); 53271 stamp.setIfNotExists("Subtype", Name.get("Stamp")); 53272 stamp.set(oldAnnotation ? "M" : "CreationDate", `D:${getModificationDate(date)}`); 53273 stamp.setIfArray("Rect", rect); 53274 stamp.setIfNotExists("F", 4); 53275 stamp.setIfNotExists("Border", [0, 0, 0]); 53276 stamp.setIfNumber("Rotate", rotation); 53277 stamp.setIfDefined("T", stringToAsciiOrUTF16BE(user)); 53278 if (apRef || ap) { 53279 const n = new Dict(xref); 53280 stamp.set("AP", n); 53281 n.set("N", apRef || ap); 53282 } 53283 return stamp; 53284 } 53285 static async #createNewAppearanceStreamForDrawing(annotation, xref) { 53286 const { 53287 areContours, 53288 color, 53289 rect, 53290 lines, 53291 thickness 53292 } = annotation; 53293 if (!color) { 53294 return null; 53295 } 53296 const appearanceBuffer = [`${thickness} w 1 J 1 j`, `${getPdfColor(color, areContours)}`]; 53297 for (const line of lines) { 53298 appearanceBuffer.push(`${numberToString(line[4])} ${numberToString(line[5])} m`); 53299 for (let i = 6, ii = line.length; i < ii; i += 6) { 53300 if (isNaN(line[i])) { 53301 appearanceBuffer.push(`${numberToString(line[i + 4])} ${numberToString(line[i + 5])} l`); 53302 } else { 53303 const [c1x, c1y, c2x, c2y, x, y] = line.slice(i, i + 6); 53304 appearanceBuffer.push([c1x, c1y, c2x, c2y, x, y].map(numberToString).join(" ") + " c"); 53305 } 53306 } 53307 if (line.length === 6) { 53308 appearanceBuffer.push(`${numberToString(line[4])} ${numberToString(line[5])} l`); 53309 } 53310 } 53311 appearanceBuffer.push(areContours ? "F" : "S"); 53312 const appearance = appearanceBuffer.join("\n"); 53313 const appearanceStreamDict = new Dict(xref); 53314 appearanceStreamDict.set("FormType", 1); 53315 appearanceStreamDict.setIfName("Subtype", "Form"); 53316 appearanceStreamDict.setIfName("Type", "XObject"); 53317 appearanceStreamDict.set("BBox", rect); 53318 appearanceStreamDict.set("Length", appearance.length); 53319 const ap = new StringStream(appearance); 53320 ap.dict = appearanceStreamDict; 53321 return ap; 53322 } 53323 static async createNewAppearanceStream(annotation, xref, params) { 53324 if (annotation.oldAnnotation) { 53325 return null; 53326 } 53327 if (annotation.isSignature) { 53328 return this.#createNewAppearanceStreamForDrawing(annotation, xref); 53329 } 53330 const { 53331 rotation 53332 } = annotation; 53333 const { 53334 imageRef, 53335 width, 53336 height 53337 } = params.image; 53338 const resources = new Dict(xref); 53339 const xobject = new Dict(xref); 53340 resources.set("XObject", xobject); 53341 xobject.set("Im0", imageRef); 53342 const appearance = `q ${width} 0 0 ${height} 0 0 cm /Im0 Do Q`; 53343 const appearanceStreamDict = new Dict(xref); 53344 appearanceStreamDict.set("FormType", 1); 53345 appearanceStreamDict.setIfName("Subtype", "Form"); 53346 appearanceStreamDict.setIfName("Type", "XObject"); 53347 appearanceStreamDict.set("BBox", [0, 0, width, height]); 53348 appearanceStreamDict.set("Resources", resources); 53349 if (rotation) { 53350 const matrix = getRotationMatrix(rotation, width, height); 53351 appearanceStreamDict.set("Matrix", matrix); 53352 } 53353 const ap = new StringStream(appearance); 53354 ap.dict = appearanceStreamDict; 53355 return ap; 53356 } 53357} 53358class FileAttachmentAnnotation extends MarkupAnnotation { 53359 constructor(params) { 53360 super(params); 53361 const { 53362 dict, 53363 xref 53364 } = params; 53365 const file = new FileSpec(dict.get("FS"), xref); 53366 this.data.annotationType = AnnotationType.FILEATTACHMENT; 53367 this.data.hasOwnCanvas = this.data.noRotate; 53368 this.data.noHTML = false; 53369 this.data.file = file.serializable; 53370 const name = dict.get("Name"); 53371 this.data.name = name instanceof Name ? stringToPDFString(name.name) : "PushPin"; 53372 const fillAlpha = dict.get("ca"); 53373 this.data.fillAlpha = typeof fillAlpha === "number" && fillAlpha >= 0 && fillAlpha <= 1 ? fillAlpha : null; 53374 } 53375} 53376 53377;// ./src/core/calculate_md5.js 53378
vendor: 1,601 bytes, lines 53379-53404
53379const PARAMS = { 53380 get r() { 53381 return shadow(this, "r", new Uint8Array([7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21])); 53382 }, 53383 get k() { 53384 return shadow(this, "k", new Int32Array([-680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426, -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162, 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632, 643717713, -373897302, -701558691, 38016083, -660478335, -405537848, 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784, 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556, -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222, -722521979, 76029189, -640364487, -421815835, 530742520, -995338651, -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606, -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649, -145523070, -1120210379, 718787259, -343485551])); 53385 } 53386}; 53387function calculateMD5(data, offset, length) { 53388 let h0 = 1732584193, 53389 h1 = -271733879, 53390 h2 = -1732584194, 53391 h3 = 271733878; 53392 const paddedLength = length + 72 & ~63; 53393 const padded = new Uint8Array(paddedLength); 53394 let i, j; 53395 for (i = 0; i < length; ++i) { 53396 padded[i] = data[offset++]; 53397 } 53398 padded[i++] = 0x80; 53399 const n = paddedLength - 8; 53400 if (i < n) { 53401 i = n; 53402 } 53403 padded[i++] = length << 3 & 0xff; 53404 padded[i++] = length >> 5 & 0xff;
vendor: 6,672 bytes, lines 53405-53646
53405 padded[i++] = length >> 13 & 0xff; 53406 padded[i++] = length >> 21 & 0xff; 53407 padded[i++] = length >>> 29 & 0xff; 53408 i += 3; 53409 const w = new Int32Array(16); 53410 const { 53411 k, 53412 r 53413 } = PARAMS; 53414 for (i = 0; i < paddedLength;) { 53415 for (j = 0; j < 16; ++j, i += 4) { 53416 w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24; 53417 } 53418 let a = h0, 53419 b = h1, 53420 c = h2, 53421 d = h3, 53422 f, 53423 g; 53424 for (j = 0; j < 64; ++j) { 53425 if (j < 16) { 53426 f = b & c | ~b & d; 53427 g = j; 53428 } else if (j < 32) { 53429 f = d & b | ~d & c; 53430 g = 5 * j + 1 & 15; 53431 } else if (j < 48) { 53432 f = b ^ c ^ d; 53433 g = 3 * j + 5 & 15; 53434 } else { 53435 f = c ^ (b | ~d); 53436 g = 7 * j & 15; 53437 } 53438 const tmp = d, 53439 rotateArg = a + f + k[j] + w[g] | 0, 53440 rotate = r[j]; 53441 d = c; 53442 c = b; 53443 b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0; 53444 a = tmp; 53445 } 53446 h0 = h0 + a | 0; 53447 h1 = h1 + b | 0; 53448 h2 = h2 + c | 0; 53449 h3 = h3 + d | 0; 53450 } 53451 return new Uint8Array([h0 & 0xFF, h0 >> 8 & 0xFF, h0 >> 16 & 0xFF, h0 >>> 24 & 0xFF, h1 & 0xFF, h1 >> 8 & 0xFF, h1 >> 16 & 0xFF, h1 >>> 24 & 0xFF, h2 & 0xFF, h2 >> 8 & 0xFF, h2 >> 16 & 0xFF, h2 >>> 24 & 0xFF, h3 & 0xFF, h3 >> 8 & 0xFF, h3 >> 16 & 0xFF, h3 >>> 24 & 0xFF]); 53452} 53453 53454;// ./src/core/dataset_reader.js 53455 53456 53457 53458function decodeString(str) { 53459 try { 53460 return stringToUTF8String(str); 53461 } catch (ex) { 53462 warn(`UTF-8 decoding failed: "${ex}".`); 53463 return str; 53464 } 53465} 53466class DatasetXMLParser extends SimpleXMLParser { 53467 constructor(options) { 53468 super(options); 53469 this.node = null; 53470 } 53471 onEndElement(name) { 53472 const node = super.onEndElement(name); 53473 if (node && name === "xfa:datasets") { 53474 this.node = node; 53475 throw new Error("Aborting DatasetXMLParser."); 53476 } 53477 } 53478} 53479class DatasetReader { 53480 constructor(data) { 53481 if (data.datasets) { 53482 this.node = new SimpleXMLParser({ 53483 hasAttributes: true 53484 }).parseFromString(data.datasets).documentElement; 53485 } else { 53486 const parser = new DatasetXMLParser({ 53487 hasAttributes: true 53488 }); 53489 try { 53490 parser.parseFromString(data["xdp:xdp"]); 53491 } catch {} 53492 this.node = parser.node; 53493 } 53494 } 53495 getValue(path) { 53496 if (!this.node || !path) { 53497 return ""; 53498 } 53499 const node = this.node.searchNode(parseXFAPath(path), 0); 53500 if (!node) { 53501 return ""; 53502 } 53503 const first = node.firstChild; 53504 if (first?.nodeName === "value") { 53505 return node.children.map(child => decodeString(child.textContent)); 53506 } 53507 return decodeString(node.textContent); 53508 } 53509} 53510 53511;// ./src/core/intersector.js 53512class SingleIntersector { 53513 #annotation; 53514 #minX = Infinity; 53515 #minY = Infinity; 53516 #maxX = -Infinity; 53517 #maxY = -Infinity; 53518 #quadPoints = null; 53519 #text = []; 53520 #extraChars = []; 53521 #lastIntersectingQuadIndex = -1; 53522 #canTakeExtraChars = false; 53523 constructor(annotation) { 53524 this.#annotation = annotation; 53525 const quadPoints = annotation.data.quadPoints; 53526 if (!quadPoints) { 53527 [this.#minX, this.#minY, this.#maxX, this.#maxY] = annotation.data.rect; 53528 return; 53529 } 53530 for (let i = 0, ii = quadPoints.length; i < ii; i += 8) { 53531 this.#minX = Math.min(this.#minX, quadPoints[i]); 53532 this.#maxX = Math.max(this.#maxX, quadPoints[i + 2]); 53533 this.#minY = Math.min(this.#minY, quadPoints[i + 5]); 53534 this.#maxY = Math.max(this.#maxY, quadPoints[i + 1]); 53535 } 53536 if (quadPoints.length > 8) { 53537 this.#quadPoints = quadPoints; 53538 } 53539 } 53540 overlaps(other) { 53541 return !(this.#minX >= other.#maxX || this.#maxX <= other.#minX || this.#minY >= other.#maxY || this.#maxY <= other.#minY); 53542 } 53543 #intersects(x, y) { 53544 if (this.#minX >= x || this.#maxX <= x || this.#minY >= y || this.#maxY <= y) { 53545 return false; 53546 } 53547 const quadPoints = this.#quadPoints; 53548 if (!quadPoints) { 53549 return true; 53550 } 53551 if (this.#lastIntersectingQuadIndex >= 0) { 53552 const i = this.#lastIntersectingQuadIndex; 53553 if (!(quadPoints[i] >= x || quadPoints[i + 2] <= x || quadPoints[i + 5] >= y || quadPoints[i + 1] <= y)) { 53554 return true; 53555 } 53556 this.#lastIntersectingQuadIndex = -1; 53557 } 53558 for (let i = 0, ii = quadPoints.length; i < ii; i += 8) { 53559 if (!(quadPoints[i] >= x || quadPoints[i + 2] <= x || quadPoints[i + 5] >= y || quadPoints[i + 1] <= y)) { 53560 this.#lastIntersectingQuadIndex = i; 53561 return true; 53562 } 53563 } 53564 return false; 53565 } 53566 addGlyph(x, y, glyph) { 53567 if (!this.#intersects(x, y)) { 53568 this.disableExtraChars(); 53569 return false; 53570 } 53571 if (this.#extraChars.length > 0) { 53572 this.#text.push(this.#extraChars.join("")); 53573 this.#extraChars.length = 0; 53574 } 53575 this.#text.push(glyph); 53576 this.#canTakeExtraChars = true; 53577 return true; 53578 } 53579 addExtraChar(char) { 53580 if (this.#canTakeExtraChars) { 53581 this.#extraChars.push(char); 53582 } 53583 } 53584 disableExtraChars() { 53585 if (!this.#canTakeExtraChars) { 53586 return; 53587 } 53588 this.#canTakeExtraChars = false; 53589 this.#extraChars.length = 0; 53590 } 53591 setText() { 53592 this.#annotation.data.overlaidText = this.#text.join(""); 53593 } 53594} 53595class Intersector { 53596 #intersectors = new Map(); 53597 constructor(annotations) { 53598 for (const annotation of annotations) { 53599 if (!annotation.data.quadPoints && !annotation.data.rect) { 53600 continue; 53601 } 53602 const intersector = new SingleIntersector(annotation); 53603 for (const [otherIntersector, overlapping] of this.#intersectors) { 53604 if (otherIntersector.overlaps(intersector)) { 53605 if (!overlapping) { 53606 this.#intersectors.set(otherIntersector, new Set([intersector])); 53607 } else { 53608 overlapping.add(intersector); 53609 } 53610 } 53611 } 53612 this.#intersectors.set(intersector, null); 53613 } 53614 } 53615 addGlyph(transform, width, height, glyph) { 53616 const x = transform[4] + width / 2; 53617 const y = transform[5] + height / 2; 53618 let overlappingIntersectors; 53619 for (const [intersector, overlapping] of this.#intersectors) { 53620 if (overlappingIntersectors) { 53621 if (overlappingIntersectors.has(intersector)) { 53622 intersector.addGlyph(x, y, glyph); 53623 } else { 53624 intersector.disableExtraChars(); 53625 } 53626 continue; 53627 } 53628 if (!intersector.addGlyph(x, y, glyph)) { 53629 continue; 53630 } 53631 overlappingIntersectors = overlapping; 53632 } 53633 } 53634 addExtraChar(char) { 53635 for (const intersector of this.#intersectors.keys()) { 53636 intersector.addExtraChar(char); 53637 } 53638 } 53639 setText() { 53640 for (const intersector of this.#intersectors.keys()) { 53641 intersector.setText(); 53642 } 53643 } 53644} 53645 53646;// ./src/core/calculate_sha_other.js
vendor: 14,028 bytes, lines 53646-54055
53646 53647 53648class Word64 { 53649 constructor(highInteger, lowInteger) { 53650 this.high = highInteger | 0; 53651 this.low = lowInteger | 0; 53652 } 53653 and(word) { 53654 this.high &= word.high; 53655 this.low &= word.low; 53656 } 53657 xor(word) { 53658 this.high ^= word.high; 53659 this.low ^= word.low; 53660 } 53661 shiftRight(places) { 53662 if (places >= 32) { 53663 this.low = this.high >>> places - 32 | 0; 53664 this.high = 0; 53665 } else { 53666 this.low = this.low >>> places | this.high << 32 - places; 53667 this.high = this.high >>> places | 0; 53668 } 53669 } 53670 rotateRight(places) { 53671 let low, high; 53672 if (places & 32) { 53673 high = this.low; 53674 low = this.high; 53675 } else { 53676 low = this.low; 53677 high = this.high; 53678 } 53679 places &= 31; 53680 this.low = low >>> places | high << 32 - places; 53681 this.high = high >>> places | low << 32 - places; 53682 } 53683 not() { 53684 this.high = ~this.high; 53685 this.low = ~this.low; 53686 } 53687 add(word) { 53688 const lowAdd = (this.low >>> 0) + (word.low >>> 0); 53689 let highAdd = (this.high >>> 0) + (word.high >>> 0); 53690 if (lowAdd > 0xffffffff) { 53691 highAdd += 1; 53692 } 53693 this.low = lowAdd | 0; 53694 this.high = highAdd | 0; 53695 } 53696 copyTo(bytes, offset) { 53697 bytes[offset] = this.high >>> 24 & 0xff; 53698 bytes[offset + 1] = this.high >> 16 & 0xff; 53699 bytes[offset + 2] = this.high >> 8 & 0xff; 53700 bytes[offset + 3] = this.high & 0xff; 53701 bytes[offset + 4] = this.low >>> 24 & 0xff; 53702 bytes[offset + 5] = this.low >> 16 & 0xff; 53703 bytes[offset + 6] = this.low >> 8 & 0xff; 53704 bytes[offset + 7] = this.low & 0xff; 53705 } 53706 assign(word) { 53707 this.high = word.high; 53708 this.low = word.low; 53709 } 53710} 53711const calculate_sha_other_PARAMS = { 53712 get k() { 53713 return shadow(this, "k", [new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd), new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc), new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019), new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118), new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe), new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2), new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1), new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694), new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3), new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65), new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483), new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5), new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210), new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4), new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725), new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70), new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926), new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df), new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8), new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b), new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001), new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30), new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910), new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8), new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53), new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8), new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb), new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3), new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60), new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec), new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9), new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b), new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207), new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178), new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6), new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b), new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493), new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c), new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a), new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)]); 53714 } 53715}; 53716function ch(result, x, y, z, tmp) { 53717 result.assign(x); 53718 result.and(y); 53719 tmp.assign(x); 53720 tmp.not(); 53721 tmp.and(z); 53722 result.xor(tmp); 53723} 53724function maj(result, x, y, z, tmp) { 53725 result.assign(x); 53726 result.and(y); 53727 tmp.assign(x); 53728 tmp.and(z); 53729 result.xor(tmp); 53730 tmp.assign(y); 53731 tmp.and(z); 53732 result.xor(tmp); 53733} 53734function sigma(result, x, tmp) { 53735 result.assign(x); 53736 result.rotateRight(28); 53737 tmp.assign(x); 53738 tmp.rotateRight(34); 53739 result.xor(tmp); 53740 tmp.assign(x); 53741 tmp.rotateRight(39); 53742 result.xor(tmp); 53743} 53744function sigmaPrime(result, x, tmp) { 53745 result.assign(x); 53746 result.rotateRight(14); 53747 tmp.assign(x); 53748 tmp.rotateRight(18); 53749 result.xor(tmp); 53750 tmp.assign(x); 53751 tmp.rotateRight(41); 53752 result.xor(tmp); 53753} 53754function littleSigma(result, x, tmp) { 53755 result.assign(x); 53756 result.rotateRight(1); 53757 tmp.assign(x); 53758 tmp.rotateRight(8); 53759 result.xor(tmp); 53760 tmp.assign(x); 53761 tmp.shiftRight(7); 53762 result.xor(tmp); 53763} 53764function littleSigmaPrime(result, x, tmp) { 53765 result.assign(x); 53766 result.rotateRight(19); 53767 tmp.assign(x); 53768 tmp.rotateRight(61); 53769 result.xor(tmp); 53770 tmp.assign(x); 53771 tmp.shiftRight(6); 53772 result.xor(tmp); 53773} 53774function calculateSHA512(data, offset, length, mode384 = false) { 53775 let h0, h1, h2, h3, h4, h5, h6, h7; 53776 if (!mode384) { 53777 h0 = new Word64(0x6a09e667, 0xf3bcc908); 53778 h1 = new Word64(0xbb67ae85, 0x84caa73b); 53779 h2 = new Word64(0x3c6ef372, 0xfe94f82b); 53780 h3 = new Word64(0xa54ff53a, 0x5f1d36f1); 53781 h4 = new Word64(0x510e527f, 0xade682d1); 53782 h5 = new Word64(0x9b05688c, 0x2b3e6c1f); 53783 h6 = new Word64(0x1f83d9ab, 0xfb41bd6b); 53784 h7 = new Word64(0x5be0cd19, 0x137e2179); 53785 } else { 53786 h0 = new Word64(0xcbbb9d5d, 0xc1059ed8); 53787 h1 = new Word64(0x629a292a, 0x367cd507); 53788 h2 = new Word64(0x9159015a, 0x3070dd17); 53789 h3 = new Word64(0x152fecd8, 0xf70e5939); 53790 h4 = new Word64(0x67332667, 0xffc00b31); 53791 h5 = new Word64(0x8eb44a87, 0x68581511); 53792 h6 = new Word64(0xdb0c2e0d, 0x64f98fa7); 53793 h7 = new Word64(0x47b5481d, 0xbefa4fa4); 53794 } 53795 const paddedLength = Math.ceil((length + 17) / 128) * 128; 53796 const padded = new Uint8Array(paddedLength); 53797 let i, j; 53798 for (i = 0; i < length; ++i) { 53799 padded[i] = data[offset++]; 53800 } 53801 padded[i++] = 0x80; 53802 const n = paddedLength - 16; 53803 if (i < n) { 53804 i = n; 53805 } 53806 i += 11; 53807 padded[i++] = length >>> 29 & 0xff; 53808 padded[i++] = length >> 21 & 0xff; 53809 padded[i++] = length >> 13 & 0xff; 53810 padded[i++] = length >> 5 & 0xff; 53811 padded[i++] = length << 3 & 0xff; 53812 const w = new Array(80); 53813 for (i = 0; i < 80; i++) { 53814 w[i] = new Word64(0, 0); 53815 } 53816 const { 53817 k 53818 } = calculate_sha_other_PARAMS; 53819 let a = new Word64(0, 0), 53820 b = new Word64(0, 0), 53821 c = new Word64(0, 0); 53822 let d = new Word64(0, 0), 53823 e = new Word64(0, 0), 53824 f = new Word64(0, 0); 53825 let g = new Word64(0, 0), 53826 h = new Word64(0, 0); 53827 const t1 = new Word64(0, 0), 53828 t2 = new Word64(0, 0); 53829 const tmp1 = new Word64(0, 0), 53830 tmp2 = new Word64(0, 0); 53831 let tmp3; 53832 for (i = 0; i < paddedLength;) { 53833 for (j = 0; j < 16; ++j) { 53834 w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3]; 53835 w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7]; 53836 i += 8; 53837 } 53838 for (j = 16; j < 80; ++j) { 53839 tmp3 = w[j]; 53840 littleSigmaPrime(tmp3, w[j - 2], tmp2); 53841 tmp3.add(w[j - 7]); 53842 littleSigma(tmp1, w[j - 15], tmp2); 53843 tmp3.add(tmp1); 53844 tmp3.add(w[j - 16]); 53845 } 53846 a.assign(h0); 53847 b.assign(h1); 53848 c.assign(h2); 53849 d.assign(h3); 53850 e.assign(h4); 53851 f.assign(h5); 53852 g.assign(h6); 53853 h.assign(h7); 53854 for (j = 0; j < 80; ++j) { 53855 t1.assign(h); 53856 sigmaPrime(tmp1, e, tmp2); 53857 t1.add(tmp1); 53858 ch(tmp1, e, f, g, tmp2); 53859 t1.add(tmp1); 53860 t1.add(k[j]); 53861 t1.add(w[j]); 53862 sigma(t2, a, tmp2); 53863 maj(tmp1, a, b, c, tmp2); 53864 t2.add(tmp1); 53865 tmp3 = h; 53866 h = g; 53867 g = f; 53868 f = e; 53869 d.add(t1); 53870 e = d; 53871 d = c; 53872 c = b; 53873 b = a; 53874 tmp3.assign(t1); 53875 tmp3.add(t2); 53876 a = tmp3; 53877 } 53878 h0.add(a); 53879 h1.add(b); 53880 h2.add(c); 53881 h3.add(d); 53882 h4.add(e); 53883 h5.add(f); 53884 h6.add(g); 53885 h7.add(h); 53886 } 53887 let result; 53888 if (!mode384) { 53889 result = new Uint8Array(64); 53890 h0.copyTo(result, 0); 53891 h1.copyTo(result, 8); 53892 h2.copyTo(result, 16); 53893 h3.copyTo(result, 24); 53894 h4.copyTo(result, 32); 53895 h5.copyTo(result, 40); 53896 h6.copyTo(result, 48); 53897 h7.copyTo(result, 56); 53898 } else { 53899 result = new Uint8Array(48); 53900 h0.copyTo(result, 0); 53901 h1.copyTo(result, 8); 53902 h2.copyTo(result, 16); 53903 h3.copyTo(result, 24); 53904 h4.copyTo(result, 32); 53905 h5.copyTo(result, 40); 53906 } 53907 return result; 53908} 53909function calculateSHA384(data, offset, length) { 53910 return calculateSHA512(data, offset, length, true); 53911} 53912 53913;// ./src/core/calculate_sha256.js 53914 53915const calculate_sha256_PARAMS = { 53916 get k() { 53917 return shadow(this, "k", [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2]); 53918 } 53919}; 53920function rotr(x, n) { 53921 return x >>> n | x << 32 - n; 53922} 53923function calculate_sha256_ch(x, y, z) { 53924 return x & y ^ ~x & z; 53925} 53926function calculate_sha256_maj(x, y, z) { 53927 return x & y ^ x & z ^ y & z; 53928} 53929function calculate_sha256_sigma(x) { 53930 return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22); 53931} 53932function calculate_sha256_sigmaPrime(x) { 53933 return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25); 53934} 53935function calculate_sha256_littleSigma(x) { 53936 return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3; 53937} 53938function calculate_sha256_littleSigmaPrime(x) { 53939 return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10; 53940} 53941function calculateSHA256(data, offset, length) { 53942 let h0 = 0x6a09e667, 53943 h1 = 0xbb67ae85, 53944 h2 = 0x3c6ef372, 53945 h3 = 0xa54ff53a, 53946 h4 = 0x510e527f, 53947 h5 = 0x9b05688c, 53948 h6 = 0x1f83d9ab, 53949 h7 = 0x5be0cd19; 53950 const paddedLength = Math.ceil((length + 9) / 64) * 64; 53951 const padded = new Uint8Array(paddedLength); 53952 let i, j; 53953 for (i = 0; i < length; ++i) { 53954 padded[i] = data[offset++]; 53955 } 53956 padded[i++] = 0x80; 53957 const n = paddedLength - 8; 53958 if (i < n) { 53959 i = n; 53960 } 53961 i += 3; 53962 padded[i++] = length >>> 29 & 0xff; 53963 padded[i++] = length >> 21 & 0xff; 53964 padded[i++] = length >> 13 & 0xff; 53965 padded[i++] = length >> 5 & 0xff; 53966 padded[i++] = length << 3 & 0xff; 53967 const w = new Uint32Array(64); 53968 const { 53969 k 53970 } = calculate_sha256_PARAMS; 53971 for (i = 0; i < paddedLength;) { 53972 for (j = 0; j < 16; ++j) { 53973 w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3]; 53974 i += 4; 53975 } 53976 for (j = 16; j < 64; ++j) { 53977 w[j] = calculate_sha256_littleSigmaPrime(w[j - 2]) + w[j - 7] + calculate_sha256_littleSigma(w[j - 15]) + w[j - 16] | 0; 53978 } 53979 let a = h0, 53980 b = h1, 53981 c = h2, 53982 d = h3, 53983 e = h4, 53984 f = h5, 53985 g = h6, 53986 h = h7, 53987 t1, 53988 t2; 53989 for (j = 0; j < 64; ++j) { 53990 t1 = h + calculate_sha256_sigmaPrime(e) + calculate_sha256_ch(e, f, g) + k[j] + w[j]; 53991 t2 = calculate_sha256_sigma(a) + calculate_sha256_maj(a, b, c); 53992 h = g; 53993 g = f; 53994 f = e; 53995 e = d + t1 | 0; 53996 d = c; 53997 c = b; 53998 b = a; 53999 a = t1 + t2 | 0; 54000 } 54001 h0 = h0 + a | 0; 54002 h1 = h1 + b | 0; 54003 h2 = h2 + c | 0; 54004 h3 = h3 + d | 0; 54005 h4 = h4 + e | 0; 54006 h5 = h5 + f | 0; 54007 h6 = h6 + g | 0; 54008 h7 = h7 + h | 0; 54009 } 54010 return new Uint8Array([h0 >> 24 & 0xFF, h0 >> 16 & 0xFF, h0 >> 8 & 0xFF, h0 & 0xFF, h1 >> 24 & 0xFF, h1 >> 16 & 0xFF, h1 >> 8 & 0xFF, h1 & 0xFF, h2 >> 24 & 0xFF, h2 >> 16 & 0xFF, h2 >> 8 & 0xFF, h2 & 0xFF, h3 >> 24 & 0xFF, h3 >> 16 & 0xFF, h3 >> 8 & 0xFF, h3 & 0xFF, h4 >> 24 & 0xFF, h4 >> 16 & 0xFF, h4 >> 8 & 0xFF, h4 & 0xFF, h5 >> 24 & 0xFF, h5 >> 16 & 0xFF, h5 >> 8 & 0xFF, h5 & 0xFF, h6 >> 24 & 0xFF, h6 >> 16 & 0xFF, h6 >> 8 & 0xFF, h6 & 0xFF, h7 >> 24 & 0xFF, h7 >> 16 & 0xFF, h7 >> 8 & 0xFF, h7 & 0xFF]); 54011} 54012 54013;// ./src/core/decrypt_stream.js 54014 54015const chunkSize = 512; 54016class DecryptStream extends DecodeStream { 54017 constructor(str, maybeLength, decrypt) { 54018 super(maybeLength); 54019 this.str = str; 54020 this.dict = str.dict; 54021 this.decrypt = decrypt; 54022 this.nextChunk = null; 54023 this.initialized = false; 54024 } 54025 readBlock() { 54026 let chunk; 54027 if (this.initialized) { 54028 chunk = this.nextChunk; 54029 } else { 54030 chunk = this.str.getBytes(chunkSize); 54031 this.initialized = true; 54032 } 54033 if (!chunk?.length) { 54034 this.eof = true; 54035 return; 54036 } 54037 this.nextChunk = this.str.getBytes(chunkSize); 54038 const hasMoreData = this.nextChunk?.length > 0; 54039 const decrypt = this.decrypt; 54040 chunk = decrypt(chunk, !hasMoreData); 54041 const bufferLength = this.bufferLength, 54042 newLength = bufferLength + chunk.length, 54043 buffer = this.ensureBuffer(newLength); 54044 buffer.set(chunk, bufferLength); 54045 this.bufferLength = newLength; 54046 } 54047} 54048 54049;// ./src/core/crypto.js 54050 54051 54052 54053 54054 54055
54056class ARCFourCipher { 54057 constructor(key) { 54058 this.a = 0; 54059 this.b = 0;
vendor: 5,126 bytes, lines 54059-54110
54059 54060 const s = new Uint8Array(256); 54061 const keyLength = key.length; 54062 for (let i = 0; i < 256; ++i) { 54063 s[i] = i; 54064 } 54065 for (let i = 0, j = 0; i < 256; ++i) { 54066 const tmp = s[i]; 54067 j = j + tmp + key[i % keyLength] & 0xff; 54068 s[i] = s[j]; 54069 s[j] = tmp; 54070 } 54071 this.s = s; 54072 } 54073 encryptBlock(data) { 54074 let a = this.a, 54075 b = this.b; 54076 const s = this.s; 54077 const n = data.length; 54078 const output = new Uint8Array(n); 54079 for (let i = 0; i < n; ++i) { 54080 a = a + 1 & 0xff; 54081 const tmp = s[a]; 54082 b = b + tmp & 0xff; 54083 const tmp2 = s[b]; 54084 s[a] = tmp2; 54085 s[b] = tmp; 54086 output[i] = data[i] ^ s[tmp + tmp2 & 0xff]; 54087 } 54088 this.a = a; 54089 this.b = b; 54090 return output; 54091 } 54092 decryptBlock(data) { 54093 return this.encryptBlock(data); 54094 } 54095 encrypt(data) { 54096 return this.encryptBlock(data); 54097 } 54098} 54099class NullCipher { 54100 decryptBlock(data) { 54101 return data; 54102 } 54103 encrypt(data) { 54104 return data; 54105 } 54106} 54107class AESBaseCipher { 54108 _s = new Uint8Array([0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16]); 54109 _inv_s = new Uint8Array([0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d]); 54110 _mix = new Uint32Array([0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927, 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45, 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb, 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381, 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf, 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66, 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28, 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012, 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec, 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e, 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd, 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7, 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89, 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a
vendor: 4,150 bytes, lines 54110-54186
54110750, 0x5ffdaa5b, 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815, 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f, 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa, 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8, 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36, 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c, 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742, 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea, 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4, 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e, 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360, 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502, 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87, 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd, 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3, 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621, 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f, 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55, 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26, 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844, 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba, 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480, 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce, 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67, 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929, 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713, 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed, 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f, 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]); 54111 _mixCol = new Uint8Array(256).map((_, i) => i < 128 ? i << 1 : i << 1 ^ 0x1b); 54112 constructor() { 54113 this.buffer = new Uint8Array(16); 54114 this.bufferPosition = 0; 54115 } 54116 _expandKey(cipherKey) { 54117 unreachable("Cannot call `_expandKey` on the base class"); 54118 } 54119 _decrypt(input, key) { 54120 let t, u, v; 54121 const state = new Uint8Array(16); 54122 state.set(input); 54123 for (let j = 0, k = this._keySize; j < 16; ++j, ++k) { 54124 state[j] ^= key[k]; 54125 } 54126 for (let i = this._cyclesOfRepetition - 1; i >= 1; --i) { 54127 t = state[13]; 54128 state[13] = state[9]; 54129 state[9] = state[5]; 54130 state[5] = state[1]; 54131 state[1] = t; 54132 t = state[14]; 54133 u = state[10]; 54134 state[14] = state[6]; 54135 state[10] = state[2]; 54136 state[6] = t; 54137 state[2] = u; 54138 t = state[15]; 54139 u = state[11]; 54140 v = state[7]; 54141 state[15] = state[3]; 54142 state[11] = t; 54143 state[7] = u; 54144 state[3] = v; 54145 for (let j = 0; j < 16; ++j) { 54146 state[j] = this._inv_s[state[j]]; 54147 } 54148 for (let j = 0, k = i * 16; j < 16; ++j, ++k) { 54149 state[j] ^= key[k]; 54150 } 54151 for (let j = 0; j < 16; j += 4) { 54152 const s0 = this._mix[state[j]]; 54153 const s1 = this._mix[state[j + 1]]; 54154 const s2 = this._mix[state[j + 2]]; 54155 const s3 = this._mix[state[j + 3]]; 54156 t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8; 54157 state[j] = t >>> 24 & 0xff; 54158 state[j + 1] = t >> 16 & 0xff; 54159 state[j + 2] = t >> 8 & 0xff; 54160 state[j + 3] = t & 0xff; 54161 } 54162 } 54163 t = state[13]; 54164 state[13] = state[9]; 54165 state[9] = state[5]; 54166 state[5] = state[1]; 54167 state[1] = t; 54168 t = state[14]; 54169 u = state[10]; 54170 state[14] = state[6]; 54171 state[10] = state[2]; 54172 state[6] = t; 54173 state[2] = u; 54174 t = state[15]; 54175 u = state[11]; 54176 v = state[7]; 54177 state[15] = state[3]; 54178 state[11] = t; 54179 state[7] = u; 54180 state[3] = v; 54181 for (let j = 0; j < 16; ++j) { 54182 state[j] = this._inv_s[state[j]]; 54183 state[j] ^= key[j]; 54184 } 54185 return state; 54186 }
vendor: 8,061 bytes, lines 54187-54432
54187 _encrypt(input, key) { 54188 const s = this._s; 54189 let t, u, v; 54190 const state = new Uint8Array(16); 54191 state.set(input); 54192 for (let j = 0; j < 16; ++j) { 54193 state[j] ^= key[j]; 54194 } 54195 for (let i = 1; i < this._cyclesOfRepetition; i++) { 54196 for (let j = 0; j < 16; ++j) { 54197 state[j] = s[state[j]]; 54198 } 54199 v = state[1]; 54200 state[1] = state[5]; 54201 state[5] = state[9]; 54202 state[9] = state[13]; 54203 state[13] = v; 54204 v = state[2]; 54205 u = state[6]; 54206 state[2] = state[10]; 54207 state[6] = state[14]; 54208 state[10] = v; 54209 state[14] = u; 54210 v = state[3]; 54211 u = state[7]; 54212 t = state[11]; 54213 state[3] = state[15]; 54214 state[7] = v; 54215 state[11] = u; 54216 state[15] = t; 54217 for (let j = 0; j < 16; j += 4) { 54218 const s0 = state[j]; 54219 const s1 = state[j + 1]; 54220 const s2 = state[j + 2]; 54221 const s3 = state[j + 3]; 54222 t = s0 ^ s1 ^ s2 ^ s3; 54223 state[j] ^= t ^ this._mixCol[s0 ^ s1]; 54224 state[j + 1] ^= t ^ this._mixCol[s1 ^ s2]; 54225 state[j + 2] ^= t ^ this._mixCol[s2 ^ s3]; 54226 state[j + 3] ^= t ^ this._mixCol[s3 ^ s0]; 54227 } 54228 for (let j = 0, k = i * 16; j < 16; ++j, ++k) { 54229 state[j] ^= key[k]; 54230 } 54231 } 54232 for (let j = 0; j < 16; ++j) { 54233 state[j] = s[state[j]]; 54234 } 54235 v = state[1]; 54236 state[1] = state[5]; 54237 state[5] = state[9]; 54238 state[9] = state[13]; 54239 state[13] = v; 54240 v = state[2]; 54241 u = state[6]; 54242 state[2] = state[10]; 54243 state[6] = state[14]; 54244 state[10] = v; 54245 state[14] = u; 54246 v = state[3]; 54247 u = state[7]; 54248 t = state[11]; 54249 state[3] = state[15]; 54250 state[7] = v; 54251 state[11] = u; 54252 state[15] = t; 54253 for (let j = 0, k = this._keySize; j < 16; ++j, ++k) { 54254 state[j] ^= key[k]; 54255 } 54256 return state; 54257 } 54258 _decryptBlock2(data, finalize) { 54259 const sourceLength = data.length; 54260 let buffer = this.buffer, 54261 bufferLength = this.bufferPosition; 54262 const result = []; 54263 let iv = this.iv; 54264 for (let i = 0; i < sourceLength; ++i) { 54265 buffer[bufferLength] = data[i]; 54266 ++bufferLength; 54267 if (bufferLength < 16) { 54268 continue; 54269 } 54270 const plain = this._decrypt(buffer, this._key); 54271 for (let j = 0; j < 16; ++j) { 54272 plain[j] ^= iv[j]; 54273 } 54274 iv = buffer; 54275 result.push(plain); 54276 buffer = new Uint8Array(16); 54277 bufferLength = 0; 54278 } 54279 this.buffer = buffer; 54280 this.bufferLength = bufferLength; 54281 this.iv = iv; 54282 if (result.length === 0) { 54283 return new Uint8Array(0); 54284 } 54285 let outputLength = 16 * result.length; 54286 if (finalize) { 54287 const lastBlock = result.at(-1); 54288 let psLen = lastBlock[15]; 54289 if (psLen <= 16) { 54290 for (let i = 15, ii = 16 - psLen; i >= ii; --i) { 54291 if (lastBlock[i] !== psLen) { 54292 psLen = 0; 54293 break; 54294 } 54295 } 54296 outputLength -= psLen; 54297 result[result.length - 1] = lastBlock.subarray(0, 16 - psLen); 54298 } 54299 } 54300 const output = new Uint8Array(outputLength); 54301 for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) { 54302 output.set(result[i], j); 54303 } 54304 return output; 54305 } 54306 decryptBlock(data, finalize, iv = null) { 54307 const sourceLength = data.length; 54308 const buffer = this.buffer; 54309 let bufferLength = this.bufferPosition; 54310 if (iv) { 54311 this.iv = iv; 54312 } else { 54313 for (let i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) { 54314 buffer[bufferLength] = data[i]; 54315 } 54316 if (bufferLength < 16) { 54317 this.bufferLength = bufferLength; 54318 return new Uint8Array(0); 54319 } 54320 this.iv = buffer; 54321 data = data.subarray(16); 54322 } 54323 this.buffer = new Uint8Array(16); 54324 this.bufferLength = 0; 54325 this.decryptBlock = this._decryptBlock2; 54326 return this.decryptBlock(data, finalize); 54327 } 54328 encrypt(data, iv) { 54329 const sourceLength = data.length; 54330 let buffer = this.buffer, 54331 bufferLength = this.bufferPosition; 54332 const result = []; 54333 iv ||= new Uint8Array(16); 54334 for (let i = 0; i < sourceLength; ++i) { 54335 buffer[bufferLength] = data[i]; 54336 ++bufferLength; 54337 if (bufferLength < 16) { 54338 continue; 54339 } 54340 for (let j = 0; j < 16; ++j) { 54341 buffer[j] ^= iv[j]; 54342 } 54343 const cipher = this._encrypt(buffer, this._key); 54344 iv = cipher; 54345 result.push(cipher); 54346 buffer = new Uint8Array(16); 54347 bufferLength = 0; 54348 } 54349 this.buffer = buffer; 54350 this.bufferLength = bufferLength; 54351 this.iv = iv; 54352 if (result.length === 0) { 54353 return new Uint8Array(0); 54354 } 54355 const outputLength = 16 * result.length; 54356 const output = new Uint8Array(outputLength); 54357 for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) { 54358 output.set(result[i], j); 54359 } 54360 return output; 54361 } 54362} 54363class AES128Cipher extends AESBaseCipher { 54364 _rcon = new Uint8Array([0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d]); 54365 constructor(key) { 54366 super(); 54367 this._cyclesOfRepetition = 10; 54368 this._keySize = 160; 54369 this._key = this._expandKey(key); 54370 } 54371 _expandKey(cipherKey) { 54372 const b = 176; 54373 const s = this._s; 54374 const rcon = this._rcon; 54375 const result = new Uint8Array(b); 54376 result.set(cipherKey); 54377 for (let j = 16, i = 1; j < b; ++i) { 54378 let t1 = result[j - 3]; 54379 let t2 = result[j - 2]; 54380 let t3 = result[j - 1]; 54381 let t4 = result[j - 4]; 54382 t1 = s[t1]; 54383 t2 = s[t2]; 54384 t3 = s[t3]; 54385 t4 = s[t4]; 54386 t1 ^= rcon[i]; 54387 for (let n = 0; n < 4; ++n) { 54388 result[j] = t1 ^= result[j - 16]; 54389 j++; 54390 result[j] = t2 ^= result[j - 16]; 54391 j++; 54392 result[j] = t3 ^= result[j - 16]; 54393 j++; 54394 result[j] = t4 ^= result[j - 16]; 54395 j++; 54396 } 54397 } 54398 return result; 54399 } 54400} 54401class AES256Cipher extends AESBaseCipher { 54402 constructor(key) { 54403 super(); 54404 this._cyclesOfRepetition = 14; 54405 this._keySize = 224; 54406 this._key = this._expandKey(key); 54407 } 54408 _expandKey(cipherKey) { 54409 const b = 240; 54410 const s = this._s; 54411 const result = new Uint8Array(b); 54412 result.set(cipherKey); 54413 let r = 1; 54414 let t1, t2, t3, t4; 54415 for (let j = 32, i = 1; j < b; ++i) { 54416 if (j % 32 === 16) { 54417 t1 = s[t1]; 54418 t2 = s[t2]; 54419 t3 = s[t3]; 54420 t4 = s[t4]; 54421 } else if (j % 32 === 0) { 54422 t1 = result[j - 3]; 54423 t2 = result[j - 2]; 54424 t3 = result[j - 1]; 54425 t4 = result[j - 4]; 54426 t1 = s[t1]; 54427 t2 = s[t2]; 54428 t3 = s[t3]; 54429 t4 = s[t4]; 54430 t1 ^= r; 54431 if ((r <<= 1) >= 256) { 54432 r = (r ^ 0x1b) & 0xff;
vendor: 69,803 bytes, lines 54433-56551
54433 } 54434 } 54435 for (let n = 0; n < 4; ++n) { 54436 result[j] = t1 ^= result[j - 32]; 54437 j++; 54438 result[j] = t2 ^= result[j - 32]; 54439 j++; 54440 result[j] = t3 ^= result[j - 32]; 54441 j++; 54442 result[j] = t4 ^= result[j - 32]; 54443 j++; 54444 } 54445 } 54446 return result; 54447 } 54448} 54449class PDFBase { 54450 _hash(password, input, userBytes) { 54451 unreachable("Abstract method `_hash` called"); 54452 } 54453 checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) { 54454 const hashData = new Uint8Array(password.length + 56); 54455 hashData.set(password, 0); 54456 hashData.set(ownerValidationSalt, password.length); 54457 hashData.set(userBytes, password.length + ownerValidationSalt.length); 54458 const result = this._hash(password, hashData, userBytes); 54459 return isArrayEqual(result, ownerPassword); 54460 } 54461 checkUserPassword(password, userValidationSalt, userPassword) { 54462 const hashData = new Uint8Array(password.length + 8); 54463 hashData.set(password, 0); 54464 hashData.set(userValidationSalt, password.length); 54465 const result = this._hash(password, hashData, []); 54466 return isArrayEqual(result, userPassword); 54467 } 54468 getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) { 54469 const hashData = new Uint8Array(password.length + 56); 54470 hashData.set(password, 0); 54471 hashData.set(ownerKeySalt, password.length); 54472 hashData.set(userBytes, password.length + ownerKeySalt.length); 54473 const key = this._hash(password, hashData, userBytes); 54474 const cipher = new AES256Cipher(key); 54475 return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16)); 54476 } 54477 getUserKey(password, userKeySalt, userEncryption) { 54478 const hashData = new Uint8Array(password.length + 8); 54479 hashData.set(password, 0); 54480 hashData.set(userKeySalt, password.length); 54481 const key = this._hash(password, hashData, []); 54482 const cipher = new AES256Cipher(key); 54483 return cipher.decryptBlock(userEncryption, false, new Uint8Array(16)); 54484 } 54485} 54486class PDF17 extends PDFBase { 54487 _hash(password, input, userBytes) { 54488 return calculateSHA256(input, 0, input.length); 54489 } 54490} 54491class PDF20 extends PDFBase { 54492 _hash(password, input, userBytes) { 54493 let k = calculateSHA256(input, 0, input.length).subarray(0, 32); 54494 let e = [0]; 54495 let i = 0; 54496 while (i < 64 || e.at(-1) > i - 32) { 54497 const combinedLength = password.length + k.length + userBytes.length, 54498 combinedArray = new Uint8Array(combinedLength); 54499 let writeOffset = 0; 54500 combinedArray.set(password, writeOffset); 54501 writeOffset += password.length; 54502 combinedArray.set(k, writeOffset); 54503 writeOffset += k.length; 54504 combinedArray.set(userBytes, writeOffset); 54505 const k1 = new Uint8Array(combinedLength * 64); 54506 for (let j = 0, pos = 0; j < 64; j++, pos += combinedLength) { 54507 k1.set(combinedArray, pos); 54508 } 54509 const cipher = new AES128Cipher(k.subarray(0, 16)); 54510 e = cipher.encrypt(k1, k.subarray(16, 32)); 54511 const remainder = Math.sumPrecise(e.slice(0, 16)) % 3; 54512 if (remainder === 0) { 54513 k = calculateSHA256(e, 0, e.length); 54514 } else if (remainder === 1) { 54515 k = calculateSHA384(e, 0, e.length); 54516 } else if (remainder === 2) { 54517 k = calculateSHA512(e, 0, e.length); 54518 } 54519 i++; 54520 } 54521 return k.subarray(0, 32); 54522 } 54523} 54524class CipherTransform { 54525 constructor(stringCipherConstructor, streamCipherConstructor) { 54526 this.StringCipherConstructor = stringCipherConstructor; 54527 this.StreamCipherConstructor = streamCipherConstructor; 54528 } 54529 createStream(stream, length) { 54530 const cipher = new this.StreamCipherConstructor(); 54531 return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) { 54532 return cipher.decryptBlock(data, finalize); 54533 }); 54534 } 54535 decryptString(s) { 54536 const cipher = new this.StringCipherConstructor(); 54537 let data = stringToBytes(s); 54538 data = cipher.decryptBlock(data, true); 54539 return bytesToString(data); 54540 } 54541 encryptString(s) { 54542 const cipher = new this.StringCipherConstructor(); 54543 if (cipher instanceof AESBaseCipher) { 54544 const strLen = s.length; 54545 const pad = 16 - strLen % 16; 54546 s += String.fromCharCode(pad).repeat(pad); 54547 const iv = new Uint8Array(16); 54548 crypto.getRandomValues(iv); 54549 let data = stringToBytes(s); 54550 data = cipher.encrypt(data, iv); 54551 const buf = new Uint8Array(16 + data.length); 54552 buf.set(iv); 54553 buf.set(data, 16); 54554 return bytesToString(buf); 54555 } 54556 let data = stringToBytes(s); 54557 data = cipher.encrypt(data); 54558 return bytesToString(data); 54559 } 54560} 54561class CipherTransformFactory { 54562 static get _defaultPasswordBytes() { 54563 return shadow(this, "_defaultPasswordBytes", new Uint8Array([0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a])); 54564 } 54565 #createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) { 54566 if (password) { 54567 const passwordLength = Math.min(127, password.length); 54568 password = password.subarray(0, passwordLength); 54569 } else { 54570 password = []; 54571 } 54572 const pdfAlgorithm = revision === 6 ? new PDF20() : new PDF17(); 54573 if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) { 54574 return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption); 54575 } else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) { 54576 return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption); 54577 } 54578 return null; 54579 } 54580 #prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) { 54581 const hashDataSize = 40 + ownerPassword.length + fileId.length; 54582 const hashData = new Uint8Array(hashDataSize); 54583 let i = 0, 54584 j, 54585 n; 54586 if (password) { 54587 n = Math.min(32, password.length); 54588 for (; i < n; ++i) { 54589 hashData[i] = password[i]; 54590 } 54591 } 54592 j = 0; 54593 while (i < 32) { 54594 hashData[i++] = CipherTransformFactory._defaultPasswordBytes[j++]; 54595 } 54596 hashData.set(ownerPassword, i); 54597 i += ownerPassword.length; 54598 hashData[i++] = flags & 0xff; 54599 hashData[i++] = flags >> 8 & 0xff; 54600 hashData[i++] = flags >> 16 & 0xff; 54601 hashData[i++] = flags >>> 24 & 0xff; 54602 hashData.set(fileId, i); 54603 i += fileId.length; 54604 if (revision >= 4 && !encryptMetadata) { 54605 hashData.fill(0xff, i, i + 4); 54606 i += 4; 54607 } 54608 let hash = calculateMD5(hashData, 0, i); 54609 const keyLengthInBytes = keyLength >> 3; 54610 if (revision >= 3) { 54611 for (j = 0; j < 50; ++j) { 54612 hash = calculateMD5(hash, 0, keyLengthInBytes); 54613 } 54614 } 54615 const encryptionKey = hash.subarray(0, keyLengthInBytes); 54616 let cipher, checkData; 54617 if (revision >= 3) { 54618 i = 0; 54619 hashData.set(CipherTransformFactory._defaultPasswordBytes, i); 54620 i += 32; 54621 hashData.set(fileId, i); 54622 i += fileId.length; 54623 cipher = new ARCFourCipher(encryptionKey); 54624 checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i)); 54625 n = encryptionKey.length; 54626 const derivedKey = new Uint8Array(n); 54627 for (j = 1; j <= 19; ++j) { 54628 for (let k = 0; k < n; ++k) { 54629 derivedKey[k] = encryptionKey[k] ^ j; 54630 } 54631 cipher = new ARCFourCipher(derivedKey); 54632 checkData = cipher.encryptBlock(checkData); 54633 } 54634 } else { 54635 cipher = new ARCFourCipher(encryptionKey); 54636 checkData = cipher.encryptBlock(CipherTransformFactory._defaultPasswordBytes); 54637 } 54638 return checkData.every((data, k) => userPassword[k] === data) ? encryptionKey : null; 54639 } 54640 #decodeUserPassword(password, ownerPassword, revision, keyLength) { 54641 const hashData = new Uint8Array(32); 54642 let i = 0; 54643 const n = Math.min(32, password.length); 54644 for (; i < n; ++i) { 54645 hashData[i] = password[i]; 54646 } 54647 let j = 0; 54648 while (i < 32) { 54649 hashData[i++] = CipherTransformFactory._defaultPasswordBytes[j++]; 54650 } 54651 let hash = calculateMD5(hashData, 0, i); 54652 const keyLengthInBytes = keyLength >> 3; 54653 if (revision >= 3) { 54654 for (j = 0; j < 50; ++j) { 54655 hash = calculateMD5(hash, 0, hash.length); 54656 } 54657 } 54658 let cipher, userPassword; 54659 if (revision >= 3) { 54660 userPassword = ownerPassword; 54661 const derivedKey = new Uint8Array(keyLengthInBytes); 54662 for (j = 19; j >= 0; j--) { 54663 for (let k = 0; k < keyLengthInBytes; ++k) { 54664 derivedKey[k] = hash[k] ^ j; 54665 } 54666 cipher = new ARCFourCipher(derivedKey); 54667 userPassword = cipher.encryptBlock(userPassword); 54668 } 54669 } else { 54670 cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes)); 54671 userPassword = cipher.encryptBlock(ownerPassword); 54672 } 54673 return userPassword; 54674 } 54675 #buildObjectKey(num, gen, encryptionKey, isAes = false) { 54676 const n = encryptionKey.length; 54677 const key = new Uint8Array(n + 9); 54678 key.set(encryptionKey); 54679 let i = n; 54680 key[i++] = num & 0xff; 54681 key[i++] = num >> 8 & 0xff; 54682 key[i++] = num >> 16 & 0xff; 54683 key[i++] = gen & 0xff; 54684 key[i++] = gen >> 8 & 0xff; 54685 if (isAes) { 54686 key[i++] = 0x73; 54687 key[i++] = 0x41; 54688 key[i++] = 0x6c; 54689 key[i++] = 0x54; 54690 } 54691 const hash = calculateMD5(key, 0, i); 54692 return hash.subarray(0, Math.min(n + 5, 16)); 54693 } 54694 #buildCipherConstructor(cf, name, num, gen, key) { 54695 if (!(name instanceof Name)) { 54696 throw new FormatError("Invalid crypt filter name."); 54697 } 54698 const self = this; 54699 const cryptFilter = cf.get(name.name); 54700 const cfm = cryptFilter?.get("CFM"); 54701 if (!cfm || cfm.name === "None") { 54702 return function () { 54703 return new NullCipher(); 54704 }; 54705 } 54706 if (cfm.name === "V2") { 54707 return function () { 54708 return new ARCFourCipher(self.#buildObjectKey(num, gen, key, false)); 54709 }; 54710 } 54711 if (cfm.name === "AESV2") { 54712 return function () { 54713 return new AES128Cipher(self.#buildObjectKey(num, gen, key, true)); 54714 }; 54715 } 54716 if (cfm.name === "AESV3") { 54717 return function () { 54718 return new AES256Cipher(key); 54719 }; 54720 } 54721 throw new FormatError("Unknown crypto method"); 54722 } 54723 constructor(dict, fileId, password) { 54724 const filter = dict.get("Filter"); 54725 if (!isName(filter, "Standard")) { 54726 throw new FormatError("unknown encryption method"); 54727 } 54728 this.filterName = filter.name; 54729 this.dict = dict; 54730 const algorithm = dict.get("V"); 54731 if (!Number.isInteger(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) { 54732 throw new FormatError("unsupported encryption algorithm"); 54733 } 54734 this.algorithm = algorithm; 54735 let keyLength = dict.get("Length"); 54736 if (!keyLength) { 54737 if (algorithm <= 3) { 54738 keyLength = 40; 54739 } else { 54740 const cfDict = dict.get("CF"); 54741 const streamCryptoName = dict.get("StmF"); 54742 if (cfDict instanceof Dict && streamCryptoName instanceof Name) { 54743 cfDict.suppressEncryption = true; 54744 const handlerDict = cfDict.get(streamCryptoName.name); 54745 keyLength = handlerDict?.get("Length") || 128; 54746 if (keyLength < 40) { 54747 keyLength <<= 3; 54748 } 54749 } 54750 } 54751 } 54752 if (!Number.isInteger(keyLength) || keyLength < 40 || keyLength % 8 !== 0) { 54753 throw new FormatError("invalid key length"); 54754 } 54755 const ownerBytes = stringToBytes(dict.get("O")), 54756 userBytes = stringToBytes(dict.get("U")); 54757 const ownerPassword = ownerBytes.subarray(0, 32); 54758 const userPassword = userBytes.subarray(0, 32); 54759 const flags = dict.get("P"); 54760 const revision = dict.get("R"); 54761 const encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get("EncryptMetadata") !== false; 54762 this.encryptMetadata = encryptMetadata; 54763 const fileIdBytes = stringToBytes(fileId); 54764 let passwordBytes; 54765 if (password) { 54766 if (revision === 6) { 54767 try { 54768 password = utf8StringToString(password); 54769 } catch { 54770 warn("CipherTransformFactory: Unable to convert UTF8 encoded password."); 54771 } 54772 } 54773 passwordBytes = stringToBytes(password); 54774 } 54775 let encryptionKey; 54776 if (algorithm !== 5) { 54777 encryptionKey = this.#prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata); 54778 } else { 54779 const ownerValidationSalt = ownerBytes.subarray(32, 40); 54780 const ownerKeySalt = ownerBytes.subarray(40, 48); 54781 const uBytes = userBytes.subarray(0, 48); 54782 const userValidationSalt = userBytes.subarray(32, 40); 54783 const userKeySalt = userBytes.subarray(40, 48); 54784 const ownerEncryption = stringToBytes(dict.get("OE")); 54785 const userEncryption = stringToBytes(dict.get("UE")); 54786 const perms = stringToBytes(dict.get("Perms")); 54787 encryptionKey = this.#createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms); 54788 } 54789 if (!encryptionKey) { 54790 if (!password) { 54791 throw new PasswordException("No password given", PasswordResponses.NEED_PASSWORD); 54792 } 54793 const decodedPassword = this.#decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength); 54794 encryptionKey = this.#prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata); 54795 } 54796 if (!encryptionKey) { 54797 throw new PasswordException("Incorrect Password", PasswordResponses.INCORRECT_PASSWORD); 54798 } 54799 if (algorithm === 4 && encryptionKey.length < 16) { 54800 this.encryptionKey = new Uint8Array(16); 54801 this.encryptionKey.set(encryptionKey); 54802 } else { 54803 this.encryptionKey = encryptionKey; 54804 } 54805 if (algorithm >= 4) { 54806 const cf = dict.get("CF"); 54807 if (cf instanceof Dict) { 54808 cf.suppressEncryption = true; 54809 } 54810 this.cf = cf; 54811 this.stmf = dict.get("StmF") || Name.get("Identity"); 54812 this.strf = dict.get("StrF") || Name.get("Identity"); 54813 this.eff = dict.get("EFF") || this.stmf; 54814 } 54815 } 54816 createCipherTransform(num, gen) { 54817 if (this.algorithm === 4 || this.algorithm === 5) { 54818 return new CipherTransform(this.#buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey), this.#buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey)); 54819 } 54820 const key = this.#buildObjectKey(num, gen, this.encryptionKey, false); 54821 const cipherConstructor = function () { 54822 return new ARCFourCipher(key); 54823 }; 54824 return new CipherTransform(cipherConstructor, cipherConstructor); 54825 } 54826} 54827 54828;// ./src/core/xref.js 54829 54830 54831 54832 54833 54834 54835class XRef { 54836 constructor(stream, pdfManager) { 54837 this.stream = stream; 54838 this.pdfManager = pdfManager; 54839 this.entries = []; 54840 this._xrefStms = new Set(); 54841 this._cacheMap = new Map(); 54842 this._pendingRefs = new RefSet(); 54843 this._newPersistentRefNum = null; 54844 this._newTemporaryRefNum = null; 54845 this._persistentRefsCache = null; 54846 } 54847 getNewPersistentRef(obj) { 54848 if (this._newPersistentRefNum === null) { 54849 this._newPersistentRefNum = this.entries.length || 1; 54850 } 54851 const num = this._newPersistentRefNum++; 54852 this._cacheMap.set(num, obj); 54853 return Ref.get(num, 0); 54854 } 54855 getNewTemporaryRef() { 54856 if (this._newTemporaryRefNum === null) { 54857 this._newTemporaryRefNum = this.entries.length || 1; 54858 if (this._newPersistentRefNum) { 54859 this._persistentRefsCache = new Map(); 54860 for (let i = this._newTemporaryRefNum; i < this._newPersistentRefNum; i++) { 54861 this._persistentRefsCache.set(i, this._cacheMap.get(i)); 54862 this._cacheMap.delete(i); 54863 } 54864 } 54865 } 54866 return Ref.get(this._newTemporaryRefNum++, 0); 54867 } 54868 resetNewTemporaryRef() { 54869 this._newTemporaryRefNum = null; 54870 if (this._persistentRefsCache) { 54871 for (const [num, obj] of this._persistentRefsCache) { 54872 this._cacheMap.set(num, obj); 54873 } 54874 } 54875 this._persistentRefsCache = null; 54876 } 54877 setStartXRef(startXRef) { 54878 this.startXRefQueue = [startXRef]; 54879 } 54880 parse(recoveryMode = false) { 54881 let trailerDict; 54882 if (!recoveryMode) { 54883 trailerDict = this.readXRef(); 54884 } else { 54885 warn("Indexing all PDF objects"); 54886 trailerDict = this.indexObjects(); 54887 } 54888 trailerDict.assignXref(this); 54889 this.trailer = trailerDict; 54890 let encrypt; 54891 try { 54892 encrypt = trailerDict.get("Encrypt"); 54893 } catch (ex) { 54894 if (ex instanceof MissingDataException) { 54895 throw ex; 54896 } 54897 warn(`XRef.parse - Invalid "Encrypt" reference: "${ex}".`); 54898 } 54899 if (encrypt instanceof Dict) { 54900 const ids = trailerDict.get("ID"); 54901 const fileId = ids?.length ? ids[0] : ""; 54902 encrypt.suppressEncryption = true; 54903 this.encrypt = new CipherTransformFactory(encrypt, fileId, this.pdfManager.password); 54904 } 54905 let root; 54906 try { 54907 root = trailerDict.get("Root"); 54908 } catch (ex) { 54909 if (ex instanceof MissingDataException) { 54910 throw ex; 54911 } 54912 warn(`XRef.parse - Invalid "Root" reference: "${ex}".`); 54913 } 54914 if (root instanceof Dict) { 54915 try { 54916 const pages = root.get("Pages"); 54917 if (pages instanceof Dict) { 54918 this.root = root; 54919 return; 54920 } 54921 } catch (ex) { 54922 if (ex instanceof MissingDataException) { 54923 throw ex; 54924 } 54925 warn(`XRef.parse - Invalid "Pages" reference: "${ex}".`); 54926 } 54927 } 54928 if (!recoveryMode) { 54929 throw new XRefParseException(); 54930 } 54931 throw new InvalidPDFException("Invalid Root reference."); 54932 } 54933 processXRefTable(parser) { 54934 if (!("tableState" in this)) { 54935 this.tableState = { 54936 entryNum: 0, 54937 streamPos: parser.lexer.stream.pos, 54938 parserBuf1: parser.buf1, 54939 parserBuf2: parser.buf2 54940 }; 54941 } 54942 const obj = this.readXRefTable(parser); 54943 if (!isCmd(obj, "trailer")) { 54944 throw new FormatError("Invalid XRef table: could not find trailer dictionary"); 54945 } 54946 let dict = parser.getObj(); 54947 if (!(dict instanceof Dict) && dict.dict) { 54948 dict = dict.dict; 54949 } 54950 if (!(dict instanceof Dict)) { 54951 throw new FormatError("Invalid XRef table: could not parse trailer dictionary"); 54952 } 54953 delete this.tableState; 54954 return dict; 54955 } 54956 readXRefTable(parser) { 54957 const stream = parser.lexer.stream; 54958 const tableState = this.tableState; 54959 stream.pos = tableState.streamPos; 54960 parser.buf1 = tableState.parserBuf1; 54961 parser.buf2 = tableState.parserBuf2; 54962 let obj; 54963 while (true) { 54964 if (!("firstEntryNum" in tableState) || !("entryCount" in tableState)) { 54965 if (isCmd(obj = parser.getObj(), "trailer")) { 54966 break; 54967 } 54968 tableState.firstEntryNum = obj; 54969 tableState.entryCount = parser.getObj(); 54970 } 54971 let first = tableState.firstEntryNum; 54972 const count = tableState.entryCount; 54973 if (!Number.isInteger(first) || !Number.isInteger(count)) { 54974 throw new FormatError("Invalid XRef table: wrong types in subsection header"); 54975 } 54976 for (let i = tableState.entryNum; i < count; i++) { 54977 tableState.streamPos = stream.pos; 54978 tableState.entryNum = i; 54979 tableState.parserBuf1 = parser.buf1; 54980 tableState.parserBuf2 = parser.buf2; 54981 const entry = {}; 54982 entry.offset = parser.getObj(); 54983 entry.gen = parser.getObj(); 54984 const type = parser.getObj(); 54985 if (type instanceof Cmd) { 54986 switch (type.cmd) { 54987 case "f": 54988 entry.free = true; 54989 break; 54990 case "n": 54991 entry.uncompressed = true; 54992 break; 54993 } 54994 } 54995 if (!Number.isInteger(entry.offset) || !Number.isInteger(entry.gen) || !(entry.free || entry.uncompressed)) { 54996 throw new FormatError(`Invalid entry in XRef subsection: ${first}, ${count}`); 54997 } 54998 if (i === 0 && entry.free && first === 1) { 54999 first = 0; 55000 } 55001 if (!this.entries[i + first]) { 55002 this.entries[i + first] = entry; 55003 } 55004 } 55005 tableState.entryNum = 0; 55006 tableState.streamPos = stream.pos; 55007 tableState.parserBuf1 = parser.buf1; 55008 tableState.parserBuf2 = parser.buf2; 55009 delete tableState.firstEntryNum; 55010 delete tableState.entryCount; 55011 } 55012 if (this.entries[0] && !this.entries[0].free) { 55013 throw new FormatError("Invalid XRef table: unexpected first object"); 55014 } 55015 return obj; 55016 } 55017 processXRefStream(stream) { 55018 if (!("streamState" in this)) { 55019 const { 55020 dict, 55021 pos 55022 } = stream; 55023 const byteWidths = dict.get("W"); 55024 const range = dict.get("Index") || [0, dict.get("Size")]; 55025 this.streamState = { 55026 entryRanges: range, 55027 byteWidths, 55028 entryNum: 0, 55029 streamPos: pos 55030 }; 55031 } 55032 this.readXRefStream(stream); 55033 delete this.streamState; 55034 return stream.dict; 55035 } 55036 readXRefStream(stream) { 55037 const streamState = this.streamState; 55038 stream.pos = streamState.streamPos; 55039 const [typeFieldWidth, offsetFieldWidth, generationFieldWidth] = streamState.byteWidths; 55040 const entryRanges = streamState.entryRanges; 55041 while (entryRanges.length > 0) { 55042 const [first, n] = entryRanges; 55043 if (!Number.isInteger(first) || !Number.isInteger(n)) { 55044 throw new FormatError(`Invalid XRef range fields: ${first}, ${n}`); 55045 } 55046 if (!Number.isInteger(typeFieldWidth) || !Number.isInteger(offsetFieldWidth) || !Number.isInteger(generationFieldWidth)) { 55047 throw new FormatError(`Invalid XRef entry fields length: ${first}, ${n}`); 55048 } 55049 for (let i = streamState.entryNum; i < n; ++i) { 55050 streamState.entryNum = i; 55051 streamState.streamPos = stream.pos; 55052 let type = 0, 55053 offset = 0, 55054 generation = 0; 55055 for (let j = 0; j < typeFieldWidth; ++j) { 55056 const typeByte = stream.getByte(); 55057 if (typeByte === -1) { 55058 throw new FormatError("Invalid XRef byteWidths 'type'."); 55059 } 55060 type = type << 8 | typeByte; 55061 } 55062 if (typeFieldWidth === 0) { 55063 type = 1; 55064 } 55065 for (let j = 0; j < offsetFieldWidth; ++j) { 55066 const offsetByte = stream.getByte(); 55067 if (offsetByte === -1) { 55068 throw new FormatError("Invalid XRef byteWidths 'offset'."); 55069 } 55070 offset = offset << 8 | offsetByte; 55071 } 55072 for (let j = 0; j < generationFieldWidth; ++j) { 55073 const generationByte = stream.getByte(); 55074 if (generationByte === -1) { 55075 throw new FormatError("Invalid XRef byteWidths 'generation'."); 55076 } 55077 generation = generation << 8 | generationByte; 55078 } 55079 const entry = {}; 55080 entry.offset = offset; 55081 entry.gen = generation; 55082 switch (type) { 55083 case 0: 55084 entry.free = true; 55085 break; 55086 case 1: 55087 entry.uncompressed = true; 55088 break; 55089 case 2: 55090 break; 55091 default: 55092 throw new FormatError(`Invalid XRef entry type: ${type}`); 55093 } 55094 if (!this.entries[first + i]) { 55095 this.entries[first + i] = entry; 55096 } 55097 } 55098 streamState.entryNum = 0; 55099 streamState.streamPos = stream.pos; 55100 entryRanges.splice(0, 2); 55101 } 55102 } 55103 indexObjects() { 55104 const TAB = 0x9, 55105 LF = 0xa, 55106 CR = 0xd, 55107 SPACE = 0x20; 55108 const PERCENT = 0x25, 55109 LT = 0x3c; 55110 function readToken(data, offset) { 55111 let token = "", 55112 ch = data[offset]; 55113 while (ch !== LF && ch !== CR && ch !== LT) { 55114 if (++offset >= data.length) { 55115 break; 55116 } 55117 token += String.fromCharCode(ch); 55118 ch = data[offset]; 55119 } 55120 return token; 55121 } 55122 function skipUntil(data, offset, what) { 55123 const length = what.length, 55124 dataLength = data.length; 55125 let skipped = 0; 55126 while (offset < dataLength) { 55127 let i = 0; 55128 while (i < length && data[offset + i] === what[i]) { 55129 ++i; 55130 } 55131 if (i >= length) { 55132 break; 55133 } 55134 offset++; 55135 skipped++; 55136 } 55137 return skipped; 55138 } 55139 const gEndobjRegExp = /\b(endobj|\d+\s+\d+\s+obj|xref|trailer\s*<<)\b/g; 55140 const gStartxrefRegExp = /\b(startxref|\d+\s+\d+\s+obj)\b/g; 55141 const objRegExp = /^(\d+)\s+(\d+)\s+obj\b/; 55142 const trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]); 55143 const startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114, 101, 102]); 55144 const xrefBytes = new Uint8Array([47, 88, 82, 101, 102]); 55145 this.entries.length = 0; 55146 this._cacheMap.clear(); 55147 const stream = this.stream; 55148 stream.pos = 0; 55149 const buffer = stream.getBytes(), 55150 bufferStr = bytesToString(buffer), 55151 length = buffer.length; 55152 let position = stream.start; 55153 const trailers = [], 55154 xrefStms = []; 55155 while (position < length) { 55156 let ch = buffer[position]; 55157 if (ch === TAB || ch === LF || ch === CR || ch === SPACE) { 55158 ++position; 55159 continue; 55160 } 55161 if (ch === PERCENT) { 55162 do { 55163 ++position; 55164 if (position >= length) { 55165 break; 55166 } 55167 ch = buffer[position]; 55168 } while (ch !== LF && ch !== CR); 55169 continue; 55170 } 55171 const token = readToken(buffer, position); 55172 let m; 55173 if (token.startsWith("xref") && (token.length === 4 || /\s/.test(token[4]))) { 55174 position += skipUntil(buffer, position, trailerBytes); 55175 trailers.push(position); 55176 position += skipUntil(buffer, position, startxrefBytes); 55177 } else if (m = objRegExp.exec(token)) { 55178 const num = m[1] | 0, 55179 gen = m[2] | 0; 55180 const startPos = position + token.length; 55181 let contentLength, 55182 updateEntries = false; 55183 if (!this.entries[num]) { 55184 updateEntries = true; 55185 } else if (this.entries[num].gen === gen) { 55186 try { 55187 const parser = new Parser({ 55188 lexer: new Lexer(stream.makeSubStream(startPos)) 55189 }); 55190 parser.getObj(); 55191 updateEntries = true; 55192 } catch (ex) { 55193 if (ex instanceof ParserEOFException) { 55194 warn(`indexObjects -- checking object (${token}): "${ex}".`); 55195 } else { 55196 updateEntries = true; 55197 } 55198 } 55199 } 55200 if (updateEntries) { 55201 this.entries[num] = { 55202 offset: position - stream.start, 55203 gen, 55204 uncompressed: true 55205 }; 55206 } 55207 gEndobjRegExp.lastIndex = startPos; 55208 const match = gEndobjRegExp.exec(bufferStr); 55209 if (match) { 55210 const endPos = gEndobjRegExp.lastIndex + 1; 55211 contentLength = endPos - position; 55212 if (match[1] !== "endobj") { 55213 warn(`indexObjects: Found "${match[1]}" inside of another "obj", ` + 'caused by missing "endobj" -- trying to recover.'); 55214 contentLength -= match[1].length + 1; 55215 } 55216 } else { 55217 contentLength = length - position; 55218 } 55219 const content = buffer.subarray(position, position + contentLength); 55220 const xrefTagOffset = skipUntil(content, 0, xrefBytes); 55221 if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) { 55222 xrefStms.push(position - stream.start); 55223 this._xrefStms.add(position - stream.start); 55224 } 55225 position += contentLength; 55226 } else if (token.startsWith("trailer") && (token.length === 7 || /\s/.test(token[7]))) { 55227 trailers.push(position); 55228 const startPos = position + token.length; 55229 let contentLength; 55230 gStartxrefRegExp.lastIndex = startPos; 55231 const match = gStartxrefRegExp.exec(bufferStr); 55232 if (match) { 55233 const endPos = gStartxrefRegExp.lastIndex + 1; 55234 contentLength = endPos - position; 55235 if (match[1] !== "startxref") { 55236 warn(`indexObjects: Found "${match[1]}" after "trailer", ` + 'caused by missing "startxref" -- trying to recover.'); 55237 contentLength -= match[1].length + 1; 55238 } 55239 } else { 55240 contentLength = length - position; 55241 } 55242 position += contentLength; 55243 } else { 55244 position += token.length + 1; 55245 } 55246 } 55247 for (const xrefStm of xrefStms) { 55248 this.startXRefQueue.push(xrefStm); 55249 this.readXRef(true); 55250 } 55251 const trailerDicts = []; 55252 let isEncrypted = false; 55253 for (const trailer of trailers) { 55254 stream.pos = trailer; 55255 const parser = new Parser({ 55256 lexer: new Lexer(stream), 55257 xref: this, 55258 allowStreams: true, 55259 recoveryMode: true 55260 }); 55261 const obj = parser.getObj(); 55262 if (!isCmd(obj, "trailer")) { 55263 continue; 55264 } 55265 const dict = parser.getObj(); 55266 if (!(dict instanceof Dict)) { 55267 continue; 55268 } 55269 trailerDicts.push(dict); 55270 if (dict.has("Encrypt")) { 55271 isEncrypted = true; 55272 } 55273 } 55274 let trailerDict, trailerError; 55275 for (const dict of [...trailerDicts, "genFallback", ...trailerDicts]) { 55276 if (dict === "genFallback") { 55277 if (!trailerError) { 55278 break; 55279 } 55280 this._generationFallback = true; 55281 continue; 55282 } 55283 let validPagesDict = false; 55284 try { 55285 const rootDict = dict.get("Root"); 55286 if (!(rootDict instanceof Dict)) { 55287 continue; 55288 } 55289 const pagesDict = rootDict.get("Pages"); 55290 if (!(pagesDict instanceof Dict)) { 55291 continue; 55292 } 55293 const pagesCount = pagesDict.get("Count"); 55294 if (Number.isInteger(pagesCount)) { 55295 validPagesDict = true; 55296 } 55297 } catch (ex) { 55298 trailerError = ex; 55299 continue; 55300 } 55301 if (validPagesDict && (!isEncrypted || dict.has("Encrypt")) && dict.has("ID")) { 55302 return dict; 55303 } 55304 trailerDict = dict; 55305 } 55306 if (trailerDict) { 55307 return trailerDict; 55308 } 55309 if (this.topDict) { 55310 return this.topDict; 55311 } 55312 if (!trailerDicts.length) { 55313 for (const num in this.entries) { 55314 if (!Object.hasOwn(this.entries, num)) { 55315 continue; 55316 } 55317 const entry = this.entries[num]; 55318 const ref = Ref.get(parseInt(num), entry.gen); 55319 let obj; 55320 try { 55321 obj = this.fetch(ref); 55322 } catch { 55323 continue; 55324 } 55325 if (obj instanceof BaseStream) { 55326 obj = obj.dict; 55327 } 55328 if (obj instanceof Dict && obj.has("Root")) { 55329 return obj; 55330 } 55331 } 55332 } 55333 throw new InvalidPDFException("Invalid PDF structure."); 55334 } 55335 readXRef(recoveryMode = false) { 55336 const stream = this.stream; 55337 const startXRefParsedCache = new Set(); 55338 while (this.startXRefQueue.length) { 55339 try { 55340 const startXRef = this.startXRefQueue[0]; 55341 if (startXRefParsedCache.has(startXRef)) { 55342 warn("readXRef - skipping XRef table since it was already parsed."); 55343 this.startXRefQueue.shift(); 55344 continue; 55345 } 55346 startXRefParsedCache.add(startXRef); 55347 stream.pos = startXRef + stream.start; 55348 const parser = new Parser({ 55349 lexer: new Lexer(stream), 55350 xref: this, 55351 allowStreams: true 55352 }); 55353 let obj = parser.getObj(); 55354 let dict; 55355 if (isCmd(obj, "xref")) { 55356 dict = this.processXRefTable(parser); 55357 if (!this.topDict) { 55358 this.topDict = dict; 55359 } 55360 obj = dict.get("XRefStm"); 55361 if (Number.isInteger(obj) && !this._xrefStms.has(obj)) { 55362 this._xrefStms.add(obj); 55363 this.startXRefQueue.push(obj); 55364 } 55365 } else if (Number.isInteger(obj)) { 55366 if (!Number.isInteger(parser.getObj()) || !isCmd(parser.getObj(), "obj") || !((obj = parser.getObj()) instanceof BaseStream)) { 55367 throw new FormatError("Invalid XRef stream"); 55368 } 55369 dict = this.processXRefStream(obj); 55370 if (!this.topDict) { 55371 this.topDict = dict; 55372 } 55373 if (!dict) { 55374 throw new FormatError("Failed to read XRef stream"); 55375 } 55376 } else { 55377 throw new FormatError("Invalid XRef stream header"); 55378 } 55379 obj = dict.get("Prev"); 55380 if (Number.isInteger(obj)) { 55381 this.startXRefQueue.push(obj); 55382 } else if (obj instanceof Ref) { 55383 this.startXRefQueue.push(obj.num); 55384 } 55385 } catch (e) { 55386 if (e instanceof MissingDataException) { 55387 throw e; 55388 } 55389 info("(while reading XRef): " + e); 55390 } 55391 this.startXRefQueue.shift(); 55392 } 55393 if (this.topDict) { 55394 return this.topDict; 55395 } 55396 if (recoveryMode) { 55397 return undefined; 55398 } 55399 throw new XRefParseException(); 55400 } 55401 getEntry(i) { 55402 const xrefEntry = this.entries[i]; 55403 if (xrefEntry && !xrefEntry.free && xrefEntry.offset) { 55404 return xrefEntry; 55405 } 55406 return null; 55407 } 55408 fetchIfRef(obj, suppressEncryption = false) { 55409 if (obj instanceof Ref) { 55410 return this.fetch(obj, suppressEncryption); 55411 } 55412 return obj; 55413 } 55414 fetch(ref, suppressEncryption = false) { 55415 if (!(ref instanceof Ref)) { 55416 throw new Error("ref object is not a reference"); 55417 } 55418 const num = ref.num; 55419 const cacheEntry = this._cacheMap.get(num); 55420 if (cacheEntry !== undefined) { 55421 if (cacheEntry instanceof Dict && !cacheEntry.objId) { 55422 cacheEntry.objId = ref.toString(); 55423 } 55424 return cacheEntry; 55425 } 55426 let xrefEntry = this.getEntry(num); 55427 if (xrefEntry === null) { 55428 return xrefEntry; 55429 } 55430 if (this._pendingRefs.has(ref)) { 55431 this._pendingRefs.remove(ref); 55432 warn(`Ignoring circular reference: ${ref}.`); 55433 return CIRCULAR_REF; 55434 } 55435 this._pendingRefs.put(ref); 55436 try { 55437 xrefEntry = xrefEntry.uncompressed ? this.fetchUncompressed(ref, xrefEntry, suppressEncryption) : this.fetchCompressed(ref, xrefEntry, suppressEncryption); 55438 this._pendingRefs.remove(ref); 55439 } catch (ex) { 55440 this._pendingRefs.remove(ref); 55441 throw ex; 55442 } 55443 if (xrefEntry instanceof Dict) { 55444 xrefEntry.objId = ref.toString(); 55445 } else if (xrefEntry instanceof BaseStream) { 55446 xrefEntry.dict.objId = ref.toString(); 55447 } 55448 return xrefEntry; 55449 } 55450 fetchUncompressed(ref, xrefEntry, suppressEncryption = false) { 55451 const gen = ref.gen; 55452 let num = ref.num; 55453 if (xrefEntry.gen !== gen) { 55454 const msg = `Inconsistent generation in XRef: ${ref}`; 55455 if (this._generationFallback && xrefEntry.gen < gen) { 55456 warn(msg); 55457 return this.fetchUncompressed(Ref.get(num, xrefEntry.gen), xrefEntry, suppressEncryption); 55458 } 55459 throw new XRefEntryException(msg); 55460 } 55461 const stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start); 55462 const parser = new Parser({ 55463 lexer: new Lexer(stream), 55464 xref: this, 55465 allowStreams: true 55466 }); 55467 const obj1 = parser.getObj(); 55468 const obj2 = parser.getObj(); 55469 const obj3 = parser.getObj(); 55470 if (obj1 !== num || obj2 !== gen || !(obj3 instanceof Cmd)) { 55471 throw new XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`); 55472 } 55473 if (obj3.cmd !== "obj") { 55474 if (obj3.cmd.startsWith("obj")) { 55475 num = parseInt(obj3.cmd.substring(3), 10); 55476 if (!Number.isNaN(num)) { 55477 return num; 55478 } 55479 } 55480 throw new XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`); 55481 } 55482 xrefEntry = this.encrypt && !suppressEncryption ? parser.getObj(this.encrypt.createCipherTransform(num, gen)) : parser.getObj(); 55483 if (!(xrefEntry instanceof BaseStream)) { 55484 this._cacheMap.set(num, xrefEntry); 55485 } 55486 return xrefEntry; 55487 } 55488 fetchCompressed(ref, xrefEntry, suppressEncryption = false) { 55489 const tableOffset = xrefEntry.offset; 55490 const stream = this.fetch(Ref.get(tableOffset, 0)); 55491 if (!(stream instanceof BaseStream)) { 55492 throw new FormatError("bad ObjStm stream"); 55493 } 55494 const first = stream.dict.get("First"); 55495 const n = stream.dict.get("N"); 55496 if (!Number.isInteger(first) || !Number.isInteger(n)) { 55497 throw new FormatError("invalid first and n parameters for ObjStm stream"); 55498 } 55499 let parser = new Parser({ 55500 lexer: new Lexer(stream), 55501 xref: this, 55502 allowStreams: true 55503 }); 55504 const nums = new Array(n); 55505 const offsets = new Array(n); 55506 for (let i = 0; i < n; ++i) { 55507 const num = parser.getObj(); 55508 if (!Number.isInteger(num)) { 55509 throw new FormatError(`invalid object number in the ObjStm stream: ${num}`); 55510 } 55511 const offset = parser.getObj(); 55512 if (!Number.isInteger(offset)) { 55513 throw new FormatError(`invalid object offset in the ObjStm stream: ${offset}`); 55514 } 55515 nums[i] = num; 55516 const entry = this.getEntry(num); 55517 if (entry?.offset === tableOffset && entry.gen !== i) { 55518 entry.gen = i; 55519 } 55520 offsets[i] = offset; 55521 } 55522 const start = (stream.start || 0) + first; 55523 const entries = new Array(n); 55524 for (let i = 0; i < n; ++i) { 55525 const length = i < n - 1 ? offsets[i + 1] - offsets[i] : undefined; 55526 if (length < 0) { 55527 throw new FormatError("Invalid offset in the ObjStm stream."); 55528 } 55529 parser = new Parser({ 55530 lexer: new Lexer(stream.makeSubStream(start + offsets[i], length, stream.dict)), 55531 xref: this, 55532 allowStreams: true 55533 }); 55534 const obj = parser.getObj(); 55535 entries[i] = obj; 55536 if (obj instanceof BaseStream) { 55537 continue; 55538 } 55539 const num = nums[i], 55540 entry = this.entries[num]; 55541 if (entry && entry.offset === tableOffset && entry.gen === i) { 55542 this._cacheMap.set(num, obj); 55543 } 55544 } 55545 xrefEntry = entries[xrefEntry.gen]; 55546 if (xrefEntry === undefined) { 55547 throw new XRefEntryException(`Bad (compressed) XRef entry: ${ref}`); 55548 } 55549 return xrefEntry; 55550 } 55551 async fetchIfRefAsync(obj, suppressEncryption) { 55552 if (obj instanceof Ref) { 55553 return this.fetchAsync(obj, suppressEncryption); 55554 } 55555 return obj; 55556 } 55557 async fetchAsync(ref, suppressEncryption) { 55558 try { 55559 return this.fetch(ref, suppressEncryption); 55560 } catch (ex) { 55561 if (!(ex instanceof MissingDataException)) { 55562 throw ex; 55563 } 55564 await this.pdfManager.requestRange(ex.begin, ex.end); 55565 return this.fetchAsync(ref, suppressEncryption); 55566 } 55567 } 55568 getCatalogObj() { 55569 return this.root; 55570 } 55571} 55572 55573;// ./src/core/document.js 55574 55575 55576 55577 55578 55579 55580 55581 55582 55583 55584 55585 55586 55587 55588 55589 55590 55591 55592 55593 55594const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792]; 55595class Page { 55596 #areAnnotationsCached = false; 55597 #resourcesPromise = null; 55598 constructor({ 55599 pdfManager, 55600 xref, 55601 pageIndex, 55602 pageDict, 55603 ref, 55604 globalIdFactory, 55605 fontCache, 55606 builtInCMapCache, 55607 standardFontDataCache, 55608 globalColorSpaceCache, 55609 globalImageCache, 55610 systemFontCache, 55611 nonBlendModesSet, 55612 xfaFactory 55613 }) { 55614 this.pdfManager = pdfManager; 55615 this.pageIndex = pageIndex; 55616 this.pageDict = pageDict; 55617 this.xref = xref; 55618 this.ref = ref; 55619 this.fontCache = fontCache; 55620 this.builtInCMapCache = builtInCMapCache; 55621 this.standardFontDataCache = standardFontDataCache; 55622 this.globalColorSpaceCache = globalColorSpaceCache; 55623 this.globalImageCache = globalImageCache; 55624 this.systemFontCache = systemFontCache; 55625 this.nonBlendModesSet = nonBlendModesSet; 55626 this.evaluatorOptions = pdfManager.evaluatorOptions; 55627 this.xfaFactory = xfaFactory; 55628 const idCounters = { 55629 obj: 0 55630 }; 55631 this._localIdFactory = class extends globalIdFactory { 55632 static createObjId() { 55633 return `p${pageIndex}_${++idCounters.obj}`; 55634 } 55635 static getPageObjId() { 55636 return `p${ref.toString()}`; 55637 } 55638 }; 55639 } 55640 #createPartialEvaluator(handler) { 55641 return new PartialEvaluator({ 55642 xref: this.xref, 55643 handler, 55644 pageIndex: this.pageIndex, 55645 idFactory: this._localIdFactory, 55646 fontCache: this.fontCache, 55647 builtInCMapCache: this.builtInCMapCache, 55648 standardFontDataCache: this.standardFontDataCache, 55649 globalColorSpaceCache: this.globalColorSpaceCache, 55650 globalImageCache: this.globalImageCache, 55651 systemFontCache: this.systemFontCache, 55652 options: this.evaluatorOptions 55653 }); 55654 } 55655 #getInheritableProperty(key, getArray = false) { 55656 const value = getInheritableProperty({ 55657 dict: this.pageDict, 55658 key, 55659 getArray, 55660 stopWhenFound: false 55661 }); 55662 if (!Array.isArray(value)) { 55663 return value; 55664 } 55665 if (value.length === 1 || !(value[0] instanceof Dict)) { 55666 return value[0]; 55667 } 55668 return Dict.merge({ 55669 xref: this.xref, 55670 dictArray: value 55671 }); 55672 } 55673 get content() { 55674 return this.pageDict.getArray("Contents"); 55675 } 55676 get resources() { 55677 const resources = this.#getInheritableProperty("Resources"); 55678 return shadow(this, "resources", resources instanceof Dict ? resources : Dict.empty); 55679 } 55680 #getBoundingBox(name) { 55681 if (this.xfaData) { 55682 return this.xfaData.bbox; 55683 } 55684 const box = lookupNormalRect(this.#getInheritableProperty(name, true), null); 55685 if (box) { 55686 if (box[2] - box[0] > 0 && box[3] - box[1] > 0) { 55687 return box; 55688 } 55689 warn(`Empty, or invalid, /${name} entry.`); 55690 } 55691 return null; 55692 } 55693 get mediaBox() { 55694 return shadow(this, "mediaBox", this.#getBoundingBox("MediaBox") || LETTER_SIZE_MEDIABOX); 55695 } 55696 get cropBox() { 55697 return shadow(this, "cropBox", this.#getBoundingBox("CropBox") || this.mediaBox); 55698 } 55699 get userUnit() { 55700 const obj = this.pageDict.get("UserUnit"); 55701 return shadow(this, "userUnit", typeof obj === "number" && obj > 0 ? obj : 1.0); 55702 } 55703 get view() { 55704 const { 55705 cropBox, 55706 mediaBox 55707 } = this; 55708 if (cropBox !== mediaBox && !isArrayEqual(cropBox, mediaBox)) { 55709 const box = Util.intersect(cropBox, mediaBox); 55710 if (box && box[2] - box[0] > 0 && box[3] - box[1] > 0) { 55711 return shadow(this, "view", box); 55712 } 55713 warn("Empty /CropBox and /MediaBox intersection."); 55714 } 55715 return shadow(this, "view", mediaBox); 55716 } 55717 get rotate() { 55718 let rotate = this.#getInheritableProperty("Rotate") || 0; 55719 if (rotate % 90 !== 0) { 55720 rotate = 0; 55721 } else if (rotate >= 360) { 55722 rotate %= 360; 55723 } else if (rotate < 0) { 55724 rotate = (rotate % 360 + 360) % 360; 55725 } 55726 return shadow(this, "rotate", rotate); 55727 } 55728 #onSubStreamError(reason, objId) { 55729 if (this.evaluatorOptions.ignoreErrors) { 55730 warn(`getContentStream - ignoring sub-stream (${objId}): "${reason}".`); 55731 return; 55732 } 55733 throw reason; 55734 } 55735 async getContentStream() { 55736 const content = await this.pdfManager.ensure(this, "content"); 55737 if (content instanceof BaseStream) { 55738 return content; 55739 } 55740 if (Array.isArray(content)) { 55741 return new StreamsSequenceStream(content, this.#onSubStreamError.bind(this)); 55742 } 55743 return new NullStream(); 55744 } 55745 get xfaData() { 55746 return shadow(this, "xfaData", this.xfaFactory ? { 55747 bbox: this.xfaFactory.getBoundingBox(this.pageIndex) 55748 } : null); 55749 } 55750 async #replaceIdByRef(annotations, deletedAnnotations, existingAnnotations) { 55751 const promises = []; 55752 for (const annotation of annotations) { 55753 if (annotation.id) { 55754 const ref = Ref.fromString(annotation.id); 55755 if (!ref) { 55756 warn(`A non-linked annotation cannot be modified: ${annotation.id}`); 55757 continue; 55758 } 55759 if (annotation.deleted) { 55760 deletedAnnotations.put(ref, ref); 55761 if (annotation.popupRef) { 55762 const popupRef = Ref.fromString(annotation.popupRef); 55763 if (popupRef) { 55764 deletedAnnotations.put(popupRef, popupRef); 55765 } 55766 } 55767 continue; 55768 } 55769 if (annotation.popup?.deleted) { 55770 const popupRef = Ref.fromString(annotation.popupRef); 55771 if (popupRef) { 55772 deletedAnnotations.put(popupRef, popupRef); 55773 } 55774 } 55775 existingAnnotations?.put(ref); 55776 annotation.ref = ref; 55777 promises.push(this.xref.fetchAsync(ref).then(obj => { 55778 if (obj instanceof Dict) { 55779 annotation.oldAnnotation = obj.clone(); 55780 } 55781 }, () => { 55782 warn(`Cannot fetch \`oldAnnotation\` for: ${ref}.`); 55783 })); 55784 delete annotation.id; 55785 } 55786 } 55787 await Promise.all(promises); 55788 } 55789 async saveNewAnnotations(handler, task, annotations, imagePromises, changes) { 55790 if (this.xfaFactory) { 55791 throw new Error("XFA: Cannot save new annotations."); 55792 } 55793 const partialEvaluator = this.#createPartialEvaluator(handler); 55794 const deletedAnnotations = new RefSetCache(); 55795 const existingAnnotations = new RefSet(); 55796 await this.#replaceIdByRef(annotations, deletedAnnotations, existingAnnotations); 55797 const pageDict = this.pageDict; 55798 const annotationsArray = this.annotations.filter(a => !(a instanceof Ref && deletedAnnotations.has(a))); 55799 const newData = await AnnotationFactory.saveNewAnnotations(partialEvaluator, task, annotations, imagePromises, changes); 55800 for (const { 55801 ref 55802 } of newData.annotations) { 55803 if (ref instanceof Ref && !existingAnnotations.has(ref)) { 55804 annotationsArray.push(ref); 55805 } 55806 } 55807 const dict = pageDict.clone(); 55808 dict.set("Annots", annotationsArray); 55809 changes.put(this.ref, { 55810 data: dict 55811 }); 55812 for (const deletedRef of deletedAnnotations) { 55813 changes.put(deletedRef, { 55814 data: null 55815 }); 55816 } 55817 } 55818 async save(handler, task, annotationStorage, changes) { 55819 const partialEvaluator = this.#createPartialEvaluator(handler); 55820 const annotations = await this._parsedAnnotations; 55821 const promises = []; 55822 for (const annotation of annotations) { 55823 promises.push(annotation.save(partialEvaluator, task, annotationStorage, changes).catch(function (reason) { 55824 warn("save - ignoring annotation data during " + `"${task.name}" task: "${reason}".`); 55825 return null; 55826 })); 55827 } 55828 return Promise.all(promises); 55829 } 55830 async loadResources(keys) { 55831 await (this.#resourcesPromise ??= this.pdfManager.ensure(this, "resources")); 55832 await ObjectLoader.load(this.resources, keys, this.xref); 55833 } 55834 async #getMergedResources(streamDict, keys) { 55835 const localResources = streamDict?.get("Resources"); 55836 if (!(localResources instanceof Dict && localResources.size)) { 55837 return this.resources; 55838 } 55839 await ObjectLoader.load(localResources, keys, this.xref); 55840 return Dict.merge({ 55841 xref: this.xref, 55842 dictArray: [localResources, this.resources], 55843 mergeSubDicts: true 55844 }); 55845 } 55846 async getOperatorList({ 55847 handler, 55848 sink, 55849 task, 55850 intent, 55851 cacheKey, 55852 annotationStorage = null, 55853 modifiedIds = null 55854 }) { 55855 const contentStreamPromise = this.getContentStream(); 55856 const resourcesPromise = this.loadResources(RESOURCES_KEYS_OPERATOR_LIST); 55857 const partialEvaluator = this.#createPartialEvaluator(handler); 55858 const newAnnotsByPage = !this.xfaFactory ? getNewAnnotationsMap(annotationStorage) : null; 55859 const newAnnots = newAnnotsByPage?.get(this.pageIndex); 55860 let newAnnotationsPromise = Promise.resolve(null); 55861 let deletedAnnotations = null; 55862 if (newAnnots) { 55863 const annotationGlobalsPromise = this.pdfManager.ensureDoc("annotationGlobals"); 55864 let imagePromises; 55865 const missingBitmaps = new Set(); 55866 for (const { 55867 bitmapId, 55868 bitmap 55869 } of newAnnots) { 55870 if (bitmapId && !bitmap && !missingBitmaps.has(bitmapId)) { 55871 missingBitmaps.add(bitmapId); 55872 } 55873 } 55874 const { 55875 isOffscreenCanvasSupported 55876 } = this.evaluatorOptions; 55877 if (missingBitmaps.size > 0) { 55878 const annotationWithBitmaps = newAnnots.slice(); 55879 for (const [key, annotation] of annotationStorage) { 55880 if (!key.startsWith(AnnotationEditorPrefix)) { 55881 continue; 55882 } 55883 if (annotation.bitmap && missingBitmaps.has(annotation.bitmapId)) { 55884 annotationWithBitmaps.push(annotation); 55885 } 55886 } 55887 imagePromises = AnnotationFactory.generateImages(annotationWithBitmaps, this.xref, isOffscreenCanvasSupported); 55888 } else { 55889 imagePromises = AnnotationFactory.generateImages(newAnnots, this.xref, isOffscreenCanvasSupported); 55890 } 55891 deletedAnnotations = new RefSet(); 55892 newAnnotationsPromise = Promise.all([annotationGlobalsPromise, this.#replaceIdByRef(newAnnots, deletedAnnotations, null)]).then(([annotationGlobals]) => { 55893 if (!annotationGlobals) { 55894 return null; 55895 } 55896 return AnnotationFactory.printNewAnnotations(annotationGlobals, partialEvaluator, task, newAnnots, imagePromises); 55897 }); 55898 } 55899 const pageListPromise = Promise.all([contentStreamPromise, resourcesPromise]).then(async ([contentStream]) => { 55900 const resources = await this.#getMergedResources(contentStream.dict, RESOURCES_KEYS_OPERATOR_LIST); 55901 const opList = new OperatorList(intent, sink); 55902 handler.send("StartRenderPage", { 55903 transparency: partialEvaluator.hasBlendModes(resources, this.nonBlendModesSet), 55904 pageIndex: this.pageIndex, 55905 cacheKey 55906 }); 55907 await partialEvaluator.getOperatorList({ 55908 stream: contentStream, 55909 task, 55910 resources, 55911 operatorList: opList 55912 }); 55913 return opList; 55914 }); 55915 let [pageOpList, annotations, newAnnotations] = await Promise.all([pageListPromise, this._parsedAnnotations, newAnnotationsPromise]); 55916 if (newAnnotations) { 55917 annotations = annotations.filter(a => !(a.ref && deletedAnnotations.has(a.ref))); 55918 for (let i = 0, ii = newAnnotations.length; i < ii; i++) { 55919 const newAnnotation = newAnnotations[i]; 55920 if (newAnnotation.refToReplace) { 55921 const j = annotations.findIndex(a => a.ref && isRefsEqual(a.ref, newAnnotation.refToReplace)); 55922 if (j >= 0) { 55923 annotations.splice(j, 1, newAnnotation); 55924 newAnnotations.splice(i--, 1); 55925 ii--; 55926 } 55927 } 55928 } 55929 annotations = annotations.concat(newAnnotations); 55930 } 55931 if (annotations.length === 0 || intent & RenderingIntentFlag.ANNOTATIONS_DISABLE) { 55932 pageOpList.flush(true); 55933 return { 55934 length: pageOpList.totalLength 55935 }; 55936 } 55937 const renderForms = !!(intent & RenderingIntentFlag.ANNOTATIONS_FORMS), 55938 isEditing = !!(intent & RenderingIntentFlag.IS_EDITING), 55939 intentAny = !!(intent & RenderingIntentFlag.ANY), 55940 intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY), 55941 intentPrint = !!(intent & RenderingIntentFlag.PRINT); 55942 const opListPromises = []; 55943 for (const annotation of annotations) { 55944 if (intentAny || intentDisplay && annotation.mustBeViewed(annotationStorage, renderForms) && annotation.mustBeViewedWhenEditing(isEditing, modifiedIds) || intentPrint && annotation.mustBePrinted(annotationStorage)) { 55945 opListPromises.push(annotation.getOperatorList(partialEvaluator, task, intent, annotationStorage).catch(function (reason) { 55946 warn("getOperatorList - ignoring annotation data during " + `"${task.name}" task: "${reason}".`); 55947 return { 55948 opList: null, 55949 separateForm: false, 55950 separateCanvas: false 55951 }; 55952 })); 55953 } 55954 } 55955 const opLists = await Promise.all(opListPromises); 55956 let form = false, 55957 canvas = false; 55958 for (const { 55959 opList, 55960 separateForm, 55961 separateCanvas 55962 } of opLists) { 55963 pageOpList.addOpList(opList); 55964 form ||= separateForm; 55965 canvas ||= separateCanvas; 55966 } 55967 pageOpList.flush(true, { 55968 form, 55969 canvas 55970 }); 55971 return { 55972 length: pageOpList.totalLength 55973 }; 55974 } 55975 async extractTextContent({ 55976 handler, 55977 task, 55978 includeMarkedContent, 55979 disableNormalization, 55980 sink, 55981 intersector = null 55982 }) { 55983 const contentStreamPromise = this.getContentStream(); 55984 const resourcesPromise = this.loadResources(RESOURCES_KEYS_TEXT_CONTENT); 55985 const langPromise = this.pdfManager.ensureCatalog("lang"); 55986 const [contentStream,, lang] = await Promise.all([contentStreamPromise, resourcesPromise, langPromise]); 55987 const resources = await this.#getMergedResources(contentStream.dict, RESOURCES_KEYS_TEXT_CONTENT); 55988 const partialEvaluator = this.#createPartialEvaluator(handler); 55989 return partialEvaluator.getTextContent({ 55990 stream: contentStream, 55991 task, 55992 resources, 55993 includeMarkedContent, 55994 disableNormalization, 55995 sink, 55996 viewBox: this.view, 55997 lang, 55998 intersector 55999 }); 56000 } 56001 async getStructTree() { 56002 const structTreeRoot = await this.pdfManager.ensureCatalog("structTreeRoot"); 56003 if (!structTreeRoot) { 56004 return null; 56005 } 56006 await this._parsedAnnotations; 56007 try { 56008 const structTree = await this.pdfManager.ensure(this, "_parseStructTree", [structTreeRoot]); 56009 const data = await this.pdfManager.ensure(structTree, "serializable"); 56010 return data; 56011 } catch (ex) { 56012 warn(`getStructTree: "${ex}".`); 56013 return null; 56014 } 56015 } 56016 _parseStructTree(structTreeRoot) { 56017 const tree = new StructTreePage(structTreeRoot, this.pageDict); 56018 tree.parse(this.ref); 56019 return tree; 56020 } 56021 async getAnnotationsData(handler, task, intent) { 56022 const annotations = await this._parsedAnnotations; 56023 if (annotations.length === 0) { 56024 return annotations; 56025 } 56026 const annotationsData = [], 56027 textContentPromises = []; 56028 let partialEvaluator; 56029 const intentAny = !!(intent & RenderingIntentFlag.ANY), 56030 intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY), 56031 intentPrint = !!(intent & RenderingIntentFlag.PRINT); 56032 const highlightedAnnotations = []; 56033 for (const annotation of annotations) { 56034 const isVisible = intentAny || intentDisplay && annotation.viewable; 56035 if (isVisible || intentPrint && annotation.printable) { 56036 annotationsData.push(annotation.data); 56037 } 56038 if (annotation.hasTextContent && isVisible) { 56039 partialEvaluator ??= this.#createPartialEvaluator(handler); 56040 textContentPromises.push(annotation.extractTextContent(partialEvaluator, task, [-Infinity, -Infinity, Infinity, Infinity]).catch(function (reason) { 56041 warn(`getAnnotationsData - ignoring textContent during "${task.name}" task: "${reason}".`); 56042 })); 56043 } else if (annotation.overlaysTextContent && isVisible) { 56044 highlightedAnnotations.push(annotation); 56045 } 56046 } 56047 if (highlightedAnnotations.length > 0) { 56048 const intersector = new Intersector(highlightedAnnotations); 56049 textContentPromises.push(this.extractTextContent({ 56050 handler, 56051 task, 56052 includeMarkedContent: false, 56053 disableNormalization: false, 56054 sink: null, 56055 viewBox: this.view, 56056 lang: null, 56057 intersector 56058 }).then(() => { 56059 intersector.setText(); 56060 })); 56061 } 56062 await Promise.all(textContentPromises); 56063 return annotationsData; 56064 } 56065 get annotations() { 56066 const annots = this.#getInheritableProperty("Annots"); 56067 return shadow(this, "annotations", Array.isArray(annots) ? annots : []); 56068 } 56069 get _parsedAnnotations() { 56070 const promise = this.pdfManager.ensure(this, "annotations").then(async annots => { 56071 if (annots.length === 0) { 56072 return annots; 56073 } 56074 const [annotationGlobals, fieldObjects] = await Promise.all([this.pdfManager.ensureDoc("annotationGlobals"), this.pdfManager.ensureDoc("fieldObjects")]); 56075 if (!annotationGlobals) { 56076 return []; 56077 } 56078 const orphanFields = fieldObjects?.orphanFields; 56079 const annotationPromises = []; 56080 for (const annotationRef of annots) { 56081 annotationPromises.push(AnnotationFactory.create(this.xref, annotationRef, annotationGlobals, this._localIdFactory, false, orphanFields, null, this.ref).catch(function (reason) { 56082 warn(`_parsedAnnotations: "${reason}".`); 56083 return null; 56084 })); 56085 } 56086 const sortedAnnotations = []; 56087 let popupAnnotations, widgetAnnotations; 56088 for (const annotation of await Promise.all(annotationPromises)) { 56089 if (!annotation) { 56090 continue; 56091 } 56092 if (annotation instanceof WidgetAnnotation) { 56093 (widgetAnnotations ||= []).push(annotation); 56094 continue; 56095 } 56096 if (annotation instanceof PopupAnnotation) { 56097 (popupAnnotations ||= []).push(annotation); 56098 continue; 56099 } 56100 sortedAnnotations.push(annotation); 56101 } 56102 if (widgetAnnotations) { 56103 sortedAnnotations.push(...widgetAnnotations); 56104 } 56105 if (popupAnnotations) { 56106 sortedAnnotations.push(...popupAnnotations); 56107 } 56108 return sortedAnnotations; 56109 }); 56110 this.#areAnnotationsCached = true; 56111 return shadow(this, "_parsedAnnotations", promise); 56112 } 56113 get jsActions() { 56114 const actions = collectActions(this.xref, this.pageDict, PageActionEventType); 56115 return shadow(this, "jsActions", actions); 56116 } 56117 async collectAnnotationsByType(handler, task, types, promises, annotationGlobals) { 56118 const { 56119 pageIndex 56120 } = this; 56121 if (this.#areAnnotationsCached) { 56122 const cachedAnnotations = await this._parsedAnnotations; 56123 for (const { 56124 data 56125 } of cachedAnnotations) { 56126 if (!types || types.has(data.annotationType)) { 56127 data.pageIndex = pageIndex; 56128 promises.push(Promise.resolve(data)); 56129 } 56130 } 56131 return; 56132 } 56133 const annots = await this.pdfManager.ensure(this, "annotations"); 56134 for (const annotationRef of annots) { 56135 promises.push(AnnotationFactory.create(this.xref, annotationRef, annotationGlobals, this._localIdFactory, false, null, types, this.ref).then(async annotation => { 56136 if (!annotation) { 56137 return null; 56138 } 56139 annotation.data.pageIndex = pageIndex; 56140 if (annotation.hasTextContent && annotation.viewable) { 56141 const partialEvaluator = this.#createPartialEvaluator(handler); 56142 await annotation.extractTextContent(partialEvaluator, task, [-Infinity, -Infinity, Infinity, Infinity]); 56143 } 56144 return annotation.data; 56145 }).catch(function (reason) { 56146 warn(`collectAnnotationsByType: "${reason}".`); 56147 return null; 56148 })); 56149 } 56150 } 56151} 56152const PDF_HEADER_SIGNATURE = new Uint8Array([0x25, 0x50, 0x44, 0x46, 0x2d]); 56153const STARTXREF_SIGNATURE = new Uint8Array([0x73, 0x74, 0x61, 0x72, 0x74, 0x78, 0x72, 0x65, 0x66]); 56154const ENDOBJ_SIGNATURE = new Uint8Array([0x65, 0x6e, 0x64, 0x6f, 0x62, 0x6a]); 56155function find(stream, signature, limit = 1024, backwards = false) { 56156 const signatureLength = signature.length; 56157 const scanBytes = stream.peekBytes(limit); 56158 const scanLength = scanBytes.length - signatureLength; 56159 if (scanLength <= 0) { 56160 return false; 56161 } 56162 if (backwards) { 56163 const signatureEnd = signatureLength - 1; 56164 let pos = scanBytes.length - 1; 56165 while (pos >= signatureEnd) { 56166 let j = 0; 56167 while (j < signatureLength && scanBytes[pos - j] === signature[signatureEnd - j]) { 56168 j++; 56169 } 56170 if (j >= signatureLength) { 56171 stream.pos += pos - signatureEnd; 56172 return true; 56173 } 56174 pos--; 56175 } 56176 } else { 56177 let pos = 0; 56178 while (pos <= scanLength) { 56179 let j = 0; 56180 while (j < signatureLength && scanBytes[pos + j] === signature[j]) { 56181 j++; 56182 } 56183 if (j >= signatureLength) { 56184 stream.pos += pos; 56185 return true; 56186 } 56187 pos++; 56188 } 56189 } 56190 return false; 56191} 56192class PDFDocument { 56193 #pagePromises = new Map(); 56194 #version = null; 56195 constructor(pdfManager, stream) { 56196 if (stream.length <= 0) { 56197 throw new InvalidPDFException("The PDF file is empty, i.e. its size is zero bytes."); 56198 } 56199 this.pdfManager = pdfManager; 56200 this.stream = stream; 56201 this.xref = new XRef(stream, pdfManager); 56202 const idCounters = { 56203 font: 0 56204 }; 56205 this._globalIdFactory = class { 56206 static getDocId() { 56207 return `g_${pdfManager.docId}`; 56208 } 56209 static createFontId() { 56210 return `f${++idCounters.font}`; 56211 } 56212 static createObjId() { 56213 unreachable("Abstract method `createObjId` called."); 56214 } 56215 static getPageObjId() { 56216 unreachable("Abstract method `getPageObjId` called."); 56217 } 56218 }; 56219 } 56220 parse(recoveryMode) { 56221 this.xref.parse(recoveryMode); 56222 this.catalog = new Catalog(this.pdfManager, this.xref); 56223 } 56224 get linearization() { 56225 let linearization = null; 56226 try { 56227 linearization = Linearization.create(this.stream); 56228 } catch (err) { 56229 if (err instanceof MissingDataException) { 56230 throw err; 56231 } 56232 info(err); 56233 } 56234 return shadow(this, "linearization", linearization); 56235 } 56236 get startXRef() { 56237 const stream = this.stream; 56238 let startXRef = 0; 56239 if (this.linearization) { 56240 stream.reset(); 56241 if (find(stream, ENDOBJ_SIGNATURE)) { 56242 stream.skip(6); 56243 let ch = stream.peekByte(); 56244 while (isWhiteSpace(ch)) { 56245 stream.pos++; 56246 ch = stream.peekByte(); 56247 } 56248 startXRef = stream.pos - stream.start; 56249 } 56250 } else { 56251 const step = 1024; 56252 const startXRefLength = STARTXREF_SIGNATURE.length; 56253 let found = false, 56254 pos = stream.end; 56255 while (!found && pos > 0) { 56256 pos -= step - startXRefLength; 56257 if (pos < 0) { 56258 pos = 0; 56259 } 56260 stream.pos = pos; 56261 found = find(stream, STARTXREF_SIGNATURE, step, true); 56262 } 56263 if (found) { 56264 stream.skip(9); 56265 let ch; 56266 do { 56267 ch = stream.getByte(); 56268 } while (isWhiteSpace(ch)); 56269 let str = ""; 56270 while (ch >= 0x20 && ch <= 0x39) { 56271 str += String.fromCharCode(ch); 56272 ch = stream.getByte(); 56273 } 56274 startXRef = parseInt(str, 10); 56275 if (isNaN(startXRef)) { 56276 startXRef = 0; 56277 } 56278 } 56279 } 56280 return shadow(this, "startXRef", startXRef); 56281 } 56282 checkHeader() { 56283 const stream = this.stream; 56284 stream.reset(); 56285 if (!find(stream, PDF_HEADER_SIGNATURE)) { 56286 return; 56287 } 56288 stream.moveStart(); 56289 stream.skip(PDF_HEADER_SIGNATURE.length); 56290 let version = "", 56291 ch; 56292 while ((ch = stream.getByte()) > 0x20 && version.length < 7) { 56293 version += String.fromCharCode(ch); 56294 } 56295 if (PDF_VERSION_REGEXP.test(version)) { 56296 this.#version = version; 56297 } else { 56298 warn(`Invalid PDF header version: ${version}`); 56299 } 56300 } 56301 parseStartXRef() { 56302 this.xref.setStartXRef(this.startXRef); 56303 } 56304 get numPages() { 56305 let num = 0; 56306 if (this.catalog.hasActualNumPages) { 56307 num = this.catalog.numPages; 56308 } else if (this.xfaFactory) { 56309 num = this.xfaFactory.getNumPages(); 56310 } else if (this.linearization) { 56311 num = this.linearization.numPages; 56312 } else { 56313 num = this.catalog.numPages; 56314 } 56315 return shadow(this, "numPages", num); 56316 } 56317 #hasOnlyDocumentSignatures(fields, recursionDepth = 0) { 56318 const RECURSION_LIMIT = 10; 56319 if (!Array.isArray(fields)) { 56320 return false; 56321 } 56322 return fields.every(field => { 56323 field = this.xref.fetchIfRef(field); 56324 if (!(field instanceof Dict)) { 56325 return false; 56326 } 56327 if (field.has("Kids")) { 56328 if (++recursionDepth > RECURSION_LIMIT) { 56329 warn("#hasOnlyDocumentSignatures: maximum recursion depth reached"); 56330 return false; 56331 } 56332 return this.#hasOnlyDocumentSignatures(field.get("Kids"), recursionDepth); 56333 } 56334 const isSignature = isName(field.get("FT"), "Sig"); 56335 const rectangle = field.get("Rect"); 56336 const isInvisible = Array.isArray(rectangle) && rectangle.every(value => value === 0); 56337 return isSignature && isInvisible; 56338 }); 56339 } 56340 #collectSignatureCertificates(fields, collectedSignatureCertificates, visited = new RefSet()) { 56341 if (!Array.isArray(fields)) { 56342 return; 56343 } 56344 for (let field of fields) { 56345 if (field instanceof Ref) { 56346 if (visited.has(field)) { 56347 continue; 56348 } 56349 visited.put(field); 56350 } 56351 field = this.xref.fetchIfRef(field); 56352 if (!(field instanceof Dict)) { 56353 continue; 56354 } 56355 if (field.has("Kids")) { 56356 this.#collectSignatureCertificates(field.get("Kids"), collectedSignatureCertificates, visited); 56357 continue; 56358 } 56359 const isSignature = isName(field.get("FT"), "Sig"); 56360 if (!isSignature) { 56361 continue; 56362 } 56363 const value = field.get("V"); 56364 if (!(value instanceof Dict)) { 56365 continue; 56366 } 56367 const subFilter = value.get("SubFilter"); 56368 if (!(subFilter instanceof Name)) { 56369 continue; 56370 } 56371 collectedSignatureCertificates.add(subFilter.name); 56372 } 56373 } 56374 get _xfaStreams() { 56375 const { 56376 acroForm 56377 } = this.catalog; 56378 if (!acroForm) { 56379 return null; 56380 } 56381 const xfa = acroForm.get("XFA"); 56382 const entries = new Map(["xdp:xdp", "template", "datasets", "config", "connectionSet", "localeSet", "stylesheet", "/xdp:xdp"].map(e => [e, null])); 56383 if (xfa instanceof BaseStream && !xfa.isEmpty) { 56384 entries.set("xdp:xdp", xfa); 56385 return entries; 56386 } 56387 if (!Array.isArray(xfa) || xfa.length === 0) { 56388 return null; 56389 } 56390 for (let i = 0, ii = xfa.length; i < ii; i += 2) { 56391 let name; 56392 if (i === 0) { 56393 name = "xdp:xdp"; 56394 } else if (i === ii - 2) { 56395 name = "/xdp:xdp"; 56396 } else { 56397 name = xfa[i]; 56398 } 56399 if (!entries.has(name)) { 56400 continue; 56401 } 56402 const data = this.xref.fetchIfRef(xfa[i + 1]); 56403 if (!(data instanceof BaseStream) || data.isEmpty) { 56404 continue; 56405 } 56406 entries.set(name, data); 56407 } 56408 return entries; 56409 } 56410 get xfaDatasets() { 56411 const streams = this._xfaStreams; 56412 if (!streams) { 56413 return shadow(this, "xfaDatasets", null); 56414 } 56415 for (const key of ["datasets", "xdp:xdp"]) { 56416 const stream = streams.get(key); 56417 if (!stream) { 56418 continue; 56419 } 56420 try { 56421 const str = stringToUTF8String(stream.getString()); 56422 const data = { 56423 [key]: str 56424 }; 56425 return shadow(this, "xfaDatasets", new DatasetReader(data)); 56426 } catch { 56427 warn("XFA - Invalid utf-8 string."); 56428 break; 56429 } 56430 } 56431 return shadow(this, "xfaDatasets", null); 56432 } 56433 get xfaData() { 56434 const streams = this._xfaStreams; 56435 if (!streams) { 56436 return null; 56437 } 56438 const data = Object.create(null); 56439 for (const [key, stream] of streams) { 56440 if (!stream) { 56441 continue; 56442 } 56443 try { 56444 data[key] = stringToUTF8String(stream.getString()); 56445 } catch { 56446 warn("XFA - Invalid utf-8 string."); 56447 return null; 56448 } 56449 } 56450 return data; 56451 } 56452 get xfaFactory() { 56453 let data; 56454 if (this.pdfManager.enableXfa && this.catalog.needsRendering && this.formInfo.hasXfa && !this.formInfo.hasAcroForm) { 56455 data = this.xfaData; 56456 } 56457 return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null); 56458 } 56459 get isPureXfa() { 56460 return this.xfaFactory ? this.xfaFactory.isValid() : false; 56461 } 56462 get htmlForXfa() { 56463 return this.xfaFactory ? this.xfaFactory.getPages() : null; 56464 } 56465 async #loadXfaImages() { 56466 const xfaImages = await this.pdfManager.ensureCatalog("xfaImages"); 56467 if (!xfaImages) { 56468 return; 56469 } 56470 this.xfaFactory.setImages(xfaImages); 56471 } 56472 async #loadXfaFonts(handler, task) { 56473 const acroForm = await this.pdfManager.ensureCatalog("acroForm"); 56474 if (!acroForm) { 56475 return; 56476 } 56477 const resources = await acroForm.getAsync("DR"); 56478 if (!(resources instanceof Dict)) { 56479 return; 56480 } 56481 await ObjectLoader.load(resources, ["Font"], this.xref); 56482 const fontRes = resources.get("Font"); 56483 if (!(fontRes instanceof Dict)) { 56484 return; 56485 } 56486 const options = Object.assign(Object.create(null), this.pdfManager.evaluatorOptions, { 56487 useSystemFonts: false 56488 }); 56489 const { 56490 builtInCMapCache, 56491 fontCache, 56492 standardFontDataCache 56493 } = this.catalog; 56494 const partialEvaluator = new PartialEvaluator({ 56495 xref: this.xref, 56496 handler, 56497 pageIndex: -1, 56498 idFactory: this._globalIdFactory, 56499 fontCache, 56500 builtInCMapCache, 56501 standardFontDataCache, 56502 options 56503 }); 56504 const operatorList = new OperatorList(); 56505 const pdfFonts = []; 56506 const initialState = { 56507 get font() { 56508 return pdfFonts.at(-1); 56509 }, 56510 set font(font) { 56511 pdfFonts.push(font); 56512 }, 56513 clone() { 56514 return this; 56515 } 56516 }; 56517 const parseFont = (fontName, fallbackFontDict, cssFontInfo) => partialEvaluator.handleSetFont(resources, [Name.get(fontName), 1], null, operatorList, task, initialState, fallbackFontDict, cssFontInfo).catch(reason => { 56518 warn(`loadXfaFonts: "${reason}".`); 56519 return null; 56520 }); 56521 const promises = []; 56522 for (const [fontName, font] of fontRes) { 56523 const descriptor = font.get("FontDescriptor"); 56524 if (!(descriptor instanceof Dict)) { 56525 continue; 56526 } 56527 let fontFamily = descriptor.get("FontFamily"); 56528 fontFamily = fontFamily.replaceAll(/[ ]+(\d)/g, "$1"); 56529 const fontWeight = descriptor.get("FontWeight"); 56530 const italicAngle = -descriptor.get("ItalicAngle"); 56531 const cssFontInfo = { 56532 fontFamily, 56533 fontWeight, 56534 italicAngle 56535 }; 56536 if (!validateCSSFont(cssFontInfo)) { 56537 continue; 56538 } 56539 promises.push(parseFont(fontName, null, cssFontInfo)); 56540 } 56541 await Promise.all(promises); 56542 const missingFonts = this.xfaFactory.setFonts(pdfFonts); 56543 if (!missingFonts) { 56544 return; 56545 } 56546 options.ignoreErrors = true; 56547 promises.length = 0; 56548 pdfFonts.length = 0; 56549 const reallyMissingFonts = new Set(); 56550 for (const missing of missingFonts) { 56551 if (!getXfaFontName(`${missing}-Regular`)) {
vendor: 3,057 bytes, lines 56552-56653
56552 reallyMissingFonts.add(missing); 56553 } 56554 } 56555 if (reallyMissingFonts.size) { 56556 missingFonts.push("PdfJS-Fallback"); 56557 } 56558 for (const missing of missingFonts) { 56559 if (reallyMissingFonts.has(missing)) { 56560 continue; 56561 } 56562 for (const fontInfo of [{ 56563 name: "Regular", 56564 fontWeight: 400, 56565 italicAngle: 0 56566 }, { 56567 name: "Bold", 56568 fontWeight: 700, 56569 italicAngle: 0 56570 }, { 56571 name: "Italic", 56572 fontWeight: 400, 56573 italicAngle: 12 56574 }, { 56575 name: "BoldItalic", 56576 fontWeight: 700, 56577 italicAngle: 12 56578 }]) { 56579 const name = `${missing}-${fontInfo.name}`; 56580 promises.push(parseFont(name, getXfaFontDict(name), { 56581 fontFamily: missing, 56582 fontWeight: fontInfo.fontWeight, 56583 italicAngle: fontInfo.italicAngle 56584 })); 56585 } 56586 } 56587 await Promise.all(promises); 56588 this.xfaFactory.appendFonts(pdfFonts, reallyMissingFonts); 56589 } 56590 loadXfaResources(handler, task) { 56591 return Promise.all([this.#loadXfaFonts(handler, task).catch(() => {}), this.#loadXfaImages()]); 56592 } 56593 serializeXfaData(annotationStorage) { 56594 return this.xfaFactory ? this.xfaFactory.serializeData(annotationStorage) : null; 56595 } 56596 get version() { 56597 return this.catalog.version || this.#version; 56598 } 56599 get formInfo() { 56600 const formInfo = { 56601 hasFields: false, 56602 hasAcroForm: false, 56603 hasXfa: false, 56604 hasSignatures: false 56605 }; 56606 const { 56607 acroForm 56608 } = this.catalog; 56609 if (!acroForm) { 56610 return shadow(this, "formInfo", formInfo); 56611 } 56612 try { 56613 const fields = acroForm.get("Fields"); 56614 const hasFields = Array.isArray(fields) && fields.length > 0; 56615 formInfo.hasFields = hasFields; 56616 const xfa = acroForm.get("XFA"); 56617 formInfo.hasXfa = Array.isArray(xfa) && xfa.length > 0 || xfa instanceof BaseStream && !xfa.isEmpty; 56618 const sigFlags = acroForm.get("SigFlags"); 56619 const hasSignatures = !!(sigFlags & 0x1); 56620 const hasOnlyDocumentSignatures = hasSignatures && this.#hasOnlyDocumentSignatures(fields); 56621 formInfo.hasAcroForm = hasFields && !hasOnlyDocumentSignatures; 56622 formInfo.hasSignatures = hasSignatures; 56623 } catch (ex) { 56624 if (ex instanceof MissingDataException) { 56625 throw ex; 56626 } 56627 warn(`Cannot fetch form information: "${ex}".`); 56628 } 56629 return shadow(this, "formInfo", formInfo); 56630 } 56631 get documentInfo() { 56632 const { 56633 catalog, 56634 formInfo, 56635 xref 56636 } = this; 56637 const docInfo = { 56638 PDFFormatVersion: this.version, 56639 Language: catalog.lang, 56640 EncryptFilterName: xref.encrypt?.filterName ?? null, 56641 IsLinearized: !!this.linearization, 56642 IsAcroFormPresent: formInfo.hasAcroForm, 56643 IsXFAPresent: formInfo.hasXfa, 56644 IsCollectionPresent: !!catalog.collection, 56645 IsSignaturesPresent: formInfo.hasSignatures 56646 }; 56647 let infoDict; 56648 try { 56649 infoDict = xref.trailer.get("Info"); 56650 } catch (err) { 56651 if (err instanceof MissingDataException) { 56652 throw err; 56653 }
vendor: 16,043 bytes, lines 56654-57177
56654 info("The document information dictionary is invalid."); 56655 } 56656 if (!(infoDict instanceof Dict)) { 56657 return shadow(this, "documentInfo", docInfo); 56658 } 56659 for (const [key, value] of infoDict) { 56660 switch (key) { 56661 case "Title": 56662 case "Author": 56663 case "Subject": 56664 case "Keywords": 56665 case "Creator": 56666 case "Producer": 56667 case "CreationDate": 56668 case "ModDate": 56669 if (typeof value === "string") { 56670 docInfo[key] = stringToPDFString(value); 56671 continue; 56672 } 56673 break; 56674 case "Trapped": 56675 if (value instanceof Name) { 56676 docInfo[key] = value; 56677 continue; 56678 } 56679 break; 56680 default: 56681 let customValue; 56682 switch (typeof value) { 56683 case "string": 56684 customValue = stringToPDFString(value); 56685 break; 56686 case "number": 56687 case "boolean": 56688 customValue = value; 56689 break; 56690 default: 56691 if (value instanceof Name) { 56692 customValue = value; 56693 } 56694 break; 56695 } 56696 if (customValue === undefined) { 56697 warn(`Bad value, for custom key "${key}", in Info: ${value}.`); 56698 continue; 56699 } 56700 docInfo.Custom ??= Object.create(null); 56701 docInfo.Custom[key] = customValue; 56702 continue; 56703 } 56704 warn(`Bad value, for key "${key}", in Info: ${value}.`); 56705 } 56706 return shadow(this, "documentInfo", docInfo); 56707 } 56708 get fingerprints() { 56709 const FINGERPRINT_FIRST_BYTES = 1024; 56710 const EMPTY_FINGERPRINT = "\x00".repeat(16); 56711 function validate(data) { 56712 return typeof data === "string" && data.length === 16 && data !== EMPTY_FINGERPRINT; 56713 } 56714 const id = this.xref.trailer.get("ID"); 56715 let hashOriginal, hashModified; 56716 if (Array.isArray(id) && validate(id[0])) { 56717 hashOriginal = stringToBytes(id[0]); 56718 if (id[1] !== id[0] && validate(id[1])) { 56719 hashModified = stringToBytes(id[1]); 56720 } 56721 } else { 56722 hashOriginal = calculateMD5(this.stream.getByteRange(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES); 56723 } 56724 return shadow(this, "fingerprints", [toHexUtil(hashOriginal), hashModified ? toHexUtil(hashModified) : null]); 56725 } 56726 async #getLinearizationPage(pageIndex) { 56727 const { 56728 catalog, 56729 linearization, 56730 xref 56731 } = this; 56732 const ref = Ref.get(linearization.objectNumberFirst, 0); 56733 try { 56734 const obj = await xref.fetchAsync(ref); 56735 if (obj instanceof Dict) { 56736 let type = obj.getRaw("Type"); 56737 if (type instanceof Ref) { 56738 type = await xref.fetchAsync(type); 56739 } 56740 if (isName(type, "Page") || !obj.has("Type") && !obj.has("Kids") && obj.has("Contents")) { 56741 if (!catalog.pageKidsCountCache.has(ref)) { 56742 catalog.pageKidsCountCache.put(ref, 1); 56743 } 56744 if (!catalog.pageIndexCache.has(ref)) { 56745 catalog.pageIndexCache.put(ref, 0); 56746 } 56747 return [obj, ref]; 56748 } 56749 } 56750 throw new FormatError("The Linearization dictionary doesn't point to a valid Page dictionary."); 56751 } catch (reason) { 56752 warn(`_getLinearizationPage: "${reason.message}".`); 56753 return catalog.getPageDict(pageIndex); 56754 } 56755 } 56756 getPage(pageIndex) { 56757 const cachedPromise = this.#pagePromises.get(pageIndex); 56758 if (cachedPromise) { 56759 return cachedPromise; 56760 } 56761 const { 56762 catalog, 56763 linearization, 56764 xfaFactory 56765 } = this; 56766 let promise; 56767 if (xfaFactory) { 56768 promise = Promise.resolve([Dict.empty, null]); 56769 } else if (linearization?.pageFirst === pageIndex) { 56770 promise = this.#getLinearizationPage(pageIndex); 56771 } else { 56772 promise = catalog.getPageDict(pageIndex); 56773 } 56774 promise = promise.then(([pageDict, ref]) => new Page({ 56775 pdfManager: this.pdfManager, 56776 xref: this.xref, 56777 pageIndex, 56778 pageDict, 56779 ref, 56780 globalIdFactory: this._globalIdFactory, 56781 fontCache: catalog.fontCache, 56782 builtInCMapCache: catalog.builtInCMapCache, 56783 standardFontDataCache: catalog.standardFontDataCache, 56784 globalColorSpaceCache: catalog.globalColorSpaceCache, 56785 globalImageCache: catalog.globalImageCache, 56786 systemFontCache: catalog.systemFontCache, 56787 nonBlendModesSet: catalog.nonBlendModesSet, 56788 xfaFactory 56789 })); 56790 this.#pagePromises.set(pageIndex, promise); 56791 return promise; 56792 } 56793 async checkFirstPage(recoveryMode = false) { 56794 if (recoveryMode) { 56795 return; 56796 } 56797 try { 56798 await this.getPage(0); 56799 } catch (reason) { 56800 if (reason instanceof XRefEntryException) { 56801 this.#pagePromises.delete(0); 56802 await this.cleanup(); 56803 throw new XRefParseException(); 56804 } 56805 } 56806 } 56807 async checkLastPage(recoveryMode = false) { 56808 const { 56809 catalog, 56810 pdfManager 56811 } = this; 56812 catalog.setActualNumPages(); 56813 let numPages; 56814 try { 56815 await Promise.all([pdfManager.ensureDoc("xfaFactory"), pdfManager.ensureDoc("linearization"), pdfManager.ensureCatalog("numPages")]); 56816 if (this.xfaFactory) { 56817 return; 56818 } else if (this.linearization) { 56819 numPages = this.linearization.numPages; 56820 } else { 56821 numPages = catalog.numPages; 56822 } 56823 if (!Number.isInteger(numPages)) { 56824 throw new FormatError("Page count is not an integer."); 56825 } else if (numPages <= 1) { 56826 return; 56827 } 56828 await this.getPage(numPages - 1); 56829 } catch (reason) { 56830 this.#pagePromises.delete(numPages - 1); 56831 await this.cleanup(); 56832 if (reason instanceof XRefEntryException && !recoveryMode) { 56833 throw new XRefParseException(); 56834 } 56835 warn(`checkLastPage - invalid /Pages tree /Count: ${numPages}.`); 56836 let pagesTree; 56837 try { 56838 pagesTree = await catalog.getAllPageDicts(recoveryMode); 56839 } catch (reasonAll) { 56840 if (reasonAll instanceof XRefEntryException && !recoveryMode) { 56841 throw new XRefParseException(); 56842 } 56843 catalog.setActualNumPages(1); 56844 return; 56845 } 56846 for (const [pageIndex, [pageDict, ref]] of pagesTree) { 56847 let promise; 56848 if (pageDict instanceof Error) { 56849 promise = Promise.reject(pageDict); 56850 promise.catch(() => {}); 56851 } else { 56852 promise = Promise.resolve(new Page({ 56853 pdfManager, 56854 xref: this.xref, 56855 pageIndex, 56856 pageDict, 56857 ref, 56858 globalIdFactory: this._globalIdFactory, 56859 fontCache: catalog.fontCache, 56860 builtInCMapCache: catalog.builtInCMapCache, 56861 standardFontDataCache: catalog.standardFontDataCache, 56862 globalColorSpaceCache: this.globalColorSpaceCache, 56863 globalImageCache: catalog.globalImageCache, 56864 systemFontCache: catalog.systemFontCache, 56865 nonBlendModesSet: catalog.nonBlendModesSet, 56866 xfaFactory: null 56867 })); 56868 } 56869 this.#pagePromises.set(pageIndex, promise); 56870 } 56871 catalog.setActualNumPages(pagesTree.size); 56872 } 56873 } 56874 async fontFallback(id, handler) { 56875 const { 56876 catalog, 56877 pdfManager 56878 } = this; 56879 for (const translatedFont of await Promise.all(catalog.fontCache)) { 56880 if (translatedFont.loadedName === id) { 56881 translatedFont.fallback(handler, pdfManager.evaluatorOptions); 56882 return; 56883 } 56884 } 56885 } 56886 async cleanup(manuallyTriggered = false) { 56887 return this.catalog ? this.catalog.cleanup(manuallyTriggered) : clearGlobalCaches(); 56888 } 56889 async #collectFieldObjects(name, parentRef, fieldRef, promises, annotationGlobals, visitedRefs, orphanFields) { 56890 const { 56891 xref 56892 } = this; 56893 if (!(fieldRef instanceof Ref) || visitedRefs.has(fieldRef)) { 56894 return; 56895 } 56896 visitedRefs.put(fieldRef); 56897 const field = await xref.fetchAsync(fieldRef); 56898 if (!(field instanceof Dict)) { 56899 return; 56900 } 56901 let subtype = await field.getAsync("Subtype"); 56902 subtype = subtype instanceof Name ? subtype.name : null; 56903 switch (subtype) { 56904 case "Link": 56905 return; 56906 } 56907 if (field.has("T")) { 56908 const partName = stringToPDFString(await field.getAsync("T")); 56909 name = name === "" ? partName : `${name}.${partName}`; 56910 } else { 56911 let obj = field; 56912 while (true) { 56913 obj = obj.getRaw("Parent") || parentRef; 56914 if (obj instanceof Ref) { 56915 if (visitedRefs.has(obj)) { 56916 break; 56917 } 56918 obj = await xref.fetchAsync(obj); 56919 } 56920 if (!(obj instanceof Dict)) { 56921 break; 56922 } 56923 if (obj.has("T")) { 56924 const partName = stringToPDFString(await obj.getAsync("T")); 56925 name = name === "" ? partName : `${name}.${partName}`; 56926 break; 56927 } 56928 } 56929 } 56930 if (parentRef && !field.has("Parent") && isName(field.get("Subtype"), "Widget")) { 56931 orphanFields.put(fieldRef, parentRef); 56932 } 56933 if (!promises.has(name)) { 56934 promises.set(name, []); 56935 } 56936 promises.get(name).push(AnnotationFactory.create(xref, fieldRef, annotationGlobals, null, true, orphanFields, null, null).then(annotation => annotation?.getFieldObject()).catch(function (reason) { 56937 warn(`#collectFieldObjects: "${reason}".`); 56938 return null; 56939 })); 56940 if (!field.has("Kids")) { 56941 return; 56942 } 56943 const kids = await field.getAsync("Kids"); 56944 if (Array.isArray(kids)) { 56945 for (const kid of kids) { 56946 await this.#collectFieldObjects(name, fieldRef, kid, promises, annotationGlobals, visitedRefs, orphanFields); 56947 } 56948 } 56949 } 56950 get fieldObjects() { 56951 const promise = this.pdfManager.ensureDoc("formInfo").then(async formInfo => { 56952 if (!formInfo.hasFields) { 56953 return null; 56954 } 56955 const annotationGlobals = await this.annotationGlobals; 56956 if (!annotationGlobals) { 56957 return null; 56958 } 56959 const { 56960 acroForm 56961 } = annotationGlobals; 56962 const visitedRefs = new RefSet(); 56963 const allFields = Object.create(null); 56964 const fieldPromises = new Map(); 56965 const orphanFields = new RefSetCache(); 56966 for (const fieldRef of acroForm.get("Fields")) { 56967 await this.#collectFieldObjects("", null, fieldRef, fieldPromises, annotationGlobals, visitedRefs, orphanFields); 56968 } 56969 const allPromises = []; 56970 for (const [name, promises] of fieldPromises) { 56971 allPromises.push(Promise.all(promises).then(fields => { 56972 fields = fields.filter(field => !!field); 56973 if (fields.length > 0) { 56974 allFields[name] = fields; 56975 } 56976 })); 56977 } 56978 await Promise.all(allPromises); 56979 return { 56980 allFields: objectSize(allFields) > 0 ? allFields : null, 56981 orphanFields 56982 }; 56983 }); 56984 return shadow(this, "fieldObjects", promise); 56985 } 56986 get hasJSActions() { 56987 const promise = this.pdfManager.ensureDoc("_parseHasJSActions"); 56988 return shadow(this, "hasJSActions", promise); 56989 } 56990 async _parseHasJSActions() { 56991 const [catalogJsActions, fieldObjects] = await Promise.all([this.pdfManager.ensureCatalog("jsActions"), this.pdfManager.ensureDoc("fieldObjects")]); 56992 if (catalogJsActions) { 56993 return true; 56994 } 56995 if (fieldObjects?.allFields) { 56996 return Object.values(fieldObjects.allFields).some(fieldObject => fieldObject.some(object => object.actions !== null)); 56997 } 56998 return false; 56999 } 57000 get calculationOrderIds() { 57001 const calculationOrder = this.catalog.acroForm?.get("CO"); 57002 if (!Array.isArray(calculationOrder) || calculationOrder.length === 0) { 57003 return shadow(this, "calculationOrderIds", null); 57004 } 57005 const ids = []; 57006 for (const id of calculationOrder) { 57007 if (id instanceof Ref) { 57008 ids.push(id.toString()); 57009 } 57010 } 57011 return shadow(this, "calculationOrderIds", ids.length ? ids : null); 57012 } 57013 get annotationGlobals() { 57014 return shadow(this, "annotationGlobals", AnnotationFactory.createGlobals(this.pdfManager)); 57015 } 57016} 57017 57018;// ./src/core/pdf_manager.js 57019 57020 57021 57022 57023 57024 57025 57026 57027 57028 57029function parseDocBaseUrl(url) { 57030 if (url) { 57031 const absoluteUrl = createValidAbsoluteUrl(url); 57032 if (absoluteUrl) { 57033 return absoluteUrl.href; 57034 } 57035 warn(`Invalid absolute docBaseUrl: "${url}".`); 57036 } 57037 return null; 57038} 57039class BasePdfManager { 57040 constructor({ 57041 docBaseUrl, 57042 docId, 57043 enableXfa, 57044 evaluatorOptions, 57045 handler, 57046 password 57047 }) { 57048 this._docBaseUrl = parseDocBaseUrl(docBaseUrl); 57049 this._docId = docId; 57050 this._password = password; 57051 this.enableXfa = enableXfa; 57052 evaluatorOptions.isOffscreenCanvasSupported &&= FeatureTest.isOffscreenCanvasSupported; 57053 evaluatorOptions.isImageDecoderSupported &&= FeatureTest.isImageDecoderSupported; 57054 this.evaluatorOptions = Object.freeze(evaluatorOptions); 57055 ImageResizer.setOptions(evaluatorOptions); 57056 JpegStream.setOptions(evaluatorOptions); 57057 OperatorList.setOptions(evaluatorOptions); 57058 const options = { 57059 ...evaluatorOptions, 57060 handler 57061 }; 57062 JpxImage.setOptions(options); 57063 IccColorSpace.setOptions(options); 57064 CmykICCBasedCS.setOptions(options); 57065 } 57066 get docId() { 57067 return this._docId; 57068 } 57069 get password() { 57070 return this._password; 57071 } 57072 get docBaseUrl() { 57073 return this._docBaseUrl; 57074 } 57075 ensureDoc(prop, args) { 57076 return this.ensure(this.pdfDocument, prop, args); 57077 } 57078 ensureXRef(prop, args) { 57079 return this.ensure(this.pdfDocument.xref, prop, args); 57080 } 57081 ensureCatalog(prop, args) { 57082 return this.ensure(this.pdfDocument.catalog, prop, args); 57083 } 57084 getPage(pageIndex) { 57085 return this.pdfDocument.getPage(pageIndex); 57086 } 57087 fontFallback(id, handler) { 57088 return this.pdfDocument.fontFallback(id, handler); 57089 } 57090 cleanup(manuallyTriggered = false) { 57091 return this.pdfDocument.cleanup(manuallyTriggered); 57092 } 57093 async ensure(obj, prop, args) { 57094 unreachable("Abstract method `ensure` called"); 57095 } 57096 requestRange(begin, end) { 57097 unreachable("Abstract method `requestRange` called"); 57098 } 57099 requestLoadedStream(noFetch = false) { 57100 unreachable("Abstract method `requestLoadedStream` called"); 57101 } 57102 sendProgressiveData(chunk) { 57103 unreachable("Abstract method `sendProgressiveData` called"); 57104 } 57105 updatePassword(password) { 57106 this._password = password; 57107 } 57108 terminate(reason) { 57109 unreachable("Abstract method `terminate` called"); 57110 } 57111} 57112class LocalPdfManager extends BasePdfManager { 57113 constructor(args) { 57114 super(args); 57115 const stream = new Stream(args.source); 57116 this.pdfDocument = new PDFDocument(this, stream); 57117 this._loadedStreamPromise = Promise.resolve(stream); 57118 } 57119 async ensure(obj, prop, args) { 57120 const value = obj[prop]; 57121 if (typeof value === "function") { 57122 return value.apply(obj, args); 57123 } 57124 return value; 57125 } 57126 requestRange(begin, end) { 57127 return Promise.resolve(); 57128 } 57129 requestLoadedStream(noFetch = false) { 57130 return this._loadedStreamPromise; 57131 } 57132 terminate(reason) {} 57133} 57134class NetworkPdfManager extends BasePdfManager { 57135 constructor(args) { 57136 super(args); 57137 this.streamManager = new ChunkedStreamManager(args.source, { 57138 msgHandler: args.handler, 57139 length: args.length, 57140 disableAutoFetch: args.disableAutoFetch, 57141 rangeChunkSize: args.rangeChunkSize 57142 }); 57143 this.pdfDocument = new PDFDocument(this, this.streamManager.getStream()); 57144 } 57145 async ensure(obj, prop, args) { 57146 try { 57147 const value = obj[prop]; 57148 if (typeof value === "function") { 57149 return value.apply(obj, args); 57150 } 57151 return value; 57152 } catch (ex) { 57153 if (!(ex instanceof MissingDataException)) { 57154 throw ex; 57155 } 57156 await this.requestRange(ex.begin, ex.end); 57157 return this.ensure(obj, prop, args); 57158 } 57159 } 57160 requestRange(begin, end) { 57161 return this.streamManager.requestRange(begin, end); 57162 } 57163 requestLoadedStream(noFetch = false) { 57164 return this.streamManager.requestAllChunks(noFetch); 57165 } 57166 sendProgressiveData(chunk) { 57167 this.streamManager.onReceiveData({ 57168 chunk 57169 }); 57170 } 57171 terminate(reason) { 57172 this.streamManager.abort(reason); 57173 } 57174} 57175 57176;// ./src/shared/message_handler.js 57177
vendor: 12,265 bytes, lines 57178-57579
57178const CallbackKind = { 57179 DATA: 1, 57180 ERROR: 2 57181}; 57182const StreamKind = { 57183 CANCEL: 1, 57184 CANCEL_COMPLETE: 2, 57185 CLOSE: 3, 57186 ENQUEUE: 4, 57187 ERROR: 5, 57188 PULL: 6, 57189 PULL_COMPLETE: 7, 57190 START_COMPLETE: 8 57191}; 57192function onFn() {} 57193function wrapReason(ex) { 57194 if (ex instanceof AbortException || ex instanceof InvalidPDFException || ex instanceof PasswordException || ex instanceof ResponseException || ex instanceof UnknownErrorException) { 57195 return ex; 57196 } 57197 if (!(ex instanceof Error || typeof ex === "object" && ex !== null)) { 57198 unreachable('wrapReason: Expected "reason" to be a (possibly cloned) Error.'); 57199 } 57200 switch (ex.name) { 57201 case "AbortException": 57202 return new AbortException(ex.message); 57203 case "InvalidPDFException": 57204 return new InvalidPDFException(ex.message); 57205 case "PasswordException": 57206 return new PasswordException(ex.message, ex.code); 57207 case "ResponseException": 57208 return new ResponseException(ex.message, ex.status, ex.missing); 57209 case "UnknownErrorException": 57210 return new UnknownErrorException(ex.message, ex.details); 57211 } 57212 return new UnknownErrorException(ex.message, ex.toString()); 57213} 57214class MessageHandler { 57215 #messageAC = new AbortController(); 57216 constructor(sourceName, targetName, comObj) { 57217 this.sourceName = sourceName; 57218 this.targetName = targetName; 57219 this.comObj = comObj; 57220 this.callbackId = 1; 57221 this.streamId = 1; 57222 this.streamSinks = Object.create(null); 57223 this.streamControllers = Object.create(null); 57224 this.callbackCapabilities = Object.create(null); 57225 this.actionHandler = Object.create(null); 57226 comObj.addEventListener("message", this.#onMessage.bind(this), { 57227 signal: this.#messageAC.signal 57228 }); 57229 } 57230 #onMessage({ 57231 data 57232 }) { 57233 if (data.targetName !== this.sourceName) { 57234 return; 57235 } 57236 if (data.stream) { 57237 this.#processStreamMessage(data); 57238 return; 57239 } 57240 if (data.callback) { 57241 const callbackId = data.callbackId; 57242 const capability = this.callbackCapabilities[callbackId]; 57243 if (!capability) { 57244 throw new Error(`Cannot resolve callback ${callbackId}`); 57245 } 57246 delete this.callbackCapabilities[callbackId]; 57247 if (data.callback === CallbackKind.DATA) { 57248 capability.resolve(data.data); 57249 } else if (data.callback === CallbackKind.ERROR) { 57250 capability.reject(wrapReason(data.reason)); 57251 } else { 57252 throw new Error("Unexpected callback case"); 57253 } 57254 return; 57255 } 57256 const action = this.actionHandler[data.action]; 57257 if (!action) { 57258 throw new Error(`Unknown action from worker: ${data.action}`); 57259 } 57260 if (data.callbackId) { 57261 const sourceName = this.sourceName, 57262 targetName = data.sourceName, 57263 comObj = this.comObj; 57264 Promise.try(action, data.data).then(function (result) { 57265 comObj.postMessage({ 57266 sourceName, 57267 targetName, 57268 callback: CallbackKind.DATA, 57269 callbackId: data.callbackId, 57270 data: result 57271 }); 57272 }, function (reason) { 57273 comObj.postMessage({ 57274 sourceName, 57275 targetName, 57276 callback: CallbackKind.ERROR, 57277 callbackId: data.callbackId, 57278 reason: wrapReason(reason) 57279 }); 57280 }); 57281 return; 57282 } 57283 if (data.streamId) { 57284 this.#createStreamSink(data); 57285 return; 57286 } 57287 action(data.data); 57288 } 57289 on(actionName, handler) { 57290 const ah = this.actionHandler; 57291 if (ah[actionName]) { 57292 throw new Error(`There is already an actionName called "${actionName}"`); 57293 } 57294 ah[actionName] = handler; 57295 } 57296 send(actionName, data, transfers) { 57297 this.comObj.postMessage({ 57298 sourceName: this.sourceName, 57299 targetName: this.targetName, 57300 action: actionName, 57301 data 57302 }, transfers); 57303 } 57304 sendWithPromise(actionName, data, transfers) { 57305 const callbackId = this.callbackId++; 57306 const capability = Promise.withResolvers(); 57307 this.callbackCapabilities[callbackId] = capability; 57308 try { 57309 this.comObj.postMessage({ 57310 sourceName: this.sourceName, 57311 targetName: this.targetName, 57312 action: actionName, 57313 callbackId, 57314 data 57315 }, transfers); 57316 } catch (ex) { 57317 capability.reject(ex); 57318 } 57319 return capability.promise; 57320 } 57321 sendWithStream(actionName, data, queueingStrategy, transfers) { 57322 const streamId = this.streamId++, 57323 sourceName = this.sourceName, 57324 targetName = this.targetName, 57325 comObj = this.comObj; 57326 return new ReadableStream({ 57327 start: controller => { 57328 const startCapability = Promise.withResolvers(); 57329 this.streamControllers[streamId] = { 57330 controller, 57331 startCall: startCapability, 57332 pullCall: null, 57333 cancelCall: null, 57334 isClosed: false 57335 }; 57336 comObj.postMessage({ 57337 sourceName, 57338 targetName, 57339 action: actionName, 57340 streamId, 57341 data, 57342 desiredSize: controller.desiredSize 57343 }, transfers); 57344 return startCapability.promise; 57345 }, 57346 pull: controller => { 57347 const pullCapability = Promise.withResolvers(); 57348 this.streamControllers[streamId].pullCall = pullCapability; 57349 comObj.postMessage({ 57350 sourceName, 57351 targetName, 57352 stream: StreamKind.PULL, 57353 streamId, 57354 desiredSize: controller.desiredSize 57355 }); 57356 return pullCapability.promise; 57357 }, 57358 cancel: reason => { 57359 assert(reason instanceof Error, "cancel must have a valid reason"); 57360 const cancelCapability = Promise.withResolvers(); 57361 this.streamControllers[streamId].cancelCall = cancelCapability; 57362 this.streamControllers[streamId].isClosed = true; 57363 comObj.postMessage({ 57364 sourceName, 57365 targetName, 57366 stream: StreamKind.CANCEL, 57367 streamId, 57368 reason: wrapReason(reason) 57369 }); 57370 return cancelCapability.promise; 57371 } 57372 }, queueingStrategy); 57373 } 57374 #createStreamSink(data) { 57375 const streamId = data.streamId, 57376 sourceName = this.sourceName, 57377 targetName = data.sourceName, 57378 comObj = this.comObj; 57379 const self = this, 57380 action = this.actionHandler[data.action]; 57381 const streamSink = { 57382 enqueue(chunk, size = 1, transfers) { 57383 if (this.isCancelled) { 57384 return; 57385 } 57386 const lastDesiredSize = this.desiredSize; 57387 this.desiredSize -= size; 57388 if (lastDesiredSize > 0 && this.desiredSize <= 0) { 57389 this.sinkCapability = Promise.withResolvers(); 57390 this.ready = this.sinkCapability.promise; 57391 } 57392 comObj.postMessage({ 57393 sourceName, 57394 targetName, 57395 stream: StreamKind.ENQUEUE, 57396 streamId, 57397 chunk 57398 }, transfers); 57399 }, 57400 close() { 57401 if (this.isCancelled) { 57402 return; 57403 } 57404 this.isCancelled = true; 57405 comObj.postMessage({ 57406 sourceName, 57407 targetName, 57408 stream: StreamKind.CLOSE, 57409 streamId 57410 }); 57411 delete self.streamSinks[streamId]; 57412 }, 57413 error(reason) { 57414 assert(reason instanceof Error, "error must have a valid reason"); 57415 if (this.isCancelled) { 57416 return; 57417 } 57418 this.isCancelled = true; 57419 comObj.postMessage({ 57420 sourceName, 57421 targetName, 57422 stream: StreamKind.ERROR, 57423 streamId, 57424 reason: wrapReason(reason) 57425 }); 57426 }, 57427 sinkCapability: Promise.withResolvers(), 57428 onPull: null, 57429 onCancel: null, 57430 isCancelled: false, 57431 desiredSize: data.desiredSize, 57432 ready: null 57433 }; 57434 streamSink.sinkCapability.resolve(); 57435 streamSink.ready = streamSink.sinkCapability.promise; 57436 this.streamSinks[streamId] = streamSink; 57437 Promise.try(action, data.data, streamSink).then(function () { 57438 comObj.postMessage({ 57439 sourceName, 57440 targetName, 57441 stream: StreamKind.START_COMPLETE, 57442 streamId, 57443 success: true 57444 }); 57445 }, function (reason) { 57446 comObj.postMessage({ 57447 sourceName, 57448 targetName, 57449 stream: StreamKind.START_COMPLETE, 57450 streamId, 57451 reason: wrapReason(reason) 57452 }); 57453 }); 57454 } 57455 #processStreamMessage(data) { 57456 const streamId = data.streamId, 57457 sourceName = this.sourceName, 57458 targetName = data.sourceName, 57459 comObj = this.comObj; 57460 const streamController = this.streamControllers[streamId], 57461 streamSink = this.streamSinks[streamId]; 57462 switch (data.stream) { 57463 case StreamKind.START_COMPLETE: 57464 if (data.success) { 57465 streamController.startCall.resolve(); 57466 } else { 57467 streamController.startCall.reject(wrapReason(data.reason)); 57468 } 57469 break; 57470 case StreamKind.PULL_COMPLETE: 57471 if (data.success) { 57472 streamController.pullCall.resolve(); 57473 } else { 57474 streamController.pullCall.reject(wrapReason(data.reason)); 57475 } 57476 break; 57477 case StreamKind.PULL: 57478 if (!streamSink) { 57479 comObj.postMessage({ 57480 sourceName, 57481 targetName, 57482 stream: StreamKind.PULL_COMPLETE, 57483 streamId, 57484 success: true 57485 }); 57486 break; 57487 } 57488 if (streamSink.desiredSize <= 0 && data.desiredSize > 0) { 57489 streamSink.sinkCapability.resolve(); 57490 } 57491 streamSink.desiredSize = data.desiredSize; 57492 Promise.try(streamSink.onPull || onFn).then(function () { 57493 comObj.postMessage({ 57494 sourceName, 57495 targetName, 57496 stream: StreamKind.PULL_COMPLETE, 57497 streamId, 57498 success: true 57499 }); 57500 }, function (reason) { 57501 comObj.postMessage({ 57502 sourceName, 57503 targetName, 57504 stream: StreamKind.PULL_COMPLETE, 57505 streamId, 57506 reason: wrapReason(reason) 57507 }); 57508 }); 57509 break; 57510 case StreamKind.ENQUEUE: 57511 assert(streamController, "enqueue should have stream controller"); 57512 if (streamController.isClosed) { 57513 break; 57514 } 57515 streamController.controller.enqueue(data.chunk); 57516 break; 57517 case StreamKind.CLOSE: 57518 assert(streamController, "close should have stream controller"); 57519 if (streamController.isClosed) { 57520 break; 57521 } 57522 streamController.isClosed = true; 57523 streamController.controller.close(); 57524 this.#deleteStreamController(streamController, streamId); 57525 break; 57526 case StreamKind.ERROR: 57527 assert(streamController, "error should have stream controller"); 57528 streamController.controller.error(wrapReason(data.reason)); 57529 this.#deleteStreamController(streamController, streamId); 57530 break; 57531 case StreamKind.CANCEL_COMPLETE: 57532 if (data.success) { 57533 streamController.cancelCall.resolve(); 57534 } else { 57535 streamController.cancelCall.reject(wrapReason(data.reason)); 57536 } 57537 this.#deleteStreamController(streamController, streamId); 57538 break; 57539 case StreamKind.CANCEL: 57540 if (!streamSink) { 57541 break; 57542 } 57543 const dataReason = wrapReason(data.reason); 57544 Promise.try(streamSink.onCancel || onFn, dataReason).then(function () { 57545 comObj.postMessage({ 57546 sourceName, 57547 targetName, 57548 stream: StreamKind.CANCEL_COMPLETE, 57549 streamId, 57550 success: true 57551 }); 57552 }, function (reason) { 57553 comObj.postMessage({ 57554 sourceName, 57555 targetName, 57556 stream: StreamKind.CANCEL_COMPLETE, 57557 streamId, 57558 reason: wrapReason(reason) 57559 }); 57560 }); 57561 streamSink.sinkCapability.reject(dataReason); 57562 streamSink.isCancelled = true; 57563 delete this.streamSinks[streamId]; 57564 break; 57565 default: 57566 throw new Error("Unexpected stream case"); 57567 } 57568 } 57569 async #deleteStreamController(streamController, streamId) { 57570 await Promise.allSettled([streamController.startCall?.promise, streamController.pullCall?.promise, streamController.cancelCall?.promise]); 57571 delete this.streamControllers[streamId]; 57572 } 57573 destroy() { 57574 this.#messageAC?.abort(); 57575 this.#messageAC = null; 57576 } 57577} 57578 57579;// ./src/core/writer.js
vendor: 11,907 bytes, lines 57579-57987
57579 57580 57581 57582 57583 57584 57585 57586 57587async function writeObject(ref, obj, buffer, { 57588 encrypt = null 57589}) { 57590 const transform = encrypt?.createCipherTransform(ref.num, ref.gen); 57591 buffer.push(`${ref.num} ${ref.gen} obj\n`); 57592 if (obj instanceof Dict) { 57593 await writeDict(obj, buffer, transform); 57594 } else if (obj instanceof BaseStream) { 57595 await writeStream(obj, buffer, transform); 57596 } else if (Array.isArray(obj) || ArrayBuffer.isView(obj)) { 57597 await writeArray(obj, buffer, transform); 57598 } 57599 buffer.push("\nendobj\n"); 57600} 57601async function writeDict(dict, buffer, transform) { 57602 buffer.push("<<"); 57603 for (const key of dict.getKeys()) { 57604 buffer.push(` /${escapePDFName(key)} `); 57605 await writeValue(dict.getRaw(key), buffer, transform); 57606 } 57607 buffer.push(">>"); 57608} 57609async function writeStream(stream, buffer, transform) { 57610 let bytes = stream.getBytes(); 57611 const { 57612 dict 57613 } = stream; 57614 const [filter, params] = await Promise.all([dict.getAsync("Filter"), dict.getAsync("DecodeParms")]); 57615 const filterZero = Array.isArray(filter) ? await dict.xref.fetchIfRefAsync(filter[0]) : filter; 57616 const isFilterZeroFlateDecode = isName(filterZero, "FlateDecode"); 57617 const MIN_LENGTH_FOR_COMPRESSING = 256; 57618 if (bytes.length >= MIN_LENGTH_FOR_COMPRESSING || isFilterZeroFlateDecode) { 57619 try { 57620 const cs = new CompressionStream("deflate"); 57621 const writer = cs.writable.getWriter(); 57622 await writer.ready; 57623 writer.write(bytes).then(async () => { 57624 await writer.ready; 57625 await writer.close(); 57626 }).catch(() => {}); 57627 const buf = await new Response(cs.readable).arrayBuffer(); 57628 bytes = new Uint8Array(buf); 57629 let newFilter, newParams; 57630 if (!filter) { 57631 newFilter = Name.get("FlateDecode"); 57632 } else if (!isFilterZeroFlateDecode) { 57633 newFilter = Array.isArray(filter) ? [Name.get("FlateDecode"), ...filter] : [Name.get("FlateDecode"), filter]; 57634 if (params) { 57635 newParams = Array.isArray(params) ? [null, ...params] : [null, params]; 57636 } 57637 } 57638 if (newFilter) { 57639 dict.set("Filter", newFilter); 57640 } 57641 if (newParams) { 57642 dict.set("DecodeParms", newParams); 57643 } 57644 } catch (ex) { 57645 info(`writeStream - cannot compress data: "${ex}".`); 57646 } 57647 } 57648 let string = bytesToString(bytes); 57649 if (transform) { 57650 string = transform.encryptString(string); 57651 } 57652 dict.set("Length", string.length); 57653 await writeDict(dict, buffer, transform); 57654 buffer.push(" stream\n", string, "\nendstream"); 57655} 57656async function writeArray(array, buffer, transform) { 57657 buffer.push("["); 57658 let first = true; 57659 for (const val of array) { 57660 if (!first) { 57661 buffer.push(" "); 57662 } else { 57663 first = false; 57664 } 57665 await writeValue(val, buffer, transform); 57666 } 57667 buffer.push("]"); 57668} 57669async function writeValue(value, buffer, transform) { 57670 if (value instanceof Name) { 57671 buffer.push(`/${escapePDFName(value.name)}`); 57672 } else if (value instanceof Ref) { 57673 buffer.push(`${value.num} ${value.gen} R`); 57674 } else if (Array.isArray(value) || ArrayBuffer.isView(value)) { 57675 await writeArray(value, buffer, transform); 57676 } else if (typeof value === "string") { 57677 if (transform) { 57678 value = transform.encryptString(value); 57679 } 57680 buffer.push(`(${escapeString(value)})`); 57681 } else if (typeof value === "number") { 57682 buffer.push(numberToString(value)); 57683 } else if (typeof value === "boolean") { 57684 buffer.push(value.toString()); 57685 } else if (value instanceof Dict) { 57686 await writeDict(value, buffer, transform); 57687 } else if (value instanceof BaseStream) { 57688 await writeStream(value, buffer, transform); 57689 } else if (value === null) { 57690 buffer.push("null"); 57691 } else { 57692 warn(`Unhandled value in writer: ${typeof value}, please file a bug.`); 57693 } 57694} 57695function writeInt(number, size, offset, buffer) { 57696 for (let i = size + offset - 1; i > offset - 1; i--) { 57697 buffer[i] = number & 0xff; 57698 number >>= 8; 57699 } 57700 return offset + size; 57701} 57702function writeString(string, offset, buffer) { 57703 const ii = string.length; 57704 for (let i = 0; i < ii; i++) { 57705 buffer[offset + i] = string.charCodeAt(i) & 0xff; 57706 } 57707 return offset + ii; 57708} 57709function computeMD5(filesize, xrefInfo) { 57710 const time = Math.floor(Date.now() / 1000); 57711 const filename = xrefInfo.filename || ""; 57712 const md5Buffer = [time.toString(), filename, filesize.toString(), ...xrefInfo.infoMap.values()]; 57713 const md5BufferLen = Math.sumPrecise(md5Buffer.map(str => str.length)); 57714 const array = new Uint8Array(md5BufferLen); 57715 let offset = 0; 57716 for (const str of md5Buffer) { 57717 offset = writeString(str, offset, array); 57718 } 57719 return bytesToString(calculateMD5(array, 0, array.length)); 57720} 57721function writeXFADataForAcroform(str, changes) { 57722 const xml = new SimpleXMLParser({ 57723 hasAttributes: true 57724 }).parseFromString(str); 57725 for (const { 57726 xfa 57727 } of changes) { 57728 if (!xfa) { 57729 continue; 57730 } 57731 const { 57732 path, 57733 value 57734 } = xfa; 57735 if (!path) { 57736 continue; 57737 } 57738 const nodePath = parseXFAPath(path); 57739 let node = xml.documentElement.searchNode(nodePath, 0); 57740 if (!node && nodePath.length > 1) { 57741 node = xml.documentElement.searchNode([nodePath.at(-1)], 0); 57742 } 57743 if (node) { 57744 node.childNodes = Array.isArray(value) ? value.map(val => new SimpleDOMNode("value", val)) : [new SimpleDOMNode("#text", value)]; 57745 } else { 57746 warn(`Node not found for path: ${path}`); 57747 } 57748 } 57749 const buffer = []; 57750 xml.documentElement.dump(buffer); 57751 return buffer.join(""); 57752} 57753async function updateAcroform({ 57754 xref, 57755 acroForm, 57756 acroFormRef, 57757 hasXfa, 57758 hasXfaDatasetsEntry, 57759 xfaDatasetsRef, 57760 needAppearances, 57761 changes 57762}) { 57763 if (hasXfa && !hasXfaDatasetsEntry && !xfaDatasetsRef) { 57764 warn("XFA - Cannot save it"); 57765 } 57766 if (!needAppearances && (!hasXfa || !xfaDatasetsRef || hasXfaDatasetsEntry)) { 57767 return; 57768 } 57769 const dict = acroForm.clone(); 57770 if (hasXfa && !hasXfaDatasetsEntry) { 57771 const newXfa = acroForm.get("XFA").slice(); 57772 newXfa.splice(2, 0, "datasets"); 57773 newXfa.splice(3, 0, xfaDatasetsRef); 57774 dict.set("XFA", newXfa); 57775 } 57776 if (needAppearances) { 57777 dict.set("NeedAppearances", true); 57778 } 57779 changes.put(acroFormRef, { 57780 data: dict 57781 }); 57782} 57783function updateXFA({ 57784 xfaData, 57785 xfaDatasetsRef, 57786 changes, 57787 xref 57788}) { 57789 if (xfaData === null) { 57790 const datasets = xref.fetchIfRef(xfaDatasetsRef); 57791 xfaData = writeXFADataForAcroform(datasets.getString(), changes); 57792 } 57793 const xfaDataStream = new StringStream(xfaData); 57794 xfaDataStream.dict = new Dict(xref); 57795 xfaDataStream.dict.setIfName("Type", "EmbeddedFile"); 57796 changes.put(xfaDatasetsRef, { 57797 data: xfaDataStream 57798 }); 57799} 57800async function getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer) { 57801 buffer.push("xref\n"); 57802 const indexes = getIndexes(newRefs); 57803 let indexesPosition = 0; 57804 for (const { 57805 ref, 57806 data 57807 } of newRefs) { 57808 if (ref.num === indexes[indexesPosition]) { 57809 buffer.push(`${indexes[indexesPosition]} ${indexes[indexesPosition + 1]}\n`); 57810 indexesPosition += 2; 57811 } 57812 if (data !== null) { 57813 buffer.push(`${baseOffset.toString().padStart(10, "0")} ${Math.min(ref.gen, 0xffff).toString().padStart(5, "0")} n\r\n`); 57814 baseOffset += data.length; 57815 } else { 57816 buffer.push(`0000000000 ${Math.min(ref.gen + 1, 0xffff).toString().padStart(5, "0")} f\r\n`); 57817 } 57818 } 57819 computeIDs(baseOffset, xrefInfo, newXref); 57820 buffer.push("trailer\n"); 57821 await writeDict(newXref, buffer); 57822 buffer.push("\nstartxref\n", baseOffset.toString(), "\n%%EOF\n"); 57823} 57824function getIndexes(newRefs) { 57825 const indexes = []; 57826 for (const { 57827 ref 57828 } of newRefs) { 57829 if (ref.num === indexes.at(-2) + indexes.at(-1)) { 57830 indexes[indexes.length - 1] += 1; 57831 } else { 57832 indexes.push(ref.num, 1); 57833 } 57834 } 57835 return indexes; 57836} 57837async function getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) { 57838 const xrefTableData = []; 57839 let maxOffset = 0; 57840 let maxGen = 0; 57841 for (const { 57842 ref, 57843 data 57844 } of newRefs) { 57845 let gen; 57846 maxOffset = Math.max(maxOffset, baseOffset); 57847 if (data !== null) { 57848 gen = Math.min(ref.gen, 0xffff); 57849 xrefTableData.push([1, baseOffset, gen]); 57850 baseOffset += data.length; 57851 } else { 57852 gen = Math.min(ref.gen + 1, 0xffff); 57853 xrefTableData.push([0, 0, gen]); 57854 } 57855 maxGen = Math.max(maxGen, gen); 57856 } 57857 newXref.set("Index", getIndexes(newRefs)); 57858 const offsetSize = getSizeInBytes(maxOffset); 57859 const maxGenSize = getSizeInBytes(maxGen); 57860 const sizes = [1, offsetSize, maxGenSize]; 57861 newXref.set("W", sizes); 57862 computeIDs(baseOffset, xrefInfo, newXref); 57863 const structSize = Math.sumPrecise(sizes); 57864 const data = new Uint8Array(structSize * xrefTableData.length); 57865 const stream = new Stream(data); 57866 stream.dict = newXref; 57867 let offset = 0; 57868 for (const [type, objOffset, gen] of xrefTableData) { 57869 offset = writeInt(type, sizes[0], offset, data); 57870 offset = writeInt(objOffset, sizes[1], offset, data); 57871 offset = writeInt(gen, sizes[2], offset, data); 57872 } 57873 await writeObject(xrefInfo.newRef, stream, buffer, {}); 57874 buffer.push("startxref\n", baseOffset.toString(), "\n%%EOF\n"); 57875} 57876function computeIDs(baseOffset, xrefInfo, newXref) { 57877 if (Array.isArray(xrefInfo.fileIds) && xrefInfo.fileIds.length > 0) { 57878 const md5 = computeMD5(baseOffset, xrefInfo); 57879 newXref.set("ID", [xrefInfo.fileIds[0], md5]); 57880 } 57881} 57882function getTrailerDict(xrefInfo, changes, useXrefStream) { 57883 const newXref = new Dict(null); 57884 newXref.set("Prev", xrefInfo.startXRef); 57885 const refForXrefTable = xrefInfo.newRef; 57886 if (useXrefStream) { 57887 changes.put(refForXrefTable, { 57888 data: "" 57889 }); 57890 newXref.set("Size", refForXrefTable.num + 1); 57891 newXref.setIfName("Type", "XRef"); 57892 } else { 57893 newXref.set("Size", refForXrefTable.num); 57894 } 57895 if (xrefInfo.rootRef !== null) { 57896 newXref.set("Root", xrefInfo.rootRef); 57897 } 57898 if (xrefInfo.infoRef !== null) { 57899 newXref.set("Info", xrefInfo.infoRef); 57900 } 57901 if (xrefInfo.encryptRef !== null) { 57902 newXref.set("Encrypt", xrefInfo.encryptRef); 57903 } 57904 return newXref; 57905} 57906async function writeChanges(changes, xref, buffer = []) { 57907 const newRefs = []; 57908 for (const [ref, { 57909 data 57910 }] of changes.items()) { 57911 if (data === null || typeof data === "string") { 57912 newRefs.push({ 57913 ref, 57914 data 57915 }); 57916 continue; 57917 } 57918 await writeObject(ref, data, buffer, xref); 57919 newRefs.push({ 57920 ref, 57921 data: buffer.join("") 57922 }); 57923 buffer.length = 0; 57924 } 57925 return newRefs.sort((a, b) => a.ref.num - b.ref.num); 57926} 57927async function incrementalUpdate({ 57928 originalData, 57929 xrefInfo, 57930 changes, 57931 xref = null, 57932 hasXfa = false, 57933 xfaDatasetsRef = null, 57934 hasXfaDatasetsEntry = false, 57935 needAppearances, 57936 acroFormRef = null, 57937 acroForm = null, 57938 xfaData = null, 57939 useXrefStream = false 57940}) { 57941 await updateAcroform({ 57942 xref, 57943 acroForm, 57944 acroFormRef, 57945 hasXfa, 57946 hasXfaDatasetsEntry, 57947 xfaDatasetsRef, 57948 needAppearances, 57949 changes 57950 }); 57951 if (hasXfa) { 57952 updateXFA({ 57953 xfaData, 57954 xfaDatasetsRef, 57955 changes, 57956 xref 57957 }); 57958 } 57959 const newXref = getTrailerDict(xrefInfo, changes, useXrefStream); 57960 const buffer = []; 57961 const newRefs = await writeChanges(changes, xref, buffer); 57962 let baseOffset = originalData.length; 57963 const lastByte = originalData.at(-1); 57964 if (lastByte !== 0x0a && lastByte !== 0x0d) { 57965 buffer.push("\n"); 57966 baseOffset += 1; 57967 } 57968 for (const { 57969 data 57970 } of newRefs) { 57971 if (data !== null) { 57972 buffer.push(data); 57973 } 57974 } 57975 await (useXrefStream ? getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) : getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer)); 57976 const totalLength = originalData.length + Math.sumPrecise(buffer.map(str => str.length)); 57977 const array = new Uint8Array(totalLength); 57978 array.set(originalData); 57979 let offset = originalData.length; 57980 for (const str of buffer) { 57981 offset = writeString(str, offset, array); 57982 } 57983 return array; 57984} 57985 57986;// ./src/core/worker_stream.js 57987
vendor: 2,316 bytes, lines 57988-58070
57988class PDFWorkerStream { 57989 constructor(msgHandler) { 57990 this._msgHandler = msgHandler; 57991 this._contentLength = null; 57992 this._fullRequestReader = null; 57993 this._rangeRequestReaders = []; 57994 } 57995 getFullReader() { 57996 assert(!this._fullRequestReader, "PDFWorkerStream.getFullReader can only be called once."); 57997 this._fullRequestReader = new PDFWorkerStreamReader(this._msgHandler); 57998 return this._fullRequestReader; 57999 } 58000 getRangeReader(begin, end) { 58001 const reader = new PDFWorkerStreamRangeReader(begin, end, this._msgHandler); 58002 this._rangeRequestReaders.push(reader); 58003 return reader; 58004 } 58005 cancelAllRequests(reason) { 58006 this._fullRequestReader?.cancel(reason); 58007 for (const reader of this._rangeRequestReaders.slice(0)) { 58008 reader.cancel(reason); 58009 } 58010 } 58011} 58012class PDFWorkerStreamReader { 58013 constructor(msgHandler) { 58014 this._msgHandler = msgHandler; 58015 this.onProgress = null; 58016 this._contentLength = null; 58017 this._isRangeSupported = false; 58018 this._isStreamingSupported = false; 58019 const readableStream = this._msgHandler.sendWithStream("GetReader"); 58020 this._reader = readableStream.getReader(); 58021 this._headersReady = this._msgHandler.sendWithPromise("ReaderHeadersReady").then(data => { 58022 this._isStreamingSupported = data.isStreamingSupported; 58023 this._isRangeSupported = data.isRangeSupported; 58024 this._contentLength = data.contentLength; 58025 }); 58026 } 58027 get headersReady() { 58028 return this._headersReady; 58029 } 58030 get contentLength() { 58031 return this._contentLength; 58032 } 58033 get isStreamingSupported() { 58034 return this._isStreamingSupported; 58035 } 58036 get isRangeSupported() { 58037 return this._isRangeSupported; 58038 } 58039 async read() { 58040 const { 58041 value, 58042 done 58043 } = await this._reader.read(); 58044 if (done) { 58045 return { 58046 value: undefined, 58047 done: true 58048 }; 58049 } 58050 return { 58051 value: value.buffer, 58052 done: false 58053 }; 58054 } 58055 cancel(reason) { 58056 this._reader.cancel(reason); 58057 } 58058} 58059class PDFWorkerStreamRangeReader { 58060 constructor(begin, end, msgHandler) { 58061 this._msgHandler = msgHandler; 58062 this.onProgress = null; 58063 const readableStream = this._msgHandler.sendWithStream("GetRangeReader", { 58064 begin, 58065 end 58066 }); 58067 this._reader = readableStream.getReader(); 58068 } 58069 get isStreamingSupported() { 58070 return false;
58071 } 58072 async read() { 58073 const { 58074 value, 58075 done 58076 } = await this._reader.read(); 58077 if (done) { 58078 return { 58079 value: undefined, 58080 done: true 58081 }; 58082 } 58083 return { 58084 value: value.buffer, 58085 done: false 58086 }; 58087 } 58088 cancel(reason) { 58089 this._reader.cancel(reason); 58090 } 58091} 58092 58093;// ./src/core/worker.js
vendor: 21,607 bytes, lines 58093-58730
58093 58094 58095 58096 58097 58098 58099 58100 58101 58102 58103 58104class WorkerTask { 58105 constructor(name) { 58106 this.name = name; 58107 this.terminated = false; 58108 this._capability = Promise.withResolvers(); 58109 } 58110 get finished() { 58111 return this._capability.promise; 58112 } 58113 finish() { 58114 this._capability.resolve(); 58115 } 58116 terminate() { 58117 this.terminated = true; 58118 } 58119 ensureNotTerminated() { 58120 if (this.terminated) { 58121 throw new Error("Worker task was terminated"); 58122 } 58123 } 58124} 58125class WorkerMessageHandler { 58126 static { 58127 if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" && typeof self.postMessage === "function" && "onmessage" in self) { 58128 this.initializeFromPort(self); 58129 } 58130 } 58131 static setup(handler, port) { 58132 let testMessageProcessed = false; 58133 handler.on("test", data => { 58134 if (testMessageProcessed) { 58135 return; 58136 } 58137 testMessageProcessed = true; 58138 handler.send("test", data instanceof Uint8Array); 58139 }); 58140 handler.on("configure", data => { 58141 setVerbosityLevel(data.verbosity); 58142 }); 58143 handler.on("GetDocRequest", data => this.createDocumentHandler(data, port)); 58144 } 58145 static createDocumentHandler(docParams, port) { 58146 let pdfManager; 58147 let terminated = false; 58148 let cancelXHRs = null; 58149 const WorkerTasks = new Set(); 58150 const verbosity = getVerbosityLevel(); 58151 const { 58152 docId, 58153 apiVersion 58154 } = docParams; 58155 const workerVersion = "5.4.296"; 58156 if (apiVersion !== workerVersion) { 58157 throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`); 58158 } 58159 const buildMsg = (type, prop) => `The \`${type}.prototype\` contains unexpected enumerable property ` + `"${prop}", thus breaking e.g. \`for...in\` iteration of ${type}s.`; 58160 for (const prop in {}) { 58161 throw new Error(buildMsg("Object", prop)); 58162 } 58163 for (const prop in []) { 58164 throw new Error(buildMsg("Array", prop)); 58165 } 58166 const workerHandlerName = docId + "_worker"; 58167 let handler = new MessageHandler(workerHandlerName, docId, port); 58168 function ensureNotTerminated() { 58169 if (terminated) { 58170 throw new Error("Worker was terminated"); 58171 } 58172 } 58173 function startWorkerTask(task) { 58174 WorkerTasks.add(task); 58175 } 58176 function finishWorkerTask(task) { 58177 task.finish(); 58178 WorkerTasks.delete(task); 58179 } 58180 async function loadDocument(recoveryMode) { 58181 await pdfManager.ensureDoc("checkHeader"); 58182 await pdfManager.ensureDoc("parseStartXRef"); 58183 await pdfManager.ensureDoc("parse", [recoveryMode]); 58184 await pdfManager.ensureDoc("checkFirstPage", [recoveryMode]); 58185 await pdfManager.ensureDoc("checkLastPage", [recoveryMode]); 58186 const isPureXfa = await pdfManager.ensureDoc("isPureXfa"); 58187 if (isPureXfa) { 58188 const task = new WorkerTask("loadXfaResources"); 58189 startWorkerTask(task); 58190 await pdfManager.ensureDoc("loadXfaResources", [handler, task]); 58191 finishWorkerTask(task); 58192 } 58193 const [numPages, fingerprints] = await Promise.all([pdfManager.ensureDoc("numPages"), pdfManager.ensureDoc("fingerprints")]); 58194 const htmlForXfa = isPureXfa ? await pdfManager.ensureDoc("htmlForXfa") : null; 58195 return { 58196 numPages, 58197 fingerprints, 58198 htmlForXfa 58199 }; 58200 } 58201 async function getPdfManager({ 58202 data, 58203 password, 58204 disableAutoFetch, 58205 rangeChunkSize, 58206 length, 58207 docBaseUrl, 58208 enableXfa, 58209 evaluatorOptions 58210 }) { 58211 const pdfManagerArgs = { 58212 source: null, 58213 disableAutoFetch, 58214 docBaseUrl, 58215 docId, 58216 enableXfa, 58217 evaluatorOptions, 58218 handler, 58219 length, 58220 password, 58221 rangeChunkSize 58222 }; 58223 if (data) { 58224 pdfManagerArgs.source = data; 58225 return new LocalPdfManager(pdfManagerArgs); 58226 } 58227 const pdfStream = new PDFWorkerStream(handler), 58228 fullRequest = pdfStream.getFullReader(); 58229 const pdfManagerCapability = Promise.withResolvers(); 58230 let newPdfManager, 58231 cachedChunks = [], 58232 loaded = 0; 58233 fullRequest.headersReady.then(function () { 58234 if (!fullRequest.isRangeSupported) { 58235 return; 58236 } 58237 pdfManagerArgs.source = pdfStream; 58238 pdfManagerArgs.length = fullRequest.contentLength; 58239 pdfManagerArgs.disableAutoFetch ||= fullRequest.isStreamingSupported; 58240 newPdfManager = new NetworkPdfManager(pdfManagerArgs); 58241 for (const chunk of cachedChunks) { 58242 newPdfManager.sendProgressiveData(chunk); 58243 } 58244 cachedChunks = []; 58245 pdfManagerCapability.resolve(newPdfManager); 58246 cancelXHRs = null; 58247 }).catch(function (reason) { 58248 pdfManagerCapability.reject(reason); 58249 cancelXHRs = null; 58250 }); 58251 new Promise(function (resolve, reject) { 58252 const readChunk = function ({ 58253 value, 58254 done 58255 }) { 58256 try { 58257 ensureNotTerminated(); 58258 if (done) { 58259 if (!newPdfManager) { 58260 const pdfFile = arrayBuffersToBytes(cachedChunks); 58261 cachedChunks = []; 58262 if (length && pdfFile.length !== length) { 58263 warn("reported HTTP length is different from actual"); 58264 } 58265 pdfManagerArgs.source = pdfFile; 58266 newPdfManager = new LocalPdfManager(pdfManagerArgs); 58267 pdfManagerCapability.resolve(newPdfManager); 58268 } 58269 cancelXHRs = null; 58270 return; 58271 } 58272 loaded += value.byteLength; 58273 if (!fullRequest.isStreamingSupported) { 58274 handler.send("DocProgress", { 58275 loaded, 58276 total: Math.max(loaded, fullRequest.contentLength || 0) 58277 }); 58278 } 58279 if (newPdfManager) { 58280 newPdfManager.sendProgressiveData(value); 58281 } else { 58282 cachedChunks.push(value); 58283 } 58284 fullRequest.read().then(readChunk, reject); 58285 } catch (e) { 58286 reject(e); 58287 } 58288 }; 58289 fullRequest.read().then(readChunk, reject); 58290 }).catch(function (e) { 58291 pdfManagerCapability.reject(e); 58292 cancelXHRs = null; 58293 }); 58294 cancelXHRs = reason => { 58295 pdfStream.cancelAllRequests(reason); 58296 }; 58297 return pdfManagerCapability.promise; 58298 } 58299 function setupDoc(data) { 58300 function onSuccess(doc) { 58301 ensureNotTerminated(); 58302 handler.send("GetDoc", { 58303 pdfInfo: doc 58304 }); 58305 } 58306 function onFailure(ex) { 58307 ensureNotTerminated(); 58308 if (ex instanceof PasswordException) { 58309 const task = new WorkerTask(`PasswordException: response ${ex.code}`); 58310 startWorkerTask(task); 58311 handler.sendWithPromise("PasswordRequest", ex).then(function ({ 58312 password 58313 }) { 58314 finishWorkerTask(task); 58315 pdfManager.updatePassword(password); 58316 pdfManagerReady(); 58317 }).catch(function () { 58318 finishWorkerTask(task); 58319 handler.send("DocException", ex); 58320 }); 58321 } else { 58322 handler.send("DocException", wrapReason(ex)); 58323 } 58324 } 58325 function pdfManagerReady() { 58326 ensureNotTerminated(); 58327 loadDocument(false).then(onSuccess, function (reason) { 58328 ensureNotTerminated(); 58329 if (!(reason instanceof XRefParseException)) { 58330 onFailure(reason); 58331 return; 58332 } 58333 pdfManager.requestLoadedStream().then(function () { 58334 ensureNotTerminated(); 58335 loadDocument(true).then(onSuccess, onFailure); 58336 }); 58337 }); 58338 } 58339 ensureNotTerminated(); 58340 getPdfManager(data).then(function (newPdfManager) { 58341 if (terminated) { 58342 newPdfManager.terminate(new AbortException("Worker was terminated.")); 58343 throw new Error("Worker was terminated"); 58344 } 58345 pdfManager = newPdfManager; 58346 pdfManager.requestLoadedStream(true).then(stream => { 58347 handler.send("DataLoaded", { 58348 length: stream.bytes.byteLength 58349 }); 58350 }); 58351 }).then(pdfManagerReady, onFailure); 58352 } 58353 handler.on("GetPage", function (data) { 58354 return pdfManager.getPage(data.pageIndex).then(function (page) { 58355 return Promise.all([pdfManager.ensure(page, "rotate"), pdfManager.ensure(page, "ref"), pdfManager.ensure(page, "userUnit"), pdfManager.ensure(page, "view")]).then(function ([rotate, ref, userUnit, view]) { 58356 return { 58357 rotate, 58358 ref, 58359 refStr: ref?.toString() ?? null, 58360 userUnit, 58361 view 58362 }; 58363 }); 58364 }); 58365 }); 58366 handler.on("GetPageIndex", function (data) { 58367 const pageRef = Ref.get(data.num, data.gen); 58368 return pdfManager.ensureCatalog("getPageIndex", [pageRef]); 58369 }); 58370 handler.on("GetDestinations", function (data) { 58371 return pdfManager.ensureCatalog("destinations"); 58372 }); 58373 handler.on("GetDestination", function (data) { 58374 return pdfManager.ensureCatalog("getDestination", [data.id]); 58375 }); 58376 handler.on("GetPageLabels", function (data) { 58377 return pdfManager.ensureCatalog("pageLabels"); 58378 }); 58379 handler.on("GetPageLayout", function (data) { 58380 return pdfManager.ensureCatalog("pageLayout"); 58381 }); 58382 handler.on("GetPageMode", function (data) { 58383 return pdfManager.ensureCatalog("pageMode"); 58384 }); 58385 handler.on("GetViewerPreferences", function (data) { 58386 return pdfManager.ensureCatalog("viewerPreferences"); 58387 }); 58388 handler.on("GetOpenAction", function (data) { 58389 return pdfManager.ensureCatalog("openAction"); 58390 }); 58391 handler.on("GetAttachments", function (data) { 58392 return pdfManager.ensureCatalog("attachments"); 58393 }); 58394 handler.on("GetDocJSActions", function (data) { 58395 return pdfManager.ensureCatalog("jsActions"); 58396 }); 58397 handler.on("GetPageJSActions", function ({ 58398 pageIndex 58399 }) { 58400 return pdfManager.getPage(pageIndex).then(page => pdfManager.ensure(page, "jsActions")); 58401 }); 58402 handler.on("GetAnnotationsByType", async function ({ 58403 types, 58404 pageIndexesToSkip 58405 }) { 58406 const [numPages, annotationGlobals] = await Promise.all([pdfManager.ensureDoc("numPages"), pdfManager.ensureDoc("annotationGlobals")]); 58407 if (!annotationGlobals) { 58408 return null; 58409 } 58410 const pagePromises = []; 58411 const annotationPromises = []; 58412 let task = null; 58413 try { 58414 for (let i = 0, ii = numPages; i < ii; i++) { 58415 if (pageIndexesToSkip?.has(i)) { 58416 continue; 58417 } 58418 if (!task) { 58419 task = new WorkerTask("GetAnnotationsByType"); 58420 startWorkerTask(task); 58421 } 58422 pagePromises.push(pdfManager.getPage(i).then(async page => { 58423 if (!page) { 58424 return []; 58425 } 58426 return page.collectAnnotationsByType(handler, task, types, annotationPromises, annotationGlobals) || []; 58427 })); 58428 } 58429 await Promise.all(pagePromises); 58430 const annotations = await Promise.all(annotationPromises); 58431 return annotations.filter(a => !!a); 58432 } finally { 58433 if (task) { 58434 finishWorkerTask(task); 58435 } 58436 } 58437 }); 58438 handler.on("GetOutline", function (data) { 58439 return pdfManager.ensureCatalog("documentOutline"); 58440 }); 58441 handler.on("GetOptionalContentConfig", function (data) { 58442 return pdfManager.ensureCatalog("optionalContentConfig"); 58443 }); 58444 handler.on("GetPermissions", function (data) { 58445 return pdfManager.ensureCatalog("permissions"); 58446 }); 58447 handler.on("GetMetadata", function (data) { 58448 return Promise.all([pdfManager.ensureDoc("documentInfo"), pdfManager.ensureCatalog("metadata")]); 58449 }); 58450 handler.on("GetMarkInfo", function (data) { 58451 return pdfManager.ensureCatalog("markInfo"); 58452 }); 58453 handler.on("GetData", function (data) { 58454 return pdfManager.requestLoadedStream().then(stream => stream.bytes); 58455 }); 58456 handler.on("GetAnnotations", function ({ 58457 pageIndex, 58458 intent 58459 }) { 58460 return pdfManager.getPage(pageIndex).then(function (page) { 58461 const task = new WorkerTask(`GetAnnotations: page ${pageIndex}`); 58462 startWorkerTask(task); 58463 return page.getAnnotationsData(handler, task, intent).then(data => { 58464 finishWorkerTask(task); 58465 return data; 58466 }, reason => { 58467 finishWorkerTask(task); 58468 throw reason; 58469 }); 58470 }); 58471 }); 58472 handler.on("GetFieldObjects", function (data) { 58473 return pdfManager.ensureDoc("fieldObjects").then(fieldObjects => fieldObjects?.allFields || null); 58474 }); 58475 handler.on("HasJSActions", function (data) { 58476 return pdfManager.ensureDoc("hasJSActions"); 58477 }); 58478 handler.on("GetCalculationOrderIds", function (data) { 58479 return pdfManager.ensureDoc("calculationOrderIds"); 58480 }); 58481 handler.on("SaveDocument", async function ({ 58482 isPureXfa, 58483 numPages, 58484 annotationStorage, 58485 filename 58486 }) { 58487 const globalPromises = [pdfManager.requestLoadedStream(), pdfManager.ensureCatalog("acroForm"), pdfManager.ensureCatalog("acroFormRef"), pdfManager.ensureDoc("startXRef"), pdfManager.ensureDoc("xref"), pdfManager.ensureCatalog("structTreeRoot")]; 58488 const changes = new RefSetCache(); 58489 const promises = []; 58490 const newAnnotationsByPage = !isPureXfa ? getNewAnnotationsMap(annotationStorage) : null; 58491 const [stream, acroForm, acroFormRef, startXRef, xref, _structTreeRoot] = await Promise.all(globalPromises); 58492 const catalogRef = xref.trailer.getRaw("Root") || null; 58493 let structTreeRoot; 58494 if (newAnnotationsByPage) { 58495 if (!_structTreeRoot) { 58496 if (await StructTreeRoot.canCreateStructureTree({ 58497 catalogRef, 58498 pdfManager, 58499 newAnnotationsByPage 58500 })) { 58501 structTreeRoot = null; 58502 } 58503 } else if (await _structTreeRoot.canUpdateStructTree({ 58504 pdfManager, 58505 newAnnotationsByPage 58506 })) { 58507 structTreeRoot = _structTreeRoot; 58508 } 58509 const imagePromises = AnnotationFactory.generateImages(annotationStorage.values(), xref, pdfManager.evaluatorOptions.isOffscreenCanvasSupported); 58510 const newAnnotationPromises = structTreeRoot === undefined ? promises : []; 58511 for (const [pageIndex, annotations] of newAnnotationsByPage) { 58512 newAnnotationPromises.push(pdfManager.getPage(pageIndex).then(page => { 58513 const task = new WorkerTask(`Save (editor): page ${pageIndex}`); 58514 startWorkerTask(task); 58515 return page.saveNewAnnotations(handler, task, annotations, imagePromises, changes).finally(function () { 58516 finishWorkerTask(task); 58517 }); 58518 })); 58519 } 58520 if (structTreeRoot === null) { 58521 promises.push(Promise.all(newAnnotationPromises).then(async () => { 58522 await StructTreeRoot.createStructureTree({ 58523 newAnnotationsByPage, 58524 xref, 58525 catalogRef, 58526 pdfManager, 58527 changes 58528 }); 58529 })); 58530 } else if (structTreeRoot) { 58531 promises.push(Promise.all(newAnnotationPromises).then(async () => { 58532 await structTreeRoot.updateStructureTree({ 58533 newAnnotationsByPage, 58534 pdfManager, 58535 changes 58536 }); 58537 })); 58538 } 58539 } 58540 if (isPureXfa) { 58541 promises.push(pdfManager.ensureDoc("serializeXfaData", [annotationStorage])); 58542 } else { 58543 for (let pageIndex = 0; pageIndex < numPages; pageIndex++) { 58544 promises.push(pdfManager.getPage(pageIndex).then(function (page) { 58545 const task = new WorkerTask(`Save: page ${pageIndex}`); 58546 startWorkerTask(task); 58547 return page.save(handler, task, annotationStorage, changes).finally(function () { 58548 finishWorkerTask(task); 58549 }); 58550 })); 58551 } 58552 } 58553 const refs = await Promise.all(promises); 58554 let xfaData = null; 58555 if (isPureXfa) { 58556 xfaData = refs[0]; 58557 if (!xfaData) { 58558 return stream.bytes; 58559 } 58560 } else if (changes.size === 0) { 58561 return stream.bytes; 58562 } 58563 const needAppearances = acroFormRef && acroForm instanceof Dict && changes.values().some(ref => ref.needAppearances); 58564 const xfa = acroForm instanceof Dict && acroForm.get("XFA") || null; 58565 let xfaDatasetsRef = null; 58566 let hasXfaDatasetsEntry = false; 58567 if (Array.isArray(xfa)) { 58568 for (let i = 0, ii = xfa.length; i < ii; i += 2) { 58569 if (xfa[i] === "datasets") { 58570 xfaDatasetsRef = xfa[i + 1]; 58571 hasXfaDatasetsEntry = true; 58572 } 58573 } 58574 if (xfaDatasetsRef === null) { 58575 xfaDatasetsRef = xref.getNewTemporaryRef(); 58576 } 58577 } else if (xfa) { 58578 warn("Unsupported XFA type."); 58579 } 58580 let newXrefInfo = Object.create(null); 58581 if (xref.trailer) { 58582 const infoMap = new Map(); 58583 const xrefInfo = xref.trailer.get("Info") || null; 58584 if (xrefInfo instanceof Dict) { 58585 for (const [key, value] of xrefInfo) { 58586 if (typeof value === "string") { 58587 infoMap.set(key, stringToPDFString(value)); 58588 } 58589 } 58590 } 58591 newXrefInfo = { 58592 rootRef: catalogRef, 58593 encryptRef: xref.trailer.getRaw("Encrypt") || null, 58594 newRef: xref.getNewTemporaryRef(), 58595 infoRef: xref.trailer.getRaw("Info") || null, 58596 infoMap, 58597 fileIds: xref.trailer.get("ID") || null, 58598 startXRef, 58599 filename 58600 }; 58601 } 58602 return incrementalUpdate({ 58603 originalData: stream.bytes, 58604 xrefInfo: newXrefInfo, 58605 changes, 58606 xref, 58607 hasXfa: !!xfa, 58608 xfaDatasetsRef, 58609 hasXfaDatasetsEntry, 58610 needAppearances, 58611 acroFormRef, 58612 acroForm, 58613 xfaData, 58614 useXrefStream: isDict(xref.topDict, "XRef") 58615 }).finally(() => { 58616 xref.resetNewTemporaryRef(); 58617 }); 58618 }); 58619 handler.on("GetOperatorList", function (data, sink) { 58620 const pageIndex = data.pageIndex; 58621 pdfManager.getPage(pageIndex).then(function (page) { 58622 const task = new WorkerTask(`GetOperatorList: page ${pageIndex}`); 58623 startWorkerTask(task); 58624 const start = verbosity >= VerbosityLevel.INFOS ? Date.now() : 0; 58625 page.getOperatorList({ 58626 handler, 58627 sink, 58628 task, 58629 intent: data.intent, 58630 cacheKey: data.cacheKey, 58631 annotationStorage: data.annotationStorage, 58632 modifiedIds: data.modifiedIds 58633 }).then(function (operatorListInfo) { 58634 finishWorkerTask(task); 58635 if (start) { 58636 info(`page=${pageIndex + 1} - getOperatorList: time=` + `${Date.now() - start}ms, len=${operatorListInfo.length}`); 58637 } 58638 sink.close(); 58639 }, function (reason) { 58640 finishWorkerTask(task); 58641 if (task.terminated) { 58642 return; 58643 } 58644 sink.error(reason); 58645 }); 58646 }); 58647 }); 58648 handler.on("GetTextContent", function (data, sink) { 58649 const { 58650 pageIndex, 58651 includeMarkedContent, 58652 disableNormalization 58653 } = data; 58654 pdfManager.getPage(pageIndex).then(function (page) { 58655 const task = new WorkerTask("GetTextContent: page " + pageIndex); 58656 startWorkerTask(task); 58657 const start = verbosity >= VerbosityLevel.INFOS ? Date.now() : 0; 58658 page.extractTextContent({ 58659 handler, 58660 task, 58661 sink, 58662 includeMarkedContent, 58663 disableNormalization 58664 }).then(function () { 58665 finishWorkerTask(task); 58666 if (start) { 58667 info(`page=${pageIndex + 1} - getTextContent: time=` + `${Date.now() - start}ms`); 58668 } 58669 sink.close(); 58670 }, function (reason) { 58671 finishWorkerTask(task); 58672 if (task.terminated) { 58673 return; 58674 } 58675 sink.error(reason); 58676 }); 58677 }); 58678 }); 58679 handler.on("GetStructTree", function (data) { 58680 return pdfManager.getPage(data.pageIndex).then(page => pdfManager.ensure(page, "getStructTree")); 58681 }); 58682 handler.on("FontFallback", function (data) { 58683 return pdfManager.fontFallback(data.id, handler); 58684 }); 58685 handler.on("Cleanup", function (data) { 58686 return pdfManager.cleanup(true); 58687 }); 58688 handler.on("Terminate", function (data) { 58689 terminated = true; 58690 const waitOn = []; 58691 if (pdfManager) { 58692 pdfManager.terminate(new AbortException("Worker was terminated.")); 58693 const cleanupPromise = pdfManager.cleanup(); 58694 waitOn.push(cleanupPromise); 58695 pdfManager = null; 58696 } else { 58697 clearGlobalCaches(); 58698 } 58699 cancelXHRs?.(new AbortException("Worker was terminated.")); 58700 for (const task of WorkerTasks) { 58701 waitOn.push(task.finished); 58702 task.terminate(); 58703 } 58704 return Promise.all(waitOn).then(function () { 58705 handler.destroy(); 58706 handler = null; 58707 }); 58708 }); 58709 handler.on("Ready", function (data) { 58710 setupDoc(docParams); 58711 docParams = null; 58712 }); 58713 return workerHandlerName; 58714 } 58715 static initializeFromPort(port) { 58716 const handler = new MessageHandler("worker", "main", port); 58717 this.setup(handler, port); 58718 handler.send("ready", null); 58719 } 58720} 58721 58722;// ./src/pdf.worker.js 58723 58724globalThis.pdfjsWorker = { 58725 WorkerMessageHandler: WorkerMessageHandler 58726}; 58727 58728export { WorkerMessageHandler }; 58729 58730//# sourceMappingURL=pdf.worker.mjs.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.